Skip to content

Commit

Permalink
Fix snapshot load not advancing to snapshot term
Browse files Browse the repository at this point in the history
Summary:
Fix the RAFT server not advancing to the term reported by a
loaded snapshot if the term is more advanced that the current
term.

Reviewed By: jaher

Differential Revision: D65828543

fbshipit-source-id: 6253652a85a8c9efb466f7a036eb4e5f264bda01
  • Loading branch information
hsun324 authored and facebook-github-bot committed Nov 12, 2024
1 parent 56589d2 commit 2578d88
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/wa_raft_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,13 @@ stalled({call, From}, ?SNAPSHOT_AVAILABLE_COMMAND(Root, #raft_log_pos{index = Sn
State2 = load_config(State1),
?LOG_NOTICE("Server[~0p, term ~0p, stalled] switching to follower after installing snapshot at ~p:~p.",
[Name, CurrentTerm, SnapshotIndex, SnapshotTerm], #{domain => [whatsapp, wa_raft]}),
State3 = case SnapshotTerm > CurrentTerm of
true -> advance_term(?FUNCTION_NAME, SnapshotTerm, undefined, State2);
false -> State2
end,
% At this point, we assume that we received some cluster membership configuration from
% our peer so it is safe to transition to an operational state.
{next_state, follower, State2, {reply, From, ok}};
{next_state, follower, State3, [{reply, From, ok}]};
{error, Reason} ->
?LOG_WARNING("Server[~0p, term ~0p, stalled] failed to rename available snapshot ~p to ~p due to ~p",
[Name, CurrentTerm, Root, Path, Reason], #{domain => [whatsapp, wa_raft]}),
Expand Down

0 comments on commit 2578d88

Please sign in to comment.