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: prevent empty .vif files from ec.decode causing parse errors (#7686)

Chris Lu5c2752250745
diff --git a/weed/server/volume_grpc_copy.go b/weed/server/volume_grpc_copy.go
index 410c6b05d5..2e20941adb 100644
--- a/weed/server/volume_grpc_copy.go
+++ b/weed/server/volume_grpc_copy.go
@@ -291,6 +291,15 @@ func writeToFile(client volume_server_pb.VolumeServer_CopyFileClient, fileName s
}
wt.MaybeSlowdown(int64(len(resp.FileContent)))
}
+ // If no data was written (source file was not found), remove the empty file
+ // to avoid leaving corrupted empty files that cause parse errors later
+ if progressedBytes == 0 && !isAppend {
+ if removeErr := os.Remove(fileName); removeErr != nil {
+ glog.V(1).Infof("failed to remove empty file %s: %v", fileName, removeErr)
+ } else {
+ glog.V(1).Infof("removed empty file %s (source file not found)", fileName)
+ }
+ }
return modifiedTsNs, nil
}
diff --git a/weed/storage/volume_info/volume_info.go b/weed/storage/volume_info/volume_info.go
index 2ac4cc4939..75cbc1472d 100644
--- a/weed/storage/volume_info/volume_info.go
+++ b/weed/storage/volume_info/volume_info.go
@@ -42,6 +42,14 @@ func MaybeLoadVolumeInfo(fileName string) (volumeInfo *volume_server_pb.VolumeIn
}
+ // Handle empty .vif files gracefully - treat as if file doesn't exist
+ // This can happen when ec.decode copies from a source that doesn't have a .vif file
+ if len(fileData) == 0 {
+ glog.Warningf("empty volume info file %s, treating as non-existent", fileName)
+ hasVolumeInfoFile = false
+ return
+ }
+
glog.V(1).Infof("maybeLoadVolumeInfo Unmarshal volume info %v", fileName)
if err = jsonpb.Unmarshal(fileData, volumeInfo); err != nil {
if oldVersionErr := tryOldVersionVolumeInfo(fileData, volumeInfo); oldVersionErr != nil {