diff --git a/mittest/mtlenv/tablelock/test_lock_memtable.cpp b/mittest/mtlenv/tablelock/test_lock_memtable.cpp index 72c11b7c0d..ce5303c25a 100644 --- a/mittest/mtlenv/tablelock/test_lock_memtable.cpp +++ b/mittest/mtlenv/tablelock/test_lock_memtable.cpp @@ -135,7 +135,7 @@ TEST_F(TestLockMemtable, lock) ObOBJLock *obj_lock = NULL; share::SCN min_commited_scn; share::SCN flushed_scn; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; MyTxCtx default_ctx; ObStoreCtx store_ctx; @@ -163,7 +163,7 @@ TEST_F(TestLockMemtable, lock) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); // 1.4 check lock at lock map LOG_INFO("TestLockMemtable::lock 1.4"); @@ -181,7 +181,7 @@ TEST_F(TestLockMemtable, lock) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); // 1.7 remove lock op at memctx. LOG_INFO("TestLockMemtable::lock 1.7"); @@ -191,7 +191,7 @@ TEST_F(TestLockMemtable, lock) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, false); // 2.1 lock @@ -210,7 +210,7 @@ TEST_F(TestLockMemtable, lock) DEFAULT_OUT_TRANS_LOCK_OP.lock_mode_, DEFAULT_OUT_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); // 2.3 unlock not complete lock LOG_INFO("TestLockMemtable::lock 2.3"); @@ -283,7 +283,7 @@ TEST_F(TestLockMemtable, lock) TEST_F(TestLockMemtable, replay) { LOG_INFO("TestLockMemtable::replay"); - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; int ret = OB_SUCCESS; bool is_try_lock = true; int64_t expired_time = ObClockGenerator::getClock() + 1 * 1000 * 1000; @@ -333,7 +333,7 @@ TEST_F(TestLockMemtable, replay) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); // 1.3 check lock at lock map LOG_INFO("TestLockMemtable::replay 1.3"); @@ -351,7 +351,7 @@ TEST_F(TestLockMemtable, replay) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); // 1.6 remove lock op at memctx. LOG_INFO("TestLockMemtable::replay 1.6"); @@ -361,7 +361,7 @@ TEST_F(TestLockMemtable, replay) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, false); // 2. REPLAY LOCK // 2.1 replay lock @@ -378,7 +378,7 @@ TEST_F(TestLockMemtable, replay) DEFAULT_OUT_TRANS_LOCK_OP.lock_mode_, DEFAULT_OUT_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); // 2.3 unlock not complete lock LOG_INFO("TestLockMemtable::replay 2.3"); @@ -540,7 +540,7 @@ TEST_F(TestLockMemtable, recover) TEST_F(TestLockMemtable, pre_check_lock) { LOG_INFO("TestLockMemtable::pre_check_lock"); - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; int ret = OB_SUCCESS; bool is_try_lock = true; bool lock_exist = false; @@ -595,7 +595,7 @@ TEST_F(TestLockMemtable, pre_check_lock) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); // 1.8 remove lock op at memctx. LOG_INFO("TestLockMemtable::pre_check_lock 1.8"); @@ -605,7 +605,7 @@ TEST_F(TestLockMemtable, pre_check_lock) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, false); } @@ -724,7 +724,7 @@ TEST_F(TestLockMemtable, out_trans_multi_source) share::SCN commit_version = share::SCN::min_scn(); share::SCN commit_scn = share::SCN::min_scn(); ObMemtableCtx *mem_ctx = NULL; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObTableLockOp lock_op = DEFAULT_OUT_TRANS_LOCK_OP; ObTableLockOp unlock_op = DEFAULT_OUT_TRANS_UNLOCK_OP; unlock_op.create_trans_id_ = TRANS_ID2; @@ -752,7 +752,7 @@ TEST_F(TestLockMemtable, out_trans_multi_source) lock_op.lock_mode_, lock_op.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); // 1.3 check exist at multi source @@ -772,7 +772,7 @@ TEST_F(TestLockMemtable, out_trans_multi_source) lock_op.lock_mode_, lock_op.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); // 2.3 check exist at multi source @@ -795,7 +795,7 @@ TEST_F(TestLockMemtable, out_trans_multi_source) lock_op.lock_mode_, lock_op.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); // 3.2 notify ON_COMMIT/ON_ABORT @@ -807,7 +807,7 @@ TEST_F(TestLockMemtable, out_trans_multi_source) lock_op.lock_mode_, lock_op.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); ret = default_ctx.tx_ctx_.notify_data_source_(NotifyType::ON_ABORT, scn, is_replay, mds_array); @@ -817,7 +817,7 @@ TEST_F(TestLockMemtable, out_trans_multi_source) lock_op.lock_mode_, lock_op.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); @@ -832,7 +832,7 @@ TEST_F(TestLockMemtable, out_trans_multi_source) lock_op.lock_mode_, lock_op.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, true); @@ -997,7 +997,7 @@ TEST_F(TestLockMemtable, test_lock_retry) bool lock_exist = false; share::SCN min_commited_scn; share::SCN flushed_scn; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObTableLockOp lock_op = DEFAULT_OUT_TRANS_LOCK_OP; min_commited_scn.set_min(); @@ -1037,7 +1037,7 @@ TEST_F(TestLockMemtable, test_lock_retry) DEFAULT_OUT_TRANS_LOCK_OP.lock_mode_, DEFAULT_OUT_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, false); // 3.3 check lock at part ctx @@ -1073,7 +1073,7 @@ TEST_F(TestLockMemtable, test_lock_retry) DEFAULT_OUT_TRANS_LOCK_OP.lock_mode_, DEFAULT_OUT_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); // 6.3 check lock at part ctx @@ -1157,7 +1157,7 @@ TEST_F(TestLockMemtable, test_lock_retry_lock_conflict) bool lock_exist = false; share::SCN min_commited_scn; share::SCN flushed_scn; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObTableLockOp lock_first = DEFAULT_OUT_TRANS_LOCK_OP; // RX, owner 0 ObTableLockOp lock_second = DEFAULT_OUT_TRANS_LOCK_OP; @@ -1257,7 +1257,7 @@ TEST_F(TestLockMemtable, test_lock_retry_lock_conflict) lock_second.lock_mode_, lock_second.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); // 6. clean diff --git a/mittest/mtlenv/tablelock/test_lock_table_callback.cpp b/mittest/mtlenv/tablelock/test_lock_table_callback.cpp index 7e4ad26834..18ebef1a40 100644 --- a/mittest/mtlenv/tablelock/test_lock_table_callback.cpp +++ b/mittest/mtlenv/tablelock/test_lock_table_callback.cpp @@ -133,7 +133,7 @@ TEST_F(TestLockTableCallback, callback) { int ret = OB_SUCCESS; bool lock_exist = false; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; const bool for_replay = false; ObIMemtable *memtable = nullptr; ObOBJLockCallback *cb = nullptr; @@ -155,7 +155,7 @@ TEST_F(TestLockTableCallback, callback) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); ret = cb->trans_commit(); ASSERT_EQ(OB_SUCCESS, ret); @@ -164,7 +164,7 @@ TEST_F(TestLockTableCallback, callback) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, false); // 3.2 intrans abort LOG_INFO("TestLockTableCallback::callback 3.2"); @@ -174,7 +174,7 @@ TEST_F(TestLockTableCallback, callback) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); ret = cb->trans_abort(); ASSERT_EQ(OB_SUCCESS, ret); @@ -183,7 +183,7 @@ TEST_F(TestLockTableCallback, callback) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, false); // 3.3 intrans stmt abort LOG_INFO("TestLockTableCallback::callback 3.3"); @@ -193,7 +193,7 @@ TEST_F(TestLockTableCallback, callback) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, true); ret = cb->rollback_callback(); ASSERT_EQ(OB_SUCCESS, ret); @@ -202,7 +202,7 @@ TEST_F(TestLockTableCallback, callback) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(lock_exist, false); } diff --git a/mittest/mtlenv/tablelock/test_mem_ctx_table_lock.cpp b/mittest/mtlenv/tablelock/test_mem_ctx_table_lock.cpp index adac7c948a..4669f2b838 100644 --- a/mittest/mtlenv/tablelock/test_mem_ctx_table_lock.cpp +++ b/mittest/mtlenv/tablelock/test_mem_ctx_table_lock.cpp @@ -111,7 +111,7 @@ TEST_F(TestMemCtxTableLock, add_lock_record) LOG_INFO("TestMemCtxTableLock::add_lock_record"); int ret = OB_SUCCESS; bool lock_exist = false; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObMemCtxLockOpLinkNode *lock_op_node = nullptr; // 1. IN TRANS LOCK // 1.1 add lock record @@ -126,7 +126,7 @@ TEST_F(TestMemCtxTableLock, add_lock_record) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, true); // 2. OUT TRANS LOCK @@ -142,7 +142,7 @@ TEST_F(TestMemCtxTableLock, add_lock_record) DEFAULT_OUT_TRANS_LOCK_OP.lock_mode_, DEFAULT_OUT_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, true); // 3. REMOVE CHECK @@ -154,7 +154,7 @@ TEST_F(TestMemCtxTableLock, add_lock_record) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); // 3.2 out trans lock remove test @@ -165,7 +165,7 @@ TEST_F(TestMemCtxTableLock, add_lock_record) DEFAULT_OUT_TRANS_LOCK_OP.lock_mode_, DEFAULT_OUT_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); @@ -180,7 +180,7 @@ TEST_F(TestMemCtxTableLock, add_lock_record) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, true); // 4.2 remove lock record @@ -191,7 +191,7 @@ TEST_F(TestMemCtxTableLock, add_lock_record) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); } @@ -201,7 +201,7 @@ TEST_F(TestMemCtxTableLock, clear_table_lock) LOG_INFO("TestMemCtxTableLock::clear_table_lock"); int ret = OB_SUCCESS; bool lock_exist = false; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObMemCtxLockOpLinkNode *lock_op_node = nullptr; bool is_committed = false; share::SCN commit_version; @@ -227,7 +227,7 @@ TEST_F(TestMemCtxTableLock, clear_table_lock) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); // 2.2 out trans lock record @@ -242,7 +242,7 @@ TEST_F(TestMemCtxTableLock, clear_table_lock) DEFAULT_OUT_TRANS_LOCK_OP.lock_mode_, DEFAULT_OUT_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); // 2.3 out trans unlock record @@ -257,7 +257,7 @@ TEST_F(TestMemCtxTableLock, clear_table_lock) DEFAULT_OUT_TRANS_UNLOCK_OP.lock_mode_, DEFAULT_OUT_TRANS_UNLOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); @@ -273,7 +273,7 @@ TEST_F(TestMemCtxTableLock, clear_table_lock) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); } @@ -284,7 +284,7 @@ TEST_F(TestMemCtxTableLock, rollback_table_lock) int ret = OB_SUCCESS; bool lock_exist = false; ObMemCtxLockOpLinkNode *lock_op_node = nullptr; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; // 1.1 add lock record LOG_INFO("TestMemCtxTableLock::rollback_table_lock 1.1"); ObTableLockOp lock_op1 = DEFAULT_IN_TRANS_LOCK_OP; @@ -304,7 +304,7 @@ TEST_F(TestMemCtxTableLock, rollback_table_lock) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, true); ret = mem_ctx_.check_lock_exist(DEFAULT_OUT_TRANS_LOCK_OP.lock_id_, @@ -312,7 +312,7 @@ TEST_F(TestMemCtxTableLock, rollback_table_lock) DEFAULT_OUT_TRANS_LOCK_OP.lock_mode_, DEFAULT_OUT_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, true); // 1.3 rollback @@ -326,7 +326,7 @@ TEST_F(TestMemCtxTableLock, rollback_table_lock) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, true); ret = mem_ctx_.check_lock_exist(DEFAULT_OUT_TRANS_LOCK_OP.lock_id_, @@ -334,7 +334,7 @@ TEST_F(TestMemCtxTableLock, rollback_table_lock) DEFAULT_OUT_TRANS_LOCK_OP.lock_mode_, DEFAULT_OUT_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); // 1.4 rollback again @@ -347,7 +347,7 @@ TEST_F(TestMemCtxTableLock, rollback_table_lock) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); } @@ -355,7 +355,7 @@ TEST_F(TestMemCtxTableLock, rollback_table_lock) TEST_F(TestMemCtxTableLock, check_lock_need_replay) { LOG_INFO("TestMemCtxTableLock::check_lock_need_replay"); - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; int ret = OB_SUCCESS; bool lock_exist = false; share::SCN scn; @@ -406,7 +406,7 @@ TEST_F(TestMemCtxTableLock, check_lock_need_replay) DEFAULT_IN_TRANS_LOCK_OP.lock_mode_, DEFAULT_IN_TRANS_LOCK_OP.op_type_, lock_exist, - lock_mode_in_same_trans); + lock_mode_cnt_in_same_trans); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(lock_exist, false); } diff --git a/mittest/mtlenv/tablelock/test_obj_lock.cpp b/mittest/mtlenv/tablelock/test_obj_lock.cpp index 3dccdfcf41..cad998f255 100644 --- a/mittest/mtlenv/tablelock/test_obj_lock.cpp +++ b/mittest/mtlenv/tablelock/test_obj_lock.cpp @@ -110,7 +110,7 @@ TEST_F(TestObjLock, in_trans_lock) bool is_try_lock = true; int64_t expired_time = 0; ObTxIDSet conflict_tx_set; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; // int64_t expired_time = ObClockGenerator::getClock() + 1000; @@ -126,7 +126,7 @@ TEST_F(TestObjLock, in_trans_lock) ret = obj_lock_.lock(param, store_ctx, DEFAULT_IN_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); @@ -140,7 +140,7 @@ TEST_F(TestObjLock, in_trans_lock) ret = obj_lock_.lock(param, store_ctx, DEFAULT_IN_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); @@ -153,7 +153,7 @@ TEST_F(TestObjLock, in_trans_lock) ret = obj_lock_.lock(param, store_ctx, DEFAULT_IN_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); @@ -182,7 +182,7 @@ TEST_F(TestObjLock, out_trans_lock) share::SCN min_commited_scn; share::SCN flushed_scn; ObTxIDSet conflict_tx_set; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObLockParam param; MyTxCtx default_ctx; @@ -200,7 +200,7 @@ TEST_F(TestObjLock, out_trans_lock) ret = obj_lock_.lock(param, store_ctx, DEFAULT_OUT_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); @@ -246,7 +246,7 @@ TEST_F(TestObjLock, out_trans_lock) ret = obj_lock_.lock(param, store_ctx, DEFAULT_OUT_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); @@ -302,7 +302,7 @@ TEST_F(TestObjLock, out_trans_unlock_twice) share::SCN commit_version; share::SCN commit_scn; ObTxIDSet conflict_tx_set; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObLockParam param; MyTxCtx default_ctx; @@ -325,7 +325,7 @@ TEST_F(TestObjLock, out_trans_unlock_twice) ret = obj_lock_.lock(param, store_ctx, DEFAULT_OUT_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); @@ -512,7 +512,7 @@ TEST_F(TestObjLock, lock_conflict_in_in) int64_t expired_time = 0; ObTxIDSet conflict_tx_set; int64_t conflict_modes; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObLockParam param; MyTxCtx default_ctx; @@ -533,14 +533,14 @@ TEST_F(TestObjLock, lock_conflict_in_in) ret = obj_lock_.lock(param, store_ctx, DEFAULT_IN_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); ret = obj_lock_.lock(param, store_ctx, DEFAULT_CONFLICT_OUT_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_TRY_LOCK_ROW_CONFLICT, ret); @@ -552,7 +552,7 @@ TEST_F(TestObjLock, lock_conflict_in_in) ret = obj_lock_.lock(param, store_ctx, DEFAULT_CONFLICT_OUT_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); if (DEFAULT_CONFLICT_OUT_TRANS_LOCK_OP.is_dml_lock_op()) { @@ -579,26 +579,26 @@ TEST_F(TestObjLock, lock_conflict_in_in) lock_second.create_trans_id_ = TRANS_ID2; for (int first = 0; first < TABLE_LOCK_MODE_COUNT; first++) { // lock the first lock - printf("first lock index:%d\n", first); - lock_first.lock_mode_ = LOCK_MODE_ARRAY[first]; + lock_first.lock_mode_ = get_lock_mode_by_index(first); + printf("first lock index: %d, mode: %d\n", first, lock_first.lock_mode_); ret = obj_lock_.lock(param, store_ctx, lock_first, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); // lock the second lock and check conflict for (int second = 0; second < TABLE_LOCK_MODE_COUNT; second++) { - printf("second lock index:%d\n", second); - lock_second.lock_mode_ = LOCK_MODE_ARRAY[second]; + lock_second.lock_mode_ = get_lock_mode_by_index(second); + printf("second lock index: %d, mode: %d\n", second, lock_second.lock_mode_); is_conflict = !request_lock(lock_first.lock_mode_, lock_second.lock_mode_, conflict_modes); ret = obj_lock_.lock(param, store_ctx2, lock_second, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); if (is_conflict) { @@ -627,7 +627,7 @@ TEST_F(TestObjLock, lock_conflict_in_out) int64_t expired_time = 0; ObTxIDSet conflict_tx_set; int64_t conflict_modes = 0; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObLockParam param; MyTxCtx default_ctx; @@ -655,26 +655,26 @@ TEST_F(TestObjLock, lock_conflict_in_out) param.expired_time_ = expired_time; for (int first = 0; first < TABLE_LOCK_MODE_COUNT; first++) { // lock the first lock - printf("first lock index:%d\n", first); - lock_first.lock_mode_ = LOCK_MODE_ARRAY[first]; + lock_first.lock_mode_ = get_lock_mode_by_index(first); + printf("first lock index: %d, mode: %d\n", first, lock_first.lock_mode_); ret = obj_lock_.lock(param, store_ctx, lock_first, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); // lock the second lock and check conflict for (int second = 0; second < TABLE_LOCK_MODE_COUNT; second++) { - printf("second lock index:%d\n", second); - lock_second.lock_mode_ = LOCK_MODE_ARRAY[second]; + lock_second.lock_mode_ = get_lock_mode_by_index(second); + printf("second lock index: %d, mode: %d\n", second, lock_second.lock_mode_); is_conflict = !request_lock(lock_first.lock_mode_, lock_second.lock_mode_, conflict_modes); ret = obj_lock_.lock(param, store_ctx2, lock_second, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); if (is_conflict) { @@ -702,7 +702,7 @@ TEST_F(TestObjLock, lock_conflict_out_in) int64_t expired_time = 0; ObTxIDSet conflict_tx_set; int64_t conflict_modes = 0; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObLockParam param; MyTxCtx default_ctx; @@ -729,26 +729,26 @@ TEST_F(TestObjLock, lock_conflict_out_in) param.expired_time_ = expired_time; for (int first = 0; first < TABLE_LOCK_MODE_COUNT; first++) { // lock the first lock - printf("first lock index:%d\n", first); - lock_first.lock_mode_ = LOCK_MODE_ARRAY[first]; + lock_first.lock_mode_ = get_lock_mode_by_index(first); + printf("first lock index: %d, mode: %d\n", first, lock_first.lock_mode_); ret = obj_lock_.lock(param, store_ctx, lock_first, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); // lock the second lock and check conflict for (int second = 0; second < TABLE_LOCK_MODE_COUNT; second++) { - printf("second lock index:%d\n", second); - lock_second.lock_mode_ = LOCK_MODE_ARRAY[second]; + lock_second.lock_mode_ = get_lock_mode_by_index(second); + printf("second lock index: %d, mode: %d\n", second, lock_second.lock_mode_); is_conflict = !request_lock(lock_first.lock_mode_, lock_second.lock_mode_, conflict_modes); ret = obj_lock_.lock(param, store_ctx2, lock_second, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); if (is_conflict) { @@ -776,7 +776,7 @@ TEST_F(TestObjLock, lock_conflict_out_out) int64_t expired_time = 0; ObTxIDSet conflict_tx_set; int64_t conflict_modes = 0; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObLockParam param; MyTxCtx default_ctx; @@ -803,26 +803,26 @@ TEST_F(TestObjLock, lock_conflict_out_out) param.expired_time_ = expired_time; for (int first = 0; first < TABLE_LOCK_MODE_COUNT; first++) { // lock the first lock - printf("first lock index:%d\n", first); - lock_first.lock_mode_ = LOCK_MODE_ARRAY[first]; + lock_first.lock_mode_ = get_lock_mode_by_index(first); + printf("first lock index: %d, mode: %d\n", first, lock_first.lock_mode_); ret = obj_lock_.lock(param, store_ctx, lock_first, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); // lock the second lock and check conflict for (int second = 0; second < TABLE_LOCK_MODE_COUNT; second++) { - printf("second lock index:%d\n", second); - lock_second.lock_mode_ = LOCK_MODE_ARRAY[second]; + lock_second.lock_mode_ = get_lock_mode_by_index(second); + printf("second lock index: %d, mode: %d\n", second, lock_second.lock_mode_); is_conflict = !request_lock(lock_first.lock_mode_, lock_second.lock_mode_, conflict_modes); ret = obj_lock_.lock(param, store_ctx2, lock_second, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set); if (is_conflict) { diff --git a/mittest/mtlenv/tablelock/test_obj_lock_map.cpp b/mittest/mtlenv/tablelock/test_obj_lock_map.cpp index 55a6b4d9cb..08d7750ac7 100644 --- a/mittest/mtlenv/tablelock/test_obj_lock_map.cpp +++ b/mittest/mtlenv/tablelock/test_obj_lock_map.cpp @@ -107,7 +107,7 @@ TEST_F(TestObjLockMap, lock) int64_t expired_time = 0; ObOBJLock *obj_lock = NULL; ObTxIDSet conflict_tx_set; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObLockParam param; MyTxCtx default_ctx; @@ -122,7 +122,7 @@ TEST_F(TestObjLockMap, lock) ret = lock_map_.lock(param, store_ctx, DEFAULT_IN_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); ret = lock_map_.get_obj_lock_with_ref_(DEFAULT_TABLET_LOCK_ID, @@ -137,7 +137,7 @@ TEST_F(TestObjLockMap, lock) ret = lock_map_.lock(param, store_ctx, DEFAULT_IN_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(obj_lock->row_exclusive_, 2); @@ -149,7 +149,7 @@ TEST_F(TestObjLockMap, lock) ret = lock_map_.lock(param, store_ctx, DEFAULT_IN_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(obj_lock->row_exclusive_, 3); @@ -180,7 +180,7 @@ TEST_F(TestObjLockMap, unlock) share::SCN min_commited_scn; share::SCN flushed_scn; ObTxIDSet conflict_tx_set; - unsigned char lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObLockParam param; MyTxCtx default_ctx; @@ -201,7 +201,7 @@ TEST_F(TestObjLockMap, unlock) ret = lock_map_.lock(param, store_ctx, DEFAULT_OUT_TRANS_LOCK_OP, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, conflict_tx_set); ASSERT_EQ(OB_SUCCESS, ret); min_commited_scn = lock_map_.get_min_ddl_committed_scn(flushed_scn); diff --git a/src/storage/memtable/ob_memtable_context.cpp b/src/storage/memtable/ob_memtable_context.cpp index d3b93d1ad0..4ed1c4a688 100644 --- a/src/storage/memtable/ob_memtable_context.cpp +++ b/src/storage/memtable/ob_memtable_context.cpp @@ -1013,7 +1013,7 @@ int ObMemtableCtx::check_lock_exist(const ObLockID &lock_id, const ObTableLockMode mode, const ObTableLockOpType op_type, bool &is_exist, - ObTableLockMode &lock_mode_in_same_trans) const + uint64_t lock_mode_cnt_in_same_trans[]) const { int ret = OB_SUCCESS; is_exist = false; @@ -1022,7 +1022,7 @@ int ObMemtableCtx::check_lock_exist(const ObLockID &lock_id, mode, op_type, is_exist, - lock_mode_in_same_trans))) { + lock_mode_cnt_in_same_trans))) { TRANS_LOG(WARN, "check lock exist failed. ", K(ret), K(lock_id), K(owner_id), K(mode), K(*this)); } diff --git a/src/storage/memtable/ob_memtable_context.h b/src/storage/memtable/ob_memtable_context.h index a0e5f332f7..8732225225 100644 --- a/src/storage/memtable/ob_memtable_context.h +++ b/src/storage/memtable/ob_memtable_context.h @@ -472,7 +472,7 @@ public: const ObTableLockMode mode, const ObTableLockOpType op_type, bool &is_exist, - ObTableLockMode &lock_mode_in_same_trans) const; + uint64_t lock_mode_cnt_in_same_trans[]) const; int check_modify_schema_elapsed(const common::ObTabletID &tablet_id, const int64_t schema_version); int check_modify_time_elapsed(const common::ObTabletID &tablet_id, diff --git a/src/storage/tablelock/ob_lock_memtable.cpp b/src/storage/tablelock/ob_lock_memtable.cpp index 228ba4f4e7..ab998460cc 100644 --- a/src/storage/tablelock/ob_lock_memtable.cpp +++ b/src/storage/tablelock/ob_lock_memtable.cpp @@ -115,20 +115,6 @@ void ObLockMemtable::reset() reset_trace_id(); } -// RX + S = RX + SRX | S + RX = S + SRX -OB_INLINE static void lock_upgrade(const ObTableLockMode &lock_mode_in_same_trans, - ObTableLockOp &lock_op) -{ - if (((lock_mode_in_same_trans & ROW_EXCLUSIVE) && - !(lock_mode_in_same_trans & SHARE) && - lock_op.lock_mode_ == SHARE) - || ((lock_mode_in_same_trans & SHARE) && - !(lock_mode_in_same_trans & ROW_EXCLUSIVE) && - lock_op.lock_mode_ == ROW_EXCLUSIVE)) { - lock_op.lock_mode_ = SHARE_ROW_EXCLUSIVE; - } -} - int ObLockMemtable::lock_( const ObLockParam ¶m, ObStoreCtx &ctx, @@ -139,7 +125,7 @@ int ObLockMemtable::lock_( int64_t USLEEP_TIME = 100 * 1000; // 100 ms ObMemtableCtx *mem_ctx = NULL; bool need_retry = false; - ObTableLockMode lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; bool lock_exist = false; ObLockStep succ_step = STEP_BEGIN; bool register_to_deadlock = false; @@ -155,7 +141,7 @@ int ObLockMemtable::lock_( { succ_step = STEP_BEGIN; lock_exist = false; - lock_mode_in_same_trans = 0x0; + memset(lock_mode_cnt_in_same_trans, 0, sizeof(lock_mode_cnt_in_same_trans)); conflict_tx_set.reset(); ObMvccWriteGuard guard; if (OB_FAIL(guard.write_auth(ctx))) { @@ -172,7 +158,7 @@ int ObLockMemtable::lock_( lock_op.lock_mode_, lock_op.op_type_, lock_exist, - lock_mode_in_same_trans))) { + lock_mode_cnt_in_same_trans))) { LOG_WARN("failed to check lock exist ", K(ret), K(lock_op)); } else if (lock_exist) { // if the lock is DBMS_LOCK, we should return error code @@ -181,8 +167,7 @@ int ObLockMemtable::lock_( ret = OB_OBJ_LOCK_EXIST; } LOG_DEBUG("lock is exist", K(ret), K(lock_op)); - } else if (FALSE_IT(lock_upgrade(lock_mode_in_same_trans, lock_op))) { - } else if (OB_FAIL(obj_lock_map_.lock(param, ctx, lock_op, lock_mode_in_same_trans, conflict_tx_set))) { + } else if (OB_FAIL(obj_lock_map_.lock(param, ctx, lock_op, lock_mode_cnt_in_same_trans, conflict_tx_set))) { if (ret != OB_TRY_LOCK_ROW_CONFLICT && ret != OB_OBJ_LOCK_EXIST) { LOG_WARN("record lock at lock map mgr failed.", K(ret), K(lock_op)); @@ -255,11 +240,11 @@ int ObLockMemtable::lock_( // wait all the conflict trans to do deadlock detect. ObFunction recheck_f([this, &lock_op, - &lock_mode_in_same_trans](bool &need_wait) -> int { + &lock_mode_cnt_in_same_trans](bool &need_wait) -> int { int ret = OB_SUCCESS; ObTxIDSet conflict_tx_set; if (OB_FAIL(this->obj_lock_map_.check_allow_lock(lock_op, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, conflict_tx_set)) && OB_TRY_LOCK_ROW_CONFLICT != ret) { LOG_WARN("check allow lock failed", K(ret)); @@ -340,7 +325,7 @@ int ObLockMemtable::unlock_( ObMemtableCtx *mem_ctx = NULL; bool lock_op_exist = false; bool need_retry = false; - ObTableLockMode unused_lock_mode_in_same_trans = 0x0; + uint64_t unused_lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; ObLockStep succ_step = STEP_BEGIN; // 1. record unlock op myself(check conflict). @@ -353,7 +338,7 @@ int ObLockMemtable::unlock_( { succ_step = STEP_BEGIN; lock_op_exist = false; - unused_lock_mode_in_same_trans = 0x0; + memset(unused_lock_mode_cnt_in_same_trans, 0, sizeof(unused_lock_mode_cnt_in_same_trans)); ObMvccWriteGuard guard(true); if (ObClockGenerator::getClock() >= expired_time) { ret = OB_TIMEOUT; @@ -369,7 +354,7 @@ int ObLockMemtable::unlock_( unlock_op.lock_mode_, unlock_op.op_type_, lock_op_exist, - unused_lock_mode_in_same_trans))) { + unused_lock_mode_cnt_in_same_trans))) { LOG_WARN("failed to check lock exist ", K(ret), K(unlock_op)); } else if (lock_op_exist) { // do nothing @@ -515,7 +500,7 @@ int ObLockMemtable::check_lock_conflict( { int ret = OB_SUCCESS; bool lock_exist = false; - ObTableLockMode lock_mode_in_same_trans = 0x0; + uint64_t lock_mode_cnt_in_same_trans[TABLE_LOCK_MODE_COUNT] = {0, 0, 0, 0, 0}; LOG_DEBUG("ObLockMemtable::check_lock_conflict ", K(lock_op)); if (IS_NOT_INIT) { @@ -530,7 +515,7 @@ int ObLockMemtable::check_lock_conflict( lock_op.lock_mode_, lock_op.op_type_, lock_exist, - lock_mode_in_same_trans))) { + lock_mode_cnt_in_same_trans))) { LOG_WARN("failed to check lock exist ", K(ret), K(lock_op)); } else if (lock_exist) { // if the lock is DBMS_LOCK, we should return error code @@ -540,7 +525,7 @@ int ObLockMemtable::check_lock_conflict( } LOG_DEBUG("lock is exist", K(ret), K(lock_op)); } else if (OB_FAIL(obj_lock_map_.check_allow_lock(lock_op, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, conflict_tx_set, include_finish_tx, only_check_dml_lock))) { diff --git a/src/storage/tablelock/ob_mem_ctx_table_lock.cpp b/src/storage/tablelock/ob_mem_ctx_table_lock.cpp index aa31fded69..14cd87b5cf 100644 --- a/src/storage/tablelock/ob_mem_ctx_table_lock.cpp +++ b/src/storage/tablelock/ob_mem_ctx_table_lock.cpp @@ -333,7 +333,7 @@ int ObLockMemCtx::check_lock_exist( //TODO(lihongqin):check it const ObTableLockMode mode, const ObTableLockOpType op_type, bool &is_exist, - ObTableLockMode &lock_mode_in_same_trans) const + uint64_t lock_mode_cnt_in_same_trans[]) const { int ret = OB_SUCCESS; is_exist = false; @@ -347,12 +347,12 @@ int ObLockMemCtx::check_lock_exist( //TODO(lihongqin):check it DLIST_FOREACH(curr, lock_list_) { if (curr->lock_op_.lock_id_ == lock_id) { // BE CAREFUL: get all the lock mode curr trans has got. - lock_mode_in_same_trans |= curr->lock_op_.lock_mode_; + lock_mode_cnt_in_same_trans[get_index_by_lock_mode(curr->lock_op_.lock_mode_)]++; // check exist. if (curr->lock_op_.owner_id_ == owner_id && curr->lock_op_.op_type_ == op_type && /* different op type may lock twice */ curr->lock_op_.lock_op_status_ == LOCK_OP_DOING) { - // dbms_lock can only have one obj lock + // dbms_lock can only have one obj lock, no matter what lock_mode is_exist = lock_id.obj_type_ == ObLockOBJType::OBJ_TYPE_DBMS_LOCK ? true : curr->lock_op_.lock_mode_ == mode; if (is_exist) break; } diff --git a/src/storage/tablelock/ob_mem_ctx_table_lock.h b/src/storage/tablelock/ob_mem_ctx_table_lock.h index 67fc56fae0..ec94829889 100644 --- a/src/storage/tablelock/ob_mem_ctx_table_lock.h +++ b/src/storage/tablelock/ob_mem_ctx_table_lock.h @@ -80,7 +80,7 @@ public: const ObTableLockMode mode, const ObTableLockOpType op_type, bool &is_exist, - ObTableLockMode &lock_mode_in_same_trans) const; + uint64_t lock_mode_cnt_in_same_trans[]) const; // wait all the trans that modify with a smaller schema_version finished. int check_modify_schema_elapsed( const ObLockID &lock_id, diff --git a/src/storage/tablelock/ob_obj_lock.cpp b/src/storage/tablelock/ob_obj_lock.cpp index ff02ea4acd..ed4d70b50c 100644 --- a/src/storage/tablelock/ob_obj_lock.cpp +++ b/src/storage/tablelock/ob_obj_lock.cpp @@ -98,20 +98,6 @@ ObOBJLock::ObOBJLock(const ObLockID &lock_id) : lock_id_(lock_id) memset(map_, 0, sizeof(ObTableLockOpList *) * TABLE_LOCK_MODE_COUNT); } -int ObOBJLock::get_index_by_lock_mode(ObTableLockMode mode) -{ - int index = 0; - switch(mode) { - case ROW_SHARE: { index = 0; break; } - case ROW_EXCLUSIVE: { index = 1; break; } - case SHARE: { index = 2; break; } - case SHARE_ROW_EXCLUSIVE: { index = 3; break; } - case EXCLUSIVE: { index = 4; break; } - default: { index = -1; } - } - return index; -} - int ObOBJLock::recover_( const ObTableLockOp &lock_op, ObMalloc &allocator) @@ -168,7 +154,7 @@ int ObOBJLock::recover_( int ObOBJLock::slow_lock( const ObLockParam ¶m, const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObMalloc &allocator, ObTxIDSet &conflict_tx_set) { @@ -186,7 +172,7 @@ int ObOBJLock::slow_lock( if (is_deleted_) { ret = OB_EAGAIN; } else if (OB_FAIL(check_allow_lock_(lock_op, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, conflict_tx_set, conflict_with_dml_lock))) { if (OB_TRY_LOCK_ROW_CONFLICT != ret) { @@ -407,7 +393,7 @@ int ObOBJLock::update_lock_status(const ObTableLockOp &lock_op, int ObOBJLock::try_fast_lock_( const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObTxIDSet &conflict_tx_set) { int ret = OB_SUCCESS; @@ -418,7 +404,7 @@ int ObOBJLock::try_fast_lock_( ret = OB_ERR_UNEXPECTED; LOG_WARN("this lock op should not do fast lock", KR(ret), K(lock_op)); } else if (OB_FAIL(check_allow_lock_(lock_op, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, conflict_tx_set, unused_conflict_with_dml_lock))) { if (OB_TRY_LOCK_ROW_CONFLICT != ret) { @@ -438,7 +424,7 @@ int ObOBJLock::try_fast_lock_( int ObOBJLock::fast_lock( const ObLockParam ¶m, const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObMalloc &allocator, ObTxIDSet &conflict_tx_set) { @@ -448,7 +434,7 @@ int ObOBJLock::fast_lock( // lock first time RDLockGuard guard(rwlock_); if (OB_FAIL(try_fast_lock_(lock_op, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, conflict_tx_set))) { if (OB_TRY_LOCK_ROW_CONFLICT != ret && OB_EAGAIN != ret) { LOG_WARN("try fast lock failed", KR(ret), K(lock_op)); @@ -464,7 +450,7 @@ int ObOBJLock::lock( const ObLockParam ¶m, ObStoreCtx &ctx, const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObMalloc &allocator, ObTxIDSet &conflict_tx_set) { @@ -481,7 +467,7 @@ int ObOBJLock::lock( if (OB_LIKELY(!lock_op.need_record_lock_op())) { if (OB_FAIL(fast_lock(param, lock_op, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator, conflict_tx_set))) { if (ret != OB_TRY_LOCK_ROW_CONFLICT && @@ -491,7 +477,7 @@ int ObOBJLock::lock( } } else if (OB_FAIL(slow_lock(param, lock_op, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator, conflict_tx_set))) { if (ret != OB_TRY_LOCK_ROW_CONFLICT && @@ -880,7 +866,7 @@ int ObOBJLock::check_allow_unlock_( int ObOBJLock::check_allow_lock_( const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObTxIDSet &conflict_tx_set, bool &conflict_with_dml_lock, const bool include_finish_tx, @@ -896,8 +882,9 @@ int ObOBJLock::check_allow_lock_( ret != OB_OBJ_LOCK_EXIST) { LOG_WARN("check_op_allow_lock failed.", K(ret), K(lock_op)); } - } else if (FALSE_IT(get_exist_lock_mode_without_cur_trans(lock_mode_in_same_trans, + } else if (OB_FAIL(get_exist_lock_mode_without_curr_trans(lock_mode_cnt_in_same_trans, curr_lock_mode))) { + LOG_WARN("meet unexpected error during get lock_mode without current trans", K(ret)); } else if (!request_lock(curr_lock_mode, lock_op.lock_mode_, conflict_modes)) { @@ -926,14 +913,14 @@ int ObOBJLock::check_allow_lock_( conflict_with_dml_lock = ((conflict_modes & ROW_SHARE && row_share_) || (conflict_modes & ROW_EXCLUSIVE && row_exclusive_)); } - LOG_DEBUG("check_allow_lock", K(ret), K(curr_lock_mode), K(lock_mode_in_same_trans), + LOG_DEBUG("check_allow_lock", K(ret), K(curr_lock_mode), K(lock_op.lock_mode_), K(lock_op), K(conflict_modes), K(conflict_tx_set)); return ret; } int ObOBJLock::check_allow_lock( const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObTxIDSet &conflict_tx_set, bool &conflict_with_dml_lock, ObMalloc &allocator, @@ -947,7 +934,7 @@ int ObOBJLock::check_allow_lock( } else { RDLockGuard guard(rwlock_); ret = check_allow_lock_(lock_op, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, conflict_tx_set, conflict_with_dml_lock, include_finish_tx, @@ -956,69 +943,81 @@ int ObOBJLock::check_allow_lock( return ret; } -void ObOBJLock::get_exist_lock_mode_without_cur_trans( - const ObTableLockMode &lock_mode_in_same_trans, - ObTableLockMode &curr_mode) +int ObOBJLock::get_exist_lock_mode_without_curr_trans( + const uint64_t lock_mode_cnt_in_same_trans[], + ObTableLockMode &lock_mode_without_curr_trans) { - curr_mode = 0x0; + int ret = OB_SUCCESS; + lock_mode_without_curr_trans = 0x0; - // get RS - int row_share_nums = (map_[0] == NULL ? 0 : map_[0]->get_size()) + row_share_; - int row_share = (lock_mode_in_same_trans & ROW_SHARE ? - row_share_nums - 1 : - row_share_nums); - curr_mode |= (row_share == 0 ? 0 : ROW_SHARE); + int row_share_not_in_curr_trans = get_exist_lock_mode_cnt_without_curr_trans_(ROW_SHARE, lock_mode_cnt_in_same_trans); + int row_exclusive_not_in_curr_trans = + get_exist_lock_mode_cnt_without_curr_trans_(ROW_EXCLUSIVE, lock_mode_cnt_in_same_trans); + int share_not_in_curr_trans = get_exist_lock_mode_cnt_without_curr_trans_(SHARE, lock_mode_cnt_in_same_trans); + int share_row_exclusive_not_in_curr_trans = + get_exist_lock_mode_cnt_without_curr_trans_(SHARE_ROW_EXCLUSIVE, lock_mode_cnt_in_same_trans); + int exclusive_not_in_curr_trans = get_exist_lock_mode_cnt_without_curr_trans_(EXCLUSIVE, lock_mode_cnt_in_same_trans); - // get RX, S, SRX - int row_exclusive_nums = (map_[1] == NULL ? 0 : map_[1]->get_size()) + row_exclusive_; - int share_nums = (map_[2] == NULL ? 0 : map_[2]->get_size()); - int share_row_exclusive_nums = (map_[3] == NULL ? 0 : map_[3]->get_size()); - if ((lock_mode_in_same_trans & ROW_EXCLUSIVE) && - (lock_mode_in_same_trans & SHARE)) { - // other trans should not have RX, S or SRX - if (row_exclusive_nums > 1 || - share_nums > 1 || - share_row_exclusive_nums > 1) { - LOG_ERROR_RET(OB_ERR_UNEXPECTED, "unexpected error", - K(row_exclusive_nums), K(share_nums), K(share_row_exclusive_nums)); - } - } else if (lock_mode_in_same_trans & ROW_EXCLUSIVE) { - // other trans in the obj should not have S or SRX - if (share_nums > 1 || - share_row_exclusive_nums > 1) { - LOG_ERROR_RET(OB_ERR_UNEXPECTED, "unexpected error", - K(row_exclusive_nums), K(share_nums), K(share_row_exclusive_nums)); - } - curr_mode |= (row_exclusive_nums > 1 ? ROW_EXCLUSIVE : 0); - } else if (lock_mode_in_same_trans & SHARE) { - // other trans in the obj should not have RX or SRX - if (row_exclusive_nums > 1 || - share_row_exclusive_nums > 1) { - LOG_ERROR_RET(OB_ERR_UNEXPECTED, "unexpected error", - K(row_exclusive_nums), K(share_nums), K(share_row_exclusive_nums)); - } - curr_mode |= (share_nums > 1 ? SHARE : 0); + if (OB_UNLIKELY(row_share_not_in_curr_trans < 0 || row_exclusive_not_in_curr_trans < 0 || share_not_in_curr_trans < 0 + || share_row_exclusive_not_in_curr_trans < 0 || exclusive_not_in_curr_trans < 0)) { + ret = OB_ERR_UNEXPECTED; + LOG_ERROR("lock_mode count should not be negative", + K(row_share_not_in_curr_trans), + K(row_exclusive_not_in_curr_trans), + K(share_not_in_curr_trans), + K(share_row_exclusive_not_in_curr_trans), + K(exclusive_not_in_curr_trans)); + } else if (OB_UNLIKELY(lock_mode_cnt_in_same_trans[get_index_by_lock_mode(ROW_SHARE)] > 0 + && exclusive_not_in_curr_trans > 0)) { + ret = OB_ERR_UNEXPECTED; + LOG_ERROR("current trans has rs lock, others should not have x lock", + K(lock_mode_cnt_in_same_trans), + K(exclusive_not_in_curr_trans)); + } else if (OB_UNLIKELY(lock_mode_cnt_in_same_trans[get_index_by_lock_mode(ROW_EXCLUSIVE)] > 0 + && (share_not_in_curr_trans > 0 || share_row_exclusive_not_in_curr_trans > 0 + || exclusive_not_in_curr_trans))) { + ret = OB_ERR_UNEXPECTED; + LOG_ERROR("current trans has rx lock, others should not have s/srx/x lock", + K(share_not_in_curr_trans), + K(share_row_exclusive_not_in_curr_trans), + K(exclusive_not_in_curr_trans)); + } else if (OB_UNLIKELY(lock_mode_cnt_in_same_trans[get_index_by_lock_mode(SHARE)] > 0 + && (row_exclusive_not_in_curr_trans > 0 || share_row_exclusive_not_in_curr_trans > 0 + || exclusive_not_in_curr_trans > 0))) { + ret = OB_ERR_UNEXPECTED; + LOG_ERROR("current trans has s lock, others should not have rx/srx/x lock", + K(row_exclusive_not_in_curr_trans), + K(share_row_exclusive_not_in_curr_trans), + K(exclusive_not_in_curr_trans)); + } else if (OB_UNLIKELY(lock_mode_cnt_in_same_trans[get_index_by_lock_mode(SHARE_ROW_EXCLUSIVE)] > 0 + && (row_exclusive_not_in_curr_trans > 0 || share_not_in_curr_trans > 0 + || share_row_exclusive_not_in_curr_trans > 0 || exclusive_not_in_curr_trans > 0))) { + ret = OB_ERR_UNEXPECTED; + LOG_ERROR("current trans has srx lock, others should not have rx/s/srx/x lock", + K(row_exclusive_not_in_curr_trans), + K(share_not_in_curr_trans), + K(share_row_exclusive_not_in_curr_trans), + K(exclusive_not_in_curr_trans)); + } else if (OB_UNLIKELY(lock_mode_cnt_in_same_trans[get_index_by_lock_mode(EXCLUSIVE)] > 0 + && (row_share_not_in_curr_trans > 0 || row_exclusive_not_in_curr_trans > 0 + || share_not_in_curr_trans > 0 || share_row_exclusive_not_in_curr_trans > 0 + || exclusive_not_in_curr_trans > 0))) { + ret = OB_ERR_UNEXPECTED; + LOG_ERROR("current trans has x lock, others should not have any locks", + K(row_share_not_in_curr_trans), + K(row_exclusive_not_in_curr_trans), + K(share_not_in_curr_trans), + K(share_row_exclusive_not_in_curr_trans), + K(exclusive_not_in_curr_trans)); } else { - curr_mode |= (row_exclusive_nums > 0 ? ROW_EXCLUSIVE : 0); - curr_mode |= (share_nums > 0 ? SHARE : 0); - curr_mode |= (share_row_exclusive_nums > 0 ? SHARE_ROW_EXCLUSIVE : 0); + lock_mode_without_curr_trans |= (row_share_not_in_curr_trans == 0 ? 0 : ROW_SHARE); + lock_mode_without_curr_trans |= (row_exclusive_not_in_curr_trans == 0 ? 0 : ROW_EXCLUSIVE); + lock_mode_without_curr_trans |= (share_not_in_curr_trans == 0 ? 0 : SHARE); + lock_mode_without_curr_trans |= (share_row_exclusive_not_in_curr_trans == 0 ? 0 : SHARE_ROW_EXCLUSIVE); + lock_mode_without_curr_trans |= (exclusive_not_in_curr_trans == 0 ? 0 : EXCLUSIVE); } - // get X - int exclusive_nums = (map_[4] == NULL ? 0 : map_[4]->get_size()); - if (lock_mode_in_same_trans & EXCLUSIVE) { - // other trans should not have RS, RX, S, SRX, X - if (row_share_nums > 1 || - row_exclusive_nums > 1 || - share_nums > 1 || - share_row_exclusive_nums > 1 || - exclusive_nums > 1) { - LOG_ERROR_RET(OB_ERR_UNEXPECTED, "unexpected error", K(row_share_nums), K(row_exclusive_nums), - K(share_nums), K(share_row_exclusive_nums), K(exclusive_nums)); - } - } else { - curr_mode |= (exclusive_nums > 0 ? EXCLUSIVE : 0); - } + return ret; } void ObOBJLock::reset_(ObMalloc &allocator) @@ -1065,7 +1064,7 @@ void ObOBJLock::print_() const for (int i = 0; i < TABLE_LOCK_MODE_COUNT; i++) { op_list = map_[i]; if (NULL != op_list) { - LOG_INFO("ObOBJLock: mode:", K(LOCK_MODE_ARRAY[i])); + LOG_INFO("ObOBJLock: mode:", K(get_lock_mode_by_index(i))); print_op_list(op_list); } } @@ -1343,7 +1342,7 @@ int ObOBJLock::get_tx_id_set_(const ObTransID &myself_tx, bool need_check_curr_list = false; for (int i = 0; i < TABLE_LOCK_MODE_COUNT && OB_SUCC(ret); i++) { op_list = map_[i]; - curr_mode = LOCK_MODE_ARRAY[i]; + curr_mode = get_lock_mode_by_index(i); need_check_curr_list = ((curr_mode & lock_modes) == curr_mode); if (NULL != op_list && need_check_curr_list) { if (OB_FAIL(get_tx_id_set_(myself_tx, @@ -1594,6 +1593,40 @@ void ObOBJLock::drop_op_list_if_empty_( } } +int ObOBJLock::get_exist_lock_mode_cnt_without_curr_trans_(const ObTableLockMode &lock_mode, + const uint64_t lock_mode_cnt_in_same_trans[]) +{ + int lock_mode_cnt_without_curr_trans = 0; + if (OB_LIKELY(is_lock_mode_valid(lock_mode))) { + int index = get_index_by_lock_mode(lock_mode); + int total_lock_mode_cnt = OB_ISNULL(map_[index]) ? 0 : map_[index]->get_size(); + lock_mode_cnt_without_curr_trans = total_lock_mode_cnt - lock_mode_cnt_in_same_trans[index]; + switch (lock_mode) { + case ROW_SHARE: { + lock_mode_cnt_without_curr_trans += row_share_; + break; + } + case ROW_EXCLUSIVE: { + lock_mode_cnt_without_curr_trans += row_exclusive_; + break; + } + case SHARE: + case SHARE_ROW_EXCLUSIVE: + case EXCLUSIVE: { + // do nothing + break; + } + default: { + lock_mode_cnt_without_curr_trans = -1; + } + } + } else { + lock_mode_cnt_without_curr_trans = -1; + } + + return lock_mode_cnt_without_curr_trans; +} + ObOBJLock *ObOBJLockFactory::alloc(const uint64_t tenant_id, const ObLockID &lock_id) { int ret = OB_SUCCESS; @@ -1745,7 +1778,7 @@ int ObOBJLockMap::lock( const ObLockParam ¶m, ObStoreCtx &ctx, const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObTxIDSet &conflict_tx_set) { int ret = OB_SUCCESS; @@ -1766,7 +1799,7 @@ int ObOBJLockMap::lock( } else if (OB_FAIL(obj_lock->lock(param, ctx, lock_op, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, allocator_, conflict_tx_set))) { if (ret != OB_EAGAIN && @@ -1966,7 +1999,7 @@ int ObOBJLockMap::update_lock_status(const ObTableLockOp &lock_op, int ObOBJLockMap::check_allow_lock( const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObTxIDSet &conflict_tx_set, const bool include_finish_tx, const bool only_check_dml_lock) @@ -1992,7 +2025,7 @@ int ObOBJLockMap::check_allow_lock( ret = OB_ERR_UNEXPECTED; LOG_WARN("op list map should not be NULL.", K(lock_op)); } else if (OB_FAIL(obj_lock->check_allow_lock(lock_op, - lock_mode_in_same_trans, + lock_mode_cnt_in_same_trans, conflict_tx_set, conflict_with_dml_lock, allocator_, @@ -2000,7 +2033,7 @@ int ObOBJLockMap::check_allow_lock( only_check_dml_lock))) { if (OB_TRY_LOCK_ROW_CONFLICT != ret) { LOG_WARN("obj_lock check_allow_lock failed", - K(ret), K(lock_op), K(lock_mode_in_same_trans)); + K(ret), K(lock_op)); } } else { LOG_DEBUG("succeed check allow lock.", K(lock_op)); diff --git a/src/storage/tablelock/ob_obj_lock.h b/src/storage/tablelock/ob_obj_lock.h index b1041a3999..58221e5198 100644 --- a/src/storage/tablelock/ob_obj_lock.h +++ b/src/storage/tablelock/ob_obj_lock.h @@ -88,7 +88,7 @@ public: const ObLockParam ¶m, storage::ObStoreCtx &ctx, const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObMalloc &allocator, ObTxIDSet &conflict_tx_set); int unlock( @@ -111,7 +111,7 @@ public: ObMalloc &allocator); int check_allow_lock( const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObTxIDSet &conflict_tx_set, bool &conflict_with_dml_lock, ObMalloc &allocator, @@ -143,7 +143,7 @@ private: void reset_(ObMalloc &allocator); int check_allow_lock_( const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObTxIDSet &conflict_tx_set, bool &conflict_with_dml_lock, const bool include_finish_tx = true, @@ -161,27 +161,27 @@ private: int fast_lock( const ObLockParam ¶m, const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObMalloc &allocator, ObTxIDSet &conflict_tx_set); int slow_lock( const ObLockParam ¶m, const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObMalloc &allocator, ObTxIDSet &conflict_tx_set); int try_fast_lock_( const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObTxIDSet &conflict_tx_set); int unlock_( const ObTableLockOp &unlock_op, ObMalloc &allocator); int check_allow_unlock_(const ObTableLockOp &unlock_op); int check_op_allow_lock_(const ObTableLockOp &lock_op); - void get_exist_lock_mode_without_cur_trans( - const ObTableLockMode &lock_mode_in_same_trans, - ObTableLockMode &curr_mode); + int get_exist_lock_mode_without_curr_trans( + const uint64_t lock_mode_cnt_in_same_trans[], + ObTableLockMode &lock_mode_without_curr_trans); void check_need_recover_( const ObTableLockOp &lock_op, const ObTableLockOpList *op_list, @@ -236,7 +236,6 @@ private: bool &is_compact, const bool is_force = false); private: - int get_index_by_lock_mode(ObTableLockMode mode); int check_op_allow_lock_from_list_( const ObTableLockOp &lock_op, const ObTableLockOpList *op_list); @@ -259,6 +258,9 @@ private: { ATOMIC_DEC(&row_exclusive_); } + int get_exist_lock_mode_cnt_without_curr_trans_( + const ObTableLockMode &lock_mode, + const uint64_t lock_mode_cnt_in_same_trans[]); public: RWLock rwlock_; bool is_deleted_; @@ -311,7 +313,7 @@ public: const ObLockParam ¶m, storage::ObStoreCtx &ctx, const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObTxIDSet &conflict_tx_set); int unlock( const ObTableLockOp &lock_op, @@ -329,7 +331,7 @@ public: bool is_inited() const { return is_inited_; } int check_allow_lock( const ObTableLockOp &lock_op, - const ObTableLockMode &lock_mode_in_same_trans, + const uint64_t lock_mode_cnt_in_same_trans[], ObTxIDSet &conflict_tx_set, const bool include_finish_tx = true, const bool only_check_dml_lock = false); diff --git a/src/storage/tablelock/ob_table_lock_common.h b/src/storage/tablelock/ob_table_lock_common.h index a92a1bbeba..7bdb6cc0eb 100644 --- a/src/storage/tablelock/ob_table_lock_common.h +++ b/src/storage/tablelock/ob_table_lock_common.h @@ -56,10 +56,6 @@ static const unsigned char SHARE_ROW_EXCLUSIVE = 0x6; // binary 0110, SHARE | RO static const unsigned char EXCLUSIVE = 0x1; // binary 0001 static const unsigned char MAX_LOCK_MODE = 0xf; -static const unsigned char LOCK_MODE_ARRAY[TABLE_LOCK_MODE_COUNT] = { - ROW_SHARE, ROW_EXCLUSIVE, SHARE, SHARE_ROW_EXCLUSIVE, EXCLUSIVE -}; - // Each item occupies 4 bits, stand for ROW SHARE, ROW EXCLUSIVE, SHARE, EXCLUSIVE. static const unsigned char compatibility_matrix[] = { 0x0, /* EXCLUSIVE : 0000 */ 0xa, /* SHARE : 1010 */ @@ -112,6 +108,31 @@ bool is_lock_mode_valid(const ObTableLockMode lock_mode) return lock_mode < MAX_LOCK_MODE; } +static inline +int get_index_by_lock_mode(const ObTableLockMode &lock_mode) +{ + int index = -1; + if (is_lock_mode_valid(lock_mode)) { + index = lock_mode >> 1; + } + return index; +} + +static inline +ObTableLockMode get_lock_mode_by_index(const int index) +{ + ObTableLockMode lock_mode = MAX_LOCK_MODE; + if (index >= 0 && index < TABLE_LOCK_MODE_COUNT) { + // EXCLUSIVE is 0001, the lowest bit will be lost during left shift + if (index == 0) { + lock_mode = EXCLUSIVE; + } else { + lock_mode = index << 1; + } + } + return lock_mode; +} + static inline bool request_lock(ObTableLockMode curr_lock, ObTableLockMode new_lock,