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
| File | What it holds |
|---|---|
internal/metadata/keys.go | The 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.go | One arm call per queue, and ResolveDue |
internal/auditor/harness.go, cursor.go | Judging and walking markers |
internal/coord/claims.go | The 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:
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.
| Queue | Key after the shard | Order | Payload | Armed by |
|---|---|---|---|---|
teardown | {readyAtMs}~{stream} | Ready time | The deletion time, or for a scalable stream its range ids | A 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 minutes | The deletion time | The first teardown walk, and the duty's own re-arm after an expel |
recovery | {readyAtMs}~{star}~{epoch} | Ready time | None | Every 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} | Expiry | None | A 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} | None | None | A 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 s | Class, footer offset and length, confirmed, shared | Retention 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 end | None | Each 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-keyed | The next attempt time, after a deferral | A decommission order, before it declares the star |
denorm | {star}~{epoch}~{firstSlot} | Ledger position | Birth, ready time, class, slots, members, and more | The span commit of every absorb, release flush, and recovery |
gc | {MaxInt64 − deadBytes}~{object} | Biggest reclaim first | Class, footer offset and length, shared | The probe, when an object's dead bytes pass the threshold |
orphan | !{object} | Object key | Class and birth time, 9 bytes | Every publish of a stream object, before its upload |
range-intent | {attempt} | None | The ranges and parents of one split, merge, or create | A scalable stream's or queue's create, a split, a merge |
range-split | {readyAtMs}~{range} | Ready time | The range change | A hot range, a stranded node, a queue's noisy key, an operator, the duty's postpone |
range-merge | {range}, or {range}~forced | None. Ready time is in the value. | The range change | A 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
- 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.
- The auditor that owns the shard walks it in key order and judges each marker. See the next section.
- It leases a ripe marker and runs the job.
- 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.agegauge. - Denorm keys sort by ledger position, so the walk reads the
denorm-ripeindex 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 after | State left behind | What the re-run does |
|---|---|---|
| An absorb's span commit, before its aftermath | Rows with no denorm or retention marker | The absorb runs again below the unmoved checkpoint and arms them |
| Arming | A marker, maybe a second copy at the same key | Writes the same key again, or runs the work once |
| A follow-up is armed, before the ref removal | An early reap-check | Its probe sees a live ref and resolves without deleting |
| The job's work, before its resolve | Done work and a standing marker | Runs the job, finds nothing left, and resolves |
| A re-arm, before the old marker's delete | Two markers for one job | Both run, and the second finds nothing to do |
| An upload, before its ref | A write intent and an object | The orphan duty judges the object after the grace |
Bounds and signals
| Bound | Value |
|---|---|
| Shards per queue | 64 |
| One walk page | 64 markers or 256 KiB |
| Streams filed per marker in the by-stream index | 8 |
| Denorm member list in one marker | 64 KiB |
| Reap-check bucket | 30 seconds |
Signals:
nova.audit.jobs.armedandnova.audit.jobs.resolved, by queuenova.auditor.due.age, by queue, for the time-ordered queues and denormnova.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,TestArmReapCheckCollapsesWithinTheGraceBucketininternal/metadata/audit_test.go;TestPendingAuditJobsFanOutCappedindueindex_test.go. - Denorm scheduling:
internal/metadata/denormschedule_test.go;TestEraSkipsALedgerLeasedElsewhereandTestGatherRoundHonorsTheByteBudgetininternal/auditor/era_test.go. - The frontier gate:
TestTeardownFirstWalkWaitsBehindTheDenormFrontierinteardown_test.go,TestAStormOfOneLedgersStreamsReadsItsFrontierOncePerWindowinteardowngate_test.go. - Crashes:
TestCrashEnumerationOrphanToReapConverges,TestCrashEnumerationRetentionConverges, andTestTeardownWalkMutationsConvergeininternal/auditor/crash_test.go.
Go deeper
How the auditor runs
The ring, the discovery pass, and the duty harness
Duties
What each queue's job does
Reclamation
Rewrites, probes, and two-stage deletes
Why work is filed instead of found: Background work.