Diffinery

homeflare/celldpublic

celld/crates/ltx/README.md
64 lines · 3.3 KBRaw History
1# celld-ltx
2
3`celld-ltx` is celld's in-process SQLite replication library. It captures
4committed WAL data as L0 LTX segments and reports the captured position. The
5crate can write segments to a filesystem or an object store. It can restore a
6database, compact levels, create a snapshot, and read segments from bundle
7objects. It can also open a database by paging: a fault-in SQLite VFS reads
8each page from the segments on first use, through a page map built from the
9segments' own page indexes, and a paged epoch continues the chain it paged
10from.
11
12celld uses this library inside a larger durability protocol. The output gate,
13epoch fencing, replicated node log, and takeover recovery enforce the write
14acknowledgement contract.
15
16## Provenance and attribution
17
18Seeded on 2026-08-03 from a read-only snapshot of rustyriver
19(https://github.com/mikenomitch/rustyriver), a from-scratch Rust
20reimplementation of Litestream v0.5 and the LTX file format. celld owns and
21evolves this snapshot as first-class celld source; it does not track an
22upstream branch.
23
24Attribution for the vendored and ported work:
25
26- **rustyriver** — Copyright 2026 The rustyriver authors, licensed under the
27 Apache License, Version 2.0.
28- **Litestream** (https://github.com/benbjohnson/litestream) — Copyright (c)
29 Ben Johnson and the Litestream authors, licensed under the Apache License,
30 Version 2.0. The original replication behavior comes from tag v0.5.11. The
31 current block format follows tag v0.5.16 because it includes LTX v0.5.2.
32- **LTX file format and reference implementation**
33 (https://github.com/superfly/ltx), tag v0.5.2 — Copyright (c) Superfly, Inc.,
34 licensed under the Apache License, Version 2.0.
35- **pierrec/lz4 block compressor**
36 (https://github.com/pierrec/lz4), tag v4.1.23 — Copyright (c) 2015 Pierre
37 Curto, licensed under the BSD 3-Clause License. The Rust port preserves the
38 exact compressed bytes that the LTX v0.5.2 writer produces.
39
40The port is not complete, deliberately. `leaser.rs` — Litestream's
41object-storage lease (`leaser.go`, `heartbeat.go`, `s3/leaser.go`) — was
42ported and then removed on 2026-08-06, unused. celld fences cell ownership
43with a conditional-write record carrying an epoch, and fences the data path by
44stamping that epoch into the LTX prefix; a lease file under the replica prefix
45would be a second, competing layer. Upstream's own leaser is unwired for the
46same reason. Recover it from git if a future design needs it.
47
48The full Apache License, Version 2.0 text is in [LICENSE](LICENSE). The full
49BSD 3-Clause License text is in
50[LICENSE.pierrec-lz4](LICENSE.pierrec-lz4).
51
52## File compatibility
53
54Celld and Litestream v0.5.16 can read the new block files and the older frame
55files. Litestream v0.5.11 can read only the older frame files. This is a reader
56compatibility boundary because LTX keeps file version 3 for both layouts.
57
58The ordinary celld L0 writer still emits the older frame representation. The
59v0.5.2 encoder and compactor emit exact block files. Celld contains a
60node-wide scheduler that publishes additive L1 files, and the scheduler is on
61by default. Every takeover target must have the dual decoder before the first
62L1 publication, so a mixed fleet must set `CELLD_LTX_COMPACTION=0` until all
63nodes can read block files. The same reader-first requirement applies to a
64later L0 writer switch.