Skip to content

Make EventSubscriptionAgentFamily.DatabaseKeyOf public #3819

Description

@jeremydmiller

EventSubscriptionAgentFamily.DatabaseKeyOf (src/Wolverine/Runtime/Agents/EventSubscriptionAgentFamily.cs:327) is internal, so anything outside Wolverine that wants to group event-subscription agents by the database they belong to has to re-implement the agent URI grammar.

internal static string DatabaseKeyOf(Uri uri)
    => uri.Segments.Length >= 3
        ? $"{uri.Host}/{uri.Segments[1].Trim('/')}/{uri.Segments[2].Trim('/')}"
        : uri.AbsoluteUri;

That grammar is exactly what group affinity keys on when distributing agents, so a consumer reasoning about agent placement per database — a test asserting co-location, an admin view, a readiness probe — needs the same key, and today can only get it by copying it.

This is already happening inside this repo

src/Persistence/MartenTests/MultiTenancy/blue_green_version_bump_assignment.cs:221-226 copies the implementation verbatim:

// The (type, name, databaseId) prefix of an agent URI, mirroring the internal
// EventSubscriptionAgentFamily.DatabaseKeyOf that group affinity keys on.
private static string DatabaseKeyOf(Uri uri) =>
    uri.Segments.Length >= 3
        ? $"{uri.Host}/{uri.Segments[1].Trim('/')}/{uri.Segments[2].Trim('/')}"
        : uri.AbsoluteUri;

while its sibling tests (sharded_two_databases_affine_colocation.cs:150, durability_projection_affinity_real_stores.cs:124) call the internal directly. So the duplication the request is about already exists in Wolverine's own test suite, and a copy can silently drift from the real distribution key it's supposed to mirror.

Ask

Make DatabaseKeyOf public. TenantNeutralKeyOf (:351) is worth considering in the same pass — it's the supersession relation's key and already has full XML docs written as if it were public, and CoreTests reaches for it too (src/Testing/CoreTests/Runtime/Agents/event_subscription_family_cardinality_assignment.cs:373).

Consistent with the existing position that consumers should not hand-build event-subscription agent URIs but call the public helpers — this is the read side of the same rule.

Raised from marten#5170, whose reporter runs a 512-shard-database deployment and hit this writing a test that reasons about agent placement per database.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions