feat(promql): route evaluated fragments to their canonical owner

PR 1 answers one series per canonical label set, but only where one
execution already holds every piece of one. A scan partitions by the
storage read_key, so pieces of one canonical label set sit in different
partitions, and a per-partition placement could not host a merge at all.

SeriesRepartitionExec is the node that makes such a placement host one:
N -> M routing of evaluated chunks by canonical label set, so a merge above
it reads each label set whole while the partitions it created stay.

One task per input partition, and no task above them: each input's task
reads its own child, assembles one whole chain locally, hashes it once and
sends it straight to its owner output. No task makes a routing decision for
another input and nothing rotates over the inputs.

That last part is a bug fix, measured. The first design had one central
router: produce ran read_all, which rotated an index over every input and
did every send from that one task. Composing two of those nodes deadlocks -
R2(R1(source)) with every chain hashing to the inner node's output 1 leaves
its output 0 empty, so the outer router parks on input 0, which cannot close
until the inner read finishes, and the inner read cannot finish because its
output 1 queue is full. 0 of 4096 series arrived before a timeout; a volume
sweep put the threshold exactly at 10->11 chunks, the total finite buffering
in the path, and a control with data on the empty input finished the same
composition in 0.8s. The regression test is not ignored.

The lifecycle is what the node's own tests cover, because a routing node
that loses a chunk or reports a clean end for a failure is worse than one
that is slow:

- claimed/remaining keep an output that was never executed claimable after a
  sibling ends normally, and stop the read only when nothing could take a
  chunk any more;
- Ending has four outcomes and Failed outranks the rest: a read that lost
  chains to a dropped output is Abandoned, never Finished, and Finished is
  the only outcome an output reports as a clean end;
- a failure is broadcast by exactly one elected task, so two concurrent
  failures cannot abort each other's broadcaster and leave an output with a
  recorded failure and no error item;
- a task that dies without an ending - a panic, or an abort - is reported by
  a drop guard, because the alternative does not see an abort;
- with one task per input, each holds a sender to every output, so the docs
  say plainly what that means: no cross-input continuation dependency, but an
  empty output closes only when the last input returns, and a starved output
  stalls the inputs parked on it.

A chain is assembled whole before it is handed over, so a partial chain never
occupies a shared output queue and no output waits for a continuation. The
cost is stated where it lives: one chain buffered per input before its first
byte goes out, and a long chain held for its whole length, charged to the
query memory pool and refused rather than awaited when it does not fit.

input_boundary now recognises this node by node identity and reports
ByCanonicalKey for it, which is what lets a merge above the repartition keep
the M owner partitions instead of collapsing them to one. It is recognised by
identity and not by partitioning on purpose: the node publishes
UnknownPartitioning(M), which promises nothing about where a key lives and is
deliberately not upgraded to a proof.

Signed-off-by: discord9 <discord9@163.com>
This commit is contained in:
discord9
2026-10-28 19:17:13 +08:00
parent 9a3187f024
commit eb2a6de171
4 changed files with 4850 additions and 6 deletions
+2
View File
@@ -26,6 +26,7 @@ mod raw_series_source;
mod scalar_calculate;
mod series_divide;
mod series_gather;
mod series_repartition;
#[cfg(test)]
mod test_util;
mod union_distinct_on;
@@ -56,6 +57,7 @@ pub use range_manipulate::{RangeManipulate, RangeManipulateExec, RangeManipulate
pub use raw_series_source::{RawSeriesSource, RawSeriesSourceExec};
pub use scalar_calculate::ScalarCalculate;
pub use series_divide::{SeriesDivide, SeriesDivideExec, SeriesDivideStream};
pub use series_repartition::SeriesRepartitionExec;
pub use union_distinct_on::{UnionDistinctOn, UnionDistinctOnExec, UnionDistinctOnStream};
pub type Millisecond = <TimestampMillisecondType as ArrowPrimitiveType>::Native;
+21 -6
View File
@@ -84,6 +84,7 @@ use store_api::region_engine::RawLabelSource;
use crate::evaluated::EvaluatedChunk;
use crate::extension_plan::aggregate_exchange::{PartialFold, aggregate_op, state_schema};
use crate::extension_plan::series_gather::{SeriesGather, spawn_partitions};
use crate::extension_plan::series_repartition::SeriesRepartitionExec;
use crate::grid_series::series_bytes;
use crate::native::execute::{InputId, NativeExecutionState, NativeExecutor};
use crate::native::plan::{
@@ -775,14 +776,28 @@ fn validate_physical_tree(tree: &NativeTree) -> DataFusionResult<Vec<Arc<SeriesS
fn input_boundary(
inputs: &[(Arc<dyn ExecutionPlan>, RawLabelSource, SeriesOrdering)],
) -> Vec<NativeProperties> {
// What a fused input proves on its own: the pieces of a metric one scan partition holds.
// Nothing here places those pieces by canonical key, so nothing is claimed about ownership - a
// merge over what this boundary describes is therefore not placeable in a per-partition
// execution, which is what [`merges_are_placeable_in`] is asked and what a single execution
// provides without needing a proof.
// What a fused input proves about the pieces it hands over.
//
// A `SeriesRepartitionExec` routes every chunk by the canonical label set it carries and is
// recognised **by node identity**, not by its declared partitioning: it publishes
// `UnknownPartitioning(M)`, which says "this node promises nothing about where a key lives" and
// is deliberately not upgraded to a proof. Every other child places pieces by the storage
// `read_key`, so pieces of one canonical label set can sit in different partitions and nothing
// is claimed about their ownership.
//
// What that means for a merge is [`merges_are_placeable_in`]'s question, not this function's:
// over an unproven input a merge is not placeable in a per-partition execution, so the route
// that would need one declines rather than collapsing the node to a single execution.
inputs
.iter()
.map(|_| NativeProperties::source_pieces())
.map(|(input, _, _)| NativeProperties {
owner: if input.downcast_ref::<SeriesRepartitionExec>().is_some() {
CanonicalOwner::ByCanonicalKey
} else {
CanonicalOwner::Unknown
},
..NativeProperties::source_pieces()
})
.collect()
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff