From 1a09bc43d119b564ee2a9a950ad3a795c838d54a Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 7 Sep 2020 11:31:33 -0700 Subject: [PATCH] refactor --- weed/shell/command_volume_fix_replication.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go index 53f88cab2..8f9700292 100644 --- a/weed/shell/command_volume_fix_replication.go +++ b/weed/shell/command_volume_fix_replication.go @@ -36,7 +36,7 @@ func (c *commandVolumeFixReplication) Help() string { Note: * each time this will only add back one replica for one volume id. If there are multiple replicas are missing, e.g. multiple volume servers are new, you may need to run this multiple times. - * do not run this too quick within seconds, since the new volume replica may take a few seconds + * do not run this too quickly within seconds, since the new volume replica may take a few seconds to register itself to the master. ` @@ -80,12 +80,14 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv, // find all under replicated volumes underReplicatedVolumeLocations := make(map[uint32][]location) + overReplicatedVolumeLocations := make(map[uint32][]location) for vid, locations := range replicatedVolumeLocations { volumeInfo := replicatedVolumeInfo[vid] replicaPlacement, _ := super_block.NewReplicaPlacementFromByte(byte(volumeInfo.ReplicaPlacement)) if replicaPlacement.GetCopyCount() > len(locations) { underReplicatedVolumeLocations[vid] = locations } else if replicaPlacement.GetCopyCount() < len(locations) { + overReplicatedVolumeLocations[vid] = locations fmt.Fprintf(writer, "volume %d replication %s, but over replicated:%+v\n", volumeInfo.Id, replicaPlacement, locations) } } @@ -101,6 +103,11 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv, // find the most under populated data nodes keepDataNodesSorted(allLocations) + return c.fixUnderReplicatedVolumes(commandEnv, writer, takeAction, underReplicatedVolumeLocations, replicatedVolumeInfo, allLocations) + +} + +func (c *commandVolumeFixReplication) fixUnderReplicatedVolumes(commandEnv *CommandEnv, writer io.Writer, takeAction bool, underReplicatedVolumeLocations map[uint32][]location, replicatedVolumeInfo map[uint32]*master_pb.VolumeInformationMessage, allLocations []location) error { for vid, locations := range underReplicatedVolumeLocations { volumeInfo := replicatedVolumeInfo[vid] replicaPlacement, _ := super_block.NewReplicaPlacementFromByte(byte(volumeInfo.ReplicaPlacement)) @@ -144,7 +151,6 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv, } } - return nil }