diff options
| author | Copilot <198982749+Copilot@users.noreply.github.com> | 2025-08-23 13:03:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-23 13:03:53 -0700 |
| commit | 91b88262d7a05b6865af748ef466f67c1f14eb76 (patch) | |
| tree | 0e90cfc69ceae7f950e383618466f92156d72e21 /weed/storage/store_disk_space_test.go | |
| parent | 41aedaa6876d5ef200928aafaec7c9d0b8a8a764 (diff) | |
| download | seaweedfs-91b88262d7a05b6865af748ef466f67c1f14eb76.tar.xz seaweedfs-91b88262d7a05b6865af748ef466f67c1f14eb76.zip | |
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>
Diffstat (limited to 'weed/storage/store_disk_space_test.go')
| -rw-r--r-- | weed/storage/store_disk_space_test.go | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/weed/storage/store_disk_space_test.go b/weed/storage/store_disk_space_test.go new file mode 100644 index 000000000..284657e3c --- /dev/null +++ b/weed/storage/store_disk_space_test.go @@ -0,0 +1,94 @@ +package storage + +import ( + "testing" + + "github.com/seaweedfs/seaweedfs/weed/storage/needle" +) + +func TestHasFreeDiskLocation(t *testing.T) { + testCases := []struct { + name string + isDiskSpaceLow bool + maxVolumeCount int32 + currentVolumes int + expected bool + }{ + { + name: "low disk space prevents allocation", + isDiskSpaceLow: true, + maxVolumeCount: 10, + currentVolumes: 5, + expected: false, + }, + { + name: "normal disk space and available volume count allows allocation", + isDiskSpaceLow: false, + maxVolumeCount: 10, + currentVolumes: 5, + expected: true, + }, + { + name: "volume count at max prevents allocation", + isDiskSpaceLow: false, + maxVolumeCount: 2, + currentVolumes: 2, + expected: false, + }, + { + name: "volume count over max prevents allocation", + isDiskSpaceLow: false, + maxVolumeCount: 2, + currentVolumes: 3, + expected: false, + }, + { + name: "volume count just under max allows allocation", + isDiskSpaceLow: false, + maxVolumeCount: 2, + currentVolumes: 1, + expected: true, + }, + { + name: "max volume count is 0 allows allocation", + isDiskSpaceLow: false, + maxVolumeCount: 0, + currentVolumes: 100, + expected: true, + }, + { + name: "max volume count is 0 but low disk space prevents allocation", + isDiskSpaceLow: true, + maxVolumeCount: 0, + currentVolumes: 100, + expected: false, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // setup + diskLocation := &DiskLocation{ + volumes: make(map[needle.VolumeId]*Volume), + isDiskSpaceLow: tc.isDiskSpaceLow, + MaxVolumeCount: tc.maxVolumeCount, + } + for i := 0; i < tc.currentVolumes; i++ { + diskLocation.volumes[needle.VolumeId(i+1)] = &Volume{} + } + + store := &Store{ + Locations: []*DiskLocation{diskLocation}, + } + + // act + result := store.hasFreeDiskLocation(diskLocation) + + // assert + if result != tc.expected { + t.Errorf("Expected hasFreeDiskLocation() = %v; want %v for volumes:%d/%d, lowSpace:%v", + result, tc.expected, len(diskLocation.volumes), diskLocation.MaxVolumeCount, diskLocation.isDiskSpaceLow) + } + }) + } +} |
