enhancement: replace sort.Slice with slices.SortFunc to reduce reflection

This commit is contained in:
justin
2022-04-18 10:35:43 +08:00
parent c6ec5269f4
commit 3551ca2fcf
25 changed files with 117 additions and 139 deletions

View File

@@ -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)