Skip to content

fix(directory)!: expose immutable partition boundaries - #11425

Merged
ReubenBond merged 8 commits into
dotnet:mainfrom
ReubenBond:rb-fix-configure-directory-partitioning
Oct 8, 2026
Merged

ReubenBond merged 8 commits into
dotnet:mainfrom
ReubenBond:rb-fix-configure-directory-partitioning

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Problem

Orleans 10.1's experimental distributed directory assigned partition numbers after sorting each silo's uniform hashes. #10047 changed that mapping to hash-generation order, and #10050 changed the default partition count from 30 to one. Restoring the count alone therefore leaves mixed-version silos addressing different partitions for the same ranges during registration and ownership transfer.

SiloAddress.GetUniformHashCodes also exposed its cached mutable array, so a caller could change the shared hash order or values used by other directory and ring consumers.

Solution

Return ImmutableArray<uint> from SiloAddress.GetUniformHashCodes. Transfer ownership of the freshly computed array into the immutable cache using ImmutableCollectionsMarshal.AsImmutableArray, preserving cached storage reuse without a defensive copy on each call.

Expose GrainDirectoryOptions.GetPartitionBoundaries as a Func<SiloAddress, int, ImmutableArray<uint>>, using the existing boundary function by default. Applications upgrading an existing 10.1 distributed-directory cluster configure 30 partitions and supply a delegate which returns the cached hashes in sorted immutable order. The upgrade guide provides a compiled snippet, and the compatibility and hosted-routing tests exercise that exact source.

siloBuilder.Configure<GrainDirectoryOptions>(options =>
{
    options.PartitionsPerSilo = 30;
    options.GetPartitionBoundaries = static (silo, partitionCount) =>
        silo.GetUniformHashCodes(partitionCount).Sort();
});

Keep the corrected index-based range storage and the current single-partition and generated-order defaults. Invalid boundary results stop membership processing and surface an OrleansConfigurationException to readers and refresh calls, preserving the original cause. Document cluster-wide mapping stability during upgrades and rollback, and regenerate both affected API surfaces.

Breaking change

The broader return-type change is intentional and explicitly approved: SiloAddress.GetUniformHashCodes(int) changes from uint[] to ImmutableArray<uint> for every caller, including consumers outside the distributed directory. It is a source- and binary-breaking change. Rebuild callers against the new signature; use ToArray() for a mutable buffer or Sort() for an immutable sorted result.

The package compatibility suppression records this approved break; it does not preserve compatibility for previously compiled consumers. It is scoped to this method in Microsoft.Orleans.Core.Abstractions for net8.0 and net10.0, and all other package validation remains enabled. Normal Release packing passes.

Rationale

An unconditional return to sorted numbering would disrupt clusters already running newer multi-partition configurations. The general-purpose immutable delegate exposes the existing internal extension point, while compatibility policy for the experimental release remains application-owned.

Replacing the existing hash getter establishes one immutable cache-ownership contract for every ring consumer, protecting the shared cache at its source. This broader approved break is preferable to a directory-only copy or a second immutable getter alongside the mutable-array API. Cached storage reuse and generation order remain unchanged.

Microsoft Reviewers: Open in CodeFlow

Copilot AI balanced review requested due to automatic review settings October 7, 2026 14:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Invalid mappings can trigger a tight retry loop, and the generated public API surface is missing.

Review effort: Balanced
Findings: 2 High severity

Open (2)
What changed in this PR

Makes distributed-directory partition boundary mapping configurable for rolling-upgrade compatibility.

Changes:

  • Adds configurable and legacy partition-boundary mappings.
  • Validates boundary result shape and wires options into directory membership.
  • Adds compatibility tests and upgrade guidance.
File Description
GrainDirectoryOptionsTests.cs Tests configured routing mappings.
DirectoryMembershipSnapshotTests.cs Tests defaults, legacy behavior, and validation.
CoreHostingExtensions.cs Injects configured boundary function.
DirectoryMembershipSnapshot.cs Validates boundary results.
DirectoryMembershipService.cs Rejects null boundary functions.
GrainDirectoryOptions.cs Exposes boundary configuration and legacy helper.
grain-directory.md Documents boundary configuration.
upgrades.md Documents rolling-upgrade compatibility.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 14:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The generated Orleans.Runtime API surface has not been updated for the new public members.

Review effort: Balanced
Findings: 2 High severity

Open (2)

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request
Lines 83.33% (118,068 / 141,694)
Branches 72.84% (35,035 / 48,100)

Report-only conclusion: current-main baseline stale.

The newest successful coverage run tested 165acd0, not current main ad8cf7c.

Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.

The comparison remains report-only while normal line and branch variance is calibrated.

Coverage details

Copilot AI balanced review requested due to automatic review settings October 7, 2026 17:33
@ReubenBond
ReubenBond force-pushed the rb-fix-configure-directory-partitioning branch from fdb0a84 to 132c853 Compare October 7, 2026 17:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Mixed-version partition identity and ownership-transfer behavior warrants final human validation despite the focused coverage.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

@ReubenBond
ReubenBond marked this pull request as ready for review October 7, 2026 21:32
Copilot AI balanced review requested due to automatic review settings October 7, 2026 23:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It changes distributed routing identity and terminal failure behavior during mixed-version cluster operation.

0 open findings

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

BREAKING CHANGE: SiloAddress.GetUniformHashCodes(int) now returns ImmutableArray<uint> instead of uint[]. GetPartitionBoundaries uses the same immutable result type. Rebuild callers against the new signature.
Copilot AI balanced review requested due to automatic review settings October 8, 2026 00:09
@ReubenBond ReubenBond changed the title fix(directory): make partition boundaries configurable fix(directory)!: expose immutable partition boundaries Oct 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The unresolved public return-type break is broader than and inconsistent with the advertised compatibility solution.

1 open finding

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 18:00
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Oct 22, 2026
Backport the immutable boundary delegate, configuration validation, failure propagation, tests, generated API and upgrade guidance. Preserve the shipped uint[] SiloAddress hash API and current partition defaults.

Upstream-PR: dotnet#11425
Upstream-Commit: ad8cf7c
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Oct 22, 2026
Backport the immutable boundary delegate, configuration validation, failure propagation, tests, generated API and upgrade guidance. Preserve the shipped uint[] SiloAddress hash API and current partition defaults.

Upstream-PR: dotnet#11425
Upstream-Commit: ad8cf7c
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Oct 23, 2026
ReubenBond added a commit that referenced this pull request Oct 23, 2026
(cherry picked from commit ad8cf7c)
Upstream-PR: #11425
Upstream-Commit: ad8cf7c
This was referenced Oct 29, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants