aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_volume_server_evacuate.go
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2022-04-17 20:59:31 -0700
committerGitHub <noreply@github.com>2022-04-17 20:59:31 -0700
commit61af76c3bb03bf40e3444c50724c8d5a1a2eafb4 (patch)
treee7bbc83368c814afa3d6c81c808738f91e32afd4 /weed/shell/command_volume_server_evacuate.go
parentb597baf488fa4449d41ac2b78d421751f65f909e (diff)
parent89eb87c1d16640030927af242b34eba47a149427 (diff)
downloadseaweedfs-61af76c3bb03bf40e3444c50724c8d5a1a2eafb4.tar.xz
seaweedfs-61af76c3bb03bf40e3444c50724c8d5a1a2eafb4.zip
Merge pull request #2929 from leyou240/slices.SortFunc
enhancement: replace sort.Slice with slices.SortFunc to reduce reflection
Diffstat (limited to 'weed/shell/command_volume_server_evacuate.go')
-rw-r--r--weed/shell/command_volume_server_evacuate.go13
1 files changed, 5 insertions, 8 deletions
diff --git a/weed/shell/command_volume_server_evacuate.go b/weed/shell/command_volume_server_evacuate.go
index 31ebcfec1..f07ea4b79 100644
--- a/weed/shell/command_volume_server_evacuate.go
+++ b/weed/shell/command_volume_server_evacuate.go
@@ -8,9 +8,9 @@ import (
"github.com/chrislusf/seaweedfs/weed/storage/needle"
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
"github.com/chrislusf/seaweedfs/weed/storage/types"
+ "golang.org/x/exp/slices"
"io"
"os"
- "sort"
)
func init() {
@@ -153,11 +153,9 @@ func evacuateEcVolumes(commandEnv *CommandEnv, topologyInfo *master_pb.TopologyI
func moveAwayOneEcVolume(commandEnv *CommandEnv, ecShardInfo *master_pb.VolumeEcShardInformationMessage, thisNode *EcNode, otherNodes []*EcNode, applyChange bool) (hasMoved bool, err error) {
for _, shardId := range erasure_coding.ShardBits(ecShardInfo.EcIndexBits).ShardIds() {
-
- sort.Slice(otherNodes, func(i, j int) bool {
- return otherNodes[i].localShardIdCount(ecShardInfo.Id) < otherNodes[j].localShardIdCount(ecShardInfo.Id)
+ slices.SortFunc(otherNodes, func(a, b *EcNode) bool {
+ return a.localShardIdCount(ecShardInfo.Id) < b.localShardIdCount(ecShardInfo.Id)
})
-
for i := 0; i < len(otherNodes); i++ {
emptyNode := otherNodes[i]
collectionPrefix := ""
@@ -188,10 +186,9 @@ func moveAwayOneNormalVolume(commandEnv *CommandEnv, volumeReplicas map[uint32][
return v.DiskType == vol.DiskType
})
}
- sort.Slice(otherNodes, func(i, j int) bool {
- return otherNodes[i].localVolumeRatio(fn) > otherNodes[j].localVolumeRatio(fn)
+ slices.SortFunc(otherNodes, func(a, b *Node) bool {
+ return a.localVolumeRatio(fn) > b.localVolumeRatio(fn)
})
-
for i := 0; i < len(otherNodes); i++ {
emptyNode := otherNodes[i]
hasMoved, err = maybeMoveOneVolume(commandEnv, volumeReplicas, thisNode, vol, emptyNode, applyChange)