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

Core clienttags, blobs, batched puts/gets Shared-memory mirrorszero-IPC reads and stats Interposers (indexer, shm cache, compressor, write-back, replication)same task interface; override data verbs, forward the rest Core container (one per node) tag and blob tables for the keys this node owns (by hash) placement engine (DPE) · data organizer · blob transform flags per-worker metadata log · eviction · failover routing metadata publishedto shared memory bdev: RAM bdev: file / NVMe safe_bdev array S3 / GCS
A put enters through the client, passes whichever interposers are composed, reaches the core container that owns the blob, and lands on a block-device target chosen by the placement engine.

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

Choosing the owner tag: hash(name) % containers; the owner gives itan id of (its node id, a counter) blob: hash(tag id, blob name) % containers owner down: the next live container stands in(failover_to_successor, majority side only) node 0 node 1the blob node 2the tag node 3 4 nodes, one core container each (container id = node id) tag "/sim/run1" hashes to node 2, which names it 2.7 blob "step_42" of tag 2.7 hashes to node 1 NODE 2 · CORE CONTAINER Tag tablename → id: "/sim/run1" → 2.7, plus each alias TagInfo of 2.7 canonical name: /sim/run1aliases: more names for this id (hard links)total size of its blobsmodified, read and changed timesfault handler: a pool asked to fill a missing blob Tag search indexregex queries over tag names, trigram prefilter The tag's blobs are spread over every node by hash. NODE 1 · CORE CONTAINER Blob table"2.7.step_42" → BlobInfo; a per-tag name index BlobInfo of step_42 score 1.0 · generation · access count · timestransform flags (sticky) · droppableplacement generation · content seqlockwrite token · reader pinsnodes holding a cached copy (dropped on write)replicas: own extents, score and flags each EXTENTS · blob size = sum of their sizes [0] RAM tieroffset 0 · 3 MiB [1] disk tieroffset 1.2 GiB · 1 MiB Target table (node 1)per target: bdev pool, score, persistence, capacity,free space, bandwidth, latency, I/O counts, lifetime RAM tier (ram)score 1.0 · volatileon this node only Disk tier (file)score 0.2 · temporarymay be a neighbor's
No node keeps a directory of every tag and blob: hashing picks one owner for each. Node 2 records the tag /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_robin and random spread writes. Chosen by dpe.dpe_type.
Data organizer
Optional (top-level organizer key; none disables 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-specific grayscott organizer.

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

Clientcore client APIany process indexerpool 564search index shm cachepool 568metadata in shm compressorpool 562optional codec write-backpool 567ack in RAM, flush cores540 now; 512 onflush, via 561 Each layer overrides a few data verbs and forwards every other core method to its next_pool_id (shipped chain shown). The shm cache answers hits in the caller's process; the other layers route each blob to its owner node by hash, as the core does. CORE CONTAINER ON THE BLOB'S OWNER NODE Data organizer (optional) every 5 s: snapshot blob stats and rescore them(hotset, frecency, cyclic, scatter, grayscott)move a blob only if its score moved by 0.05 or more:place a new copy, swap it in, log, then free the old Eviction (and the write-back flush) a core never moves data to another core; thewrite-back cache flushes dirty volatile blobs tothe persistent core every 10 s, on fsync and at stop;eviction is a DelBlob on the volatile core 1 · Placement (max_bw) keep targets with room for the bytesprefer score ≤ blob's, hottest firstthen hotter tiers, closest firstties: bandwidth; latency if < 32 KiBskip dead nodes, wrong persistence 2 · Blob table and log swap the new extents into the BlobInfoand bump its placement generation;append one record to this worker'sshard: [type][seq][size][payload], seqfrom one counter per container 3 · Mirror update withdraw the blob's record beforeits old extents are freed, thenrepublish extents, generation,flags, tag size and timesbest effort: never fails a write Metadata log files (disk) cte_metadata_log.blob.i and .tag.i: a shard per workerrecords: create, extend (full layout), clear, delete,transform, replica layout, droppable, tag name, xattrcte_metadata_log: the snapshot, built in .tmp, renamedevery 5 s: fsync the shards; snapshot when they pass32 MB, or 60 s after a score change; cut what it coversrestart: load the snapshot, replay the shards by seq Shared-memory mirror (this node) tag name → id; tag id → size and times"2.7.step_42" → blob record:· up to 16 extents (pool, offset, size, tier, node)· placement generation and content seqlock· flags: direct-readable, truncated, transformed· the cache copy's extents, when it has onedirect-readable: every extent in this node's RAM Zero-IPC read (a client on the same node) look up the record; refuse when it is not direct-readable or its seqlock is odd; copy the bytes out of the RAM tier; if the generation or seqlock moved meanwhile, discard them and send a task
A put passes the interposers and reaches the core container that owns the blob. There the placement engine picks extents, the blob table takes them, the worker's log shard records them, and the node's shared-memory mirror is refreshed. The organizer moves blobs later through the same steps, always writing the new copy before freeing the old, and a reader on the same node copies a RAM-resident blob with no task at all.

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

DecisionBuysCosts
Hash-owned metadataNo metadata server; scales with nodesListings and searches are broadcasts
Per-blob tokenLock-free reads, simple crash orderingWriters to one hot blob serialize
Copy-then-free movementA crash never loses the only copyMoves need free space for a second copy
Per-worker logsUncontended metadata writesReplay merges several logs at startup