s3: run the in-flight pointer grace from its local commit too

The grace was measured from the version id's mint time on the origin
cluster against the local clock, so a peer whose clock ran more than
the grace ahead, or a filer.sync backlog longer than the grace, saw a
just-synced pointer as stale and could remove or roll back the version.
The .versions entry's commit time is stamped by the local filer when
the pointer is stored, so it bounds the wait with the local clock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-11-27 13:14:53 -08:00
1 parent 86d52c0298
commit ab7bc8de5b
2 files changed
+23 -7

No files matched your search

+15 -7
View File
@@ -2430,20 +2430,28 @@ func (s3a *S3ApiServer) healStaleLatestVersionPointer(bucket, normalizedObject s
return latestEntry, nil
}
// staleVersionPointerGrace leaves a pointer to a recently minted version as it
// is: its file can still be on its way, e.g. when filer.sync applies the
// staleVersionPointerGrace leaves a recently minted or recently stored pointer
// as it is: its file can still be on its way, e.g. when filer.sync applies the
// .versions directory before the version file, and a local removal or repair
// then would replicate back and delete or roll back the version on the peer.
const staleVersionPointerGrace = 10 * time.Minute
// versionPointerGraceLeft returns how much of the grace the pointer has left;
// zero means its version file is overdue.
// zero means its version file is overdue. The grace runs from the later of the
// version's mint, stamped by the minting cluster, and the local commit of the
// .versions entry, so neither a clock ahead of the minting cluster nor a sync
// backlog ends it before the file could arrive.
func versionPointerGraceLeft(versionsEntry *filer_pb.Entry) time.Duration {
ts := getVersionTimestamp(string(versionsEntry.GetExtended()[s3_constants.ExtLatestVersionIdKey]))
if ts <= 0 {
return 0
var left time.Duration
for _, ts := range []int64{
getVersionTimestamp(string(versionsEntry.GetExtended()[s3_constants.ExtLatestVersionIdKey])),
versionsEntry.GetCommitTsNs(),
} {
if ts > 0 {
left = max(left, staleVersionPointerGrace-time.Since(time.Unix(0, ts)))
}
}
return min(max(staleVersionPointerGrace-time.Since(time.Unix(0, ts)), 0), staleVersionPointerGrace)
return min(left, staleVersionPointerGrace)
}
// conditionalUpdateEntryRouted persists the repair on the object's write
@@ -19,6 +19,11 @@ func versionPointerEntry(versionId string) *filer_pb.Entry {
return &filer_pb.Entry{Extended: map[string][]byte{s3_constants.ExtLatestVersionIdKey: []byte(versionId)}}
}
func committedAt(entry *filer_pb.Entry, at time.Time) *filer_pb.Entry {
entry.CommitTsNs = at.UnixNano()
return entry
}
func TestVersionPointerGraceLeft(t *testing.T) {
now := time.Now()
for _, tc := range []struct {
@@ -31,6 +36,9 @@ func TestVersionPointerGraceLeft(t *testing.T) {
{"minted within the grace", versionPointerEntry(invertedVersionId(now.Add(-staleVersionPointerGrace + 2*time.Minute))), time.Minute, 2 * time.Minute},
{"minted in the future", versionPointerEntry(invertedVersionId(now.Add(time.Hour))), staleVersionPointerGrace, staleVersionPointerGrace},
{"minted before the grace", versionPointerEntry(invertedVersionId(now.Add(-2 * staleVersionPointerGrace))), 0, 0},
{"minted before the grace, stored just now", committedAt(versionPointerEntry(invertedVersionId(now.Add(-2*staleVersionPointerGrace))), now), staleVersionPointerGrace - time.Minute, staleVersionPointerGrace},
{"minted and stored before the grace", committedAt(versionPointerEntry(invertedVersionId(now.Add(-2*staleVersionPointerGrace))), now.Add(-staleVersionPointerGrace)), 0, 0},
{"null version stored just now", committedAt(versionPointerEntry("null"), now), staleVersionPointerGrace - time.Minute, staleVersionPointerGrace},
{"null version", versionPointerEntry("null"), 0, 0},
{"no pointer", &filer_pb.Entry{}, 0, 0},
} {