From b2736662c6ced88c7f04d6cca202d5cd9ecc01e5 Mon Sep 17 00:00:00 2001 From: lidezhu Date: Tue, 28 Jun 2022 18:02:00 +0800 Subject: [PATCH] remove unnecessary change --- .../Storages/Transaction/RegionCFDataBase.cpp | 34 +++++++------------ .../Storages/Transaction/TiKVRecordFormat.h | 9 ++--- .../Transaction/tests/gtest_tikv_keyvalue.cpp | 2 +- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/dbms/src/Storages/Transaction/RegionCFDataBase.cpp b/dbms/src/Storages/Transaction/RegionCFDataBase.cpp index 578fd244be7..f0d56b50fbe 100644 --- a/dbms/src/Storages/Transaction/RegionCFDataBase.cpp +++ b/dbms/src/Storages/Transaction/RegionCFDataBase.cpp @@ -14,7 +14,6 @@ #include #include -#include #include namespace DB @@ -37,7 +36,7 @@ template <> std::shared_ptr RegionCFDataBase::getTiKVValuePtr(const Value & val) { auto decode_lock_value_ptr = std::get<1>(val); - return decode_lock_value_ptr->getLockCfValue(); + return decode_lock_value_ptr->getTiKVValuePtr(); } template @@ -74,15 +73,8 @@ RegionDataRes RegionCFDataBase::insert(std::pair && kv_pair) template size_t RegionCFDataBase::calcTiKVKeyValueSize(const Value & value) { - return calcTiKVKeyValueSize(getTiKVKey(value), *getTiKVValuePtr(value)); -} - -template <> -size_t RegionCFDataBase::calcTiKVKeyValueSize(const Value & value) -{ - std::ignore = value; - return 0; - return calcTiKVKeyValueSize(getTiKVKey(value), *getTiKVValuePtr(value)); + auto tikv_value_ptr = getTiKVValuePtr(value); + return calcTiKVKeyValueSize(getTiKVKey(value), *tikv_value_ptr); } template @@ -142,7 +134,9 @@ bool RegionCFDataBase::cmp(const Map & a, const Map & b) { if (auto it = b.find(key); it != b.end()) { - if (getTiKVKey(value) != getTiKVKey(it->second) || *getTiKVValuePtr(value) != *getTiKVValuePtr(it->second)) + auto a_tikv_value_ptr = getTiKVValuePtr(value); + auto b_tikv_value_ptr = getTiKVValuePtr(it->second); + if (getTiKVKey(value) != getTiKVKey(it->second) || *a_tikv_value_ptr != *b_tikv_value_ptr) return false; } else @@ -233,9 +227,9 @@ size_t RegionCFDataBase::serialize(WriteBuffer & buf) const for (const auto & ele : data) { const auto & key = getTiKVKey(ele.second); - const auto & value = *getTiKVValuePtr(ele.second); + auto value_ptr = getTiKVValuePtr(ele.second); total_size += key.serialize(buf); - total_size += value.serialize(buf); + total_size += value_ptr->serialize(buf); } return total_size; @@ -244,7 +238,7 @@ size_t RegionCFDataBase::serialize(WriteBuffer & buf) const template size_t RegionCFDataBase::deserialize(ReadBuffer & buf, RegionCFDataBase & new_region_data) { - size_t size = readBinary2(buf); + auto size = readBinary2(buf); size_t cf_data_size = 0; for (size_t i = 0; i < size; ++i) { @@ -275,11 +269,10 @@ template struct RegionCFDataBase; namespace RecordKVFormat { // https://github.com/tikv/tikv/blob/master/components/txn_types/src/lock.rs -inline std::pair decodeLockCfValue(DecodedLockCFValue & res, std::shared_ptr & value) +inline void decodeLockCfValue(DecodedLockCFValue & res, std::shared_ptr & value) { const char * data = value->data(); - size_t total_size = value->dataSize(); - size_t len = total_size; + size_t len = value->dataSize(); kvrpcpb::Op lock_type = kvrpcpb::Op_MIN; switch (readUInt8(data, len)) @@ -357,7 +350,7 @@ inline std::pair decodeLockCfValue(DecodedLockCFValue & res, std } default: { - std::string msg = std::string("invalid flag ") + flag + " in lock value " + value->toDebugString(); + std::string msg = std::string("invalid flag (") + std::to_string(int(flag)) + ") in lock value " + value->toDebugString(); throw Exception(msg, ErrorCodes::LOGICAL_ERROR); } } @@ -365,7 +358,6 @@ inline std::pair decodeLockCfValue(DecodedLockCFValue & res, std if (len != 0) throw Exception("invalid lock value " + value->toDebugString(), ErrorCodes::LOGICAL_ERROR); } - return std::make_pair(0, 0); } DecodedLockCFValue::DecodedLockCFValue(std::shared_ptr & key_, std::shared_ptr & val_) @@ -405,7 +397,7 @@ std::unique_ptr DecodedLockCFValue::intoLockInfo() const return res; } -std::shared_ptr DecodedLockCFValue::getLockCfValue() const +std::shared_ptr DecodedLockCFValue::getTiKVValuePtr() const { LockType cf_lock_type; switch (lock_type) diff --git a/dbms/src/Storages/Transaction/TiKVRecordFormat.h b/dbms/src/Storages/Transaction/TiKVRecordFormat.h index 298d6e19644..db01af2fa36 100644 --- a/dbms/src/Storages/Transaction/TiKVRecordFormat.h +++ b/dbms/src/Storages/Transaction/TiKVRecordFormat.h @@ -277,10 +277,7 @@ inline TiKVValue encodeLockCfValue( TiKV::writeVarInt(static_cast(primary.size()), res); res.write(primary.data(), primary.size()); TiKV::writeVarUInt(lock_version, res); - if (ttl) - { - TiKV::writeVarUInt(ttl, res); - } + TiKV::writeVarUInt(ttl, res); if (short_value) { res.write(SHORT_VALUE_PREFIX); @@ -312,10 +309,10 @@ inline TiKVValue encodeLockCfValue( struct DecodedLockCFValue : boost::noncopyable { - DecodedLockCFValue(std::shared_ptr & key_, std::shared_ptr & value_); + DecodedLockCFValue(std::shared_ptr & key_, std::shared_ptr & val_); std::unique_ptr intoLockInfo() const; void intoLockInfo(kvrpcpb::LockInfo &) const; - std::shared_ptr getLockCfValue() const; + std::shared_ptr getTiKVValuePtr() const; std::shared_ptr key; UInt64 lock_version{0}; diff --git a/dbms/src/Storages/Transaction/tests/gtest_tikv_keyvalue.cpp b/dbms/src/Storages/Transaction/tests/gtest_tikv_keyvalue.cpp index 8491d818ad4..af14d9aefd4 100644 --- a/dbms/src/Storages/Transaction/tests/gtest_tikv_keyvalue.cpp +++ b/dbms/src/Storages/Transaction/tests/gtest_tikv_keyvalue.cpp @@ -166,7 +166,7 @@ TEST(TiKVKeyValueTest, PortedTests) } } { - auto lock_cf_value_ptr = lock.getLockCfValue(); + auto lock_cf_value_ptr = lock.getTiKVValue(); auto new_lock_info = RecordKVFormat::DecodedLockCFValue(ori_key, lock_cf_value_ptr); auto & lock_info = lock; ASSERT_TRUE(new_lock_info.lock_type == lock_info.lock_type);