Repository navigation
[9.0] ShardedTenancy: never reassign an already-assigned tenant when its shard isn't loaded (#5995) - #5997
Merged
Conversation
…ard isn't loaded (#5995) A store that was given no AddDatabase() and had not run BuildDatabases() did not find an assigned tenant's shard in its local cache. findOrAssignTenantDatabaseAsync then treated the tenant as new under the advisory lock, re-ran the assignment strategy and overwrote the assignment row with "on conflict do update", leaving the tenant's data behind on the old shard without a word. An existing assignment is now final on both checks, before and under the lock: the assigned shard is loaded from the pool table the way BuildDatabases loads it, and the strategy runs only for a tenant with no assignment row at all. When the pool no longer has the assigned shard, the new AssignedShardNotFoundException names the tenant and the shard instead of moving the tenant. The same defect let two processes resolving one new tenant disagree: the lock serialized them, but the second did not have the first's shard cached and reassigned the tenant to its own pick. The race test covers that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit e7dc0ac)
Merged
This was referenced Nov 16, 2026
This was referenced Nov 24, 2026
This was referenced Nov 26, 2026
Closed
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.
Backport of #5996
Fixes #5995 on the 9.0 branch. This is the master commit cherry-picked with
-x, thenorigin/9.0merged in.ShardedTenancy.cswas identical on both branches before the fix, so the cherry-pick applied cleanly.The details are in #5996. In short: an existing assignment row is now never overwritten by re-running the assignment strategy. When the assigned shard isn't cached locally (no
AddDatabase, noBuildDatabases), it's loaded from the pool table. When the pool no longer has the shard, the newAssignedShardNotFoundExceptionnames the tenant and the shard.Evidence on this branch (net10.0, database
marten_9_5995)Bug_5995_sharded_existing_assignment_is_never_reassigned, with the fix reverted: 5 of 7 failed (the row moved from_ato_b, the racing stores disagreed, no exception for the missing shard)TenantPartitionedEventsTests.Sharded: 44/44🤖 Generated with Claude Code