carlos / platform Public

hibernate-verify: leave out hosts with no database; fleet boxes exit 0

The first drill night on the dev boxes (2026-11-13) showed two kinds of
nightly noise.

A. Hosts with no database. Static-site instances and an empty HA host
are hibernating rows with a db_path whose file never existed. Their
replica holds no LTX, so the drill recorded them unverified,
nothing_replicated every night: verify_unverified would fire on night 3
and verify_coverage after 7 days, on every sleeping static site.

drillOne now has three outcomes (drillAbandoned, drillDecided,
drillNoDatabase) in place of (Verdict, bool). drillNoDatabase is
reached only in the final restoreNothing case, after the identity
bracket and the move staging both closed clean, and only when lstat of
the route's DBPath answers not-exist. A file that is there, any other
stat error, a dangling symlink, or an empty DBPath keep today's
unverified/nothing_replicated. The run records such a host in
RunResults.LeftOut, not in its verdicts, and the publisher drops it
from the fleet before dbverify.Merge, so no earlier verdict is carried
over and no not_reached is invented: the host is absent from
control/verify/<ref>.json and from the local copy the alerts read. The
run log prints "left out   <host>: no database here (...)" per host,
and the summary lines add ", N left out (no database)".

B. Fleet boxes. A fleet box has no CARLOS_DEPLOYMENT_BUCKET or
CARLOS_DEPLOYMENT_DIR, so the unit exited 1 every night. With
CARLOS_FLEET set and neither variable set (openDeployStore's new
errNoDeployStore), the run prints one line and exits 0, publishing
nothing. A platform box without a deployment store still fails as
before.

Census: hibernateRun.run's body changed (no new read source) and
noDatabase is a new unit reading +file:Lstat; TestPlan14RootReadCensus
needs the overlay and a reviewer's verdict.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 08ab27f866797b89726922c6c088fc2a8dd14965 parent 6847507
4 files changed, +431 −56
  • internal/ops/hibernate_verify.go +105 −32
  • internal/ops/hibernate_verify_run_test.go +187 −4
  • internal/ops/hibernate_verify_test.go +79 −5
  • internal/ops/ops.go +60 −15
diff --git a/internal/ops/hibernate_verify.go b/internal/ops/hibernate_verify.go
index ce0bd223d..d1d711fe8 100644
--- a/internal/ops/hibernate_verify.go
+++ b/internal/ops/hibernate_verify.go
@@ -229,7 +229,13 @@ type Drill struct {
// restore found. So is its move staging (R1): a staged copy waiting for
// the first wake's promotion at either end is unverified, moving. Freshness is judged only on the box that provably holds
// the live lease (P-14).
-func VerifyHibernating(ctx context.Context, d Drill, hosts []HibernatingRoute, now func() time.Time, publish func(map[string]dbverify.Verdict) bool) map[string]dbverify.Verdict {
+//
+// A host whose bracket closed clean with nothing replicated, and whose
+// live database file is absent from this box, has no database to back up
+// (a static site, an instance that never opened one): it gets no verdict
+// and is left out (RunResults.LeftOut), so the record does not carry it at
+// all.
+func VerifyHibernating(ctx context.Context, d Drill, hosts []HibernatingRoute, now func() time.Time, publish func(RunResults) bool) RunResults {
start := now()
runCtx, cancel := ctx, context.CancelFunc(func() {})
if d.Budget > 0 {
@@ -282,25 +288,40 @@ func VerifyHibernating(ctx context.Context, d Drill, hosts []HibernatingRoute, n
break
}
visited++
- v, ok := d.drillOne(runCtx, rt, now)
- if !ok {
+ v, outcome := d.drillOne(runCtx, rt, now)
+ switch outcome {
+ case drillAbandoned:
fmt.Printf("abandoned %s: the run ended during its test; no verdict, and it goes to the back of the next run\n", rt.Host)
res.add(rt.Host, dbverify.Verdict{Result: dbverify.ResultUnverified, Reason: dbverify.ReasonNotReached,
Prefix: activator.HibernatePrefix(d.Cfg.Prefix, rt.Host), AttemptedAt: now().UTC()})
- continue
+ case drillNoDatabase:
+ fmt.Printf("left out %s: no database here (nothing replicated, and no file at %s)\n", rt.Host, rt.DBPath)
+ res.leaveOut(rt.Host)
+ default:
+ res.add(rt.Host, v)
+ printVerdict(rt.Host, v)
}
- res.add(rt.Host, v)
- printVerdict(rt.Host, v)
}
return res.all()
}
+// RunResults is what a run has finished: a verdict per host it decided
+// (or abandoned, as not_reached), and the hosts it left out because they
+// have no database to back up. A host left out has no verdict, and the
+// publisher keeps it out of the record: no streak, no coverage, and no
+// carry-over of an earlier verdict.
+type RunResults struct {
+ Verdicts map[string]dbverify.Verdict
+ LeftOut map[string]bool
+}
+
// runResults is a run's verdicts so far, shared by the drill and the
// publish ticker.
type runResults struct {
mu sync.Mutex
out map[string]dbverify.Verdict
- version int // bumped by every add
+ leftOut map[string]bool
+ version int // bumped by every add and leaveOut
published int // the version the last successful ticker publish carried
}
@@ -314,22 +335,42 @@ func (r *runResults) add(host string, v dbverify.Verdict) {
r.version++
}
-// all is a copy of every verdict so far.
-func (r *runResults) all() map[string]dbverify.Verdict {
+// leaveOut records a host with no database to back up.
+func (r *runResults) leaveOut(host string) {
+ r.mu.Lock()
+ defer r.mu.Unlock()
+ if r.leftOut == nil {
+ r.leftOut = map[string]bool{}
+ }
+ r.leftOut[host] = true
+ r.version++
+}
+
+// all is a copy of everything so far.
+func (r *runResults) all() RunResults {
r.mu.Lock()
defer r.mu.Unlock()
- return cloneVerdicts(r.out)
+ return r.snapshot()
}
-// unpublished is a copy of every verdict so far and its version, when
+// unpublished is a copy of everything so far and its version, when
// something was added since the last acknowledged publish.
-func (r *runResults) unpublished() (map[string]dbverify.Verdict, int, bool) {
+func (r *runResults) unpublished() (RunResults, int, bool) {
r.mu.Lock()
defer r.mu.Unlock()
if r.version == r.published {
- return nil, 0, false
+ return RunResults{}, 0, false
}
- return cloneVerdicts(r.out), r.version, true
+ return r.snapshot(), r.version, true
+}
+
+// snapshot copies the results; the caller holds mu.
+func (r *runResults) snapshot() RunResults {
+ left := make(map[string]bool, len(r.leftOut))
+ for h := range r.leftOut {
+ left[h] = true
+ }
+ return RunResults{Verdicts: cloneVerdicts(r.out), LeftOut: left}
}
// acknowledge records that the snapshot at version was published.
@@ -379,21 +420,35 @@ type restoreResult struct {
err error
}
-// drillOne tests one host. ok is false when the run's context ended while
-// the host was in progress: the host is abandoned, with no verdict.
-func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() time.Time) (dbverify.Verdict, bool) {
+// drillOutcome is what drillOne came to for one host.
+type drillOutcome int
+
+const (
+ // drillAbandoned: the run's context ended while the host was in
+ // progress. No verdict; the run records it not_reached.
+ drillAbandoned drillOutcome = iota
+ // drillDecided: the host has a verdict.
+ drillDecided
+ // drillNoDatabase: the bracket closed clean, the replica holds
+ // nothing, and the live database file is absent from this box: there
+ // is no database to back up, so the host is left out of the record.
+ drillNoDatabase
+)
+
+// drillOne tests one host.
+func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() time.Time) (dbverify.Verdict, drillOutcome) {
prefix := activator.HibernatePrefix(d.Cfg.Prefix, rt.Host)
v := dbverify.Verdict{Prefix: prefix, BracketOpenedAt: now().UTC()}
- unverified := func(reason, detail string) (dbverify.Verdict, bool) {
+ unverified := func(reason, detail string) (dbverify.Verdict, drillOutcome) {
v.Result, v.Reason, v.Detail = dbverify.ResultUnverified, reason, detail
v.VerifiedAt = now().UTC()
- return v, true
+ return v, drillDecided
}
id, code, detail, err := captureDrillIdentity(ctx, d.Store, d.Region, rt)
if err != nil {
if ctx.Err() != nil {
- return dbverify.Verdict{}, false
+ return dbverify.Verdict{}, drillAbandoned
}
return unverified(ReasonRecordUnreadable, err.Error())
}
@@ -413,7 +468,7 @@ func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() tim
// and when the staging cannot be read, nothing is either.
switch staged, err := d.stagedCopy(ctx, rt.Host); {
case err != nil && ctx.Err() != nil:
- return dbverify.Verdict{}, false
+ return dbverify.Verdict{}, drillAbandoned
case err != nil:
return unverified(ReasonStorageUnavailable, err.Error())
case staged:
@@ -427,13 +482,13 @@ func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() tim
scratch, err := os.MkdirTemp(d.TmpDir, "drill-")
if err != nil {
fmt.Printf("hibernate-verify: %s: no scratch directory on this box: %v\n", rt.Host, err)
- return dbverify.Verdict{}, false
+ return dbverify.Verdict{}, drillAbandoned
}
defer os.RemoveAll(scratch)
res := d.restore(ctx, prefix, scratch)
if res.err != nil && ctx.Err() != nil {
- return dbverify.Verdict{}, false
+ return dbverify.Verdict{}, drillAbandoned
}
// Freshness is read before the bracket closes, so a record change
// while it is read discards it too.
@@ -443,14 +498,14 @@ func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() tim
if res.kind == restoreClean {
fresh, stale, staleDetail = d.freshness(ctx, rt, prefix, res.counter)
if ctx.Err() != nil {
- return dbverify.Verdict{}, false
+ return dbverify.Verdict{}, drillAbandoned
}
}
code, err = confirmDrillIdentity(ctx, d.Store, rt, id)
if err != nil {
if ctx.Err() != nil {
- return dbverify.Verdict{}, false
+ return dbverify.Verdict{}, drillAbandoned
}
return unverified(ReasonRecordUnreadable, "the record could not be read again after the restore, so its result was discarded: "+err.Error())
}
@@ -462,7 +517,7 @@ func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() tim
// so neither a stale pass nor a mixed-lineage failure can stand.
switch staged, err := d.stagedCopy(ctx, rt.Host); {
case err != nil && ctx.Err() != nil:
- return dbverify.Verdict{}, false
+ return dbverify.Verdict{}, drillAbandoned
case err != nil:
return unverified(ReasonStorageUnavailable, "the move staging could not be read again after the restore, so its result was discarded: "+err.Error())
case staged:
@@ -472,26 +527,44 @@ func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() tim
v.VerifiedAt = now().UTC()
switch res.kind {
case restoreNothing:
+ // Only here, with the bracket and the staging closed clean, and only
+ // on a proven absence: a file that is there is a database with
+ // nothing replicated, a real gap.
+ if noDatabase(rt.DBPath) {
+ return dbverify.Verdict{}, drillNoDatabase
+ }
v.Result, v.Reason, v.Detail = dbverify.ResultUnverified, ReasonNothingReplicated, "no replica yet"
- return v, true
+ return v, drillDecided
case restorePlanMoved:
v.Result, v.Reason, v.Detail = dbverify.ResultUnverified, ReasonPlanMoved, res.err.Error()
- return v, true
+ return v, drillDecided
case restoreFailed:
v.Result, v.Reason, v.Detail = dbverify.ResultFailed, ReasonRestoreError, res.err.Error()
- return v, true
+ return v, drillDecided
case restoreUnavailable:
v.Result, v.Reason, v.Detail = dbverify.ResultUnverified, ReasonStorageUnavailable, res.err.Error()
- return v, true
+ return v, drillDecided
}
v.TXID, v.WrittenAt, v.RestoredBytes = res.plan.TXID, res.plan.At, res.plan.RestoredBytes
v.Freshness = fresh
if stale {
v.Result, v.Reason, v.Detail = dbverify.ResultFailed, ReasonStale, staleDetail
- return v, true
+ return v, drillDecided
}
v.Result = dbverify.ResultPassed
- return v, true
+ return v, drillDecided
+}
+
+// noDatabase reports whether the live database at path is proven absent
+// from this box: lstat answers that nothing at all is there. Any other
+// answer (a file, a dangling symlink, a permission or path error) is not
+// proof, and neither is a route with no path recorded.
+func noDatabase(path string) bool {
+ if path == "" {
+ return false
+ }
+ _, err := os.Lstat(path)
+ return errors.Is(err, fs.ErrNotExist)
}
// stagedCopy reports whether a move's staged copy of host waits under
diff --git a/internal/ops/hibernate_verify_run_test.go b/internal/ops/hibernate_verify_run_test.go
index 2361eea71..96dcd2678 100644
--- a/internal/ops/hibernate_verify_run_test.go
+++ b/internal/ops/hibernate_verify_run_test.go
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
+ "io"
"os"
"path/filepath"
"slices"
@@ -13,6 +14,7 @@ import (
"time"
"github.com/carlosframework/platform/internal/dbverify"
+ "github.com/carlosframework/platform/internal/metrics"
)
// A failed periodic upload is not acknowledged: the next tick publishes
@@ -36,10 +38,10 @@ func TestVerifyHibernatingRetriesAFailedPublish(t *testing.T) {
var mu sync.Mutex
var calls []int
up := false
- publish := func(r map[string]dbverify.Verdict) bool {
+ publish := func(r RunResults) bool {
mu.Lock()
defer mu.Unlock()
- calls = append(calls, len(r))
+ calls = append(calls, len(r.Verdicts))
return up
}
seen := func() []int {
@@ -85,11 +87,11 @@ func TestVerifyPublisherReportsSuccess(t *testing.T) {
fx := newDrillFx(t)
store := &failingStore{ctxStore: ctxStore{Store: fx.store}, fail: true}
pub := newVerifyPublisher(context.Background(), store, fxSelf, nil, []string{"a.example.com"}, nil, t.TempDir(), fx.clock.Now, t.Logf)
- if pub.publish(nil) {
+ if pub.publish(RunResults{}) {
t.Fatal("a failed upload reported success")
}
store.fail = false
- if !pub.publish(nil) {
+ if !pub.publish(RunResults{}) {
t.Fatal("an upload that landed reported failure")
}
}
@@ -362,3 +364,184 @@ func TestRunHibernateVerifyEmptyFleetClearsCrashedScratch(t *testing.T) {
})
}
}
+
+// captureStdout runs f and returns what it printed: the run's own lines go
+// to stdout, its refusals through Logf.
+func captureStdout(t *testing.T, f func()) string {
+ t.Helper()
+ r, w, err := os.Pipe()
+ if err != nil {
+ t.Fatal(err)
+ }
+ old := os.Stdout
+ os.Stdout = w
+ restored := false
+ restore := func() {
+ if !restored {
+ os.Stdout = old
+ w.Close()
+ restored = true
+ }
+ }
+ t.Cleanup(restore)
+ out := make(chan string)
+ go func() {
+ b, _ := io.ReadAll(r)
+ r.Close()
+ out <- string(b)
+ }()
+ f()
+ restore()
+ return <-out
+}
+
+// TestRunHibernateVerifyLeavesOutHostsWithNoDatabase: a host with nothing
+// replicated and no database file on this box (a static site, an
+// instance that never opened a database) has nothing to back up. It is
+// left out of the record, in the bucket and in the local copy the alerts
+// read, so it carries no streak and counts for no coverage; one that was
+// unverified on earlier nights drops out rather than being carried over.
+// A host with nothing replicated whose database file is there is a real
+// gap and stays unverified, nothing_replicated.
+func TestRunHibernateVerifyLeavesOutHostsWithNoDatabase(t *testing.T) {
+ const app, site, gap = "app.example.com", "site.example.com", "gap.example.com"
+ fx := newRunFx(t, app, site, gap)
+ fx.writeSelf(fxSelf, false)
+ fx.replicaFor[fx.prefix(site)] = fx.empty
+ fx.replicaFor[fx.prefix(gap)] = fx.empty
+ if err := os.WriteFile(filepath.Join(fx.dataDir, gap+".db"), []byte("x"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ prior := &dbverify.Record{V: 2, Box: fxSelf, CheckedAt: at("2026-11-11T03:00:00Z"), Hosts: map[string]dbverify.Verdict{
+ site: {Result: dbverify.ResultUnverified, Reason: ReasonNothingReplicated, Detail: "no replica yet",
+ Identity: fx.identity(site), UnverifiedRuns: 2, FirstSeen: at("2026-11-02T03:00:00Z"), VerifiedAt: at("2026-11-11T03:00:00Z")},
+ app: {Result: dbverify.ResultPassed, Identity: fx.identity(app), FirstSeen: at("2026-11-02T03:00:00Z"),
+ VerifiedAt: at("2026-11-11T03:00:00Z"), LastDecidedAt: at("2026-11-11T03:00:00Z")},
+ }}
+ if err := dbverify.Publish(context.Background(), fx.store, prior); err != nil {
+ t.Fatal(err)
+ }
+
+ var code int
+ out := captureStdout(t, func() { code = fx.runner().run(context.Background()) })
+ if code != 0 {
+ t.Fatalf("exited %d: %s\n%s", code, fx.logs, out)
+ }
+ rec := fx.published(fxSelf)
+ if got, want := sortedHosts(rec), []string{app, gap}; !slices.Equal(got, want) {
+ t.Fatalf("record names %v, want %v (%s has no database)", got, want, site)
+ }
+ if v := rec.Hosts[gap]; !v.Unverified() || v.Reason != ReasonNothingReplicated || v.UnverifiedRuns != 1 {
+ t.Fatalf("%s, a database with nothing replicated: %+v, want unverified/nothing_replicated, streak 1", gap, v)
+ }
+ if !rec.Hosts[app].OK() {
+ t.Fatalf("%s: %+v", app, rec.Hosts[app])
+ }
+ local, err := fx.localCopy()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got := sortedHosts(local); !slices.Equal(got, sortedHosts(rec)) {
+ t.Fatalf("local copy names %v, the bucket's %v", got, sortedHosts(rec))
+ }
+ // The alert rules read the local copy: nothing there for the host, a
+ // week on or not.
+ reading, err := metrics.ReadVerify(dbverify.LocalPath(fx.dataDir), fx.clock.Now().Add(8*24*time.Hour))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, streak := reading.UnverifiedStreak[site]; streak || slices.Contains(reading.Hosts, site) || slices.Contains(reading.Behind, site) {
+ t.Fatalf("the alerts still see %s: %+v", site, reading)
+ }
+ if !strings.Contains(out, "left out "+site+": no database here") {
+ t.Fatalf("the run log does not say %s was left out:\n%s", site, out)
+ }
+ if !strings.Contains(out, "1 left out (no database)") {
+ t.Fatalf("the run's summary does not count the host left out:\n%s", out)
+ }
+}
+
+// TestRunHibernateVerifyLastHostLeftOutClearsTheRecord: when every host is
+// left out, the record published is empty, not the prior one.
+func TestRunHibernateVerifyLastHostLeftOutClearsTheRecord(t *testing.T) {
+ const site = "site.example.com"
+ fx := newRunFx(t, site)
+ fx.writeSelf(fxSelf, false)
+ fx.replicaFor[fx.prefix(site)] = fx.empty
+ prior := &dbverify.Record{V: 2, Box: fxSelf, CheckedAt: at("2026-11-11T03:00:00Z"), Hosts: map[string]dbverify.Verdict{
+ site: {Result: dbverify.ResultUnverified, Reason: ReasonNothingReplicated, Identity: fx.identity(site),
+ UnverifiedRuns: 2, FirstSeen: at("2026-11-02T03:00:00Z"), VerifiedAt: at("2026-11-11T03:00:00Z")},
+ }}
+ if err := dbverify.Publish(context.Background(), fx.store, prior); err != nil {
+ t.Fatal(err)
+ }
+ var code int
+ captureStdout(t, func() { code = fx.runner().run(context.Background()) })
+ if code != 0 {
+ t.Fatalf("exited %d: %s", code, fx.logs)
+ }
+ if rec := fx.published(fxSelf); rec == nil || len(rec.Hosts) != 0 {
+ t.Fatalf("published %+v, want an empty record", rec)
+ }
+ if local, err := fx.localCopy(); err != nil || len(local.Hosts) != 0 {
+ t.Fatalf("local copy %+v, %v; want an empty record", local, err)
+ }
+}
+
+// TestRunHibernateVerifyFleetBoxWithoutDeploymentStore: a fleet box reaches
+// its deployment through the console, not a bucket of its own, so the
+// instances' records are out of its reach. It says so once and exits 0,
+// publishing nothing, instead of failing its unit every night. A platform
+// box missing its deployment bucket still fails loudly.
+func TestRunHibernateVerifyFleetBoxWithoutDeploymentStore(t *testing.T) {
+ t.Setenv("CARLOS_DEPLOYMENT_BUCKET", "")
+ t.Setenv("CARLOS_DEPLOYMENT_DIR", "")
+ for name, c := range map[string]struct {
+ fleet string
+ code int
+ }{
+ "fleet box": {fleet: "acme", code: 0},
+ "platform box": {fleet: "", code: 1},
+ } {
+ t.Run(name, 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.OpenStore = openDeployStore
+ r.Fleet = c.fleet
+ var code int
+ out := captureStdout(t, func() { code = r.run(context.Background()) })
+ if code != c.code {
+ t.Fatalf("exited %d, want %d: %s\n%s", code, c.code, fx.logs, out)
+ }
+ if restored {
+ t.Fatal("drilled with no deployment store")
+ }
+ keys, err := fx.store.List(context.Background(), "control/")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(keys) != 0 {
+ t.Fatalf("published %v", keys)
+ }
+ if _, err := fx.localCopy(); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("a local copy was written: %v", err)
+ }
+ fleetLine := "hibernate-verify: fleet box: instance records are not reachable from here, so the drill does not run on fleet boxes yet"
+ if c.fleet != "" {
+ if !strings.Contains(out, fleetLine) || fx.logs.Len() != 0 {
+ t.Fatalf("stdout %q, log %q; want the one fleet line", out, fx.logs)
+ }
+ return
+ }
+ if strings.Contains(out, fleetLine) || !strings.Contains(fx.logs.String(), "NOT RUN: the deployment bucket") {
+ t.Fatalf("stdout %q, log %q; want the NOT RUN refusal", out, fx.logs)
+ }
+ })
+ }
+}
diff --git a/internal/ops/hibernate_verify_test.go b/internal/ops/hibernate_verify_test.go
index 2f2f7fa8e..a3c1fe5d6 100644
--- a/internal/ops/hibernate_verify_test.go
+++ b/internal/ops/hibernate_verify_test.go
@@ -354,7 +354,12 @@ func (fx *drillFx) routes(hosts ...string) []HibernatingRoute {
return out
}
-func (fx *drillFx) run(ctx context.Context, d Drill, hosts []HibernatingRoute, publish func(map[string]dbverify.Verdict) bool) map[string]dbverify.Verdict {
+func (fx *drillFx) run(ctx context.Context, d Drill, hosts []HibernatingRoute, publish func(RunResults) bool) map[string]dbverify.Verdict {
+ return fx.runAll(ctx, d, hosts, publish).Verdicts
+}
+
+// runAll is run with the hosts left out too.
+func (fx *drillFx) runAll(ctx context.Context, d Drill, hosts []HibernatingRoute, publish func(RunResults) bool) RunResults {
return VerifyHibernating(ctx, d, hosts, fx.clock.Now, publish)
}
@@ -431,6 +436,75 @@ func TestVerifyHibernatingVerdicts(t *testing.T) {
fx.scratchEmpty()
}
+// TestVerifyHibernatingLeavesOutAHostWithNoDatabase: a host whose replica
+// holds nothing and whose live database file is absent from this box has
+// no database to back up (a static site, an instance that never opened
+// one). It gets no verdict: the run leaves it out. Only a proven absence
+// counts: a file that is there, any other answer from the disk, and a
+// route with no database path keep nothing_replicated. And the leave-out
+// comes last: a host the bracket refused, or whose bracket did not close
+// clean, keeps the verdict that says so.
+func TestVerifyHibernatingLeavesOutAHostWithNoDatabase(t *testing.T) {
+ const host = "site.example.com"
+ dir := t.TempDir()
+ absent := filepath.Join(dir, "absent.db")
+ present := filepath.Join(dir, "present.db")
+ notADir := filepath.Join(dir, "file")
+ dangling := filepath.Join(dir, "dangling.db")
+ for _, p := range []string{present, notADir} {
+ if err := os.WriteFile(p, []byte("x"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := os.Symlink(filepath.Join(dir, "nowhere.db"), dangling); err != nil {
+ t.Fatal(err)
+ }
+ cases := map[string]struct {
+ dbPath string
+ setup func(fx *drillFx)
+ leftOut bool
+ reason string
+ }{
+ "no database file": {dbPath: absent, leftOut: true},
+ "database file present": {dbPath: present, reason: ReasonNothingReplicated},
+ "stat fails another way": {dbPath: filepath.Join(notADir, "x.db"), reason: ReasonNothingReplicated},
+ "a dangling symlink": {dbPath: dangling, reason: ReasonNothingReplicated},
+ "no database path recorded": {dbPath: "", reason: ReasonNothingReplicated},
+ "no record": {dbPath: absent, reason: dbverify.ReasonNoRecord,
+ setup: func(fx *drillFx) { fx.deleteRecord(fxAccount, host) }},
+ "a staged copy waits": {dbPath: absent, reason: ReasonMoving,
+ setup: func(fx *drillFx) { fx.stage(host) }},
+ "staging unreadable": {dbPath: absent, reason: ReasonStorageUnavailable,
+ setup: func(fx *drillFx) { fx.stagingErr = errors.New("AccessDenied") }},
+ "record changed during the test": {dbPath: absent, reason: ReasonRecordChanged,
+ setup: func(fx *drillFx) {
+ fx.onList[fx.prefix(host)] = func() { fx.deleteRecord(fxAccount, host) }
+ }},
+ }
+ for name, c := range cases {
+ t.Run(name, func(t *testing.T) {
+ fx := newDrillFx(t, host)
+ fx.replicaFor[fx.prefix(host)] = fx.empty
+ if c.setup != nil {
+ c.setup(fx)
+ }
+ rt := fx.routes(host)
+ rt[0].DBPath = c.dbPath
+ res := fx.runAll(context.Background(), fx.drill(), rt, nil)
+ v, decided := res.Verdicts[host]
+ switch {
+ case c.leftOut && (decided || !res.LeftOut[host]):
+ t.Fatalf("verdict %+v (decided %v), left out %v; want no verdict, left out", v, decided, res.LeftOut)
+ case !c.leftOut && (!decided || res.LeftOut[host]):
+ t.Fatalf("left out %v, verdict %v; want unverified/%s", res.LeftOut, decided, c.reason)
+ case !c.leftOut && (!v.Unverified() || v.Reason != c.reason):
+ t.Fatalf("verdict %s/%s, want unverified/%s (%+v)", v.Result, v.Reason, c.reason, v)
+ }
+ fx.scratchEmpty()
+ })
+ }
+}
+
// The per-host prefix must be the one the activator actually writes to, or
// every drill reports "no replica" over perfectly good backups; the lock
// read is the same prefix's.
@@ -1078,9 +1152,9 @@ func TestVerifyHibernatingPublishesPeriodically(t *testing.T) {
published := make(chan map[string]dbverify.Verdict, 8)
done := make(chan map[string]dbverify.Verdict)
go func() {
- done <- fx.run(context.Background(), d, fx.routes(hosts...), func(r map[string]dbverify.Verdict) bool {
+ done <- fx.run(context.Background(), d, fx.routes(hosts...), func(r RunResults) bool {
ok := pub.publish(r)
- published <- r
+ published <- r.Verdicts
return ok
})
}()
@@ -1143,7 +1217,7 @@ func TestVerifyHibernatingTickWithNothingNewIsQuiet(t *testing.T) {
var calls atomic.Int32
done := make(chan struct{})
go func() {
- fx.run(context.Background(), d, fx.routes("a.example.com"), func(map[string]dbverify.Verdict) bool { calls.Add(1); return true })
+ fx.run(context.Background(), d, fx.routes("a.example.com"), func(RunResults) bool { calls.Add(1); return true })
close(done)
}()
<-blocked
@@ -1194,7 +1268,7 @@ func TestVerifyHibernatingStreakOncePerRun(t *testing.T) {
d.PublishEvery = 10 * time.Minute
pub := newVerifyPublisher(context.Background(), store, fxSelf, prior, hosts, nil, t.TempDir(), fx.clock.Now, t.Logf)
// The unverified host first, so every publish of the run carries it.
- fx.run(context.Background(), d, fx.routes(hosts...), func(r map[string]dbverify.Verdict) bool {
+ fx.run(context.Background(), d, fx.routes(hosts...), func(r RunResults) bool {
ok := pub.publish(r)
published <- struct{}{}
return ok
diff --git a/internal/ops/ops.go b/internal/ops/ops.go
index 843976418..14a325de0 100644
--- a/internal/ops/ops.go
+++ b/internal/ops/ops.go
@@ -374,6 +374,7 @@ func runHibernateVerify(args []string) {
Root: os.Geteuid() == 0,
Cfg: cfg,
OpenStore: openDeployStore,
+ Fleet: fleetBox(os.Getenv),
Region: strings.TrimSpace(os.Getenv("CARLOS_REGION")),
DataDir: dir,
RegPath: rp,
@@ -404,9 +405,12 @@ var (
// box named, so a test can run it whole.
type hibernateRun struct {
// Root is a run as effective uid 0, which run refuses first of all.
- Root bool
- Cfg *activator.Config
- OpenStore func(context.Context) (release.Store, error)
+ Root bool
+ Cfg *activator.Config
+ OpenStore func(context.Context) (release.Store, error)
+ // Fleet is the fleet this box is on (CARLOS_FLEET), "" on a platform
+ // box. A fleet box with no deployment store of its own does not run.
+ Fleet string
Region string // CARLOS_REGION: the region an instance's record must name; "" on a home-region box
DataDir string
RegPath string
@@ -483,6 +487,14 @@ func (r hibernateRun) run(ctx context.Context) int {
return 1
}
store, err := r.OpenStore(ctx)
+ if errors.Is(err, errNoDeployStore) && r.Fleet != "" {
+ // A fleet box reaches its deployment through the console door, not
+ // a bucket of its own (openDeployStore), so the records the bracket
+ // binds each verdict to are out of its reach. Not a failure of the
+ // box: a unit failing every night on every fleet box is noise.
+ fmt.Println("hibernate-verify: fleet box: instance records are not reachable from here, so the drill does not run on fleet boxes yet")
+ return 0
+ }
if err != nil {
r.Logf("hibernate-verify: NOT RUN: the deployment bucket, which holds the instances' records and this box's verdicts: %v", err)
return 1
@@ -528,7 +540,7 @@ func (r hibernateRun) run(ctx context.Context) int {
fmt.Println("hibernate-verify: no hibernating instances for this box to drill")
return 0
}
- pub.publish(nil)
+ pub.publish(RunResults{})
fmt.Println("hibernate-verify: no hibernating instances for this box to drill; its record is cleared")
return 0
}
@@ -544,6 +556,7 @@ func (r hibernateRun) run(ctx context.Context) int {
Budget: r.Budget, Max: r.Max, PublishEvery: r.PublishEvery}
results := VerifyHibernating(ctx, d, OldestFirst(set.Drill, prior), r.Now, pub.publish)
rec := pub.last
+ left := len(results.LeftOut)
if n := rec.Failures(); n > 0 {
r.Logf("hibernate-verify: %d replica(s) did not restore clean", n)
@@ -553,13 +566,15 @@ func (r hibernateRun) run(ctx context.Context) int {
// coverage, and a summary that said otherwise would be the same comfortable
// lie this verb exists to remove.
proven := 0
- for _, v := range results {
+ for _, v := range results.Verdicts {
if v.OK() {
proven++
}
}
- fmt.Printf("hibernate-verify: %d of %d replicas this box drills proven this run (%d visited, %d in its record)\n",
- proven, len(set.Drill), len(results), len(set.Fleet))
+ // A host left out has no database, so no replica to prove: it is
+ // counted apart, not as one this box drills.
+ fmt.Printf("hibernate-verify: %d of %d replicas this box drills proven this run (%d visited, %d in its record%s)\n",
+ proven, len(set.Drill)-left, len(results.Verdicts)+left, len(rec.Hosts), leftOutNote(left))
return 0
}
@@ -638,15 +653,25 @@ func newVerifyPublisher(ctx context.Context, store release.Store, ref string, pr
// stopped, still publishes what it finished. The local copy is written
// whether or not the publish succeeded, so the box's own alerts see it.
// It reports whether the bucket took the record.
-func (p *verifyPublisher) publish(results map[string]dbverify.Verdict) bool {
- all := make(map[string]dbverify.Verdict, len(results)+len(p.extra))
+//
+// A host the run left out (no database to back up) is taken out of the
+// fleet before the merge, so neither its verdict from the run-start record
+// nor a not_reached is carried for it.
+func (p *verifyPublisher) publish(results RunResults) bool {
+ all := make(map[string]dbverify.Verdict, len(results.Verdicts)+len(p.extra))
for h, v := range p.extra {
all[h] = v
}
- for h, v := range results {
+ for h, v := range results.Verdicts {
all[h] = v
}
- rec := dbverify.Merge(p.prior, p.ref, p.now(), p.fleet, all)
+ fleet := make([]string, 0, len(p.fleet))
+ for _, h := range p.fleet {
+ if !results.LeftOut[h] {
+ fleet = append(fleet, h)
+ }
+ }
+ rec := dbverify.Merge(p.prior, p.ref, p.now(), fleet, all)
for h := range p.dropped {
delete(rec.Hosts, h)
}
@@ -664,7 +689,7 @@ func (p *verifyPublisher) publish(results map[string]dbverify.Verdict) bool {
for h := range rec.Hosts {
p.known[h] = true
}
- fmt.Printf("hibernate-verify: published %s (%d hosts, %d unverified)\n", dbverify.KeyFor(p.ref), len(rec.Hosts), rec.Unverified())
+ fmt.Printf("hibernate-verify: published %s (%d hosts, %d unverified%s)\n", dbverify.KeyFor(p.ref), len(rec.Hosts), rec.Unverified(), leftOutNote(len(results.LeftOut)))
} else {
p.logf("hibernate-verify: NOT PUBLISHED: %v; the verdicts exist only in this log and %s", err, localVerifyPath(p.dataDir))
}
@@ -674,6 +699,15 @@ func (p *verifyPublisher) publish(results map[string]dbverify.Verdict) bool {
return ok
}
+// leftOutNote is the run log's count of the hosts left out for having no
+// database, "" when there are none.
+func leftOutNote(n int) string {
+ if n == 0 {
+ return ""
+ }
+ return fmt.Sprintf(", %d left out (no database)", n)
+}
+
// localVerifyPath is the local alert copy, beside the agent's self record:
// <data>/monitor/verify.json.
func localVerifyPath(dataDir string) string {
@@ -693,11 +727,22 @@ func writeLocalVerify(dataDir string, rec *dbverify.Record) error {
return boxself.WriteFile(localVerifyPath(dataDir), body, dbverify.LocalMax)
}
+// errNoDeployStore is openDeployStore's answer when neither variable is set.
+var errNoDeployStore = errors.New("neither CARLOS_DEPLOYMENT_BUCKET nor CARLOS_DEPLOYMENT_DIR is set")
+
+// fleetBox is the fleet this box is on (CARLOS_FLEET), "" on a platform box.
+// The agent's own test is the variable being set (internal/host,
+// shouldSkipPublisherElection); a value of only spaces is not a fleet here,
+// so it fails as a platform box would rather than going quiet.
+func fleetBox(getenv func(string) string) string {
+ return strings.TrimSpace(getenv("CARLOS_FLEET"))
+}
+
// openDeployStore resolves the deployment bucket the same way the agent's
// bucket/dir env vars do. A fleet box that reaches its deployment through the
// console door instead (openDeployStoreEnv's third case in internal/host) is
-// NOT covered here and is told so out loud rather than publishing nothing
-// quietly.
+// NOT covered here: it gets errNoDeployStore, and the run says so in one
+// line and stops without failing (hibernateRun.Fleet).
func openDeployStore(ctx context.Context) (release.Store, error) {
if b := os.Getenv("CARLOS_DEPLOYMENT_BUCKET"); b != "" {
return release.NewDeploymentS3Store(ctx, b)
@@ -707,5 +752,5 @@ func openDeployStore(ctx context.Context) (release.Store, error) {
ds.EnableChangeIndex()
return ds, nil
}
- return nil, errors.New("neither CARLOS_DEPLOYMENT_BUCKET nor CARLOS_DEPLOYMENT_DIR is set")
+ return nil, errNoDeployStore
}