fix(cluster): unify delivery topology with Meta CAS + fencing (#5293 #5288) - #5308
Merged
Conversation
…#5293 apache#5288) Sticky-only delivery topology (removes cross-instance forwarding): - Delete HttpForwarder and the /internal/forward + /internal/reply-forward endpoints in UniHttpServer; reply() on a non-owner instance now 404s (SDK pins to one instance via instanceUrl, no forwarding needed) - Remove DistributionMode.LOAD_BALANCE_STICKY; LOAD_BALANCE absorbs the sticky semantics (partitionkey hash routes to one subscriber) Atomic Meta CAS fencing (replaces read-then-write gen overwrite): - MetaStore.tryAcquire(key, expectedOldValue, newValue): atomic CAS (InMemory: ConcurrentHashMap putIfAbsent/replace; Nacos 2.x: publishConfigCas with casMd5 = MD5(expected content)) - FencingToken "<bootEpoch>:<counter>" per JVM, monotonic and restart-safe; assignment record "/em/assignments/<topic#partition>" = "<token>|<ownerInstanceId>" - acquireOrFence: Case 1 unclaimed (or released tombstone) -> CAS claim; Case 2 still ours -> sync token; Case 3 another owner -> CAS takeover when TTL-evicted or token strictly higher, else fenced - releaseStale: partitions that left our assigner share are CAS'd to a "" tombstone so the new rightful owner can claim them (prevents stranding after membership churn); tombstone is CAS-equivalent to absent on both MetaStore backends Heartbeat scheduling fix (apache#5288): - ClusterMembership.heartbeat() was never scheduled; enableCluster now runs it every 5s and releases it on shutdown together with the partition lease Tests: - FencingTokenTest, InMemoryMetaStoreTest (incl. concurrent CAS), PartitionFencingTest (first claim / race / restart fencing / stale CAS) - ClusterDeliveryFaultTest: in-process 3-4 instance fault injection (steady-state split, crash takeover, scale-out churn, Meta partition split-brain guard, healed partition reclaim) driven by a mutable clock - no sleeps, fully deterministic - Remove ClusterForwardIntegrationTest / NacosClusterForwardIntegrationTest (they covered the deleted forwarding path)
This was referenced Aug 20, 2026
Contributor
Author
|
Upstream CI all green on this PR (5 PR-triggered workflows,
Same config (License Check + CI + Code Scanning) was previously green on #5307 (which was merged into master as commit |
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes #5293
Fixes #5288
The uni-architecture cluster delivery currently mixes two modes: sticky delivery with cross-instance HTTP forwarding (
HttpForwarder+/internal/forwardendpoints) and partition assignment without fencing. The forwarding path adds an extra network hop, hidden failure modes, and makes delivery depend on instance-to-instance reachability. At the same time, partition assignment uses read-then-write generation overwrite, which is racy: a stale instance can silently overwrite the assignment of the rightful owner after a restart or a long GC pause. Finally,ClusterMembership.heartbeat()is never scheduled (#5288), so partition leases expire for live instances.Modifications
1. Sticky-only delivery topology (issue #5293)
HttpForwarderand the/internal/forward+/internal/reply-forwardendpoints inUniHttpServer;reply()on a non-owner instance now 404s. The SDK pins to one instance viainstanceUrl, so forwarding is no longer needed.DistributionMode.LOAD_BALANCE_STICKY;LOAD_BALANCEabsorbs the sticky semantics (partition-key hash routes to one subscriber).2. Atomic Meta CAS fencing (issue #5293)
MetaStore.tryAcquire(key, expectedOldValue, newValue): atomic compare-and-swap. InMemory:ConcurrentHashMapputIfAbsent/replace; Nacos 2.x:publishConfigCaswithcasMd5 = MD5(expected content).FencingToken "<bootEpoch>:<counter>"per JVM — monotonic and restart-safe. Assignment record/em/assignments/<topic#partition>="<token>|<ownerInstanceId>".acquireOrFencethree-branch protocol:"") → CAS claimreleaseStale: partitions that left our assigner share are CAS'd to a""tombstone so the new rightful owner can claim them on its next cycle (prevents stranding after membership churn). The tombstone is CAS-equivalent to an absent key on both MetaStore backends.3. Heartbeat scheduling fix (issue #5288)
ClusterMembership.heartbeat()was never scheduled;enableClusternow runs it every 5s and releases it on shutdown together with the partition lease.Tests
FencingTokenTest,InMemoryMetaStoreTest(incl. concurrent CAS),PartitionFencingTest(first claim / race / restart fencing / stale CAS).ClusterDeliveryFaultTest: in-process 3-4 instance fault injection (steady-state split, crash takeover, scale-out churn, Meta partition split-brain guard, healed partition reclaim) driven by a mutable clock — no sleeps, fully deterministic.ClusterForwardIntegrationTest/NacosClusterForwardIntegrationTest(they covered the deleted forwarding path).Documentation
docs/eventmesh-uni-architecture-redesign.md§13.2.10 updated with the acquireOrFence protocol, release path, and fault-injection test coverage)