Duties

Duties

Each of the auditor's 14 jobs, with its trigger, steps, crash behavior, settings, and tests.

A duty is one family of auditor jobs, draining one due-queue. Each duty converges: run again after a crash at any step, it reaches the same state. The auditor registers 14 duties, in the priority order below. How the auditor runs describes the harness they share, and Reclamation the rewrite and delete steps several of them use.

Job summary

PriorityDutyQueueWhat it produces or removes
1TeardownteardownA deleted stream's refs and serving rows, behind the denorm frontier
2Final teardownteardown-finalThe deleted stream's tombstone, once the purge gate opens
3RecoveryrecoveryRefs over a stopped ledger's committed slots; garbage above its cut
4RetentionretentionThe trim watermark of an age limit, and the refs and objects below it
5Retention checkretention-checkA retention pass now, until a byte limit is met
6Reap-checkreapDead stream objects; gc markers for partly dead ones
7Trim-checktrimcheckWAL slots that denorm has copied out
8Star reclaimstar-reclaimA decommissioned node's ledger records and WAL keys
9DenormdenormStream objects from transit bundles
10Garbage collectiongcThe live part of a partly dead stream object, at a new revision
11OrphanorphanObjects whose upload never became visible
12Range intentrange-intentRanges an interrupted split, merge, or create never added to the map
13Range splitrange-splitA split of one open range
14Range mergerange-mergeA merge of cold neighbouring ranges

Jobs file each other's work:

Span commit Denorm Retention Trim-check Orphan Reap-check Retention check Teardown Final teardown GC Range split Range intent Range merge

Deleted-stream cleanup

Removes a deleted stream's refs and serving rows, without racing a denorm that may still be writing the stream.

ItemValue
Keydue/teardown/{shard}/{readyAtMs}~{stream}. The value is the deletion time, or for a scalable stream a record with its range ids.
Armed byDeleteStream after the tombstone, a repeated delete, a create over a tombstone, and the gate's re-arm
Job16 markers a job, 8 streams walked at once
  1. A scalable stream deletes each of its ranges as a stream of its own, each with its own tombstone and marker. A queue's dispatch rows and dead-letter stream go next, and its configuration row last.
  2. The walk reads the stream's refs once. It collects a reap-check for each stream object, and the last slot it uses in each ledger.
  3. The frontier gate. If a ledger's denorm frontier is at or below the stream's last slot there, the walk makes those markers due, re-arms itself 5 minutes later with the same deletion time, and resolves. It has armed and removed nothing.
  4. Otherwise it arms the reap-checks one read grace out, then removes all the stream's refs in one range delete. WAL slots need no reap-check, because trim-check deletes them.
  5. It deletes the trim watermark, producer row, last-writer record, and clean-release record.
  6. It arms the final teardown 3 minutes after this walk, and resolves.
internal/auditor/teardown.go
	if err := d.reclaim.ReclaimStream(ctx, id, d.gateOnFrontier); err != nil {
		if errors.Is(err, errGated) {
			return d.gateWalk(ctx, record, id, deletedAtMs)
		}

		return err
	}

	readyAt := d.now().Add(TeardownQuiesce)
	if err := d.due.ArmTeardown(ctx, id, readyAt, deletedAtMs, true); err != nil {

After a crash. Every step is idempotent, and every reap-check is armed before any ref is removed. A crash between the gate's re-arm and its resolve runs the old marker again, which gates again. A crash between the final arm and the resolve leaves two final markers, and each converges.

Signals. nova.auditor.teardown.gated counts gated walks. Debug lines: auditor: teardown first walk gated behind the denorm frontier, auditor: stream teardown walked; quiesce re-walk armed. Tests: TestTeardownFirstWalkWaitsBehindTheDenormFrontier, TestGatedRearmKeepsTheDeletionBirth, TestTeardownSparesACoBundledSurvivor, TestTeardownDeletesAScalableStreamsRanges, TestTeardownWalkMutationsConverge.

Final teardown

Purges the tombstone, and so frees the stream id, only when no node can still hold a record of the stream that is not indexed.

ItemValue
Keydue/teardown-final/{shard}/{readyAtMs}~{stream}, value the deletion time
Armed byThe first walk, and the duty's own re-arm after an expel
GateRead at most every 5 seconds, before the walk judges any marker

A commit that passed its checks before the delete can finish after it. The purge gate waits for those. It lists every ledger the recovery queue names and each live node's absorb watermark. For a delete at time D, the gate opens when three things hold:

  • its last read succeeded;
  • no node's clock runs more than 10 seconds ahead;
  • every ledger born by D plus 10 seconds is absorbed past that time.

A ledger with no published absorb watermark behind it holds every purge until the ledger is indexed: one whose node has departed, an earlier incarnation of a node, or a node that publishes none.

internal/auditor/purgegate.go
	bar := d.Add(absorbSkew)

	for _, b := range g.bounds {
		if b.born.After(bar) {
			continue
		}

		if b.through.IsZero() || b.through.Before(bar) {
			return false
		}
	}

	return true

While the gate is closed, the walk stops at the marker. When it opens:

  1. The job reads the stream's writer lease. If a node still holds it, a leadership survived the delete. The job deletes the stream again through that node, which ends the leadership, re-arms with the expel time as the new D, and resolves.
  2. With no lease, it checks for leftover refs with one scan. If any remain, it removes them, with no frontier gate.
  3. It purges the tombstone with a compare-and-set on its version, and resolves.

After a crash. A second purge finds the row gone. A failed expel leaves the marker. A failed gate read keeps the gate closed. A crash after an expel and before its re-arm runs the marker again with the original D, finds no lease, and purges. No test covers that window.

Signals. nova.auditor.teardown.expelled, nova.auditor.stars.clock_ahead. Warn: auditor: a star's clock runs ahead of this auditor's; teardown holds every purge until it is corrected, auditor: the fleet's absorb watermark could not be read; teardown holds every purge until it can. Tests: TestAPurgeWaitsForEveryStarToAbsorbPastTheDelete, TestADepartedStarsLedgerHoldsPurgesUntilIndexed, TestAStarClockAheadHoldsEveryPurge, TestTheReWalkExpelsASurvivingLeadershipBeforeItPurges, TestAReWalkRunTwiceConverges.

Recovery

Indexes a ledger that nothing else will: one left by a node that stopped, or superseded by its own node's newer ledger. Ledger recovery owns the walk itself.

ItemValue
Keydue/recovery/{shard}/{readyAtMs}~{star}~{epoch}
Armed byEvery ledger mint, for all the star's unindexed ledgers; a WAL open; a read at a vacant stream's end; a decommission; its own deferral
Claimrecovery/{star}/{epoch}, shared with every other recoverer
  1. A ledger that no longer exists resolves the marker.
  2. A node's newest ledger in a class is left alone while the node is alive: the job re-arms 5 minutes later. An absent node inside its mint grace gets a re-arm at the end of the grace.
  3. Otherwise the job runs ledger recovery: fence, index up to the cut, delete garbage above it, mark the ledger Indexed. Another recoverer's claim leaves the marker for a later pass.

After a crash. The marker stays until the ledger is Indexed, and the claim allows one walk at a time. Tests: TestRecoveryDutyResumesAKilledRecovery, TestRecoveryDutyDefersALiveStar, TestRecoveryDutySkipsAClaimedRecovery. Metric: nova.auditor.garbage.reaped.

Age retention

Trims records older than a stream's age limit, reclaims what lies below, enforces a byte limit, and prunes a scalable stream's exhausted ranges.

ItemValue
Keydue/retention/{shard}/{expiresAtMs}~{stream}
Armed byThe first commit with an age limit, at the ref's newest record time plus the limit; a scalable stream's creation; a reconfigure that adds an age, due at once; its own re-arm
SettingsThe stream's MaxAge and MaxBytes; --auditor-read-grace before object deletes
  1. A stream that is gone, or has no age limit, resolves the marker. The chain ends.
  2. The job lists the members: the stream itself, or every range in a scalable stream's map.
  3. For each member it finds the position at now − MaxAge and trims there if that is above the watermark. The trim goes through the member's leader when it has one, so the leader's watermark stays current, or straight to the metadata store when it is vacant. It then removes the refs below that point, on every pass.
  4. With a byte limit, it trims the oldest row across all members until the total is under the limit, at most 64 steps a pass.
  5. On a scalable stream, it prunes each sealed range whose watermark reached its end, unless a parent of it is still in the map. The prune deletes the range's stream, removes its queue rows, then drops it from the map with a compare-and-set.
  6. If the byte limit is not yet met, it arms a retention check. It re-arms at the earliest member expiry, or now plus MaxAge, then resolves.
internal/auditor/retention.go
	if point > trim {
		if err := d.trimmer.Trim(ctx, id, point); err != nil {
			return aged{}, err
		}

		d.log.Info("auditor: retention trimmed", "stream", id, "through", point-1)
	}

	if err := d.reclaim.ReclaimBelow(ctx, id, point, nil); err != nil {
		return aged{}, err
	}

Removal reaches only below the age point. A client trim past that point is reclaimed once the age point passes it, or when the stream is deleted.

After a crash. Watermarks only move forward, the reclaim runs on every pass to cover a crash between the trim and the reclaim, and the prune deletes the stream before it changes the map. Tests: TestRetentionTrimsExpiredSegmentsAndReclaims, TestRetentionReArmsForTheNextExpiry, TestRetentionRoutesTheTrimThroughTheTrimmer, TestCrashEnumerationRetentionConverges, and the tests in scalableretention_test.go. Log: auditor: retention trimmed, auditor: range pruned.

Retention check

Runs one retention pass now, outside the age chain, and stands until a byte limit is met.

ItemValue
Keydue/retention-check/{shard}/{stream}, one per stream
Armed byA writer each time a stream passes a mark of its byte limit (an eighth of it, at least 1 MiB); a trim that empties a range, for the range's parent; a reconfigure that sets a byte limit; an uncapped retention pass

The job resolves when the stream is gone or has neither an age nor a byte limit. Otherwise it runs the retention pass. If the pass met the byte limit, it resolves; if not, the marker stays for the next pass. It does not re-arm the age chain. A scalable stream with no limit at all resolves without a pass, so a trim that empties one of its ranges prunes nothing.

Tests: TestRetentionCapsAPlainStreamsBytes, TestRetentionByteCapIsBoundedPerPass, TestAppendsPastAMarkArmTheRetentionCheck, TestTrimEmptyingARangeArmsTheParentsRetentionCheck.

Object deletion checks

Decides whether a stream object can be deleted, needs a gc rewrite, or must stay. The probe and the two-stage delete are on Reclamation.

ItemValue
Keydue/reap/{shard}/{graceEndMs}~{object}, grace end rounded up to 30 seconds; value class, footer range, confirmed
Armed byRetention and teardown before a ref goes; the probe's own confirm; a gc or tail extension for its source; the orphan judge, already confirmed
Settings--auditor-read-grace, --auditor-delete-budget

The probe reads the object's footer and checks each chunk's ref. Its verdict is recorded under nova.auditor.probe.verdicts:

VerdictWhenAction
goneThe object no longer existsResolve
standLive chunks remain, below the gc thresholdResolve
gcLive chunks remain, and dead bytes reach 64 MiB and more than half the objectArm a gc marker, then resolve
observeEvery chunk is dead, and the marker is not confirmedArm a confirmed marker one read grace out, then resolve
confirm-reapEvery chunk is dead, and the marker is confirmedSpool the delete. The marker resolves when its batch is deleted.

After a crash. A marker resolves only after its batch delete succeeds, and the re-probe finds the object gone. Tests: TestReapCheckObservesThenConfirmsThenDeletes, TestReapCheckArmsGCPastTheThreshold, TestReapCheckStandsWhileAnySpanLives, TestConfirmedReapsDeleteThroughBatches.

WAL slot cleanup

Deletes the WAL slots that denorm has copied out, by cursor arithmetic, from every bucket of the ledger's class.

ItemValue
Keydue/trimcheck/{shard}/{graceEndMs}~{star}~{epoch}
Armed byEach settled denorm batch, one read grace out; a gc of a WAL-slot source; a star reclaim, due at once; the duty itself under storage pressure
Leasetrim/{star}~{epoch}, one run per ledger
  1. A ledger that no longer exists resolves the marker.
  2. The job moves the ledger's rewritten cursor to its first standing denorm marker, or to its checkpoint when none stands, with a compare-and-set.
  3. While the fleet reports storage pressure for the class, it re-arms after the hold and resolves.
  4. Otherwise it deletes the slots from trimmed to rewritten in batches of one second of the delete budget. After each batch it moves trimmed with a compare-and-set.
  5. The pin cap. If 4 GiB of the ledger's slots wait behind its first standing marker, and that marker is at least the denorm linger old, it makes every marker up to the checkpoint due at once. The linger is 5 minutes by default.
  6. It resolves, and resolves every other ripe trim-check of the ledger with it.

After a crash. Deletes ignore missing objects, both cursors refuse to move backwards, and trimmed moves after each batch, so a re-run resumes where it stopped. Metrics: nova.auditor.slots.trimmed, nova.auditor.pin_cap.ripens, nova.auditor.pin_cap.pinned_bytes. Log: auditor: ledger trimmed. Tests: TestTrimCheckStopsAtAPendingRewrite, TestTrimCheckRunsOncePerLedger, TestTrimCheckCutBetweenDeleteAndCursorConverges, TestPinCapIsFourGiB.

Retired star reclaim

Deletes a decommissioned node's ledger records and leftover WAL keys, without leaking a slot.

ItemValue
Keydue/star-reclaim/{shard}/{armedAtMs}~{star}~{force or cooldown}, never re-keyed, so the queue's age is how long the reclaim has waited
Armed bynova node decommission, before it declares the node retired
Leasestar-reclaim/{star}
  1. A node that is not retired is never touched. A marker under an hour old waits a minute. An older one is dropped and logged, and armed again if the node turns out to be retired by then.
  2. Unless the order chose --cool-down, the job makes the node's pending denorm work due now.
  3. Every ledger must be Indexed, or the job fails. A ledger with slots below its checkpoint waits a minute: one with a pending denorm waits for it, and one without gets a trim-check due now.
  4. It lists wal/{h}/{star}/{epoch}/ for every epoch the node minted, read from its mint counter, so a slot whose ledger record is gone is still found.
  5. It deletes the ledger records, keeping the mint counter, then lists wal/{star}/.
  6. Each listing deletes what it finds, except the fence marker of the node's last ledger in each class. A listing that finds a slot whose ledger still owes a denorm fails, and the job runs again.
internal/storage/reclaim/star.go
	if err := r.awaitTrimmed(ctx, star, ledgers); err != nil {
		return err
	}

	if err := r.sweepHashed(ctx, star, heads); err != nil {
		return err
	}

	if err := r.ledgers.Reap(ctx, star); err != nil {
		return err
	}

	return r.sweepPrefix(ctx, objectkey.StarSlotPrefix(star), heads)

Only the standard bucket is listed. After a crash, every step is idempotent, and the trim judgment cannot move back for a retired node, so a re-run finds only trimmed records. Log: auditor: retired star reclaimed, with how long it was held. The NovaStarReclaimHeld alert reads this queue's age. Tests: TestAStarReclaimNeverTouchesAStarStillServing, TestAStarReclaimCutAnywhereConverges, TestSweepReachesHashedLedgersWithoutTheirRecords, TestSweepKeepsThePoisonOfTheStarsLastEpoch.

Denorm

Copies each stream's records from transit bundles into stream objects. Stream objects and denorm owns the mechanism.

ItemValue
Keydue/denorm/{shard}/{star}~{epoch}~{firstSlot}, walked through the denorm-ripe index by ready time
Armed byThe aftermath of every span commit: absorb, a release flush, ledger recovery
LeaseNone per marker. An era leases its ledger, ledger/{star}~{epoch}.
Settings--denorm-linger, --denorm-age-cap, --express-denorm-age-cap, --denorm-output-cap-mib, --auditor-markers-per-era (1), --auditor-member-parallel (8), --auditor-fetch-cache-dir

The walk scans all 64 shards and skips ledgers placed on another auditor or already busy here. Before it loads any of a stream's window, the job reads the stream's registry row fresh, so a stream deleted meanwhile is never read or downloaded; its spans are teardown's. With --auditor-fetch-cache-dir, the auditor downloads each transit bundle once to local disk and copies every stream's share from it. A node with --audit=only on object storage refuses to start without that directory.

Garbage collection rewrites

Copies the live chunks of a partly dead stream object to its next revision, so the old object can be reaped.

ItemValue
Keydue/gc/{shard}/{MaxInt64 − deadBytes}~{object}, biggest reclaim first
Armed byThe probe's gc verdict
SettingsDead fraction 0.5 and at least 64 MiB, fixed; --auditor-rewrite-mib, --auditor-s3-budget
  1. A deleted stream, or a ref that no longer names this object, skips to step 4.
  2. The job reads the footer and the trim watermark, and keeps the stream's chunks that are not wholly below the watermark.
  3. It publishes them at revision plus one under a write intent, then replaces the catalog entry it expects, (epoch, first, revision), with a compare-and-set. A lost compare-and-set leaves the output for the orphan duty.
  4. It arms the source's reap-check one read grace out, or a trim-check for a WAL slot, then resolves.

After a crash. The source always gets its check before the marker resolves, and gc never resolves its output's intent, which the orphan duty clears. A crash between the upload and the catalog swap is not yet handled: the re-run derives the same key, finds the object there, and fails. Each failed run writes the intent again with a new birth time, so the orphan grace does not pass, and the job keeps failing. Tests: TestGCRewriteRevisesTheCatalogEntry, TestGCRewriteOnAWALSlotArmsTheTrimCheck, TestAGCReviseRacingATeardownLeavesNoObjectBehind, TestCrashEnumerationStreamObjectRewriteConverges.

Abandoned object cleanup

Judges stream objects whose write intent was never resolved.

ItemValue
Keydue/orphan/{shard}/!{object}, value class and birth time
Armed byEvery stream object publish, before its upload
Settings--auditor-orphan-grace (1 hour), longer than the slowest upload-to-commit

The walk skips intents younger than the grace. For an older one, the job reads the object:

FindingJudgment
No objectNothing to do
Shorter than a trailer, or a footer that does not decodeThe upload never finished: delete it
A chunk's ref names this object, and the stream is liveVisible: the normal lifecycle owns it
A whole object that no live ref namesArm a confirmed reap-check one read grace out

Then it resolves the intent. A read that fails leaves the intent for a later pass, so nothing is deleted on a partial read. Logs: reclaim: orphan reclaimed for a partial upload, reclaim: orphan handed to the reap. Tests: TestOrphanTrueOrphanIsReclaimed, TestOrphanGenuineCommitResolvesIntentOnly, TestOrphanUnreferencedObjectWaitsOutTheReadGrace, TestCrashEnumerationOrphanToReapConverges.

Range intent

Removes the ranges an interrupted split, merge, or create made but never added to the map.

ItemValue
Keydue/range-intent/{shard}/{attempt}, value the ranges, parents, and queue rows the attempt makes
Armed byA scalable stream's or queue's create, a split, a merge, before their first write
Settings5 minute grace, fixed
  1. The job reads the map. While a parent named by the intent is still open in it, the attempt may still finish, and the marker stays.
  2. For a queue create whose stream is not the queue, it deletes the queue's configuration and dead-letter stream.
  3. It deletes every range the map does not claim, through the node's stream deleter, and resolves.

Tests: TestRangeIntentDutyReapsUnclaimedRanges, TestRangeIntentWaitsWhileItsSplitIsUndecided, TestRangeIntentDutyReapsADeadQueueCreation. Log: auditor: dead attempt's ranges reaped.

Range split

Splits one open range of a scalable stream into children, through one change to its map.

ItemValue
Keydue/range-split/{shard}/{readyAtMs}~{range}
Armed byA range's leader over the split rate, a stranded node, a queue's noisy key with a point, an operator's forced split, the duty's postpone
Leaserange-change/{bucket}/{key}, one change per stream
Settings--range-split-mib (100 on Standard, 130 on Express), --range-split-window (1m); 1 minute cooldown and 256 ranges, fixed
  1. The job refuses and resolves when the stream is gone, the range is not in the map or is sealed, the point is invalid, or the children would pass 256 ranges. It counts the refusal by reason.
  2. A range younger than the cooldown is postponed to its end, unless the split is forced.
  3. It derives the children's ids and router tokens from the parent's id, arms a range intent, and seals the parent.
  4. For each child it installs the router token, then creates the range's stream. On a queue it files the children for dispatch.
  5. It changes the map with a compare-and-set: the parent sealed at its end, the children open. It then resolves the intent and the marker.
internal/auditor/rangesplit.go
	children, err := carve(parent, change.Point)
	if err != nil {
		return refuse("invalid-point", err.Error())
	}

	if len(rm.Ranges)+len(children) > int(rm.MaxRanges) {
		return refuse("cap", fmt.Sprintf("the map holds %d of %d entries: %d children would pass the cap", len(rm.Ranges), rm.MaxRanges, len(children)))
	}

	if ripe := parent.CreatedAt.Add(d.cooldown); !change.Forced && d.now().Before(ripe) {
		return d.postpone(ctx, record, change, ripe)
	}

	return d.split(ctx, record, change, rm, parent, children)

After a crash. The derived names make every step before the map change converge. After the map change, a re-run refuses with sealed, and the range-intent job finds nothing to remove. Metric: nova.auditor.range_split.refused by reason. Tests: TestRangeSplitDutySplitsAnOpenRange, TestRangeSplitDutySplitsThreeWayAtAPoint, TestRangeSplitDutyConvergesAfterACrashAtEachStep, TestSplitRefusalsAreCounted.

Range merge

Merges a cold range with a cold neighbour, or an operator's run of neighbouring ranges.

ItemValue
Keydue/range-merge/{shard}/{range}, or {range}~forced; ready time in the value
Armed byA range leader's departure, 5 minutes out and at most once per window; an operator's forced merge; its own re-arm; a merge, for the new range
Leaserange-change/{bucket}/{key}
SettingsWindow 5 minutes, cooldown 5 minutes, recheck 1 hour, all fixed
  1. The job refuses on a missing stream, an unmapped or sealed range, or a full map.
  2. A forced merge checks that the ranges are one contiguous run, then merges.
  3. Otherwise a range inside its cooldown re-arms at its end. A range with a leader re-arms an hour out. Without a leader, the first neighbour that is past its cooldown and has no leader is its partner, lower span first.
  4. The merge arms a range intent, seals each member, creates the new range, files it for dispatch on a queue, changes the map with a compare-and-set, and arms the new range's own check.

After a crash. As for a split. A crash after the map change leaves the new range without its check until its first leader departs. Tests: TestRangeMergeDutyMergesVacantNeighbours, TestRangeMergeDutyLedRangeWaitsForItsDeparture, TestRangeMergeDutyForcedMergesALedRun, TestRangeMergeDutyConvergesAfterACrashAtEachStep.

Related operations

A decommission is an admin operation. It recovers the node's ledgers, arms its reclaim, and records the node as retired; the reclaim happens afterwards. Extending a stream's small last object is part of denorm. Nothing runs a periodic full check: refs, markers, and intents name all unfinished cleanup.

Go deeper

Why the auditor owns these jobs: Background work.

On this page