mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
use logical number of files and sizes for statistics and quota
This commit is contained in:
parent
f51e20028a
commit
6e49e75a5b
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,10 +24,10 @@ func (c *commandCollectionList) Help() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CollectionInfo struct {
|
type CollectionInfo struct {
|
||||||
FileCount uint64
|
FileCount float64
|
||||||
DeleteCount uint64
|
DeleteCount float64
|
||||||
DeletedByteCount uint64
|
DeletedByteCount float64
|
||||||
Size uint64
|
Size float64
|
||||||
VolumeCount int
|
VolumeCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ func (c *commandCollectionList) Do(args []string, commandEnv *CommandEnv, writer
|
||||||
if !found {
|
if !found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Fprintf(writer, "collection:\"%s\"\tvolumeCount:%d\tsize:%d\tfileCount:%d\tdeletedBytes:%d\tdeletion:%d\n", c, cif.VolumeCount, cif.Size, cif.FileCount, cif.DeletedByteCount, cif.DeleteCount)
|
fmt.Fprintf(writer, "collection:\"%s\"\tvolumeCount:%d\tsize:%.0f\tfileCount:%.0f\tdeletedBytes:%.0f\tdeletion:%.0f\n", c, cif.VolumeCount, cif.Size, cif.FileCount, cif.DeletedByteCount, cif.DeleteCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(writer, "Total %d collections.\n", len(collections))
|
fmt.Fprintf(writer, "Total %d collections.\n", len(collections))
|
||||||
|
@ -85,10 +86,12 @@ func addToCollection(collectionInfos map[string]*CollectionInfo, vif *master_pb.
|
||||||
cif = &CollectionInfo{}
|
cif = &CollectionInfo{}
|
||||||
collectionInfos[c] = cif
|
collectionInfos[c] = cif
|
||||||
}
|
}
|
||||||
cif.Size += vif.Size
|
replicaPlacement, _ := super_block.NewReplicaPlacementFromByte(byte(vif.ReplicaPlacement))
|
||||||
cif.DeleteCount += vif.DeleteCount
|
copyCount := float64(replicaPlacement.GetCopyCount())
|
||||||
cif.FileCount += vif.FileCount
|
cif.Size += float64(vif.Size) / copyCount
|
||||||
cif.DeletedByteCount += vif.DeletedByteCount
|
cif.DeleteCount += float64(vif.DeleteCount) / copyCount
|
||||||
|
cif.FileCount += float64(vif.FileCount) / copyCount
|
||||||
|
cif.DeletedByteCount += float64(vif.DeletedByteCount) / copyCount
|
||||||
cif.VolumeCount++
|
cif.VolumeCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,12 +58,12 @@ func (c *commandS3BucketList) Do(args []string, commandEnv *CommandEnv, writer i
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
collection := entry.Name
|
collection := entry.Name
|
||||||
var collectionSize, fileCount uint64
|
var collectionSize, fileCount float64
|
||||||
if collectionInfo, found := collectionInfos[collection]; found {
|
if collectionInfo, found := collectionInfos[collection]; found {
|
||||||
collectionSize = collectionInfo.Size
|
collectionSize = collectionInfo.Size
|
||||||
fileCount = collectionInfo.FileCount - collectionInfo.DeleteCount
|
fileCount = collectionInfo.FileCount - collectionInfo.DeleteCount
|
||||||
}
|
}
|
||||||
fmt.Fprintf(writer, " %s\tsize:%d\tfile:%d", entry.Name, collectionSize, fileCount)
|
fmt.Fprintf(writer, " %s\tsize:%.0f\tfile:%.0f", entry.Name, collectionSize, fileCount)
|
||||||
if entry.Quota > 0 {
|
if entry.Quota > 0 {
|
||||||
fmt.Fprintf(writer, "\tquota:%d\tusage:%.2f%%", entry.Quota, float64(collectionSize)*100/float64(entry.Quota))
|
fmt.Fprintf(writer, "\tquota:%d\tusage:%.2f%%", entry.Quota, float64(collectionSize)*100/float64(entry.Quota))
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ func (c *commandS3BucketQuotaEnforce) Do(args []string, commandEnv *CommandEnv,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
collection := entry.Name
|
collection := entry.Name
|
||||||
var collectionSize uint64
|
var collectionSize float64
|
||||||
if collectionInfo, found := collectionInfos[collection]; found {
|
if collectionInfo, found := collectionInfos[collection]; found {
|
||||||
collectionSize = collectionInfo.Size
|
collectionSize = collectionInfo.Size
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ func (c *commandS3BucketQuotaEnforce) Do(args []string, commandEnv *CommandEnv,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commandS3BucketQuotaEnforce) processEachBucket(fc *filer.FilerConf, filerBucketsPath string, entry *filer_pb.Entry, writer io.Writer, collectionSize uint64) (hasConfChanges bool) {
|
func (c *commandS3BucketQuotaEnforce) processEachBucket(fc *filer.FilerConf, filerBucketsPath string, entry *filer_pb.Entry, writer io.Writer, collectionSize float64) (hasConfChanges bool) {
|
||||||
|
|
||||||
locPrefix := filerBucketsPath + "/" + entry.Name + "/"
|
locPrefix := filerBucketsPath + "/" + entry.Name + "/"
|
||||||
locConf := fc.MatchStorageRule(locPrefix)
|
locConf := fc.MatchStorageRule(locPrefix)
|
||||||
|
@ -103,12 +103,12 @@ func (c *commandS3BucketQuotaEnforce) processEachBucket(fc *filer.FilerConf, fil
|
||||||
|
|
||||||
if entry.Quota > 0 {
|
if entry.Quota > 0 {
|
||||||
if locConf.ReadOnly {
|
if locConf.ReadOnly {
|
||||||
if collectionSize < uint64(entry.Quota) {
|
if collectionSize < float64(entry.Quota) {
|
||||||
locConf.ReadOnly = false
|
locConf.ReadOnly = false
|
||||||
hasConfChanges = true
|
hasConfChanges = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if collectionSize > uint64(entry.Quota) {
|
if collectionSize > float64(entry.Quota) {
|
||||||
locConf.ReadOnly = true
|
locConf.ReadOnly = true
|
||||||
hasConfChanges = true
|
hasConfChanges = true
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ func (c *commandS3BucketQuotaEnforce) processEachBucket(fc *filer.FilerConf, fil
|
||||||
|
|
||||||
if hasConfChanges {
|
if hasConfChanges {
|
||||||
fmt.Fprintf(writer, " %s\tsize:%d", entry.Name, collectionSize)
|
fmt.Fprintf(writer, " %s\tsize:%d", entry.Name, collectionSize)
|
||||||
fmt.Fprintf(writer, "\tquota:%d\tusage:%.2f%%", entry.Quota, float64(collectionSize)*100/float64(entry.Quota))
|
fmt.Fprintf(writer, "\tquota:%d\tusage:%.2f%%", entry.Quota, collectionSize*100/float64(entry.Quota))
|
||||||
fmt.Fprintln(writer)
|
fmt.Fprintln(writer)
|
||||||
if locConf.ReadOnly {
|
if locConf.ReadOnly {
|
||||||
fmt.Fprintf(writer, " changing bucket %s to read only!\n", entry.Name)
|
fmt.Fprintf(writer, " changing bucket %s to read only!\n", entry.Name)
|
||||||
|
|
Loading…
Reference in a new issue