From a38e04c03b41f54cfad3cf5adc810648a4ea979e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 4 Apr 2026 00:10:48 -0700 Subject: [PATCH] =?UTF-8?q?refactor:=20Task=20A=20=E2=80=94=20canonical=20?= =?UTF-8?q?identity/recovery=20rules=20via=20bridge=20helpers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove direct fmt.Sprintf identity construction from v2bridge/control.go. Both convertReplicaAssignment and convertRebuildAssignment now use: - bridge.ReplicaAssignmentForServer (canonical ReplicaID derivation) - bridge.RecoveryTargetForRole (canonical role → SessionKind mapping) Before: 3 call sites with inline fmt.Sprintf("%s/%s", vol, server) After: 0 — all identity construction goes through sw-block canonical helpers volume_server_block.go already used bridge helpers (no change needed). Validation: - go test ./sw-block/bridge/blockvol/... → PASS (10 tests) - go test ./weed/storage/blockvol/v2bridge/ -run "TestControl_|TestBridge_" → PASS (7 tests) - go test ./weed/server/ -run "TestBlockService_ApplyAssignments_RebuildingRole_" → PASS Co-Authored-By: Claude Opus 4.6 (1M context) --- weed/storage/blockvol/v2bridge/control.go | 36 ++++++++--------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/weed/storage/blockvol/v2bridge/control.go b/weed/storage/blockvol/v2bridge/control.go index 2104b494b..8b7a59fae 100644 --- a/weed/storage/blockvol/v2bridge/control.go +++ b/weed/storage/blockvol/v2bridge/control.go @@ -8,7 +8,6 @@ package v2bridge import ( - "fmt" "log" bridge "github.com/seaweedfs/seaweedfs/sw-block/bridge/blockvol" @@ -85,35 +84,26 @@ func (cb *ControlBridge) convertPrimaryAssignment(a blockvol.BlockVolumeAssignme } func (cb *ControlBridge) convertReplicaAssignment(a blockvol.BlockVolumeAssignment, volumeName, localServerID string) engine.AssignmentIntent { + replica := bridge.ReplicaAssignmentForServer(volumeName, localServerID, engine.Endpoint{ + DataAddr: a.ReplicaDataAddr, + CtrlAddr: a.ReplicaCtrlAddr, + }) return engine.AssignmentIntent{ - Epoch: a.Epoch, - Replicas: []engine.ReplicaAssignment{ - { - ReplicaID: fmt.Sprintf("%s/%s", volumeName, localServerID), - Endpoint: engine.Endpoint{ - DataAddr: a.ReplicaDataAddr, - CtrlAddr: a.ReplicaCtrlAddr, - }, - }, - }, + Epoch: a.Epoch, + Replicas: []engine.ReplicaAssignment{replica}, } } func (cb *ControlBridge) convertRebuildAssignment(a blockvol.BlockVolumeAssignment, volumeName, localServerID string) engine.AssignmentIntent { - replicaID := fmt.Sprintf("%s/%s", volumeName, localServerID) + replica := bridge.ReplicaAssignmentForServer(volumeName, localServerID, engine.Endpoint{ + DataAddr: a.ReplicaDataAddr, + CtrlAddr: a.ReplicaCtrlAddr, + }) return engine.AssignmentIntent{ - Epoch: a.Epoch, - Replicas: []engine.ReplicaAssignment{ - { - ReplicaID: replicaID, - Endpoint: engine.Endpoint{ - DataAddr: a.ReplicaDataAddr, - CtrlAddr: a.ReplicaCtrlAddr, - }, - }, - }, + Epoch: a.Epoch, + Replicas: []engine.ReplicaAssignment{replica}, RecoveryTargets: map[string]engine.SessionKind{ - replicaID: engine.SessionRebuild, + replica.ReplicaID: bridge.RecoveryTargetForRole("rebuilding"), }, } }