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. raft follower will rollback itself when it misses a certain log #5905

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/kvstore/raftex/RaftPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1731,8 +1731,10 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req,
TermID lastTerm = (numLogs == 0) ? req.get_last_log_term_sent()
: req.get_log_str_list().back().get_log_term();
auto localWalIt = wal_->iterator(firstId, lastId);
bool hasConflict = false;
for (size_t i = 0; i < numLogs && localWalIt->valid(); ++i, ++(*localWalIt), ++diffIndex) {
if (localWalIt->logTerm() != req.get_log_str_list()[i].get_log_term()) {
hasConflict = true;
break;
}
}
Expand All @@ -1749,7 +1751,9 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req,

// Found a difference at log of (firstId + diffIndex), all logs from (firstId + diffIndex)
// could be truncated
wal_->rollbackToLog(firstId + diffIndex - 1);
if (hasConflict) {
wal_->rollbackToLog(firstId + diffIndex - 1);
}
firstId = firstId + diffIndex;
numLogs = numLogs - diffIndex;
}
Expand Down