aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_volume_fix_replication.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-02-16 05:13:48 -0800
committerChris Lu <chris.lu@gmail.com>2021-02-16 05:13:48 -0800
commit36f95e50a9beb528263dcf69277365baf7b4e82b (patch)
tree69d7f87491fc49a011fa3259d2930b8bdd549b91 /weed/shell/command_volume_fix_replication.go
parent43101ccea03f45de6d43b41a4d08eba1de1b89e6 (diff)
downloadseaweedfs-36f95e50a9beb528263dcf69277365baf7b4e82b.tar.xz
seaweedfs-36f95e50a9beb528263dcf69277365baf7b4e82b.zip
avoid possible nil disk info
Diffstat (limited to 'weed/shell/command_volume_fix_replication.go')
-rw-r--r--weed/shell/command_volume_fix_replication.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go
index c7de14318..7b2eb6769 100644
--- a/weed/shell/command_volume_fix_replication.go
+++ b/weed/shell/command_volume_fix_replication.go
@@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"github.com/chrislusf/seaweedfs/weed/storage/needle"
+ "github.com/chrislusf/seaweedfs/weed/storage/types"
"io"
"path/filepath"
"sort"
@@ -167,7 +168,8 @@ func (c *commandVolumeFixReplication) fixUnderReplicatedVolumes(commandEnv *Comm
keepDataNodesSorted(allLocations, replica.info.DiskType)
for _, dst := range allLocations {
// check whether data nodes satisfy the constraints
- if dst.dataNode.DiskInfos[replica.info.DiskType].FreeVolumeCount > 0 && satisfyReplicaPlacement(replicaPlacement, replicas, dst) {
+ fn := capacityByFreeVolumeCount(types.ToDiskType(replica.info.DiskType))
+ if fn(dst.dataNode) > 0 && satisfyReplicaPlacement(replicaPlacement, replicas, dst) {
// check collection name pattern
if *c.collectionPattern != "" {
matched, err := filepath.Match(*c.collectionPattern, replica.info.Collection)
@@ -218,8 +220,9 @@ func (c *commandVolumeFixReplication) fixUnderReplicatedVolumes(commandEnv *Comm
}
func keepDataNodesSorted(dataNodes []location, diskType string) {
+ fn := capacityByFreeVolumeCount(types.ToDiskType(diskType))
sort.Slice(dataNodes, func(i, j int) bool {
- return dataNodes[i].dataNode.DiskInfos[diskType].FreeVolumeCount > dataNodes[j].dataNode.DiskInfos[diskType].FreeVolumeCount
+ return fn(dataNodes[i].dataNode) > fn(dataNodes[j].dataNode)
})
}