Skip to content

fix(adonet): preserve membership consistency - #11317

Merged
ReubenBond merged 15 commits into
dotnet:mainfrom
ReubenBond:rb-fix-adonet-membership-consistency
Sep 18, 2026
Merged

ReubenBond merged 15 commits into
dotnet:mainfrom
ReubenBond:rb-fix-adonet-membership-consistency

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Problem

Some existing ADO.NET membership definitions commit a version increment when the membership row is missing, rely on optional PostgreSQL assertions for rollback, or clean up non-Dead rows using heartbeat age alone. Improving these definitions should preserve operational simplicity and compatibility with existing deployments.

Solution

Keep the SQL enhancements in the four existing *-Clustering.sql installation scripts. This PR adds no operational scripts and leaves the historical migrations unchanged. Existing silos and ADO.NET gateway-discovery clients can upgrade the provider package while continuing to use their installed SQL catalog; no database update or new query key is required.

The script enhancements include atomic rollback on failed membership updates, PostgreSQL rollback independent of optional assertions for two-write mutations, and improved Dead-row cleanup. Schemas, stored formats, and existing query parameter sets remain unchanged. Fresh installations receive the definitions through the usual database setup.

Each silo owns its heartbeat: the dedicated operation remains one blind, primary-key-targeted IAmAliveTime assignment, with no pre-read, version/status check, or provider retry. Canonical updates can use the original logical row/table tokens captured before a heartbeat. Full-row SQL retains the inexpensive inline heartbeat maximum within its already-required update statement.

SQL Server membership read queries remain unchanged from the original scripts. SQLServer-Main.sql already enables READ_COMMITTED_SNAPSHOT, providing coherent statement snapshots without added read-lock hints. Speculative version-overflow guards are omitted.

Existing-deployment compatibility

Original catalogs keep using their installed CleanupDefunctSiloEntriesKey query and behavior. The captured-row CleanupDefunctSiloEntryKey is optional: when installed, it enables exact exclusive start/heartbeat/suspicion eligibility and a native condition protecting concurrent changes. Both paths preserve native errors and cancellation. Cleanup remains unversioned.

Providers cache definitions during initialization. Operators choosing to adopt revised definitions can use their normal database change-management process and reinitialize providers afterward. The enhanced SQL behavior applies to callers using those definitions; older installed definitions retain their existing behavior. The provider never applies DDL or rewrites the catalog during startup.

Compatibility coverage

Native scenarios install either frozen pre-change definitions or the current installation scripts for SQL Server, PostgreSQL, and MySQL. Both cases initialize current silo and gateway providers, read and mutate membership, publish a blind heartbeat, reuse original tokens, and execute the installed cleanup path. Enhanced cases cover atomic conditional failures and retention-aware cleanup. SQL Server reader/writer coverage verifies the existing snapshot configuration and coherent observations.

Fresh clustering test setup uses the current installation definitions directly, so historical upgrade scripts cannot overwrite current routines. Oracle native execution remains outside the available test infrastructure.

Split prerequisite

Includes only the tiny legacy cleanup-test preparation from the first commit of #11308 (bede893d290a9035f196f4c3ed58213d102efc6c), retained as a separate cherry-pick. The provider work was carved from frozen commit 1dfe8b54cda3582ddf3795113eaa2f4e9d1b6254 onto d515d75eaaa3a0390a74cb11c96aa758358b5a67, then simplified to existing-script enhancements with original-catalog compatibility. Shared conformance-kit wiring remains separate.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 17, 2026 23:34

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

🟢 Approval recommended

No unresolved blocking issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Hardens ADO.NET membership consistency across relational providers with atomic writes, heartbeat preservation, exact token validation, and safe cleanup.

Changes:

  • Updates provider SQL and migrations for atomic membership updates.
  • Adds captured-value cleanup for stale Dead entries.
  • Expands relational and membership test coverage.
File Description
test/​Orleans.Runtime.Internal.Tests/​MembershipTests/​MembershipTableTestsBase.cs Updates cleanup expectations and fixtures.
test/​Extensions/​Orleans.AdoNet.Tests/​StorageTests/​Relational/​RelationalOrleansQueriesUnitTests.cs Adds relational behavior and cleanup tests.
test/​Extensions/​Orleans.AdoNet.Tests/​StorageTests/​Relational/​AdoNetMembershipSqlTests.cs Validates SQL and migration compatibility.
src/​AdoNet/​Shared/​Storage/​RelationalOrleansQueries.cs Implements token validation and captured cleanup.
src/​AdoNet/​Shared/​Storage/​DbStoredQueries.cs Registers the new cleanup query.
src/​AdoNet/​Orleans.Clustering.AdoNet/​SQLServer-Clustering.sql Updates SQL Server membership operations.
src/​AdoNet/​Orleans.Clustering.AdoNet/​PostgreSQL-Clustering.sql Updates PostgreSQL membership operations.
src/​AdoNet/​Orleans.Clustering.AdoNet/​Oracle-Clustering.sql Updates Oracle membership operations.
src/​AdoNet/​Orleans.Clustering.AdoNet/​MySQL-Clustering.sql Updates MySQL membership operations.
src/​AdoNet/​Orleans.Clustering.AdoNet/​Migrations/​SQLServer-Clustering-AtomicWrites.sql Adds SQL Server upgrade procedures.
src/​AdoNet/​Orleans.Clustering.AdoNet/​Migrations/​PostgreSQL-Clustering-AtomicWrites.sql Adds PostgreSQL upgrade procedures.
src/​AdoNet/​Orleans.Clustering.AdoNet/​Migrations/​Oracle-Clustering-AtomicWrites.sql Adds Oracle upgrade procedures.
src/​AdoNet/​Orleans.Clustering.AdoNet/​Migrations/​MySQL-Clustering-AtomicWrites.sql Adds MySQL upgrade procedures.
src/​AdoNet/​Orleans.Clustering.AdoNet/​Messaging/​AdoNetClusteringTable.cs Enforces matching row and table tokens.

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

@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request
Lines 82.76% (114,896 / 138,832)
Branches 72.07% (33,385 / 46,320)

Report-only conclusion: current-main baseline stale.

The newest successful coverage run tested f278e80, not current main 2994764.

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

@ReubenBond
ReubenBond marked this pull request as ready for review September 18, 2026 15:11
Copilot AI review requested due to automatic review settings September 18, 2026 15:12

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

Broad cross-provider SQL and upgrade changes require final human validation.

Review effort: Lite
Findings: None

Copilot AI review requested due to automatic review settings September 18, 2026 15:41

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

SQL Server and MySQL rolling upgrades can deadlock when cached and migrated insert paths use different lock orders.

Review effort: Lite
Findings: None

Copilot AI review requested due to automatic review settings September 18, 2026 16:02

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

The documented migration rollout can leave older processes using cached unsafe queries during the upgrade window.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)

Comment thread src/AdoNet/Orleans.Clustering.AdoNet/README.md Outdated
Copilot AI review requested due to automatic review settings September 18, 2026 16:07

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

Critical rolling-upgrade risks remain in the MySQL cached-query path and SQL Server lock ordering.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 High severity

Open (3)

Comment thread src/AdoNet/Orleans.Clustering.AdoNet/Migrations/MySQL-Clustering-AtomicWrites.sql Outdated
Copilot AI review requested due to automatic review settings September 18, 2026 16:24

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

Critical lock-order deadlocks remain possible, and negative version tokens are not rejected locally.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 5 High severity

Open (5)
Resolved since last review (1)

Comment thread src/AdoNet/Orleans.Clustering.AdoNet/Migrations/MySQL-Clustering-AtomicWrites.sql Outdated
Comment thread src/AdoNet/Orleans.Clustering.AdoNet/SQLServer-Clustering.sql Outdated
Copilot AI review requested due to automatic review settings September 18, 2026 16:55

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 broad cross-provider SQL and migration changes warrant final human review.

Review effort: Lite
Findings: None

Copilot AI review requested due to automatic review settings September 18, 2026 23:05

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

Enhanced cleanup performs serial per-row deletes, causing linear database round-trips for retained Dead rows.

Review effort: Lite
Findings: None

Copilot AI review requested due to automatic review settings September 18, 2026 23:15

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

Negative canonical tokens can still reach the SQL write path and must be rejected.

Review effort: Lite
Findings: None

@ReubenBond
ReubenBond requested a lite review from Copilot September 18, 2026 23:33
@ReubenBond
ReubenBond merged commit 2994764 into dotnet:main Sep 18, 2026
68 checks passed
@ReubenBond
ReubenBond deleted the rb-fix-adonet-membership-consistency branch September 18, 2026 23:34

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

Optional cleanup currently performs sequential database round trips for each eligible row and should be batched or made set-based.

Review effort: Lite
Findings: None

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.

2 participants