weedfs_quota.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package mount
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/seaweedfs/seaweedfs/weed/glog"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  7. "time"
  8. )
  9. func (wfs *WFS) loopCheckQuota() {
  10. for {
  11. time.Sleep(61 * time.Second)
  12. if wfs.option.Quota <= 0 {
  13. continue
  14. }
  15. err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  16. request := &filer_pb.StatisticsRequest{
  17. Collection: wfs.option.Collection,
  18. Replication: wfs.option.Replication,
  19. Ttl: fmt.Sprintf("%ds", wfs.option.TtlSec),
  20. DiskType: string(wfs.option.DiskType),
  21. }
  22. resp, err := client.Statistics(context.Background(), request)
  23. if err != nil {
  24. glog.V(0).Infof("reading quota usage %v: %v", request, err)
  25. return err
  26. }
  27. glog.V(4).Infof("read quota usage: %+v", resp)
  28. isOverQuota := int64(resp.UsedSize) > wfs.option.Quota
  29. if isOverQuota && !wfs.IsOverQuota {
  30. glog.Warningf("Quota Exceeded! quota:%d used:%d", wfs.option.Quota, resp.UsedSize)
  31. } else if !isOverQuota && wfs.IsOverQuota {
  32. glog.Warningf("Within quota limit! quota:%d used:%d", wfs.option.Quota, resp.UsedSize)
  33. }
  34. wfs.IsOverQuota = isOverQuota
  35. return nil
  36. })
  37. if err != nil {
  38. glog.Warningf("read quota usage: %v", err)
  39. }
  40. }
  41. }