Files
greptimedb/docs/formats/mito-samples.md
T
Yingwen a6ca1de729 feat(mito2)!: add short-series IPC storage for Narthex (#10814)
* feat(mito2): store short Narthex series in Arrow IPC pages

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): share inline tails across Narthex sample layouts

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): key sample tails by region file ID

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): narrow IPC scope and consolidate artifact metadata

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): read sample sizes from the SST inventory

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): keep memory sample tails with their bytes

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito2): use crate-qualified imports in sample IPC codec

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito2): compile sample key helper only in unit tests

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito2): bound Narthex IPC pages and reads

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito-codec)!: cap sparse primary keys at 16 MiB

BREAKING CHANGE: Newly encoded sparse primary keys omit the first label that exceeds the key budget and all following labels. Oversized pre-encoded keys are rejected at write admission.

Signed-off-by: evenyag <realevenyag@gmail.com>

---------

Signed-off-by: evenyag <realevenyag@gmail.com>
2026-12-02 18:28:16 +00:00

5.2 KiB

Narthex samples format

NarthexSamples stores timestamps, sequences, operation types, and nullable Float64 or native histogram fields. The series index stores exact series identities and tags.

SST objects

Region manifest
└─ narthex_samples
   └─ parts[part_id] = { file_size, tail_size }

<region_dir>/<file_id>/part-<part_id>.samples
┌───────────────────────┬──────────────────────────────────────────────────┐
│ header | groups …     │ fixed-width group directory | JSON | trailer    │
└───────────────────────┴──────────────────────────────────────────────────┘
                        ↑                   tail_size bytes                ↑
                        file_size - tail_size                              EOF
  • Header contains GTSAMPLE followed by eight reserved zero bytes.
  • JSON descriptor contains the layout (series_blocks or arrow_ipc), immutable file identity, timestamp and field schemas, and one part record with the part ID, inclusive series/time bounds, and row and block counts.
  • Trailer is 24 bytes containing NXSAMPLE, the directory length as a little-endian u64, and the JSON length as a little-endian u64.
  • Group directory uses 108 bytes per entry. The first group starts after the header. Each following group starts at the end of the previous root page.
Group entry Bytes
First and last (table_id, tsid) and min/max timestamp 40
Root payload reference 24
Page depth 4
Payload end, stored key end, logical key end 8 each
Row count, block or run count 8 each

The reader fetches [file_size - tail_size, file_size) in one range read per part. The three tail sections supply the schema, layout, and pruning bounds. Part copies preserve the immutable file ID and byte contents.

Group layouts

series_blocks
[group start]
    timestamp / sequence / operation / value chunks
    key frames       [stored lengths: u32 … | frame bytes …]
    descriptor pages [leaf … | root if depth = 2]
[group end]

arrow_ipc
[group start]
    Arrow batch      [message length: u64 | message | 8-byte padding | body]
    key frames       [Zstd frames of (key length: u32, sparse key bytes) …]
    series runs      [run count: u16 | frame count: u16 | runs … | frames …]
[group end]

The streaming writer computes the average rows per exact series over a prefix of up to 4,096 sorted rows, including retained versions and deletes. It uses Arrow IPC at an average of at most eight rows per series and series blocks above that. Each SST uses one layout. Direct flush uploads already encoded series blocks.

Series blocks

root ─┬─ leaf ─┬─ block → exact key + column payload references
      │        └─ block → exact key + column payload references
      └─ leaf ─── block → exact key + column payload references

Each block covers one exact series. Rows are ordered by increasing timestamp and decreasing sequence at the same timestamp. Leaf pages store block descriptors. An internal root stores child bounds and references. A one-leaf group uses that leaf as its root. A block descriptor records the coarse series ID, exact-key offset and length, time bounds, ordinal, row count, and column descriptors. Each column descriptor records the role, column ID, payload reference, and null count.

Logical key references are offsets into the decoded key stream based at payload_end. The stream is split into 64 KiB frames. A frame is raw when its stored length equals its logical length and Zstd-compressed otherwise.

Column Encoding ID and representation
Timestamp 1 constant step, 2 delta of delta
Sequence 3 constant, 4 delta
Float64 5 nullable XOR
Operation 6 constant, 7 raw
Native histogram 8 Arrow struct encoded by child

Arrow IPC pages

The uncompressed Arrow batch contains the timestamp, sequence, operation, and value columns. A serialized batch may occupy up to 128 MiB, with a separate 64 MiB budget for the stored key frames. The writer retries with fewer rows when a page exceeds either budget. Each encoded key is at most 16 MiB. The directory uses Zstd with raw fallback.

Directory record Fields in byte order
Run Table ID u32, TSID u64, cumulative row end u16
Key frame First run u16, offset from payload end u64, stored length u32, decoded length u32

A point lookup binary-searches the group directory and series runs, then reads the required key frames. Both layouts compare the full sparse key when coarse IDs collide.

Payload references

[offset: u64 | stored length: u32 | decoded length: u32
 | encoding: u16 | compression: u16 | reserved: u32]

Offsets are absolute unless explicitly described as relative. Integers are little-endian. Compression ID 0 means raw and ID 1 means Zstd. The storage layer provides byte integrity. Sample payloads and tails carry no application-level checksums.