1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2025-06-29 16:22:46 +02:00
seaweedfs/weed/mount/weedfs_quota.go
2025-05-22 09:54:31 -07:00

54 lines
1.2 KiB
Go

package mount
import (
"context"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/util/log"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"time"
)
func (wfs *WFS) loopCheckQuota() {
for {
time.Sleep(61 * time.Second)
if wfs.option.Quota <= 0 {
continue
}
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 {
log.V(3).Infof("reading quota usage %v: %v", request, err)
return err
}
log.V(-1).Infof("read quota usage: %+v", resp)
isOverQuota := int64(resp.UsedSize) > wfs.option.Quota
if isOverQuota && !wfs.IsOverQuota {
log.Warningf("Quota Exceeded! quota:%d used:%d", wfs.option.Quota, resp.UsedSize)
} else if !isOverQuota && wfs.IsOverQuota {
log.Warningf("Within quota limit! quota:%d used:%d", wfs.option.Quota, resp.UsedSize)
}
wfs.IsOverQuota = isOverQuota
return nil
})
if err != nil {
log.Warningf("read quota usage: %v", err)
}
}
}