Fix #4681 — centralize high-water progression-row identity in a Marten helper#4689
Merged
Merged
Conversation
…ten helper
The high-water grammar is intentionally asymmetric to the rest of JasperFx.Events'
ShardName (which collapses HighWaterMark identities to the constant -- the tenant
slot is discarded). Marten layers per-tenant high-water tracking on top by writing
one row per tenant under the convention `"{HighWaterMark}:{tenantId}"`, but until
now the convention was hand-rolled at several SQL sites:
* HighWaterDetector.loadPerTenantStatistics — `ShardState.HighWaterMark + ":"`
fed as a `:prefix` parameter and concatenated `prog.name = :prefix || tenant_id`
inside SQL.
* HighWaterStatisticsDetector — the literal `'{ShardState.HighWaterMark}'` in
SQL for the store-global progression-row name.
* BulkEventAppender.updateHighWaterMark — the bare literal `'HighWaterMark'`
for the store-global UPSERT.
Any future grammar change (separator, version segment, escape rule) would have
to be hunted down across every one of these sites.
New `Marten.Events.Daemon.HighWater.HighWaterShardIdentity` is the single source
of truth for these names:
* `StoreGlobal` — the literal store-global name (= ShardState.HighWaterMark)
* `PerTenantPrefix` — `"HighWaterMark:"`, for SQL-side concat-style joins
* `PerTenant(tenantId)` — the full identity for a tenant's row
All three call sites now reference the helper. The comment in EventProgressionTable
that describes the per-tenant naming convention now points at the helper as the
authoritative producer. JasperFx-side `ShardName` retains its existing collapsing
behavior -- no API change there, just a Marten-side hygiene refactor.
Six unit-test cases in CoreTests pin the round-trip: StoreGlobal == constant,
PerTenantPrefix shape, PerTenant() = prefix+id, and a "matches the HighWaterDetector
SQL join" pin so any future drift between the helper and the SQL gets caught by an
already-failing test.
DaemonTests (188/188) and TenantPartitionedEventsTests (177/177) pass against the
refactor on net9.0. No behavior change -- byte-identical SQL output, same
progression-row names, same `mt_event_progression` keying.
Closes #4681.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Jun 10, 2026
Merged
This was referenced Jun 17, 2026
This was referenced Jun 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4681.
The per-tenant high-water grammar is intentionally asymmetric to the rest of
JasperFx.Events'ShardName(which collapsesHighWaterMarkidentities to the constant — the tenant slot is discarded). Marten layers per-tenant high-water tracking on top by writing one row per tenant under the convention"{HighWaterMark}:{tenantId}", but until now that convention was hand-rolled across three sites:HighWaterDetector.loadPerTenantStatisticsShardState.HighWaterMark + ":"fed as a:prefixparameter, joinedprog.name = :prefix || tenant_idin SQLHighWaterStatisticsDetector'{ShardState.HighWaterMark}'baked into the SQLBulkEventAppender.updateHighWaterMark'HighWaterMark'literal in the UPSERTAny future grammar change (separator, version segment, escape rule) would have to be hunted down across all of them.
What ships
New
Marten.Events.Daemon.HighWater.HighWaterShardIdentityis the single source of truth:StoreGlobalShardState.HighWaterMark)PerTenantPrefix\"HighWaterMark:\", for SQL-side concat-style joinsPerTenant(tenantId)All three call sites now reference the helper. The comment in
EventProgressionTablethat describes the per-tenant naming convention points at the helper as the authoritative producer.No behavior change. Byte-identical SQL output, same progression-row names, same
mt_event_progressionkeying.JasperFx.Events'ShardNameis unchanged.Tests
CoreTests/Events/Daemon/HighWaterShardIdentity_round_trip.cspin the round-trip —StoreGlobal == constant, thePerTenantPrefixshape,PerTenant() = prefix + idacross several tenant-id forms, and a "matches the HighWaterDetector SQL join" pin so any future drift between the helper and the SQL is a failing test.Followups left in #4681
The issue mentions a JasperFx-side companion that would let
ShardName.Compose(\"HighWaterMark\", tenantId: …)produce the per-tenant identity directly (instead of collapsing). That stays as the JasperFx-side hand-off; this PR is just the Marten-side hygiene refactor it asked for.🤖 Generated with Claude Code