carlos / platform Public

edge: the import reconcile rotates through its suspects (#1429)

Astra R3 P2-4, Fable R3 P3-1: each pass sorted the names and spent its
five ReconcileImport calls from the start, so five names that kept
failing (an unreadable claim, a refused delete) starved every later
one. A cursor kept across passes now starts each pass just after the
last name tried, still at most five calls. Test: five failing names
ahead of a deletable one; it is deleted within two passes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev f6f52a30e7b17920b045d553c6fc51bd9262c5ec parent 8c5bdfd
2 files changed, +68 −16
  • internal/edge/certimport.go +22 −16
  • internal/edge/certimport_test.go +46 −0
diff --git a/internal/edge/certimport.go b/internal/edge/certimport.go
index 55a99a66e..1f470a3c9 100644
--- a/internal/edge/certimport.go
+++ b/internal/edge/certimport.go
@@ -268,6 +268,8 @@ type importReconciler struct {
// mirror that has not listed since does not spend another
// ReconcileImport call on it.
removed map[string]string
+ // cursor is the last name a pass tried: the next pass starts after it.
+ cursor string
lastLog time.Time
}
@@ -335,28 +337,32 @@ func (r *importReconciler) pass(ctx context.Context) {
if r.now != nil {
now = r.now()
}
- names := make([]string, 0, len(imports))
+ // The prefilter. A claim the listing named but could not read is absent
+ // from claims, so it is a suspect like a missing one: ReconcileImport
+ // reads it afresh, and keeps the entry if that read fails as well.
+ var suspects []string
for name := range imports {
- names = append(names, name)
- }
- slices.Sort(names)
- calls := 0
- for _, name := range names {
host := strings.TrimSuffix(name, domains.ImportSuffix)
if r.alreadyRemoved(name, imports[name].etag) {
continue
}
- // The prefilter. A claim the listing named but could not read is
- // absent from claims, so it is a candidate like a missing one:
- // ReconcileImport reads it afresh, and keeps the entry if that read
- // fails as well.
- if _, suspect := domains.StaleImport(host, snap.entries[name], byHost[host], false, now, certSweepGrace); !suspect {
- continue
- }
- if calls >= importReconcileDeletesPerPass {
- return
+ if _, suspect := domains.StaleImport(host, snap.entries[name], byHost[host], false, now, certSweepGrace); suspect {
+ suspects = append(suspects, name)
}
- calls++
+ }
+ slices.Sort(suspects)
+ // Rotated through the sorted suspects from just after the last name the
+ // previous pass tried, so names that keep failing (an unreadable claim, a
+ // refused delete) cannot spend every pass's budget ahead of the rest.
+ r.mu.Lock()
+ start, _ := slices.BinarySearch(suspects, r.cursor+"\x00")
+ r.mu.Unlock()
+ for i := range min(len(suspects), importReconcileDeletesPerPass) {
+ name := suspects[(start+i)%len(suspects)]
+ host := strings.TrimSuffix(name, domains.ImportSuffix)
+ r.mu.Lock()
+ r.cursor = name
+ r.mu.Unlock()
dctx, cancel := context.WithTimeout(held, certPublishTimeout)
deleted, reason, err := domains.ReconcileImport(dctx, r.store, host, now, certSweepGrace)
cancel()
diff --git a/internal/edge/certimport_test.go b/internal/edge/certimport_test.go
index 546b38cae..5db6fd75a 100644
--- a/internal/edge/certimport_test.go
+++ b/internal/edge/certimport_test.go
@@ -1215,3 +1215,49 @@ func TestImportReconcileUnreadListingStillGetsAFreshLook(t *testing.T) {
t.Fatal("an import whose claim the fresh read shows held by another account survived")
}
}
+
+// manyClaimGetFailStore fails every Get of a set of claim keys.
+type manyClaimGetFailStore struct {
+ *release.DirStore
+ keys map[string]bool
+}
+
+func (c manyClaimGetFailStore) Get(ctx context.Context, key string) ([]byte, string, error) {
+ if c.keys[key] {
+ return nil, "", errors.New("bucket blip")
+ }
+ return c.DirStore.Get(ctx, key)
+}
+
+// Names that keep failing cannot starve the rest (Astra R3 P2-4, Fable R3
+// P3-1): five suspects whose claims never read sort ahead of a deletable
+// sixth, and the sixth is still deleted within two passes, five calls each.
+func TestImportReconcileRotatesPastPersistentFailures(t *testing.T) {
+ e2eQuietLogs(t)
+ ca := newE2ECA(t)
+ ds := release.NewDirStore(t.TempDir())
+ fail := map[string]bool{}
+ for _, l := range "abcde" {
+ h := string(l) + ".import.test"
+ putClaim(t, ds, h, "zzz", importApp, importCreated, false)
+ fail[domains.ClaimKey(h)] = true
+ putBucket(t, ds, domains.ImportName(h), goodImport(t, ca, h, false))
+ }
+ const last = "f.import.test" // no claim: deletable
+ putBucket(t, ds, domains.ImportName(last), goodImport(t, ca, last, false))
+ s := manyClaimGetFailStore{DirStore: ds, keys: fail}
+ m := newCertMirror(s, nil)
+ refreshMirror(t, m)
+ r := reconcilerFor(s, m, true)
+ r.pass(context.Background())
+ r.pass(context.Background())
+ if importPresent(t, ds, last) {
+ t.Fatal("five failing names ahead of it starved a deletable import")
+ }
+ for h := range fail {
+ host := strings.TrimSuffix(strings.TrimPrefix(h, domains.ClaimsPrefix), ".json")
+ if !importPresent(t, ds, host) {
+ t.Fatalf("%s was deleted on an unreadable claim", host)
+ }
+ }
+}