Due-queues

Due-queues

How background work is filed as due markers, made due, leased, and resolved.

A due marker is a metadata store key that names one piece of background work and when it becomes due. Work is filed, or armed, by the step that creates it, before that step removes anything the work needs, and a marker is deleted only after its work is durable. So a crash never loses work, and no auditor ever scans storage or metadata to find it.

Where it lives

FileWhat it holds
internal/metadata/keys.goThe marker key layout and the shard hash
internal/metadata/audit.go, dueindex.go, reapcheck.go, trimcheck.go, ledgers.go, starreclaim.go, rangechange.go, rangeintent.go, commit.go, denormmarker.goOne arm call per queue, and ResolveDue
internal/auditor/harness.go, cursor.goJudging and walking markers
internal/coord/claims.goThe session-bound claims used as job leases

Queue keys

Markers live in the queues keyspace. A time-ordered key is the queue, the subject's shard, a fixed-width order, then the rest that names the target:

internal/metadata/keys.go
func dueOrderedKey(jobType, subject string, order int64, rest string) string {
	return fmt.Sprintf("due/%s/%02d/%020d~%s", jobType, dueShard(subject), order, rest)
}

The shard is the FNV-32a hash of the subject, modulo 64. It hashes only the subject, so an escaped or suffixed rest still goes to its subject's shard. Object keys inside a marker replace / with !, which an object key cannot contain. A locality key keeps each queue shard on one metadata store shard.

QueueKey after the shardOrderPayloadArmed by
teardown{readyAtMs}~{stream}Ready timeThe deletion time, or for a scalable stream its range idsA stream's delete, a repeated delete, a create over a tombstone, the gate's re-arm
teardown-final{readyAtMs}~{stream}Ready time: the first walk plus 3 minutesThe deletion timeThe first teardown walk, and the duty's own re-arm after an expel
recovery{readyAtMs}~{star}~{epoch}Ready timeNoneEvery ledger mint, for the star's unindexed ledgers; a WAL open; a read of a vacant stream's end; a decommission; the duty's own deferral
retention{expiresAtMs}~{stream}ExpiryNoneA stream's first commit with an age limit, a scalable stream's creation, a reconfigure that adds an age, the duty's own re-arm
retention-check{stream}NoneNoneA writer passing a mark of its byte limit, a trim that empties a range, a reconfigure that sets a byte limit, an uncapped retention pass
reap{graceEndMs}~{object}Grace end, rounded up to 30 sClass, footer offset and length, confirmed, sharedRetention and teardown before they remove a ref; the probe's confirm; a rewrite's source; the orphan judge, already confirmed
trimcheck{graceEndMs}~{star}~{epoch}Grace endNoneEach settled denorm batch, a gc of a WAL-slot source, a star reclaim, the duty itself under storage pressure
star-reclaim{armedAtMs}~{star}~{force or cooldown}Arm time, never re-keyedThe next attempt time, after a deferralA decommission order, before it declares the star
denorm{star}~{epoch}~{firstSlot}Ledger positionBirth, ready time, class, slots, members, and moreThe span commit of every absorb, release flush, and recovery
gc{MaxInt64 − deadBytes}~{object}Biggest reclaim firstClass, footer offset and length, sharedThe probe, when an object's dead bytes pass the threshold
orphan!{object}Object keyClass and birth time, 9 bytesEvery publish of a stream object, before its upload
range-intent{attempt}NoneThe ranges and parents of one split, merge, or createA scalable stream's or queue's create, a split, a merge
range-split{readyAtMs}~{range}Ready timeThe range changeA hot range, a stranded node, a queue's noisy key, an operator, the duty's postpone
range-merge{range}, or {range}~forcedNone. Ready time is in the value.The range changeA range leader's departure, an operator, the duty's re-arm, a merge's new range

Two indexes sit beside the queues. The denorm-ripe index orders denorm markers by ready time, {shard}/{readyMs}~{marker}, so the walk can stop at the first one not due. The by-stream index lists the pending work of each stream for the admin API. A marker files at most 8 streams there, and shared marks a marker that names more than one. Deleting the marker deletes its entries in the same write.

Filing and resolving work

Change state and arm the marker Walk an owned shard in key order A ripe marker Take the job lease Read, publish, or delete CAS the result, arm the next marker Resolve the marker, release the lease Foreground step Metadata store Auditor Object storage
One marker's life. The next marker is written before the old one is deleted.
  1. A step arms a marker. Keys are deterministic and written without a version check, so arming twice writes one key. Denorm markers for one ledger merge by compare-and-set, keeping the earliest birth and ready time.
  2. The auditor that owns the shard walks it in key order and judges each marker. See the next section.
  3. It leases a ripe marker and runs the job.
  4. The job arms any follow-up work first, then resolves its own marker. To try again later, it writes a new marker at a later time, then deletes the old one.

Absorb arms denorm and retention right after its span commit, in the commit's aftermath, and only then moves the ledger's checkpoint. A crash between the commit and the arming leaves rows with no marker. The checkpoint has not moved, so the absorb runs again over the same slots, finds the rows standing with no marker, and arms one.

Pending and ready markers

A marker is standing from its creation until it is resolved, and ripe once its time has come. The walk treats a marker that is not ripe according to its queue's order:

  • Time-ordered queues stop the walk at the first marker that is not ripe, since every later one is younger: teardown, teardown-final, recovery, retention, reap, trimcheck, and range-split. The first entry is the oldest work, which feeds the nova.auditor.due.age gauge.
  • Denorm keys sort by ledger position, so the walk reads the denorm-ripe index and stops at its first future entry. It skips ledgers placed on another auditor, and ledgers already busy here.
  • star-reclaim and range-merge keep the ready time in the value. The walk skips a marker that is not due and goes on.
  • orphan and range-intent skip a marker younger than its grace: 1 hour and 5 minutes.
  • retention-check and gc run every marker they find.

teardown-final also stops the walk while the purge gate is closed. A marker too malformed to run is resolved without a lease, with a Warn, by teardown-final, recovery, star-reclaim, and the range duties. teardown and trim-check fail the walk instead, and the marker stays.

Tracking denorm progress

A denorm marker is keyed by its ledger and first slot, {star}~{epoch}~{firstSlot}, with both numbers zero-padded to 20 digits. Markers appear at rising positions as absorb passes run, and leave as denorm finishes them. The ledger's first standing marker is its denorm frontier, found with a one-entry prefix read. Every slot below it has been copied out.

Two jobs depend on the frontier:

  • Trim-check deletes slots up to the frontier, or up to the checkpoint when no marker stands.
  • Teardown's first walk waits while the frontier is at or below the deleted stream's last slot, so it never races a denorm that is still writing the stream. It makes those markers due at once and re-arms itself 5 minutes later. It reads each ledger's frontier at most once per window, so a burst of deletes on one ledger reads it once.

Recording objects before upload

Before it uploads a stream object, a denorm, a gc revision, or a tail extension writes a write intent under due/orphan/. Denorm resolves the intent once a ref names the object. A gc revision leaves its intent for the orphan duty to judge after the grace. A WAL slot needs no intent: its conditional write is the commit, and absorb files a denorm marker before it moves the checkpoint past the slot.

Keeping objects discoverable

A watcher is anything that makes an object findable: a ref, a write intent, or a marker. Every object has at least one at all times.

  • Retention, teardown, and tail extension arm a reap-check before they remove a ref they could not find again. A crash can leave the check early, and its probe finds live data and stops.
  • Denorm and gc keep their own marker until they finish, and arm the source's check before they resolve it.
  • A write intent is resolved only once a ref names its object. When another object already covers the output, the intent stays for the orphan duty.

Completing and rescheduling work

A marker is resolved only after its work is durable: a reap waits for the delete, denorm for its catalog commit, a walk for its ref removals. ResolveDue is a delete that succeeds when the key is already gone.

A duty that must try again writes the new marker first and deletes the old one second. A crash between them leaves duplicate work that converges. Deterministic keys merge repeated arming:

  • A reap-check rounds its grace end up to a 30 second bucket, so the removals of many refs to one shared object arm one check.
  • A trim-check is keyed by the exact time. Duplicates for one ledger run under one lease, and the run resolves every ripe check of its ledger.
  • Teardown keeps the original deletion time when it re-arms, so the queue's age shows how long the stream has waited.

Job leases

Before it runs a job, an auditor takes a session-bound claim under auditor/lease/{jobKey}. A held claim makes the walk skip the job. The claim ends with the job, with the session, or at the 10 minute job deadline. Leases cut duplicate work. The compare-and-set updates and the safe re-runs keep it correct.

A denorm era takes one lease for its ledger, ledger/{star}~{epoch}, instead of one per marker, which saves a write and a delete per marker. Ledger recovery takes its own claim, recovery/{star}/{epoch}, wherever it runs: in the auditor, in a producer's open, or in a read at a vacant stream's end.

Crash points

Crash afterState left behindWhat the re-run does
An absorb's span commit, before its aftermathRows with no denorm or retention markerThe absorb runs again below the unmoved checkpoint and arms them
ArmingA marker, maybe a second copy at the same keyWrites the same key again, or runs the work once
A follow-up is armed, before the ref removalAn early reap-checkIts probe sees a live ref and resolves without deleting
The job's work, before its resolveDone work and a standing markerRuns the job, finds nothing left, and resolves
A re-arm, before the old marker's deleteTwo markers for one jobBoth run, and the second finds nothing to do
An upload, before its refA write intent and an objectThe orphan duty judges the object after the grace

Bounds and signals

BoundValue
Shards per queue64
One walk page64 markers or 256 KiB
Streams filed per marker in the by-stream index8
Denorm member list in one marker64 KiB
Reap-check bucket30 seconds

Signals:

  • nova.audit.jobs.armed and nova.audit.jobs.resolved, by queue
  • nova.auditor.due.age, by queue, for the time-ordered queues and denorm
  • nova.auditor.lease.skips, by queue
  • Log auditor: marker is malformed; resolving it away
  • Log auditor: queue walk failed; the shard retries next pass
  • Log auditor: job lease contended past the grace; the holder may be wedged

Tests

  • Keys and resolve: TestScanDueAndResolve, TestOldestDueReady, TestArmReapCheckCollapsesWithinTheGraceBucket in internal/metadata/audit_test.go; TestPendingAuditJobsFanOutCapped in dueindex_test.go.
  • Denorm scheduling: internal/metadata/denormschedule_test.go; TestEraSkipsALedgerLeasedElsewhere and TestGatherRoundHonorsTheByteBudget in internal/auditor/era_test.go.
  • The frontier gate: TestTeardownFirstWalkWaitsBehindTheDenormFrontier in teardown_test.go, TestAStormOfOneLedgersStreamsReadsItsFrontierOncePerWindow in teardowngate_test.go.
  • Crashes: TestCrashEnumerationOrphanToReapConverges, TestCrashEnumerationRetentionConverges, and TestTeardownWalkMutationsConverge in internal/auditor/crash_test.go.

Go deeper

Why work is filed instead of found: Background work.

On this page