mirror of
https://github.com/chrislusf/seaweedfs
synced 2024-07-07 09:37:49 +02:00
volume: add a note file to avoid incomplete volume files
fix https://github.com/chrislusf/seaweedfs/issues/1567
This commit is contained in:
parent
6da87720eb
commit
53c3aad875
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
@ -60,6 +61,8 @@ func (vs *VolumeServer) VolumeCopy(ctx context.Context, req *volume_server_pb.Vo
|
||||||
|
|
||||||
volumeFileName = storage.VolumeFileName(location.Directory, volFileInfoResp.Collection, int(req.VolumeId))
|
volumeFileName = storage.VolumeFileName(location.Directory, volFileInfoResp.Collection, int(req.VolumeId))
|
||||||
|
|
||||||
|
ioutil.WriteFile(volumeFileName+".note", []byte(fmt.Sprintf("copying from %s", req.SourceDataNode)), 0755)
|
||||||
|
|
||||||
// println("source:", volFileInfoResp.String())
|
// println("source:", volFileInfoResp.String())
|
||||||
if err := vs.doCopyFile(client, false, req.Collection, req.VolumeId, volFileInfoResp.CompactionRevision, volFileInfoResp.DatFileSize, volumeFileName, ".dat", false, true); err != nil {
|
if err := vs.doCopyFile(client, false, req.Collection, req.VolumeId, volFileInfoResp.CompactionRevision, volFileInfoResp.DatFileSize, volumeFileName, ".dat", false, true); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -73,6 +76,8 @@ func (vs *VolumeServer) VolumeCopy(ctx context.Context, req *volume_server_pb.Vo
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os.Remove(volumeFileName+".note")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/chrislusf/seaweedfs/weed/stats"
|
"github.com/chrislusf/seaweedfs/weed/stats"
|
||||||
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
|
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
|
||||||
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiskLocation struct {
|
type DiskLocation struct {
|
||||||
|
@ -60,6 +61,13 @@ func parseCollectionVolumeId(base string) (collection string, vid needle.VolumeI
|
||||||
func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind NeedleMapType) bool {
|
func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind NeedleMapType) bool {
|
||||||
name := fileInfo.Name()
|
name := fileInfo.Name()
|
||||||
if !fileInfo.IsDir() && strings.HasSuffix(name, ".idx") {
|
if !fileInfo.IsDir() && strings.HasSuffix(name, ".idx") {
|
||||||
|
noteFile := l.Directory + "/" + name + ".note"
|
||||||
|
if util.FileExists(noteFile) {
|
||||||
|
note, _ := ioutil.ReadFile(noteFile)
|
||||||
|
glog.Warningf("volume %s was not completed: %s", name, string(note))
|
||||||
|
removeVolumeFiles(l.Directory + "/" + name)
|
||||||
|
return false
|
||||||
|
}
|
||||||
vid, collection, err := l.volumeIdFromPath(fileInfo)
|
vid, collection, err := l.volumeIdFromPath(fileInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("get volume id failed, %s, err : %s", name, err)
|
glog.Warningf("get volume id failed, %s, err : %s", name, err)
|
||||||
|
|
|
@ -56,16 +56,21 @@ func (v *Volume) Destroy() (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.Close()
|
v.Close()
|
||||||
os.Remove(v.FileName() + ".dat")
|
removeVolumeFiles(v.FileName())
|
||||||
os.Remove(v.FileName() + ".idx")
|
|
||||||
os.Remove(v.FileName() + ".vif")
|
|
||||||
os.Remove(v.FileName() + ".sdx")
|
|
||||||
os.Remove(v.FileName() + ".cpd")
|
|
||||||
os.Remove(v.FileName() + ".cpx")
|
|
||||||
os.RemoveAll(v.FileName() + ".ldb")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeVolumeFiles(filename string) {
|
||||||
|
os.Remove(filename+ ".dat")
|
||||||
|
os.Remove(filename + ".idx")
|
||||||
|
os.Remove(filename + ".vif")
|
||||||
|
os.Remove(filename + ".sdx")
|
||||||
|
os.Remove(filename + ".cpd")
|
||||||
|
os.Remove(filename + ".cpx")
|
||||||
|
os.RemoveAll(filename + ".ldb")
|
||||||
|
os.Remove(filename + ".note")
|
||||||
|
}
|
||||||
|
|
||||||
func (v *Volume) asyncRequestAppend(request *needle.AsyncRequest) {
|
func (v *Volume) asyncRequestAppend(request *needle.AsyncRequest) {
|
||||||
v.asyncRequestsChan <- request
|
v.asyncRequestsChan <- request
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue