Resolve replica placement for EC volumes from master server defaults. (#6303)
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user