From f627aa79fc66e4e26cb5ada5339fe9701ab937d1 Mon Sep 17 00:00:00 2001 From: Copilot Date: Sat, 21 Mar 2026 14:10:29 -0700 Subject: [PATCH] fix: avoid caching transient directory marker lookup failures --- test/s3/spark/issue_8285_repro_test.go | 2 +- .../empty_folder_cleaner.go | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/test/s3/spark/issue_8285_repro_test.go b/test/s3/spark/issue_8285_repro_test.go index 66b46439d..b715bfaf4 100644 --- a/test/s3/spark/issue_8285_repro_test.go +++ b/test/s3/spark/issue_8285_repro_test.go @@ -70,7 +70,7 @@ print("WRITE_COUNT=" + str(count)) "issue-8285/output/_temporary/0/", "issue-8285/output/_temporary/0/_temporary/", } - lingering := waitForObjectsToDisappear(t, env, "test", temporaryCandidates, 35*time.Second) + lingering := waitForObjectsToDisappear(t, env, "test", temporaryCandidates, 60*time.Second) if len(lingering) > 0 { t.Fatalf("issue #8285 regression detected: lingering temporary directories: %v", lingering) } diff --git a/weed/filer/empty_folder_cleanup/empty_folder_cleaner.go b/weed/filer/empty_folder_cleanup/empty_folder_cleaner.go index 5401537d8..3869f1f81 100644 --- a/weed/filer/empty_folder_cleanup/empty_folder_cleaner.go +++ b/weed/filer/empty_folder_cleanup/empty_folder_cleaner.go @@ -321,10 +321,13 @@ func (efc *EmptyFolderCleaner) executeCleanup(folder string, triggeredBy string) isMarker = *state.isDirectoryMarker } else { efc.mu.Unlock() - isMarker = efc.isDirectoryMarker(ctx, folder) + var cacheable bool + isMarker, cacheable = efc.isDirectoryMarker(ctx, folder) efc.mu.Lock() - if state, exists := efc.folderCounts[folder]; exists && state != nil { - state.isDirectoryMarker = &isMarker + if cacheable { + if state, exists := efc.folderCounts[folder]; exists && state != nil { + state.isDirectoryMarker = &isMarker + } } } efc.mu.Unlock() @@ -361,20 +364,20 @@ func (efc *EmptyFolderCleaner) deleteFolder(ctx context.Context, folder string) return efc.filer.DeleteEntryMetaAndData(ctx, util.FullPath(folder), false, false, false, false, nil, 0) } -func (efc *EmptyFolderCleaner) isDirectoryMarker(ctx context.Context, folder string) bool { +func (efc *EmptyFolderCleaner) isDirectoryMarker(ctx context.Context, folder string) (bool, bool) { attrs, err := efc.filer.GetEntryAttributes(ctx, util.FullPath(folder)) if err != nil { if errors.Is(err, filer_pb.ErrNotFound) { - return false + return false, true } - glog.V(2).Infof("EmptyFolderCleaner: error reading attributes for %s, skipping deletion: %v", folder, err) - return true + glog.V(2).Infof("EmptyFolderCleaner: error reading attributes for %s, allowing deletion: %v", folder, err) + return false, false } if attrs == nil { - return false + return false, true } _, hasMime := attrs[s3_constants.ExtMimeType] - return hasMime + return hasMime, true } func (efc *EmptyFolderCleaner) getBucketCleanupPolicy(ctx context.Context, folder string) (bucketPath string, autoRemove bool, source string, attrValue string, err error) {