mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-29 06:04:06 +00:00
fix(promql): do not record a label set a series never produced a value under
`rate` over a five-minute window holding one sample has no result, so a series can reach this node with a closing chunk of missing values and nothing else. Recording that chunk registered the label set and marked it closed, which then refused the *next* series that also produced nothing: the answer was empty, and the node reported a collision instead. A chunk holding no value under a label set not yet seen owns nothing, so it is passed over. A label set that already holds values still closes on its last chunk, and a real collision -- two series holding a value at the same position -- is still refused. Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
This commit is contained in:
@@ -319,6 +319,13 @@ impl Emitted {
|
||||
.iter()
|
||||
.map(|field| occupied_runs(field, base))
|
||||
.collect();
|
||||
// A series that produced no value at all owns nothing here: it hands out no sample under
|
||||
// this label set, so recording it would refuse the next series that produces none either,
|
||||
// and the answer to both is simply empty. Only a label set already holding values has to
|
||||
// be marked closed when its last chunk arrives.
|
||||
if occupied.iter().all(Vec::is_empty) && !self.sets.contains_key(&labels) {
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(history) = self.sets.get(&labels) {
|
||||
if history.closed {
|
||||
return Err(closed_label_set(path, &labels));
|
||||
|
||||
@@ -1622,3 +1622,51 @@ fn the_emitted_charge_is_the_same_folded_in_as_walked() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Two series that each produce no value at all are not a collision: both answer empty, and the
|
||||
/// node hands nothing on rather than refusing the second one.
|
||||
///
|
||||
/// `rate` over a five-minute window with one sample in it has no result, in the single-point and
|
||||
/// the batch kernel alike. Both series then arrive as a closing chunk of missing values under the
|
||||
/// same label set -- `rate` drops the name -- but neither holds a sample, so there is nothing to
|
||||
/// report twice and nothing to merge.
|
||||
#[test]
|
||||
fn two_series_with_no_result_do_not_collide() {
|
||||
let out = grid(0, 60_000, 1);
|
||||
let tree = NativeTree::try_new(window_with(
|
||||
input(),
|
||||
RangeFunction::Rate,
|
||||
300_000,
|
||||
None,
|
||||
Arc::clone(&out),
|
||||
))
|
||||
.unwrap();
|
||||
let schema = raw_schema();
|
||||
let mut execution = executor(&tree, pool(), &ExecutionPlanMetricsSet::new());
|
||||
|
||||
// One sample each: rate over a 5m window with a single sample has no result.
|
||||
for name in ["a", "b"] {
|
||||
execution
|
||||
.push_raw(raw_chunk_of(
|
||||
&schema,
|
||||
name.as_bytes(),
|
||||
MetricName::try_new(Some(name.into()), vec![]).unwrap(),
|
||||
&[0],
|
||||
&[1.0],
|
||||
true,
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
let mut handed = Vec::new();
|
||||
loop {
|
||||
match execution.next_chunk() {
|
||||
Ok(Some(chunk)) => handed.push(decided(&[chunk])),
|
||||
Ok(None) => break,
|
||||
Err(error) => panic!("two empty series were refused: {error}"),
|
||||
}
|
||||
}
|
||||
assert!(
|
||||
handed.iter().flatten().all(|(_, value)| value.is_none()),
|
||||
"a series with no result handed a value on: {handed:?}"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user