Skip to content

feat(6o-i): a capable replica applies each transaction group atomically (PR 4) - #198

Merged
akosidencio merged 15 commits into
devfrom
feat/v0.6o-i-replica-atomic-apply
Nov 26, 2026
Merged

akosidencio merged 15 commits into
devfrom
feat/v0.6o-i-replica-atomic-apply

Conversation

@akosidencio

Copy link
Copy Markdown
Member

Phase 6O-I, PR 4: a capable replica applies each transaction group atomically. Design #195, §6.4–§6.5.

Stacked: this branch merges #196 (PR 2) and #197 (PR 3). Its own changes are the commits after those merges: 6c4b89f, cc58268 and 02d01bb. It stays a draft until #196 and #197 merge.

Review C: APPROVED in round 2. Round 1 was APPROVED WITH CHANGES, with one High (H1) and one Medium (M1); both are fixed and confirmed by the reviewer, who checked that reverting either fix makes its new test fail.

Changes

  • Atomic apply. apply_repl_group parses and checks every member, takes one lock_commands for the group, checks still_following once, then runs KeyValueStore::apply_transaction. That is the primary's own 6O-G boundary, run inside without_expiry for expirylog1. Readers of a replica never see part of a group.
  • Effects. They run in member order: one group into this node's AOF, one group to its sub-replicas (on_group_logged, fan_out_group), then WATCH/QSUB notifications coalesced exactly as EXEC's (notify_replicated_group reuses NotificationPlan; review C H1), then pushes.
  • Failure. A member that fails or panics stops the rest. The node then:
    • latches persistence when it has an AOF;
    • resets its stream, so sub-replicas take a full sync, even if this node is promoted first (review C M1 / review D D-1);
    • resynchronizes its sync clients;
    • tells watchers;
    • ends the link with a protocol error, which forces a full sync.

Tests

tests/replica_atomicity_6oi.rs:

  • Every read kind blocks inside a paused group apply.
  • The baseline reproduction, extended to 3 store readers, sequential GET pairs, a client reader and overlapping transactions. It saw 380–518 part-applied MGETs per run on the previous per-member path; none now.
  • The replica's own AOF group and a restart.
  • A three-level relay.
  • Failure and panic, each with and without an AOF.
  • Review C's delta live query and set-then-remove WATCH cases.
  • A failed group on a promoted middle replica.
  • A check that a frame's fixed cost fits the per-frame charge.

…ly (PR 4)

apply_repl_group parses and checks every member first, takes the
replication-order stripes of all of them once, checks the node still
follows, then runs them through KeyValueStore::apply_transaction, the
primary's own 6O-G boundary (inside without_expiry for an expirylog1
stream): one hold of the group's store stripes, marked, from its first
member to its last. Readers of the replica (GET, MGET, EXISTS, TYPE,
STRLEN, a client's borrowed reads) wait for or validate across it and
never see part of a group. The first member that fails stops the rest;
a failure or a panic ends the link with a protocol error (a full sync),
latching persistence unhealthy only when there is an AOF. Then the
effects: this node's AOF takes the group as one group, its sub-replicas
get it with fan_out_group, then notifications and pushes per member.

Design: benchmarks/v0.6.0/6o-i/V0.6O-I-PROTOCOL-DESIGN.md §6.4-§6.5.
…imary's; a failed group converges every copy

- C H1: a replica announces a group's keys through EXEC's own
  NotificationPlan (notify_replicated_group): each key once, at its last
  change, as its full value when the group changed it more than once, as
  removed_after_set when it was set then removed, FLUSHDB as the primary
  does. Whether a member removed its keys is decided right after it ran,
  inside the hold. Before, each member was announced after the whole group
  with its own delta: a delta live query ended with "abb" for SET a,
  APPEND b.
- C M1 / D D-1: a group that fails or panics part-way resets this node's
  stream (sub-replicas take a full sync from a new run id, also if it is
  promoted first), closes its sync clients to rebuild and tells watchers
  the keyspace changed, as the primary's converge does.
- C L2: the relay takes the group's frames without another copy
  (on_group_logged).
- C L3: why the effects step is not cancellation-safe, and why that is
  acceptable.
- C L1: tests for the delta live query, a WATCH invalidated by set-then-
  remove, a failed group on a middle replica promoted before it reconnects,
  and a failed group with an AOF (latch, prefix kept until the full sync).
@akosidencio
akosidencio merged commit 8b4c1f7 into dev Nov 26, 2026
12 of 13 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