Files
seaweedfs/weed/mount/weedfs_stats_test.go
Chris LuandGitHub fee3fcb55a mount: report data sizes to df with -df.logical (#10459)
df on a mount shows the space the cluster gives up to the data: every
replica of a regular volume, every shard of an ec one. That is the honest
answer for capacity planning, but it is not the question a user asks when
they want to know how much of their data is stored.

Add -df.logical. The master reports the logical sizes alongside the raw
ones: one replica per regular volume, the data shards of each ec volume
counted once. Free space is divided by the copies the requested
replication makes, so used plus available stays the amount of data the
mount can still write, and it comes off the cluster-wide usage rather
than one collection's, since capacity is cluster-wide too.

Statistics through a filer resolves an unset replication to the filer's
default rather than the master's, matching where the writes it is sizing
for actually land.

The flag governs the quota check too, so a mount has one notion of how
much it is using. A filer that predates the new fields sends zeros, and
the mount keeps reporting the raw sizes.
2026-07-27 14:28:29 -07:00

32 lines
856 B
Go

package mount
import "testing"
func TestDiskSizes(t *testing.T) {
wfs := &WFS{option: &Option{}}
wfs.stats.TotalSize = 3000
wfs.stats.UsedSize = 2000
wfs.stats.LogicalTotalSize = 1500
wfs.stats.LogicalUsedSize = 1000
total, used := wfs.diskSizes()
if total != 3000 || used != 2000 {
t.Errorf("raw sizes: got %d/%d, want 3000/2000", total, used)
}
wfs.option.LogicalDiskUsage = true
total, used = wfs.diskSizes()
if total != 1500 || used != 1000 {
t.Errorf("logical sizes: got %d/%d, want 1500/1000", total, used)
}
// a filer that does not report logical sizes must not read as an empty
// filesystem
wfs.stats.LogicalTotalSize = 0
wfs.stats.LogicalUsedSize = 0
total, used = wfs.diskSizes()
if total != 3000 || used != 2000 {
t.Errorf("sizes from a filer without logical support: got %d/%d, want 3000/2000", total, used)
}
}