Time-series · Engineering
Retention, tombstones, and compaction
Why deleting time-series rows does not shrink data.mdb, how deletion bitmaps work, and when to compact.
Deleting data feels like it should free disk. In an LMDB-backed database, it usually does not — at least not immediately. Pages become reusable, but the file keeps its high-water mark.
Time-series retention makes this visible because the workload deletes a lot of rows on a schedule.
Retention
A time-series collection can set expireAfterSeconds relative to the event time. Expired rows are hidden immediately from reads. Sealing drops them from the sealed payload.
Retention is not a separate storage engine. It uses the normal delete path, including history tombstones if history is enabled. A collection can set purge_history to delete stored revisions instead.
The maintenance worker runs retention periodically. The schedule is controlled by daemon settings, and a manual pass can be triggered through the CLI or API.
Tombstones and bitmaps
Deleting a row does not rewrite the whole bucket immediately. The delete sets a bit in a per-bucket deletion bitmap. Reads skip those rows; the values are cleared on the next bucket rewrite.
The bitmap is compact: one bit per row. A thousand deleted rows cost 125 bytes, not a thousand tombstone keys. That is a deliberate trade: deletion is cheap, and space is reclaimed later.
Older releases used separate tombstone keys; reads accept both formats, and any write or seal folds the old keys into the bitmap.
Why the file does not shrink
LMDB is copy-on-write. A write allocates new pages and publishes a new root. Pages freed by deletion can be reused by later writes, but the file is not truncated. The high-water mark remains.
This is true for ordinary collections too; time-series just makes it more obvious because retention deletes a large fraction of the data.
A compacting copy walks the live tree and writes a new file with only reachable pages. That is how the file shrinks. It is a whole-database operation, not a per-collection one.
How to compact
Stop the daemon and run:
nonodb-cli compact /var/lib/nonodb/defaultThe command copies data.mdb through LMDB’s compacting copy, fsyncs it, swaps it in, and keeps data.mdb.before-compact until the swap succeeds. It refuses to run against a live environment.
A backup is often safer on a primary:
nonodb-cli --db app1 backup /var/lib/nonodb /var/backups/nonodb/app1The backup path uses a compacting copy without touching the source. Restore it to reduce the live file size.
The daemon can also run online compaction when the database is idle. That is convenient, but it is still a copy; plan for the extra disk and I/O.
The numbers to read carefully
In the 100k-row benchmark:
| Form | Size | Bytes/row |
|---|---|---|
| Standard collection, no indexes | 41.59 MB | 436.1 |
| Time-series, sealed before compaction | 8.18 MB | 85.7 |
| Time-series, compacted copy | 1.02 MB | 10.69 |
| After deleting 25k rows, compacted | 1.02 MB | 14.3 |
| After retention leaves 37.5k rows, compacted | 0.54 MB | 15.07 |
The compacted copy is the smallest honest number. The live data.mdb after sealing is larger. Reporting only 1.02 MB without the compaction caveat would be misleading.
Deletes versus retention
- A delete by
_idsets a bitmap bit; the row is hidden immediately. - Retention removes a whole time window and uses the same bitmap path for the boundary bucket.
- Sealing rewrites the bucket and clears deleted values.
- Compaction reclaims the file space.
If you delete a lot and never compact, the file stays large. If you compact during a write-heavy period, you pay for the copy. Schedule it.
Operational checklist
- Set retention before the collection grows.
- Monitor disk usage and the high-water mark.
- Use backup/restore or
compactrather than expecting deletes to shrink the file. - Keep enough free space for a compacting copy.
- Test restore and search after compaction.
- Do not edit LMDB files manually.
The time-series disk usage and operations guide cover the exact commands and compaction behavior.