From eb1dca808897090af06327cd05ac0b7e3c9ff12f Mon Sep 17 00:00:00 2001 From: Carlos Leyva <66577002+carlos-leyva-guerrero@users.noreply.github.com> Date: Wed, 18 Nov 2026 07:37:56 +0100 Subject: [PATCH] filer: release the stamps of parent directories a rename creates (#12711) * filer: release the stamps of parent directories a rename creates * filer: test that a suppressed create keeps the moved entry's stamp in flight Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Chris Lu Co-authored-by: Claude Opus 5.5 --- weed/filer/filer.go | 10 ++++-- weed/filer/filer_notify_inflight_test.go | 45 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/weed/filer/filer.go b/weed/filer/filer.go index 0fa2c4399f..1b9b10664f 100644 --- a/weed/filer/filer.go +++ b/weed/filer/filer.go @@ -699,9 +699,11 @@ func (f *Filer) ensureParentDirectoryEntry(ctx context.Context, entry *Entry, di glog.V(3).InfofCtx(ctx, "mkdir %s: %v", dirPath, mkdirErr) return fmt.Errorf("mkdir %s: %v", dirPath, mkdirErr) } - } else if !strings.HasPrefix("/"+util.Join(dirParts[:]...), SystemLogDir) { + } else if !metadataEventsSuppressed(ctx) && !strings.HasPrefix("/"+util.Join(dirParts[:]...), SystemLogDir) { f.NotifyUpdateEvent(ctx, nil, dirEntry, false, isFromOtherCluster, nil) } else { + // No event adopts this stamp: a suppressing caller (rename) covers + // only its own entry, not the parents created on the way. f.releaseEntryCommitTsNs(dirEntry.CommitTsNs) } @@ -727,7 +729,11 @@ func (f *Filer) ensureParentDirectoryEntry(ctx context.Context, entry *Entry, di f.releaseEntryCommitTsNs(dirEntry.CommitTsNs) return fmt.Errorf("promote %s to directory: %v", dirPath, updateErr) } - f.NotifyUpdateEvent(ctx, nil, dirEntry, false, isFromOtherCluster, nil) + if metadataEventsSuppressed(ctx) { + f.releaseEntryCommitTsNs(dirEntry.CommitTsNs) + } else { + f.NotifyUpdateEvent(ctx, nil, dirEntry, false, isFromOtherCluster, nil) + } } return nil diff --git a/weed/filer/filer_notify_inflight_test.go b/weed/filer/filer_notify_inflight_test.go index 91c2f34ac2..19cbf76203 100644 --- a/weed/filer/filer_notify_inflight_test.go +++ b/weed/filer/filer_notify_inflight_test.go @@ -1,9 +1,11 @@ package filer import ( + "context" "testing" "time" + "github.com/seaweedfs/seaweedfs/weed/util" "github.com/seaweedfs/seaweedfs/weed/util/log_buffer" ) @@ -132,3 +134,46 @@ func TestMetaLogInflightStampMonotonic(t *testing.T) { inflight.done(ts1) inflight.done(ts2) } + +// TestSuppressedCreateReleasesParentDirectoryStamps pins the stamps of the +// parent directories a rename creates or promotes on the way to its target: +// the rename's covering event names the moved entry only, so a parent stamp +// left in flight caps LocalDeliveredThroughTsNs for good and every peer holds +// its aggregated subscribers at the settled horizon. +func TestSuppressedCreateReleasesParentDirectoryStamps(t *testing.T) { + for _, tc := range []struct { + name string + existing string // an object where the target's parent will be + targetPath string + }{ + {name: "missing parents", targetPath: "/buckets/data/.trash/2026/11/file.txt"}, + {name: "object promoted to directory", existing: "/buckets/data/prefix", targetPath: "/buckets/data/prefix/file.txt"}, + } { + t.Run(tc.name, func(t *testing.T) { + f, _ := newTestFilerWithStubStore(t) + if tc.existing != "" { + object := &Entry{FullPath: util.FullPath(tc.existing), Attr: Attr{Mode: 0o644}} + if err := f.CreateEntry(context.Background(), object, nil, false, false, nil, false, f.MaxFilenameLength); err != nil { + t.Fatalf("create %s: %v", tc.existing, err) + } + } + + entry := &Entry{FullPath: util.FullPath(tc.targetPath), Attr: Attr{Mode: 0o644}} + ctx := WithSuppressedMetadataEvents(context.Background()) + if err := f.CreateEntry(ctx, entry, nil, false, false, nil, false, f.MaxFilenameLength); err != nil { + t.Fatalf("create %s: %v", tc.targetPath, err) + } + if got := f.LocalDeliveredThroughTsNs(time.Now().UnixNano()); got != entry.CommitTsNs-1 { + t.Fatalf("claim=%d before the covering event, want %d: the moved entry's stamp must stay in flight", got, entry.CommitTsNs-1) + } + // The rename handler emits the covering event for the moved entry + // after the commit, which adopts the entry's own stamp. + f.NotifyUpdateEvent(context.Background(), nil, entry, false, false, nil) + + now := time.Now().UnixNano() + if got := f.LocalDeliveredThroughTsNs(now); got != now { + t.Fatalf("claim=%d want now=%d: %d parent directory stamp(s) still in flight", got, now, len(f.metaLogInflight.stamped)) + } + }) + } +}