Skip to content

Commit

Permalink
Fix rare race condition on commit cv (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
alesapin authored Mar 25, 2021
1 parent 3f7708b commit 2df09cc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/handle_commit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ void raft_server::commit_in_bg() {
sm_commit_index_ >= log_store_->next_slot() - 1 ) {
std::unique_lock<std::mutex> lock(commit_cv_lock_);

auto wait_check = [this] () {
return (log_store_->next_slot() - 1 > sm_commit_index_ &&
quick_commit_index_ > sm_commit_index_) || stopping_;
};
p_tr("commit_cv_ sleep\n");
commit_cv_.wait(lock);
commit_cv_.wait(lock, wait_check);

p_tr("commit_cv_ wake up\n");
if (stopping_) {
Expand Down

0 comments on commit 2df09cc

Please sign in to comment.