JoinerReconnectController

Manages per-peer reconnect windows on the leader side.

When a joiner's transport link drops, the leader calls onPeerUnresponsive to open a timed reconnect window (default 60 s). Within that window a joiner that proves it holds the seat is restored through tryResume. Once the window expires the peer is evicted and a late reconnect is treated as a fresh join.

State-resync (replaying application state to the reconnected joiner) is out of scope here. The consumer's leader logic subscribes to events and drives the state snapshot on JoinerReconnectEvent.Resumed. Integration point: observe events.filterIsInstance<JoinerReconnectEvent.Resumed>() and push current application state to event.peerId.

A seat is held only by the host that admitted the joiner. That host holds the seat and this controller holds its window, both in memory, so a host that did not admit the joiner — a newly elected leader, another server in a cluster — has no seat for its key, and admits it as a new member.

Partition events (PartitionEvent) are produced by the partition-detector layer. Until that wiring lands, callers bridge manually: on transport close, invoke onPeerUnresponsive directly.

Thread safety: implementations must be safe for concurrent calls.

Calls can arrive out of order, so order them by the instant they carry (#3673). A room calls onPeerUnresponsive and onPeerRecovered outside its own lock, so that this controller's code never runs under it (#1614). A thread can stall between the room's decision and the call, and a peer can meanwhile leave, be admitted again under the same PeerId and drop again. The stalled call then arrives after the newer membership's, carrying its own, older instant. An implementation that keeps one window per peer must therefore:

  • ignore an onPeerUnresponsive whose at is no later than a window it holds that is still live, one neither resumed, expired nor ended by a recovery. Acted on, an older one replaces the newer window with one that expires early, so a valid return is admitted fresh.

  • disarm a window on onPeerRecovered only when its at is strictly later than the window's. Acted on, an earlier recovery disarms the newer window, so its seat never expires and no other member is told it is gone. A detector reports a recovery at least one poll after the drop it recovers from, so a recovery at the window's own instant is about the episode before it.

This ordering assumes the room's clock does not run backwards. A wall clock can step back, and one too coarse, or a test's fixed one, does not move: the next drop then carries an at no later than the last window, which has finished by then. Open a window for it: refused, the drop has no window, so nothing expires its seat.

Inheritors

Properties

Link copied to clipboard

Functions

Link copied to clipboard
abstract fun expire(peerId: PeerId, at: Long)

Force-expires the reconnect window for peerId before the timer fires.

Link copied to clipboard
abstract fun onPeerRecovered(peerId: PeerId, at: Long)

peerId became responsive again without resuming — close its reconnect window, and close it without expiring it.

Link copied to clipboard
abstract fun onPeerUnresponsive(peerId: PeerId, at: Long)

Opens (or refreshes) the reconnect window for peerId.

Link copied to clipboard
abstract suspend fun tryResume(resume: ProvenResume, at: Long): ResumeResult.HostVerdict

Attempts to restore the held seat resume names.