Stream objects and denorm
How the auditor copies each stream's records out of shared transit bundles into stream objects of its own.
Denorm copies a stream's records out of the shared transit bundles in a node's WAL and into stream objects, which hold one stream each. Long reads and retention then work per stream, and the WAL's slots can be deleted. While denorm runs, every record a reader can reach keeps a valid reference: a span ref into a WAL slot, or a catalog entry into a stream object. A slot is deleted only after every stream it carries has been copied out.
Denorm is an auditor duty. It runs in the background, after acknowledgement, and moves bytes only between objects. See Background work for why records are written twice.
Where it lives
| Code | What it owns |
|---|---|
internal/auditor/denorm.go | The denorm duty: which markers are ripe, the era of one ledger, the one-era-per-ledger lock |
internal/storage/rewrite/streamdenorm.go | Mover: judging a marker, planning its streams, and moving each stream's window |
internal/storage/rewrite/era.go | Warming an era's slots into the fetch cache |
internal/metadata/denormmarker.go | The batch marker: arming at absorb, merging, the ripe index |
internal/metadata/catalog.go | CommitCatalog: the swap from span rows to a catalog row |
internal/auditor/pincap.go, trimcheck.go | The pin cap, and the trim-check that deletes copied slots |
The data
The batch marker
Each absorb arms one batch marker for the slots it covered. The marker is the denorm work item.
due/denorm/<shard>/<star>~<epoch>~<firstSlot> in the queues keyspaceAll markers of one ledger land in one shard, keyed by first slot, so the trim-check reads a ledger's open work as one bounded prefix scan. A secondary index, denorm-ripe, orders the markers by ready time, and the duty walks it.
type DenormBatch struct {
Star stream.StarID
Epoch stream.Epoch
Layout objectkey.SlotLayout
Class objectstore.Class
Birth time.Time
Ready time.Time // when the marker becomes denorm work
Crossed bool // ripened by a size crossing
AbsorbedBefore uint64 // the ledger's absorbed bytes before the first slot
AbsorbedKnown bool
Slots []DenormBatchSlot
Members []DenormMember // the batch's streams and their records, when known
}The schedule
A marker's ready time is the earlier of two clocks:
| Trigger | Ready at | Default |
|---|---|---|
| Age cap | Birth plus the class's age cap | 24h Standard (--denorm-age-cap), 1h Express (--express-denorm-age-cap) |
| Size crossing | The crossing plus the linger | 5m (--denorm-linger) |
A size crossing happens when a stream's running byte total passes a multiple of 8 MiB. Absorb sees it when it writes the span row and sets Crossed on the batch's marker. Busy streams are therefore copied minutes after they fill 8 MiB, and quiet streams at the age cap. Express has the shorter cap because express storage costs more per byte held.
The catalog row
A catalog row replaces a run of span rows at the same key, streams/<id>/refs/<firstSeq>. It lists up to 128 stream objects, ascending and tiling the range from its first sequence number. Each entry holds the epoch, the first sequence number, the revision, the footer range, the bytes, the time bounds, and the class, and the object's key follows from these. A read finds either kind of row with the same floor lookup.
Building stream objects
A denorm job takes an era of one ledger's markers, decides which streams still need copying, and copies each of them into stream objects. Each object it writes follows the commit protocol, so the job can retry after a crash at any step.
One job, step by step
- Pick a ripe marker. The duty walks the
denorm-ripeindex across every shard and stops at the first marker that is not yet ready. A placement hint gives each ledger to one auditor. A marker of a ledger placed elsewhere is left for its owner. - Gather an era. An era is a run of ready markers from one ledger. The job takes a lock on the ledger, so only one era per ledger runs in the fleet. It gathers up to
--auditor-markers-per-eramarkers (1 by default), and for up to half its deadline it adds markers of the same ledger that become ready. - Judge each marker. The job reads the marker's members, or the footers of its slots by ranged GET when the marker has none. For each stream it checks whether span rows still stand over those records. Streams deleted meanwhile belong to teardown: before it loads any of a stream's window, the job reads the stream's registry row fresh, so a deleted stream is never read or downloaded. A marker with nothing left resolves without downloading a body.
- Plan. A plan takes at most 2,048 streams. After a size crossing, only streams with at least 8 MiB waiting join it, so a small stream never takes a place. A stream's plan covers its whole transit window: every span row standing from its oldest uncopied record, across later markers too.
- Warm. With
--auditor-fetch-cache-dirset, the job downloads the slots it needs into its scratch cache, at most 2 GiB per sub-era, so many streams share one download. - Move each stream. Up to
--auditor-member-parallelstreams (8) move at once. A stream first extends its last stream object toward--denorm-output-cap-mib(256 MiB), then writes full-size objects from whole span rows. Each output follows the commit protocol below. - Finish the marker. When every planned stream is done, the job arms a trim-check one read grace out (
--auditor-read-grace, 10 minutes by default) and removes the marker.
When ready streams remain past the 2,048, the marker stays ready and the job plans the next 2,048 while its time lasts. When only streams under 8 MiB remain after a crossing, the marker is rescheduled at the age cap with Crossed cleared.
The commit protocol
Each output object goes through four steps:
newKey := objectkey.StreamObject(bucket, id, epoch, window[0].First)
if err := rw.spans.PrepareObject(ctx, newKey, objectstore.ClassStandard); err != nil {
return metadata.CatalogEntry{}, 0, err
}
size, standing, err := standingSize(ctx, dst, newKey)
// ...
if standing {
return rw.adoptStanding(ctx, dst, newKey, size, id, epoch, window[0].First, relocs)
}
desc, stats, err := rw.relocateWithRetry(ctx, src, dst, newKey, relocs)- Intent.
PrepareObjectwrites an orphan intent,due/orphan/<shard>/!<escaped key>, before the object exists. An object that no reference ever names is found through it. - Publish once. The key derives from the first record the object covers. If the object already stands, an earlier run published it and was cut short: the job checks the standing footer against the records it wants and adopts it. Otherwise it assembles the object and creates it with
If-None-Match: *. Losing that race also leads to adopting the winner's object. - Swap the catalog.
CommitCatalogwrites the catalog row. Extra pages of a large window land first. Then the row at the window's first sequence number replaces the span row there by CAS, which makes the copy visible. The covered span rows are then deleted in ascending order. - Resolve the intent. The orphan intent is removed, because a reference now names the object.
Assembly uses server-side range copies for extents of at least 5 MiB, inside a multipart upload. An object with no such extent, up to --s3-single-put-max (64 MiB), streams its ranges and footer as one conditional PUT instead. Larger objects upload their smaller ranges as multipart parts. Chunk bytes and checksums are kept; the footer is rebuilt.
Budgets and memory
A stream moves in groups, each the span rows that become one output. Before its first group, the job may extend the stream's last object with the leading rows. Each group and extension pays two per-auditor budgets, the rewrite budget for bytes (--auditor-rewrite-mib) and the request budget (--auditor-s3-budget), and holds a share of the denorm memory budget while it moves.
Booking before a byte moves
Before any of its bytes move, the job prices a group's or an extension's whole cost and books it on both budgets. The bytes are the output (the rows, plus the last object for an extension, plus a bound on the footer and trailer it seals) and the slots it must download first: those the fetch cache holds neither on disk nor in flight. The requests are two for each of those slots, one for each slot extent read when reads go direct, and two for publishing the output.
A booking tells the job how long the budgets would make it wait. The job takes it only if the wait, plus twice the group's estimated time, fits in what is left of the job's deadline past a reserve of a twentieth of it (30 seconds of a 10-minute job). A group of one row is taken as long as the wait leaves it at least half that time. When a booking does not fit:
- A group shrinks to the rows the time left after the wait still covers, and books again.
- When not even one row fits, the job pauses. It ends with every committed group kept, and the marker stands for the next job.
- An extension of the stream's last object is planned again over fewer slots. Once it can no longer double the last object, it is dropped, and its rows land as an object of their own with the groups that follow. An extension never pauses the job: it is planned at the job's whole slot budget, so any wait outruns it, and every later job would plan the same extension and pause on it again.
nova.auditor.denorm.budget_holds counts each outcome: shrunk, paused, or dropped. A climbing paused count means the budget, not the work, sets how fast denorm drains. A climbing dropped count means small objects pile up.
A granted booking reserves its cost, so the group's own charges draw on it and never wait. If another job took the tokens the price counted, the reservation's wait runs past what the job allowed. The reservation is then returned at once: a group's job pauses instead of failing, and an extension is dropped. Downloads that warm the fetch cache ahead of the groups queue on the budget no further ahead than a group may wait, half the time left past the reserve. A download the budget cannot grant within that is refused and holds nothing.
The memory budget
--auditor-denorm-memory-mib bounds the per-record state denorm holds at once, across every stream the auditor moves. A group holds about 64 bytes a record for its relocations and the footer it seals. Extending the last object adds about 80 bytes for each record already in that object, whose whole footer is read. A group or an extension waits for its share before it starts, and nova.auditor.denorm.memory_waits counts the waits. A share larger than the whole budget is cut to the budget, so a row that needs more still moves, alone. The default is a quarter of the container's memory limit, or 512 MiB without one, and a larger value is cut to the limit.
The pin cap
Slots are trimmed only below a ledger's earliest standing marker. A marker rescheduled at the age cap, for a stream that writes slowly, would therefore hold a busy ledger's slots for up to 24 hours. The pin cap prevents that. When 4 GiB of slots sit behind a ledger's earliest standing marker, and that marker is at least one linger old, the trim-check makes every standing marker of the ledger, up to its checkpoint, due at once. One denorm job then copies every held stream's remainder, and the trims move on. Both classes use the pin cap, and one ledger is released this way at most once per linger.
The denorm frontier
A ledger's denorm frontier is the first slot with a standing marker. It only moves forward. No denorm job ever writes data at a position the frontier has passed. The ledger's rewritten cursor follows it, and the trim-check deletes slots in [trimmed, rewritten) from every bucket after the read grace. See Reclamation for the trim.
Crash points
| Crash after | State left behind | What the re-run does |
|---|---|---|
| The intent | An intent; no object | Derives the same key and creates the object |
| The create | An object no reference names | Finds it standing, checks its footer, and adopts it |
| Extra catalog pages, before the pivot swap | Pages for the window's later objects; the span row at the window's start still stands | Writes the pages again, then swaps the pivot |
| The pivot swap | The catalog row is visible; covered span rows remain | Deletes the covered span rows, then resolves the intent |
| The intent's removal | The marker still stands | Judges the stream as covered and skips it |
| The trim-check arm, before the marker's removal | A trim-check and the marker | Judges every stream covered, arms the trim-check again, and removes the marker |
Every step is keyed by what it covers, so each stream resumes on its own.
Concurrency
- One era per ledger. The ledger lock keeps two auditors from copying the same ledger. Markers carry no leases of their own.
- Create-once outputs. Two jobs that derive the same key converge on one object. The loser adopts what the winner wrote.
- Absorb keeps writing. The live indexer commits new span rows above the window while denorm runs. A window covers only rows that stood when it was planned.
- Readers. A concurrent read finds either the span rows or the new catalog row. The pivot CAS switches one to the other in a single write.
- Recreated streams. A stream recreated under the same ID before its predecessor's objects are reaped can collide on a key. Denorm refuses to adopt an object another incarnation wrote, logs
rewrite: denorm refused a standing output another incarnation published; the marker waits for its reap, and waits.
Bounds and signals
| Bound | Default | Set by |
|---|---|---|
| Markers per era | 1 | --auditor-markers-per-era |
| Streams moving at once | 8 | --auditor-member-parallel |
| Output object size | 256 MiB | --denorm-output-cap-mib |
| Streams per plan | 2,048 | Fixed |
| Warmed bytes per sub-era | 2 GiB | Fixed |
| Pin cap | 4 GiB per ledger | Fixed |
| Per-record state held at once | A quarter of the memory limit, else 512 MiB | --auditor-denorm-memory-mib |
| Bytes and requests a group books | 64 MiB/s and 50 a second per auditor | --auditor-rewrite-mib, --auditor-s3-budget |
| Single-PUT limit | 64 MiB | --s3-single-put-max |
| Signal | What it shows |
|---|---|
nova.auditor.due.age{queue="denorm"} | How far past due the oldest marker is. A standing marker that is not yet due counts as zero. |
nova.auditor.denorm.bytes | Bytes moved, by outcome: published or adopted |
nova.auditor.denorm.spans | Span rows swapped, and markers resolved as already covered |
nova.auditor.denorm.budget_holds | Groups the budgets held, by outcome: shrunk, paused, dropped |
nova.auditor.denorm.memory_waits | Groups that waited for their share of the memory budget |
nova.auditor.pin_cap.pinned_bytes, nova.auditor.pin_cap.ripens | The most bytes a ledger pins, and pin-cap releases |
nova.denorm.stalled | The longest any ledger this auditor places has had a due frontier that did not move; zero when no frontier is due |
auditor: a ledger's denorm frontier has stood due past the stall bound | A ledger whose due frontier has not moved for 15 minutes |
NovaDenormBacklogAging alerts on the denorm queue's age, and NovaDenormStalled on a frontier that stopped moving. Age alone cannot tell a denorm that lags from one that is stuck. A slow denorm never slows appends; it keeps transit bundles longer. See Auditor delays.
Tests
internal/auditor:TestARetriedDenormAdoptsItsOwnOutput,TestADenormFaultedAtAnyCatalogMutationConverges,TestADenormWiderThanOneRunConvergesAcrossCuts,TestEraDenormsConsecutiveMarkersWithOneDownloadPerSlot,TestEraSkipsALedgerLeasedElsewhere,TestOverCapPlanDenormsAcrossRounds,TestTombstonedEraResolvesWithoutDownloading,TestPinCapReleasesATrickleHeldLedger,TestPinCapWaitsForTheLinger.internal/metadata:TestCommitCatalogCrashMidwayConverges,TestCommitCatalogRetiresTheCoveredSpanRows,TestCommitCatalogPaginatesWideWindows,TestCrossingRipensTheBatchMarkerAtTheLinger,TestDenormScheduleRipensByClass.tlaplus/ObjectLifecycle.tlamodels intents, publication, and reaping, withObjectLifecycle.mustfail-intent.cfgandObjectLifecycle.mustfail-onephase.cfg.