console: the fleet seed hold in one place (Task 16 review)
- P1-1: the hold lives in the retirement primitives, not at each door. fleetSeedHold (a fleet file seed neither placed nor rolled-back) is asked in retireRecordWithLifetimeLocked under the app and hostname locks, and in retireHostRecord's lifetimes-off instance branch (retireLegacyInstanceRecord). It returns fleetSeedHoldError: domain detach (both doors) and the delete door answer its FS-33/FS-34 sentence, the purge FS-35. Rolled-back, reached only by the seeds door after the box's proof, passes, so the finish retires it. The app purge guards stay, refusing before any teardown. - P2-1: the sweep's fleet listing is its own half; a failure is logged and the region half carries on. - P3-1: with no data bucket the sweep leaves region seeds alone in its abandonment and finish steps. - P3-2: the fleet storage branch's unreachable refusal is commented.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 files changed,
+377
−8
internal/console/apidomains.go+4 −0internal/console/apiinstanceimport.go+4 −0internal/console/domainattach.go+6 −0internal/console/hostclaimops.go+41 −1internal/console/lifetimes_retire.go+8 −0internal/console/ownership.go+5 −0internal/console/seedfile.go+57 −1internal/console/seedholdreview_test.go+224 −0internal/console/seedsweep.go+12 −5internal/provision/fleet_seeded_create_3_census_test.go+16 −1
CI failed — run details
diff --git a/internal/console/apidomains.go b/internal/console/apidomains.go| index 503f47511..8331fe835 100644 |
| --- a/internal/console/apidomains.go |
| +++ b/internal/console/apidomains.go |
| @@ -1261,6 +1261,10 @@ func (s *Server) handleAPIDomainDetach(w http.ResponseWriter, r *http.Request) { |
| } |
| } else if err == nil && cur.Account == acct.Sqid && cur.App == app && cur.Route == "" { |
| if err := s.retireInstanceRecord(ctx, acct.Sqid, app, host, principal, cur.RecordIncarnation, retireAny); err != nil { |
| + if ref, ok := fleetSeedHoldRefusal(err); ok { |
| + jsonError(w, ref.Status, ref.Msg) |
| + return |
| + } |
| if accepted, ok := claimRetireAcceptedOf(err); ok { |
| s.audit(acct, app, principal, "domain-detach", "detach of hostname "+host+" accepted, operation "+accepted.operation+" (cli)") |
| s.bumpSerial(ctx) |
diff --git a/internal/console/apiinstanceimport.go b/internal/console/apiinstanceimport.go| index fc919029c..1ebea710e 100644 |
| --- a/internal/console/apiinstanceimport.go |
| +++ b/internal/console/apiinstanceimport.go |
| @@ -1136,6 +1136,10 @@ func (s *Server) importDeleteRule(w http.ResponseWriter, r *http.Request, acct * |
| // refusal (settling, refused, pending) as itself, anything else main's |
| // delete sentence. |
| func (s *Server) deleteRefused(w http.ResponseWriter, sqid, app, host string, err error) (answered, finished bool) { |
| + if ref, ok := fleetSeedHoldRefusal(err); ok { |
| + jsonError(w, ref.Status, ref.Msg) |
| + return true, false |
| + } |
| if ref, ok := lifetimeRetireRefusal(err, msgLifetimeSettling, msgLifetimeDeletePending, http.StatusBadGateway); ok { |
| if !errors.Is(err, errLifetimeSettling) { |
| log.Printf("console: api instances delete %s/%s/%s: %v", sqid, app, host, err) |
diff --git a/internal/console/domainattach.go b/internal/console/domainattach.go| index eff9f536e..765d8f848 100644 |
| --- a/internal/console/domainattach.go |
| +++ b/internal/console/domainattach.go |
| @@ -472,6 +472,9 @@ func (s *Server) releaseDomainHost(ctx context.Context, acct *Account, app, host |
| // attach. A record left behind by a released claim would keep a |
| // route alive for a host anyone may now claim. |
| if err := s.retireInstanceRecord(ctx, acct.Sqid, app, host, "domain-detach", claim.RecordIncarnation, retireAny); err != nil { |
| + if ref, ok := fleetSeedHoldRefusal(err); ok { |
| + return ref |
| + } |
| // The record's delete operation is durable and still running |
| // (or another operation holds the app): the hostname stays |
| // claimed until a later detach finds the record gone. |
| @@ -521,6 +524,9 @@ func (s *Server) detachRetireLocked(ctx context.Context, sqid, app, host string) |
| if err == nil { |
| return nil, nil |
| } |
| + if ref, ok := fleetSeedHoldRefusal(err); ok { |
| + return ref, nil |
| + } |
| // Settling and pending both leave the route's removal to finish first: |
| // a later detach finds the record gone and releases the claim. |
| if ref, ok := lifetimeRetireRefusal(err, claimDetachInProgressMsg, claimDetachInProgressMsg, http.StatusConflict); ok { |
diff --git a/internal/console/hostclaimops.go b/internal/console/hostclaimops.go| index 344d43a1e..ac47332a0 100644 |
| --- a/internal/console/hostclaimops.go |
| +++ b/internal/console/hostclaimops.go |
| @@ -2,8 +2,10 @@ package console |
| import ( |
| "context" |
| + "encoding/json" |
| "errors" |
| "log" |
| + "os" |
| "time" |
| "github.com/carlosframework/platform/internal/hostclaim" |
| @@ -30,7 +32,45 @@ func (s *Server) retireHostRecord(ctx context.Context, ref provision.RetireRef) |
| if s.cfg.HostClaimOps != nil { |
| claims = s.cfg.HostClaimOps |
| } |
| - return provision.RetireRecord(ctx, s.cfg.Releases, ref, provision.RetireOptions{HostClaim: s.cfg.HostClaim, Claims: claims}) |
| + opt := provision.RetireOptions{HostClaim: s.cfg.HostClaim, Claims: claims} |
| + if ref.Family == "instance" { |
| + return s.retireLegacyInstanceRecord(ctx, ref, opt) |
| + } |
| + return provision.RetireRecord(ctx, s.cfg.Releases, ref, opt) |
| +} |
| + |
| +// retireLegacyInstanceRecord is a claims-off instance retirement with |
| +// lifetimes off: the fleet seed hold (fleetSeedHold, Task 16 review P1-1) |
| +// asked of the record as it reads now, then the legacy delete exactly as |
| +// before (provision.RetireRecord). A record gone already, or a body that |
| +// will not decode, is no seed, and the delete runs as it always has. |
| +// |
| +// The delete stays unconditional, as the legacy callers (detach, attach |
| +// rollback, a create's undo) and their stores expect, so a fleet file seed |
| +// written at the host between this read and that delete is not seen here. |
| +// That window is lifetimes-off only and needs a seed create racing a |
| +// detach of the same host; with lifetimes on the hold is asked under the |
| +// app and hostname locks every writer of the host takes |
| +// (retireRecordWithLifetimeLocked). |
| +func (s *Server) retireLegacyInstanceRecord(ctx context.Context, ref provision.RetireRef, opt provision.RetireOptions) error { |
| + raw, _, err := s.cfg.Releases.Get(ctx, provision.RecordKey(ref.Account, ref.App, ref.Host)) |
| + switch { |
| + case err == nil: |
| + // Only the fields the hold reads: the record's own decode is the |
| + // readers', and this is no copy of it. |
| + var body struct { |
| + Region string `json:"region"` |
| + Seed *provision.SeedSource `json:"seed"` |
| + } |
| + if json.Unmarshal(raw, &body) == nil { |
| + if err := fleetSeedHoldOf(ref.Host, body.Region, body.Seed); err != nil { |
| + return err |
| + } |
| + } |
| + case !errors.Is(err, os.ErrNotExist): |
| + return err |
| + } |
| + return provision.RetireRecord(ctx, s.cfg.Releases, ref, opt) |
| } |
| func (s *Server) adoptHostRecord(ctx context.Context, key string) (hostclaim.Observed, error) { |
| if !s.cfg.HostClaim || s.cfg.HostClaimOps == nil { |
diff --git a/internal/console/lifetimes_retire.go b/internal/console/lifetimes_retire.go| index b0746cd16..2613f2dcd 100644 |
| --- a/internal/console/lifetimes_retire.go |
| +++ b/internal/console/lifetimes_retire.go |
| @@ -125,6 +125,14 @@ func (s *Server) retireRecordWithLifetimeLocked(ctx context.Context, acct, app, |
| owned && slot.Incarnation == expect.Incarnation): |
| return nil |
| } |
| + // The fleet seed hold (Task 16 review P1-1): a fleet file seed whose box |
| + // has not proved it gone is never retired, whichever entrance asked. |
| + // Read under both locks, before anything is persisted. |
| + if obs.Present { |
| + if err := fleetSeedHold(obs.Rec); err != nil { |
| + return err |
| + } |
| + } |
| liveOwned := owned && slot.State == provision.SlotLive |
| switch { |
| case !obs.Present && slot == nil: // (a) |
diff --git a/internal/console/ownership.go b/internal/console/ownership.go| index b5c8a39ef..b2fef71b3 100644 |
| --- a/internal/console/ownership.go |
| +++ b/internal/console/ownership.go |
| @@ -728,7 +728,12 @@ func (s *Server) trashFailure(w http.ResponseWriter, r *http.Request, acct *Acco |
| // same sentence the CLI's 409 gives (apicli.go), so an operator who meets both |
| // doors hears one instruction rather than two. |
| func purgeAdvice(err error, app string) string { |
| + var held *fleetSeedHoldError |
| switch { |
| + case errors.As(err, &held): |
| + // The hold's backstop in the retirement primitive (the purge |
| + // entrances ask unfinishedFleetFileSeeds first): FS-35. |
| + return fmt.Sprintf(fileSeedPurgeHeldCopy, app, held.Host) |
| case errors.Is(err, release.ErrNotTrashed): |
| return "“" + app + "” is not in the trash, so nothing was deleted. It may have been " + |
| "restored, or already deleted, since this page was loaded." |
diff --git a/internal/console/seedfile.go b/internal/console/seedfile.go| index 3b0e4f82b..4fb7116c3 100644 |
| --- a/internal/console/seedfile.go |
| +++ b/internal/console/seedfile.go |
| @@ -265,6 +265,10 @@ func (s *Server) refuseHASeed(w http.ResponseWriter, rec *provision.Record, kind |
| // goes there (seedSnapshotTarget), and its replica is the fleet's own. |
| func (s *Server) seedStorageRefusal(kind, placement string) *doorRefusal { |
| if _, fleet := registry.FleetPlacement(placement); fleet && kind == seeds.KindFile { |
| + // Defensive only, and unreachable today: every door that reaches |
| + // here has passed instanceGate, which already refuses a console |
| + // with no deployment bucket (apiinstances.go). The import's |
| + // sentence stands in rather than new copy. |
| if s.cfg.Releases == nil { |
| return seedNoDataRefusal() |
| } |
| @@ -591,6 +595,48 @@ func fleetSeedHeldSentence(host string, seed *provision.SeedSource) string { |
| return fmt.Sprintf(fileSeedHeldInStorageCopy, host, where) |
| } |
| +// fleetSeedHoldError is a record retirement refused because the record is |
| +// a fleet file seed whose box has not proved it gone: the hold (fleet |
| +// seeded create design §3.6, Task 16 review P1-1). Msg is the delete |
| +// door's sentence for it (fleetSeedHeldSentence: FS-33, or FS-34 naming |
| +// where the copy is); each door answers it as its own 409, and the purge |
| +// as FS-35. |
| +type fleetSeedHoldError struct { |
| + Host, Msg string |
| +} |
| + |
| +func (e *fleetSeedHoldError) Error() string { |
| + return "console: " + e.Host + " is held by a fleet file seed: " + e.Msg |
| +} |
| + |
| +// fleetSeedHold is the hold's one predicate: nil unless rec is a fleet file |
| +// seed in any state but placed or rolled-back. Rolled-back is reached only |
| +// by the fleet seeds door's rolledback, after the box's proof, so the |
| +// finish (finishSeedOnce) passes and nothing before that proof does. |
| +// |
| +// It is enforced in the record retirement primitives every entrance funnels |
| +// through (retireRecordWithLifetimeLocked, with lifetimes on, and |
| +// retireHostRecord's legacy branch with them off), so an entrance nobody |
| +// listed still cannot release a held hostname. The app purges also ask it |
| +// first, through unfinishedFleetFileSeeds, so they refuse before any |
| +// teardown rather than midway. |
| +func fleetSeedHold(rec *provision.Record) error { |
| + if rec == nil { |
| + return nil |
| + } |
| + return fleetSeedHoldOf(rec.Host, rec.Region, rec.Seed) |
| +} |
| + |
| +// fleetSeedHoldOf is fleetSeedHold asked of a record's three fields, for a |
| +// caller holding only its body (retireLegacyInstanceRecord). |
| +func fleetSeedHoldOf(host, region string, seed *provision.SeedSource) error { |
| + if _, fleet := registry.FleetPlacement(region); !fleet || seed == nil || seed.Kind != seeds.KindFile || |
| + seed.State == seeds.StatePlaced || seed.State == seeds.StateRolledBack { |
| + return nil |
| + } |
| + return &fleetSeedHoldError{Host: host, Msg: fleetSeedHeldSentence(host, seed)} |
| +} |
| + |
| // unfinishedFleetFileSeeds names, sorted, the hosts of sqid/app whose record |
| // is a fleet file seed in any state but placed or rolled-back (plan R1-1): |
| // a hostname its box has not yet proved free (design §3.6). Every entrance |
| @@ -612,7 +658,7 @@ func (s *Server) unfinishedFleetFileSeeds(ctx context.Context, sqid, app string) |
| var hosts []string |
| for i := range recs { |
| rec := &recs[i] |
| - if seedOnFleet(rec) && rec.Seed.State != seeds.StatePlaced && rec.Seed.State != seeds.StateRolledBack { |
| + if fleetSeedHold(rec) != nil { |
| hosts = append(hosts, rec.Host) |
| } |
| } |
| @@ -634,3 +680,13 @@ func (s *Server) fleetSeedPurgeRefusal(ctx context.Context, sqid, app string) (s |
| } |
| return fmt.Sprintf(fileSeedPurgeHeldCopy, app, strings.Join(hosts, ", ")), nil |
| } |
| + |
| +// fleetSeedHoldRefusal is a door's answer to the hold: a 409 with the held |
| +// sentence, and ok, when err is a fleetSeedHoldError. |
| +func fleetSeedHoldRefusal(err error) (*doorRefusal, bool) { |
| + var held *fleetSeedHoldError |
| + if !errors.As(err, &held) { |
| + return nil, false |
| + } |
| + return &doorRefusal{Status: http.StatusConflict, Msg: held.Msg}, true |
| +} |
diff --git a/internal/console/seedholdreview_test.go b/internal/console/seedholdreview_test.go| new file mode 100644 |
| index 000000000..9d90001c4 |
| --- /dev/null |
| +++ b/internal/console/seedholdreview_test.go |
| @@ -0,0 +1,224 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "net/http" |
| + "net/url" |
| + "os" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/domains" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/seeds" |
| +) |
| + |
| +// Task 16 review: the fleet seed hold in one place (P1-1), and the sweep's |
| +// two halves (P2-1, P3-1). |
| + |
| +const holdHost = "woodstar.app" |
| + |
| +// holdWorld is titogo (bab) with lifetimes on or off, a first-route claim on |
| +// woodstar.app (the claim `domains attach` makes), and a fleet file seed's |
| +// record at the same host, created through the seed doors' own create and |
| +// aborted with FS-30 held in the replica: the hostname its box has not yet |
| +// proved free. |
| +func holdWorld(t *testing.T, on bool) (*consoleFixture, string, func(*testing.T) context.Context) { |
| + t.Helper() |
| + clock := useLifetimesClock(t) |
| + fx, member := instanceFixture(t, "code-hold") |
| + if on { |
| + turnLifetimesOn(t, fx.srv, clock) |
| + } |
| + ctxOf := func(t *testing.T) context.Context { |
| + if on { |
| + return onCtx(t, fx.srv) |
| + } |
| + return context.Background() |
| + } |
| + if _, _, err := domains.AttachClaim(context.Background(), fx.rel, domains.Claim{ |
| + Host: holdHost, Account: "bab", App: "titogo", CreatedAt: time.Now().UTC().Format(time.RFC3339), |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + life, err := fx.st.AppLife(OpsAccountID, "titogo") |
| + if err != nil || life == nil { |
| + t.Fatalf("app life: %v %v", life, err) |
| + } |
| + now := time.Now().UTC() |
| + rec := provision.Record{Schema: 1, Host: holdHost, Slug: "woodstar", App: "titogo", Account: "bab", Channel: "edge", |
| + Region: "fleet/pi", CreatedAt: now, |
| + Seed: &provision.SeedSource{ID: newSeedID(t), Kind: seeds.KindFile, State: seeds.StateReady, |
| + SHA256: strings.Repeat("a", 64), Bytes: 4, By: "alice@keymail.dev", At: now}} |
| + if err := fx.srv.createSeedRecord(ctxOf(t), seedCreate{lifetime: life.Lifetime}, rec); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := provision.SetRecordSeed(ctxOf(t), fx.rel, "bab", "titogo", holdHost, |
| + provision.SeedFail(rec.Seed.ID, fileSeedCopyInStorageCopy, provision.SeedHeldReplica)); err != nil { |
| + t.Fatal(err) |
| + } |
| + return fx, member, ctxOf |
| +} |
| + |
| +func holdRecord(t *testing.T, fx *consoleFixture) []byte { |
| + t.Helper() |
| + raw, _, err := fx.rel.Get(context.Background(), provision.RecordKey("bab", "titogo", holdHost)) |
| + if err != nil && !errors.Is(err, os.ErrNotExist) { |
| + t.Fatal(err) |
| + } |
| + return raw |
| +} |
| + |
| +func TestDomainDetachRefusesHeldFleetFileSeed(t *testing.T) { |
| + held := fleetSeedHeldSentence(holdHost, &provision.SeedSource{Reason: fileSeedCopyInStorageCopy, Held: provision.SeedHeldReplica}) |
| + for _, on := range []bool{false, true} { |
| + mode := map[bool]string{false: "lifetimes off", true: "lifetimes on"}[on] |
| + t.Run(mode+", the CLI door", func(t *testing.T) { |
| + fx, member, _ := holdWorld(t, on) |
| + code, _, out := rawReq(t, http.MethodDelete, domainsURL(fx, "bab", "titogo")+"/"+holdHost, member, "") |
| + if code != http.StatusConflict || errorOf(t, out) != held { |
| + t.Fatalf("detach = %d %s, want 409 %q", code, out, held) |
| + } |
| + if holdRecord(t, fx) == nil { |
| + t.Fatal("the detach retired the held seed's record") |
| + } |
| + if _, err := domains.GetClaim(context.Background(), fx.rel, holdHost); err != nil { |
| + t.Fatalf("the claim went: %v", err) |
| + } |
| + }) |
| + t.Run(mode+", the browser door", func(t *testing.T) { |
| + fx, _, _ := holdWorld(t, on) |
| + // The owner: instanceFixture's cliToken left alice signed in. |
| + fx.setUser("paul@keymail.dev") |
| + c := newBrowser(t) |
| + signUp(t, fx, c, "code-paul-detach") |
| + csrf := sessionToken(t, fx, c) |
| + status, _, body := postForm(t, c, fx.ts.URL+"/a/bab/apps/titogo/domains/detach", |
| + url.Values{"csrf": {csrf}, "host": {holdHost}, "confirm": {holdHost}}) |
| + if status != http.StatusConflict || !strings.Contains(body, "woodstar.app keeps its hostname") { |
| + t.Fatalf("detach = %d, want 409 with the held sentence:\n%s", status, body) |
| + } |
| + if holdRecord(t, fx) == nil { |
| + t.Fatal("the detach retired the held seed's record") |
| + } |
| + if _, err := domains.GetClaim(context.Background(), fx.rel, holdHost); err != nil { |
| + t.Fatalf("the claim went: %v", err) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// The primitive itself: retiring a held fleet file seed refuses, whoever |
| +// asks; once the seeds door has moved it to rolled-back (after the box's |
| +// proof), the finish retires it. |
| +func TestRetireRefusesHeldFleetFileSeed(t *testing.T) { |
| + for _, on := range []bool{false, true} { |
| + t.Run(map[bool]string{false: "lifetimes off", true: "lifetimes on"}[on], func(t *testing.T) { |
| + fx, _, ctxOf := holdWorld(t, on) |
| + var held *fleetSeedHoldError |
| + err := fx.srv.retireInstanceRecord(ctxOf(t), "bab", "titogo", holdHost, "test", "", retireAny) |
| + if !errors.As(err, &held) || held.Host != holdHost { |
| + t.Fatalf("retireInstanceRecord = %v, want the hold", err) |
| + } |
| + if on { |
| + err := fx.srv.retireRecordWithLifetime(ctxOf(t), "bab", "titogo", holdHost, retireAny) |
| + if !errors.As(err, &held) { |
| + t.Fatalf("retireRecordWithLifetime = %v, want the hold", err) |
| + } |
| + } |
| + if holdRecord(t, fx) == nil { |
| + t.Fatal("a refused retirement removed the record") |
| + } |
| + rec, _, err := fx.srv.readRecord(ctxOf(t), "bab", "titogo", holdHost) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := provision.SetRecordSeed(ctxOf(t), fx.rel, "bab", "titogo", holdHost, provision.SeedRolledBack(rec.Seed.ID)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := fx.srv.finishSeed(ctxOf(t), "bab", "titogo", holdHost, rec.Seed.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + if holdRecord(t, fx) != nil { |
| + t.Fatal("the finish did not retire the rolled-back seed") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// failingFleetList is the deployment store with a fleet listing that fails. |
| +type failingFleetList struct{ release.Store } |
| + |
| +func (failingFleetList) ListMod(context.Context, string) ([]release.KeyMod, error) { |
| + return nil, errors.New("listing unavailable") |
| +} |
| + |
| +// jobCtx is a context whose jobFailed calls are collected. |
| +func jobCtx() (context.Context, *jobRun) { |
| + run := &jobRun{} |
| + return context.WithValue(context.Background(), jobRunKey{}, run), run |
| +} |
| + |
| +// P2-1: a fleet listing that fails costs only the fleet half. |
| +func TestSeedsPassRegionHalfSurvivesFleetListingFailure(t *testing.T) { |
| + f := newFleetFileFixture(t) |
| + f.fx.srv.cfg.Releases = failingFleetList{Store: f.fx.srv.cfg.Releases} |
| + fleetID := f.fleetSeedRecord(t, fileHost, seeds.StateAborted, "", "", time.Now()) |
| + // A region seed of another app at another host, aborted, with its |
| + // snapshot in the data bucket. |
| + regionID := newSeedID(t) |
| + const regionHost = "region.other.example.com" |
| + if err := provision.CreateRecord(context.Background(), f.fx.rel, provision.Record{Schema: 1, Host: regionHost, Slug: "region", |
| + App: "other", Account: "bab", Channel: "stable", CreatedAt: time.Now().UTC(), |
| + Seed: &provision.SeedSource{ID: regionID, Kind: seeds.KindFile, State: seeds.StateAborted, By: "bob@example.com", At: time.Now()}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + regionKey := seeds.SnapshotKey(regionHost, regionID) |
| + if _, err := f.data.Put(context.Background(), regionKey, []byte("snap"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + ctx, run := jobCtx() |
| + f.fx.srv.seedsPass(ctx, time.Now()) |
| + if _, _, err := f.data.Get(context.Background(), regionKey); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("the region snapshot: %v, want it swept", err) |
| + } |
| + if !f.hasKey(t, fleetSnapshotOf(fileHost, fleetID)) { |
| + t.Fatal("a fleet snapshot was deleted with its listing failed") |
| + } |
| + if run.err == nil || !strings.Contains(run.err.Error(), "fleet seed snapshots") { |
| + t.Fatalf("job error = %v, want the fleet listing's", run.err) |
| + } |
| +} |
| + |
| +// P3-1: a console with no data bucket leaves region seeds alone in steps 4 |
| +// and 6, rather than failing on them every pass. |
| +func TestSeedsPassWithoutSeedDataLeavesRegionSeeds(t *testing.T) { |
| + f := newFleetFileFixture(t) |
| + f.sweepable() |
| + f.fx.srv.cfg.SeedData = nil |
| + now := time.Now() |
| + put := func(host, state string, at time.Time) { |
| + t.Helper() |
| + if err := provision.CreateRecord(context.Background(), f.fx.rel, provision.Record{Schema: 1, Host: host, Slug: "r", |
| + App: "other", Account: "bab", Channel: "stable", CreatedAt: now.UTC(), |
| + Seed: &provision.SeedSource{ID: newSeedID(t), Kind: seeds.KindFile, State: state, By: "bob@example.com", At: at}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + put("stuck.other.example.com", seeds.StateReserving, now.Add(-seedFileReserveTTL-time.Minute)) |
| + put("back.other.example.com", seeds.StateRolledBack, now) |
| + ctx, run := jobCtx() |
| + f.fx.srv.seedsPass(ctx, now) |
| + if run.err != nil { |
| + t.Fatalf("job error = %v, want none", run.err) |
| + } |
| + for host, want := range map[string]string{"stuck.other.example.com": seeds.StateReserving, "back.other.example.com": seeds.StateRolledBack} { |
| + rec, err := provision.GetRecord(context.Background(), f.fx.rel, "bab", "other", host) |
| + if err != nil || rec.Seed.State != want { |
| + t.Fatalf("%s = %+v %v, want %s", host, rec.Seed, err, want) |
| + } |
| + } |
| +} |
diff --git a/internal/console/seedsweep.go b/internal/console/seedsweep.go| index da9ec573d..35cee7149 100644 |
| --- a/internal/console/seedsweep.go |
| +++ b/internal/console/seedsweep.go |
| @@ -181,13 +181,20 @@ func (s *Server) seedsPass(ctx context.Context, now time.Time) { |
| } |
| } |
| } |
| + // The fleet half's listing is its own (Task 16 review P2-1): one that |
| + // fails leaves this pass with no fleet snapshot to decide on, so none |
| + // is deleted, and the region half carries on. |
| fleet, err := s.fleetSeedSnapshots(ctx) |
| if err != nil { |
| - log.Printf("console: seeds pass: list fleet seed snapshots: %v (nothing swept this pass)", err) |
| - jobFailed(ctx, fmt.Errorf("seeds pass: list fleet seed snapshots: %w (nothing swept this pass)", err)) |
| - return |
| + log.Printf("console: seeds pass: list fleet seed snapshots: %v (no fleet seed's snapshot swept this pass)", err) |
| + jobFailed(ctx, fmt.Errorf("seeds pass: list fleet seed snapshots: %w (no fleet seed's snapshot swept this pass)", err)) |
| + fleet = nil |
| } |
| snaps = append(snaps, fleet...) |
| + // A console with no data bucket runs the fleet half alone (review |
| + // P3-1): a region seed's abandonment and finish need that bucket, and |
| + // would fail every pass, so steps 4 and 6 leave region seeds alone. |
| + regionHalf := s.cfg.SeedData != nil |
| if seedsPassBetweenListings != nil { |
| seedsPassBetweenListings() |
| } |
| @@ -255,7 +262,7 @@ func (s *Server) seedsPass(ctx context.Context, now time.Time) { |
| if ctx.Err() != nil { |
| return |
| } |
| - if !seedStale(rec.Seed, now) || held(rec.Host) { |
| + if !seedStale(rec.Seed, now) || held(rec.Host) || !regionHalf && !seedOnFleet(&rec) { |
| continue |
| } |
| if s.abandonSeed(ctx, rec) { |
| @@ -284,7 +291,7 @@ func (s *Server) seedsPass(ctx context.Context, now time.Time) { |
| if ctx.Err() != nil { |
| return |
| } |
| - if rec.Seed == nil || rec.Seed.State != seeds.StateRolledBack || held(rec.Host) { |
| + if rec.Seed == nil || rec.Seed.State != seeds.StateRolledBack || held(rec.Host) || !regionHalf && !seedOnFleet(&rec) { |
| continue |
| } |
| if err := s.finishSeed(ctx, rec.Account, rec.App, rec.Host, rec.Seed.ID); err != nil { |
diff --git a/internal/provision/fleet_seeded_create_3_census_test.go b/internal/provision/fleet_seeded_create_3_census_test.go| index c442f1180..b0012b5bb 100644 |
| --- a/internal/provision/fleet_seeded_create_3_census_test.go |
| +++ b/internal/provision/fleet_seeded_create_3_census_test.go |
| @@ -6,7 +6,8 @@ package provision |
| // fleetSeededCreate2WriteCensusInventory (main's newest at origin/main |
| // 772aabbb0, the slice 2 merge). |
| // Reviewed by the branch author against the source. No class or site kind |
| -// changes; one unit is new, two tables and four seed units are re-pinned. |
| +// changes; two units are new, two tables, four seed units and one |
| +// retirement primitive are re-pinned. |
| // |
| // New (Task 15, the fleet seeds door): |
| // |
| @@ -51,6 +52,18 @@ package provision |
| // needed), and its replica is never touched (the fleet's own, proved |
| // gone by its box). The record delete, by CAS or retirement, as before. |
| // |
| +// The fleet seed hold in one place (Task 16 review P1-1): |
| +// - Server.retireRecordWithLifetimeLocked (console, re-pinned): before |
| +// any retirement step, under the app and hostname locks, a record that |
| +// is a fleet file seed neither placed nor rolled-back is refused with |
| +// fleetSeedHoldError (fleetSeedHold). Its record-key sites are |
| +// unchanged. key-site / key:RecordKey, as before. |
| +// - Server.retireLegacyInstanceRecord (console, new): retireHostRecord's |
| +// claims-off, lifetimes-off instance branch. It reads the record's body |
| +// (a Get of RecordKey), asks the same hold of its region and seed, and |
| +// then retires through provision.RetireRecord exactly as before. It |
| +// writes nothing itself. key-site / key:RecordKey. |
| +// |
| // Not in the inventory, because they write no record: seedFleetReady, |
| // fleetSeedSnapshots (the sweep's fleet listing; the sweep's own record |
| // write stays in abandonSeed), unfinishedFleetFileSeeds and |
| @@ -69,6 +82,7 @@ func fleetSeededCreate3WriteCensusInventory() []censusEntry { |
| {"internal/console/apiinstanceimport.go", "Server.runImportUpload", "record-writer", "key:SetRecordSeed", "051483202bca1a0af137b0181cf5c7e59c71c0c79511ef501e0f35ea1428e805"}, |
| {"internal/console/seedfile.go", "Server.fileSeedDeleteRule", "record-writer", "key:SetRecordSeed", "c3872951d6f0f0a469eb93828843153c023a408df8672a7e11c08cb1c8937d6b"}, |
| {"internal/console/seedfinish.go", "Server.finishSeedOnce", "key-site", "key:RecordKey", "f5da4e619ec229aef9ae9559cf347b62dbd6e0556b325d5ca6ad8f56c09f859d"}, |
| + {"internal/console/lifetimes_retire.go", "Server.retireRecordWithLifetimeLocked", "key-site", "key:RecordKey", "16ba61287735836465c84ef20a36b43ec6896faccaa985cfe5b09388cce0ae57"}, |
| } { |
| replaced := false |
| for i, e := range entries { |
| @@ -85,6 +99,7 @@ func fleetSeededCreate3WriteCensusInventory() []censusEntry { |
| } |
| } |
| return append(entries, |
| + censusEntry{"internal/console/hostclaimops.go", "Server.retireLegacyInstanceRecord", "key-site", "key:RecordKey", "df655a77aa25b47e06185d3127b539c8b32257c42ec2e71c61393498c2bda34b"}, |
| censusEntry{"internal/console/apifleetseeds.go", "Server.fleetSeedTransition", "record-writer", "key:SetRecordSeed", "360d42934163d3d07225d927ac7fee6fdd40a6d9d86658a829b587450dee3f7a"}, |
| ) |
| } |