Skip to content

Commit e1df149

Browse files
authored
[fix](local shuffle) Prevent local exchange under serial parent pipeline (apache#67490)
When FE local shuffle planning inserted a local exchange into a pipeline whose parent pipeline was serial, it could increase only the downstream pipeline task count while the paired sink and source operators remained one-to-one. This produced inconsistent pipeline concurrency and could fail during execution. Root cause: FE did not propagate the serial state of a parent pipeline across pipeline boundaries. This change tracks that state and skips local exchange insertion when the parent pipeline is serial, matching the existing BE planning constraint. ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
1 parent ac7244f commit e1df149

4 files changed

Lines changed: 63 additions & 3 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PlanTranslatorContext.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ public class PlanTranslatorContext {
133133
// root and across pipeline boundaries (see shouldResetSerialFlagForChild).
134134
private final Map<PlanNodeId, Boolean> serialAncestorInPipelineMap = Maps.newHashMap();
135135

136+
// Per-node "does this pipeline have a serial parent pipeline" flag. Mirrors BE's
137+
// Pipeline::num_tasks_of_parent() gate in _add_local_exchange: a pipeline whose parent
138+
// has one task must not be split by another local exchange, because that would raise only
139+
// the new source side to N tasks while the paired sink/source operators stay one-to-one.
140+
private final Map<PlanNodeId, Boolean> serialParentPipelineMap = Maps.newHashMap();
141+
136142
// Per-node "is there a downstream operator that depends on hash distribution for
137143
// correctness, with HASH/NOOP path connecting it to me" flag. Mirrors BE's
138144
// _followed_by_shuffled_operator propagation in pipeline_fragment_context.cpp.
@@ -292,6 +298,14 @@ public boolean hasSerialAncestorInPipeline(PlanNode node) {
292298
return serialAncestorInPipelineMap.getOrDefault(node.getId(), false);
293299
}
294300

301+
public void setHasSerialParentPipeline(PlanNode node, boolean value) {
302+
serialParentPipelineMap.put(node.getId(), value);
303+
}
304+
305+
public boolean hasSerialParentPipeline(PlanNode node) {
306+
return serialParentPipelineMap.getOrDefault(node.getId(), false);
307+
}
308+
295309
public void setHasShuffleForCorrectnessAncestor(PlanNode node, boolean value) {
296310
shuffledAncestorMap.put(node.getId(), value);
297311
}

‎fe/fe-core/src/main/java/org/apache/doris/planner/AddLocalExchange.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ private void addLocalExchangeForFragment(PlanFragment fragment, PlanTranslatorCo
197197
? LocalExchangeTypeRequire.noRequire() : sink.getLocalExchangeTypeRequire();
198198
PlanNode root = fragment.getPlanRoot();
199199
context.setHasSerialAncestorInPipeline(root, false);
200+
context.setHasSerialParentPipeline(root, false);
200201
Pair<PlanNode, LocalExchangeType> output = root
201202
.enforceAndDeriveLocalExchange(context, null, require);
202203
PlanNode newRoot = output.first;

‎fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
import com.google.common.base.Joiner;
5252
import com.google.common.base.Preconditions;
53+
import com.google.common.base.Suppliers;
5354
import com.google.common.collect.Lists;
5455
import com.google.common.collect.Maps;
5556
import org.apache.commons.collections4.CollectionUtils;
@@ -65,6 +66,7 @@
6566
import java.util.Set;
6667
import java.util.function.Consumer;
6768
import java.util.function.Predicate;
69+
import java.util.function.Supplier;
6870
import java.util.stream.Collectors;
6971

7072
/**
@@ -1069,7 +1071,12 @@ protected Pair<PlanNode, LocalExchangeType> enforceRequire(
10691071
// node's sink, e.g. Exchange is in AGG_Sink pipeline).
10701072
// For non-splitting operators (shouldReset=false, e.g. streaming AGG):
10711073
// Inherit parent's serial flag + this node's own.
1072-
boolean inheritedSerial = shouldResetSerialFlagForChild(childIndex)
1074+
boolean startsNewPipeline = shouldResetSerialFlagForChild(childIndex);
1075+
Supplier<Boolean> currentNodeSerialOnBe = Suppliers.memoize(
1076+
() -> isSerialOperatorOnBe(translatorContext.getConnectContext()));
1077+
boolean currentPipelineSerial = translatorContext.hasSerialAncestorInPipeline(this)
1078+
|| currentNodeSerialOnBe.get();
1079+
boolean inheritedSerial = startsNewPipeline
10731080
? false : translatorContext.hasSerialAncestorInPipeline(this);
10741081
// Use isSerialOperatorOnBe (= isSerialNode && fragment.useSerialSource) instead of the
10751082
// raw isSerialNode(). BE's OperatorBase reads the Thrift `is_serial_operator` flag —
@@ -1078,8 +1085,10 @@ protected Pair<PlanNode, LocalExchangeType> enforceRequire(
10781085
// Using isSerialNode here would set the child's serial-ancestor flag wider than BE's
10791086
// view and over-skip required LocalExchanges downstream.
10801087
boolean childHasSerialAncestor = inheritedSerial
1081-
|| isSerialOperatorOnBe(translatorContext.getConnectContext());
1088+
|| currentNodeSerialOnBe.get();
10821089
translatorContext.setHasSerialAncestorInPipeline(child, childHasSerialAncestor);
1090+
translatorContext.setHasSerialParentPipeline(child, startsNewPipeline
1091+
? currentPipelineSerial : translatorContext.hasSerialParentPipeline(this));
10831092

10841093
// 1b. Propagate shuffle-for-correctness-ancestor flag to child.
10851094
// Mirrors BE's _followed_by_shuffled_operator: a downstream operator needs hash
@@ -1140,7 +1149,8 @@ protected Pair<PlanNode, LocalExchangeType> enforceRequire(
11401149
// Use isSerialOperatorOnBe (not isSerialNode) because BE's Pipeline::need_to_local_exchange
11411150
// checks op->is_serial_operator() which reads the Thrift flag set from isSerialOperatorOnBe;
11421151
// when fragment.useSerialSource is false, BE treats this node as non-serial.
1143-
if (translatorContext.hasSerialAncestorInPipeline(this)
1152+
if (translatorContext.hasSerialParentPipeline(this)
1153+
|| translatorContext.hasSerialAncestorInPipeline(this)
11441154
|| isSerialOperatorOnBe(translatorContext.getConnectContext())) {
11451155
return childOutput;
11461156
}

‎regression-test/suites/nereids_p0/local_shuffle/test_local_shuffle_rqg_bugs.groovy‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,5 +1663,40 @@ suite("test_local_shuffle_rqg_bugs") {
16631663
assertTrue(false, "Bug 26: ${t.message}")
16641664
}
16651665

1666+
// Bug 27: do not insert a local exchange in a pipeline whose parent pipeline is serial.
1667+
// Otherwise the local exchange raises the lower AggSink pipeline to N tasks while its
1668+
// paired AggSource remains at one task, leaving task 1+ without a source dependency.
1669+
def bug27Query = { planner -> """
1670+
SELECT /*+SET_VAR(enable_local_shuffle_planner=${planner},
1671+
enable_local_exchange_before_agg=false,
1672+
enable_local_exchange_before_streaming_agg=true,
1673+
enable_broadcast_join_force_passthrough=true,
1674+
enable_share_hash_table_for_broadcast_join=false,
1675+
parallel_pipeline_task_num=3,
1676+
enable_sql_cache=false)*/
1677+
COUNT(*),
1678+
COUNT(DISTINCT CAST(f.pk AS STRING)),
1679+
MIN(CAST(f.pk AS STRING)),
1680+
MAX(CAST(f.pk AS STRING)),
1681+
COUNT(DISTINCT CAST(d.pk AS STRING)),
1682+
MIN(CAST(d.pk AS STRING)),
1683+
MAX(CAST(d.pk AS STRING)),
1684+
COUNT(DISTINCT CAST(f.col_int_undef_signed AS STRING)),
1685+
MIN(CAST(f.col_int_undef_signed AS STRING)),
1686+
MAX(CAST(f.col_int_undef_signed AS STRING))
1687+
FROM rqg_t1 f
1688+
INNER JOIN (
1689+
SELECT * FROM rqg_t2 d
1690+
WHERE d.col_int_undef_signed = 1 AND COALESCE(d.pk, -1) >= 10
1691+
) d ON d.col_int_undef_signed = f.col_int_undef_signed
1692+
AND f.col_int_undef_signed = f.col_int_undef_signed2
1693+
AND f.pk = d.pk
1694+
""" }
1695+
1696+
def bug27BeResult = sql bug27Query(false)
1697+
for (int i = 0; i < 20; i++) {
1698+
assertEquals(bug27BeResult, sql(bug27Query(true)), "Bug 27 run ${i}")
1699+
}
1700+
16661701
logger.info("=== All RQG bug reproduction tests completed ===")
16671702
}

0 commit comments

Comments
 (0)