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
filer: fail writes when the existing-entry lookup fails (#11699)
Chris Luc3d13c60e91d
diff --git a/weed/filer/filer.go b/weed/filer/filer.goindex a78d906912..bee16acdf3 100644--- a/weed/filer/filer.go+++ b/weed/filer/filer.go@@ -339,9 +339,9 @@ func (f *Filer) CreateEntry(ctx context.Context, entry *Entry, existing *Entry,if oldEntry == nil {var findErr erroroldEntry, findErr = f.FindEntry(ctx, entry.FullPath)- if o_excl && findErr != nil && !errors.Is(findErr, filer_pb.ErrNotFound) {- // An exclusive create cannot decide whether the path exists when- // the lookup itself failed; proceeding would upsert over it.+ if findErr != nil && !errors.Is(findErr, filer_pb.ErrNotFound) {+ // A create cannot decide whether the path exists when the lookup+ // itself failed; proceeding would upsert over it.return fmt.Errorf("find entry %s: %w", entry.FullPath, findErr)}}diff --git a/weed/filer/filer_inode_test.go b/weed/filer/filer_inode_test.goindex 0c6b5db69a..b00c1ec7e2 100644--- a/weed/filer/filer_inode_test.go+++ b/weed/filer/filer_inode_test.go@@ -265,3 +265,28 @@ func TestUpdateEntryBackfillsMissingLegacyInode(t *testing.T) {assert.NotZero(t, stored.Attr.Inode)assert.NotEqual(t, uint64(1), stored.Attr.Inode)}++// A transient store error must fail the write instead of being mistaken for a+// missing entry: on upsert stores proceeding would replace the entry without+// loading the old chunks, orphaning them from cleanup.+func TestCreateEntryFailsWhenLookupErrors(t *testing.T) {+ f, store := newTestFilerWithStubStore()+ path := util.FullPath("/dir/file.txt")+ require.NoError(t, store.InsertEntry(context.Background(), &Entry{+ FullPath: path,+ Content: []byte("existing"),+ }))+ store.findErr = errors.New("transient store failure")++ entry := &Entry{+ FullPath: path,+ Attr: Attr{Mode: 0o644},+ Content: []byte("overwrite"),+ }+ require.Error(t, f.CreateEntry(context.Background(), entry, nil, false, false, nil, false, f.MaxFilenameLength))++ store.findErr = nil+ stored, findErr := store.FindEntry(context.Background(), path)+ require.NoError(t, findErr)+ assert.Equal(t, "existing", string(stored.Content))+}