|
227 | 227 | -type commit_command() :: ?COMMIT_COMMAND(wa_raft_acceptor:op()). |
228 | 228 | -type read_command() :: ?READ_COMMAND(wa_raft_acceptor:read_op()). |
229 | 229 | -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). |
231 | 231 | -type resign_command() :: ?RESIGN_COMMAND. |
232 | 232 | -type adjust_membership_command() :: ?ADJUST_MEMBERSHIP_COMMAND(membership_action(), peer() | undefined, wa_raft_log:log_index() | undefined). |
233 | 233 | -type snapshot_available_command() :: ?SNAPSHOT_AVAILABLE_COMMAND(string(), wa_raft_log:log_pos()). |
@@ -466,22 +466,22 @@ promote(Server) -> |
466 | 466 |
|
467 | 467 | -spec promote( |
468 | 468 | Server :: gen_statem:server_ref(), |
469 | | - Term :: wa_raft_log:log_term() |
| 469 | + Term :: wa_raft_log:log_term() | next |
470 | 470 | ) -> ok | wa_raft:error(). |
471 | 471 | promote(Server, Term) -> |
472 | 472 | promote(Server, Term, false). |
473 | 473 |
|
474 | 474 | -spec promote( |
475 | 475 | Server :: gen_statem:server_ref(), |
476 | | - Term :: wa_raft_log:log_term(), |
| 476 | + Term :: wa_raft_log:log_term() | next, |
477 | 477 | Force :: boolean() |
478 | 478 | ) -> ok | wa_raft:error(). |
479 | 479 | promote(Server, Term, Force) -> |
480 | 480 | promote(Server, Term, Force, undefined). |
481 | 481 |
|
482 | 482 | -spec promote( |
483 | 483 | Server :: gen_statem:server_ref(), |
484 | | - Term :: wa_raft_log:log_term(), |
| 484 | + Term :: wa_raft_log:log_term() | next, |
485 | 485 | Force :: boolean(), |
486 | 486 | Config :: config() | config_all() | undefined |
487 | 487 | ) -> ok | wa_raft:error(). |
@@ -1850,9 +1850,13 @@ command( |
1850 | 1850 | end; |
1851 | 1851 |
|
1852 | 1852 | %% [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), |
1854 | 1854 | #raft_state{application = App, name = Name, log_view = View0, current_term = CurrentTerm, leader_heartbeat_ts = HeartbeatTs} = State0) when StateName =/= disabled -> |
1855 | 1855 | ElectionWeight = ?RAFT_ELECTION_WEIGHT(App), |
| 1856 | + Term = case RawTerm of |
| 1857 | + next -> CurrentTerm + 1; |
| 1858 | + _ when is_integer(RawTerm) -> RawTerm |
| 1859 | + end, |
1856 | 1860 | Config = case ConfigAll of |
1857 | 1861 | undefined -> undefined; |
1858 | 1862 | _ -> maybe_upgrade_config(ConfigAll) |
|
0 commit comments