Crate litetx

source ·
Expand description

Lite Transaction File (LTX)

The LTX file format provides a way to store SQLite transactional data in a way that can be encrypted and compacted and is optimized for performance.

The Rust implementation is derived from the original Go implementation and mostly follows its design.

Until the library reaches version 1.0, the API is not considered stable and is subject to change.

File Format

An LTX file is composed of several sections:

  1. Header
  2. Page block
  3. Trailer

The header contains metadata about the file, the page block contains page frames, and the trailer contains checksums of the file and the database end state.

The header provides information about the number of page frames as well as database information such as the page size and database size. LTX files can be compacted together so each file contains the transaction ID (TXID) range that it represents. A timestamp provides users with a rough approximation of the time the transaction occurred and the checksum provides a basic integrity check.

OffsetSizeDescription
04Magic number. Always “LTX1”.
44Flags. See below.
84Page size, in bytes.
124Size of DB after transaction, in pages.
168Minimum transaction ID.
248Maximum transaction ID.
328Timestamp (Milliseconds since epoch)
408Pre-apply DB checksum (CRC-ISO-64)
488File offset in WAL, zero if journal
568Size of WAL segment, zero if journal
644Salt-1 from WAL, zero if journal or compacted
684Salt-2 from WAL, zero if journal or compacted
728ID of the node that created file, zero if unset
8020Reserved.
Header flags
FlagDescription
0x00000001Data is compressed with LZ4
Page block

This block stores a series of page headers and page data.

OffsetSizeDescription
04Page number.
4NPage data.
Trailer

The trailer provides checksum for the LTX file data, a rolling checksum of the database state after the LTX file is applied, and the checksum of the trailer itself.

OffsetSizeDescription
08Post-apply DB checksum (CRC-ISO-64)
88File checksum (CRC-ISO-64)

Structs

Enums

Traits