Browse Source

fix: consistent hasMore pattern and remove double-counted LoadCount in scoring

- Adopt vacuum_handler's hasMore pattern: over-fetch by 1, check
  len > maxResults, and truncate — consistent truncation semantics
- Remove direct LoadCount penalty in calculateBalanceScore since
  LoadCount is already factored into effectiveVolumeCount for
  utilization scoring; bump utilization weight from 40 to 50 to
  compensate for the removed 10-point load penalty
pull/8559/head
Chris Lu 2 days ago
parent
commit
85bc50ee1e
  1. 8
      weed/plugin/worker/volume_balance_handler.go
  2. 9
      weed/worker/tasks/balance/detection.go

8
weed/plugin/worker/volume_balance_handler.go

@ -228,7 +228,7 @@ func (h *VolumeBalanceHandler) Detect(
if maxResults <= 0 { if maxResults <= 0 {
maxResults = 1 maxResults = 1
} }
results, err := balancetask.Detection(metrics, clusterInfo, workerConfig.TaskConfig, maxResults)
results, err := balancetask.Detection(metrics, clusterInfo, workerConfig.TaskConfig, maxResults+1)
if err != nil { if err != nil {
return err return err
} }
@ -236,7 +236,11 @@ func (h *VolumeBalanceHandler) Detect(
glog.Warningf("Plugin worker failed to emit volume_balance detection trace: %v", traceErr) glog.Warningf("Plugin worker failed to emit volume_balance detection trace: %v", traceErr)
} }
hasMore := len(results) >= maxResults
hasMore := false
if maxResults > 0 && len(results) > maxResults {
hasMore = true
results = results[:maxResults]
}
proposals := make([]*plugin_pb.JobProposal, 0, len(results)) proposals := make([]*plugin_pb.JobProposal, 0, len(results))
for _, result := range results { for _, result := range results {

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

@ -370,11 +370,13 @@ func calculateBalanceScore(disk *topology.DiskInfo, sourceRack, sourceDC string,
score := 0.0 score := 0.0
// Prefer disks with lower effective volume count (current + pending moves)
// Prefer disks with lower effective volume count (current + pending moves).
// LoadCount is included so that disks already targeted by planned moves
// appear more utilized, naturally spreading work across targets.
if disk.DiskInfo.MaxVolumeCount > 0 { if disk.DiskInfo.MaxVolumeCount > 0 {
effectiveVolumeCount := float64(disk.DiskInfo.VolumeCount) + float64(disk.LoadCount) effectiveVolumeCount := float64(disk.DiskInfo.VolumeCount) + float64(disk.LoadCount)
utilization := effectiveVolumeCount / float64(disk.DiskInfo.MaxVolumeCount) utilization := effectiveVolumeCount / float64(disk.DiskInfo.MaxVolumeCount)
score += (1.0 - utilization) * 40.0 // Up to 40 points for low utilization
score += (1.0 - utilization) * 50.0 // Up to 50 points for low utilization
} }
// Prefer different racks for better distribution // Prefer different racks for better distribution
@ -387,8 +389,5 @@ func calculateBalanceScore(disk *topology.DiskInfo, sourceRack, sourceDC string,
score += 20.0 score += 20.0
} }
// Prefer disks with lower current load
score += (10.0 - float64(disk.LoadCount)) // Up to 10 points for low load
return score return score
} }
Loading…
Cancel
Save