mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-01 18:00:46 +01:00
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.
This commit is contained in:
1 parent
152f1a2096
commit
fee3fcb55a
21 files changed
+429
-43
No files matched your search
@@ -61,6 +61,10 @@ type Option struct {
|
||||
DisableXAttr bool
|
||||
IsMacOs bool
|
||||
|
||||
// LogicalDiskUsage reports data sizes rather than the space they occupy,
|
||||
// for both df and the quota. See WFS.diskSizes.
|
||||
LogicalDiskUsage bool
|
||||
|
||||
MountUid uint32
|
||||
MountGid uint32
|
||||
MountMode os.FileMode
|
||||
|
||||
@@ -64,8 +64,8 @@ func (wfs *WFS) IsOverQuotaWithUncommitted() bool {
|
||||
}
|
||||
// Check if uncommitted writes would exceed quota
|
||||
uncommitted := atomic.LoadInt64(&uncommittedBytes)
|
||||
usedSize := int64(wfs.stats.UsedSize)
|
||||
return (usedSize + uncommitted) > wfs.option.Quota
|
||||
_, usedSize := wfs.diskSizes()
|
||||
return (int64(usedSize) + uncommitted) > wfs.option.Quota
|
||||
}
|
||||
|
||||
func (wfs *WFS) loopCheckQuota() {
|
||||
@@ -98,9 +98,9 @@ func (wfs *WFS) getQuotaCheckInterval() time.Duration {
|
||||
return defaultQuotaCheckInterval
|
||||
}
|
||||
|
||||
usedSize := int64(wfs.stats.UsedSize)
|
||||
_, usedSize := wfs.diskSizes()
|
||||
uncommitted := atomic.LoadInt64(&uncommittedBytes)
|
||||
totalUsed := usedSize + uncommitted
|
||||
totalUsed := int64(usedSize) + uncommitted
|
||||
|
||||
// If we're at 90% or more of quota, check more frequently
|
||||
if float64(totalUsed) >= float64(wfs.option.Quota)*quotaWarningThreshold {
|
||||
@@ -129,15 +129,18 @@ func (wfs *WFS) checkQuotaOnce() {
|
||||
// Update the stats cache with latest filer data
|
||||
wfs.stats.UsedSize = resp.UsedSize
|
||||
wfs.stats.TotalSize = resp.TotalSize
|
||||
wfs.stats.LogicalUsedSize = resp.LogicalUsedSize
|
||||
wfs.stats.LogicalTotalSize = resp.LogicalTotalSize
|
||||
|
||||
// Reset uncommitted counter since we now have fresh data from filer
|
||||
wfs.ResetUncommittedBytes()
|
||||
|
||||
isOverQuota := int64(resp.UsedSize) > wfs.option.Quota
|
||||
_, usedSize := wfs.diskSizes()
|
||||
isOverQuota := int64(usedSize) > wfs.option.Quota
|
||||
if isOverQuota && !wfs.IsOverQuota {
|
||||
glog.Warningf("Quota Exceeded! quota:%d used:%d", wfs.option.Quota, resp.UsedSize)
|
||||
glog.Warningf("Quota Exceeded! quota:%d used:%d", wfs.option.Quota, usedSize)
|
||||
} else if !isOverQuota && wfs.IsOverQuota {
|
||||
glog.Warningf("Within quota limit! quota:%d used:%d", wfs.option.Quota, resp.UsedSize)
|
||||
glog.Warningf("Within quota limit! quota:%d used:%d", wfs.option.Quota, usedSize)
|
||||
}
|
||||
wfs.IsOverQuota = isOverQuota
|
||||
|
||||
|
||||
@@ -18,6 +18,19 @@ type statsCache struct {
|
||||
lastChecked int64 // unix time in seconds
|
||||
}
|
||||
|
||||
// diskSizes reports the sizes df and the quota work from. By default that is
|
||||
// the space the cluster gives up to the data, counting every replica and every
|
||||
// EC shard. Under -df.logical it is the data itself, with the free space
|
||||
// converted to how much more of it the mount's replication setting allows.
|
||||
func (wfs *WFS) diskSizes() (totalSize, usedSize uint64) {
|
||||
// a filer older than the logical sizes sends zeros, so keep reporting the
|
||||
// raw ones rather than an empty filesystem
|
||||
if wfs.option.LogicalDiskUsage && wfs.stats.LogicalTotalSize > 0 {
|
||||
return wfs.stats.LogicalTotalSize, wfs.stats.LogicalUsedSize
|
||||
}
|
||||
return wfs.stats.TotalSize, wfs.stats.UsedSize
|
||||
}
|
||||
|
||||
func (wfs *WFS) StatFs(cancel <-chan struct{}, in *fuse.InHeader, out *fuse.StatfsOut) (code fuse.Status) {
|
||||
|
||||
// glog.V(4).Infof("reading fs stats")
|
||||
@@ -43,6 +56,8 @@ func (wfs *WFS) StatFs(cancel <-chan struct{}, in *fuse.InHeader, out *fuse.Stat
|
||||
|
||||
wfs.stats.TotalSize = resp.TotalSize
|
||||
wfs.stats.UsedSize = resp.UsedSize
|
||||
wfs.stats.LogicalTotalSize = resp.LogicalTotalSize
|
||||
wfs.stats.LogicalUsedSize = resp.LogicalUsedSize
|
||||
wfs.stats.FileCount = resp.FileCount
|
||||
wfs.stats.lastChecked = time.Now().Unix()
|
||||
|
||||
@@ -54,8 +69,7 @@ func (wfs *WFS) StatFs(cancel <-chan struct{}, in *fuse.InHeader, out *fuse.Stat
|
||||
}
|
||||
}
|
||||
|
||||
totalDiskSize := wfs.stats.TotalSize
|
||||
usedDiskSize := wfs.stats.UsedSize
|
||||
totalDiskSize, usedDiskSize := wfs.diskSizes()
|
||||
actualFileCount := wfs.stats.FileCount
|
||||
|
||||
if wfs.option.Quota > 0 && totalDiskSize > uint64(wfs.option.Quota) {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user