Skip to content

fix: guarantee sequential consistency across recovery - #99

Open
Tech-Matt wants to merge 38 commits into
mainfrom
fix/sequential-consistency
Open

fix: guarantee sequential consistency across recovery#99
Tech-Matt wants to merge 38 commits into
mainfrom
fix/sequential-consistency

Conversation

@Tech-Matt

Copy link
Copy Markdown
Collaborator

Summary

main did not guarantee the sequential consistency required by specs/ds1_project_2026_v1.pdf: reads were unimplemented there, the update and election protocols were still separate, update identities were not stable, and coordinator recovery could fork or lose the committed prefix.

This PR:

Correctness argument

  1. Client serializes each client's operations through one current transaction and a FIFO queue.
  2. The coordinator actor reserves update pairs in mailbox order.
  3. Per-channel FIFO ensures each participant receives update A before B and returns ACK A before ACK B.
  4. Therefore B cannot obtain a strict-majority quorum before A obtains the same quorum, so the coordinator sends WRITEOK A before WRITEOK B.
  5. Coordinator-to-replica FIFO makes every correct replica apply a prefix of that same order.
  6. After coordinator failure, election selects the longest applied EpochPair, synchronizes one common prefix, and only then continues in a higher epoch.

The report gives the complete proof and explicitly separates this safety result from assumptions about bounded delay, strict-majority availability, and reasonable client timeouts.

Validation

Run with an isolated Gradle home because the machine's default Gradle home could not load its native platform library:

GRADLE_USER_HOME=/tmp/coredump-gradle-home gradle compileJava compileTestJava --no-daemon
GRADLE_USER_HOME=/tmp/coredump-gradle-home gradle test --tests it.unitn.ds.TestSequentialConsistency --no-daemon
GRADLE_USER_HOME=/tmp/coredump-gradle-home gradle regression --no-daemon
GRADLE_USER_HOME=/tmp/coredump-gradle-home gradle test --no-daemon
GRADLE_USER_HOME=/tmp/coredump-gradle-home gradle staticAnalysis --no-daemon
git diff --check origin/main...HEAD

Results:

  • compilation: passed;
  • focused sequential-consistency tests: 4/4 passed;
  • regression task: passed;
  • complete test suite: 80/80 passed;
  • static-analysis task: BUILD SUCCESSFUL with 0 errors, 42 warnings, 2 informational findings, 2 duplication findings, and 0 formatting findings;
  • full PR diff check: passed.

The non-error static-analysis findings are principally in the integrated election implementation and do not block the build. Reports are generated under build/reports/.

Integration note

Because main did not yet contain the read, update, or election state machines needed to establish this end-to-end property, this PR includes the live work from #83, #86, and #97. Those PRs should not be merged independently without reconciling their history with this branch.

alanmasu and others added 30 commits August 17, 2026 01:24
…saction

* Continued the intrgration of the `UpdateTransaction` with the system,
* Fixed initialization of `HeartbeatTransaction`'s `TransactionId` to use the proper `Replica` method
* Created the `TestUpdateTransaction` class to test the `UpdateTransaction` functionality, this test:
    - a basic write operation issued to a non-coordinator replica
    - a basic write operation issued to a non-coordinator replica that is crashed, expecting a timeout response
    - a basic write operation issued to a non-coordinator replica followed by a crash of the coordinator replica, expecting a timeout response
* Corrected the `transaction_Write.mmd` chart to be compliant to the implementation

Fixes #55, Related to #59, #60, #61
I've fixed the destination provided when the `UpdateTransaction` is issued on the replicas that dosn't initiated the transaction.

Corrected also the test to ensure this behaviour
Reordered the replica cases to check first if the replica is the coordinator or not.
…RDINATOR_BEAT_INTERVAL`

I changed the original function to use a parameter for the heartbeat interval instead the class constant.
This is to speedup tests, infact having an interval of 1s could result in really long tests timings
Before, if a `WriteTransaction` is issued on the coord directly would fail due to non complete termination protocol. Now is fixed

Fixes #89
- Now each replica contains a `Map<EpochPair, UpdateTransactio>` where the updates are stored.
- Each `Replica` epochPair is updated after the each update
…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.
Tech-Matt and others added 8 commits August 26, 2026 22:40
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.
There was no call to `replica.setPosition(int, int)`
…sg and improved test cases for crash scenarios
…/sequential-consistency

# Conflicts:
#	src/main/java/it/unitn/ds/Replica.java
…o fix/sequential-consistency

# Conflicts:
#	src/main/java/it/unitn/ds/Replica.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants