transferLeadership
Initiates a graceful leadership transfer to target per Raft §3.10, and suspends until the transfer either completes (target wins an election) or fails.
Protocol:
The leader stops accepting new propose calls (they receive NotLeaderException).
The leader sends AppendEntries to bring target's log up to the current commitIndex.
The leader sends a
TimeoutNowmessage to target.target immediately starts a real election (bypassing its election-timeout wait).
If target wins, the old leader steps down naturally on seeing the higher term. This call returns normally.
If target does not win within one election-timeout window, the auto-timeout fires: the old leader resumes accepting proposals and this call throws LeadershipTransferException.
Cancellation: call cancelTransfer from a separate coroutine to abort early. The LeadershipTransferException will carry "cancelled" in its message.
Constraints:
Only the leader may call this. Non-leaders throw NotLeaderException immediately.
target must be a voter in the current cluster config, and must not be
thisnode's own id. Invalid targets throw IllegalArgumentException immediately.While a transfer is in flight, propose throws NotLeaderException.
Parameters
The NodeId of the voter to transfer leadership to.
Throws
if this node is not currently the leader.
if target is not a known voter, or is this node's own id.
if the transfer timed out or was cancelled.