transferLeadership
Initiates a graceful leadership transfer to target per Raft §3.10, and suspends until the transfer is confirmed or fails. It returns normally only when this node observes a leader-authored message from target — an AppendEntries/InstallSnapshot sent by target at a term above the transfer's start term — proof the target actually won an election. An intervening step-down does not resolve the call (the sender of the first higher-term message identifies neither the winner nor even a campaigner): the transfer stays pending until the confirmation arrives or the one-election-timeout auto-abandon fires. Failure still means only that the transfer could not be confirmed within the window: on a degraded/partitioned network the target may have won without its first leader message reaching this node in time.
Protocol:
The leader stops accepting new propose and changeMembership calls (they receive NotLeaderException).
The leader sends AppendEntries to bring target's log fully up to the leader's last log index (§3.10 step 2 — not merely the current commitIndex, so an uncommitted tail cannot trigger a premature transfer to a not-caught-up target).
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 on seeing the higher term, and this call returns normally once target's first leader-authored message (typically its initial heartbeat) reaches this node.
If that confirmation does not arrive within one election-timeout window, the auto-timeout fires: the node resumes normal operation (accepting proposals again if still leader) and this call throws LeadershipTransferException. The same exception is thrown if this node is re-elected leader itself before the confirmation arrives.
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 and changeMembership throw 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.