简单测试latch nowilling等待模式案例(2)

$ . y1.sh
20190424091250
[3]-  Done                    sqlplus / as sysdba <<< "@ exclusive_latch.txt 'test excl. parent2 l0' 0 1 2 6" > /dev/null
[1]  Done                    source peek.sh 'test excl. parent2 l0' 20 | timestamp.pl >|/tmp/peekx_${zdate}.txt
[4]-  Done                    sqlplus / as sysdba <<< "@ exclusive_latch.txt 'test excl. parent2 l0' 0 3 4 6" > /dev/null
[5]+  Done                    sqlplus / as sysdba <<< "@ exclusive_latch.txt 'test excl. parent2 l0' 0 5 6 6" > /dev/null
[2]+  Done                    seq 20 | xargs -I{} echo -e 'sqlplus -s -l / as sysdba <<< @latch_free\nsleep 1' | bash >|/tmp/latch_freeo_${zdate}.txt

2.测试:
$ grep  -v '^.*: $' /tmp/peekx_20190424091250.txt | cut -c10- | uniq -c
      1  SYSDATE            LADDR
      1  ------------------- ----------------
      1  2019-04-24 09:12:50 0000000060009978
      1  Statement processed.
      6  [060009978, 060009980) = 00000015 00000000
      1  [060009978, 060009980) = 00000000 00000000
      6  [060009978, 060009980) = 00000015 00000000
      7  [060009978, 060009980) = 00000000 00000000
--//你可以发现第1个会话申请成功,第2个会话没有申请成功,直接退出.第3个会话申请成功(因为sleep 2+4.1秒).

--//cat /tmp/latch_freeo_20190424091250.txt
2019-04-24 09:12:50
2019-04-24 09:12:51
Process 21
 holding: 0000000060009978  "test excl. parent2 l0" lvl=0 whr=2 why=1, SID=295

2019-04-24 09:12:52
Process 21
 holding: 0000000060009978  "test excl. parent2 l0" lvl=0 whr=2 why=1, SID=295

2019-04-24 09:12:53
Process 21
 holding: 0000000060009978  "test excl. parent2 l0" lvl=0 whr=2 why=1, SID=295

2019-04-24 09:12:54
Process 21
 holding: 0000000060009978  "test excl. parent2 l0" lvl=0 whr=2 why=1, SID=295

2019-04-24 09:12:55
Process 21
 holding: 0000000060009978  "test excl. parent2 l0" lvl=0 whr=2 why=1, SID=295

2019-04-24 09:12:56
Process 21
 holding: 0000000060009978  "test excl. parent2 l0" lvl=0 whr=6 why=5, SID=295

2019-04-24 09:12:57
Process 21
 holding: 0000000060009978  "test excl. parent2 l0" lvl=0 whr=6 why=5, SID=295

2019-04-24 09:12:58
Process 21
 holding: 0000000060009978  "test excl. parent2 l0" lvl=0 whr=6 why=5, SID=295

2019-04-24 09:13:00
Process 21
 holding: 0000000060009978  "test excl. parent2 l0" lvl=0 whr=6 why=5, SID=295

2019-04-24 09:13:01
Process 21
 holding: 0000000060009978  "test excl. parent2 l0" lvl=0 whr=6 why=5, SID=295

2019-04-24 09:13:02
Process 21
 holding: 0000000060009978  "test excl. parent2 l0" lvl=0 whr=6 why=5, SID=295

2019-04-24 09:13:03
2019-04-24 09:13:04
--//21=0x15,与peek看到的一致.

3.手工测试看看函数的返回值
--//session 1:
SYS@book> @ exclusive_latch.txt 'test excl. parent2 l0' 0 1 2 60
old  1: SELECT addr laddr FROM v$latch_parent WHERE
new  1: SELECT addr laddr FROM v$latch_parent WHERE

LADDR
----------------
0000000060009978

Statement processed.
Function returned 1
Function returned 0

--//session 2:
SYS@book> @ exclusive_latch.txt 'test excl. parent2 l0' 0 3 4 6
old  1: SELECT addr laddr FROM v$latch_parent WHERE
new  1: SELECT addr laddr FROM v$latch_parent WHERE

LADDR
----------------
0000000060009978

Statement processed.
Function returned 0

ORA-00600: internal error code, arguments: [510], [0x060009978], [test excl. parent2 l0], [], [], [], [], [], [], [], [], []

--//可以发现申请成功函数返回值是1.失败是0.只所以session 2报错主要原因是没有申请成功,kslfre肯定报错.

4.看看latch统计信息的情况:
SYS@book> select addr,name,level#,latch#,gets,misses,sleeps,immediate_gets,immediate_misses,waiters_woken,waits_holding_latch,spin_gets,wait_time from v$latch_parent  where lower(name) like '%'||lower('test excl. parent2 l0')||'%';
ADDR            NAME                  LEVEL#    LATCH#      GETS    MISSES    SLEEPS IMMEDIATE_GETS IMMEDIATE_MISSES WAITERS_WOKEN WAITS_HOLDING_LATCH  SPIN_GETS  WAIT_TIME
---------------- --------------------- ------ ---------- ---------- ---------- ---------- -------------- ---------------- ------------- ------------------- ---------- ----------
0000000060009978 test excl. parent2 l0      0          5          4          0          0              4                3            0                  0          0          0

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/ab603bc79af929add398774c08ad744c.html