Docs · Context Transfer Engine
Inside the Context Transfer Engine.
The CTE is one runtime module, the core, plus a family of modules that stand in front of it. This page names the pieces of the code and how a request moves through them. The Design section's pages explain each mechanism and its tradeoffs in depth.
- Core module
- clio_cte_core
- Placement
- max_bw, round_robin, random
- Organizers
- hotset, frecency, cyclic, scatter, grayscott
The pieces
The core container
The core is the module clio_cte_core. Each node runs one container of it, and that container owns a slice of all tags and blobs: a blob's owner is chosen by hashing its tag and name, so metadata is spread over the cluster with no central server. The container keeps, for the keys it owns:
- The tag table: tag name to id, and per-tag statistics.
- The blob table: for each blob, its score, generation, transform flags, and a list of extents, each naming a target, an offset and a size there (the blob's size is their sum). A blob can span several extents on several targets, for example when it grew after its first tier filled.
- The target table: the block-device pools composed as tiers, with their capacity, score, persistence level and live free-space and bandwidth figures.
Concurrency on one blob is a per-blob token: readers proceed together without it, writers take it one at a time, and a change that frees extents (a move, a delete, a truncate) also waits for in-flight readers to finish first. Different blobs never contend. Concurrency explains the rules.
How tags and blobs are stored
/sim/run1, and each
of its blobs is recorded wherever its own hash lands. A blob's record lists
extents, each a range on one storage target; this one grew after the RAM
tier filled, so its last 1 MiB went to disk.Placement engines and organizers
Two pluggable policies decide where bytes go.
- Placement engine (DPE)
- Chooses targets for a new write, from the blob's score and the targets' scores and free space.
max_bw(default) matches score to tier and breaks ties by bandwidth;round_robinandrandomspread writes. Chosen bydpe.dpe_type. - Data organizer
- Optional (top-level
organizerkey;nonedisables it). A periodic task rescores blobs from snapshots of their access statistics and moves the ones whose score changed. Variants:hotset,frecency(frequency and recency),cyclic,scatter, and a workload-specificgrayscottorganizer.
Movement always copies before it frees: a reorganized blob is written to its new target, its extents are swapped in the table and logged, and only then is the old space released. Placement and tiering covers scores, flushing and eviction.
A write, step by step
Metadata log and recovery
Each worker appends the metadata changes it makes (new tags, new extents, deletes, renames) to its own log shard under metadata_log_path, so logging never contends between threads; one sequence counter per container orders the shards for replay. The log is off when that path is empty; the shipped configuration sets it. A snapshot, taken when the shards pass transaction_log_capacity (32 MB), bounds replay time. Score changes are not logged: they reach disk with the next snapshot, which is taken at most about a minute after one. On clio-run start the core container replays its logs and rebuilds its tables; data on volatile tiers that was not flushed reads as an I/O error, never as zeros. Modules that keep their own node-local metadata, such as the filesystem and stream, use a shared append-only record log with the same crash rules. Durability and recovery states what survives what.
The shared-memory read path
For blobs whose bytes are in a RAM target on the same node, the core publishes metadata into a shared-memory segment the client maps. A local reader can find the blob's location and copy the bytes directly, with no task and no context switch. Version checks make a concurrent overwrite visible, and transformed (for example, compressed) blobs are refused on this path because their stored bytes are not the caller's bytes. The same mirrors serve file sizes and statistics.
The interposer base
Every chain module derives from one interposer base class. It speaks the core's method ids and task structs, lets the module override a few data verbs (put, get, size, batched put), and forwards every other method unchanged to its next_pool_id. A core client pointed at any interposer therefore works unchanged. Batched and vectored requests are encoded and walked by one shared helper, so the client, the core and every interposer agree on the format. The interposition chain describes each module.
Blob transforms
When a module stores bytes that differ from what the caller put, it sets a persistent transform flag on the blob. That flag, not the module's configuration, is the single answer to "are the stored bytes the caller's bytes?", and every layer that might read raw bytes (the shared-memory path, the cache, replication) checks it.
Costs of this design
| Decision | Buys | Costs |
|---|---|---|
| Hash-owned metadata | No metadata server; scales with nodes | Listings and searches are broadcasts |
| Per-blob token | Lock-free reads, simple crash ordering | Writers to one hot blob serialize |
| Copy-then-free movement | A crash never loses the only copy | Moves need free space for a second copy |
| Per-worker logs | Uncontended metadata writes | Replay merges several logs at startup |