Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix learner's wal is not empty in rare cases #4292

Merged
merged 2 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/kvstore/raftex/RaftPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@ const char* RaftPart::roleStr(Role role) const {
void RaftPart::start(std::vector<HostAddr>&& peers, bool asLearner) {
std::lock_guard<std::mutex> g(raftLock_);

// There are some rare cases that the part start as learner, but wal is not empty. For example,
// the node is dead, and one partition is removed from raft group (majority still alive). However,
// the part is added back to raft group again as learner. So the wal may be not empty, what is
// worse, there could be case that commitLogId is 0, but wal's lastLogId is not 0, which is
// obviously not expected
if (asLearner) {
wal_->reset();
}

lastLogId_ = wal_->lastLogId();
lastLogTerm_ = wal_->lastLogTerm();
term_ = lastLogTerm_;
Expand Down
1 change: 1 addition & 0 deletions src/kvstore/wal/FileBasedWal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ bool FileBasedWal::reset() {
unlink(absFn.c_str());
}
lastLogId_ = firstLogId_ = 0;
lastLogTerm_ = 0;
return true;
}

Expand Down