首页 > 其他分享 >[20240827]分析为什么出现library cache lock等待事件2.txt

[20240827]分析为什么出现library cache lock等待事件2.txt

时间:2024-09-01 17:17:34浏览次数:9  
标签:10 27 -- lock cache 20240827 2024 KGLLKHDL ----------

[20240827]分析为什么出现library cache lock等待事件2.txt

--//前几天一直在分析如果表不存在的情况下,密集执行为什么出现library cache lock等待事件,而且出现的mode=2(共享模式),按照道
--//理不应该阻塞,做一个分析.

1.环境:
SCOTT@book01p> @ver2
==============================
PORT_STRING                   : x86_64/Linux 2.4.xx
VERSION                       : 21.0.0.0.0
BANNER                        : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
BANNER_FULL                   : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
BANNER_LEGACY                 : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
CON_ID                        : 0
PL/SQL procedure successfully completed.

2.首先定位该对象handle address,编写gdb脚本:
$ cat lcl.gdb
set $lk  = 0
break kgllkal
commands
silent
printf "kgllkal count %02d -- handle address: %016x, mode: %d ", ++$lk ,$rdx ,$rcx
echo kglnaobj address:
x/s $rdx+0x1c8
finish
end

--//session 1:
SCOTT@book01p(290,36393)> @ spid
 SID SERIAL# PROCESS SERVER    SPID PID  P_SERIAL# C50
---- ------- ------- --------- ---- --- ---------- --------------------------------------------------
 290   36393 3803    DEDICATED 3805  62          2 alter system kill session '290,36393' immediate;

--//window 1: (注:表示打开新的bash shell终端,与上面区分开来)
$ rlgdb -f -p 3805 -x lcl.gdb
...

--//session 1:
SCOTT@book01p(290,36393)> select count(1) from deptxxx;

--//window 1:按不断c继续:
(gdb) c
Continuing.
kgllkal count 04 -- handle address: 000000006a65df50, mode: 2 kglnaobj address:0x6a65e118:      "aa0b8a5e997323ce2d65f9b7af91ed4f$BUILD$BOOK01P"
0x0000000015363ad0 in kglLock ()
--//出现"aa0b8a5e997323ce2d65f9b7af91ed4f$BUILD$BOOK01P"记下handle address: 000000006a65df50.
--//退出gdb界面.
--//修改lcl.gdb文件;
$ cat lcl.gdb
set $lk  = 0
break kgllkal if ( $rdx==0x000000006a65df50 )
#break kgllkal
commands
silent
printf "kgllkal count %02d -- handle address: %016x, mode: %d ", ++$lk ,$rdx ,$rcx
echo kglnaobj address:
x/s $rdx+0x1c8
finish
end

--//window 1,再次重启gdb检测:
$ rlgdb -f -p 3805 -x lcl.gdb

--//session 2:
SCOTT@book01p(151,22503)> @ spid
 SID  SERIAL# PROCESS SERVER    SPID PID  P_SERIAL# C50
---- -------- ------- --------- ---- --- ---------- --------------------------------------------------
 151    22503 4065    DEDICATED 4067  65          2 alter system kill session '151,22503' immediate;

--//window 2:
--//window 1检测session 1.window 2检测session 2.
$ rlgdb -f -p 4067 -x lcl.gdb

--//session 1:
SCOTT@book01p(290,36393)> select count(1) from deptxxx;
--//挂起!!

--//window 1,按c继续:
Breakpoint 1 at 0x15367e90
(gdb) c
Continuing.
kgllkal count 01 -- handle address: 000000006a65df50, mode: 2 kglnaobj address:0x6a65e118:      "aa0b8a5e997323ce2d65f9b7af91ed4f$BUILD$BOOK01P"
0x0000000015363ad0 in kglLock ()
--//停在kglLock.

--//session 3:
SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLLKREQ,KGLNAOBJ,KGLLKHDL from x$kgllk where KGLLKHDL=hextoraw(upper('000000006a65df50'));
       SID   KGLLKMOD   KGLLKREQ KGLNAOBJ                                 KGLLKHDL
---------- ---------- ---------- ---------------------------------------- ----------------
       290          2          0 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50

--//session 2:
SCOTT@book01p(151,22503)> select count(1) from deptxxx;
--//挂起!!

--//window 2,按c继续:
Breakpoint 1 at 0x15367e90
(gdb) c
Continuing.
kgllkal count 01 -- handle address: 000000006a65df50, mode: 2 kglnaobj address:0x6a65e118:      "aa0b8a5e997323ce2d65f9b7af91ed4f$BUILD$BOOK01P"
0x0000000015363ad0 in kglLock ()
--//停在kglLock.

--//session 3:
SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLLKREQ,KGLNAOBJ,KGLLKHDL from x$kgllk where KGLLKHDL=hextoraw(upper('000000006a65df50'));

       SID   KGLLKMOD   KGLLKREQ KGLNAOBJ                                 KGLLKHDL
---------- ---------- ---------- ---------------------------------------- ----------------
       290          2          0 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
       151          2          0 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
--//现在sid=151,290同时持有00000000701E7A28的library cache lock,mode=2,说明共享模式没有问题.

SYS@book> @ ashtop event,p1,p1hex,p3hex "event='library cache lock'" &10s
no rows selected
--//现在并没有阻塞.出现等待事件在library cache lock.

--//window 1,按c继续:
(gdb) c
Continuing.

--//session 3:
SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLLKREQ,KGLNAOBJ,KGLLKHDL from x$kgllk where KGLLKHDL=hextoraw(upper('000000006a65df50'));

       SID   KGLLKMOD   KGLLKREQ KGLNAOBJ                                 KGLLKHDL
---------- ---------- ---------- ---------------------------------------- ----------------
       290          0          3 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
       151          2          0 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
--//sid=290开始释放library cache lock,但是还没有释放,KGLLKMOD=0,KGLLKREQ=3,请求mode=3.

--//window 1,如果等几十秒,你可以发现如下信息;
(gdb) c
Continuing.

Program received signal SIGUSR2, User defined signal 2.
0x00007f65c72a0fca in semtimedop () at ../sysdeps/unix/syscall-template.S:81
/usr/src/debug/glibc-2.17-c758a686/sysdeps/unix/syscall-template.S:81:3374:beg:0x7f65c72a0fca
--//sesson 1进入休眠模式,注意信号semtimedop.

(gdb) bt 8
#0  0x00007f65c72a0fca in semtimedop () at ../sysdeps/unix/syscall-template.S:81
#1  0x0000000015339805 in sskgpwwait ()
#2  0x0000000015334595 in skgpwwait ()
#3  0x000000001498b09e in ksliwat ()
#4  0x000000001498a4ba in kslwaitctx ()
#5  0x000000000591f453 in kglLockWait ()
#6  0x00000000058f9e65 in kglUpgradeLock ()
#7  0x0000000003ffce7c in kksGetBuildLock ()
(More stack frames follow...)

--//session 3:
SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLLKREQ,KGLNAOBJ,KGLLKHDL from x$kgllk where KGLLKHDL=hextoraw(upper('000000006a65df50'));
       SID   KGLLKMOD   KGLLKREQ KGLNAOBJ                                 KGLLKHDL
---------- ---------- ---------- ---------------------------------------- ----------------
       290          0          3 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
       151          2          0 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50

SYS@book> @ ashtop event,p1,p1hex,p3hex,sid 1=1 &10s

    Total                                                                                                                                                                Distinct Distinct    Distinct
  Seconds     AAS %This   EVENT                                              P1 P1HEX             P3HEX                    SID FIRST_SEEN          LAST_SEEN           Execs Seen  Tstamps Execs Seen1
--------- ------- ------- ------------------------------------------ ---------- ----------------- ----------------- ---------- ------------------- ------------------- ---------- -------- -----------
       10     1.0   37% | library cache lock                         1785061200  000000006A65DF50  0000000000520003        290 2024-08-27 10:00:27 2024-08-27 10:00:36          1       10          10
       10     1.0   37% |                                            1413697536                                            151 2024-08-27 10:00:27 2024-08-27 10:00:36          1       10          10
        5      .5   19% |                                                   100                                            132 2024-08-27 10:00:27 2024-08-27 10:00:36          1        5           5
        2      .2    7% |                                                   100                                            261 2024-08-27 10:00:29 2024-08-27 10:00:34          1        2           2
--//实际上现在sid=290,P3HEX=0000000000520003,也就是释放时是尝试持有mode=3,排他模式.

SYS@book> @ wcx &10s
-- Display ASH Wait Chain Signatures script v0.7 by Tanel Poder ( http://blog.tanelpoder.com )
%This     SECONDS     AAS WAIT_CHAIN                                                               FIRST_SEEN          LAST_SEEN
------ ---------- ------- ------------------------------------------------------------------------ ------------------- -------------------
  38%          10     1.0 -> ,,@=>151,22503,@1=>                                                   2024-08-27 10:00:55 2024-08-27 10:01:04
  38%          10     1.0 -> 151,22503,@1=>290,36393,@1=>library cache lock -> ,,@=>151,22503,@1=> 2024-08-27 10:00:55 2024-08-27 10:01:04
  19%           5      .5 -> ,,@=>132,3926,@1=>                                                    2024-08-27 10:00:57 2024-08-27 10:01:02
   4%           1      .1 -> ,,@=>270,42455,@1=>                                                   2024-08-27 10:01:04 2024-08-27 10:01:04
--//这时等待链条是 151->290->library cache lock->151.阻塞者是sid=290.

--//window 2,按c继续:
(gdb) c
Continuing.
Program received signal SIGUSR2, User defined signal 2.
0x0000000015363ad0 in kglLock ()
--//session 2停在kglLock,到session 2释放library cache lock.

(gdb) c
Continuing.

--//等一小段时间...
Program received signal SIGUSR2, User defined signal 2.
0x00007fd3f17fdfca in semtimedop () at ../sysdeps/unix/syscall-template.S:81
/usr/src/debug/glibc-2.17-c758a686/sysdeps/unix/syscall-template.S:81:3374:beg:0x7fd3f17fdfca
--//sesson 2进入休眠模式,注意信号semtimedop.

--//session 3:
SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLLKREQ,KGLNAOBJ,KGLLKHDL from x$kgllk where KGLLKHDL=hextoraw(upper('000000006a65df50'));

       SID   KGLLKMOD   KGLLKREQ KGLNAOBJ                                 KGLLKHDL
---------- ---------- ---------- ---------------------------------------- ----------------
       151          0          2 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
       290          3          0 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
--//这时sid=290持有mode=3.sid=151的KGLLKREQ=2.
--//为什么这时sid=151的KGLLKREQ=3呢?也许sid=290,持有mode=3,只能请求mode=2.

SYS@book> @ ashtop event,p1,p1hex,p3hex,sid 1=1 &10s
    Total                                                                                                                                                                Distinct Distinct    Distinct
  Seconds     AAS %This   EVENT                                              P1 P1HEX             P3HEX                    SID FIRST_SEEN          LAST_SEEN           Execs Seen  Tstamps Execs Seen1
--------- ------- ------- ------------------------------------------ ---------- ----------------- ----------------- ---------- ------------------- ------------------- ---------- -------- -----------
       10     1.0   45% | library cache lock                         1785061200  000000006A65DF50  0000000000520002        151 2024-08-27 10:05:47 2024-08-27 10:05:56          1       10          10
       10     1.0   45% | library cache lock                         1785061200  000000006A65DF50  0000000000520003        290 2024-08-27 10:05:47 2024-08-27 10:05:56          1       10          10
        1      .1    5% |                                                     3                                              5 2024-08-27 10:05:54 2024-08-27 10:05:54          1        1           1
        1      .1    5% |                                                   100                                            132 2024-08-27 10:05:53 2024-08-27 10:05:53          1        1           1
--//sid=151 看到P3hex=0000000000520002.

--//window 1,按c继续:
(gdb) c
Continuing.

--//session 1:
SCOTT@book01p(290,36393)> select count(1) from deptxxx;
select count(1) from deptxxx
                     *
ERROR at line 1:
ORA-00942: table or view does not exist
--//报错,执行完成!!

--//session 3:
SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLLKREQ,KGLNAOBJ,KGLLKHDL from x$kgllk where KGLLKHDL=hextoraw(upper('000000006a65df50'));
       SID   KGLLKMOD   KGLLKREQ KGLNAOBJ                                 KGLLKHDL
---------- ---------- ---------- ---------------------------------------- ----------------
       151          2          0 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
--//sid=151 现在持有mode=2.

--//window 2,按c继续:
(gdb) c
Continuing.

--//session 2:
SCOTT@book01p(151,22503)> select count(1) from deptxxx;
select count(1) from deptxxx
                     *
ERROR at line 1:
ORA-00942: table or view does not exist
--//报错,执行完成!!

--//session 3:
SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLNAOBJ,KGLLKHDL from x$kgllk where KGLLKHDL=hextoraw(upper('000000006a65df50'));
no rows selected

3.简单总结:
--//实际上问题在于后续的kglLock函数调用,当存在多个持有mode=2的情况,释放lock,请求的mode=3排他模式方式,以前一直以为kgllkal
--//持有的mode=2,不会存在阻塞.问题实际上在于后续的操作.
--//更正:实际上即使一个会话,也是请求mode=3的排他模式.

$ head -4 m2.sh ;tail -4 m2.sh
#! /bin/bash
sleep $(echo $1/500 | bc -l )
sqlplus -s -l scott/book@book01p <<EOF  >/dev/null
set feedback off
/
/
quit
EOF
--//中间20000个/.

$ zzdate ; seq 10 | xargs -IQ -P 5 ./m2.sh Q ;zzdate
trunc(sysdate)+10/24+43/1440+01/86400 == 2024/08/27 10:43:01

SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLLKREQ,KGLNAOBJ,KGLLKHDL from x$kgllk where KGLLKHDL=hextoraw(upper('000000006a65df50'));

       SID   KGLLKMOD   KGLLKREQ KGLNAOBJ                                 KGLLKHDL
---------- ---------- ---------- ---------------------------------------- ----------------
       145          0          2 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
       277          0          2 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
       397          0          2 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
        24          0          2 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
        30          3          0 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50

SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLLKREQ,KGLNAOBJ,KGLLKHDL from x$kgllk where KGLLKHDL=hextoraw(upper('000000006a65df50'));

       SID   KGLLKMOD   KGLLKREQ KGLNAOBJ                                 KGLLKHDL
---------- ---------- ---------- ---------------------------------------- ----------------
        17          0          2 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
        24          0          2 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
       397          0          2 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
       145          0          3 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50
       277          2          0 aa0b8a5e997323ce2d65f9b7af91ed4f         000000006A65DF50


标签:10,27,--,lock,cache,20240827,2024,KGLLKHDL,----------
From: https://www.cnblogs.com/lfree/p/18391463

相关文章

  • [20240828]分析为什么出现library cache lock等待事件5.txt
    [20240828]分析为什么出现librarycachelock等待事件5.txt--//前几天测试遇到的问题,假如表不存在的情况下,如果密集执行这类sql语句,不理解为什么出现librarycachelock等待事件.--//验证如果有1个会话,是否会持有mode=3的情况出现.--//上午使用gdb设置断点来验证,这次直接密集......
  • ReentrantReadWriteLock源码剖析
    ReentrantReadWriteLock源码剖析测试案例:publicclassReentrantReadWriteLockDemo{privatestaticReentrantReadWriteLockreadWriteLock=newReentrantReadWriteLock();privatestaticLockreadLock=readWriteLock.readLock();//定义读锁privatesta......
  • ReentrantLock源码剖析
    ReentrantLock源码剖析测试案例:publicclassReentrantLockDemo{//ReentrantLocklock=newReentrantLock();//默认是非公平锁//ReentrantLocklock=newReentrantLock(true);//true:公平锁,false:非公平锁publicstaticvoidmain(String[]args){......
  • Clocking Wizard IP使用
    简介本章节主要针对XILINX的PLLIP做详细介绍,并通过AXILite总线对时钟在线配置。VIVADO界面选择clockingwizardIP具体介绍如下:PLLIP介绍clockingoption界面1、MMCM和PLL选择;        (1)PLL:为锁相回路或锁相环,用来统一整合时钟信号,使高频器件正常工作,如内存......
  • python并发与并行(三) ———— 利用Lock防止多个线程争用同一份数据
    了解到全局解释器锁(GIL)的效果之后,许多Python新手可能觉得没必要继续在代码里使用互斥锁(mutual-exclusionlock,mutex)了。既然GIL让Python线程没办法平行地运行在多个CPU核心上,那是不是就意味着它同时还会自动保护程序里面的数据结构,让我们不需要再加锁了?在列表与字典等结构上面测试......
  • zdppy_cache缓存框架升级,支持用户级别的缓存隔离,支持超级管理员管理普通用户的缓存
    启动服务importzdppy_apiasapiimportzdppy_cachekey1="admin"key2="admin"app=api.Api(routes=[*zdppy_cache.zdppy_api.cache(key1,key2,api)])if__name__=='__main__':importzdppy_uvicornzdppy_uvico......
  • 20240827_102249 python 认识csv格式
    目标认识csv格式制作一个csv文件示例......
  • 20240827_102109 python 字符流遍历得到每一行的数据
    需求python字符流遍历得到每一行的数据读取文件的内容每隔一秒钟,显示一行内容示例1示例2......
  • lock 为什么要传入一个object对象
    lock为什么要传入一个object对象publicclassSingleton{publicstaticSingletoninstance;publicstaticreadonlyobjectsingletonLock=newobject();privateSingleton(){}publicstaticSingletonGetInstance(){if(instance=......
  • 数据存储“取经路”,HBlock轻松“渡”!
    近日,天翼云联合权威科技媒体InfoQ举办了以“新存储,更轻量”为主题的线上技术分享会。天翼云存储产品线总监武志民讲解了HBlock的创新设计和技术。高性能·高可用·高可靠自研创新解决存储技术难题 天翼云自主研发的业内首款存储资源盘活系统HBlock能够与底层基础设施完全解耦,......