From 6bc3dee5b37aefc0a04603c6f00670dd6ec2d2ea Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 22 Jun 2019 10:56:54 -0700 Subject: [PATCH] refactoring --- weed/shell/command_ec_encode.go | 16 ++++++---------- weed/shell/command_volume_fix_replication.go | 20 ++++++++------------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/weed/shell/command_ec_encode.go b/weed/shell/command_ec_encode.go index 686849cb8..492dc77eb 100644 --- a/weed/shell/command_ec_encode.go +++ b/weed/shell/command_ec_encode.go @@ -245,19 +245,15 @@ func collectVolumeIdsForEcEncode(ctx context.Context, commandEnv *CommandEnv, se fmt.Printf("ec encode volumes quiet for: %d seconds\n", quietSeconds) vidMap := make(map[uint32]bool) - for _, dc := range resp.TopologyInfo.DataCenterInfos { - for _, r := range dc.RackInfos { - for _, dn := range r.DataNodeInfos { - for _, v := range dn.VolumeInfos { - if v.Collection == selectedCollection && v.ModifiedAtSecond+quietSeconds < nowUnixSeconds { - if float64(v.Size) > fullPercentage/100*float64(resp.VolumeSizeLimitMb)*1024*1024 { - vidMap[v.Id] = true - } - } + eachDataNode(resp.TopologyInfo, func(dc string, rack RackId, dn *master_pb.DataNodeInfo) { + for _, v := range dn.VolumeInfos { + if v.Collection == selectedCollection && v.ModifiedAtSecond+quietSeconds < nowUnixSeconds { + if float64(v.Size) > fullPercentage/100*float64(resp.VolumeSizeLimitMb)*1024*1024 { + vidMap[v.Id] = true } } } - } + }) for vid, _ := range vidMap { vids = append(vids, needle.VolumeId(vid)) diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go index 09e1c19eb..0b3b0363c 100644 --- a/weed/shell/command_volume_fix_replication.go +++ b/weed/shell/command_volume_fix_replication.go @@ -63,20 +63,16 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv, replicatedVolumeLocations := make(map[uint32][]location) replicatedVolumeInfo := make(map[uint32]*master_pb.VolumeInformationMessage) var allLocations []location - for _, dc := range resp.TopologyInfo.DataCenterInfos { - for _, rack := range dc.RackInfos { - for _, dn := range rack.DataNodeInfos { - loc := newLocation(dc.Id, rack.Id, dn) - for _, v := range dn.VolumeInfos { - if v.ReplicaPlacement > 0 { - replicatedVolumeLocations[v.Id] = append(replicatedVolumeLocations[v.Id], loc) - replicatedVolumeInfo[v.Id] = v - } - } - allLocations = append(allLocations, loc) + eachDataNode(resp.TopologyInfo, func(dc string, rack RackId, dn *master_pb.DataNodeInfo) { + loc := newLocation(dc.Id, rack.Id, dn) + for _, v := range dn.VolumeInfos { + if v.ReplicaPlacement > 0 { + replicatedVolumeLocations[v.Id] = append(replicatedVolumeLocations[v.Id], loc) + replicatedVolumeInfo[v.Id] = v } } - } + allLocations = append(allLocations, loc) + }) // find all under replicated volumes underReplicatedVolumeLocations := make(map[uint32][]location)