06 · Dataset storage
Status: Implemented (T7) · compaction/expiry jobs (T16) · Owner: Platform ·
Code: engine/crates/flux-exec/src/lake.rs. Supersedes the
original storage design.
A dataset is a DuckLake table in schema main:
- Catalog: the standard DuckLake tables (
ducklake_snapshot,ducklake_table,ducklake_data_file,ducklake_file_column_stats, …) in Postgres. In the cluster that’s the enki databaseflux, schemaducklake; the catalog URL setsoptions=-c search_path=ducklake. - Data: immutable Parquet files at
{data_path}/main/{dataset}/, wheredata_pathiss3://flux-data/lake/in the cluster (object storage, ADR-0006), orfile:///…locally. - Snapshots: every commit creates a snapshot, so readers can time-travel to any of them.
The layout follows the DuckLake spec, so DuckDB’s ducklake extension can attach the same
catalog read-only for ad-hoc analysis.
Write protocol
Section titled “Write protocol”
flowchart LR
subgraph stage[Stage · per shard, invisible]
s1[sort by key] --> s2[stream to rolling Parquet files<br/>main/ds/flux-RUN-sNNNN-NNNNN.parquet]
s2 --> s3[manifest<br/>_flux/staging/RUN/ds/shard-NNNN.json]
end
subgraph commit[Commit · once per run]
c0{already committed?<br/>commit_extra_info = flux-run:RUN:ds} -->|yes| done[return snapshot]
c0 -->|no| c1[read all shard manifests]
c1 --> c2[read footers → column stats]
c2 --> c3[register files<br/>one catalog transaction]
end
stage --> commit
- Stage. The runner writes files directly (not through the DuckLake writer), which gives Flux control of the physical layout. Files roll over every ~4M rows. A manifest per shard lists files, rows and bytes.
- Commit. Reads every shard’s manifest; a missing shard fails the commit. Shard schemas
must match. Two small ranged reads per file fetch the Parquet footer, from which
min/max/null statistics are computed. Then all files are registered in one catalog
transaction with
commit_extra_info = flux-run:<run>:<dataset>. - Idempotency. Before committing, the tag is looked up. A retried commit returns the existing snapshot and writes nothing.
- Abort. A failed run deletes its staged files and manifests. Anything left behind by a crash is unreferenced and is removed by the orphan-file cleanup (T16).
Files carry no Parquet field ids; DuckLake reads them by column name. Column ids are assigned by the catalog at commit time, which keeps shards independent.
Write modes
Section titled “Write modes”| Mode | Effect |
|---|---|
replace |
New files become the table’s only live files. Conflicts with a concurrent writer abort the commit |
append |
New files are added |
upsert |
Rows whose key appears in the new data are replaced; others are kept. v1 computes (existing − new keys) ∪ new and commits it as replace (conflict-checked). Sharded upserts merge per shard and need the shard key in the dataset |
Empty replace guard: a replace run that produced zero rows fails instead of emptying
an existing dataset. That’s almost always a broken extract, not an intent to delete.
Physical layout (for point reads)
Section titled “Physical layout (for point reads)”| Setting | Value | Why |
|---|---|---|
| Sort | dataset key, ascending, nulls first | Files and row groups cover contiguous key ranges, so min/max pruning is exact |
| Bloom filters | key columns, fpp 1%, sized per row group | Rules out row groups that can’t contain a key |
| Statistics | page level (column index + offset index) | Skip to the single page that can hold a key |
| Data page | ≤ 4,096 rows | A point read decodes one small page |
| Row group | 65,536 rows | Large enough for efficient scans |
| File | ~4M rows | Few files per dataset, cheap footers |
| Compression | ZSTD level 3 | Smaller range reads |
sorting_columns |
recorded in metadata | Readers know the order |
These are the defaults in lake::Layout and are tuned in design 07. The test
files_are_laid_out_for_point_lookups checks bloom filters, page indexes and sort metadata.
Guarantees
Section titled “Guarantees”- Atomic per dataset: readers see all of a run’s files for a dataset, or none.
- Isolation: readers work at a snapshot; commits never change files in place.
- Idempotent: committing a run twice has no effect.
- Multiple targets in one run are committed one dataset at a time, in spec order.
If dataset 2 fails after dataset 1 committed, the run is
failedwith dataset 1 committed. Retrying the commit is safe and completes dataset 2.
Maintenance (T16)
Section titled “Maintenance (T16)”Planned jobs: compaction (merge small files and rewrite with deletes applied), snapshot expiry (keep N days or M snapshots), and orphan-file cleanup. They run as scheduled Flux system jobs.
Local vs cluster
Section titled “Local vs cluster”| Local | Cluster | |
|---|---|---|
| Catalog | Postgres flux (any schema) |
enki flux, schema ducklake |
| Data | file:///… or any S3 API (versitygw on macOS) |
Object storage s3://flux-data/lake/ |
| AWS later | — | S3 + RDS: endpoint and credentials change only |