Skip to content

Pin that removing a tenant from its shard takes its natural key rows - #5770

Merged
jeremydmiller merged 1 commit into
JasperFx:masterfrom
lahma:fix/remove-tenant-natural-key-rows
Oct 26, 2026
Merged

jeremydmiller merged 1 commit into
JasperFx:masterfrom
lahma:fix/remove-tenant-natural-key-rows

Conversation

@lahma

@lahma lahma commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

#5746 (#5742) made ShardedTenancy.RemoveTenantAsync delete a tenant's mt_natural_key_* rows before it drops the tenant's partitions, along with the two single-database removal paths. It noted that the sharded path had no test of its own because "the sharded fixtures do not build partitioned events". They do: ShardedPartitionedContext.BuildShardedStore sets UseTenantPartitionedEvents, and #5720's removing_a_tagged_tenant_from_its_shard runs on it.

New file: TenantPartitionedEventsTests/Sharded/removing_a_tenant_with_natural_keys_from_its_shard.cs. Two tenants with a [NaturalKey] stream share one shard, and RemoveTenantFromShardAsync removes one of them. The removed tenant's natural-key rows go; the other tenant's row, and its FetchLatest by natural key, survive. No production code changes.

Red on 3e77b1dfc (master just before #5746 merged): 23503: removing partition "mt_streams_rmnk_alpha" violates foreign key constraint "mt_natural_key_shardedremovalcase_stream_id_tenant_id_fkey". Green on master 1d65a1a2d. TenantPartitionedEventsTests: 287 passed, 2 skipped, 0 failed (net10.0, PostgreSQL 17).

🤖 Generated with Claude Code

JasperFx#5746 (JasperFx#5742) made ShardedTenancy.RemoveTenantAsync delete a tenant's
mt_natural_key_* rows before it drops the tenant's partitions, alongside the two
single-database removal paths, and noted that the sharded path had no test of its
own. This adds one: two tenants with a [NaturalKey] stream on one shard, then
RemoveTenantFromShardAsync. The removed tenant's natural key rows go, and the
other tenant's row and lookup survive.

It fails on 3e77b1d, master just before JasperFx#5746 merged, with
23503: removing partition "mt_streams_rmnk_alpha" violates foreign key constraint
"mt_natural_key_shardedremovalcase_stream_id_tenant_id_fkey", and passes on master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeremydmiller
jeremydmiller merged commit 82487f2 into JasperFx:master Oct 26, 2026
32 checks passed
@lahma
lahma deleted the fix/remove-tenant-natural-key-rows branch October 26, 2026 20:21
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.

2 participants