Skip to content

[9.0] Weasel 9.51.0: SetFloor race fix (#5998) and synchronous single-server tenant resolution (#5985) - #6013

Merged
jeremydmiller merged 1 commit into
9.0from
weasel-9.51-on-9.0
Nov 16, 2026
Merged

jeremydmiller merged 1 commit into
9.0from
weasel-9.51-on-9.0

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

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.Storage and Weasel.EntityFrameworkCore 9.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.TrySetCurrentHi now takes the same lock as NextLong. HiloSequence.SetFloor installs 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 after SetFloor returned, and ids below the floor followed. No Marten code change.

Master's hilo_set_floor_race_tests relies on HiLo prefetch hooks that 9.0 does not have, so this adds a new test, Bug_5998_set_floor_race:

  • A HiloSequence subclass (MaxLo 2) reserves every hi from the database through mt_get_next_hi. It holds one synchronous advance between its reservation (hi 1) and its install, inside NextLong's lock. SetFloor is Marten's own.
  • SetFloor(1000) runs on another thread. The test releases the held advance only once SetFloor has 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 in WaitSleepJoin. The test polls that condition. It does not sleep for a guessed interval, and every wait has a 10 second timeout.
  • It asserts that the advance in flight keeps its old id (3), and that the next six ids are all above 1000 and strictly increasing.

Red/green, net10.0, DocumentDbTests in Release:

Weasel Result
9.50.0 Failed 3 of 3 runs. The ids after SetFloor(1000) returned were 4, 1005, 1006, 1007, 1008, 1009
9.51.0 Passed 5 of 5 runs, about 400 ms each, so the timeout path was never taken

#5985: synchronous single-server tenant resolution (weasel#843, for weasel#839)

This ports the single-server half of master's #6001. SingleServerMultiTenancy.GetTenant now resolves an uncached tenant through Weasel's FindOrCreateDatabaseSynchronously. Before, it blocked a pool thread on FindOrCreateDatabase(...).AsTask().GetAwaiter().GetResult(). The new method falls back to blocking on the asynchronous path only when the master connection string turns on Multiplexing.

Tests ported from master:

  • SingleServerMultiTenancyTests.build_mapped_tenants_synchronously
  • SingleServerMultiTenancyTests.build_tenant_synchronously_when_the_master_connection_is_multiplexed
  • sync_tenant_resolution_thread_pool_tests.a_burst_of_sync_session_opens_for_uncached_single_server_tenants_does_not_starve_the_thread_pool, with its SingleServerDatabases helper

9.0's master-table tests in that file are unchanged, because 9.0 fixed MasterTableTenancy in Marten itself (#5988).

The starvation test fails with SingleServerMultiTenancy.cs reverted 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.md now 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 second TimeoutException. 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 errors
  • DocumentDbTests, namespace DocumentDbTests.Writing.Identity.Sequences: 52 of 52 passed, including hilo_tests (10 of 10) and the new test
  • MultiTenancyTests SingleServerMultiTenancyTests: 16 of 16 passed
  • MultiTenancyTests sync_tenant_resolution_thread_pool_tests: 3 of 3 passed, in two runs
  • MultiTenancyTests sync_master_table_tenant_resolution_with_multiplexing: 1 of 1 passed

🤖 Generated with Claude Code

…-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>
@jeremydmiller
jeremydmiller merged commit 0151b94 into 9.0 Nov 16, 2026
32 checks passed
@jeremydmiller
jeremydmiller deleted the weasel-9.51-on-9.0 branch November 16, 2026 18:34
@jeremydmiller jeremydmiller mentioned this pull request Nov 16, 2026
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