Commit d23f3903 authored by Yossi Gottlieb's avatar Yossi Gottlieb
Browse files

Fix: safety issues loading a snapshot.

If snapshot is on the same term, avoid resetting voted_for to prevent an
additional vote.

If snapshot is on a newer term, reset and persist term and vote.
parent 699e87d3
......@@ -1486,9 +1486,11 @@ int raft_begin_load_snapshot(
if (last_included_term == me->snapshot_last_term && last_included_index == me->snapshot_last_idx)
return RAFT_ERR_SNAPSHOT_ALREADY_LOADED;
if (me->current_term < last_included_term)
if (me->current_term < last_included_term) {
raft_set_current_term(me_, last_included_term);
me->current_term = last_included_term;
me->voted_for = -1;
}
raft_set_state((raft_server_t*)me, RAFT_STATE_FOLLOWER);
me->current_leader = NULL;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment