Skip to main content

Module chunk

Module chunk 

Source
Expand description

Sorted runs on disk: the spill files of the external sort.

During Phase 1 (read + process), each rayon thread accumulates SortEntry items in a local buffer. When the buffer exceeds a size threshold, it is sorted by key and written as one run.

A run is a header, a sequence of blocks and an end marker. A block holds a few thousand entries in the columnar layout of crate::sort::block, compressed with zstd, with the xxh3 checksum of the compressed bytes in its header. The end marker holds the number of blocks and entries and its own checksum, so a run that was cut short, damaged or written by another version stops the reader with a SortRunError and never yields a wrong entry.

The reader keeps one block in memory, so the k-way merge over thousands of runs stays small, and it can give the disk space of every block back to the file system as soon as the block is read (see ChunkReader::open_reclaiming).

Structs§

ChunkReader
Streaming reader for a single chunk file.
ChunkSink
Manages writing sorted chunk files to a temporary directory.
SortBuffer
A thread-local buffer that accumulates sort entries and flushes to a ChunkSink when the buffer exceeds the size threshold.

Constants§

RUN_EXTENSION
File extension of a run.

Functions§

read_chunk
Read all sort entries from a chunk file, in order.