mount: fence events below a cached entry's own commit stamp (#13152)

A listing snapshot capped at the peers' delivery watermark can trail
entries already in the store. A delayed event older than the listed
version then rolled the entry back, e.g. a completed file to its empty
create, until the newer event arrived. A live entry now counts as
versioned at least at its CommitTsNs.

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:
authored and GitHub committed 2026-11-30 15:28:08 -08:00
1 parent 0d09c87281
commit df2fa630c1
2 files changed
+68 -1

No files matched your search

+7 -1
View File
@@ -647,9 +647,15 @@ func (mc *MetaCache) entryVersionBlocksLocked(ctx context.Context, fp util.FullP
// event can correct it.
return false
}
if !tombstone && !mc.entryExistsLocked(ctx, fp) {
entry, err := mc.localStore.FindEntry(ctx, fp)
live := err == nil && entry != nil && !isTtlExpired(entry)
if !tombstone && !live {
recordTsNs = 0
}
// A live entry reflects its own commit, even under an older listing floor.
if live && entry.CommitTsNs > recordTsNs {
recordTsNs = entry.CommitTsNs
}
floorTsNs := mc.entryVersionFloorLocked(fp, recordTsNs)
if removal && !tombstone {
return floorTsNs > tsNs
@@ -957,3 +957,64 @@ func TestUnversionedWriteDoesNotInheritDirectoryFloor(t *testing.T) {
}
mc.WaitForEntryInvalidations()
}
// A listing snapshot can trail the listed entries: a peer's held watermark
// caps it below writes already in the store. A delayed older event must not
// roll a listed entry back to the state it replaced.
func TestBuildKeepsListedEntryNewerThanSnapshot(t *testing.T) {
mc, _, _, _ := newTestMetaCache(t, map[util.FullPath]bool{
"/": true,
"/dir": true,
})
defer mc.Shutdown()
if err := mc.BeginDirectoryBuild(context.Background(), util.FullPath("/dir")); err != nil {
t.Fatalf("begin build: %v", err)
}
if err := mc.doBatchInsertEntries(context.Background(), []*filer.Entry{{
FullPath: "/dir/file",
Attr: filer.Attr{
Crtime: time.Unix(1, 0),
Mtime: time.Unix(1, 0),
Mode: 0100644,
FileSize: 300,
},
CommitTsNs: 3000,
}}); err != nil {
t.Fatalf("batch insert: %v", err)
}
if err := mc.CompleteDirectoryBuild(context.Background(), util.FullPath("/dir"), 2000, nil); err != nil {
t.Fatalf("complete build: %v", err)
}
apply := func(tsNs int64, oldEntry, newEntry *filer_pb.Entry) {
t.Helper()
resp := &filer_pb.SubscribeMetadataResponse{
Directory: "/dir",
TsNs: tsNs,
EventNotification: &filer_pb.EventNotification{
OldEntry: oldEntry,
NewEntry: newEntry,
NewParentPath: "/dir",
},
}
if err := mc.ApplyMetadataResponse(context.Background(), resp, SubscriberMetadataResponseApplyOptions); err != nil {
t.Fatalf("apply event at %d: %v", tsNs, err)
}
}
wantSize := func(want uint64, why string) {
t.Helper()
entry, _, err := mc.FindEntry(context.Background(), util.FullPath("/dir/file"))
if err != nil || entry.FileSize != want {
t.Fatalf("entry = %+v, %v; want size %d (%s)", entry, err, want, why)
}
}
apply(2500, nil, &filer_pb.Entry{Name: "file", CommitTsNs: 2500, Attributes: &filer_pb.FuseAttributes{FileMode: 0100644}})
wantSize(300, "the create below the listed commit is already reflected")
apply(2500, &filer_pb.Entry{Name: "file"}, nil)
wantSize(300, "a removal below the listed commit is already reflected")
apply(3500, &filer_pb.Entry{Name: "file"}, &filer_pb.Entry{Name: "file", CommitTsNs: 3500, Attributes: &filer_pb.FuseAttributes{FileSize: 500, FileMode: 0100644}})
wantSize(500, "a change past the listed commit applies")
mc.WaitForEntryInvalidations()
}