store_vacuum.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package storage
  2. import (
  3. "fmt"
  4. "github.com/chrislusf/seaweedfs/weed/stats"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  7. )
  8. func (s *Store) CheckCompactVolume(volumeId needle.VolumeId) (float64, error) {
  9. if v := s.findVolume(volumeId); v != nil {
  10. glog.V(3).Infof("volumd %d garbage level: %f", volumeId, v.garbageLevel())
  11. return v.garbageLevel(), nil
  12. }
  13. return 0, fmt.Errorf("volume id %d is not found during check compact", volumeId)
  14. }
  15. func (s *Store) CompactVolume(vid needle.VolumeId, preallocate int64, compactionBytePerSecond int64, progressFn ProgressFunc) error {
  16. if v := s.findVolume(vid); v != nil {
  17. s := stats.NewDiskStatus(v.dir)
  18. if int64(s.Free) < preallocate {
  19. return fmt.Errorf("free space: %d bytes, not enough for %d bytes", s.Free, preallocate)
  20. }
  21. return v.Compact2(preallocate, compactionBytePerSecond, progressFn)
  22. }
  23. return fmt.Errorf("volume id %d is not found during compact", vid)
  24. }
  25. func (s *Store) CommitCompactVolume(vid needle.VolumeId) (bool, error) {
  26. if v := s.findVolume(vid); v != nil {
  27. return v.IsReadOnly(), v.CommitCompact()
  28. }
  29. return false, fmt.Errorf("volume id %d is not found during commit compact", vid)
  30. }
  31. func (s *Store) CommitCleanupVolume(vid needle.VolumeId) error {
  32. if v := s.findVolume(vid); v != nil {
  33. return v.cleanupCompact()
  34. }
  35. return fmt.Errorf("volume id %d is not found during cleaning up", vid)
  36. }