Public API to enumerate node-owned databases under managed event subscription distribution (#3340)#3345
Merged
Merged
Conversation
…subscription distribution (#3340) Under a MultiTenantedWithShardedDatabases Marten store with UseWolverineManagedEventSubscriptionDistribution, agent assignment is database-affine: a node only runs the daemon for the shard databases it owns. There was no first-class public way for application code (post-deploy readiness gates, per-node health checks) to discover that same subset, so per-pod components fanned out a connection pool to every shard database and exhausted a shared shard server. Adds: - EventSubscriptionAgentFamily.DatabaseIdOf(Uri): public, robust extraction of the shard DatabaseId from an event-subscriptions:// agent URI. Keeps the URI grammar in the family instead of forcing callers to re-implement the internal DatabaseKeyOf segment layout. - IAgentRuntime.AllLocallyOwnedDatabaseIds(): the distinct DatabaseId set whose event-subscription agents currently run on THIS node. Tests: fast unit coverage of DatabaseIdOf (per-tenant URI, realistic dotted-host sharded id round-trip, non-scheme and short-URI null cases) plus an end-to-end assertion in the two-database affine-colocation multi-node test that each node reports exactly its owned database and the two nodes partition the set. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 9, 2026
Merged
This was referenced Jul 13, 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 #3340.
Problem
Under a
MultiTenantedWithShardedDatabasesMarten store withUseWolverineManagedEventSubscriptionDistribution = true, agent assignment isdatabase-affine (#486/#487): each node only runs the projection/subscription
daemon for the shard databases it owns. But there was no public API for
application code to ask "which databases does the local node own?"
With one physical Postgres database per shard (the reporter runs ~490), a per-pod
component that needs to inspect only its own shards was forced to iterate all
databases — so every pod opened a connection pool to every shard and exhausted a
shared server (
53300: remaining connection slots are reserved...). The onlyworkaround re-implemented the internal
EventSubscriptionAgentFamily.DatabaseKeyOfagent-URI grammar by hand.
Change
EventSubscriptionAgentFamily.DatabaseIdOf(Uri)— public, robust extractionof the shard
DatabaseIdfrom anevent-subscriptions://agent URI. The URIgrammar stays in the family (mirrors the existing
UriFor/BuildAgentAsyncpair) instead of leaking to callers. Returns
nullfor non-scheme or malformedURIs.
IAgentRuntime.AllLocallyOwnedDatabaseIds()— the distinctDatabaseIdsetwhose event-subscription agents are currently running on this node. Replaces
the entire fragile workaround with one call.
The reporter's readiness gate becomes:
Tests
DatabaseIdOf: per-tenant URI, realistic dotted-host shardedid round-trip, non-scheme URI, and short-URI null cases.
multi-node integration test: each node reports exactly its one owned database,
matching its running agents, and the two nodes partition the full set.
Both green locally (
CoreTests+MartenTestsagainst docker Postgres).Notes / out of scope
The issue's "bonus" ask — a node-scoped projection-progress query — is store-specific
(Marten) and larger; this PR delivers the small, additive, transport-agnostic core
API that unblocks it. A caller can already build that query by intersecting
AllLocallyOwnedDatabaseIds()with the store's databases as shown above.🤖 Generated with Claude Code