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.

44 lines
1.4 KiB

  1. package storage
  2. import (
  3. "fmt"
  4. "strconv"
  5. "github.com/chrislusf/weed-fs/go/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) 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()
  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. }