Expand description
dendro is a segmented Parquet archive with a write-ahead log, in a single SQLite file. It is for append-heavy, time-ordered data that has to stay readable while it is still being written.
Parquet is a batch format. A file is unreadable until its footer lands, so a process that stops with a batch still open loses that batch. Shortening the batches puts less at risk and costs read performance and space: on one body of data, 400 segments instead of one read 18.2x slower and took 2.38x the space, because every segment carries its own footer and compression cannot cross a segment boundary.
dendro separates the two. Rows land in a write-ahead log, and a committed row is durable and readable at once; the WAL is not a staging area you flush before the data counts. When the caller decides a stream has accumulated enough, it seals those rows into an immutable Parquet segment. dendro never seals on its own. Readers union the sealed segments with the live WAL tail, so they see a consistent view while another process goes on appending.
Durability then belongs to the commit and segment size belongs to the seal, and you can choose them independently.
Two things here are write-ahead logs. The archive’s WAL is the wal table
inside the SQLite file, which holds unsealed rows and which readers query.
SQLite’s WAL is the -wal file it writes commits into before folding them
into the main file; these docs call that file the sidecar.
§Vocabulary
The model has four nested parts:
archive → stream → segment → row
| term | meaning |
|---|---|
| archive | The file. One SQLite database, holding everything below. One file at rest once finished and read, three while it is open; see archive. |
| stream | A named sequence of rows inside a source. Streams are independent: each accumulates, seals and expires on its own schedule. They are also transient: one can start late, stop early, have gaps, and stop existing once its rows are evicted. |
| segment | An immutable Parquet BLOB holding one sealed run of a stream’s rows. A stream is many segments end to end. |
| row | One payload with a timestamp and a wall-clock offset. The timestamp is an i64, SQLite’s only integer type, so negative means before 1970. The payload is opaque to dendro. |
Plus five that are not containers:
| term | meaning |
|---|---|
| source | The namespace a stream belongs to: one producer, one clock domain, one label set. cpu from host=web-01 and cpu from host=web-02 are two streams in two sources. Most archives have exactly one; several when you record two hosts or two arms into one file. |
| WAL | The wal table rows land in. Durable and readable immediately; not a staging area you have to flush before the data counts. |
| seal | Turning a stream’s accumulated WAL rows into a segment. |
| tail | The live WAL rows past a stream’s newest segment, materialized on read. |
| catalog | The SQLite tables describing sources, streams and segments. It is what makes retention and range reads indexed lookups rather than scans. |
| index | The caller’s, not dendro’s: an opaque blob stored beside a segment (Segment::index) that the archive never reads. The catalog knows a segment’s stream and span; anything finer lives here. |
| caller store | Also the caller’s: opaque rows kept against (stream, ts) (archive::CallerRow), read by range, evicted with the segments, and untouched by compaction. For what must survive a merge, which a per-segment index cannot. |
| encoder | The caller’s SegmentEncoder. The only thing that knows what a row means. |
| document | Named JSON belonging to the archive rather than to a source (archive::Document): a saved view, a report’s selection. Revisions are appended, never overwritten. The copies this crate makes carry them; replication does not (FORMAT.md §3.6). |
A source is a namespace. It makes a stream name unambiguous and gives
its rows a shared wall-clock anchor: row timestamps are
anchor + monotonic elapsed, so one source is one clock. It is not a
level of the nesting above, because nothing is stored in a source that is
not in one of its streams.
A stream is derived from its rows. There is no streams table: a
stream is a name that rows in segments and wal carry, and the set of
streams is derived by Archive::all_streams, which unions those two columns.
This has three consequences:
- A stream needs no declaration. It exists from its first row.
- A stream has no lifetime of its own. It can begin partway through a source, stop before the source does, and leave gaps. Nothing in the container says otherwise, and nothing records what its span was meant to be.
- A stream can stop existing. Once its segments and WAL rows are gone
(retention removes the segments and the rows they cover,
discard_live_rowsthe live rows) it vanishes fromall_streams, and the archive keeps no record that it was ever there. Reusing the name later starts a new one.
The nesting is therefore about containment, not lifetime: an archive holds what its sources’ streams currently hold, and nothing more.
The model contains nothing about metrics, samples, series or observations. dendro came out of a telemetry agent and fits telemetry, but the container does not know that and must not learn it.
§The boundary
dendro does not know what a row means. A row is bytes, a timestamp and
a wall-clock offset; turning a batch of them into a Parquet segment is the
caller’s job, expressed as a SegmentEncoder. That is the whole schema
boundary. The archive owns storage, cataloging, retention, checkpointing
and segment mechanics, and the caller owns what is in the columns.
Two consequences matter for implementers:
- An encoder must work from the rows alone. Both the writer (when it seals) and a separate reader (materializing a tail out of an archive another process is appending to) call it, and the reader has none of the writer’s in-memory state. Anything an encode needs must travel in the rows.
- An encoder may drop a leading or trailing run of rows it cannot decode on
their own, such as rows that reference a schema anchor. It may not drop
from the middle: the prune deletes every WAL row up to the segment’s
last_ts, so a hole inside that span is rows left in no segment and no WAL. The writer checks this by counting, and refuses a segment whose span does not hold exactly the rows it claims.
A reader without the caller’s encoder reads sealed segments only. Any Parquet reader opens those; the live tail is unencoded rows.
§Shape of the API
Writing goes through writer::Writer, which owns the single writing
connection on its own thread:
let mut writer = Writer::create("out.dendro".as_ref(), Box::new(MyEncoder))?;
let mut source = writer.add_source(seed)?;
source.wal(rows)?; // durable, and readable now
source.seal(vec!["temps".to_string()])?; // -> one parquet segment
source.finalize((0, 0))?;
writer.join()?;Reading hands back Parquet bytes. dendro does not open them and has no
opinion about the query engine that will; see read::read_archive.
A archive::Archive reads. Every write to the catalog and the WAL is a method on
archive::ArchiveMut: archive::ArchiveMut::create for a new archive, and
archive::ArchiveMut::open for an existing one, which takes the file exclusively
and is refused while a writer thread, a reader, or another ArchiveMut holds
it. So a caller cannot write to an archive behind its writer’s back.
§One file, or three
An archive is three files while anyone has it open: SQLite adds a -wal
and a -shm whenever the file is opened, a read included. Any writing
handle also leaves an empty -lock file beside it, which holds no data and
which a copy does not need. The last
read-write connection to close removes them; a read-only one leaves them.
archive::Archive::open reads a finished archive (at least one source,
every source finalized) on a read-write connection with query_only set,
so a finished archive is one file once a read handle opened after the
finalize closes last. A reader opened before the finalize is read-only,
and when it closes last the sidecars stay until the next read. An unclean
kill leaves all three.
Creation checkpoints the catalog into the archive, so the archive alone
always opens; every commit since the last checkpoint is in the sidecar
until something opens the set and folds it back in.
dendro does not rewrite an unfinished archive on its own. It does not migrate an older schema in place, and it does not normalize a crashed one. An open is how you read a buffer another process is still appending to, and a reader that rearranges its subject cannot be pointed at production.
SQLite does rewrite, and the distinction matters. A read-write connection
that is the last one open checkpoints on close, so archive::ArchiveMut::open
on a crashed archive folds the sidecar back in and deletes it: measured at
64 KiB to 80 KiB, with a 3.3 MB sidecar, from nothing but an open and a
drop. That is recovery, and it is intentional: ArchiveMut::open takes the
file exclusively. A reader must never do it by surprise, so
archive::Archive::open opens an archive with an unfinished source
read-only and writes nothing to it. On an archive that is finished both
when it opens and when it closes, its close can fold committed rows of
finished sources into the file. Use it
for anything pointed at a live buffer, at an artifact you do not own, or
at read-only media, where ArchiveMut::open is refused by name.
§Where dendro sits
dendro is a two-level log-structured merge tree whose memtable is a SQLite
table and whose sorted files are Parquet BLOBs in the same file. DESIGN.md
in the repository places it against RocksDB, Prometheus, InfluxDB,
TimescaleDB, Apache Hudi and the lakehouse table formats, and lists what
the single-file design costs: one host and one writer, a tail readable only
through the encoder, a measured 3.14x write amplification, and large BLOBs
in 4 KiB SQLite pages.
Re-exports§
Modules§
- archive
- The container: schema, catalog, and every statement that touches SQL.
- error
- What can go wrong. Errors returned by archive operations.
- keys
- Reserved
sources.metadatakeys. - read
archive - Resolving an archive to segment bytes, live tail included. Reading an archive: a stream’s segments, oldest first, with its live WAL tail spliced on as the newest one.
- replicate
- An archive’s contents as a stream of frames, and the applier that turns them back into an archive.
- rewrite
archive - Combining, trimming and time-bounding archives, and compacting their segments. Rewriting an archive: combining, trimming and time-bounding it, and compacting its segments.
- seal
- When to seal. When to seal: the policy that decides how long a stream’s rows accumulate in the WAL before they become a segment.
- segment
archive - Segments, and the encoder boundary. Segments: what a stream’s rows become when they are sealed, and the boundary across which dendro does not know what a row means.
- writer
write - The writer thread.