Skip to content

Commit

Permalink
Make errors more descriptive instead of being reported as badarg
Browse files Browse the repository at this point in the history
Summary: Instead of {error, badarg} use more descriptive names. If we handover from self to self just report ok status instead of returning an error.

Differential Revision: D58003136

fbshipit-source-id: ef79d0201dbb6785fd74e96d7031303e494a924a
  • Loading branch information
Jose-Angel Herrero Bajo authored and facebook-github-bot committed May 31, 2024
1 parent 2734682 commit 4c0868f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/wa_raft_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1021,11 +1021,11 @@ leader(Type, ?HANDOVER_COMMAND(undefined), #raft_state{name = Name, current_term
leader(Type, ?HANDOVER_COMMAND(Peer), State)
end;

%% [Handover] Do not allow handover to self
%% [Handover] Handover to self results in no-op
leader(Type, ?HANDOVER_COMMAND(Peer), #raft_state{name = Name, current_term = CurrentTerm} = State) when Peer =:= node() ->
?LOG_WARNING("Server[~0p, term ~0p, leader] dropping handover to self.",
[Name, CurrentTerm], #{domain => [whatsapp, wa_raft]}),
reply(Type, {error, badarg}),
reply(Type, {ok, Peer}),
{keep_state, State};

%% [Handover] Attempt to start a handover to the specified peer
Expand All @@ -1037,7 +1037,7 @@ leader(Type, ?HANDOVER_COMMAND(Peer),
false ->
?LOG_WARNING("Server[~0p, term ~0p, leader] dropping handover to unknown peer ~p.",
[Name, CurrentTerm, Peer], #{domain => [whatsapp, wa_raft]}),
reply(Type, {error, badarg}),
reply(Type, {error, invalid_peer}),
keep_state_and_data;
true ->
PeerMatchIndex = maps:get(Peer, State0#raft_state.match_index, 0),
Expand Down

0 comments on commit 4c0868f

Please sign in to comment.