Implement ring-based ElectionTransaction FSM and coordinator recovery - #97
Merged
Conversation
…action diagrams inside the `charts/transactions` folder
Introduce immutable election candidates ordered by EpochPair, with replica ID as the deterministic tie-breaker. Add ring-navigation rules for wraparound, skipped replicas, and the no-available-replica case. These pure rules establish predictable election behavior before adding Akka messages, timeouts, and FSM transitions.
Add deterministic candidate comparison and ring navigation with wraparound and failed-replica skipping. Introduce immutable ElectionMsg, ElectionAckMsg, and local ElectionAckTimeoutMsg objects. Add regression coverage and update the election sequence diagram to match the simplified message contract.
Implement ElectionTransaction with immutable election messages, candidate comparison, deterministic replica-ID tie-breaking, ring navigation, ACK timeouts, failed-replica skipping, and coordinator selection. Integrate election startup with heartbeat failure detection and Replica message dispatch. Add coordinator callbacks, synchronization messages carrying the authoritative positions snapshot, epoch advancement, and heartbeat restart after election completion. Extend regression coverage for candidate ordering, ring navigation, message immutability, ACK metadata, timeout metadata, and synchronization snapshots. Update the election sequence diagram to document the implemented protocol flow.
Reserve a separate transaction-ID namespace for elections so delayed ACKs and timeouts cannot be routed to heartbeat transactions. Schedule election startup according to ring distance, arbitrate concurrent election attempts by initiator ID, and reject losing election transactions. Increase ACK timeout coverage to include token forwarding and the return acknowledgement, preventing healthy replicas from being discarded prematurely. Update the election diagrams to document the arbitration and round-trip timeout behavior.
Reject malformed or stale election and synchronization messages before they can create invalid local transactions or poison a recovery term. Track the election transaction through synchronizing and completion, align the diagrams with forward-before-ACK ordering, and add regression coverage for forged, malformed, and invalid synchronization traffic.
alanmasu
self-requested a review
August 27, 2026 15:03
alanmasu
approved these changes
Aug 28, 2026
alanmasu
left a comment
Owner
There was a problem hiding this comment.
Only one comment, please add the Javadoc on the new functions/classes.
Comment on lines
+43
to
+55
| public ElectionTransaction( | ||
| TransactionId id, | ||
| DistributedActor owner, | ||
| EpochPair startEpochPair) { | ||
| super(id, owner, startEpochPair); | ||
| this.failedCoordinatorId = -1; | ||
| this.replicaRefs = Map.of(); | ||
| this.ringNavigation = null; | ||
| this.localInitiator = false; | ||
| this.unavailableReplicaIds = new HashSet<>(); | ||
| this.pendingTargetId = -1; | ||
| this.state = State.NEW; | ||
| } |
Owner
There was a problem hiding this comment.
This could diverge from the last constructor. BTW if this is provided only for compatibility with the super, please remove it.
Comment on lines
+57
to
+61
| public ElectionTransaction(TransactionId id, DistributedActor owner, EpochPair startEpochPair, | ||
| int failedCoordinatorId, Map<Integer, ActorRef> replicaRefs) | ||
| { | ||
| this(id, owner, startEpochPair, failedCoordinatorId, replicaRefs, true); | ||
| } |
Owner
There was a problem hiding this comment.
If not needed please remove all misleading and not fully functional constructors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the ring-based coordinator election flow and integrates it with heartbeat failure detection and coordinator recovery.
This PR targets:
What changed
Election protocol
ElectionTransactionas the local FSM owned by eachReplica.ElectionMsg,ElectionAckMsg,ElectionAckTimeoutMsg,ElectionStartMsg,ElectionRejectMsg, andSynchronizationMsg.EpochPair, then higher replica ID for equal pairs.ACKs, timeouts, and failures
Heartbeat handoff and recovery
SYNCHRONIZINGandDONE, and old election/heartbeat state is removed before the new heartbeat term starts.Tests and documentation
TestElectionTransactionwith coverage for candidate ordering, ring wraparound, skipped replicas, immutable payloads, invalid synchronization senders, invalid snapshots, malformed election identities, and term preservation after rejected input.Verification
gradle regressionpasses on the committed branch head.replicaReportsStartedElectionsandreplicaReportsElectedCoordinators.git diff --checkpasses.gradle staticAnalysiscompletes under the repository configuredignoreFailurespolicy.The callback-contract task still reports unrelated pre-existing failures for read and update callbacks. Those are outside this election-focused PR.
Scope note
This PR synchronizes the current authoritative positions snapshot and uses
EpochPairelection metadata. Full ordered update-history replay and incomplete-update recovery require the separateUpdateTransactionand history contract, and are intentionally not introduced here.