mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-23 15:43:34 +08:00
Refactor out volume vacuum.
This commit is contained in:
@@ -281,34 +281,6 @@ func (v *Volume) read(n *Needle) (int, error) {
|
|||||||
return -1, errors.New("Not Found")
|
return -1, errors.New("Not Found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Volume) garbageLevel() float64 {
|
|
||||||
return float64(v.nm.DeletedSize()) / float64(v.ContentSize())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Volume) Compact() error {
|
|
||||||
v.accessLock.Lock()
|
|
||||||
defer v.accessLock.Unlock()
|
|
||||||
|
|
||||||
filePath := v.FileName()
|
|
||||||
glog.V(3).Infof("creating copies for volume %d ...", v.Id)
|
|
||||||
return v.copyDataAndGenerateIndexFile(filePath+".cpd", filePath+".cpx")
|
|
||||||
}
|
|
||||||
func (v *Volume) commitCompact() error {
|
|
||||||
v.accessLock.Lock()
|
|
||||||
defer v.accessLock.Unlock()
|
|
||||||
_ = v.dataFile.Close()
|
|
||||||
var e error
|
|
||||||
if e = os.Rename(v.FileName()+".cpd", v.FileName()+".dat"); e != nil {
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
if e = os.Rename(v.FileName()+".cpx", v.FileName()+".idx"); e != nil {
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
if e = v.load(true, false); e != nil {
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (v *Volume) freeze() error {
|
func (v *Volume) freeze() error {
|
||||||
if v.readOnly {
|
if v.readOnly {
|
||||||
return nil
|
return nil
|
||||||
|
35
go/storage/volume_vacuum.go
Normal file
35
go/storage/volume_vacuum.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.google.com/p/weed-fs/go/glog"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (v *Volume) garbageLevel() float64 {
|
||||||
|
return float64(v.nm.DeletedSize()) / float64(v.ContentSize())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Volume) Compact() error {
|
||||||
|
v.accessLock.Lock()
|
||||||
|
defer v.accessLock.Unlock()
|
||||||
|
|
||||||
|
filePath := v.FileName()
|
||||||
|
glog.V(3).Infof("creating copies for volume %d ...", v.Id)
|
||||||
|
return v.copyDataAndGenerateIndexFile(filePath+".cpd", filePath+".cpx")
|
||||||
|
}
|
||||||
|
func (v *Volume) commitCompact() error {
|
||||||
|
v.accessLock.Lock()
|
||||||
|
defer v.accessLock.Unlock()
|
||||||
|
_ = v.dataFile.Close()
|
||||||
|
var e error
|
||||||
|
if e = os.Rename(v.FileName()+".cpd", v.FileName()+".dat"); e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
if e = os.Rename(v.FileName()+".cpx", v.FileName()+".idx"); e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
if e = v.load(true, false); e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Reference in New Issue
Block a user