filer: stamp ObjectTransaction's log_ts_ns from the meta-log clock

The wall clock can step back between two transactions on one key, or sit
below stamps already bumped past it, giving a later transaction a smaller
stamp than an earlier one or than its own event. Take the response stamp
from the same monotonic allocator the events use, released at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-01 13:58:56 -08:00
1 parent c529121bb8
commit b62d6d1d4e
3 files changed
+38 -1

No files matched your search

+8
View File
@@ -256,6 +256,14 @@ func (f *Filer) ReleaseEntryCommitTsNs(tsNs int64) {
f.metaLogInflight.release(tsNs)
}
// LogFenceTsNs returns a stamp above every event stamped so far; every later
// event stamps above it, even after the wall clock steps back.
func (f *Filer) LogFenceTsNs() int64 {
tsNs := f.metaLogInflight.stamp()
f.metaLogInflight.release(tsNs)
return tsNs
}
// stampOf returns the event's timestamp: the entry's in-flight stamp, or a
// fresh one for events with no newly stamped entry (deletes).
func (f *Filer) stampOf(newEntry *Entry) int64 {
+1 -1
View File
@@ -554,7 +554,7 @@ func (fs *FilerServer) ObjectTransaction(ctx context.Context, req *filer_pb.Obje
// Still under the lock: after every event this transaction logged, before
// the next writer of lock_key stamps its own.
resp.LogTsNs = time.Now().UnixNano()
resp.LogTsNs = fs.filer.LogFenceTsNs()
return resp, nil
}
@@ -1283,3 +1283,32 @@ func TestObjectTransactionLogTsNs(t *testing.T) {
t.Fatalf("refused mutation: failed_mutation %v log_ts_ns %d, want set and 0", refused.FailedMutation, refused.LogTsNs)
}
}
// With the wall clock behind stamps already issued, each transaction's stamp
// still follows its own event and the previous transaction's stamp.
func TestObjectTransactionLogTsNsClockBehind(t *testing.T) {
now := time.Unix(1700000000, 0)
fs, store := newTxnTestServer(t, map[string]*filer.Entry{
"/buckets/b/obj": {Attr: filer.Attr{Inode: 1, Mtime: now, Crtime: now, Mode: 0644}},
})
prev := time.Now().Add(time.Hour).UnixNano()
fs.filer.LocalDeliveredThroughTsNs(prev)
for i := 0; i < 2; i++ {
resp, err := fs.ObjectTransaction(context.Background(), &filer_pb.ObjectTransactionRequest{
LockKey: "/buckets/b/obj",
Mutations: []*filer_pb.ObjectMutation{{
Type: filer_pb.ObjectMutation_PATCH_EXTENDED, Directory: "/buckets/b", Name: "obj",
SetExtended: map[string][]byte{"X-Amz-Meta-k": []byte(strconv.Itoa(i))},
}},
})
if err != nil || resp.Error != "" {
t.Fatalf("txn %d: err=%v resp=%q", i, err, resp.GetError())
}
event := store.entries["/buckets/b/obj"].CommitTsNs
if event <= prev || resp.LogTsNs <= event {
t.Fatalf("txn %d: previous %d, event %d, log_ts_ns %d; want increasing", i, prev, event, resp.LogTsNs)
}
prev = resp.LogTsNs
}
}