Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fix "weed backup" rerunning

Chris Lu9b3bf0e46c65
diff --git a/weed/storage/volume_loading.go b/weed/storage/volume_loading.go
index 5722206507..37a6e07b29 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
}