Repository navigation
fix(membership): preserve core membership invariants - #11307
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Provider implementations still do not enforce the required monotonic liveness and Dead-only cleanup contracts.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (3)
What changed in this PR
This PR hardens membership-table invariants around state isolation, monotonic liveness, cleanup, and table-version overflow.
Changes:
- Added defensive copying and monotonic heartbeat handling.
- Restricted cleanup to sufficiently old
Deadentries. - Added regression coverage for cleanup, conformance, and version boundaries.
| File | Summary |
|---|---|
test/TestInfrastructure/Orleans.TestingHost.Tests/InProcessMembershipTableTests.cs |
Adds in-process isolation and cleanup regression coverage. |
test/Orleans.Runtime.Internal.Tests/MembershipTests/InMemoryMembershipTableTests.cs |
Updates in-memory cleanup expectations. |
test/Orleans.Runtime.Internal.Tests/MembershipTests/InMemoryMembershipTableConformanceTests.cs |
Adds conformance regressions; includes a minor test-name typo. |
test/Orleans.Core.Tests/Membership/TableVersionTests.cs |
Tests table-version overflow behavior. |
test/Orleans.Core.Tests/Membership/MembershipTableCleanupAgentTests.cs |
Covers cleanup eligibility and timestamp cutoffs. |
src/Orleans.TestingHost/InProcess/InProcessMembershipTable.cs |
Applies defensive copying and monotonic liveness semantics. |
src/Orleans.Runtime/MembershipService/MembershipTableCleanupAgent.cs |
Restricts cleanup decisions to expired Dead entries; provider operations still require corresponding updates. |
src/Orleans.Runtime/MembershipService/InMemoryMembershipTable.cs |
Preserves detached entries and maximum heartbeat timestamps. |
src/Orleans.Core/SystemTargetInterfaces/IMembershipTable.cs |
Defines updated liveness and cleanup contracts; provider implementations do not yet fully satisfy them. |
src/Orleans.Core/Configuration/Options/ClusterMembershipOptions.cs |
Clarifies dead-entry retention options. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Code coverage
Report-only conclusion: current-main baseline stale. The newest successful coverage run tested 986e5c7, not current main dcf2925. 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 |


The runtime's in-memory membership table retains caller-owned entries, allowing later mutations to change stored state outside conditional writes. Heartbeat-only writes can invalidate membership concurrency tokens, and cleanup can remove silos which are still progressing through their lifecycle.
This focused core change:
IAmAliveTimewith an earlier supplied value.IAmAliveTime. All other membership fields, the row ETag, and the table version/ETag remain unchanged. Canonical inserts and updates continue to create new tokens.TableVersion.Next()for overflow and covers the boundary in the existing core test project.ClusterOptions.ClusterIdand rejects foreign-cluster deletion withArgumentExceptionbefore mutation. Cancellation takes priority; own-cluster deletion preserves the existing terminal table invalidation. Focused regressions exercise the real target and its DI construction.Focused raw-table, in-process-table, and cleanup-agent regressions accompany these changes. Heartbeat regressions cover owner reports, including equal timestamps and clock adjustments, while checking retained membership fields and concurrency tokens. Exact interleaving regressions read row/table tokens, write an owner heartbeat, then successfully commit a canonical update using the original tokens; that update advances the version and replaces its tokens. These interleaving assertions cover canonical state independently of the resulting raw heartbeat value. The baseline already contains #11296, which owns snapshot-level observed liveness maxima and same-version Dead-row pruning semantics.
Compatibility and risk
Public signatures, serialization IDs, RPC aliases, storage schemas, and ETag formats remain compatible. This change requires no schema migration or specially ordered rollout. During a mixed-version upgrade, the in-memory table owner's implementation determines its write/cleanup behavior and the elected cleanup silo determines request timing. Development clustering retains its existing primary-lifetime requirement.
The intentional behavior changes are conservative retention of non-Dead rows, stable row and table tokens across in-memory heartbeat writes, rejection of foreign-cluster deletion, and an
OverflowExceptionfromTableVersion.Next()atint.MaxValueinstead of integer wraparound. Abandoned non-Dead entries remain until the membership protocol declares them Dead. Storage accepts supplied liveness values directly during heartbeats and full-row replacements; snapshot merging retains its existing observed-maximum behavior.Provider scope
The public XML contract requires canonical fields and the table version/ETag to remain stable across heartbeat-only activity. Returned row ETags are provider-defined and may be physical metadata which changes on heartbeat. Providers can validate a separate canonical row token or rely on atomic table-ETag CAS plus an existing-row update and ignore the supplied row ETag. Previously read row/table inputs remain usable for a canonical update after heartbeat-only activity while the row exists and the table ETag remains current. The raw and in-process implementations retain their stronger row-token stability and independent row checks.
Provider-wide absent-row heartbeat and effective-update-time cleanup contract additions remain in the provider follow-ups. Existing external-provider cleanup behavior, including removal of old non-Active rows, remains scoped to those implementations. Changing the cleanup agent's eligibility predicate improves scheduling; provider-specific changes establish the corresponding storage guarantees.
The conformance kit/shared test preparation is tracked in #11308, and provider corrections are in the separate provider PRs (#11309 through #11316). Hosted conformance integration and membership-table routing support remain in their respective follow-up layers.
Microsoft Reviewers: Open in CodeFlow