carlos / platform Public

ops: drill every family with a drill-side identity bracket (#898)

Final fix wave items 1 and 2 (Astra P1, Fable P1, Fable P2-2).

- captureDrillIdentity / confirmDrillIdentity identify a host by its own
  family's record: instances/<host>.json, or sidecars/<name>.json for a
  sidecar route, with none of the db door's class refusals (no sleep,
  pooled, fleet-placed, kind, own address). dbreads.CaptureIdentity is
  unchanged for db reads.
- no_record when the record is missing in its family, names another
  host, or places the host outside this box's region; record_changed is
  now only a difference between open and close (or a record gone
  mid-run). A record in another region was record_changed; it is
  no_record now (conservative: holds the streak, leaves coverage).
- A fleet box's CARLOS_REGION is its placement (fleet/<name>): the run
  accepts it, so fleet-placed hosts are drilled at all.
- Group boxes drill their non-HA rows locally; the assignment decides HA
  rows only, so a non-HA row is never no_assignment.
- HibernatingRoute carries Sidecar and HA.
- Tests: sidecar, resident rootfs, pooled and fleet-placed records end
  to end through hibernateRun.run; no_record cases; the sidecar bracket;
  the db read rule still refuses a resident; group non-HA rows; the
  fleet row in identity_test.go asks in fleet/acme so only the fleet
  guard can refuse it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 2ba48242917238e0ea4bde9881b81d2b5ed927f7 parent c6ce7af
6 files changed, +448 −27
  • internal/dbreads/identity_test.go +4 −2
  • internal/ops/drillidentity.go +133 −0
  • internal/ops/hibernate_verify.go +29 −19
  • internal/ops/hibernate_verify_families_test.go +269 −0
  • internal/ops/hibernate_verify_test.go +9 −4
  • internal/ops/ops.go +4 −2
diff --git a/internal/dbreads/identity_test.go b/internal/dbreads/identity_test.go
index 32de6631c..1b57f071f 100644
--- a/internal/dbreads/identity_test.go
+++ b/internal/dbreads/identity_test.go
@@ -21,7 +21,9 @@ func (fx *fixture) identity() Identity {
}
// CaptureIdentity reads the record fresh and refuses anything the platform
-// keeps no database copy for, or that is not where it was asked for.
+// keeps no database copy for, or that is not where it was asked for. The
+// fleet row asks in the record's own region, so only the fleet guard can
+// refuse it.
func TestCaptureIdentityRefusals(t *testing.T) {
t.Parallel()
const badHost = "bad_host.example.com"
@@ -42,7 +44,7 @@ func TestCaptureIdentityRefusals(t *testing.T) {
"another region": {func(fx *fixture) { r := fx.record(); r.Region = "ie"; fx.putRecord(r) }, asked, CodeRecordChanged},
"asked another": {func(*fixture) {}, ask{"ie", fxAccount, fxApp, fxHost}, CodeRecordChanged},
"pooled": {func(fx *fixture) { r := fx.record(); r.Pool = "shared"; fx.putRecord(r) }, asked, CodeRecordChanged},
- "placed on a fleet": {func(fx *fixture) { r := fx.record(); r.Region = "fleet/acme"; fx.putRecord(r) }, asked, CodeRecordChanged},
+ "placed on a fleet": {func(fx *fixture) { r := fx.record(); r.Region = "fleet/acme"; fx.putRecord(r) }, ask{"fleet/acme", fxAccount, fxApp, fxHost}, CodeRecordChanged},
"does not sleep": {func(fx *fixture) { r := fx.record(); r.Hibernate = &no; fx.putRecord(r) }, asked, CodeRecordChanged},
"not an instance": {func(fx *fixture) { r := fx.record(); r.Kind = "static"; fx.putRecord(r) }, asked, CodeRecordChanged},
"own address": {func(fx *fixture) { r := fx.record(); r.Addr = "10.0.0.1:8080"; fx.putRecord(r) }, asked, CodeRecordChanged},
diff --git a/internal/ops/drillidentity.go b/internal/ops/drillidentity.go
new file mode 100644
index 000000000..28da68058
--- /dev/null
+++ b/internal/ops/drillidentity.go
@@ -0,0 +1,133 @@
+package ops
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "os"
+ "strings"
+ "time"
+
+ "github.com/carlosframework/platform/internal/dbreads"
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// The drill's identity bracket (member backups slice 2a, final fix wave).
+//
+// dbreads.CaptureIdentity is the db door's rule: it refuses every class the
+// platform does not offer member reads for (a record that does not sleep,
+// a pooled or fleet-placed record, a non-instance kind). The drill must not
+// share those refusals: it tests every database the activator replicates,
+// which is every family HibernatingHosts selects (hibernating instances,
+// resident rootfs instances, hibernating sidecars, on any pool or fleet).
+// Refusing any of them would leave it undrilled and alerting forever. So
+// the drill identifies a host by its own family's record, here, and keeps
+// only the rules that make a verdict mean "this instance's copy": the
+// record exists, names this host, places it in this box's region, and is
+// not mid-move.
+
+// codeNoRecord is captureDrillIdentity's code for a host with no record of
+// its family in this box's region: there is no instance here to bind a
+// test to. The drill records it unverified, no_record, which holds the
+// streak and leaves coverage.
+const codeNoRecord = "no-record"
+
+// drillRecord is what the bracket reads from a host's record, whatever its
+// family.
+type drillRecord struct {
+ account, app, host, region string
+ created time.Time
+ moving bool
+}
+
+// captureDrillIdentity is the opening half of the drill's bracket: the
+// host's record read fresh (an instance's at instances/<host>.json, a
+// sidecar's at sidecars/<name>.json) and its identity, or a code:
+// codeNoRecord when there is no record of the family, it names another
+// host, or it places the host outside region (on a fleet box, region is
+// its placement); dbreads.CodeMoving, with the identity, when the instance
+// is mid-move. detail says why for a code. err is a record that could not
+// be read or whose identity cannot be computed.
+func captureDrillIdentity(ctx context.Context, s release.Store, region string, rt HibernatingRoute) (id dbreads.Identity, code, detail string, err error) {
+ rec, detail, err := readDrillRecord(ctx, s, rt)
+ if err != nil || detail != "" {
+ if detail != "" {
+ return dbreads.Identity{}, codeNoRecord, detail, nil
+ }
+ return dbreads.Identity{}, "", "", err
+ }
+ if rec.region != region {
+ return dbreads.Identity{}, codeNoRecord,
+ fmt.Sprintf("its record places it in %q, not this box's %q", rec.region, region), nil
+ }
+ inc, err := provision.Incarnation(rec.account, rec.app, rec.host, rec.created)
+ if err != nil {
+ return dbreads.Identity{}, "", "", fmt.Errorf("the record's identity: %w", err)
+ }
+ id = dbreads.Identity{Account: rec.account, App: rec.app, Host: rec.host, Region: region, Incarnation: inc}
+ if rec.moving {
+ return id, dbreads.CodeMoving, "", nil
+ }
+ return id, "", "", nil
+}
+
+// confirmDrillIdentity is the closing half: captureDrillIdentity again for
+// want's host, and dbreads.CodeRecordChanged unless it finds want. A record
+// that has gone (or left this region) since the bracket opened is
+// CodeRecordChanged, never codeNoRecord, and a change outranks a move.
+func confirmDrillIdentity(ctx context.Context, s release.Store, rt HibernatingRoute, want dbreads.Identity) (code string, err error) {
+ got, code, _, err := captureDrillIdentity(ctx, s, want.Region, rt)
+ switch {
+ case err != nil:
+ return "", err
+ case code == codeNoRecord, got != want:
+ return dbreads.CodeRecordChanged, nil
+ }
+ return code, nil
+}
+
+// readDrillRecord reads rt's record from its family. A host with none, or
+// whose record names another host, is a detail saying so and no error.
+func readDrillRecord(ctx context.Context, s release.Store, rt HibernatingRoute) (drillRecord, string, error) {
+ if !rt.Sidecar {
+ rec, err := provision.GetRecord(ctx, s, rt.Account, rt.App, rt.Host)
+ if errors.Is(err, os.ErrNotExist) {
+ return drillRecord{}, "this box has the host, but there is no instance record for it", nil
+ }
+ if err != nil {
+ return drillRecord{}, "", err
+ }
+ return drillRecord{account: rec.Account, app: rec.App, host: rec.Host, region: rec.Region,
+ created: rec.CreatedAt, moving: rec.Move != nil}, "", nil
+ }
+ name, ok := sidecarName(rt.Host)
+ if !ok {
+ return drillRecord{}, "this box has a sidecar route whose host names no sidecar", nil
+ }
+ rec, err := provision.GetSidecarRecord(ctx, s, rt.Account, rt.App, name)
+ if errors.Is(err, os.ErrNotExist) {
+ return drillRecord{}, "this box has the sidecar, but there is no sidecar record for it", nil
+ }
+ if err != nil {
+ return drillRecord{}, "", err
+ }
+ if rec.Host != rt.Host {
+ return drillRecord{}, fmt.Sprintf("the sidecar record %q names host %q, not this one", name, rec.Host), nil
+ }
+ return drillRecord{account: rec.Account, app: rec.App, host: rec.Host, region: rec.Region, created: rec.CreatedAt}, "", nil
+}
+
+// sidecarName is the sidecar name a sidecar host carries, its first label
+// (provision.SidecarHost: <name>.<app>.<sqid><SidecarSuffix>).
+func sidecarName(host string) (string, bool) {
+ rest, ok := strings.CutSuffix(host, provision.SidecarSuffix)
+ if !ok {
+ return "", false
+ }
+ name, _, ok := strings.Cut(rest, ".")
+ if !ok || !provision.ValidSidecarName(name) {
+ return "", false
+ }
+ return name, true
+}
diff --git a/internal/ops/hibernate_verify.go b/internal/ops/hibernate_verify.go
index d8cb36454..b8b911a7d 100644
--- a/internal/ops/hibernate_verify.go
+++ b/internal/ops/hibernate_verify.go
@@ -46,11 +46,16 @@ import (
// different questions and the second one needs the source. Account and App
// name the instance's provision record, which the identity bracket reads:
// Account as the record files it (a route's "" is the ops account).
+// Sidecar says the record is a sidecar's (sidecars/<name>.json), not an
+// instance's. HA says a group box's drill assignment decides who drills
+// it; a non-HA row is drilled by the box that holds it.
type HibernatingRoute struct {
Host string
DBPath string
Account string
App string
+ Sidecar bool
+ HA bool
}
// HibernatingHosts lists the routes whose replication the activator owns —
@@ -73,7 +78,7 @@ func HibernatingHosts(reg *registry.Registry) ([]HibernatingRoute, error) {
// rootfs row is drilled here, never by box-wide litestream.
if !r.Stateless && r.ActivatorLeased() && r.DBPath != "" {
hosts = append(hosts, HibernatingRoute{Host: r.Host, DBPath: r.DBPath,
- Account: registry.EffectiveAccount(r.Account), App: r.App})
+ Account: registry.EffectiveAccount(r.Account), App: r.App, Sidecar: r.IsSidecar(), HA: r.HA})
}
}
sort.Slice(hosts, func(i, j int) bool { return hosts[i].Host < hosts[j].Host })
@@ -83,8 +88,9 @@ func HibernatingHosts(reg *registry.Registry) ([]HibernatingRoute, error) {
// The reasons the drill gives a failed or unverified verdict, besides
// dbverify's own not_reached and no_assignment.
const (
- // ReasonRecordChanged: the instance's record was missing, refused, or
- // named another instance when the bracket opened or closed.
+ // ReasonRecordChanged: the instance's record changed between the
+ // bracket's open and close: it went, left this box's region, or names
+ // another incarnation.
ReasonRecordChanged = "record_changed"
// ReasonMoving: the instance was mid-move when the bracket opened or
// closed.
@@ -327,7 +333,7 @@ func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() tim
return v, true
}
- id, rec, code, err := dbreads.CaptureIdentity(ctx, d.Store, d.Region, rt.Account, rt.App, rt.Host)
+ id, code, detail, err := captureDrillIdentity(ctx, d.Store, d.Region, rt)
if err != nil {
if ctx.Err() != nil {
return dbverify.Verdict{}, false
@@ -335,14 +341,14 @@ func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() tim
return unverified(ReasonRecordUnreadable, err.Error())
}
v.Identity = dbverify.Identity(id)
- if code == dbreads.CodeRecordChanged && rec.Host == "" {
- // No record at all when the test began (CaptureIdentity's zero
- // record): there is no instance to bind a test to. It holds the
- // streak, unlike a record that refuses or changes.
- return unverified(dbverify.ReasonNoRecord, "this box has the host, but there is no instance record for it")
- }
- if code != "" {
- return unverified(bracketReason(code), "the instance's record refused the test when it began")
+ switch code {
+ case codeNoRecord:
+ // No record of the host's family in this region when the test
+ // began: there is no instance here to bind a test to. It holds the
+ // streak and leaves coverage.
+ return unverified(dbverify.ReasonNoRecord, detail)
+ case dbreads.CodeMoving:
+ return unverified(ReasonMoving, "the instance was moving when the test began")
}
// Each host restores into its own scratch directory, removed whatever
@@ -372,7 +378,7 @@ func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() tim
}
}
- _, code, err = dbreads.ConfirmIdentity(ctx, d.Store, id)
+ code, err = confirmDrillIdentity(ctx, d.Store, rt, id)
if err != nil {
if ctx.Err() != nil {
return dbverify.Verdict{}, false
@@ -494,13 +500,15 @@ type drillSet struct {
}
// selectHosts picks this run's hosts (P-9, P2-9). A fixed box drills every
-// local sleeping host. A group box reads its assignment once, here, and
-// keeps it for the whole run (F2-6); it drills the hosts assigned to its
-// own reference. A host listed unknown, one in neither the assigned nor
-// the unknown list, and every host when the assignment is missing,
+// local sleeping host. A group box drills its non-HA hosts the same way:
+// the assignment covers HA rows only, and a non-HA row is on this box
+// alone. For its HA hosts it reads its assignment once, here, and keeps it
+// for the whole run (F2-6); it drills the HA hosts assigned to its own
+// reference. An HA host listed unknown, one in neither the assigned nor
+// the unknown list, and every HA host when the assignment is missing,
// unreadable or older than assignmentMaxAge, is recorded no_assignment, so
-// coverage alerts still see it (F2-1). why says what made the assignment
-// unusable, "" when it was usable or not needed.
+// alerts still see it (F2-1). why says what made the assignment unusable,
+// "" when it was usable or not needed.
func selectHosts(self boxself.Self, dataDir string, now time.Time, hosts []HibernatingRoute, hibPrefix string) (set drillSet, why string) {
set.NoAssignment = map[string]dbverify.Verdict{}
if !self.Group {
@@ -525,6 +533,8 @@ func selectHosts(self boxself.Self, dataDir string, now time.Time, hosts []Hiber
for _, h := range hosts {
ref, assigned := a.Hosts[h.Host]
switch {
+ case !h.HA:
+ set.Drill = append(set.Drill, h)
case why == "" && !unknown[h.Host] && assigned && ref == self.Ref:
set.Drill = append(set.Drill, h)
case why == "" && !unknown[h.Host] && assigned:
diff --git a/internal/ops/hibernate_verify_families_test.go b/internal/ops/hibernate_verify_families_test.go
new file mode 100644
index 000000000..800a4eb2f
--- /dev/null
+++ b/internal/ops/hibernate_verify_families_test.go
@@ -0,0 +1,269 @@
+package ops
+
+import (
+ "context"
+ "encoding/json"
+ "path/filepath"
+ "slices"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/dbreads"
+ "github.com/carlosframework/platform/internal/dbverify"
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
+)
+
+// The families HibernatingHosts selects, and the drill-side identity rule
+// that binds each to its own record (final fix wave, item 1): the bracket
+// identifies a host by its family's record, with none of the member-facing
+// class refusals dbreads.CaptureIdentity keeps for db reads.
+
+const fxSidecarSqid = "k3x9"
+
+var fxCreated = time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC)
+
+// putSidecar writes the sidecar record name in fxAccount/fxApp, for host,
+// in fxRegion unless mutate says otherwise.
+func (fx *drillFx) putSidecar(name, host string, created time.Time, mutate func(*provision.SidecarRecord)) {
+ fx.t.Helper()
+ rec := provision.SidecarRecord{Schema: 1, Name: name, Host: host, App: fxApp, Account: fxAccount,
+ Region: fxRegion, CreatedAt: created}
+ if mutate != nil {
+ mutate(&rec)
+ }
+ body, err := json.Marshal(rec)
+ if err != nil {
+ fx.t.Fatal(err)
+ }
+ key := provision.SidecarRecordKey(fxAccount, fxApp, name)
+ if err := fx.store.Delete(context.Background(), key); err != nil {
+ fx.t.Fatal(err)
+ }
+ if _, err := fx.store.Put(context.Background(), key, body, ""); err != nil {
+ fx.t.Fatal(err)
+ }
+}
+
+func (fx *drillFx) deleteSidecar(name string) {
+ fx.t.Helper()
+ if err := fx.store.Delete(context.Background(), provision.SidecarRecordKey(fxAccount, fxApp, name)); err != nil {
+ fx.t.Fatal(err)
+ }
+}
+
+// idFor is the identity a record with these fields binds a verdict to.
+func idFor(t *testing.T, host, region string, created time.Time) dbverify.Identity {
+ t.Helper()
+ inc, err := provision.Incarnation(fxAccount, fxApp, host, created)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return dbverify.Identity{Account: fxAccount, App: fxApp, Host: host, Region: region, Incarnation: inc}
+}
+
+// addRoute puts rt in the run fixture's registry.
+func (fx *runFx) addRoute(rt registry.Route) {
+ fx.t.Helper()
+ reg, err := registry.Open(fx.regPath)
+ if err != nil {
+ fx.t.Fatal(err)
+ }
+ defer reg.Close()
+ if rt.DBPath == "" {
+ rt.DBPath = filepath.Join(fx.dataDir, rt.Host+".db")
+ }
+ if rt.Account == "" {
+ rt.Account = fxAccount
+ }
+ if rt.App == "" {
+ rt.App = fxApp
+ }
+ if err := reg.Upsert(rt); err != nil {
+ fx.t.Fatal(err)
+ }
+}
+
+// TestDrillsEveryFamilyEndToEnd: a hibernating sidecar (its record under
+// sidecars/), a resident rootfs instance (Hibernate=false), a pooled
+// instance and, on a fleet box, a fleet-placed instance are each drilled
+// through the whole run and pass, bound to their own record's identity.
+// Before this rule the bracket refused all four (Astra P1, Fable P1).
+func TestDrillsEveryFamilyEndToEnd(t *testing.T) {
+ sidecarHost := provision.SidecarHost("worker", fxApp, fxSidecarSqid)
+ const (
+ resident = "resident.example.com"
+ pooled = "pooled.example.com"
+ plain = "plain.example.com"
+ )
+ t.Run("regional box", func(t *testing.T) {
+ fx := newRunFx(t, plain)
+ fx.writeSelf(fxSelf, false)
+ no := false
+ fx.putRecord(fxAccount, resident, fxCreated, func(r *provision.Record) { r.Hibernate = &no })
+ fx.putRecord(fxAccount, pooled, fxCreated, func(r *provision.Record) { r.Pool = "shared" })
+ fx.putSidecar("worker", sidecarHost, fxCreated, nil)
+ fx.addRoute(registry.Route{Host: resident, Kind: "instance", Runtime: registry.RuntimeRootfsV1})
+ fx.addRoute(registry.Route{Host: pooled, Kind: "instance", Hibernate: true, Pool: "shared"})
+ fx.addRoute(registry.Route{Host: sidecarHost, Kind: provision.SidecarKind, Slug: "worker", Hibernate: true})
+
+ var drilled []string
+ fx.stubVerify(func(_ context.Context, prefix, _ string, _ uint64) (uint32, error) {
+ drilled = append(drilled, filepath.Base(prefix))
+ return 1, nil
+ })
+ if code := fx.runner().run(context.Background()); code != 0 {
+ t.Fatalf("exited %d: %s", code, fx.logs)
+ }
+ rec := fx.published(fxSelf)
+ want := []string{plain, pooled, resident, sidecarHost}
+ slices.Sort(want)
+ slices.Sort(drilled)
+ if !slices.Equal(drilled, want) || !slices.Equal(sortedHosts(rec), want) {
+ t.Fatalf("drilled %v, published %v; want %v", drilled, sortedHosts(rec), want)
+ }
+ for _, h := range want {
+ v := rec.Hosts[h]
+ if !v.OK() || v.Identity != idFor(t, h, fxRegion, fxCreated) {
+ t.Errorf("%s: %+v, want passed, bound to %+v", h, v, idFor(t, h, fxRegion, fxCreated))
+ }
+ }
+ })
+ t.Run("fleet box", func(t *testing.T) {
+ const placement = "fleet/acme"
+ fx := newRunFx(t)
+ fx.writeSelf(fxSelf, false)
+ fx.putRecord(fxAccount, plain, fxCreated, func(r *provision.Record) { r.Region = placement })
+ fx.putSidecar("worker", sidecarHost, fxCreated, func(r *provision.SidecarRecord) { r.Region = placement })
+ fx.addRoute(registry.Route{Host: plain, Kind: "instance", Hibernate: true, Region: placement})
+ fx.addRoute(registry.Route{Host: sidecarHost, Kind: provision.SidecarKind, Slug: "worker", Hibernate: true, Region: placement})
+ r := fx.runner()
+ r.Region = placement // a fleet box's CARLOS_REGION is its placement
+ if code := r.run(context.Background()); code != 0 {
+ t.Fatalf("exited %d: %s", code, fx.logs)
+ }
+ rec := fx.published(fxSelf)
+ for _, h := range []string{plain, sidecarHost} {
+ if v := rec.Hosts[h]; !v.OK() || v.Identity != idFor(t, h, placement, fxCreated) {
+ t.Errorf("%s: %+v, want passed, bound to the fleet placement", h, v)
+ }
+ }
+ })
+}
+
+// A route whose record exists in no family, or whose record places the
+// instance outside this box's region, is no_record when the bracket opens:
+// nothing is planned, the streak holds, and coverage leaves it out. None
+// of the member-facing class refusals turns a host away any more.
+func TestDrillNoRecordIsTheOnlyStandingRefusal(t *testing.T) {
+ sidecarHost := provision.SidecarHost("worker", fxApp, fxSidecarSqid)
+ orphanSidecar := provision.SidecarHost("gone", fxApp, fxSidecarSqid)
+ otherHost := provision.SidecarHost("named", fxApp, fxSidecarSqid)
+ fx := newDrillFx(t, "elsewhere.example.com", "static.example.com", "addr.example.com")
+ fx.putRecord(fxAccount, "elsewhere.example.com", fxCreated, func(r *provision.Record) { r.Region = "ie" })
+ // Classes the db door refuses, which the drill does not.
+ fx.putRecord(fxAccount, "static.example.com", fxCreated, func(r *provision.Record) { r.Kind = "static" })
+ fx.putRecord(fxAccount, "addr.example.com", fxCreated, func(r *provision.Record) { r.Addr = "10.0.0.1:8080" })
+ fx.putSidecar("worker", sidecarHost, fxCreated, func(r *provision.SidecarRecord) { r.Region = "ie" })
+ fx.putSidecar("named", "someone-else.sidecar.internal", fxCreated, nil)
+ planned := map[string]bool{}
+ fx.stubVerify(func(_ context.Context, prefix, _ string, _ uint64) (uint32, error) {
+ planned[filepath.Base(prefix)] = true
+ return 1, nil
+ })
+ routes := fx.routes("elsewhere.example.com", "static.example.com", "addr.example.com", "nothing.example.com")
+ for _, h := range []string{sidecarHost, orphanSidecar, otherHost} {
+ routes = append(routes, HibernatingRoute{Host: h, Account: fxAccount, App: fxApp, Sidecar: true})
+ }
+ got := fx.run(context.Background(), fx.drill(), routes, nil)
+ for _, h := range []string{"elsewhere.example.com", "nothing.example.com", sidecarHost, orphanSidecar, otherHost} {
+ if v := got[h]; !v.Unverified() || v.Reason != dbverify.ReasonNoRecord || planned[h] {
+ t.Errorf("%s: %+v (restored %v), want no_record and no restore", h, v, planned[h])
+ }
+ }
+ for _, h := range []string{"static.example.com", "addr.example.com"} {
+ if v := got[h]; !v.OK() {
+ t.Errorf("%s: %+v, want passed: the drill keeps no class refusal", h, v)
+ }
+ }
+}
+
+// A sidecar whose record changes between the bracket's open and close is
+// record_changed, as an instance's is: deleted, or recreated (a new
+// incarnation). record_changed is only ever that difference.
+func TestDrillSidecarBracket(t *testing.T) {
+ host := provision.SidecarHost("worker", fxApp, fxSidecarSqid)
+ for name, change := range map[string]func(fx *drillFx){
+ "deleted": func(fx *drillFx) { fx.deleteSidecar("worker") },
+ "recreated": func(fx *drillFx) { fx.putSidecar("worker", host, fxCreated.Add(time.Hour), nil) },
+ "placed elsewhere": func(fx *drillFx) {
+ fx.putSidecar("worker", host, fxCreated, func(r *provision.SidecarRecord) { r.Region = "ie" })
+ },
+ } {
+ t.Run(name, func(t *testing.T) {
+ fx := newDrillFx(t)
+ fx.putSidecar("worker", host, fxCreated, nil)
+ fx.stubVerify(func(context.Context, string, string, uint64) (uint32, error) {
+ change(fx)
+ return 1, nil
+ })
+ rt := []HibernatingRoute{{Host: host, Account: fxAccount, App: fxApp, Sidecar: true}}
+ v := fx.run(context.Background(), fx.drill(), rt, nil)[host]
+ if !v.Unverified() || v.Reason != ReasonRecordChanged || v.Identity != idFor(t, host, fxRegion, fxCreated) {
+ t.Fatalf("verdict %+v, want record_changed bound to the opened identity", v)
+ }
+ })
+ }
+}
+
+// The drill's capture never consults dbreads' class rail, which still
+// refuses the same records for db reads: the two rules stay apart.
+func TestDrillIdentityLeavesTheDbReadRuleAlone(t *testing.T) {
+ fx := newDrillFx(t)
+ no := false
+ fx.putRecord(fxAccount, "resident.example.com", fxCreated, func(r *provision.Record) { r.Hibernate = &no })
+ _, _, code, err := dbreads.CaptureIdentity(context.Background(), fx.store, fxRegion, fxAccount, fxApp, "resident.example.com")
+ if err != nil || code != dbreads.CodeRecordChanged {
+ t.Fatalf("dbreads.CaptureIdentity = %q, %v; the db read rule must still refuse a resident", code, err)
+ }
+ id, code, _, err := captureDrillIdentity(context.Background(), fx.store, fxRegion,
+ HibernatingRoute{Host: "resident.example.com", Account: fxAccount, App: fxApp})
+ if err != nil || code != "" || dbverify.Identity(id) != idFor(t, "resident.example.com", fxRegion, fxCreated) {
+ t.Fatalf("captureDrillIdentity = %+v, %q, %v", id, code, err)
+ }
+}
+
+// On a group box the assignment covers HA rows only. A non-HA row on the
+// box is this box's alone, so it is drilled here as on a fixed box, never
+// no_assignment, with or without a usable assignment (Fable P2-2).
+func TestVerifyHibernatingGroupDrillsLocalNonHA(t *testing.T) {
+ for name, write := range map[string]func(fx *runFx){
+ "usable assignment": func(fx *runFx) {
+ fx.writeAssignment(fx.clock.Now(), map[string]string{"ha.example.com": "box-b"})
+ },
+ "missing assignment": func(*runFx) {},
+ } {
+ t.Run(name, func(t *testing.T) {
+ fx := newRunFx(t, "ha.example.com")
+ fx.putRecord(fxAccount, "local.example.com", fxCreated, nil)
+ fx.addRoute(registry.Route{Host: "local.example.com", Kind: "instance", Hibernate: true})
+ fx.writeSelf(fxSelf, true)
+ write(fx)
+ var drilled []string
+ fx.stubVerify(func(_ context.Context, prefix, _ string, _ uint64) (uint32, error) {
+ drilled = append(drilled, filepath.Base(prefix))
+ return 1, nil
+ })
+ if code := fx.runner().run(context.Background()); code != 0 {
+ t.Fatalf("exited %d: %s", code, fx.logs)
+ }
+ if !slices.Equal(drilled, []string{"local.example.com"}) {
+ t.Fatalf("drilled %v, want the local non-HA host alone", drilled)
+ }
+ rec := fx.published(fxSelf)
+ if v := rec.Hosts["local.example.com"]; !v.OK() {
+ t.Fatalf("local non-HA host: %+v", v)
+ }
+ })
+ }
+}
diff --git a/internal/ops/hibernate_verify_test.go b/internal/ops/hibernate_verify_test.go
index a765e35cd..00f01cd20 100644
--- a/internal/ops/hibernate_verify_test.go
+++ b/internal/ops/hibernate_verify_test.go
@@ -672,7 +672,8 @@ func TestVerifyHibernatingBracket(t *testing.T) {
}
}
-// A record that already refuses when the bracket opens is not drilled.
+// A host the bracket cannot open on (mid-move, in another region, retired
+// or missing) is not drilled.
func TestVerifyHibernatingRefusesBeforePlanning(t *testing.T) {
fx := newDrillFx(t, "moving.example.com", "elsewhere.example.com", "retired.example.com")
fx.putRecord(fxAccount, "moving.example.com", time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC), func(r *provision.Record) {
@@ -697,8 +698,10 @@ func TestVerifyHibernatingRefusesBeforePlanning(t *testing.T) {
if v := got["moving.example.com"]; v.Reason != ReasonMoving || !v.Unverified() || v.Identity.Host != "moving.example.com" {
t.Fatalf("moving: %+v", v)
}
- if v := got["elsewhere.example.com"]; v.Reason != ReasonRecordChanged || !v.Unverified() {
- t.Fatalf("a record that refuses: %+v, want record_changed", v)
+ // A record that places the instance in another region is no record of
+ // it here: record_changed is only a change between open and close.
+ if v := got["elsewhere.example.com"]; v.Reason != dbverify.ReasonNoRecord || !v.Unverified() {
+ t.Fatalf("a record in another region: %+v, want no_record", v)
}
for _, h := range []string{"retired.example.com", "gone.example.com"} {
if v := got[h]; v.Reason != dbverify.ReasonNoRecord || !v.Unverified() {
@@ -1203,8 +1206,10 @@ func newRunFx(t *testing.T, hosts ...string) *runFx {
if err != nil {
t.Fatal(err)
}
+ // HA rows, so a group box's assignment decides them; a fixed box
+ // drills them whatever HA says.
for _, h := range hosts {
- if err := reg.Upsert(registry.Route{Host: h, DBPath: filepath.Join(fx.dataDir, h+".db"), Hibernate: true, Account: fxAccount, App: fxApp}); err != nil {
+ if err := reg.Upsert(registry.Route{Host: h, DBPath: filepath.Join(fx.dataDir, h+".db"), Hibernate: true, HA: true, Account: fxAccount, App: fxApp}); err != nil {
t.Fatal(err)
}
}
diff --git a/internal/ops/ops.go b/internal/ops/ops.go
index 05a5a361a..f4d534967 100644
--- a/internal/ops/ops.go
+++ b/internal/ops/ops.go
@@ -426,7 +426,9 @@ func (r hibernateRun) run(ctx context.Context) int {
r.Logf("hibernate-verify: NOT RUN: no fresh self record at %s (%v); publishing nothing rather than under a name that may not be this box's", boxself.SelfPath(r.DataDir), err)
return 1
}
- if !dbreads.ValidRegion(r.Region) {
+ // A fleet box's region is its placement (fleet/<name>), which its
+ // records name too.
+ if _, fleet := registry.FleetPlacement(r.Region); !dbreads.ValidRegion(r.Region) && !fleet {
r.Logf("hibernate-verify: NOT RUN: CARLOS_REGION %q is not a region, so no verdict could be bound to an instance", r.Region)
return 1
}
@@ -463,7 +465,7 @@ func (r hibernateRun) run(ctx context.Context) int {
set, why := selectHosts(self, r.DataDir, r.Now(), hosts, r.Cfg.Prefix)
if why != "" {
- r.Logf("hibernate-verify: %s; this box drills none of its %d hosts and records each as no_assignment", why, len(set.NoAssignment))
+ r.Logf("hibernate-verify: %s; this box drills none of its %d HA hosts and records each as no_assignment", why, len(set.NoAssignment))
}
pub := newVerifyPublisher(ctx, store, ref, prior, set.Fleet, set.NoAssignment, r.DataDir, r.Now, r.Logf)