mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-16 02:58:35 +02:00
fix(shell): compare fractional evacuation destination ratios (#11752)
This commit is contained in:
1 parent
9e56651808
commit
e12ec94747
2 files changed
+18
-1
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -273,7 +274,7 @@ 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))
|
||||
return cmp.Compare(a.localVolumeRatio(maxVolumeCountFn), b.localVolumeRatio(maxVolumeCountFn))
|
||||
})
|
||||
for i := 0; i < len(otherNodes); i++ {
|
||||
emptyNode := otherNodes[i]
|
||||
|
||||
@@ -5,6 +5,22 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEvacuatePrefersLowerVolumeRatio(t *testing.T) {
|
||||
volumes := mkByteVolumes(1, 1, 1)
|
||||
source := makeByteNode("source", 10, 0, 0, volumes)
|
||||
fuller := makeByteNode("fuller", 10, 0, 0, mkByteVolumes(10, 4, 1))
|
||||
emptier := makeByteNode("emptier", 10, 0, 0, mkByteVolumes(20, 2, 1))
|
||||
|
||||
// Put the 40%-full server first: truncating 0.2 - 0.4 to int makes the ratios tie.
|
||||
moved, err := moveAwayOneNormalVolume(nil, nil, volumes[0], source, []*Node{fuller, emptier}, false)
|
||||
if err != nil || !moved {
|
||||
t.Fatalf("evacuate: moved=%v, err=%v", moved, err)
|
||||
}
|
||||
if _, found := emptier.selectedVolumes[volumes[0].Id]; !found {
|
||||
t.Fatal("expected evacuation to choose the server with lower occupancy")
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeServerEvacuate(t *testing.T) {
|
||||
targetServer := ""
|
||||
volumeRack := "rack1"
|
||||
|
||||
Reference in new issue
Block a user