Disk Segment Files

June 12, 2026 ยท View on GitHub

Disk segments are immutable persistent record sets. This page describes their physical file shape. For terminology, see segments. For sizing and merge tuning, see disk segment tuning.

File Categories

ZoneTree stores disk segment data through random-access devices. The common file categories are:

CategoryPurpose
.dataserialized key/value bytes or fixed-size record data
.headheaders and offsets for layouts that need them
.sparseoptional sparse index entries
.multimultipart disk segment descriptor

Compression usually adds the .z suffix to the physical file.

single-part segment 10
  10.data.z
  10.head.z
  10.sparse.z

multipart segment 20
  20.multi
  part files for segment 11
  part files for segment 12
  part files for segment 13

Fixed-size key/value layouts may not need a .head file. Variable-size layouts use headers and offsets so ZoneTree can keep random access while supporting strings, arrays, and other variable-size serialized values.

Single-Part Layouts

Single-part disk segments choose one of four layouts from the key and value shape:

LayoutPhysical idea
fixed key + fixed valuerecords can be addressed directly in .data
fixed key + variable valuefixed keys and value offsets are stored in .head; value bytes live in .data
variable key + fixed valuekey offsets and fixed values are stored in .head; key bytes live in .data
variable key + variable valuekey/value offsets are stored in .head; key/value bytes live in .data

This is a storage optimization. The logical API stays the same for all layouts.

Multipart Descriptor

A multipart disk segment is one logical disk segment made from ordered parts. Its .multi descriptor stores the part segment ids and boundary key/value information needed to route reads to the correct part.

20.multi
  part ids: 11, 12, 13
  first/last keys for each part
  first/last values for each part

The parts are regular IDiskSegment instances. A part can be carried forward into a later multipart segment when its key range is unchanged by a merge.

Sparse Index File

The .sparse file stores selected key/value/index entries. It helps ZoneTree position disk searches without loading every key into memory.

DefaultSparseArrayStepSize controls sparse index density:

ValueEffect
smaller stepmore sparse entries, faster positioning, more memory
larger stepfewer sparse entries, less memory, more local search
0disables default sparse array creation/loading

Immutability

Disk segment files are immutable after creation. Merge operations create new disk segment files and then drop old files when they are no longer needed.

Iterators and live backup can pin disk segments while they read or copy files. A pinned segment is not rewritten; its deletion is delayed until the pin is released.

Restore And Backup

IDiskSegment.GetFiles() returns the physical files that belong to a disk segment. For multipart segments, this includes the .multi descriptor and every part file.

Live backup stores these immutable files and streams in-memory records separately. Restore uses the recorded file order to rebuild the DiskSegment and bottom segment layout.