Skip to content

Commit

Permalink
Handle orphan default keys (#7842)
Browse files Browse the repository at this point in the history
close #7836
  • Loading branch information
CalvinNeo authored Jul 25, 2023
1 parent 0fcf9bf commit 96fbffd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion dbms/src/Storages/Transaction/Region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,8 @@ EngineStoreApplyRes Region::handleWriteRaftCmd(const WriteCmdsView & cmds, UInt6
Stopwatch watch;
SCOPE_EXIT({ GET_METRIC(tiflash_raft_apply_write_command_duration_seconds, type_write).Observe(watch.elapsedSeconds()); });

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

const auto handle_by_index_func = [&](auto i) {
auto type = cmds.cmd_types[i];
auto cf = cmds.cmd_cf[i];
Expand All @@ -691,7 +693,15 @@ EngineStoreApplyRes Region::handleWriteRaftCmd(const WriteCmdsView & cmds, UInt6
auto tikv_value = TiKVValue(cmds.vals[i].data, cmds.vals[i].len);
try
{
doInsert(cf, std::move(tikv_key), std::move(tikv_value));
if (is_v2)
{
// There may be orphan default key in a snapshot.
doInsert(cf, std::move(tikv_key), std::move(tikv_value), DupCheck::AllowSame);
}
else
{
doInsert(cf, std::move(tikv_key), std::move(tikv_value), DupCheck::Deny);
}
}
catch (Exception & e)
{
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/Transaction/Region.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class Region : public std::enable_shared_from_this<Region>

// Private methods no need to lock mutex, normally

void doInsert(ColumnFamilyType type, TiKVKey && key, TiKVValue && value, DupCheck mode = DupCheck::Deny);
void doInsert(ColumnFamilyType type, TiKVKey && key, TiKVValue && value, DupCheck mode);
void doCheckTable(const DecodedTiKVKey & key) const;
void doRemove(ColumnFamilyType type, const TiKVKey & key);

Expand Down

0 comments on commit 96fbffd

Please sign in to comment.