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.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
fix(ec): don't fabricate a stub .vif when mounting an EC volume (#9951)
Chris Lu26754fca4d65
diff --git a/weed/storage/erasure_coding/ec_volume.go b/weed/storage/erasure_coding/ec_volume.goindex 7ea3373fba..ac919b37ac 100644--- a/weed/storage/erasure_coding/ec_volume.go+++ b/weed/storage/erasure_coding/ec_volume.go@@ -173,8 +173,13 @@ func NewEcVolume(diskType types.DiskType, dir string, dirIdx string, collectionev.ECContext = NewDefaultECContext(collection, vid)}} else {- glog.Warningf("vif file not found,volumeId:%d, filename:%s", vid, vifFileName)- volume_info.SaveVolumeInfo(dataBaseFileName+".vif", &volume_server_pb.VolumeInfo{Version: uint32(ev.Version)})+ // Don't fabricate a stub .vif here: a version-only stub implies the+ // default 10+4 ratio with DatFileSize=0 and no encode identity, which+ // the custom-ratio resolver and the startup credibility checks must not+ // mistake for an authoritative config. Mount with in-memory defaults and+ // leave the real .vif to the encoder or a recovery tool (the Rust volume+ // server already behaves this way).+ glog.Warningf("vif file not found, using defaults, volumeId:%d, filename:%s", vid, vifFileName)ev.ECContext = NewDefaultECContext(collection, vid)}diff --git a/weed/storage/erasure_coding/ec_volume_test.go b/weed/storage/erasure_coding/ec_volume_test.goindex 0864a2bd4d..639a4c1572 100644--- a/weed/storage/erasure_coding/ec_volume_test.go+++ b/weed/storage/erasure_coding/ec_volume_test.go@@ -91,3 +91,31 @@ func TestNewEcVolumeLoadsEncodeTsNs(t *testing.T) {t.Errorf("EncodeTsNs = %d, want %d", ev.EncodeTsNs, tsNs)}}++// TestNewEcVolumeDoesNotWriteStubVif pins that mounting an EC volume whose .vif+// is missing does NOT fabricate a stub .vif. A version-only stub would imply+// the default ratio with DatFileSize=0 and no encode identity, which the+// custom-ratio resolver and startup credibility checks must not trust.+func TestNewEcVolumeDoesNotWriteStubVif(t *testing.T) {+ dir := t.TempDir()+ const vid = needle.VolumeId(124)+ base := EcShardFileName("", dir, int(vid))++ if err := os.WriteFile(base+".ecx", nil, 0o644); err != nil {+ t.Fatalf("write .ecx: %v", err)+ }++ ev, err := NewEcVolume(types.HardDriveType, dir, dir, "", vid)+ if err != nil {+ t.Fatalf("NewEcVolume: %v", err)+ }+ defer ev.Close()++ if _, statErr := os.Stat(base + ".vif"); !os.IsNotExist(statErr) {+ t.Fatalf("mounting without a .vif must not create one, stat err=%v", statErr)+ }+ // Mount still succeeds with the build's default EC ratio in memory.+ if ev.ECContext == nil || ev.ECContext.DataShards != int(DataShardsCount) {+ t.Fatalf("expected default EC context, got %+v", ev.ECContext)+ }+}