Trimming
A trim makes a stream's oldest records unreadable by moving its trim watermark forward.
Trimming makes the oldest records of a stream unreadable. You give a point, and Nova moves the stream's trim watermark, the first sequence number a reader can still read, up to it. Records below the watermark become unreadable at once. After a trim to sequence number 2, a read from 0 is refused:
{
"error": "reader: read 01a20484-c2b1-76ab-ae91-978e3924ba73 from 0 below the watermark 2: reader: entries trimmed"
}Use a trim when your application decides that records are no longer needed, for example once it has saved a snapshot of the state they built. To drop records by age or size without code, use retention, which trims for you.
What a trim does
A trim takes one of three points:
| Point | Makes unreadable |
|---|---|
| A sequence number | Every record before it |
| A timestamp | Every record stamped before that time |
| A bookmark | On each range a bookmark names, every record before its place there |
The watermark only moves forward, and never past the tail. A trim behind the current watermark changes nothing, so a retry is safe. A trim past the tail makes every record unreadable and leaves the tail where it was. The new watermark applies when the trim returns.
A trim cannot be undone. It does not free storage by itself: Nova deletes stored records only below the point the stream's retention sets, or when you delete the stream. On a stream without retention, trimmed records stay in storage until you delete the stream. Background work explains why.
A token needs the trim permission to trim; permission to append or read does not include it. See API keys and tokens.
On a scalable stream, a sequence number has no meaning across ranges, so you trim to a time or a bookmark. A time trims every range.
Sequence numbers after trimming
A trim does not renumber anything. After a trim below 1,000, the first record is still number 1,000, and the tail and the next sequence number stay the same. A sequence number you saved keeps pointing at the same record for as long as that record exists.
Reads below the watermark
A read or subscription that starts below the watermark fails: 410 Gone over HTTP, OUT_OF_RANGE over gRPC. A subscription that falls behind and needs records that were trimmed ends with the same error.
To start at the oldest record still kept, ask the read to clamp, or read from the beginning. A reader that may fall behind a trim should clamp and then check, from the sequence numbers, whether it skipped records.
How it works: Background work.