Browse Source

fix: deterministic disk tie-breaking and stronger pre-existing task test

- Sort available disks by NodeID then DiskID before scoring so
  destination selection is deterministic when two disks score equally
- Add task count bounds assertion to SkipsPreExistingPendingTasks test:
  with 15 of 20 volumes already having pending tasks, at most 5 new
  tasks should be created and at least 1 (imbalance still exists)
pull/8559/head
Chris Lu 21 hours ago
parent
commit
d6fa3c9331
  1. 8
      weed/worker/tasks/balance/detection.go
  2. 9
      weed/worker/tasks/balance/detection_test.go

8
weed/worker/tasks/balance/detection.go

@ -377,6 +377,14 @@ func planBalanceDestination(activeTopology *topology.ActiveTopology, selectedVol
return nil, fmt.Errorf("no available disks for balance operation")
}
// Sort available disks by NodeID then DiskID for deterministic tie-breaking
sort.Slice(availableDisks, func(i, j int) bool {
if availableDisks[i].NodeID != availableDisks[j].NodeID {
return availableDisks[i].NodeID < availableDisks[j].NodeID
}
return availableDisks[i].DiskID < availableDisks[j].DiskID
})
// Find the best destination disk based on balance criteria
var bestDisk *topology.DiskInfo
bestScore := math.Inf(-1)

9
weed/worker/tasks/balance/detection_test.go

@ -576,6 +576,15 @@ func TestDetection_SkipsPreExistingPendingTasks(t *testing.T) {
}
}
// With 15 of 20 volumes on node-a already having pending tasks, only
// volumes 16-20 are eligible. Detection should produce at most 5 new tasks.
if len(tasks) > 5 {
t.Errorf("Expected at most 5 new tasks (only 5 eligible volumes remain), got %d", len(tasks))
}
if len(tasks) == 0 {
t.Errorf("Expected at least 1 new task since imbalance still exists with actual volume counts")
}
assertNoDuplicateVolumes(t, tasks)
}

Loading…
Cancel
Save