Skip to content

Commit 6ae69b0

Browse files
Besroyyawzhanggreensky00
authored
Fix snapshot retry rewind handling (#657)
When a follower reports RECEIVING_SNAPSHOT, the leader should retry snapshot sync instead of applying the normal append failure rewind. Rewinding next_log_idx from 1 to 0 causes the next request path to treat the peer progress as uninitialized and reset it to the leader's current next_slot, which can make create_sync_snapshot_req validate against an impossible last_log_idx. Keep next_log_idx aligned with the follower response and skip the rewind for RECEIVING_SNAPSHOT so snapshot retry starts from the expected peer progress. Co-authored-by: yawzhang <yawzhang@ebay.com> Co-authored-by: Jung-Sang Ahn <jungsang.ahn@gmail.com>
1 parent 18a6685 commit 6ae69b0

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

src/handle_append_entries.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,10 @@ void raft_server::handle_append_entries_resp(resp_msg& resp) {
13451345
do_log_rewind = false;
13461346
} else if (appendix->extra_order_ == resp_appendix::RECEIVING_SNAPSHOT) {
13471347
p->set_snapshot_sync_is_needed(true);
1348+
if (resp.get_next_idx() > 0) {
1349+
p->set_next_log_idx(resp.get_next_idx());
1350+
}
1351+
do_log_rewind = false;
13481352
p_in("peer %d was in snapshot sync mode, re-sending a snapshot. "
13491353
"peers next log idx: %" PRIu64 ", resp next idx: %" PRIu64,
13501354
p->get_id(), prev_next_log, resp.get_next_idx());

tests/asio/custom_quorum_test.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ int full_consensus_with_snapshot_transfer_test() {
14171417
restart_params.with_election_timeout_upper(RaftAsioPkg::HEARTBEAT_MS * 4);
14181418
restart_params.with_reserved_log_items(5);
14191419
restart_params.with_snapshot_enabled(10);
1420+
restart_params.with_max_append_size(5);
14201421
restart_params.with_client_req_timeout(10000);
14211422
restart_params.return_method_ = raft_params::async_handler;
14221423
restart_params.use_full_consensus_among_healthy_members_ = true;

0 commit comments

Comments
 (0)