filer: fence CreateEntry and UpdateEntry from the event stamp sequence

Both stamped their pre-write fence from the raw wall clock, so after a
backwards clock step the fence could sit below events the acknowledged
state already reflects, including the previous write's event on the same
key. A mount that versions a no-op ack by that fence would then accept an
older event over it. Take the fence from the same sequence the events use,
so it lands above every earlier event and below the write's own.

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:18:04 -08:00
1 parent 7a5d9b0ad2
commit b4ea73b231
2 files changed
+47 -2

No files matched your search

+2 -2
View File
@@ -280,7 +280,7 @@ func (fs *FilerServer) CreateEntry(ctx context.Context, req *filer_pb.CreateEntr
// Fence stamped under the lock: a no-op create returns no event, but the
// acknowledged state still reflects everything at or below this.
resp.LogTsNs = time.Now().UnixNano()
resp.LogTsNs = fs.filer.LogFenceTsNs()
resp.LogSignature = fs.filer.Signature
// Evaluate the optional precondition against the current entry while the
@@ -1033,7 +1033,7 @@ func (fs *FilerServer) updateEntry(ctx context.Context, req *filer_pb.UpdateEntr
// Fence stamped under the lock: the no-change path below returns no event,
// but the acknowledged state still reflects everything at or below this.
logTsNs := time.Now().UnixNano()
logTsNs := fs.filer.LogFenceTsNs()
transactional := fs.filer.RefusesConflictingCommits(lockPath)
var entry *filer.Entry
@@ -1312,3 +1312,48 @@ func TestObjectTransactionLogTsNsClockBehind(t *testing.T) {
prev = resp.LogTsNs
}
}
// stepMetaLogClockBack leaves the wall clock d behind the filer's log history,
// as after a backwards clock step: an issued claim ahead of now is a floor the
// log's stamps must stay above.
func stepMetaLogClockBack(f *filer.Filer, d time.Duration) int64 {
ahead := time.Now().Add(d).UnixNano()
f.LocalDeliveredThroughTsNs(ahead)
return ahead
}
// CreateEntry and UpdateEntry fence before their write: with the wall clock
// behind the log, each fence is above the previous write's event on the key
// and below its own.
func TestCreateUpdateEntryLogTsNsAcrossClockStep(t *testing.T) {
fs, _ := newTxnTestServer(t, nil)
entry := func(mtime int64) *filer_pb.Entry {
return &filer_pb.Entry{Name: "obj", Attributes: &filer_pb.FuseAttributes{Mtime: mtime, FileMode: 0644, Inode: 1}}
}
floor := stepMetaLogClockBack(fs.filer, time.Hour)
created, err := fs.CreateEntry(context.Background(), &filer_pb.CreateEntryRequest{Directory: "/buckets/bkt", Entry: entry(1700000000)})
if err != nil || created.Error != "" {
t.Fatalf("CreateEntry: err=%v resp=%q", err, created.GetError())
}
createEv := created.MetadataEvent
if createEv == nil {
t.Fatal("CreateEntry logged no event")
}
if created.LogTsNs <= floor || created.LogTsNs >= createEv.TsNs {
t.Fatalf("CreateEntry log_ts_ns %d not between the log floor %d and its event %d", created.LogTsNs, floor, createEv.TsNs)
}
stepMetaLogClockBack(fs.filer, 2*time.Hour)
updated, err := fs.UpdateEntry(context.Background(), &filer_pb.UpdateEntryRequest{Directory: "/buckets/bkt", Entry: entry(1700000005)})
if err != nil {
t.Fatalf("UpdateEntry: %v", err)
}
updateEv := updated.MetadataEvent
if updateEv == nil {
t.Fatal("UpdateEntry logged no event")
}
if updated.LogTsNs <= createEv.TsNs || updated.LogTsNs >= updateEv.TsNs {
t.Fatalf("UpdateEntry log_ts_ns %d not between the create's event %d and its own %d", updated.LogTsNs, createEv.TsNs, updateEv.TsNs)
}
}