mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-18 09:46:24 +01:00
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 <noreply@anthropic.com> --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2 files changed
+53
-2
No files matched your search
+8
-2
@@ -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
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user