Skip to content

Weasel.SqlServer: managed dynamic per-tenant partitioning API (parity with Weasel.Postgresql ManagedListPartitions) #301

Description

@jeremydmiller

Background

Weasel.SqlServer currently ships only RangePartitioning (ISqlServerPartitioning) with static, migration-time boundaries (additive ALTER PARTITION FUNCTION ... SPLIT RANGE). There is no managed/dynamic per-tenant partitioning API analogous to Weasel.Postgresql's ManagedListPartitions (Weasel.Postgresql/Tables/Partitioning/ManagedListPartitions.cs), which Marten relies on for per-tenant LIST partitions that grow as tenants are registered at runtime.

Why

Polecat (the SQL Server event store / "Marten for SQL Server") is implementing per-tenant event partitioning — JasperFx/polecat#163. The bounded-scan win comes from per-tenant sequences, but the issue also calls for physical per-tenant partitioning of pc_events / pc_streams. Without a managed-partition API in Weasel.SqlServer, Polecat would have to hand-roll runtime CREATE PARTITION FUNCTION / ALTER PARTITION FUNCTION ... SPLIT RANGE DDL as tenants join, which violates the "use Weasel for all schema management" principle and duplicates logic Weasel already owns for PostgreSQL.

Proposal

Add a managed per-tenant partitioning strategy to Weasel.SqlServer mirroring ManagedListPartitions:

  • A ManagedRangePartitions (or ManagedTenantPartitions) ISqlServerPartitioning implementation that:
    • tracks the desired set of tenant boundary values (e.g. a tenant-ordinal column),
    • emits CREATE PARTITION FUNCTION + CREATE PARTITION SCHEME for the initial set,
    • computes an additive delta and emits SPLIT RANGE for newly-added tenants at migration time,
    • exposes a runtime "add tenant/boundary" operation (idempotent SPLIT RANGE) so a store can register a new tenant partition without a full migration.
  • Consider a small registry-table convention (tenant_id → ordinal) so the partition column is a compact int rather than a varchar tenant id.

Acceptance

Related

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