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 731c0b1
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/braft/replicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,18 +447,26 @@ 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
<< " log_index=" << r->_next_index << " mismatch";
BRAFT_VLOG << "Group " << r->_options.group_id
<< " log_index=" << r->_next_index << " mismatch";
// 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
<< " peer=" << r->_options.peer_id
<< " declares that log at index=0 doesn't match,"
" which is not supposed to happen";
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";
}
}
// dummy_id is unlock in _send_heartbeat
Expand Down

0 comments on commit 731c0b1

Please sign in to comment.