filer: keep the stamp sequence above renumbered log positions

The meta log buffer renumbers an event appended out of stamp order past
the last position it holds, and that position is what subscribers see.
Concurrent writers append in whatever order their notify work finishes,
and with the wall clock behind the sequence every renumbered position
lands past the last stamp, so a later fence could sit below an event the
fenced state already reflects. Feed each delivered position back into the
sequence stamps and fences draw from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-01 14:43:04 -08:00
1 parent 36a11744cb
commit 9684b466f3
2 files changed
+50

No files matched your search

+14
View File
@@ -143,6 +143,17 @@ func (t *metaLogInflight) nextLocked() int64 {
return tsNs
}
// delivered keeps later stamps and fences above a position the buffer
// assigned: it renumbers an event appended out of stamp order past the
// last position, which can be past every stamp issued so far.
func (t *metaLogInflight) delivered(positionNs int64) {
t.Lock()
defer t.Unlock()
if positionNs > t.lastStampNs {
t.lastStampNs = positionNs
}
}
// done removes a stamp once the event has been appended to the buffer.
func (t *metaLogInflight) done(tsNs int64) {
t.Lock()
@@ -337,6 +348,9 @@ func (f *Filer) logMetaEvent(ctx context.Context, event *filer_pb.SubscribeMetad
glog.Errorf("failed to add data to log buffer for %s: %v", event.Directory, err)
return
}
// Before a locked writer releases its path, so a fenced read of that path
// lands above the position its event was delivered at.
f.metaLogInflight.delivered(tsNs)
notifyRenameTarget(f.LocalMetaLogBuffer, event)
// The in-memory copy now carries the position the stream assigns it, the
// same value subscribers will see delivered.
+36
View File
@@ -161,6 +161,42 @@ func TestMetaLogInflightFenceOrdersWithStamps(t *testing.T) {
}
}
// Events appended out of stamp order are renumbered by the buffer past the
// last stamp; a fence drawn afterwards must still sit above every delivered
// position, also with the wall clock behind the log.
func TestLogFenceAboveRenumberedPositions(t *testing.T) {
f, _ := newTestFilerWithStubStore(t)
f.LocalDeliveredThroughTsNs(time.Now().Add(time.Hour).UnixNano())
var entries []*Entry
var lastStamp int64
for _, name := range []string{"a", "b", "c"} {
entry := &Entry{FullPath: util.FullPath("/dir/" + name), Attr: Attr{Mode: 0o644}}
lastStamp = f.StampEntryCommitTsNs(entry)
entries = append(entries, entry)
}
var maxPosition int64
for i := len(entries) - 1; i >= 0; i-- {
ctx, sink := WithMetadataEventSink(context.Background())
f.NotifyUpdateEvent(ctx, nil, entries[i], false, false, nil)
if sink.Last() == nil {
t.Fatalf("no event for %s", entries[i].FullPath)
}
maxPosition = max(maxPosition, sink.Last().TsNs)
}
if maxPosition <= lastStamp {
t.Fatalf("appends were not renumbered: max position %d, last stamp %d", maxPosition, lastStamp)
}
if fence := f.LogFenceTsNs(); fence <= maxPosition {
t.Fatalf("fence %d not above delivered position %d", fence, maxPosition)
}
entry := &Entry{FullPath: "/dir/d", Attr: Attr{Mode: 0o644}}
if next := f.StampEntryCommitTsNs(entry); next <= maxPosition {
t.Fatalf("next stamp %d not above delivered position %d", next, maxPosition)
}
f.ReleaseEntryCommitTsNs(entry.CommitTsNs)
}
// 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