Skip to content

feat(storage): support single-shard transactions on the in-process Raft adapter - #407

Merged
ashione merged 3 commits into
mainfrom
feat/393-replicated-transactions
Nov 25, 2026
Merged

ashione merged 3 commits into
mainfrom
feat/393-replicated-transactions

Conversation

@ashione

@ashione ashione commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Summary

Refs #393. Implement the write-only single-shard transaction contract on the in-process Raft adapter. Begin captures the committed sequence after a leader read barrier. Commit sends one conditional D1V1 batch with the original epoch, sequence and request ID.

Contract and scope

Local and replicated adapters share the bounded staging buffer. A staging error discards the accepted prefix. Abort and drop discard all staged operations. Failed admission and sequence conflicts remain explicit. A timeout after Raft submission returns UnknownOutcome with the original request ID, and the caller does not automatically replay the batch. The existing log and storage formats are unchanged.

Remote and routed transaction entry points, independent-process crash/restart coverage and recovery of the original commit outcome remain open in #393. The README, transaction contract, current status and roadmap describe the supported entry points. This PR adds no CLI or graph query syntax.

Verification

On PR head cfeab68, with Rust 1.100.0 on macOS:

  • cargo test --locked -p replicated-graph --test cluster staged_transaction passed both new three-voter tests. After leader change the new leader sees the complete winning batch and no keys from rejected or aborted transactions. When state-machine application is paused after staging, commit can time out and the entire batch can subsequently appear once.
  • cargo fmt --all --check, cargo clippy --all-targets --locked -- -D warnings and git diff --check HEAD~2 HEAD passed.
  • The full workspace run on 3bdf8fa used cargo test --locked --no-fail-fast and passed 1,445 tests across 98 targets, with 0 failures and 47 ignored. Local validation dynamically linked RocksDB from the locked build to limit disk usage. The rebase onto docs: align recovery, transaction and benchmark evidence with main #406 and the subsequent status update changed only documentation, verified by diffing the two revisions.

@ashione ashione left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two inline notes on the in-process transaction contract: admission on managed shards and coverage for a timeout before Raft handoff.

let end = options.deadline.min(self.dispatch_deadline()?);
let sequence = self.dispatch_until(None, end, async move {
leader_barrier(&raft).await?;
checked_sequence(&state, shard, epoch).await

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Reject already-managed shards at begin_v1. This barrier and metadata read checks shard, epoch, and sequence, but not the write mode. A managed shard can therefore return a usable-looking handle and accept the entire staged batch, even though D1Command::Write will reject it with ManagedWriteRequired at commit. Could we check the mode in the same state read as the sequence and return Unsupported here? Keep the existing apply-time check for mode changes after begin.

if let Err(error) = options.check() {
return Ok(Err(error));
}
if submission.swap(true, Ordering::AcqRel) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Cover the timeout-before-handoff branch. The new paused-apply test covers UnknownOutcome after handoff. Please add a deterministic test for the other side of this race: gate the worker before it claims submission, let the caller deadline close the window, then release or drain the worker and verify that the shard sequence is unchanged and neither staged key exists. This would pin down the no-late-write guarantee; no failure is known on this path.

@ashione
ashione merged commit 570c3e3 into main Nov 25, 2026
16 checks passed
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.

1 participant