Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions dbms/src/Storages/KVStore/MultiRaft/RaftCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,22 @@ std::pair<EngineStoreApplyRes, DM::WriteResult> Region::handleWriteRaftCmd(

auto is_v2 = this->getClusterRaftstoreVer() == RaftstoreVer::V2;

auto update_write_size = [&write_size](Int64 payload) {
if (payload > 0)
{
write_size += static_cast<size_t>(payload);
}
else if (payload < 0)
{
// A lock being rewritten could lead to a negative payload.
// Try to turn the negative payload into a positive decrement on `write_size`.
const auto dec = static_cast<size_t>(-(payload + 1)) + 1; // avoid INT64_MIN overflow
if (write_size >= dec)
write_size -= dec;
else
write_size = 0;
}
};
const auto handle_by_index_func = [&](auto i) {
auto type = cmds.cmd_types[i];
auto cf = cmds.cmd_cf[i];
Expand All @@ -371,15 +387,10 @@ std::pair<EngineStoreApplyRes, DM::WriteResult> Region::handleWriteRaftCmd(
}
try
{
if unlikely (is_v2)
{
// There may be orphan default key in a snapshot.
write_size += doInsert(cf, std::move(tikv_key), std::move(tikv_value), DupCheck::AllowSame);
}
else
{
write_size += doInsert(cf, std::move(tikv_key), std::move(tikv_value), DupCheck::Deny);
}
// There may be orphan default key in a snapshot under raftstore v2.
auto dup_check = is_v2 ? DupCheck::AllowSame : DupCheck::Deny;
auto payload = doInsert(cf, std::move(tikv_key), std::move(tikv_value), dup_check);
update_write_size(payload);
}
catch (Exception & e)
{
Expand Down Expand Up @@ -523,4 +534,4 @@ RegionRaftCommandDelegate & Region::makeRaftCommandDelegate(const KVStoreTaskLoc
std::ignore = lock;
return static_cast<RegionRaftCommandDelegate &>(*this);
}
} // namespace DB
} // namespace DB