欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

[20190401]跟踪dbms_lock.sleep调用.txt

程序员文章站 2022-10-18 11:37:24
[20190401]跟踪dbms_lock.sleep调用.txt--//自己在semtimedop函数调用理解错误,加深理解,跟踪dbms_lock.sleep调用的情况.1.环境:SCOTT@book> @ ver1PORT_STRING VERSION BANNER x86_64/Linux ......

[20190401]跟踪dbms_lock.sleep调用.txt

--//自己在semtimedop函数调用理解错误,加深理解,跟踪dbms_lock.sleep调用的情况.

1.环境:
scott@book> @ ver1
port_string                    version        banner
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/linux 2.4.xx            11.2.0.4.0     oracle database 11g enterprise edition release 11.2.0.4.0 - 64bit production

grant execute on  dbms_lock to scott;

scott@book> @ spid
       sid    serial# process                  server    spid       pid  p_serial# c50
---------- ---------- ------------------------ --------- ------ ------- ---------- --------------------------------------------------
        51          7 60257                    dedicated 60258       27        123 alter system kill session '51,7' immediate;

 $ strace -ftr -e semtimedop -p 60258
process 60258 attached - interrupt to quit

--//仅仅跟踪semtimedop.

2.测试:
scott@book> exec dbms_lock.sleep(5.3)
pl/sql procedure successfully completed.

$ strace -ftr -e semtimedop -p 60258
process 60258 attached - interrupt to quit
     0.000000 semtimedop(309821440, 0x7fffe52f9ac0, 1, {5, 300000000}) = -1 eagain (resource temporarily unavailable) <5.300886>
--//可以发现实际上执行dbms_lock.sleep(5.3),调用函数是semtimedop,睡眠5.3秒.

scott@book> exec dbms_lock.sleep(10.3)
pl/sql procedure successfully completed.

$ strace -ftr -e semtimedop -p 60258
..
    65.217301 semtimedop(309821440, 0x7fffe52f9ac0, 1, {3, 0}) = -1 eagain (resource temporarily unavailable) <3.000460>
     3.000610 semtimedop(309821440, 0x7fffe52f9ac0, 1, {3, 0}) = -1 eagain (resource temporarily unavailable) <3.000960>
     3.001073 semtimedop(309821440, 0x7fffe52f9ac0, 1, {4, 300000000}) = -1 eagain (resource temporarily unavailable) <4.300934>

--//你可以基本看出执行dbms_lock.sleep大致算法,oracle许多东西都与3秒有关.
--//分成多个3秒,开始调用semtimedop 3秒,剩下部分小于2*3秒时,调用剩余的部分.

--//再次测试,在执行的过程中打开新终端窗口,执行kill -1 60258.
scott@book> exec dbms_lock.sleep(10.3)
--//中间执行:
$ kill -1 60258

pl/sql procedure successfully completed.

--//注:kill -1 并不会杀死进程,仅仅挂起.可以通过kill -l了解一些细节.
 $ kill -l
 1) sighup       2) sigint       3) sigquit      4) sigill
 5) sigtrap      6) sigabrt      7) sigbus       8) sigfpe
 9) sigkill     10) sigusr1     11) sigsegv     12) sigusr2
13) sigpipe     14) sigalrm     15) sigterm     16) sigstkflt
17) sigchld     18) sigcont     19) sigstop     20) sigtstp
21) sigttin     22) sigttou     23) sigurg      24) sigxcpu
25) sigxfsz     26) sigvtalrm   27) sigprof     28) sigwinch
29) sigio       30) sigpwr      31) sigsys      34) sigrtmin
35) sigrtmin+1  36) sigrtmin+2  37) sigrtmin+3  38) sigrtmin+4
39) sigrtmin+5  40) sigrtmin+6  41) sigrtmin+7  42) sigrtmin+8
43) sigrtmin+9  44) sigrtmin+10 45) sigrtmin+11 46) sigrtmin+12
47) sigrtmin+13 48) sigrtmin+14 49) sigrtmin+15 50) sigrtmax-14
51) sigrtmax-13 52) sigrtmax-12 53) sigrtmax-11 54) sigrtmax-10
55) sigrtmax-9  56) sigrtmax-8  57) sigrtmax-7  58) sigrtmax-6
59) sigrtmax-5  60) sigrtmax-4  61) sigrtmax-3  62) sigrtmax-2
63) sigrtmax-1  64) sigrtmax

$ strace -ftr -e semtimedop -p 60258
..
   154.662451 semtimedop(309821440, 0x7fffe52f9ac0, 1, {3, 0}) = -1 eagain (resource temporarily unavailable) <3.000463>
     3.000651 semtimedop(309821440, 0x7fffe52f9ac0, 1, {3, 0}) = -1 eintr (interrupted system call) <1.573761>
     1.573876 --- sighup (hangup) @ 0 (0) ---
     0.000203 semtimedop(309821440, 0x7fffe52f9ac0, 1, {5, 730000000}) = -1 eagain (resource temporarily unavailable) <5.730875>
--//在第2个3秒中发出了中断,仅仅执行1.57秒.最后1次调用执行 4.3+1.43 = 5.73秒.

--//再次测试,中间按ctrl+c看看:
scott@book> exec dbms_lock.sleep(10.3)
begin dbms_lock.sleep(10.3); end;

*
error at line 1:
ora-01013: user requested cancel of current operation
ora-06512: at "sys.dbms_lock", line 205
ora-06512: at line 1

$ strace -ftr -e semtimedop -p 60258
..
    14.543729 semtimedop(309821440, 0x7fffe52f9ac0, 1, {3, 0}) = -1 eintr (interrupted system call) <2.880053>
     2.880177 --- sigurg (urgent i/o condition) @ 0 (0) ---
--//中断不再继续执行.

--//再次测试,中间执行kill -19 60258, 19表示sigstop,暂停执行.
$ strace -ftr -e semtimedop -p 60258
..

   172.564623 semtimedop(309821440, 0x7fffe52f9ac0, 1, {3, 0}) = -1 eintr (interrupted system call) <2.343982>
     2.344113 --- sigstop (stopped (signal)) @ 0 (0) ---
     0.000071 --- sigstop (stopped (signal)) @ 0 (0) ---
     0.000326 semtimedop(309821440, 0x7fffe52f9ac0, 1, {3, 0}) = -1 eagain (resource temporarily unavailable) <3.000768>
     3.000904 semtimedop(309821440, 0x7fffe52f9ac0, 1, {4, 960000000}) = -1 eagain (resource temporarily unavailable) <4.960862>

--//可以发现仅仅暂停第1个3秒的执行.总的sleep时间是不变的.
--//2.343982+3.000768+4.960862 = 10.305612
--//后续的sql语句并不影响执行.

--//做这些测试仅仅是加强理解..^_^.

--//顺便说一下linux sleep调用的是nanosleep.
$ strace sleep 10.3
...
brk(0x1d63000)                          = 0x1d63000
nanosleep({10, 300000001}, null)        = 0
close(1)                                = 0
exit_group(0)                           = ?