Skip to content

Commit

Permalink
remove unnecessary change
Browse files Browse the repository at this point in the history
  • Loading branch information
lidezhu committed Jun 28, 2022
1 parent 912728d commit b273666
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
34 changes: 13 additions & 21 deletions dbms/src/Storages/Transaction/RegionCFDataBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <Storages/Transaction/RegionCFDataBase.h>
#include <Storages/Transaction/RegionCFDataTrait.h>
#include <Storages/Transaction/RegionData.h>
#include <Storages/Transaction/RegionRangeKeys.h>

namespace DB
Expand All @@ -37,7 +36,7 @@ template <>
std::shared_ptr<const TiKVValue> RegionCFDataBase<RegionLockCFDataTrait>::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 <typename Trait>
Expand Down Expand Up @@ -74,15 +73,8 @@ RegionDataRes RegionCFDataBase<Trait>::insert(std::pair<Key, Value> && kv_pair)
template <typename Trait>
size_t RegionCFDataBase<Trait>::calcTiKVKeyValueSize(const Value & value)
{
return calcTiKVKeyValueSize(getTiKVKey(value), *getTiKVValuePtr(value));
}

template <>
size_t RegionCFDataBase<RegionLockCFDataTrait>::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 <typename Trait>
Expand Down Expand Up @@ -142,7 +134,9 @@ bool RegionCFDataBase<Trait>::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
Expand Down Expand Up @@ -233,9 +227,9 @@ size_t RegionCFDataBase<Trait>::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;
Expand All @@ -244,7 +238,7 @@ size_t RegionCFDataBase<Trait>::serialize(WriteBuffer & buf) const
template <typename Trait>
size_t RegionCFDataBase<Trait>::deserialize(ReadBuffer & buf, RegionCFDataBase & new_region_data)
{
size_t size = readBinary2<size_t>(buf);
auto size = readBinary2<size_t>(buf);
size_t cf_data_size = 0;
for (size_t i = 0; i < size; ++i)
{
Expand Down Expand Up @@ -275,11 +269,10 @@ template struct RegionCFDataBase<RegionLockCFDataTrait>;
namespace RecordKVFormat
{
// https://github.com/tikv/tikv/blob/master/components/txn_types/src/lock.rs
inline std::pair<size_t, size_t> decodeLockCfValue(DecodedLockCFValue & res, std::shared_ptr<const TiKVValue> & value)
inline void decodeLockCfValue(DecodedLockCFValue & res, std::shared_ptr<const TiKVValue> & 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))
Expand Down Expand Up @@ -357,15 +350,14 @@ inline std::pair<size_t, size_t> 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);
}
}
}
if (len != 0)
throw Exception("invalid lock value " + value->toDebugString(), ErrorCodes::LOGICAL_ERROR);
}
return std::make_pair(0, 0);
}

DecodedLockCFValue::DecodedLockCFValue(std::shared_ptr<const TiKVKey> & key_, std::shared_ptr<const TiKVValue> & val_)
Expand Down Expand Up @@ -405,7 +397,7 @@ std::unique_ptr<kvrpcpb::LockInfo> DecodedLockCFValue::intoLockInfo() const
return res;
}

std::shared_ptr<const TiKVValue> DecodedLockCFValue::getLockCfValue() const
std::shared_ptr<const TiKVValue> DecodedLockCFValue::getTiKVValuePtr() const
{
LockType cf_lock_type;
switch (lock_type)
Expand Down
9 changes: 3 additions & 6 deletions dbms/src/Storages/Transaction/TiKVRecordFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,7 @@ inline TiKVValue encodeLockCfValue(
TiKV::writeVarInt(static_cast<Int64>(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);
Expand Down Expand Up @@ -312,10 +309,10 @@ inline TiKVValue encodeLockCfValue(

struct DecodedLockCFValue : boost::noncopyable
{
DecodedLockCFValue(std::shared_ptr<const TiKVKey> & key_, std::shared_ptr<const TiKVValue> & value_);
DecodedLockCFValue(std::shared_ptr<const TiKVKey> & key_, std::shared_ptr<const TiKVValue> & val_);
std::unique_ptr<kvrpcpb::LockInfo> intoLockInfo() const;
void intoLockInfo(kvrpcpb::LockInfo &) const;
std::shared_ptr<const TiKVValue> getLockCfValue() const;
std::shared_ptr<const TiKVValue> getTiKVValuePtr() const;

std::shared_ptr<const TiKVKey> key;
UInt64 lock_version{0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b273666

Please sign in to comment.