Skip to content

Commit

Permalink
Fix the potential issue of inconsistent results that occurs right aft…
Browse files Browse the repository at this point in the history
…er restart (#3114)
  • Loading branch information
solotzg authored Sep 18, 2021
1 parent 3392653 commit 5191b8d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions dbms/src/Storages/Transaction/LearnerRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,26 @@ LearnerReadSnapshot doLearnerRead(const TiDB::TableID table_id, //

GET_METRIC(metrics, tiflash_raft_read_index_count).Increment(batch_read_index_req.size());

const auto & make_default_batch_read_index_result = [&]() {
const auto & make_default_batch_read_index_result = [&](bool with_region_error) {
for (const auto & req : batch_read_index_req)
{
batch_read_index_result.emplace(req.context().region_id(), kvrpcpb::ReadIndexResponse());
auto resp = kvrpcpb::ReadIndexResponse();
if (with_region_error)
resp.mutable_region_error()->mutable_region_not_found();
batch_read_index_result.emplace(req.context().region_id(), std::move(resp));
}
};
[&]() {
if (!tmt.checkRunning(std::memory_order_relaxed))
{
make_default_batch_read_index_result();
make_default_batch_read_index_result(true);
return;
}
kvstore->addReadIndexEvent(1);
SCOPE_EXIT({ kvstore->addReadIndexEvent(-1); });
if (!tmt.checkRunning())
{
make_default_batch_read_index_result();
make_default_batch_read_index_result(true);
return;
}

Expand All @@ -234,7 +237,8 @@ LearnerReadSnapshot doLearnerRead(const TiDB::TableID table_id, //
}
else
{
make_default_batch_read_index_result();
// Only in mock test, `proxy_helper` will be `nullptr`. Set `read_index` to 0 and skip waiting.
make_default_batch_read_index_result(false);
}
}();

Expand Down

0 comments on commit 5191b8d

Please sign in to comment.