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.

42 lines
1.5 KiB

6 years ago
6 years ago
6 years ago
  1. package storage
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/stats"
  5. "github.com/seaweedfs/seaweedfs/weed/glog"
  6. "github.com/seaweedfs/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 s.isStopping {
  27. return false, fmt.Errorf("volume id %d skips compact because volume is stopping", vid)
  28. }
  29. if v := s.findVolume(vid); v != nil {
  30. return v.IsReadOnly(), v.CommitCompact()
  31. }
  32. return false, fmt.Errorf("volume id %d is not found during commit compact", vid)
  33. }
  34. func (s *Store) CommitCleanupVolume(vid needle.VolumeId) error {
  35. if v := s.findVolume(vid); v != nil {
  36. return v.cleanupCompact()
  37. }
  38. return fmt.Errorf("volume id %d is not found during cleaning up", vid)
  39. }