From 9b3bf0e46c65ab8dfa980750cb1b805f08383df9 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 9 Sep 2018 02:48:58 -0700 Subject: [PATCH] fix "weed backup" rerunning "weed backup" rerunning will already have ReplicaPlacement set, while version is not set. --- weed/storage/volume_loading.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/weed/storage/volume_loading.go b/weed/storage/volume_loading.go index 572220650..37a6e07b2 100644 --- a/weed/storage/volume_loading.go +++ b/weed/storage/volume_loading.go @@ -19,8 +19,9 @@ func loadVolumeWithoutIndex(dirname string, collection string, id VolumeId, need func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind NeedleMapType, preallocate int64) error { var e error fileName := v.FileName() + alreadyHasSuperBlock := false - if exists, canRead, canWrite, modifiedTime := checkFile(fileName + ".dat"); exists { + if exists, canRead, canWrite, modifiedTime, fileSize := checkFile(fileName + ".dat"); exists { if !canRead { return fmt.Errorf("cannot read Volume Data file %s.dat", fileName) } @@ -32,6 +33,9 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind v.dataFile, e = os.Open(fileName + ".dat") v.readOnly = true } + if fileSize >= _SuperBlockSize { + alreadyHasSuperBlock = true + } } else { if createDatIfMissing { v.dataFile, e = createVolumeFile(fileName+".dat", preallocate) @@ -48,7 +52,7 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind } } - if v.ReplicaPlacement == nil { + if alreadyHasSuperBlock { e = v.readSuperBlock() } else { e = v.maybeWriteSuperBlock() @@ -97,7 +101,7 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind return e } -func checkFile(filename string) (exists, canRead, canWrite bool, modTime time.Time) { +func checkFile(filename string) (exists, canRead, canWrite bool, modTime time.Time, fileSize int64) { exists = true fi, err := os.Stat(filename) if os.IsNotExist(err) { @@ -111,5 +115,6 @@ func checkFile(filename string) (exists, canRead, canWrite bool, modTime time.Ti canWrite = true } modTime = fi.ModTime() + fileSize = fi.Size() return }