Skip to content

Commit d51693f

Browse files
hsun324facebook-github-bot
authored andcommitted
Allow indicating promotion to next term
Summary: Allow the special value `next` to be provided as the term when using `wa_raft_server:promote/3` and `wa_raft_server:promote/4` which will be taken to mean the successor term to the current term when the promotion command is handed on the RAFT server. Reviewed By: aravindanilango Differential Revision: D71002259 fbshipit-source-id: 4563fdf47e28d6269cbb9c4a8b599e56858806e2
1 parent 2c22006 commit d51693f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/wa_raft_server.erl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
-type commit_command() :: ?COMMIT_COMMAND(wa_raft_acceptor:op()).
228228
-type read_command() :: ?READ_COMMAND(wa_raft_acceptor:read_op()).
229229
-type status_command() :: ?STATUS_COMMAND.
230-
-type promote_command() :: ?PROMOTE_COMMAND() | ?PROMOTE_COMMAND(wa_raft_log:log_term(), boolean(), config() | undefined).
230+
-type promote_command() :: ?PROMOTE_COMMAND() | ?PROMOTE_COMMAND(wa_raft_log:log_term() | next, boolean(), config() | undefined).
231231
-type resign_command() :: ?RESIGN_COMMAND.
232232
-type adjust_membership_command() :: ?ADJUST_MEMBERSHIP_COMMAND(membership_action(), peer() | undefined, wa_raft_log:log_index() | undefined).
233233
-type snapshot_available_command() :: ?SNAPSHOT_AVAILABLE_COMMAND(string(), wa_raft_log:log_pos()).
@@ -466,22 +466,22 @@ promote(Server) ->
466466

467467
-spec promote(
468468
Server :: gen_statem:server_ref(),
469-
Term :: wa_raft_log:log_term()
469+
Term :: wa_raft_log:log_term() | next
470470
) -> ok | wa_raft:error().
471471
promote(Server, Term) ->
472472
promote(Server, Term, false).
473473

474474
-spec promote(
475475
Server :: gen_statem:server_ref(),
476-
Term :: wa_raft_log:log_term(),
476+
Term :: wa_raft_log:log_term() | next,
477477
Force :: boolean()
478478
) -> ok | wa_raft:error().
479479
promote(Server, Term, Force) ->
480480
promote(Server, Term, Force, undefined).
481481

482482
-spec promote(
483483
Server :: gen_statem:server_ref(),
484-
Term :: wa_raft_log:log_term(),
484+
Term :: wa_raft_log:log_term() | next,
485485
Force :: boolean(),
486486
Config :: config() | config_all() | undefined
487487
) -> ok | wa_raft:error().
@@ -1850,9 +1850,13 @@ command(
18501850
end;
18511851

18521852
%% [Promote] Non-disabled nodes check if eligible to promote and then promote to leader.
1853-
command(StateName, {call, From}, ?PROMOTE_COMMAND(Term, Force, ConfigAll),
1853+
command(StateName, {call, From}, ?PROMOTE_COMMAND(RawTerm, Force, ConfigAll),
18541854
#raft_state{application = App, name = Name, log_view = View0, current_term = CurrentTerm, leader_heartbeat_ts = HeartbeatTs} = State0) when StateName =/= disabled ->
18551855
ElectionWeight = ?RAFT_ELECTION_WEIGHT(App),
1856+
Term = case RawTerm of
1857+
next -> CurrentTerm + 1;
1858+
_ when is_integer(RawTerm) -> RawTerm
1859+
end,
18561860
Config = case ConfigAll of
18571861
undefined -> undefined;
18581862
_ -> maybe_upgrade_config(ConfigAll)

0 commit comments

Comments
 (0)