carlos / platform Public

drill: run on home-region boxes, matching region "" exactly (#898 R3)

Home-region boxes have no CARLOS_REGION and their instances' records
carry region "", so the armed drill refused every night with "NOT RUN:
CARLOS_REGION \"\" is not a region" and exited 1 (all of flagship's
home region, e.g. annie, and dev's home boxes).

An empty region is now the home region: the drill runs and its bracket
binds verdicts to records whose region is "" exactly, as it already
compared. Nothing else is loosened: a malformed non-empty region still
refuses, and a record in another region is still no_record. Assignment,
publish and freshness never read CARLOS_REGION.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 06f609fe532ace5fc49beffa3d932e366ee66261 parent 2a6daef
3 files changed, +117 −4
  • internal/ops/hibernate_verify.go +2 −1
  • internal/ops/hibernate_verify_home_test.go +109 −0
  • internal/ops/ops.go +6 −3
diff --git a/internal/ops/hibernate_verify.go b/internal/ops/hibernate_verify.go
index cf2191ff7..2dfcb76b3 100644
--- a/internal/ops/hibernate_verify.go
+++ b/internal/ops/hibernate_verify.go
@@ -173,7 +173,8 @@ var (
// Drill is one run's settings. Cfg names the hibernate bucket; Store is the
// deployment bucket the provision records are read from; Region is this
-// box's region, which an instance's record must name; SelfRef is this
+// box's region, which an instance's record must name exactly ("" on a
+// home-region box, whose records carry ""); SelfRef is this
// box's reference, the owner its lease locks carry; TmpDir is the on-disk
// scratch each restore lands in.
//
diff --git a/internal/ops/hibernate_verify_home_test.go b/internal/ops/hibernate_verify_home_test.go
new file mode 100644
index 000000000..21060a91c
--- /dev/null
+++ b/internal/ops/hibernate_verify_home_test.go
@@ -0,0 +1,109 @@
+package ops
+
+import (
+ "context"
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/dbverify"
+ "github.com/carlosframework/platform/internal/lease"
+ "github.com/carlosframework/platform/internal/provision"
+)
+
+// Member backups 2a, R3: a home-region box has no CARLOS_REGION, and its
+// instances' records carry region "". An empty region is the home region:
+// the drill runs there and binds verdicts to records whose region is ""
+// exactly. Nothing else is loosened: a malformed region still refuses, and
+// a record in another region still does not match.
+
+// A home box (region "") drills a home instance end to end through the
+// real run path, restore included, and publishes its verdict, bound to the
+// home record. A record in another region on the same box is no_record.
+func TestRunHibernateVerifyHomeBoxDrillsHomeInstances(t *testing.T) {
+ const home, away = "home.example.com", "away.example.com"
+ fx := newRunFx(t, home, away)
+ fx.putRecord(fxAccount, home, fxCreated, func(r *provision.Record) { r.Region = "" })
+ fx.putRecord(fxAccount, away, fxCreated, func(r *provision.Record) { r.Region = "uk" })
+ swap(t, &verifyAt, lease.VerifyReaderAt)
+ fx.writeSelf(fxSelf, false)
+ r := fx.runner()
+ r.Region = ""
+ if code := r.run(context.Background()); code != 0 {
+ t.Fatalf("a home box exited %d:\n%s", code, fx.logs)
+ }
+ if strings.Contains(fx.logs.String(), "NOT RUN") {
+ t.Fatalf("a home box did not run:\n%s", fx.logs)
+ }
+ rec := fx.published(fxSelf)
+ v := rec.Hosts[home]
+ if !v.OK() || v.TXID != fx.plan().TXID {
+ t.Fatalf("home instance: published %+v, want passed at txid %d", v, fx.plan().TXID)
+ }
+ if want := idFor(t, home, "", fxCreated); v.Identity != want {
+ t.Fatalf("home instance: identity %+v, want %+v", v.Identity, want)
+ }
+ if a := rec.Hosts[away]; a.Result != dbverify.ResultUnverified || a.Reason != dbverify.ReasonNoRecord {
+ t.Fatalf("a record in another region on a home box: %+v, want unverified/no_record", a)
+ }
+ fx.scratchEmpty()
+}
+
+// The exact match runs both ways: a region box does not take a home
+// record, and a home record that leaves for a region while it is tested
+// is record_changed at the close.
+func TestDrillHomeRegionMatchesExactly(t *testing.T) {
+ const host = "home.example.com"
+ t.Run("a region box and a home record", func(t *testing.T) {
+ fx := newDrillFx(t, host)
+ fx.putRecord(fxAccount, host, fxCreated, func(r *provision.Record) { r.Region = "" })
+ d := fx.drill() // region uk
+ v := fx.run(context.Background(), d, fx.routes(host), nil)[host]
+ if v.Result != dbverify.ResultUnverified || v.Reason != dbverify.ReasonNoRecord {
+ t.Fatalf("verdict %+v, want unverified/no_record", v)
+ }
+ })
+ t.Run("a home record leaving during the test", func(t *testing.T) {
+ fx := newDrillFx(t, host)
+ fx.putRecord(fxAccount, host, fxCreated, func(r *provision.Record) { r.Region = "" })
+ fx.stubVerify(func(context.Context, string, string, uint64) (uint32, error) {
+ fx.putRecord(fxAccount, host, fxCreated, func(r *provision.Record) { r.Region = "uk" })
+ return 1, nil
+ })
+ d := fx.drill()
+ d.Region = ""
+ v := fx.run(context.Background(), d, fx.routes(host), nil)[host]
+ if v.Result != dbverify.ResultUnverified || v.Reason != ReasonRecordChanged {
+ t.Fatalf("verdict %+v, want unverified/record_changed", v)
+ }
+ })
+}
+
+// A malformed region still refuses: nothing drilled, nothing published.
+func TestRunHibernateVerifyRefusesAMalformedRegion(t *testing.T) {
+ for _, region := range []string{" ", "UK", "eu west", "fleet/", "uk/", "-uk"} {
+ t.Run(region, func(t *testing.T) {
+ fx := newRunFx(t, "a.example.com")
+ fx.writeSelf(fxSelf, false)
+ restored := false
+ fx.stubVerify(func(context.Context, string, string, uint64) (uint32, error) {
+ restored = true
+ return 1, nil
+ })
+ r := fx.runner()
+ r.Region = region
+ if code := r.run(context.Background()); code != 1 {
+ t.Fatalf("CARLOS_REGION %q: exited %d, want 1", region, code)
+ }
+ if restored || !strings.Contains(fx.logs.String(), "is not a region") {
+ t.Fatalf("CARLOS_REGION %q: restored %v, log:\n%s", region, restored, fx.logs)
+ }
+ keys, err := fx.store.List(context.Background(), "control/")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(keys) != 0 {
+ t.Fatalf("CARLOS_REGION %q: published %v", region, keys)
+ }
+ })
+ }
+}
diff --git a/internal/ops/ops.go b/internal/ops/ops.go
index 324c57d59..843976418 100644
--- a/internal/ops/ops.go
+++ b/internal/ops/ops.go
@@ -407,7 +407,7 @@ type hibernateRun struct {
Root bool
Cfg *activator.Config
OpenStore func(context.Context) (release.Store, error)
- Region string // CARLOS_REGION: the region an instance's record must name
+ Region string // CARLOS_REGION: the region an instance's record must name; "" on a home-region box
DataDir string
RegPath string
TmpDir string
@@ -474,8 +474,11 @@ func (r hibernateRun) run(ctx context.Context) int {
return 1
}
// 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 {
+ // records name too. A home-region box has no CARLOS_REGION, and its
+ // instances' records carry region "": an empty region is the home
+ // region, which the bracket matches exactly (R3). Anything else that
+ // is not a region still refuses.
+ if _, fleet := registry.FleetPlacement(r.Region); 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
}