From eb4071ed05d25e18fd04ae4cbbafd1fb402fcddf Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 30 Apr 2026 10:57:09 -0700 Subject: [PATCH] fix(test): align component cluster harness to replica-%d (Phase 0 prerequisite) The component harness (cluster.go) constructed dual-lane executors with rid="r-%d" while the engine driver in dual_lane_engine_test.go sent AssignmentInfo / ProbeResult under "replica-%d". Pre-Phase-0- Fix-#1 this silently diverged: bridge keyed coord.PinFloor under "r-N", sink keyed WalShipper writeMu + post-emit RecordShipped under "replica-N". The rebuild barrier completed despite the keying mismatch (replica-driven BarrierResp), so the bug stayed invisible. Now that startRebuildDualLane fail-closes on a mismatched non-empty construction RID (commit 11392ba), this drift surfaces as a hard error in TestDualLane_EngineDrivenRebuild_HappyPath / _WithPushLive DuringSession. Aligning the harness to the engine driver's "replica-%d" convention restores the invariant: construction RID == engine arg, coord/sink/bridge all keyed identically. Test assertions that probed the stale "r-0" key (lines 110, 197, 251 region) updated to "replica-0". Refs: INV-RID-UNIFIED-PER-SESSION (commit 11392ba); v3-recovery-execution-institution.md Phase 0. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../core/replication/component/cluster.go | 12 +++++++++++- .../replication/component/dual_lane_engine_test.go | 14 +++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/seaweed-block/core/replication/component/cluster.go b/seaweed-block/core/replication/component/cluster.go index 013fbc956b..6bb1849535 100644 --- a/seaweed-block/core/replication/component/cluster.go +++ b/seaweed-block/core/replication/component/cluster.go @@ -459,7 +459,17 @@ func (c *Cluster) Start() *Cluster { executors := make([]*transport.BlockExecutor, c.replicaN) for i, r := range c.replicas { if c.dualLane { - rid := recovery.ReplicaID(fmt.Sprintf("r-%d", i)) + // INV-RID-UNIFIED-PER-SESSION: the construction RID MUST + // match the engine driver's per-replica ID (the arg flowing + // through StartRebuild). Engine driver convention here is + // "replica-%d" — see the AssignmentInfo / ProbeResult + // callsites in dual_lane_engine_test.go and the + // VolumeReplicaAdapter's keying. Pre-Phase-0-Fix-#1 this + // was "r-%d", which silently diverged: bridge keyed coord + // under "r-N" while sink keyed under "replica-N". The + // startRebuildDualLane assert now fails closed on that + // mismatch. + rid := recovery.ReplicaID(fmt.Sprintf("replica-%d", i)) executors[i] = transport.NewBlockExecutorWithDualLane( pStore, r.Addr, r.DualLaneAddr, c.coord, rid, ) diff --git a/seaweed-block/core/replication/component/dual_lane_engine_test.go b/seaweed-block/core/replication/component/dual_lane_engine_test.go index 6f052555cb..ffe5e52329 100644 --- a/seaweed-block/core/replication/component/dual_lane_engine_test.go +++ b/seaweed-block/core/replication/component/dual_lane_engine_test.go @@ -107,7 +107,11 @@ func TestDualLane_EngineDrivenRebuild_HappyPath(t *testing.T) { } // Coordinator should be back to Idle for replica-0. - if got := c.Coord().Phase(recovery.ReplicaID("r-0")); got != recovery.PhaseIdle { + // Phase-0-Fix-#1 INV-RID-UNIFIED-PER-SESSION: the engine arg + // flowing through StartRebuild is "replica-0"; the bridge now + // keys coord under that arg. (Pre-fix this was "r-0", + // matching the cluster harness's stale construction RID.) + if got := c.Coord().Phase(recovery.ReplicaID("replica-0")); got != recovery.PhaseIdle { t.Errorf("coord phase post-session: %s want Idle", got) } @@ -190,7 +194,8 @@ func TestDualLane_CoordReleasesPinFloorAfterSession(t *testing.T) { if _, anyActive := c.Coord().MinPinAcrossActiveSessions(); anyActive { t.Errorf("post-session: MinPinAcrossActiveSessions still reports anyActive=true") } - if got := c.Coord().PinFloor(recovery.ReplicaID("r-0")); got != 0 { + // Phase-0-Fix-#1: keyed under the engine arg "replica-0" (was "r-0"). + if got := c.Coord().PinFloor(recovery.ReplicaID("replica-0")); got != 0 { t.Errorf("post-session: PinFloor=%d want 0 (released)", got) } }) @@ -246,7 +251,10 @@ func TestDualLane_EngineDrivenRebuild_WithPushLiveDuringSession(t *testing.T) { t.Fatal("BlockExecutor missing dual-lane PrimaryBridge") } - // PeerShipCoordinator keys match NewBlockExecutorWithDualLane replica id ("r-0"). + // PeerShipCoordinator keys match NewBlockExecutorWithDualLane replica id + // ("replica-0" post-Phase-0-Fix-#1). DualLanePrimaryBridge() returns the + // construction RID, which now agrees with the engine arg per + // INV-RID-UNIFIED-PER-SESSION. if c.Coord().Phase(coordRID) == recovery.PhaseIdle { t.Fatal("coord still Idle after rebuild dispatch — PushLiveWrite would fail") }