mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-24 15:00:43 +02:00
The max volume count subtracted each volume's remaining room from the free disk space, except when the master had preallocation turned on, in which case it subtracted nothing. That is wrong for a disk that mixes preallocated and plain volumes, and on platforms where preallocation is not supported. Use the larger of the .dat file's size and its allocated blocks, in the Go and the Rust volume server, so a preallocated volume counts as full and a plain one keeps its remaining room reserved. Fixes #5778 Co-authored-by: Dan Foster <4570306+danfoster@users.noreply.github.com>
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package storage
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
)
|
|
|
|
// A volume that was not preallocated keeps its remaining room reserved when
|
|
// the master turns preallocation on, so it still takes a slot of the free space.
|
|
func TestMaybeAdjustVolumeMaxReservesPlainVolumesWhilePreallocating(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Room for 2.5 volumes: the plain volume claims one, leaving one more slot.
|
|
volumeSizeLimit := uint64(float64(stats.NewDiskStatus(dir).Free) / 2.5)
|
|
if volumeSizeLimit == 0 {
|
|
t.Skip("cannot determine free disk space")
|
|
}
|
|
|
|
loc := &DiskLocation{Directory: dir, IdxDirectory: dir}
|
|
loc.volumes = make(map[needle.VolumeId]*Volume)
|
|
loc.SetVolume(1, &Volume{Id: 1, dir: dir, dirIdx: dir, DataBackend: &mockBackendStorageFile{}, nm: &mockNeedleMapper{}})
|
|
s := &Store{Locations: []*DiskLocation{loc}}
|
|
s.SetVolumeSizeLimit(volumeSizeLimit)
|
|
s.SetPreallocate(true)
|
|
|
|
s.MaybeAdjustVolumeMax()
|
|
|
|
if loc.MaxVolumeCount != 2 {
|
|
t.Errorf("MaxVolumeCount=%d; want 2", loc.MaxVolumeCount)
|
|
}
|
|
}
|