mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* fix(master): handle capacity changes during volume placement * topology: test capacity changes during placement deterministically The maintenance-toggling loops ran for seconds and could pass without reaching either guard. Drain the secondary rack or data center right before its slot draw, and feed PickNodesByWeight a node whose reported capacity changes between reads. Each case fails on the code before the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1008 B
Go
39 lines
1008 B
Go
package topology
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
)
|
|
|
|
// shiftingDataNode reports a different free slot count on each read, as a
|
|
// heartbeat landing mid-selection would.
|
|
type shiftingDataNode struct {
|
|
*DataNode
|
|
reads []int64
|
|
}
|
|
|
|
func (s *shiftingDataNode) AvailableSpaceFor(*VolumeGrowOption) int64 {
|
|
v := s.reads[0]
|
|
if len(s.reads) > 1 {
|
|
s.reads = s.reads[1:]
|
|
}
|
|
return v
|
|
}
|
|
|
|
func TestPickNodesByWeightReadsCapacityOnce(t *testing.T) {
|
|
rack := NewRack("rack1")
|
|
addMaintenanceTestNode(rack, "steady", 10)
|
|
shifting := &shiftingDataNode{DataNode: NewDataNode("shifting"), reads: []int64{10, 10, 0}}
|
|
rack.LinkChildNode(shifting)
|
|
|
|
option := &VolumeGrowOption{DiskType: types.HardDriveType}
|
|
first, rest, err := rack.PickNodesByWeight(2, option, func(Node) error { return nil })
|
|
if err != nil {
|
|
t.Fatalf("PickNodesByWeight: %v", err)
|
|
}
|
|
if first == nil || len(rest) != 1 {
|
|
t.Fatalf("picked first=%v and %d more nodes, want 1 more", first, len(rest))
|
|
}
|
|
}
|