2014-05-20 02:18:39 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
2014-10-26 18:34:55 +00:00
|
|
|
|
2016-06-03 01:09:14 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2014-05-20 02:18:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Store) CheckCompactVolume(volumeIdString string, garbageThresholdString string) (error, bool) {
|
|
|
|
vid, err := NewVolumeId(volumeIdString)
|
|
|
|
if err != nil {
|
2015-03-10 07:20:31 +00:00
|
|
|
return fmt.Errorf("Volume Id %s is not a valid unsigned integer", volumeIdString), false
|
2014-05-20 02:18:39 +00:00
|
|
|
}
|
|
|
|
garbageThreshold, e := strconv.ParseFloat(garbageThresholdString, 32)
|
|
|
|
if e != nil {
|
2015-03-10 07:20:31 +00:00
|
|
|
return fmt.Errorf("garbageThreshold %s is not a valid float number", garbageThresholdString), false
|
2014-05-20 02:18:39 +00:00
|
|
|
}
|
|
|
|
if v := s.findVolume(vid); v != nil {
|
|
|
|
glog.V(3).Infoln(vid, "garbage level is", v.garbageLevel())
|
|
|
|
return nil, garbageThreshold < v.garbageLevel()
|
|
|
|
}
|
2015-03-10 07:20:31 +00:00
|
|
|
return fmt.Errorf("volume id %d is not found during check compact", vid), false
|
2014-05-20 02:18:39 +00:00
|
|
|
}
|
2017-08-30 06:59:53 +00:00
|
|
|
func (s *Store) CompactVolume(volumeIdString string, preallocate int64) error {
|
2014-05-20 02:18:39 +00:00
|
|
|
vid, err := NewVolumeId(volumeIdString)
|
|
|
|
if err != nil {
|
2015-03-10 07:20:31 +00:00
|
|
|
return fmt.Errorf("Volume Id %s is not a valid unsigned integer", volumeIdString)
|
2014-05-20 02:18:39 +00:00
|
|
|
}
|
|
|
|
if v := s.findVolume(vid); v != nil {
|
2017-08-30 06:59:53 +00:00
|
|
|
return v.Compact(preallocate)
|
2014-05-20 02:18:39 +00:00
|
|
|
}
|
2015-03-10 07:20:31 +00:00
|
|
|
return fmt.Errorf("volume id %d is not found during compact", vid)
|
2014-05-20 02:18:39 +00:00
|
|
|
}
|
|
|
|
func (s *Store) CommitCompactVolume(volumeIdString string) error {
|
|
|
|
vid, err := NewVolumeId(volumeIdString)
|
|
|
|
if err != nil {
|
2015-03-10 07:20:31 +00:00
|
|
|
return fmt.Errorf("Volume Id %s is not a valid unsigned integer", volumeIdString)
|
2014-05-20 02:18:39 +00:00
|
|
|
}
|
|
|
|
if v := s.findVolume(vid); v != nil {
|
|
|
|
return v.commitCompact()
|
|
|
|
}
|
2015-03-10 07:20:31 +00:00
|
|
|
return fmt.Errorf("volume id %d is not found during commit compact", vid)
|
2014-05-20 02:18:39 +00:00
|
|
|
}
|
2017-08-30 06:59:53 +00:00
|
|
|
func (s *Store) CommitCleanupVolume(volumeIdString string) error {
|
|
|
|
vid, err := NewVolumeId(volumeIdString)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Volume Id %s is not a valid unsigned integer", volumeIdString)
|
|
|
|
}
|
|
|
|
if v := s.findVolume(vid); v != nil {
|
|
|
|
return v.cleanupCompact()
|
|
|
|
}
|
|
|
|
return fmt.Errorf("volume id %d is not found during cleaning up", vid)
|
|
|
|
}
|