create new volumes on less occupied disk locations (#7349)

* create new volumes on less occupied disk locations

* add unit tests

* address comments

* fixes
This commit is contained in:
Chris Lu
2025-10-20 16:11:29 -07:00
committed by GitHub
parent 3e8cc5a906
commit ffd43218f6
4 changed files with 328 additions and 4 deletions

View File

@@ -165,14 +165,18 @@ func (s *Store) addVolume(vid needle.VolumeId, collection string, needleMapKind
return fmt.Errorf("Volume Id %d already exists!", vid)
}
// Find location and its index
// Find location with lowest local volume count (load balancing)
var location *DiskLocation
var diskId uint32
var minVolCount int
for i, loc := range s.Locations {
if loc.DiskType == diskType && s.hasFreeDiskLocation(loc) {
location = loc
diskId = uint32(i)
break
volCount := loc.LocalVolumesLen()
if location == nil || volCount < minVolCount {
location = loc
diskId = uint32(i)
minVolCount = volCount
}
}
}