mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-06 03:57:48 +01:00
balance: extract the bytes-aware density metric to a shared package (#10174)
* balance: extract the bytes-aware density metric to weed/topology/balancer The shell's volume.balance ranks servers by a bytes-aware density (used volume equivalents over free capacity). Move that math into the shared balancer package (VolumeDensity / DensityRatio / DensityNextRatio) so the maintenance worker can adopt the same metric next. Shell behavior is unchanged. * balance: rank a server with no free capacity as the fullest DensityRatio/DensityNextRatio divided by capacity, so a server past its slot limit (negative capacity) returned a negative ratio and sorted as the emptiest under ascending consumers — the opposite of reality. Treat any non-positive capacity (full, or overfull mid-run after receiving volumes) as the fullest (+Inf) so it is a move source, never a target. Covered by negative-capacity and ordering tests.
This commit is contained in:
1 parent
430d4b5394
commit
b872d5e683
3 files changed
+138
-21
No files matched your search
@@ -23,10 +23,7 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
||||
)
|
||||
|
||||
const (
|
||||
thresholdVolumeSize = 1.01
|
||||
countZeroSelectedVolumes = 0.5
|
||||
)
|
||||
const thresholdVolumeSize = 1.01
|
||||
|
||||
func init() {
|
||||
Commands = append(Commands, &commandVolumeBalance{})
|
||||
@@ -338,8 +335,7 @@ func capacityByMinVolumeDensity(diskType types.DiskType, volumeSizeLimitMb uint6
|
||||
if volumeSizeLimitMb == 0 {
|
||||
volumeSizeLimitMb = util.VolumeSizeLimitGB * util.KiByte
|
||||
}
|
||||
usedVolumeCount := volumeSizes / (volumeSizeLimitMb * util.MiByte)
|
||||
return float64(diskInfo.MaxVolumeCount - int64(usedVolumeCount)), usedVolumeCount
|
||||
return balancer.VolumeDensity(diskInfo.MaxVolumeCount, volumeSizes, volumeSizeLimitMb*util.MiByte)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,8 +361,7 @@ func capacityByActualDataUsage(diskType types.DiskType, volumeSizeLimitMb uint64
|
||||
if volumeSizeLimitMb == 0 {
|
||||
volumeSizeLimitMb = util.VolumeSizeLimitGB * util.KiByte
|
||||
}
|
||||
usedVolumeCount := volumeSizes / (volumeSizeLimitMb * util.MiByte)
|
||||
return 1, usedVolumeCount
|
||||
return 1, balancer.UsedVolumeEquivalents(volumeSizes, volumeSizeLimitMb*util.MiByte)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,22 +394,11 @@ func capacityByFreeVolumeCount(diskType types.DiskType) CapacityFunc {
|
||||
}
|
||||
|
||||
func (n *Node) localVolumeDensityRatio(capacityFunc DensityFunc) float64 {
|
||||
capacity, selectedVolumes := capacityFunc(n.info)
|
||||
if capacity == 0 {
|
||||
return 0
|
||||
}
|
||||
if selectedVolumes == 0 {
|
||||
return countZeroSelectedVolumes / capacity
|
||||
}
|
||||
return float64(selectedVolumes) / capacity
|
||||
return balancer.DensityRatio(capacityFunc(n.info))
|
||||
}
|
||||
|
||||
func (n *Node) localVolumeDensityNextRatio(capacityFunc DensityFunc) float64 {
|
||||
capacity, selectedVolumes := capacityFunc(n.info)
|
||||
if capacity == 0 {
|
||||
return 0
|
||||
}
|
||||
return float64(selectedVolumes+1) / capacity
|
||||
return balancer.DensityNextRatio(capacityFunc(n.info))
|
||||
}
|
||||
|
||||
func (n *Node) localVolumeRatio(capacityFunc CapacityFunc) float64 {
|
||||
|
||||
Reference in new issue
Block a user