How the auditor runs

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

PackageWhat it holds
internal/auditorAuditor 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/coordThe ring (ring.go), session-bound claims used as leases (claims.go), and ledger placement (placement.go)
internal/metadataDue-marker keys and their arm and resolve calls (keys.go, audit.go, and one file per queue)
internal/daemonBuilds 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

RecordKeyLifetime
Ring seatcluster/auditors/{star} in the sessions keyspace, holding the node's star recordEnds with the node's metadata store session
Due markerdue/{queue}/{shard}/… in the queues keyspace. See Due-queues.Until its job resolves it
Job leaseauditor/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.

internal/coord/ring.go
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

How background tasks runforeground commitabsorb · denorm · trim · deleteschedules work in the same updatedue queuesmetadata store work namespacedenorm (batch markers)recovery · trim-checkreap-check · gc · retentionorphan intents · teardownshards assigned to workersdiscovery readersread assigned shards, due firstdispatch passdeal ripe markers to workersworkers (N)bounded work · leased tasksbudgetsS3 requests/srewrite MiB/sfetch cache MiBgateobject storagestream objects PUT (create-once)slot & object DELETE, via the cachemetadata storecatalog rows CAS · markers resolvednext task scheduledschedules the next taskRing membership assigns each auditor a share of the queue shards using rendezvous hashing.When membership changes, shard assignments change. Pending work stays in metadata.
A metadata update also records any required follow-up work. Workers find it in scheduled queues instead of scanning all objects or metadata.

Run loops over passes. A pass starts at once while ready work remains, when a job finishes, or after 30 seconds otherwise.

loop [Until walks end or 30 s pass] Retry leaked lease releases Read the ring, take the owned shards Open one paged walk per duty and shard Judge the next marker, with no I/O Take the job's lease Submit the job Wake the reap flusher Handle: read, write, CAS, arm the next marker Resolve the marker, release the lease Auditor pass Metadata store Worker pool
One discovery pass. Jobs run on the worker pool and outlive the pass that started them.
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. A job's Handle runs 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:

internal/auditor/harness.go
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:

VerdictMeaningUsed by
runJobLease the marker and handle itEvery duty, for a ripe marker
stopWalkThe queue is ordered by time and this marker is not due, so nothing after it isThe time-ordered queues
skipRecordLeave this marker and keep walking: the key order is not an age orderstar-reclaim, range-merge, orphan, range-intent
discardMarkerThe marker can never be run: resolve it without a lease and log a Warnteardown-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.

PriorityDutyWalk
1teardowntime-ordered, 16 markers a job
2teardown-finaltime-ordered, 16 markers a job, held by the purge gate
3recoverytime-ordered
4retentiontime-ordered
5retention-checkevery marker is run
6reaptime-ordered, pays the delete budget
7trimchecktime-ordered, pays the delete budget, one lease per ledger
8star-reclaimskips markers that are not due, one lease per star
9denormall 64 shards through the ready-time index, no marker lease
10gcbiggest reclaim first
11orphankey order, skips intents younger than the orphan grace, pays the delete budget
12range-intentskips intents younger than 5 minutes
13range-splittime-ordered, one lease per stream
14range-mergeskips 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 afterState left behindWhat the re-run does
The lease is takenA session-bound claim and the markerThe claim ends with the session. A peer, or this auditor after a restart, leases the marker again.
A lease release failsA claim with no job behind itThe 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 deadlinePartial work and the markerThe job is cut with an error. The next pass runs it again from what is stored.
The seat is lost with the sessionNo seat. Peers take its shards.The next pass writes the seat again. Shards move back.
Withdrawal fails at exitA seat with no auditorIt 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

BoundDefaultSet by
Jobs at once2--auditor-workers
Jobs of one dutyHalf the workers, at least 1Fixed
Jobs that pay the delete budgetA quarter of the workers, at least 1Fixed
Job deadline10 minutesFixed
Pass length, and idle wait30 seconds eachFixed
Storage requests50 a second per auditor--auditor-s3-budget
Bytes moved by rewrites64 MiB/s per node--auditor-rewrite-mib
Deletes1,000 keys a second per bucket, shared by every live auditor--auditor-delete-budget
Reads10,000 a second per bucket, shared; 64 open per auditor--auditor-read-budget, --auditor-read-concurrency

Metrics:

  • nova.auditor.step.duration, by step
  • nova.auditor.due.age, by queue
  • nova.auditor.lease.skips, by queue. A lease whose key is not a marker key counts under queue="unknown".
  • nova.auditor.workers.active and nova.auditor.workers.limit
  • nova.auditor.owned.shards and nova.auditor.budget.wait
  • nova.audit.jobs.armed and nova.audit.jobs.resolved, by queue

Log lines:

  • auditor: running
  • auditor: ring seat lost with its session; re-announced
  • auditor left the ring; the seat is vacated
  • auditor: marker is malformed; resolving it away
  • auditor: job failed; the queue retries next pass
  • auditor: job held off after a backend throttle
  • auditor: 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, TestStuckJobStarvesNoOtherDuty in internal/auditor/dispatch_test.go.
  • Leases: TestJobsSkipLeasedEntries, TestJobsStealOwnLeakedLease, TestLeakedLeaseReleaseIsRetriedNextCycle in jobs_test.go, and TestJobDeadlineCutsAWedgedDuty in metrics_test.go.
  • The ring: TestShardOwnershipPartitionsTheFleet and TestOwnershipAbsorbsADeadNode in ring_test.go, TestRunRestoresASeatLostWithItsSession and TestRunRetriesARefusedAnnounce in seat_test.go, TestRunWithdrawsOnStop and TestRunWithdrawsOnCancel in withdraw_test.go.
  • Placement: TestDenormJudgeSkipsForeignLedgers in placement_test.go.

Go deeper

Operating the auditor: The auditor and Auditor delays. Design documents: Code map.

On this page