store_vacuum.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package storage
  2. import (
  3. "fmt"
  4. "strconv"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. )
  7. func (s *Store) CheckCompactVolume(volumeIdString string, garbageThresholdString string) (error, bool) {
  8. vid, err := NewVolumeId(volumeIdString)
  9. if err != nil {
  10. return fmt.Errorf("Volume Id %s is not a valid unsigned integer", volumeIdString), false
  11. }
  12. garbageThreshold, e := strconv.ParseFloat(garbageThresholdString, 32)
  13. if e != nil {
  14. return fmt.Errorf("garbageThreshold %s is not a valid float number", garbageThresholdString), false
  15. }
  16. if v := s.findVolume(vid); v != nil {
  17. glog.V(3).Infoln(vid, "garbage level is", v.garbageLevel())
  18. return nil, garbageThreshold < v.garbageLevel()
  19. }
  20. return fmt.Errorf("volume id %d is not found during check compact", vid), false
  21. }
  22. func (s *Store) CompactVolume(volumeIdString string, preallocate int64) error {
  23. vid, err := NewVolumeId(volumeIdString)
  24. if err != nil {
  25. return fmt.Errorf("Volume Id %s is not a valid unsigned integer", volumeIdString)
  26. }
  27. if v := s.findVolume(vid); v != nil {
  28. return v.Compact(preallocate)
  29. }
  30. return fmt.Errorf("volume id %d is not found during compact", vid)
  31. }
  32. func (s *Store) CommitCompactVolume(volumeIdString string) error {
  33. vid, err := NewVolumeId(volumeIdString)
  34. if err != nil {
  35. return fmt.Errorf("Volume Id %s is not a valid unsigned integer", volumeIdString)
  36. }
  37. if v := s.findVolume(vid); v != nil {
  38. return v.commitCompact()
  39. }
  40. return fmt.Errorf("volume id %d is not found during commit compact", vid)
  41. }
  42. func (s *Store) CommitCleanupVolume(volumeIdString string) error {
  43. vid, err := NewVolumeId(volumeIdString)
  44. if err != nil {
  45. return fmt.Errorf("Volume Id %s is not a valid unsigned integer", volumeIdString)
  46. }
  47. if v := s.findVolume(vid); v != nil {
  48. return v.cleanupCompact()
  49. }
  50. return fmt.Errorf("volume id %d is not found during cleaning up", vid)
  51. }