You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

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