Skip to content

GH-684 Composite projections: opt-in KeepUnchangedMembers keeps unchanged members' documents and progress across a version bump - #1290

Merged
jeremydmiller merged 1 commit into
mainfrom
gh-684-composite-keep-unchanged-members
Nov 24, 2026
Merged

jeremydmiller merged 1 commit into
mainfrom
gh-684-composite-keep-unchanged-members

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Part of #684: the JasperFx side. The design is in #684 (comment). The store halves are marten#5247, polecat#490 and fisher#109, so #684 stays open until they land.

What it does

A composite's members already have their own identity: ProjectionStage.MemberShardName names each one member:V{member.Version}, and each writes its own progression row in the composite's batch. This PR makes those rows count.

  • CompositeProjection.KeepUnchangedMembers (opt-in, default false). Turn it on, then bump both the member you changed and the composite. The composite replays from 0. Before its first range, the composite execution reads each member's own row. A member whose row is ahead of the composite's floor is kept through that position: ranges at or below it do nothing for that member (no apply, no progress write), and a straddling range hands it only the later events, with its floor at its own row, so a store's "update where at floor" progress write matches. Members that changed have no row for their new version, so they replay in the same pass. Once past the window, every member is in lockstep again.
  • Single-stage only. A later stage reads the in-flight output of the stages before it, which a kept member wouldn't produce. A multi-stage composite with the flag on replays every member, as now, and logs one warning saying why. The property's docs say that turning it on also asserts that no member enriches from a sibling member's stored documents (the time-dependence hazard in the issue).
  • CompositeProjection.MembersToTearDownAsync(IEventDatabase, ShardName? parent, CancellationToken): the members a store's rebuild teardown should tear down. That's all of them unless the flag applies, in which case a member whose row is ahead of the composite's own row is left out. So a rebuild after a bump keeps the unchanged members, while a rebuild with no bump (everything in lockstep, i.e. a repair) still tears down and rebuilds every member.

Binary compatibility

Strictly additive:

  • a new property on CompositeProjection, and a new public async method;
  • ExecutionStage.ExecuteDownstreamAsync(EventRange, IReadOnlyDictionary<ISubscriptionExecution,long>?) as a new overload; the existing one-argument method now forwards to it;
  • an internal init property on CompositeExecution;
  • in JasperFx.Events.ComplianceTests, a default-throwing IComplianceCompositeBuilder.KeepUnchangedMembers() and a SupportsKeepingUnchangedCompositeMembers fixture flag that defaults to false.

No signature changed. With the flag off, the execution reads no extra progression rows and every member processes every range exactly as before.

Tests

  • EventTests/.../CompositeKeepUnchangedMembersTests (10 tests), using a progression table that mirrors Marten's insert-at-0 / update-at-floor rule:
    • a kept member skips the replay up to its row, then resumes from it;
    • a straddling range is trimmed;
    • lockstep members aren't kept;
    • with the flag off, no member row is read;
    • the composite passes the setting down to its executions;
    • multi-stage composites don't keep members;
    • teardown: all members by default, the kept ones left out after a bump, everything on a repair rebuild, everything for multi-stage.
  • JasperFx.Events.ComplianceTests: a new CompositeKeepUnchangedMembersCompliance suite, marked [RequiresCapability("SupportsKeepingUnchangedCompositeMembers")], so a store that hasn't adopted this is excused from the enrollment check automatically. It's the store-side proof: after a simulated bump (the composite's own row deleted), a rebuild leaves the kept members' documents untouched, and a rebuild with no bump still rebuilds every member. Each store enrolls it when it implements teardown through MembersToTearDownAsync.

What each store changes

As in the design comment:

  • Teardown: tear down only MembersToTearDownAsync, and keep a kept member's documents and progression row.
  • Compliance: implement KeepUnchangedMembers() on the compliance builder and flip the fixture flag.

Gate

The full local gate (stoat gate exec critter-stack-net11-rc/gate-slot-jasperfx -- ./build.sh Test) is green on this commit. It ran after the #1287 gate, never at the same time.

🤖 Generated with Claude Code

…s that did not change keep their documents and progress

Each member already runs under its own progression row, named for its own
version. With KeepUnchangedMembers on (single-stage composites only), a
member whose row is ahead of the composite's position skips the replay
up to it, and MembersToTearDownAsync tells a store's rebuild teardown to
leave such members standing. Off by default: no row is read and every
member replays, as before. Strictly additive: a new property, a new
ExecutionStage overload, a new async method, and a gated compliance
suite with a default-throwing builder member.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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