SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
weed/shell: Fix volume.balance logic (#5238)
Benoît Knechta6aee847b9b2
diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.goindex 2284ceea6c..ccfa27bb90 100644--- a/weed/shell/command_volume_balance.go+++ b/weed/shell/command_volume_balance.go@@ -1,6 +1,7 @@package shellimport (+ "cmp""flag""fmt""io"@@ -244,7 +245,7 @@ func (n *Node) selectVolumes(fn func(v *master_pb.VolumeInformationMessage) boolfunc sortWritableVolumes(volumes []*master_pb.VolumeInformationMessage) {slices.SortFunc(volumes, func(a, b *master_pb.VolumeInformationMessage) int {- return int(a.Size - b.Size)+ return cmp.Compare(a.Size, b.Size)})}@@ -270,7 +271,7 @@ func balanceSelectedVolume(commandEnv *CommandEnv, diskType types.DiskType, volufor hasMoved {hasMoved = falseslices.SortFunc(nodesWithCapacity, func(a, b *Node) int {- return int(a.localVolumeRatio(capacityFunc) - b.localVolumeRatio(capacityFunc))+ return cmp.Compare(a.localVolumeRatio(capacityFunc), b.localVolumeRatio(capacityFunc))})if len(nodesWithCapacity) == 0 {fmt.Printf("no volume server found with capacity for %s", diskType.ReadableString())@@ -278,7 +279,8 @@ func balanceSelectedVolume(commandEnv *CommandEnv, diskType types.DiskType, volu}var fullNode *Node- for fullNodeIndex := len(nodesWithCapacity) - 1; fullNodeIndex >= 0; fullNodeIndex-- {+ var fullNodeIndex int+ for fullNodeIndex = len(nodesWithCapacity) - 1; fullNodeIndex >= 0; fullNodeIndex-- {fullNode = nodesWithCapacity[fullNodeIndex]if !fullNode.isOneVolumeOnly() {break@@ -289,9 +291,7 @@ func balanceSelectedVolume(commandEnv *CommandEnv, diskType types.DiskType, volucandidateVolumes = append(candidateVolumes, v)}sortCandidatesFn(candidateVolumes)-- for i := 0; i < len(nodesWithCapacity)-1; i++ {- emptyNode := nodesWithCapacity[i]+ for _, emptyNode := range nodesWithCapacity[:fullNodeIndex] {if !(fullNode.localVolumeRatio(capacityFunc) > idealVolumeRatio && emptyNode.localVolumeNextRatio(capacityFunc) <= idealVolumeRatio) {// no more volume servers with empty slotsbreak