How the auditor runs
The auditor's ring, its discovery pass, the duty harness, and the rules every job follows.
Every piece of background work is a due marker in the metadata store, and any auditor can run any marker. Each job converges when run again after a crash at any step. So the ring that shares the work, and the leases that keep two auditors off one job, only save duplicated effort. Correctness never depends on them.
Where it lives
| Package | What it holds |
|---|---|
internal/auditor | Auditor and its Run loop (auditor.go), the discovery pass (dispatch.go), the duty harness (harness.go), the ring seat (seat.go), job leases (leases.go), budgets, and one file per duty |
internal/coord | The ring (ring.go), session-bound claims used as leases (claims.go), and ledger placement (placement.go) |
internal/metadata | Due-marker keys and their arm and resolve calls (keys.go, audit.go, and one file per queue) |
internal/daemon | Builds the auditor for --audit=on (inside a serving node) or --audit=only (a node that serves no clients), and stops it on a drain (audit.go) |
The data
| Record | Key | Lifetime |
|---|---|---|
| Ring seat | cluster/auditors/{star} in the sessions keyspace, holding the node's star record | Ends with the node's metadata store session |
| Due marker | due/{queue}/{shard}/… in the queues keyspace. See Due-queues. | Until its job resolves it |
| Job lease | auditor/lease/{jobKey}, a session-bound claim. The job key is the marker key, except trim/{star}~{epoch} for trim-check, star-reclaim/{star}, and range-change/{bucket}/{key} for splits and merges. Denorm takes ledger/{star}~{epoch} per era instead. | Released when the job ends, or with the session |
Sharing work across auditors
The due-queues have 64 shards. Every auditor writes a seat under cluster/auditors/{star}, and the seats form the ring. Each shard belongs to the seat with the highest rendezvous score for it, so a pass reads only its own shards. A change of membership moves shards without moving any local state.
func (a Assignment) Owner(shard int) (stream.StarID, bool) {
if len(a.members) == 0 {
return stream.StarID{}, false
}
subject := shardSubject(shard, a.shards)
best := a.members[0]
for _, m := range a.members[1:] {
if Score(subject, m) > Score(subject, best) {
best = m
}
}
return best, true
}Denorm is placed by ledger instead of by shard, so that one auditor walks a ledger's consecutive slots. Every auditor scans all 64 denorm shards and skips the ledgers placed elsewhere. Placement deals the sorted live stars over the sorted ring members, one each in turn. A star that is not live falls back to rendezvous hashing.
The seat is tied to the metadata store session. A store failover that outlasts the session timeout deletes it while the process keeps running. The first pass announces the seat. Every later pass reads it first and writes it again if it is gone, logging auditor: ring seat lost with its session; re-announced. A refused announcement is retried at the next pass. When Run exits, whether it was stopped or cancelled, the auditor drains its workers and then withdraws its seat, so peers take its shards at once. A node that runs only the auditor reports itself unready as soon as its seat is gone.
How jobs run
Run loops over passes. A pass starts at once while ready work remains, when a job finishes, or after 30 seconds otherwise.
- The pass retries lease releases that failed earlier, reads the ring, and takes its shards. It sets its share of the fleet's delete and read budgets from the member count, and refreshes ledger placement. The same read reports storage pressure: a node whose WAL writes of a class were throttled by object storage in the last 30 seconds says so. The class's deletes then wait while any node reports it, and for a minute after, so reclamation leaves the storage to the write path.
- It opens a paged walk for each duty over each owned shard, in registration order. A page is at most 64 markers or 256 KiB.
- It rotates over the walks, offering one job from each per round. Each marker is first judged with no I/O, then leased, then submitted to the worker pool.
- The pass ends when every walk is exhausted, after 30 seconds, or on stop. It then wakes the reap flusher, which sends spooled deletes in batches.
- A job's
Handleruns to convergence within its deadline, arms whatever comes next, and resolves its marker.
A failed job logs auditor: job failed; the queue retries next pass and leaves its marker. A job cut by a backend throttle is held off for 30 seconds, doubling up to 10 minutes, and the pass moves on.
The duty harness
A duty is one family of jobs. The harness owns leases, deadlines, malformed markers, and step metrics. The duty owns only two methods:
type duty interface {
Judge(now time.Time, record metadata.DueEntry) (verdict, error)
Handle(ctx context.Context, record metadata.DueEntry) error
}Judge returns one of four verdicts:
| Verdict | Meaning | Used by |
|---|---|---|
runJob | Lease the marker and handle it | Every duty, for a ripe marker |
stopWalk | The queue is ordered by time and this marker is not due, so nothing after it is | The time-ordered queues |
skipRecord | Leave this marker and keep walking: the key order is not an age order | star-reclaim, range-merge, orphan, range-intent |
discardMarker | The marker can never be run: resolve it without a lease and log a Warn | teardown-final, recovery, star-reclaim, and the three range duties |
Registration sets each duty's queue and walk, and its order sets dispatch priority. A higher duty is offered a worker first in every round.
| Priority | Duty | Walk |
|---|---|---|
| 1 | teardown | time-ordered, 16 markers a job |
| 2 | teardown-final | time-ordered, 16 markers a job, held by the purge gate |
| 3 | recovery | time-ordered |
| 4 | retention | time-ordered |
| 5 | retention-check | every marker is run |
| 6 | reap | time-ordered, pays the delete budget |
| 7 | trimcheck | time-ordered, pays the delete budget, one lease per ledger |
| 8 | star-reclaim | skips markers that are not due, one lease per star |
| 9 | denorm | all 64 shards through the ready-time index, no marker lease |
| 10 | gc | biggest reclaim first |
| 11 | orphan | key order, skips intents younger than the orphan grace, pays the delete budget |
| 12 | range-intent | skips intents younger than 5 minutes |
| 13 | range-split | time-ordered, one lease per stream |
| 14 | range-merge | skips markers that are not due, one lease per stream |
range-split and range-merge register only when the host lends a way to seal a range, which every novad does. Duties describes each one.
Crash points
| Crash after | State left behind | What the re-run does |
|---|---|---|
| The lease is taken | A session-bound claim and the marker | The claim ends with the session. A peer, or this auditor after a restart, leases the marker again. |
| A lease release fails | A claim with no job behind it | The auditor remembers the key and retries the release at the start of every pass. A claim naming this node that is not in flight is taken back. |
| A job passes its 10 minute deadline | Partial work and the marker | The job is cut with an error. The next pass runs it again from what is stored. |
| The seat is lost with the session | No seat. Peers take its shards. | The next pass writes the seat again. Shards move back. |
| Withdrawal fails at exit | A seat with no auditor | It ends with the session, 10 seconds later on external Oxia and 15 on the built-in one |
Concurrency
Two auditors can briefly own one shard while the ring changes, and a job can outlive its lease. Nothing relies on exclusion:
- Shared metadata changes are compare-and-set on the version read. Cursors and trim watermarks only move forward. A catalog replacement names the entry it expects.
- Every job is safe to run twice or to stop between any two steps.
- Discovery uses bounded range reads, and liveness uses point reads. The one listing is a retired star's reclaim, which lists that star's own WAL prefixes.
- A marker, a reference, or a write intent names every object until its cleanup is finished. Cleanup arms its next check before it removes what finds the object.
- Work is filed when it is created, so nothing scans for it.
Bounds and signals
| Bound | Default | Set by |
|---|---|---|
| Jobs at once | 2 | --auditor-workers |
| Jobs of one duty | Half the workers, at least 1 | Fixed |
| Jobs that pay the delete budget | A quarter of the workers, at least 1 | Fixed |
| Job deadline | 10 minutes | Fixed |
| Pass length, and idle wait | 30 seconds each | Fixed |
| Storage requests | 50 a second per auditor | --auditor-s3-budget |
| Bytes moved by rewrites | 64 MiB/s per node | --auditor-rewrite-mib |
| Deletes | 1,000 keys a second per bucket, shared by every live auditor | --auditor-delete-budget |
| Reads | 10,000 a second per bucket, shared; 64 open per auditor | --auditor-read-budget, --auditor-read-concurrency |
Metrics:
nova.auditor.step.duration, by stepnova.auditor.due.age, by queuenova.auditor.lease.skips, by queue. A lease whose key is not a marker key counts underqueue="unknown".nova.auditor.workers.activeandnova.auditor.workers.limitnova.auditor.owned.shardsandnova.auditor.budget.waitnova.audit.jobs.armedandnova.audit.jobs.resolved, by queue
Log lines:
auditor: runningauditor: ring seat lost with its session; re-announcedauditor left the ring; the seat is vacatedauditor: marker is malformed; resolving it awayauditor: job failed; the queue retries next passauditor: job held off after a backend throttleauditor: job lease contended past the grace; the holder may be wedged, for a lease conflict on a marker over 5 minutes late
Tests
- Passes:
TestAPassWalksItsDueQueuesWithoutACoroutineEach,TestDispatchKeepsQueuesLiveBehindACrawlingOrphanSweep,TestStuckJobStarvesNoOtherDutyininternal/auditor/dispatch_test.go. - Leases:
TestJobsSkipLeasedEntries,TestJobsStealOwnLeakedLease,TestLeakedLeaseReleaseIsRetriedNextCycleinjobs_test.go, andTestJobDeadlineCutsAWedgedDutyinmetrics_test.go. - The ring:
TestShardOwnershipPartitionsTheFleetandTestOwnershipAbsorbsADeadNodeinring_test.go,TestRunRestoresASeatLostWithItsSessionandTestRunRetriesARefusedAnnounceinseat_test.go,TestRunWithdrawsOnStopandTestRunWithdrawsOnCancelinwithdraw_test.go. - Placement:
TestDenormJudgeSkipsForeignLedgersinplacement_test.go.
Go deeper
Duties
Every job: trigger, steps, crash behavior, and settings
Due-queues
How work is filed, made due, and resolved
Reclamation
The rewrite protocol, probes, and two-stage deletes
Background work
Why the auditor exists, and what it costs
Operating the auditor: The auditor and Auditor delays. Design documents: Code map.