暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

OB为什么行锁信息查不到

原创 范计杰 2024-08-20
260

[[toc]]

概述

__all_virtual_trans_lock_stat记录了OB的行锁持有信息,但有时存在行锁,__all_virtual_trans_lock_stat查不到相关记录,为什么?

推测,OB行锁没有单独的数据结构,记录在行的头部,猜测__all_virtual_trans_lock_stat数据来源于memstore中,转储后memstore未提交事务同样会转储到磁盘sstable中,释放memstore导致查不到。

验证

1、检查timeout参数,确认测试期间,事务不会超时中断

obclient [SYS]> show variables like '%timeout%'
    -> ;
+---------------------+------------------+
| VARIABLE_NAME       | VALUE            |
+---------------------+------------------+
| connect_timeout     | 10               |
| interactive_timeout | 28800            |
| net_read_timeout    | 30               |
| net_write_timeout   | 60               |
| ob_pl_block_timeout | 3216672000000000 |
| ob_query_timeout    | 7200000000       |
| ob_trx_idle_timeout | 7200000000       |
| ob_trx_lock_timeout | 7200000000       |
| ob_trx_timeout      | 7200000000       |
| wait_timeout        | 259200           |
+---------------------+------------------+
10 rows in set (0.002 sec)

2、更新5条记录,不提交,模拟行锁

obclient [SYS]> update test.rtest1 set c=c where id<=5;
Query OK, 5 rows affected (0.004 sec)
Rows matched: 5  Changed: 5  Warnings: 0

MySQL [oceanbase]> select * from __all_virtual_trans_lock_stat;
+-----------+-------------------------------------------------------------------------------------------+---------------+----------+----------------------------------------------------+------------------+------------------------------------------------------------------+------------+----------------------+----------------------------+----------------------------+-----------------+
| tenant_id | trans_id                                                                                  | svr_ip        | svr_port | partition                                          | table_id         | rowkey                                                           | session_id | proxy_id             | ctx_create_time            | expired_time               | row_lock_addr   |
+-----------+-------------------------------------------------------------------------------------------+---------------+----------+----------------------------------------------------+------------------+------------------------------------------------------------------+------------+----------------------+----------------------------+----------------------------+-----------------+
|      1001 | {hash:14993881902589449425, inc:255032832, addr:"192.168.56.36:2882", t:1706771972977340} | 192.168.56.36 |     2882 | {tid:1100611139453972, partition_id:0, part_cnt:0} | 1100611139453972 | table_id=1100611139453972 rowkey_object=[{"BIGINT UNSIGNED":1}]  | 3221711608 | "192.168.56.36:2883" | 2024-02-01 15:19:32.977340 | 2024-02-01 17:19:32.975732 | 139867027327560 |
|      1001 | {hash:14993881902589449425, inc:255032832, addr:"192.168.56.36:2882", t:1706771972977340} | 192.168.56.36 |     2882 | {tid:1100611139453972, partition_id:0, part_cnt:0} | 1100611139453972 | table_id=1100611139453972 rowkey_object=[{"BIGINT UNSIGNED":2}]  | 3221711608 | "192.168.56.36:2883" | 2024-02-01 15:19:32.977340 | 2024-02-01 17:19:32.975732 | 139867027388776 |
|      1001 | {hash:14993881902589449425, inc:255032832, addr:"192.168.56.36:2882", t:1706771972977340} | 192.168.56.36 |     2882 | {tid:1100611139453972, partition_id:0, part_cnt:0} | 1100611139453972 | table_id=1100611139453972 rowkey_object=[{"BIGINT UNSIGNED":3}]  | 3221711608 | "192.168.56.36:2883" | 2024-02-01 15:19:32.977340 | 2024-02-01 17:19:32.975732 | 139867027389216 |
|      1001 | {hash:14993881902589449425, inc:255032832, addr:"192.168.56.36:2882", t:1706771972977340} | 192.168.56.36 |     2882 | {tid:1100611139453972, partition_id:0, part_cnt:0} | 1100611139453972 | table_id=1100611139453972 rowkey_object=[{"BIGINT UNSIGNED":4}]  | 3221711608 | "192.168.56.36:2883" | 2024-02-01 15:19:32.977340 | 2024-02-01 17:19:32.975732 | 139867027389656 |
|      1001 | {hash:14993881902589449425, inc:255032832, addr:"192.168.56.36:2882", t:1706771972977340} | 192.168.56.36 |     2882 | {tid:1100611139453972, partition_id:0, part_cnt:0} | 1100611139453972 | table_id=1100611139453972 rowkey_object=[{"BIGINT UNSIGNED":5}]  | 3221711608 | "192.168.56.36:2883" | 2024-02-01 15:19:32.977340 | 2024-02-01 17:19:32.975732 | 139867027390096 |
+-----------+-------------------------------------------------------------------------------------------+---------------+----------+----------------------------------------------------+------------------+------------------------------------------------------------------+------------+----------------------+----------------------------+----------------------------+-----------------+
5 rows in set (0.040 sec)


3、发起合并(会进行转储),等待一段时间,转储完成

MySQL [oceanbase]> alter system minor freeze;
Query OK, 0 rows affected (0.476 sec)


4、检查__all_virtual_trans_lock_stat已查不到行锁记录

MySQL [oceanbase]> select * from __all_virtual_trans_lock_stat;
Empty set (0.041 sec)

5、开启另一session update会被阻塞,被刚刚更新未提交的事务阻塞

session 2 update waiting
obclient [SYS]> update test.rtest1 set c=c where id<=5;   ---waiting

---__all_virtual_trans_lock_stat查不到记录
MySQL [oceanbase]> select * from __all_virtual_trans_lock_stat;
Empty set (0.040 sec)

6、通过__all_virtual_lock_wait_stat视图可以查到行锁等待信息,也能查不到blocking session,但查不到行锁记录

MySQL [oceanbase]> select * from __all_virtual_lock_wait_stat\G
*************************** 1. row ***************************
          svr_ip: 192.168.56.36
        svr_port: 2882
        table_id: 1100611139453972
          rowkey: {"BIGINT UNSIGNED":1}
            addr: 139798389326208
       need_wait: 1
         recv_ts: 1706772177841656
         lock_ts: 1706772249664155
     abs_timeout: 1706779377741656
  try_lock_times: 8
 time_after_recv: 79238804
      session_id: 3221720776
block_session_id: 3221720776
            type: 0
       lock_mode: 0
total_update_cnt: -1
1 row in set (0.028 sec)

MySQL [oceanbase]> select * from __all_virtual_trans_lock_stat;
Empty set (0.040 sec)

MySQL [oceanbase]>
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论