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.

46 lines
1.6 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("volume %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, int64, error) {
  26. if s.isStopping {
  27. return false, 0, fmt.Errorf("volume id %d skips compact because volume is stopping", vid)
  28. }
  29. if v := s.findVolume(vid); v != nil {
  30. isReadOnly := v.IsReadOnly()
  31. err := v.CommitCompact()
  32. volumeSize, _, _ := v.DataBackend.GetStat()
  33. return isReadOnly, volumeSize, err
  34. }
  35. return false, 0, fmt.Errorf("volume id %d is not found during commit compact", vid)
  36. }
  37. func (s *Store) CommitCleanupVolume(vid needle.VolumeId) error {
  38. if v := s.findVolume(vid); v != nil {
  39. return v.cleanupCompact()
  40. }
  41. return fmt.Errorf("volume id %d is not found during cleaning up", vid)
  42. }