From 75967b355cd3d7ae67785df6183d704df56af4c0 Mon Sep 17 00:00:00 2001 From: "user.email" Date: Fri, 23 Oct 2026 18:56:57 -0700 Subject: [PATCH] filer: run the lock pre-pass for ancestors of the buckets dir A recursive delete rooted at the buckets dir (or an ancestor of it when nested) reaches each bucket only mid-walk, where an unmarked bucket on a drop-capable store loses its children to an unchecked DeleteFolderChildren. mayDescendantsHoldLocks now also answers true when the subtree contains the buckets dir rather than sitting inside it, so the pre-pass walks those buckets before the first drop can run. --- weed/filer/filer_delete_entry.go | 6 +++++- weed/filer/filer_delete_entry_test.go | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/weed/filer/filer_delete_entry.go b/weed/filer/filer_delete_entry.go index 56aec5d6aa..27d8e5fb12 100644 --- a/weed/filer/filer_delete_entry.go +++ b/weed/filer/filer_delete_entry.go @@ -205,7 +205,11 @@ func (f *Filer) mayDescendantsHoldLocks(ctx context.Context, p util.FullPath, en } rel := strings.TrimPrefix(string(p), f.DirBucketsPath+"/") if rel == string(p) { - return false + // The subtree can also hold locks by containing the buckets dir + // itself: deleting it or an ancestor drops each bucket's children + // unseen mid-walk. + dir := strings.TrimSuffix(string(p), "/") + return dir == f.DirBucketsPath || strings.HasPrefix(f.DirBucketsPath, dir+"/") } bucket, _, _ := strings.Cut(rel, "/") if bucket == "" { diff --git a/weed/filer/filer_delete_entry_test.go b/weed/filer/filer_delete_entry_test.go index 91090aa3c2..e338299ed9 100644 --- a/weed/filer/filer_delete_entry_test.go +++ b/weed/filer/filer_delete_entry_test.go @@ -359,6 +359,29 @@ func TestDeleteUnmarkedBucketNonRecursiveRefusesLockedObject(t *testing.T) { require.NotNil(t, store.getEntry("/buckets/b/held.bin"), "a non-recursive unmarked bucket drop must not swallow the locked object") } +// A recursive delete rooted at the buckets dir reaches each bucket only +// mid-walk, so the pre-pass has to know the subtree holds buckets whose +// children the store would drop unseen. +func TestDeleteBucketsRootRecursiveRefusesLockedObject(t *testing.T) { + store := newStubFilerStore() + f := newTestFiler(t, store, NewFilerRemoteStorage()) + f.DirBucketsPath = "/buckets" + f.Store = NewFilerStoreWrapper(&bucketDropStore{store}) + ctx := context.Background() + + require.NoError(t, f.CreateEntry(ctx, &Entry{FullPath: "/buckets", Attr: Attr{Mode: os.ModeDir | 0755}}, nil, false, false, nil, true, 255)) + require.NoError(t, f.CreateEntry(ctx, &Entry{FullPath: "/buckets/b", Attr: Attr{Mode: os.ModeDir | 0755}}, nil, false, false, nil, true, 255)) + require.NoError(t, f.CreateEntry(ctx, &Entry{ + FullPath: "/buckets/b/held.bin", + Attr: Attr{Mode: 0644}, + Extended: map[string][]byte{s3_constants.ExtLegalHoldKey: []byte("ON")}, + }, nil, false, false, nil, true, 255)) + + err := f.DeleteEntryMetaAndData(ctx, "/buckets", true, true, true, false, nil, 0) + require.ErrorIs(t, err, ErrEntryLocked) + require.NotNil(t, store.getEntry("/buckets/b/held.bin"), "an unseen bucket drop must not swallow the locked object") +} + // An expired retention no longer locks: the delete proceeds normally. func TestDeleteEntryAllowsExpiredRetention(t *testing.T) { store := newStubFilerStore()