Fix volume allocation with max=0 and minFreeSpace - prevent allocate-then-delete behavior (#7147)
* Initial plan * Fix volume allocation with max=0 and minFreeSpace - prevent allocate-then-delete behavior Co-authored-by: chrislusf <1543151+chrislusf@users.noreply.github.com> * improve tests * table driven * Update weed/storage/store.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * add tests * add more tests --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: chrislusf <1543151+chrislusf@users.noreply.github.com> Co-authored-by: chrislu <chris.lu@gmail.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -202,6 +202,17 @@ func (s *Store) addVolume(vid needle.VolumeId, collection string, needleMapKind
|
||||
|
||||
// hasFreeDiskLocation checks if a disk location has free space
|
||||
func (s *Store) hasFreeDiskLocation(location *DiskLocation) bool {
|
||||
// Check if disk space is low first
|
||||
if location.isDiskSpaceLow {
|
||||
return false
|
||||
}
|
||||
|
||||
// If MaxVolumeCount is 0, it means unlimited volumes are allowed
|
||||
if location.MaxVolumeCount == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check if current volume count is below the maximum
|
||||
return int64(location.VolumesLen()) < int64(location.MaxVolumeCount)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user