Skip to content
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