Expand description
Routes evaluated and raw series across DataFusion input partitions.
Canonical routing hashes complete labels; matching routing hashes the evaluator’s own PromQL matching key. Routing groups are not merge identities: evaluated series merge only by exact name and tags. Raw ownership is the complete primary key plus exact label agreement; each input’s complete chain or EOF establishes its contribution to a raw identity for contiguous inputs. An interleaved raw frame here consists of concatenated, independently closed producer chains; identities can recur, but open chains cannot be multiplexed. The owner retains those raw identities until every input reaches normal EOF, then reconstructs contiguous output.
Chains are transported intact to owners with their input-partition ID, followed by one charged normal-EOF message per live output from each completed input. Owners group exact identities and, except for interleaved raw input, may publish an identity as soon as every input has contributed its final chain or normal EOF. Evaluated chunks are decoded only to read routing labels.
§Routing
The key is label_set of the chunk’s metric, hashed whole: coarsening it (a subset of the
labels, a metric name alone) would send two label sets to one output for sharing a prefix, which
is not the relation a downstream merge groups by. One Routing is built per execution and
every chunk is reduced with it, so the destination of a label set cannot depend on which chunk of
it was routed first.
The node declares [Partitioning::UnknownPartitioning], never [Partitioning::Hash]: the key is
decoded from the rows, and a hash declaration carries an Arrow expression DataFusion could use to
prove two plans agree on a partitioning. There is no such expression here, so the claim would be
one no optimizer could check and a hash exchange inserted on top of it could silently disagree
with. No ordering is declared either: the node reorders, and it says so by claiming nothing.
§Chain boundaries
A consumer of these frames requires a series’ identity not to change and its positions to increase
strictly while open, with is_last closing it. An input task therefore assembles each child chain
before routing it as one atomic unit. This prevents chains from interleaving during transport; it
does not establish the output order or final series boundaries. For a full exact identity (metric
name and every tag name/value), the input contract is that each identity closes at most once per
input, except for the independently closed chains of an interleaved raw frame. Each owner waits
for each distinct input’s final chain or normal EOF before merging a contiguous identity, and
for all input EOFs before merging an interleaved raw identity.
What that costs is stated rather than hidden. Nothing of a chain is handed over before the chain
closes, so the first chunk of a series reaches its output later than a chunk-at-a-time design would
deliver it, and a long chain occupies memory for as long as it is being read. Those bytes are
charged to a [MemoryConsumer] as the chain grows, so a pool under pressure ends the read with an
error instead of letting a chain grow without bound: the node refuses, it does not spin and it does
not buffer past the pool’s limit.
Queues carry whole chains rather than individual chunks, so two sources’ partial chains cannot interleave on one shared output queue; each output needs only one queue.
§Where the reads run
One task per child partition, and no task above them: each input’s task reads its own child, assembles that input’s chains and sends them to their owners itself. No task makes a routing decision for another input, and nothing rotates over the inputs.
That is not an optimisation of the routing: an evaluated partition is one stream whose computation
happens inside its poll_next, so a task polling every partition in turn runs the child’s native
kernels for all of them itself, one chunk at a time, and the partition count the child declared
buys no parallelism at all. It is also what keeps routing local, which is what this node needs
when two of them are composed:
- A partial chain never occupies a shared output queue, so no output waits for a continuation: a chain is either fully assembled in the input task that read it, or not sent at all.
- A task never waits for another task’s routing decision, and the tasks share no lock while routing, so where one input’s chain goes is not something another input learns or needs.
Producer queues are unbounded: unread owners do not stall routing, but their retained chains continue to consume pool-accounted memory. Owners publish each exact identity after its per-input close/EOF barrier, or all input EOFs for interleaved raw frames, with finality recomputed for that output series.
§Memory, backpressure and end of stream
Output queues are unbounded; each input task holds at most the one chain it is assembling. Every queued chain is admitted through the task context’s pool and carries its charge. The public packed stream releases a completed cursor’s charges after its batch is flushed, while retaining the current cursor’s charges until the cursor is exhausted. The pool controls admission, but queue length is not a constant-byte bound. Owners retain each pending exact identity until its per-input close/EOF barrier is satisfied, then reserve merge workspace for that identity alone. This bounds merge workspace to one pending identity, while its inputs remain charged until handoff. No task waits for memory admission.
An output ends only when every input partition finished and its queue was drained; a chain that closed locally is not the end of anything. Each input sends its own EOF to each live output before recording normal completion. With one task per input the tasks count themselves down: the last records the read outcome, then sender closure lets outputs detect missing EOF or report failure. If the child errors, the failing task records it before cancelling its peers; sender closure makes every output report that recorded error instead of a clean end.
Shared execution records the read outcome before producer senders close, so queue closure together with that shared outcome distinguishes normal completion from a stopped or failed read. A stopped read is missing exactly what it did not route and is reported as an error rather than a clean end.
An output stream owns the read, not the plan it was executed from: DataFusion’s
execute_stream_partitioned takes the plan by value and keeps only the streams, so a read tied to
the plan would be stopped while its streams are still being consumed. The read therefore lives as
long as any of its outputs does, and stops only when there is nothing left it could deliver to:
every output was handed out and every one of them is gone. An output that ends - normally, or by
being dropped - while another partition was never executed stops nothing by itself, because that
partition can still claim its queue; the execution going away as a whole, which no later execute
can reach, is the other point at which everything is released.
Structs§
- Chunk
Output 🔒Stream - One owner’s publications as handed-over chunks.
- Evaluated
Output 🔒Stream - Turns an owner’s evaluated publications into the evaluated stream the packer consumes.
- Handoff 🔒
- Charges move out of the current cursor only after it is exhausted; the public batch stream releases completed cursors after the packer has flushed the frames they back.
- Held
Evaluated 🔒 HeldSeriesChargesread as evaluated series.- HeldRaw 🔒
HeldSeriesChargesread as raw series.- Held
Series 🔒Charges - A child’s chunks, read as the series this node’s chain assembly expects.
- Input
State 🔒 - What
Inputsguards. - Inputs 🔒
- The input tasks of one read: what is left of them, and what the last of them records.
- Output
Lease 🔒 - What one output stream holds so that the read belongs to the streams rather than to the plan.
- Packed
Handoff 🔒Stream - Pending
Group 🔒 - Queued
State 🔒Chunk - What one queued state group holds: the group, and the charges it keeps alive.
- RawOutput
Stream 🔒 - Turns an owner’s raw publications into the raw frame stream the packer consumes.
- Ready
Series 🔒 - Repartition
Stream 🔒 - Report
IfUnreported 🔒 - Reports an input task that stopped without recording an outcome, on the paths that would otherwise report nothing.
- Routing 🔒
- The hash configuration one execution routes with.
- Running 🔒
- What one execution’s state holds that has to be stopped together.
- Series
Repartition Exec - The Repartition stage: one child’s partitions, redistributed by canonical label set.
- Shared
Execution 🔒 - One execution’s state: the child read once, and the outputs it is being distributed into.
- State
Batch 🔒Output Stream - One owner processes identities as soon as every input has closed or contributed its final chain.
- State
Chunk 🔒Output Stream - One owner’s exported state, as the rows it is.
Enums§
- Ending 🔒
- How a read ended, as an output whose queue has closed has to report it.
- Identity
Completion - Whether a series identity is complete on a single chain, or has to be merged across inputs.
- Input
Read 🔒 - How the claim of an output reads this node’s child.
- Owner
Key 🔒 - What one owner groups by: an evaluated exact identity, or a complete raw primary key.
- Queued 🔒
- What one output queue carries: a whole chain and its memory charge.
- Ready
Output 🔒 - Routed
Chain 🔒 - Routed
Input 🔒 - One whole chain of one series: its chunks from the one that opened it to the one that closed it, each with the bytes it is charged.
- Series
Routing - Selects the key used to route a series to an output partition.
- Stop 🔒
- Why one input task stopped reading its partition.
Constants§
- MAX_
EMPTY_ 🔒STATE_ BATCHES_ PER_ POLL - How many empty exported batches one poll reads before yielding, mirroring the frame consumer’s own guard so a producer of empty batches cannot hold the task.
- ROUTING_
SEED 🔒 - The seed behind every routing decision.
Functions§
- boxed 🔒
- The boxed error a frame stream reports.
- declared_
state_ 🔒of - Whether
chunkis a publication of the state this node declared it routes. - exact_
identity 🔒 - group_
ready 🔒 - Whether this owner may publish
groupnow. - histogram_
table_ 🔒slice_ bytes - Accounts for the portion of a decoded histogram table retained by one series slice.
- raw_
chunk_ 🔒slice_ bytes - The raw identity of one chunk: its complete stored primary key and nothing else.
- raw_
identity 🔒 - read_
evaluated_ 🔒chains - Reads one input partition to its end, one whole chain at a time, routing each chain as it closes.
- read_
raw_ 🔒chains - read_
state_ 🔒batches - Routes state rows without materializing Rust accumulator objects or rebuilding Arrow columns.
- read_
state_ 🔒chunks - Reads a child’s handed-over state, routing each group to the owner that folds it.
- route_
partition 🔒 - One input partition’s task: reads its own child, assembles chains, and sends each complete chain to its canonical owner. Output queues are unbounded, so sending does not wait for an owner to poll; queued chains remain charged to the pool until consumed or dropped. Each task records its outcome before returning and dropping its senders, so output streams observe the final read outcome.
- routed_
input 🔒 - One child partition, as this node reads it: its chunks when it hands them over, its frames when it does not.
- state_
slice_ 🔒wrapper_ bytes - Upper bound for transient arrays allocated by slicing one aggregate-state row. It counts each
schema node’s concrete array object, two
usizewrapper words, and one reference per child.