mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-19 06:37:56 +08:00
mount: quota for one mounted collection
related to https://github.com/seaweedfs/seaweedfs-csi-driver/issues/48
This commit is contained in:
@@ -11,6 +11,7 @@ type MountOptions struct {
|
|||||||
dir *string
|
dir *string
|
||||||
dirAutoCreate *bool
|
dirAutoCreate *bool
|
||||||
collection *string
|
collection *string
|
||||||
|
collectionQuota *int
|
||||||
replication *string
|
replication *string
|
||||||
diskType *string
|
diskType *string
|
||||||
ttlSec *int
|
ttlSec *int
|
||||||
@@ -44,6 +45,7 @@ func init() {
|
|||||||
mountOptions.dir = cmdMount.Flag.String("dir", ".", "mount weed filer to this directory")
|
mountOptions.dir = cmdMount.Flag.String("dir", ".", "mount weed filer to this directory")
|
||||||
mountOptions.dirAutoCreate = cmdMount.Flag.Bool("dirAutoCreate", false, "auto create the directory to mount to")
|
mountOptions.dirAutoCreate = cmdMount.Flag.Bool("dirAutoCreate", false, "auto create the directory to mount to")
|
||||||
mountOptions.collection = cmdMount.Flag.String("collection", "", "collection to create the files")
|
mountOptions.collection = cmdMount.Flag.String("collection", "", "collection to create the files")
|
||||||
|
mountOptions.collectionQuota = cmdMount.Flag.Int("collectionQuotaMB", 0, "quota for the collection")
|
||||||
mountOptions.replication = cmdMount.Flag.String("replication", "", "replication(e.g. 000, 001) to create to files. If empty, let filer decide.")
|
mountOptions.replication = cmdMount.Flag.String("replication", "", "replication(e.g. 000, 001) to create to files. If empty, let filer decide.")
|
||||||
mountOptions.diskType = cmdMount.Flag.String("disk", "", "[hdd|ssd|<tag>] hard drive or solid state drive or any tag")
|
mountOptions.diskType = cmdMount.Flag.String("disk", "", "[hdd|ssd|<tag>] hard drive or solid state drive or any tag")
|
||||||
mountOptions.ttlSec = cmdMount.Flag.Int("ttl", 0, "file ttl in seconds")
|
mountOptions.ttlSec = cmdMount.Flag.Int("ttl", 0, "file ttl in seconds")
|
||||||
|
@@ -209,6 +209,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
|
|||||||
CacheDir: *option.cacheDir,
|
CacheDir: *option.cacheDir,
|
||||||
CacheSizeMB: *option.cacheSizeMB,
|
CacheSizeMB: *option.cacheSizeMB,
|
||||||
DataCenter: *option.dataCenter,
|
DataCenter: *option.dataCenter,
|
||||||
|
Quota: int64(*option.collectionQuota) * 1024 * 1024,
|
||||||
MountUid: uid,
|
MountUid: uid,
|
||||||
MountGid: gid,
|
MountGid: gid,
|
||||||
MountMode: mountMode,
|
MountMode: mountMode,
|
||||||
|
@@ -37,6 +37,7 @@ type Option struct {
|
|||||||
CacheSizeMB int64
|
CacheSizeMB int64
|
||||||
DataCenter string
|
DataCenter string
|
||||||
Umask os.FileMode
|
Umask os.FileMode
|
||||||
|
Quota int64
|
||||||
|
|
||||||
MountUid uint32
|
MountUid uint32
|
||||||
MountGid uint32
|
MountGid uint32
|
||||||
@@ -107,6 +108,7 @@ func NewSeaweedFileSystem(option *Option) *WFS {
|
|||||||
func (wfs *WFS) StartBackgroundTasks() {
|
func (wfs *WFS) StartBackgroundTasks() {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
go meta_cache.SubscribeMetaEvents(wfs.metaCache, wfs.signature, wfs, wfs.option.FilerMountRootPath, startTime.UnixNano())
|
go meta_cache.SubscribeMetaEvents(wfs.metaCache, wfs.signature, wfs, wfs.option.FilerMountRootPath, startTime.UnixNano())
|
||||||
|
go wfs.loopCheckQuota()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wfs *WFS) String() string {
|
func (wfs *WFS) String() string {
|
||||||
|
53
weed/mount/weedfs_quota.go
Normal file
53
weed/mount/weedfs_quota.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package mount
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (wfs *WFS) loopCheckQuota() {
|
||||||
|
|
||||||
|
if wfs.option.Quota <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
|
||||||
|
err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
|
||||||
|
request := &filer_pb.StatisticsRequest{
|
||||||
|
Collection: wfs.option.Collection,
|
||||||
|
Replication: wfs.option.Replication,
|
||||||
|
Ttl: fmt.Sprintf("%ds", wfs.option.TtlSec),
|
||||||
|
DiskType: string(wfs.option.DiskType),
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Statistics(context.Background(), request)
|
||||||
|
if err != nil {
|
||||||
|
glog.V(0).Infof("reading quota usage %v: %v", request, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
glog.V(4).Infof("read quota usage: %+v", resp)
|
||||||
|
|
||||||
|
isOverQuota := int64(resp.UsedSize) > wfs.option.Quota
|
||||||
|
if isOverQuota && !wfs.IsOverQuota {
|
||||||
|
glog.Warningf("Quota Exceeded! quota:%d used:%d", wfs.option.Quota, resp.UsedSize)
|
||||||
|
} else if !isOverQuota && wfs.IsOverQuota {
|
||||||
|
glog.Warningf("Within quota limit! quota:%d used:%d", wfs.option.Quota, resp.UsedSize)
|
||||||
|
}
|
||||||
|
wfs.IsOverQuota = isOverQuota
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
glog.Warningf("read quota usage: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(61 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user