南大通用GBase 8a集群查看gnode计算节点某张表的锁

GBase 8a数据库集群,通过锁机制实现并行访问控制,在集群管理层和数据计算层都有各自的锁,本文介绍在计算节点查看锁的方法。

使用方法

show table locks 库名.表名

比如show table locks testdb.t_n1。

使用样例1

使用样例2

gbase> show table locks t1;
Empty set (Elapsed: 00:00:00.00)

gbase> lock table t1 write;\
ERROR 1235 (42000): This version of GBase doesn't yet support 'lock Table when use transaction mode'
gbase> set autocommit=0;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)

gbase> select * from t1;
+------+-----------+
| id   | name      |
+------+-----------+
|    1 | First     |
|    2 | 第二名    |
+------+-----------+
2 rows in set (Elapsed: 00:00:00.00)

gbase> insert into t1 values(3,'333');
Query OK, 1 row affected (Elapsed: 00:00:00.00)

gbase> show table locks t1;
+--------+-----------+-----------+------------+-------------------+---------------+--------------------+
| DB     | TableName | ReadLocks | WriteLocks | ReceiveWriteLocks | ExcusiveLocks | ExcusiveWriteLocks |
+--------+-----------+-----------+------------+-------------------+---------------+--------------------+
| testdb | t1        |         1 |          1 |                 0 |             0 |                  0 |
+--------+-----------+-----------+------------+-------------------+---------------+--------------------+
1 row in set (Elapsed: 00:00:00.00)

其中
ReadLocks 读锁
WriteLocks 写锁
ReceiveWriteLocks 拿到的写锁
ExcusiveLocks 排他锁,独占锁
ExcusiveWriteLocks 排它写锁

拿到锁对应的session

通过gbaseadmin 的debug命令,获得锁的详情。

gbaseadmin -h10.0.2.201  -P5050 debug

然后从system.log里面看到输出。请关注最后的总结部分。

Memory status:
Non-mmapped space allocated from system: 658505728
Number of free chunks:                   0
Number of fastbin blocks:                0
Number of mmapped regions:               0
Space in mmapped regions:                0
Maximum total allocated space:           0
Space available in freed fastbin blocks: 471488312
Total allocated space:                   181741768
Total free space:                        5275648
Top-most, releasable space:              0
Estimated memory (with thread stack):    661127168



Events status:
LLA = Last Locked At  LUA = Last Unlocked At
WOC = Waiting On Condition  DL = Data Locked

Event scheduler status:
State      : INITIALIZED
Thread id  : 0
LLA        : n/a:0
LUA        : n/a:0
WOC        : NO
Workers    : 0
Executed   : 0
Data locked: NO

Event queue status:
Element count   : 0
Data locked     : NO
Attempting lock : NO
LLA             : init_queue:132
LUA             : init_queue:142
WOC             : NO
Next activation : never

Status information:

Current dir: /opt/gnode/userdata/gbase/
Running threads: 10  Stack size: 262144
Current locks:
lock: 0x1104c410:

lock: 0x1020e5b0:

lock: 0x7eaa310: write
write     : 0x1c9f1170 (127151:6);

lock: 0x3ebfb68:

lock: 0x3ed6368:

lock: 0x3e1fb68:

lock: 0x3c68b68:

lock: 0x3c6d968:

lock: 0x3b6e168:

lock: 0x3c6ac68:

lock: 0x3b6d768:

lock: 0x3c2de68:

lock: 0x3c2cc68:

lock: 0x3c1cf68:

lock: 0x45df368:

lock: 0x3b51968:

lock: 0x4e69368:

lock: 0x3c01568:

lock: 0x3b50e68:

lock: 0x3b4b968:

lock: 0x4e66b68:


Key caches:
default
Buffer_size:       8384512
Block_size:           1024
Division_limit:        100
Age_limit:             300
blocks used:             4
not flushed:             0
w_requests:              0
writes:                  0
r_requests:             30
reads:                   4


handler status:
read_key:           14
read_next:           0
read_rnd             0
read_first:          3
write:             306
delete               0
update:              0

Table status:
Opened tables:     131521
Open tables:           24
Open files:            36
Open streams:           0

Alarm status:
Active alarms:   0
Max used alarms: 7
Next alarm time: 0

Thread database.table_name          Locked/Waiting        Lock_type

127151  testdb.t1_n1                Locked - write        High priority write lock




Begin safemalloc memory dump:

End safemalloc memory dump.

如上总结部分如下。 线程sessionID, 库表,锁,锁类型。

Thread database.table_name          Locked/Waiting        Lock_type

127151  testdb.t1_n1                Locked - write        High priority write lock

参考