Skip to content

Commit

Permalink
decrease _next_index when when the request with the minimum log
Browse files Browse the repository at this point in the history
  • Loading branch information
ehds committed Apr 7, 2024
1 parent 59c40e5 commit aec152e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/braft/replicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,23 @@ void Replicator::_on_rpc_returned(ReplicatorId id, brpc::Controller* cntl,
<< " is " << response->last_log_index();
// The peer contains less logs than leader
r->_next_index = response->last_log_index() + 1;
} else {
} else {
// The peer contains logs from old term which should be truncated,
// decrease _last_log_at_peer by one to test the right index to keep
if (BAIDU_LIKELY(r->_next_index > 1)) {
BRAFT_VLOG << "Group " << r->_options.group_id
BRAFT_VLOG << "Group " << r->_options.group_id
<< " log_index=" << r->_next_index << " mismatch";
--r->_next_index;
// Decrease the |_next_index| when the request with the minimum log
// index mismatch.
// Because when we enable pipeline replication and disable cache,
// the request with larger log index would be handled before the
// smaller request, we should ignore it.
// See https://github.com/baidu/braft/issues/421
if (request->prev_log_index() == r->_next_index - 1) {
--r->_next_index;
}
} else {
LOG(ERROR) << "Group " << r->_options.group_id
LOG(ERROR) << "Group " << r->_options.group_id
<< " peer=" << r->_options.peer_id
<< " declares that log at index=0 doesn't match,"
" which is not supposed to happen";
Expand Down

0 comments on commit aec152e

Please sign in to comment.