Repository navigation
[9.0] Weasel 9.51.0: SetFloor race fix (#5998) and synchronous single-server tenant resolution (#5985) - #6013
Merged
Merged
Conversation
…-server tenant resolution (#5985) Weasel.Postgresql, Weasel.Storage and Weasel.EntityFrameworkCore 9.50.0 -> 9.51.0. #5998: weasel#853 serializes HiloSequenceBase.TrySetCurrentHi with NextLong, so HiloSequence.SetFloor waits for an advance in flight instead of having that advance install a block from below the new floor after SetFloor returned. No Marten code change; Bug_5998_set_floor_race is the regression test (red on 9.50.0, next ids 4, 1005, ...; green on 9.51.0). #5985 (single server half of #6001): SingleServerMultiTenancy.GetTenant resolves an uncached tenant through Weasel's FindOrCreateDatabaseSynchronously (weasel#843) instead of blocking a pool thread on FindOrCreateDatabase. Ports the two SingleServerMultiTenancyTests cases and the single-server thread-pool starvation test from master, and updates the multitenancy docs table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
This was referenced Nov 16, 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.
Part of #5985
Fixes #5998 on the 9.x line
Adopts Weasel 9.51.0 (weasel#858) on the 9.0 branch:
Weasel.Postgresql,Weasel.StorageandWeasel.EntityFrameworkCore9.50.0 -> 9.51.0. Both Weasel changes are additive, with no DDL and no migration-output change.#5998: SetFloor race (weasel#853, for weasel#849)
HiloSequenceBase.TrySetCurrentHinow takes the same lock asNextLong.HiloSequence.SetFloorinstalls through it, so it waits for an advance in flight and installs after it. Before, an advance that had reserved its block under the old floor installed that block on top of the floor's afterSetFloorreturned, and ids below the floor followed. No Marten code change.Master's
hilo_set_floor_race_testsrelies on HiLo prefetch hooks that 9.0 does not have, so this adds a new test,Bug_5998_set_floor_race:HiloSequencesubclass (MaxLo 2) reserves every hi from the database throughmt_get_next_hi. It holds one synchronous advance between its reservation (hi 1) and its install, insideNextLong's lock.SetFlooris Marten's own.SetFloor(1000)runs on another thread. The test releases the held advance only onceSetFloorhas either returned (Weasel 9.50.0) or is blocked on its first install (9.51.0). "Blocked" means an install has started, has not finished, and its thread is inWaitSleepJoin. The test polls that condition. It does not sleep for a guessed interval, and every wait has a 10 second timeout.Red/green, net10.0, DocumentDbTests in Release:
SetFloor(1000)returned were4, 1005, 1006, 1007, 1008, 1009#5985: synchronous single-server tenant resolution (weasel#843, for weasel#839)
This ports the single-server half of master's #6001.
SingleServerMultiTenancy.GetTenantnow resolves an uncached tenant through Weasel'sFindOrCreateDatabaseSynchronously. Before, it blocked a pool thread onFindOrCreateDatabase(...).AsTask().GetAwaiter().GetResult(). The new method falls back to blocking on the asynchronous path only when the master connection string turns onMultiplexing.Tests ported from master:
SingleServerMultiTenancyTests.build_mapped_tenants_synchronouslySingleServerMultiTenancyTests.build_tenant_synchronously_when_the_master_connection_is_multiplexedsync_tenant_resolution_thread_pool_tests.a_burst_of_sync_session_opens_for_uncached_single_server_tenants_does_not_starve_the_thread_pool, with itsSingleServerDatabaseshelper9.0's master-table tests in that file are unchanged, because 9.0 fixed
MasterTableTenancyin Marten itself (#5988).The starvation test fails with
SingleServerMultiTenancy.csreverted to 9.0's version and Weasel left at 9.51.0: 88 callers starved the thread pool for 2,590 ms against a 500 ms limit. With the change it passes.The docs table "First synchronous resolution of a tenant" in
docs/configuration/multitenancy.mdnow describes the single-instance row as synchronous I/O, as on master. The paragraph after the table also changes: it no longer says single-instance callers block, and it describes the one-at-a-time resolution with its 5 secondTimeoutException. markdownlint and cspell are clean on that file.Verification (local, PostgreSQL 17, net10.0)
dotnet build src/Marten.slnx -c Release(net9.0 and net10.0): 0 errorsDocumentDbTests.Writing.Identity.Sequences: 52 of 52 passed, includinghilo_tests(10 of 10) and the new testSingleServerMultiTenancyTests: 16 of 16 passedsync_tenant_resolution_thread_pool_tests: 3 of 3 passed, in two runssync_master_table_tenant_resolution_with_multiplexing: 1 of 1 passed🤖 Generated with Claude Code