mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-21 14:46:58 +00:00
refactor: Task A — canonical identity/recovery rules via bridge helpers
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) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
13680c9aa6
commit
a38e04c03b
@@ -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"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user