s3: leave a pointer to a recently minted version unrepaired

When a versioned read finds a latest pointer whose version file is
missing, the self-heal rescanned .versions and then either removed the
directory (no version left) or rewrote the pointer to the newest version
found. With filer.sync the directory and its pointer can arrive before
the version file, so the heal acted on a version still in flight: the
local directory removal replicated back and deleted the committed
version on the source cluster, and a pointer repair would roll its
latest pointer back.

While the pointer names a version minted in the last ten minutes, the
read now answers from the rescan without persisting anything, and the
reconciler skips the key. After that window the heal works as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-11-27 12:35:29 -08:00
1 parent 0b3bb80be8
commit 5604340c37
4 files changed
+61 -1

No files matched your search

+19
View File
@@ -2339,6 +2339,14 @@ func (s3a *S3ApiServer) healStaleLatestVersionPointer(bucket, normalizedObject s
return nil, scanErr
}
if versionPointerInFlight(versionsEntry) {
versioningHealInfof("deferred", "bucket=%s key=%s mode=recent_pointer missing_file=%s", bucket, normalizedObject, stalePointerFile)
if latestEntry == nil {
return nil, fmt.Errorf("%w: no remaining version in %s", filer_pb.ErrNotFound, versionsDir)
}
return attachResolvedVersionId(latestEntry, latestVersionId), nil
}
if latestEntry == nil {
// No version remains: remove the residue directory outright so future
// reads take the clean ErrNotFound path instead of re-entering this
@@ -2422,6 +2430,17 @@ 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
// .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
func versionPointerInFlight(versionsEntry *filer_pb.Entry) bool {
ts := getVersionTimestamp(string(versionsEntry.GetExtended()[s3_constants.ExtLatestVersionIdKey]))
return ts > 0 && time.Since(time.Unix(0, ts)) < staleVersionPointerGrace
}
// conditionalUpdateEntryRouted persists the repair on the object's write
// owner — the filer the heal read from — via an ObjectTransaction carrying
// the object's route key. A conditioned UpdateEntry would instead route by
@@ -0,0 +1,37 @@
package s3api
import (
"fmt"
"math"
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
)
func TestVersionPointerInFlight(t *testing.T) {
inverted := func(at time.Time) string {
return fmt.Sprintf("%016x", uint64(math.MaxInt64-at.UnixNano())) + "0000000000000000"
}
pointer := func(id string) *filer_pb.Entry {
return &filer_pb.Entry{Extended: map[string][]byte{s3_constants.ExtLatestVersionIdKey: []byte(id)}}
}
now := time.Now()
for _, tc := range []struct {
name string
entry *filer_pb.Entry
want bool
}{
{"just minted", pointer(generateVersionId(true)), true},
{"just minted, old format", pointer(generateVersionId(false)), true},
{"minted within the grace", pointer(inverted(now.Add(-staleVersionPointerGrace / 2))), true},
{"minted before the grace", pointer(inverted(now.Add(-2 * staleVersionPointerGrace))), false},
{"null version", pointer("null"), false},
{"no pointer", &filer_pb.Entry{}, false},
} {
if got := versionPointerInFlight(tc.entry); got != tc.want {
t.Errorf("%s: versionPointerInFlight = %v, want %v", tc.name, got, tc.want)
}
}
}
+1 -1
View File
@@ -125,7 +125,7 @@ func TestVersioningHealEventVocabulary(t *testing.T) {
"produced", "surfaced", "healed", "enqueue",
"drain", "retry", "gave_up", "anomaly",
"clear_failed", "heal_persist_failed", "teardown_failed",
"queue_full",
"queue_full", "deferred",
}
// Just assert the list itself stays explicit and non-empty.
assert.NotEmpty(t, known)
@@ -29,6 +29,7 @@ const versioningHealLogPrefix = "[versioning-heal]"
// event=produced — stranded state was created (or would have been before this PR's fixes)
// event=surfaced — read-path heal triggered for an already-stranded key
// event=healed — pointer was successfully repaired or cleared
// event=deferred — pointer to a recently minted version left unrepaired
// event=enqueue — reconciler queued a candidate
// event=drain — reconciler successfully drained a candidate
// event=retry — reconciler attempt failed, will retry
@@ -271,6 +272,9 @@ func (s3a *S3ApiServer) healVersionsPointer(bucket, object string) error {
return nil
}
latestFile := string(fileBytes)
if versionPointerInFlight(versionsEntry) {
return nil
}
if _, probeErr := s3a.getEntry(bucketDir+"/"+versionsObjectPath, latestFile); probeErr == nil {
// Pointer is consistent.
return nil