Specification for Lithoglyph’s fixed-size block storage format.
Status: PROPOSED (resolves Q-BLOCK-HEADER-001)
Lithoglyph stores all data in fixed-size blocks. Each block has a header that provides:
-
Renderability: Deterministic text representation for audit
-
Integrity: Checksums and validation
-
Forward Compatibility: Versioning and reserved space
Decision: 4096 bytes (4 KiB)
Rationale:
-
Matches most filesystem block sizes and SSD page sizes
-
Provides good balance between space efficiency and I/O granularity
-
Small enough for fine-grained locking, large enough for meaningful payloads
| Offset | Size | Field | Description |
|---|---|---|---|
0 |
4 |
|
Magic bytes: |
4 |
2 |
|
Block format version (current: 1) |
6 |
2 |
|
Block type (see Block Types) |
8 |
8 |
|
Unique block identifier (uint64) |
16 |
8 |
|
Journal sequence number at creation |
24 |
8 |
|
Creation timestamp (Unix microseconds) |
32 |
8 |
|
Last modification timestamp (Unix microseconds) |
40 |
4 |
|
Actual payload length in bytes |
44 |
4 |
|
CRC32C of payload |
48 |
8 |
|
Previous block in chain (0 if none) |
56 |
4 |
|
Block flags (see Block Flags) |
60 |
4 |
|
Reserved for future use (must be 0) |
Bytes 64-4095 contain the block-type-specific payload.
Block Layout (4096 bytes):
┌─────────────────────────────────────────┐ 0
│ magic [4] │ version [2] │ type [2] │
├─────────────────────────────────────────┤ 8
│ block_id [8] │
├─────────────────────────────────────────┤ 16
│ sequence [8] │
├─────────────────────────────────────────┤ 24
│ created_at [8] │
├─────────────────────────────────────────┤ 32
│ modified_at [8] │
├─────────────────────────────────────────┤ 40
│ payload_len [4] │ checksum [4] │
├─────────────────────────────────────────┤ 48
│ prev_block_id [8] │
├─────────────────────────────────────────┤ 56
│ flags [4] │ reserved [4] │
├─────────────────────────────────────────┤ 64
│ │
│ Payload (4032 bytes) │
│ │
└─────────────────────────────────────────┘ 4096| Value | Name | Description |
|---|---|---|
0x0000 |
|
Unused/deallocated block |
0x0001 |
|
Database metadata (exactly one per database) |
0x0010 |
|
Collection definition and schema |
0x0011 |
|
Document data |
0x0012 |
|
Document overflow (large documents) |
0x0020 |
|
Edge collection definition |
0x0021 |
|
Edge data |
0x0030 |
|
Index root node |
0x0031 |
|
Index internal node |
0x0032 |
|
Index leaf node |
0x0040 |
|
Journal segment (multiple entries per block) |
0x0050 |
|
Schema definition |
0x0051 |
|
Constraint definition |
0x0060 |
|
Migration artefact |
0xFF00-0xFFFF |
Reserved |
Reserved for extensions |
| Bit | Name | Description |
|---|---|---|
0 |
|
Payload is LZ4-compressed |
1 |
|
Payload is encrypted |
2 |
|
More blocks follow (overflow) |
3 |
|
Logically deleted (awaiting compaction) |
4-31 |
Reserved |
Must be 0 |
The superblock (block_id = 0) contains database metadata:
| Offset | Size | Field |
|---|---|---|
0 |
16 |
Database UUID |
16 |
8 |
Journal head sequence |
24 |
8 |
Last checkpoint sequence |
32 |
8 |
Total block count |
40 |
8 |
Free block count |
48 |
8 |
Creation timestamp |
56 |
64 |
Database name (UTF-8, null-padded) |
120 |
3912 |
Reserved |
All blocks MUST have a deterministic text representation for audit purposes.
BLOCK block_id=42 version=1 type=DOCUMENT
sequence=1234 created=2026-01-11T12:00:00Z
payload_len=256 checksum=0xABCD1234
flags=[]-
Magic bytes must be
LGH\x00 -
Version must be recognized (currently: 1)
-
Block type must be valid
-
Payload length must be ⇐ 4032
-
Checksum must match computed CRC32C
-
Reserved fields must be 0
When validation fails, Lithoglyph provides structured guidance:
BLOCK_VALIDATION_FAILED block_id=42
error: CHECKSUM_MISMATCH
expected: 0xABCD1234
actual: 0xDEADBEEF
recovery_options:
- RESTORE_FROM_JOURNAL: Reconstruct from journal entries
- MARK_CORRUPT: Flag block as corrupt, exclude from queries
- MANUAL_REPAIR: Export payload for manual inspection-
Major version (high byte): Breaking changes
-
Minor version (low byte): Compatible additions
Current version: 0x0001 (1.0)
Golden test vectors in test-vectors/blocks/:
-
superblock.bin- Valid superblock -
superblock.txt- Canonical rendering -
document_simple.bin- Simple document block -
document_simple.txt- Canonical rendering -
invalid_checksum.bin- Block with wrong checksum -
invalid_magic.bin- Block with wrong magic bytes