内容纲要
概要描述
本文主要介绍argodb锁如何查看锁并解锁。
# host为 TDDMS Webserver 节点的ip
# 获取当前集群中事务信息,默认获取活跃事务:
curl -XGET ':/bulk_transaction?[pretty]'
# 强制终止一个活跃事务:
curl -XDELETE ":/bulk_transaction/id?[pretty]"
详细介绍
1、创建测试表
DROP TABLE IF EXISTS EMP_HOLO;
CREATE TABLE EMP_HOLO(
EMPNO int,
ENAME string,
JOB string,
MGR INT,
HIREDATE DATE,
SAL INT,
COMM INT,
DEPTNO INT
)CLUSTERED BY (empno) INTO 3 BUCKETS
STORED AS HOLODESK;
INSERT INTO EMP_HOLO VALUES (7369,'SMITH','CLERK',7902,tdh_todate('17-12-1980','dd-mm-yyyy'),800,NULL,20);
2、执行锁语句,delete操作
CREATE SEQUENCE test_seq
INCREMENT BY 1
START WITH 1
NOMAXVALUE
NOMINVALUE
NOCYCLE
CACHE 20;
set transaction.type=holodesk;
BEGIN
begin transaction;
--前后分别通过sequence值来标记执行顺序
SELECT test_seq.NEXTVAL FROM system.dual;
--Action
DELETE FROM EMP_HOLO WHERE ENAME ='SMITH';
--通过睡眠函数控制执行顺序
dbms_lock.sleep(600);
--前后分别通过sequence值来标记执行顺序
SELECT test_seq.NEXTVAL FROM system.dual;
commit;
END
执行上述plsql块之后,一直处于运行状态。
3、检查活跃事务信息:
[root@argodb1~]$ curl -XGET '172.22.23.1:4567/bulk_transaction?pretty'
{
"log_id" : 1676003325746,
"code" : 0,
"msg" : "ok",
"transaction_ids" : [ 1493 ],
"status" : [ "kActiveBulkTransaction" ],
"bulk_transaction_descriptions" : [ {
"id" : 1493,
"status" : "kActiveBulkTransaction",
"read_write_tables" : [ {
"table_id" : 24,
"bulk_loads" : [ {
"bulk_load_id" : 1478,
"section_names" : [ "default.emp_holo_3b71d992-e5b5-4bc2-940e-63233830e8cf" ]
} ],
"bulk_reads" : [ {
"section_name" : "default.emp_holo_3b71d992-e5b5-4bc2-940e-63233830e8cf",
"read_num" : 2
} ],
"schema_version" : 3
} ],
"policy_version" : 0,
"retain_si_read" : false,
"gcable" : false,
"creator" : {
"address" : "172.22.23.1:37463",
"log_id" : 1676007619045
}
} ]
}
这个因为是手动开启事务,所以在begin transaction的时候事务ID就已经确定了
4、手动终止事务
a. 从前面的结果可以看到 "status" : [ "kActiveBulkTransaction" ]
,代表 ACTIVE 状态的话,可以通过下面的方式终止:
强行结束事务kActive状态事务
# IP和PORT按照tddms webui
# curl -XDELETE "IP:PORT/bulk_transaction/"
curl -XDELETE "172.22.23.1:4567/bulk_transaction/1493"
{"log_id": 1676003325954,"code": 0,"msg": "bulk transaction:1494 is aborted"}
b. 如果事务状态是 "status" : [ "kWaitingBulkTransaction" ]
,代表 WAITING 状态的话,可以使用下面命令强行终止
强行结束事务kwaitting状态事务
# IP和PORT按照tddms webui
# curl -XPOST "IP:PORT/bulk_transaction/terminate/"
curl -XPOST "172.22.23.1:4567/bulk_transaction/terminate/123788"
如果报错
NEGOTIATED_ROLE_NOT_EXIST
,需要加上-u shiva:shiva