From 40e8acf6aa4a297c6a9c1c01f889a614bb14c6ee Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Thu, 11 Jul 2024 11:00:32 +0800 Subject: [PATCH 1/2] add ut for parsing lock value --- .../KVStore/tests/gtest_tikv_keyvalue.cpp | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/dbms/src/Storages/KVStore/tests/gtest_tikv_keyvalue.cpp b/dbms/src/Storages/KVStore/tests/gtest_tikv_keyvalue.cpp index 5f051fa533c..c8866d2a8b0 100644 --- a/dbms/src/Storages/KVStore/tests/gtest_tikv_keyvalue.cpp +++ b/dbms/src/Storages/KVStore/tests/gtest_tikv_keyvalue.cpp @@ -12,9 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include #include +#include #include #include @@ -69,6 +71,13 @@ TiKVValue encode_lock_cf_value( RecordKVFormat::encodeUInt64(12345678, res); TiKV::writeVarUInt(87654321, res); } + { + res.write(RecordKVFormat::TXN_SOURCE_PREFIX_FOR_LOCK); + TiKV::writeVarUInt(876543, res); + } + { + res.write(RecordKVFormat::PESSIMISTIC_LOCK_WITH_CONFLICT_PREFIX); + } return TiKVValue(res.releaseStr()); } @@ -442,7 +451,49 @@ TEST(TiKVKeyValueTest, PortedTests) ASSERT_EQ(*tidb_pk, pk); } } + +} + +TEST(TiKVKeyValueTest, ParseLockValue) +try +{ + // prepare + std::string shor_value = "value"; + auto lock_for_update_ts = 7777, txn_size = 1; + const std::vector & async_commit = {"s1", "s2"}; + const std::vector & rollback = {3, 4}; + auto lock_value = encode_lock_cf_value( + Region::DelFlag, + "primary key", + 421321, + std::numeric_limits::max(), + &shor_value, + 66666, + lock_for_update_ts, + txn_size, + async_commit, + rollback); + + // parse + auto ori_key = std::make_shared(RecordKVFormat::genKey(1, 88888)); + auto lock = RecordKVFormat::DecodedLockCFValue(ori_key, std::make_shared(std::move(lock_value))); + + // check the parsed result + { + auto & lock_info = lock; + ASSERT_TRUE(kvrpcpb::Op::Del == lock_info.lock_type); + ASSERT_TRUE("primary key" == lock_info.primary_lock); + ASSERT_TRUE(421321 == lock_info.lock_version); + ASSERT_TRUE(std::numeric_limits::max() == lock_info.lock_ttl); + ASSERT_TRUE(66666 == lock_info.min_commit_ts); + ASSERT_TRUE(ori_key == lock_info.key); + ASSERT_EQ(lock_for_update_ts, lock_info.lock_for_update_ts); + ASSERT_EQ(txn_size, lock_info.txn_size); + + ASSERT_EQ(true, lock_info.use_async_commit); + } } +CATCH TEST(TiKVKeyValueTest, Redact) try From f575a7c40bd874e82a2f8cdbc9e7505847cd85da Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Thu, 11 Jul 2024 11:30:02 +0800 Subject: [PATCH 2/2] Format files --- dbms/src/Storages/KVStore/tests/gtest_tikv_keyvalue.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/dbms/src/Storages/KVStore/tests/gtest_tikv_keyvalue.cpp b/dbms/src/Storages/KVStore/tests/gtest_tikv_keyvalue.cpp index c8866d2a8b0..aac8369985e 100644 --- a/dbms/src/Storages/KVStore/tests/gtest_tikv_keyvalue.cpp +++ b/dbms/src/Storages/KVStore/tests/gtest_tikv_keyvalue.cpp @@ -451,7 +451,6 @@ TEST(TiKVKeyValueTest, PortedTests) ASSERT_EQ(*tidb_pk, pk); } } - } TEST(TiKVKeyValueTest, ParseLockValue)