aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_volume_fix_replication.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_fix_replication.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_fix_replication.go')
-rw-r--r--weed/shell/command_volume_fix_replication.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go
index 78285d8a5..c4bef5925 100644
--- a/weed/shell/command_volume_fix_replication.go
+++ b/weed/shell/command_volume_fix_replication.go
@@ -7,9 +7,9 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb"
"github.com/chrislusf/seaweedfs/weed/storage/needle"
"github.com/chrislusf/seaweedfs/weed/storage/types"
+ "golang.org/x/exp/slices"
"io"
"path/filepath"
- "sort"
"strconv"
"time"
@@ -308,8 +308,8 @@ func (c *commandVolumeFixReplication) fixOneUnderReplicatedVolume(commandEnv *Co
func keepDataNodesSorted(dataNodes []location, diskType types.DiskType) {
fn := capacityByFreeVolumeCount(diskType)
- sort.Slice(dataNodes, func(i, j int) bool {
- return fn(dataNodes[i].dataNode) > fn(dataNodes[j].dataNode)
+ slices.SortFunc(dataNodes, func(a, b location) bool {
+ return fn(a.dataNode) > fn(b.dataNode)
})
}
@@ -488,9 +488,7 @@ func countReplicas(replicas []*VolumeReplica) (diffDc, diffRack, diffNode map[st
}
func pickOneReplicaToDelete(replicas []*VolumeReplica, replicaPlacement *super_block.ReplicaPlacement) *VolumeReplica {
-
- sort.Slice(replicas, func(i, j int) bool {
- a, b := replicas[i], replicas[j]
+ slices.SortFunc(replicas, func(a, b *VolumeReplica) bool {
if a.info.Size != b.info.Size {
return a.info.Size < b.info.Size
}