From 645ae8c57bc449cbb298e90d1ad19f7d2153aea0 Mon Sep 17 00:00:00 2001 From: chrislu Date: Mon, 25 Sep 2023 09:35:16 -0700 Subject: [PATCH] Revert "Revert "Merge branch 'master' of https://github.com/seaweedfs/seaweedfs"" This reverts commit 8cb42c39 --- weed/command/master.go | 4 ++-- weed/filer/filechunks2_test.go | 6 +++--- weed/filer/filechunks_read.go | 14 ++++++++++---- weed/filer/redis/universal_redis_store.go | 4 ++-- weed/filer/stream.go | 8 ++++---- weed/s3api/filer_multipart.go | 4 ++-- weed/s3api/s3api_object_handlers.go | 4 ++-- .../filer_server_handlers_write_upload.go | 4 ++-- weed/shell/command_ec_balance.go | 8 ++++---- weed/shell/command_ec_common.go | 8 ++++---- weed/shell/command_volume_balance.go | 8 ++++---- weed/shell/command_volume_check_disk.go | 4 ++-- weed/shell/command_volume_fix_replication.go | 14 +++++++------- weed/shell/command_volume_list.go | 17 +++++++++-------- weed/shell/command_volume_server_evacuate.go | 8 ++++---- weed/shell/shell_liner.go | 4 ++-- weed/storage/disk_location_ec.go | 5 +++-- weed/storage/erasure_coding/ec_volume.go | 7 +++++-- weed/storage/store_ec.go | 4 ++-- weed/topology/data_center.go | 5 +++-- weed/topology/rack.go | 5 +++-- weed/topology/topology_info.go | 5 +++-- weed/util/chunk_cache/on_disk_cache_layer.go | 4 ++-- 23 files changed, 84 insertions(+), 70 deletions(-) diff --git a/weed/command/master.go b/weed/command/master.go index 02a155da8..6a32b8abe 100644 --- a/weed/command/master.go +++ b/weed/command/master.go @@ -288,8 +288,8 @@ func checkPeers(masterIp string, masterPort int, masterGrpcPort int, peers strin } func isTheFirstOne(self pb.ServerAddress, peers []pb.ServerAddress) bool { - slices.SortFunc(peers, func(a, b pb.ServerAddress) bool { - return strings.Compare(string(a), string(b)) < 0 + slices.SortFunc(peers, func(a, b pb.ServerAddress) int { + return strings.Compare(string(a), string(b)) }) if len(peers) <= 0 { return true diff --git a/weed/filer/filechunks2_test.go b/weed/filer/filechunks2_test.go index 6966360ad..6728aec0d 100644 --- a/weed/filer/filechunks2_test.go +++ b/weed/filer/filechunks2_test.go @@ -73,11 +73,11 @@ func TestCompactFileChunksRealCase(t *testing.T) { } func printChunks(name string, chunks []*filer_pb.FileChunk) { - slices.SortFunc(chunks, func(a, b *filer_pb.FileChunk) bool { + slices.SortFunc(chunks, func(a, b *filer_pb.FileChunk) int { if a.Offset == b.Offset { - return a.ModifiedTsNs < b.ModifiedTsNs + return int(a.ModifiedTsNs - b.ModifiedTsNs) } - return a.Offset < b.Offset + return int(a.Offset - b.Offset) }) for _, chunk := range chunks { glog.V(0).Infof("%s chunk %s [%10d,%10d)", name, chunk.GetFileIdString(), chunk.Offset, chunk.Offset+int64(chunk.Size)) diff --git a/weed/filer/filechunks_read.go b/weed/filer/filechunks_read.go index 8b2d36e12..b8768ed63 100644 --- a/weed/filer/filechunks_read.go +++ b/weed/filer/filechunks_read.go @@ -30,14 +30,20 @@ func readResolvedChunks(chunks []*filer_pb.FileChunk, startOffset int64, stopOff isStart: false, }) } - slices.SortFunc(points, func(a, b *Point) bool { + slices.SortFunc(points, func(a, b *Point) int { if a.x != b.x { - return a.x < b.x + return int(a.x - b.x) } if a.ts != b.ts { - return a.ts < b.ts + return int(a.ts - b.ts) } - return !a.isStart + if a.isStart { + return -1 + } + if b.isStart { + return 1 + } + return 0 }) var prevX int64 diff --git a/weed/filer/redis/universal_redis_store.go b/weed/filer/redis/universal_redis_store.go index e56a6bf3c..33c0ea342 100644 --- a/weed/filer/redis/universal_redis_store.go +++ b/weed/filer/redis/universal_redis_store.go @@ -164,8 +164,8 @@ func (store *UniversalRedisStore) ListDirectoryEntries(ctx context.Context, dirP } // sort - slices.SortFunc(members, func(a, b string) bool { - return strings.Compare(a, b) < 0 + slices.SortFunc(members, func(a, b string) int { + return strings.Compare(a, b) }) // limit diff --git a/weed/filer/stream.go b/weed/filer/stream.go index 9e3bb5f76..eb8f0f3a1 100644 --- a/weed/filer/stream.go +++ b/weed/filer/stream.go @@ -45,11 +45,11 @@ func isSameChunks(a, b []*filer_pb.FileChunk) bool { if len(a) != len(b) { return false } - slices.SortFunc(a, func(i, j *filer_pb.FileChunk) bool { - return strings.Compare(i.ETag, j.ETag) < 0 + slices.SortFunc(a, func(i, j *filer_pb.FileChunk) int { + return strings.Compare(i.ETag, j.ETag) }) - slices.SortFunc(b, func(i, j *filer_pb.FileChunk) bool { - return strings.Compare(i.ETag, j.ETag) < 0 + slices.SortFunc(b, func(i, j *filer_pb.FileChunk) int { + return strings.Compare(i.ETag, j.ETag) }) for i := 0; i < len(a); i++ { if a[i].ETag != b[i].ETag { diff --git a/weed/s3api/filer_multipart.go b/weed/s3api/filer_multipart.go index f8027c7ee..765a5679e 100644 --- a/weed/s3api/filer_multipart.go +++ b/weed/s3api/filer_multipart.go @@ -72,8 +72,8 @@ func (s3a *S3ApiServer) completeMultipartUpload(input *s3.CompleteMultipartUploa glog.V(2).Infof("completeMultipartUpload input %v", input) completedParts := parts.Parts - slices.SortFunc(completedParts, func(a, b CompletedPart) bool { - return a.PartNumber < b.PartNumber + slices.SortFunc(completedParts, func(a, b CompletedPart) int { + return a.PartNumber - b.PartNumber }) uploadDirectory := s3a.genUploadsFolder(*input.Bucket) + "/" + *input.UploadId diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go index b63997cd3..f32dcefeb 100644 --- a/weed/s3api/s3api_object_handlers.go +++ b/weed/s3api/s3api_object_handlers.go @@ -334,8 +334,8 @@ func (s3a *S3ApiServer) doDeleteEmptyDirectories(client filer_pb.SeaweedFilerCli for dir := range directoriesWithDeletion { allDirs = append(allDirs, dir) } - slices.SortFunc(allDirs, func(a, b string) bool { - return len(a) > len(b) + slices.SortFunc(allDirs, func(a, b string) int { + return len(b) - len(a) }) newDirectoriesWithDeletion = make(map[string]int) for _, dir := range allDirs { diff --git a/weed/server/filer_server_handlers_write_upload.go b/weed/server/filer_server_handlers_write_upload.go index c47ed223b..a329a38af 100644 --- a/weed/server/filer_server_handlers_write_upload.go +++ b/weed/server/filer_server_handlers_write_upload.go @@ -135,8 +135,8 @@ func (fs *FilerServer) uploadReaderToChunks(w http.ResponseWriter, r *http.Reque fs.filer.DeleteChunks(fileChunks) return nil, md5Hash, 0, uploadErr, nil } - slices.SortFunc(fileChunks, func(a, b *filer_pb.FileChunk) bool { - return a.Offset < b.Offset + slices.SortFunc(fileChunks, func(a, b *filer_pb.FileChunk) int { + return int(a.Offset - b.Offset) }) return fileChunks, md5Hash, chunkOffset, nil, smallContent } diff --git a/weed/shell/command_ec_balance.go b/weed/shell/command_ec_balance.go index bc322f8fe..41077923a 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) bool { - return a.freeEcSlot > b.freeEcSlot + slices.SortFunc(rackEcNodes, func(a, b *EcNode) int { + return b.freeEcSlot - a.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) bool { - return a.shardCount > b.shardCount + slices.SortFunc(candidateEcNodes, func(a, b *CandidateEcNode) int { + return b.shardCount - a.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 5ca77785f..d3ea19256 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) bool { - return a.freeEcSlot > b.freeEcSlot + slices.SortFunc(ecNodes, func(a, b *EcNode) int { + return b.freeEcSlot - a.freeEcSlot }) } func sortEcNodesByFreeslotsAscending(ecNodes []*EcNode) { - slices.SortFunc(ecNodes, func(a, b *EcNode) bool { - return a.freeEcSlot < b.freeEcSlot + slices.SortFunc(ecNodes, func(a, b *EcNode) int { + return a.freeEcSlot - b.freeEcSlot }) } diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.go index b2b65d5d2..2284ceea6 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) bool { - return a.Size < b.Size + slices.SortFunc(volumes, func(a, b *master_pb.VolumeInformationMessage) int { + return int(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) bool { - return a.localVolumeRatio(capacityFunc) < b.localVolumeRatio(capacityFunc) + slices.SortFunc(nodesWithCapacity, func(a, b *Node) int { + return int(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 6a1634f8a..43a4b26ca 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) bool { - return fileCount(a) > fileCount(b) + slices.SortFunc(replicas, func(a, b *VolumeReplica) int { + return int(fileCount(b) - fileCount(a)) }) 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 528dfbd2e..56f5f5532 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) bool { - return fn(a.dataNode) > fn(b.dataNode) + slices.SortFunc(dataNodes, func(a, b location) int { + return int(fn(b.dataNode) - fn(a.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) bool { + slices.SortFunc(replicas, func(a, b *VolumeReplica) int { if a.info.Size != b.info.Size { - return a.info.Size < b.info.Size + return int(a.info.Size - b.info.Size) } if a.info.ModifiedAtSecond != b.info.ModifiedAtSecond { - return a.info.ModifiedAtSecond < b.info.ModifiedAtSecond + return int(a.info.ModifiedAtSecond - b.info.ModifiedAtSecond) } if a.info.CompactRevision != b.info.CompactRevision { - return a.info.CompactRevision < b.info.CompactRevision + return int(a.info.CompactRevision - b.info.CompactRevision) } - return false + return 0 }) return replicas[0] diff --git a/weed/shell/command_volume_list.go b/weed/shell/command_volume_list.go index b4f94df1a..70b7553b3 100644 --- a/weed/shell/command_volume_list.go +++ b/weed/shell/command_volume_list.go @@ -8,6 +8,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding" "golang.org/x/exp/slices" "path/filepath" + "strings" "io" ) @@ -81,8 +82,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) bool { - return a.Id < b.Id + slices.SortFunc(t.DataCenterInfos, func(a, b *master_pb.DataCenterInfo) int { + return strings.Compare(a.Id, b.Id) }) var s statistics for _, dc := range t.DataCenterInfos { @@ -98,8 +99,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) bool { - return a.Id < b.Id + slices.SortFunc(t.RackInfos, func(a, b *master_pb.RackInfo) int { + return strings.Compare(a.Id, b.Id) }) for _, r := range t.RackInfos { if *c.rack != "" && *c.rack != r.Id { @@ -114,8 +115,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) bool { - return a.Id < b.Id + slices.SortFunc(t.DataNodeInfos, func(a, b *master_pb.DataNodeInfo) int { + return strings.Compare(a.Id, b.Id) }) for _, dn := range t.DataNodeInfos { if *c.dataNode != "" && *c.dataNode != dn.Id { @@ -159,8 +160,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) bool { - return a.Id < b.Id + slices.SortFunc(t.VolumeInfos, func(a, b *master_pb.VolumeInformationMessage) int { + return int(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 bf0c192ec..57eb6fc45 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) bool { - return a.localShardIdCount(ecShardInfo.Id) < b.localShardIdCount(ecShardInfo.Id) + slices.SortFunc(otherNodes, func(a, b *EcNode) int { + 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) bool { - return a.localVolumeRatio(maxVolumeCountFn) < b.localVolumeRatio(maxVolumeCountFn) + slices.SortFunc(otherNodes, func(a, b *Node) int { + return int(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 f8f4002fa..3e55cc88e 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) bool { - return strings.Compare(a.Name(), b.Name()) < 0 + slices.SortFunc(Commands, func(a, b command) int { + return strings.Compare(a.Name(), b.Name()) }) line = liner.NewLiner() defer line.Close() diff --git a/weed/storage/disk_location_ec.go b/weed/storage/disk_location_ec.go index 5af354277..8315fe363 100644 --- a/weed/storage/disk_location_ec.go +++ b/weed/storage/disk_location_ec.go @@ -7,6 +7,7 @@ import ( "path" "regexp" "strconv" + "strings" "github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding" "github.com/seaweedfs/seaweedfs/weed/storage/needle" @@ -144,8 +145,8 @@ func (l *DiskLocation) loadAllEcShards() (err error) { } dirEntries = append(dirEntries, indexDirEntries...) } - slices.SortFunc(dirEntries, func(a, b os.DirEntry) bool { - return a.Name() < b.Name() + slices.SortFunc(dirEntries, func(a, b os.DirEntry) int { + return strings.Compare(a.Name(), b.Name()) }) var sameVolumeShards []string var prevVolumeId needle.VolumeId diff --git a/weed/storage/erasure_coding/ec_volume.go b/weed/storage/erasure_coding/ec_volume.go index 3e48e2c2d..81284d19f 100644 --- a/weed/storage/erasure_coding/ec_volume.go +++ b/weed/storage/erasure_coding/ec_volume.go @@ -84,8 +84,11 @@ func (ev *EcVolume) AddEcVolumeShard(ecVolumeShard *EcVolumeShard) bool { } } ev.Shards = append(ev.Shards, ecVolumeShard) - slices.SortFunc(ev.Shards, func(a, b *EcVolumeShard) bool { - return a.VolumeId < b.VolumeId || a.VolumeId == b.VolumeId && a.ShardId < b.ShardId + slices.SortFunc(ev.Shards, func(a, b *EcVolumeShard) int { + if a.VolumeId != b.VolumeId { + return int(a.VolumeId - b.VolumeId) + } + return int(a.ShardId - b.ShardId) }) return true } diff --git a/weed/storage/store_ec.go b/weed/storage/store_ec.go index 18dc5677c..4e2c8df3b 100644 --- a/weed/storage/store_ec.go +++ b/weed/storage/store_ec.go @@ -400,8 +400,8 @@ func (s *Store) EcVolumes() (ecVolumes []*erasure_coding.EcVolume) { } location.ecVolumesLock.RUnlock() } - slices.SortFunc(ecVolumes, func(a, b *erasure_coding.EcVolume) bool { - return a.VolumeId > b.VolumeId + slices.SortFunc(ecVolumes, func(a, b *erasure_coding.EcVolume) int { + return int(b.VolumeId - a.VolumeId) }) return ecVolumes } diff --git a/weed/topology/data_center.go b/weed/topology/data_center.go index 26d2de7d3..55b17e911 100644 --- a/weed/topology/data_center.go +++ b/weed/topology/data_center.go @@ -3,6 +3,7 @@ package topology import ( "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" "golang.org/x/exp/slices" + "strings" ) type DataCenter struct { @@ -46,8 +47,8 @@ func (dc *DataCenter) ToInfo() (info DataCenterInfo) { racks = append(racks, rack.ToInfo()) } - slices.SortFunc(racks, func(a, b RackInfo) bool { - return a.Id < b.Id + slices.SortFunc(racks, func(a, b RackInfo) int { + return strings.Compare(string(a.Id), string(b.Id)) }) info.Racks = racks return diff --git a/weed/topology/rack.go b/weed/topology/rack.go index c96bf421e..6bf8b5b4e 100644 --- a/weed/topology/rack.go +++ b/weed/topology/rack.go @@ -5,6 +5,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/storage/types" "github.com/seaweedfs/seaweedfs/weed/util" "golang.org/x/exp/slices" + "strings" "time" ) @@ -69,8 +70,8 @@ func (r *Rack) ToInfo() (info RackInfo) { dns = append(dns, dn.ToInfo()) } - slices.SortFunc(dns, func(a, b DataNodeInfo) bool { - return a.Url < b.Url + slices.SortFunc(dns, func(a, b DataNodeInfo) int { + return strings.Compare(a.Url, b.Url) }) info.DataNodes = dns diff --git a/weed/topology/topology_info.go b/weed/topology/topology_info.go index 680a0528c..afbeb4894 100644 --- a/weed/topology/topology_info.go +++ b/weed/topology/topology_info.go @@ -3,6 +3,7 @@ package topology import ( "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" "golang.org/x/exp/slices" + "strings" ) type TopologyInfo struct { @@ -21,8 +22,8 @@ func (t *Topology) ToInfo() (info TopologyInfo) { dcs = append(dcs, dc.ToInfo()) } - slices.SortFunc(dcs, func(a, b DataCenterInfo) bool { - return a.Id < b.Id + slices.SortFunc(dcs, func(a, b DataCenterInfo) int { + return strings.Compare(string(a.Id), string(b.Id)) }) info.DataCenters = dcs diff --git a/weed/util/chunk_cache/on_disk_cache_layer.go b/weed/util/chunk_cache/on_disk_cache_layer.go index 9f5d9ff9a..b89b4aab8 100644 --- a/weed/util/chunk_cache/on_disk_cache_layer.go +++ b/weed/util/chunk_cache/on_disk_cache_layer.go @@ -32,8 +32,8 @@ func NewOnDiskCacheLayer(dir, namePrefix string, diskSize int64, segmentCount in } // keep newest cache to the front - slices.SortFunc(c.diskCaches, func(a, b *ChunkCacheVolume) bool { - return a.lastModTime.After(b.lastModTime) + slices.SortFunc(c.diskCaches, func(a, b *ChunkCacheVolume) int { + return b.lastModTime.Compare(a.lastModTime) }) return c }