mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-19 12:34:29 +02: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
@@ -23,7 +23,7 @@ func (fs *FilerServer) Statistics(ctx context.Context, req *filer_pb.StatisticsR
|
||||
|
||||
err = fs.filer.MasterClient.WithClient(false, func(masterClient master_pb.SeaweedClient) error {
|
||||
grpcResponse, grpcErr := masterClient.Statistics(context.Background(), &master_pb.StatisticsRequest{
|
||||
Replication: req.Replication,
|
||||
Replication: fs.statisticsReplication(req.Replication),
|
||||
Collection: req.Collection,
|
||||
Ttl: req.Ttl,
|
||||
DiskType: req.DiskType,
|
||||
@@ -41,12 +41,25 @@ func (fs *FilerServer) Statistics(ctx context.Context, req *filer_pb.StatisticsR
|
||||
}
|
||||
|
||||
return &filer_pb.StatisticsResponse{
|
||||
TotalSize: output.TotalSize,
|
||||
UsedSize: output.UsedSize,
|
||||
FileCount: output.FileCount,
|
||||
TotalSize: output.TotalSize,
|
||||
UsedSize: output.UsedSize,
|
||||
FileCount: output.FileCount,
|
||||
LogicalTotalSize: output.LogicalTotalSize,
|
||||
LogicalUsedSize: output.LogicalUsedSize,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// statisticsReplication names the replication the caller's writes will use, so
|
||||
// the master sizes free space by the right number of copies. Writes through
|
||||
// this filer follow its default, not the master's, so fill that in when the
|
||||
// request leaves the choice open.
|
||||
func (fs *FilerServer) statisticsReplication(requested string) string {
|
||||
if requested != "" {
|
||||
return requested
|
||||
}
|
||||
return fs.option.DefaultReplication
|
||||
}
|
||||
|
||||
// isKnownPingTarget reports whether target is a peer the filer has learned
|
||||
// about from its master subscription (other filers, volume servers) or from
|
||||
// its own master list. Restricting Ping prevents the RPC from being used as
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package weed_server
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestStatisticsReplication(t *testing.T) {
|
||||
fs := &FilerServer{option: &FilerOption{DefaultReplication: "001"}}
|
||||
|
||||
if got := fs.statisticsReplication("020"); got != "020" {
|
||||
t.Errorf("requested replication: got %q, want %q", got, "020")
|
||||
}
|
||||
if got := fs.statisticsReplication(""); got != "001" {
|
||||
t.Errorf("empty replication: got %q, want the filer default %q", got, "001")
|
||||
}
|
||||
|
||||
// a filer without its own default leaves the choice to the master
|
||||
fs.option.DefaultReplication = ""
|
||||
if got := fs.statisticsReplication(""); got != "" {
|
||||
t.Errorf("empty replication without a filer default: got %q, want %q", got, "")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package weed_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
||||
"github.com/seaweedfs/seaweedfs/weed/topology"
|
||||
)
|
||||
|
||||
// ecShardSizes returns count shard sizes of size bytes each.
|
||||
func ecShardSizes(count int, size int64) []int64 {
|
||||
sizes := make([]int64, count)
|
||||
for i := range sizes {
|
||||
sizes[i] = size
|
||||
}
|
||||
return sizes
|
||||
}
|
||||
|
||||
// newStatisticsMaster returns a leader master over four nodes of 10 volume
|
||||
// slots at 1MB each. Collection c1 holds a 1000 byte volume replicated to two
|
||||
// nodes and an EC volume of 14 shards at 100 bytes; collection c2 holds a
|
||||
// single 5000 byte volume.
|
||||
func newStatisticsMaster(t *testing.T) *MasterServer {
|
||||
t.Helper()
|
||||
|
||||
ms := newLeaderMaster()
|
||||
ms.option.VolumeSizeLimitMB = 1
|
||||
|
||||
rack := ms.Topo.GetOrCreateDataCenter("dc1").GetOrCreateRack("rack1")
|
||||
maxVolumeCounts := map[string]uint32{"": 10}
|
||||
newNode := func(host string) *topology.DataNode {
|
||||
dn := rack.GetOrCreateDataNode(host, 34534, 0, host, "", maxVolumeCounts)
|
||||
// VolumeLocationList.Stats only counts nodes connected for over a minute
|
||||
dn.LastSeen = time.Now().Unix() - 61
|
||||
return dn
|
||||
}
|
||||
|
||||
replicatedVolume := &master_pb.VolumeInformationMessage{
|
||||
Id: 1, Size: 1000, Collection: "c1", FileCount: 10,
|
||||
ReplicaPlacement: 1, // 001: one copy in the same rack
|
||||
Version: uint32(needle.GetCurrentVersion()),
|
||||
}
|
||||
for _, host := range []string{"127.0.0.1", "127.0.0.2"} {
|
||||
ms.Topo.SyncDataNodeRegistration([]*master_pb.VolumeInformationMessage{replicatedVolume}, newNode(host))
|
||||
}
|
||||
|
||||
otherCollectionNode := newNode("127.0.0.3")
|
||||
ms.Topo.SyncDataNodeRegistration([]*master_pb.VolumeInformationMessage{
|
||||
{Id: 3, Size: 5000, Collection: "c2", FileCount: 50, Version: uint32(needle.GetCurrentVersion())},
|
||||
}, otherCollectionNode)
|
||||
|
||||
// EC shards are not replicated here, so the volume sits on one node
|
||||
ms.Topo.SyncDataNodeEcShards([]*master_pb.VolumeEcShardInformationMessage{
|
||||
{Id: 2, Collection: "c1", EcIndexBits: 1<<14 - 1, ShardSizes: ecShardSizes(14, 100), FileCount: 7},
|
||||
}, newNode("127.0.0.4"))
|
||||
|
||||
return ms
|
||||
}
|
||||
|
||||
func TestStatisticsLogicalSizes(t *testing.T) {
|
||||
ms := newStatisticsMaster(t)
|
||||
|
||||
resp, err := ms.Statistics(context.Background(), &master_pb.StatisticsRequest{
|
||||
Collection: "c1",
|
||||
Replication: "001",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Statistics: %v", err)
|
||||
}
|
||||
|
||||
// 1000 bytes on each of two replicas, plus every shard of the EC volume
|
||||
if got, want := resp.UsedSize, uint64(2*1000+14*100); got != want {
|
||||
t.Errorf("used size: got %d, want %d", got, want)
|
||||
}
|
||||
// one replica, and the 10 data shards of the EC volume
|
||||
if got, want := resp.LogicalUsedSize, uint64(1000+10*100); got != want {
|
||||
t.Errorf("logical used size: got %d, want %d", got, want)
|
||||
}
|
||||
|
||||
// four nodes of 10 slots at 1MB each
|
||||
totalSize := uint64(40 * 1024 * 1024)
|
||||
if resp.TotalSize != totalSize {
|
||||
t.Fatalf("total size: got %d, want %d", resp.TotalSize, totalSize)
|
||||
}
|
||||
// what is left over is what c2 has not taken either, and 001 writes two
|
||||
// copies of it
|
||||
clusterUsedSize := resp.UsedSize + 5000
|
||||
want := resp.LogicalUsedSize + (totalSize-clusterUsedSize)/2
|
||||
if resp.LogicalTotalSize != want {
|
||||
t.Errorf("logical total size: got %d, want %d", resp.LogicalTotalSize, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatisticsReplicaCopyCount(t *testing.T) {
|
||||
ms := newStatisticsMaster(t)
|
||||
ms.option.DefaultReplicaPlacement = "010"
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
replication string
|
||||
copies uint64
|
||||
}{
|
||||
{"requested", "002", 3},
|
||||
{"empty falls back to the master default", "", 2},
|
||||
{"unparsable falls back to the master default", "not-a-replication", 2},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
resp, err := ms.Statistics(context.Background(), &master_pb.StatisticsRequest{
|
||||
Replication: tc.replication,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Statistics: %v", err)
|
||||
}
|
||||
want := resp.LogicalUsedSize + (resp.TotalSize-resp.UsedSize)/tc.copies
|
||||
if resp.LogicalTotalSize != want {
|
||||
t.Errorf("logical total size: got %d, want %d for %d copies",
|
||||
resp.LogicalTotalSize, want, tc.copies)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -205,19 +205,49 @@ func (ms *MasterServer) Statistics(ctx context.Context, req *master_pb.Statistic
|
||||
}
|
||||
|
||||
// an empty collection means all collections, and a named collection covers
|
||||
// all its layouts and EC volumes, so used size matches the topology-wide
|
||||
// total size below
|
||||
// all its layouts and EC volumes
|
||||
stats := ms.Topo.CollectionVolumeStats(req.Collection)
|
||||
totalSize := ms.Topo.GetDiskUsages().GetMaxVolumeCount() * int64(ms.option.VolumeSizeLimitMB) * 1024 * 1024
|
||||
totalSize := uint64(ms.Topo.GetDiskUsages().GetMaxVolumeCount() * int64(ms.option.VolumeSizeLimitMB) * 1024 * 1024)
|
||||
// capacity is cluster-wide, so what is left over is what every collection
|
||||
// has not taken, not just the one asked about
|
||||
clusterUsedSize := stats.UsedSize
|
||||
if req.Collection != "" {
|
||||
clusterUsedSize = ms.Topo.CollectionVolumeStats("").UsedSize
|
||||
}
|
||||
// and the free space holds that many copies fewer of whatever the caller writes
|
||||
var freeSize uint64
|
||||
if totalSize > clusterUsedSize {
|
||||
freeSize = (totalSize - clusterUsedSize) / uint64(ms.replicaCopyCount(req.Replication))
|
||||
}
|
||||
resp := &master_pb.StatisticsResponse{
|
||||
TotalSize: uint64(totalSize),
|
||||
UsedSize: stats.UsedSize,
|
||||
FileCount: stats.FileCount,
|
||||
TotalSize: totalSize,
|
||||
UsedSize: stats.UsedSize,
|
||||
FileCount: stats.FileCount,
|
||||
LogicalTotalSize: stats.LogicalUsedSize + freeSize,
|
||||
LogicalUsedSize: stats.LogicalUsedSize,
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// replicaCopyCount returns how many copies the given replication makes, falling
|
||||
// back to the master default and then to a single copy. Unparsable input is
|
||||
// reported rather than failing the call: statistics are informational.
|
||||
func (ms *MasterServer) replicaCopyCount(replication string) int {
|
||||
for _, s := range []string{replication, ms.option.DefaultReplicaPlacement} {
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
rp, err := super_block.NewReplicaPlacementFromString(s)
|
||||
if err != nil {
|
||||
glog.V(1).Infof("statistics replication %q: %v", s, err)
|
||||
continue
|
||||
}
|
||||
return rp.GetCopyCount()
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
func (ms *MasterServer) VolumeList(ctx context.Context, req *master_pb.VolumeListRequest) (*master_pb.VolumeListResponse, error) {
|
||||
|
||||
if !ms.Topo.IsLeader() {
|
||||
|
||||
Reference in new issue
Block a user