diff options
Diffstat (limited to 'weed/shell')
| -rw-r--r-- | weed/shell/command_ec_balance.go | 8 | ||||
| -rw-r--r-- | weed/shell/command_ec_common.go | 8 | ||||
| -rw-r--r-- | weed/shell/command_volume_balance.go | 8 | ||||
| -rw-r--r-- | weed/shell/command_volume_check_disk.go | 4 | ||||
| -rw-r--r-- | weed/shell/command_volume_fix_replication.go | 14 | ||||
| -rw-r--r-- | weed/shell/command_volume_list.go | 17 | ||||
| -rw-r--r-- | weed/shell/command_volume_server_evacuate.go | 8 | ||||
| -rw-r--r-- | weed/shell/shell_liner.go | 4 |
8 files changed, 35 insertions, 36 deletions
diff --git a/weed/shell/command_ec_balance.go b/weed/shell/command_ec_balance.go index 41077923a..bc322f8fe 100644 --- a/weed/shell/command_ec_balance.go +++ b/weed/shell/command_ec_balance.go @@ -411,8 +411,8 @@ func doBalanceEcRack(commandEnv *CommandEnv, ecRack *EcRack, applyBalancing bool hasMove := true for hasMove { hasMove = false - slices.SortFunc(rackEcNodes, func(a, b *EcNode) int { - return b.freeEcSlot - a.freeEcSlot + slices.SortFunc(rackEcNodes, func(a, b *EcNode) bool { + return a.freeEcSlot > b.freeEcSlot }) emptyNode, fullNode := rackEcNodes[0], rackEcNodes[len(rackEcNodes)-1] emptyNodeShardCount, fullNodeShardCount := ecNodeIdToShardCount[emptyNode.info.Id], ecNodeIdToShardCount[fullNode.info.Id] @@ -492,8 +492,8 @@ func pickNEcShardsToMoveFrom(ecNodes []*EcNode, vid needle.VolumeId, n int) map[ }) } } - slices.SortFunc(candidateEcNodes, func(a, b *CandidateEcNode) int { - return b.shardCount - a.shardCount + slices.SortFunc(candidateEcNodes, func(a, b *CandidateEcNode) bool { + return a.shardCount > b.shardCount }) for i := 0; i < n; i++ { selectedEcNodeIndex := -1 diff --git a/weed/shell/command_ec_common.go b/weed/shell/command_ec_common.go index d3ea19256..5ca77785f 100644 --- a/weed/shell/command_ec_common.go +++ b/weed/shell/command_ec_common.go @@ -119,14 +119,14 @@ func eachDataNode(topo *master_pb.TopologyInfo, fn func(dc string, rack RackId, } func sortEcNodesByFreeslotsDescending(ecNodes []*EcNode) { - slices.SortFunc(ecNodes, func(a, b *EcNode) int { - return b.freeEcSlot - a.freeEcSlot + slices.SortFunc(ecNodes, func(a, b *EcNode) bool { + return a.freeEcSlot > b.freeEcSlot }) } func sortEcNodesByFreeslotsAscending(ecNodes []*EcNode) { - slices.SortFunc(ecNodes, func(a, b *EcNode) int { - return a.freeEcSlot - b.freeEcSlot + slices.SortFunc(ecNodes, func(a, b *EcNode) bool { + return a.freeEcSlot < b.freeEcSlot }) } diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.go index 2284ceea6..b2b65d5d2 100644 --- a/weed/shell/command_volume_balance.go +++ b/weed/shell/command_volume_balance.go @@ -243,8 +243,8 @@ func (n *Node) selectVolumes(fn func(v *master_pb.VolumeInformationMessage) bool } func sortWritableVolumes(volumes []*master_pb.VolumeInformationMessage) { - slices.SortFunc(volumes, func(a, b *master_pb.VolumeInformationMessage) int { - return int(a.Size - b.Size) + slices.SortFunc(volumes, func(a, b *master_pb.VolumeInformationMessage) bool { + return a.Size < b.Size }) } @@ -269,8 +269,8 @@ func balanceSelectedVolume(commandEnv *CommandEnv, diskType types.DiskType, volu for hasMoved { hasMoved = false - slices.SortFunc(nodesWithCapacity, func(a, b *Node) int { - return int(a.localVolumeRatio(capacityFunc) - b.localVolumeRatio(capacityFunc)) + slices.SortFunc(nodesWithCapacity, func(a, b *Node) bool { + return a.localVolumeRatio(capacityFunc) < b.localVolumeRatio(capacityFunc) }) if len(nodesWithCapacity) == 0 { fmt.Printf("no volume server found with capacity for %s", diskType.ReadableString()) diff --git a/weed/shell/command_volume_check_disk.go b/weed/shell/command_volume_check_disk.go index 43a4b26ca..6a1634f8a 100644 --- a/weed/shell/command_volume_check_disk.go +++ b/weed/shell/command_volume_check_disk.go @@ -80,8 +80,8 @@ func (c *commandVolumeCheckDisk) Do(args []string, commandEnv *CommandEnv, write if *volumeId > 0 && replicas[0].info.Id != uint32(*volumeId) { continue } - slices.SortFunc(replicas, func(a, b *VolumeReplica) int { - return int(fileCount(b) - fileCount(a)) + slices.SortFunc(replicas, func(a, b *VolumeReplica) bool { + return fileCount(a) > fileCount(b) }) for len(replicas) >= 2 { a, b := replicas[0], replicas[1] diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go index 56f5f5532..528dfbd2e 100644 --- a/weed/shell/command_volume_fix_replication.go +++ b/weed/shell/command_volume_fix_replication.go @@ -328,8 +328,8 @@ func (c *commandVolumeFixReplication) fixOneUnderReplicatedVolume(commandEnv *Co func keepDataNodesSorted(dataNodes []location, diskType types.DiskType) { fn := capacityByFreeVolumeCount(diskType) - slices.SortFunc(dataNodes, func(a, b location) int { - return int(fn(b.dataNode) - fn(a.dataNode)) + slices.SortFunc(dataNodes, func(a, b location) bool { + return fn(a.dataNode) > fn(b.dataNode) }) } @@ -514,17 +514,17 @@ func countReplicas(replicas []*VolumeReplica) (diffDc, diffRack, diffNode map[st } func pickOneReplicaToDelete(replicas []*VolumeReplica, replicaPlacement *super_block.ReplicaPlacement) *VolumeReplica { - slices.SortFunc(replicas, func(a, b *VolumeReplica) int { + slices.SortFunc(replicas, func(a, b *VolumeReplica) bool { if a.info.Size != b.info.Size { - return int(a.info.Size - b.info.Size) + return a.info.Size < b.info.Size } if a.info.ModifiedAtSecond != b.info.ModifiedAtSecond { - return int(a.info.ModifiedAtSecond - b.info.ModifiedAtSecond) + return a.info.ModifiedAtSecond < b.info.ModifiedAtSecond } if a.info.CompactRevision != b.info.CompactRevision { - return int(a.info.CompactRevision - b.info.CompactRevision) + return a.info.CompactRevision < b.info.CompactRevision } - return 0 + return false }) return replicas[0] diff --git a/weed/shell/command_volume_list.go b/weed/shell/command_volume_list.go index 70b7553b3..b4f94df1a 100644 --- a/weed/shell/command_volume_list.go +++ b/weed/shell/command_volume_list.go @@ -8,7 +8,6 @@ import ( "github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding" "golang.org/x/exp/slices" "path/filepath" - "strings" "io" ) @@ -82,8 +81,8 @@ func diskInfoToString(diskInfo *master_pb.DiskInfo) string { func (c *commandVolumeList) writeTopologyInfo(writer io.Writer, t *master_pb.TopologyInfo, volumeSizeLimitMb uint64, verbosityLevel int) statistics { output(verbosityLevel >= 0, writer, "Topology volumeSizeLimit:%d MB%s\n", volumeSizeLimitMb, diskInfosToString(t.DiskInfos)) - slices.SortFunc(t.DataCenterInfos, func(a, b *master_pb.DataCenterInfo) int { - return strings.Compare(a.Id, b.Id) + slices.SortFunc(t.DataCenterInfos, func(a, b *master_pb.DataCenterInfo) bool { + return a.Id < b.Id }) var s statistics for _, dc := range t.DataCenterInfos { @@ -99,8 +98,8 @@ func (c *commandVolumeList) writeTopologyInfo(writer io.Writer, t *master_pb.Top func (c *commandVolumeList) writeDataCenterInfo(writer io.Writer, t *master_pb.DataCenterInfo, verbosityLevel int) statistics { output(verbosityLevel >= 1, writer, " DataCenter %s%s\n", t.Id, diskInfosToString(t.DiskInfos)) var s statistics - slices.SortFunc(t.RackInfos, func(a, b *master_pb.RackInfo) int { - return strings.Compare(a.Id, b.Id) + slices.SortFunc(t.RackInfos, func(a, b *master_pb.RackInfo) bool { + return a.Id < b.Id }) for _, r := range t.RackInfos { if *c.rack != "" && *c.rack != r.Id { @@ -115,8 +114,8 @@ func (c *commandVolumeList) writeDataCenterInfo(writer io.Writer, t *master_pb.D func (c *commandVolumeList) writeRackInfo(writer io.Writer, t *master_pb.RackInfo, verbosityLevel int) statistics { output(verbosityLevel >= 2, writer, " Rack %s%s\n", t.Id, diskInfosToString(t.DiskInfos)) var s statistics - slices.SortFunc(t.DataNodeInfos, func(a, b *master_pb.DataNodeInfo) int { - return strings.Compare(a.Id, b.Id) + slices.SortFunc(t.DataNodeInfos, func(a, b *master_pb.DataNodeInfo) bool { + return a.Id < b.Id }) for _, dn := range t.DataNodeInfos { if *c.dataNode != "" && *c.dataNode != dn.Id { @@ -160,8 +159,8 @@ func (c *commandVolumeList) writeDiskInfo(writer io.Writer, t *master_pb.DiskInf diskType = "hdd" } output(verbosityLevel >= 4, writer, " Disk %s(%s)\n", diskType, diskInfoToString(t)) - slices.SortFunc(t.VolumeInfos, func(a, b *master_pb.VolumeInformationMessage) int { - return int(a.Id - b.Id) + slices.SortFunc(t.VolumeInfos, func(a, b *master_pb.VolumeInformationMessage) bool { + return a.Id < b.Id }) for _, vi := range t.VolumeInfos { if c.isNotMatchDiskInfo(vi.ReadOnly, vi.Collection, vi.Id) { diff --git a/weed/shell/command_volume_server_evacuate.go b/weed/shell/command_volume_server_evacuate.go index 57eb6fc45..bf0c192ec 100644 --- a/weed/shell/command_volume_server_evacuate.go +++ b/weed/shell/command_volume_server_evacuate.go @@ -179,8 +179,8 @@ func (c *commandVolumeServerEvacuate) evacuateEcVolumes(commandEnv *CommandEnv, func (c *commandVolumeServerEvacuate) 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() { - slices.SortFunc(otherNodes, func(a, b *EcNode) int { - return a.localShardIdCount(ecShardInfo.Id) - b.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] @@ -214,8 +214,8 @@ func moveAwayOneNormalVolume(commandEnv *CommandEnv, volumeReplicas map[uint32][ }) } // most empty one is in the front - slices.SortFunc(otherNodes, func(a, b *Node) int { - return int(a.localVolumeRatio(maxVolumeCountFn) - b.localVolumeRatio(maxVolumeCountFn)) + slices.SortFunc(otherNodes, func(a, b *Node) bool { + return a.localVolumeRatio(maxVolumeCountFn) < b.localVolumeRatio(maxVolumeCountFn) }) for i := 0; i < len(otherNodes); i++ { emptyNode := otherNodes[i] diff --git a/weed/shell/shell_liner.go b/weed/shell/shell_liner.go index 3e55cc88e..f8f4002fa 100644 --- a/weed/shell/shell_liner.go +++ b/weed/shell/shell_liner.go @@ -26,8 +26,8 @@ var ( ) func RunShell(options ShellOptions) { - slices.SortFunc(Commands, func(a, b command) int { - return strings.Compare(a.Name(), b.Name()) + slices.SortFunc(Commands, func(a, b command) bool { + return strings.Compare(a.Name(), b.Name()) < 0 }) line = liner.NewLiner() defer line.Close() |
