aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_ec_common.go
diff options
context:
space:
mode:
authorLisandro Pin <lisandro.pin@proton.ch>2024-12-02 17:44:07 +0100
committerGitHub <noreply@github.com>2024-12-02 08:44:07 -0800
commitb2ba7d7408500bb450884a288327a1fb53e67fae (patch)
treeb16eac42446ecd69bf5c2a8b3a57afb49b0d644b /weed/shell/command_ec_common.go
parent9a741a61b195ccdf9815ab64dc9f0725f620f836 (diff)
downloadseaweedfs-b2ba7d7408500bb450884a288327a1fb53e67fae.tar.xz
seaweedfs-b2ba7d7408500bb450884a288327a1fb53e67fae.zip
Resolve replica placement for EC volumes from master server defaults. (#6303)
Diffstat (limited to 'weed/shell/command_ec_common.go')
-rw-r--r--weed/shell/command_ec_common.go67
1 files changed, 46 insertions, 21 deletions
diff --git a/weed/shell/command_ec_common.go b/weed/shell/command_ec_common.go
index 3b4a0ff25..906e2e0dc 100644
--- a/weed/shell/command_ec_common.go
+++ b/weed/shell/command_ec_common.go
@@ -39,6 +39,42 @@ type EcRack struct {
freeEcSlot int
}
+var (
+ // Overridable functions for testing.
+ getDefaultReplicaPlacement = _getDefaultReplicaPlacement
+)
+
+func _getDefaultReplicaPlacement(commandEnv *CommandEnv) (*super_block.ReplicaPlacement, error) {
+ var resp *master_pb.GetMasterConfigurationResponse
+ var err error
+
+ err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
+ resp, err = client.GetMasterConfiguration(context.Background(), &master_pb.GetMasterConfigurationRequest{})
+ return err
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return super_block.NewReplicaPlacementFromString(resp.DefaultReplication)
+}
+func parseReplicaPlacementArg(commandEnv *CommandEnv, replicaStr string) (*super_block.ReplicaPlacement, error) {
+ if replicaStr != "" {
+ rp, err := super_block.NewReplicaPlacementFromString(replicaStr)
+ if err == nil {
+ fmt.Printf("using replica placement %q for EC volumes\n", rp.String())
+ }
+ return rp, err
+ }
+
+ // No replica placement argument provided, resolve from master default settings.
+ rp, err := getDefaultReplicaPlacement(commandEnv)
+ if err == nil {
+ fmt.Printf("using master default replica placement %q for EC volumes\n", rp.String())
+ }
+ return rp, err
+}
+
func moveMountedShardToEcNode(commandEnv *CommandEnv, existingLocation *EcNode, collection string, vid needle.VolumeId, shardId erasure_coding.ShardId, destinationEcNode *EcNode, applyBalancing bool) (err error) {
if !commandEnv.isLocked() {
@@ -840,15 +876,19 @@ func collectVolumeIdToEcNodes(allEcNodes []*EcNode, collection string) map[needl
return vidLocations
}
-// TODO: EC volumes have no replica placement info :( Maybe rely on the master's default?
-func volumeIdToReplicaPlacement(vid needle.VolumeId, nodes []*EcNode) (*super_block.ReplicaPlacement, error) {
+// TODO: EC volumes have no topology replica placement info :( We need a better solution to resolve topology, and balancing, for those.
+func volumeIdToReplicaPlacement(commandEnv *CommandEnv, vid needle.VolumeId, nodes []*EcNode, ecReplicaPlacement *super_block.ReplicaPlacement) (*super_block.ReplicaPlacement, error) {
for _, ecNode := range nodes {
for _, diskInfo := range ecNode.info.DiskInfos {
for _, volumeInfo := range diskInfo.VolumeInfos {
- if needle.VolumeId(volumeInfo.Id) != vid {
- continue
+ if needle.VolumeId(volumeInfo.Id) == vid {
+ return super_block.NewReplicaPlacementFromByte(byte(volumeInfo.ReplicaPlacement))
+ }
+ }
+ for _, ecShardInfo := range diskInfo.EcShardInfos {
+ if needle.VolumeId(ecShardInfo.Id) == vid {
+ return ecReplicaPlacement, nil
}
- return super_block.NewReplicaPlacementFromByte(byte(volumeInfo.ReplicaPlacement))
}
}
}
@@ -856,22 +896,7 @@ func volumeIdToReplicaPlacement(vid needle.VolumeId, nodes []*EcNode) (*super_bl
return nil, fmt.Errorf("failed to resolve replica placement for volume ID %d", vid)
}
-func getDefaultReplicaPlacement(commandEnv *CommandEnv) (*super_block.ReplicaPlacement, error) {
- var resp *master_pb.GetMasterConfigurationResponse
- var err error
-
- err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
- resp, err = client.GetMasterConfiguration(context.Background(), &master_pb.GetMasterConfigurationRequest{})
- return err
- })
- if err != nil {
- return nil, err
- }
-
- return super_block.NewReplicaPlacementFromString(resp.DefaultReplication)
-}
-
-func EcBalance(commandEnv *CommandEnv, collections []string, dc string, applyBalancing bool) (err error) {
+func EcBalance(commandEnv *CommandEnv, collections []string, dc string, ecReplicaPlacement *super_block.ReplicaPlacement, applyBalancing bool) (err error) {
if len(collections) == 0 {
return fmt.Errorf("no collections to balance")
}