Skip to content

feat(raft): add nested transaction and CAS support#111

Merged
slow2342 merged 1 commit into
mainfrom
feat/txn-cas
Jun 11, 2026
Merged

feat(raft): add nested transaction and CAS support#111
slow2342 merged 1 commit into
mainfrom
feat/txn-cas

Conversation

@slow2342

Copy link
Copy Markdown
Owner

Summary

Add compare-and-swap (CAS) transaction support with nested Txn capability. Switch RaftRequest/RaftResponse serialization from rkyv to bincode to enable recursive types. Fix several bugs discovered during implementation review.

Changes

  • Cargo.toml — Add bincode = "1" dependency.
  • proto/kv.proto — Add TxnRequest txn / TxnResponse txn to RequestOp / ResponseOp for nested Txn proto support.
  • src/raft/mod.rs — Remove rkyv derives from all raft types, keep serde only. Add TxnRequest, TxnResponse structs. Add Request::Txn(Box<TxnRequest>) and Response::Txn(Box<TxnResponse>) variants.
  • src/raft/raftrs_handle.rs — Switch RaftRequest/RaftResponse serialization from rkyv to bincode.
  • src/raft/state_machine.rs — Switch deserialization to bincode. Extract evaluate_compare method. Implement nested Txn execution sharing parent's WriteBatch for atomicity. Fix TxnSnapshot::rollback() lease reconciliation order. Fix Get/Range/compare within Txn to read from value_cache for uncommitted values.
  • src/api/kv.rs — Extract convert_compares, convert_response_ops, convert_kv helpers. convert_request_ops becomes fallible with MAX_TXN_DEPTH=1 depth limit. Add recursive check_txn_ops_permissions for nested Txn auth. Add raft::Response::Txn handling in response conversion.
  • src/auth/role.rsextract_txn_keys recursively handles nested Txn.

Testing

  • 15 new CAS tests covering all compare targets (Version, Value, Create, Mod, Lease), all compare results (Equal, NotEqual, Greater, Less), multi-compare, failure branch, nonexistent key, Get/Delete in success branch.
  • 2 new nested Txn tests: basic nested execution and uncommitted value read in nested compare.
  • All 74 tests pass, clippy clean, fmt clean.

How to verify

cargo build
cargo test -p aether --lib
cargo clippy -- -D warnings
cargo fmt -- --check

Related issues

Refs #82

Switch RaftRequest/RaftResponse serialization from rkyv to bincode to
support recursive Txn types. Add Request::Txn/Response::Txn variants
with nested Txn execution in the state machine sharing WriteBatch for
atomicity.

Fixes:
- rollback() lease reconciliation order (reconcile before restore)
- Txn Get/Range/compare reads uncommitted values from value_cache
- Nested Txn auth check recursively validates sub-operations
- MAX_TXN_DEPTH=1 at API boundary prevents stack overflow

Add 15 CAS tests + 2 nested Txn tests covering all compare targets,
results, failure branches, and uncommitted value reads.
@slow2342
slow2342 merged commit 90cee00 into main Jun 11, 2026
5 of 7 checks passed
@slow2342
slow2342 deleted the feat/txn-cas branch June 11, 2026 10:58
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