This is an automated email from the ASF dual-hosted git repository.

huajianlan pushed a commit to branch fe_local_shuffle
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 20d282ad2c01c509523350530c1bbe9a61e2346a
Author: 924060929 <[email protected]>
AuthorDate: Tue Apr 14 14:49:09 2026 +0800

    [fix](local shuffle) Fix instanceCount check and 
ExchangeNode.isSerialOperator cycle
    
    1. AddLocalExchange: use per-BE max instance count instead of global sum
       to match BE's _num_instances semantics. Fixes mismatch where FE inserts
       LE (global instanceCount>1) but each BE locally skips (num_instances=1).
    
    2. ExchangeNode: break isSerialOperator→useSerialSource→hasSerialChildren
       →isSerialOperator infinite recursion by splitting static serial check
       into private isStaticSerialOperator() used by hasSerialChildren().
---
 .../org/apache/doris/planner/AddLocalExchange.java | 18 +++++++++++------
 .../org/apache/doris/planner/ExchangeNode.java     | 23 ++++++++++++++++------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/AddLocalExchange.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/AddLocalExchange.java
index b518c4bf042..864fed6aeb6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/AddLocalExchange.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/AddLocalExchange.java
@@ -37,16 +37,22 @@ public class AddLocalExchange {
     }
 
     /** addLocalExchange with distributed plans, skipping single-instance 
fragments.
-     *  BE's _plan_local_exchange processes all pipelines regardless of 
_num_instances,
-     *  but with _num_instances==1 all pipelines have 1 task so local exchange 
is a no-op.
-     *  Skipping avoids inserting LOCAL_EXCHANGE_NODEs that change pipeline 
structure
-     *  without benefit and may cause sender/receiver count mismatches. */
+     *  BE's _plan_local_exchange checks _num_instances which is the per-BE 
instance count.
+     *  With _num_instances<=1 all pipelines on that BE have 1 task so local 
exchange is a no-op.
+     *  We must use the same per-BE semantics: skip when every BE has at most 
1 instance.
+     *  Using global instanceCount would insert LE for fragments where 2 BEs 
each have 1 instance
+     *  (global=2, per-BE=1), causing pipeline task mismatch and deadlock. */
     public void addLocalExchange(FragmentIdMapping<DistributedPlan> 
distributedPlans,
             PlanTranslatorContext context) {
         for (DistributedPlan plan : distributedPlans.values()) {
             PipelineDistributedPlan pipePlan = (PipelineDistributedPlan) plan;
-            int instanceCount = pipePlan.getInstanceJobs().size();
-            if (instanceCount <= 1) {
+            // Use per-BE max instance count to match BE's _num_instances 
semantics.
+            // BE skips _plan_local_exchange when _num_instances <= 1 (per-BE 
check).
+            long maxPerBeInstances = pipePlan.getInstanceJobs().stream()
+                    .collect(java.util.stream.Collectors.groupingBy(
+                            j -> j.getAssignedWorker().id(), 
java.util.stream.Collectors.counting()))
+                    
.values().stream().mapToLong(Long::longValue).max().orElse(0);
+            if (maxPerBeInstances <= 1) {
                 continue;
             }
             PlanFragment fragment = pipePlan.getFragmentJob().getFragment();
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/ExchangeNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/ExchangeNode.java
index 8c6eb5c8885..cc084c0f4b5 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/ExchangeNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/ExchangeNode.java
@@ -157,11 +157,14 @@ public class ExchangeNode extends PlanNode {
      *
      * So FRAGMENT 0 should not use serial source.
      */
+    /**
+     * Whether this Exchange will be serial on BE. Matches toThrift condition:
+     * (staticSerial || hasSerialScanNode) && useSerialSource.
+     * Without useSerialSource gate, non-pooling UNPARTITIONED exchanges would 
be treated
+     * as serial, causing incorrect PASS_TO_ONE insertion in broadcast joins.
+     */
     @Override
     public boolean isSerialOperator() {
-        // Must match toThrift: (staticSerial || hasSerialScanNode) && 
useSerialSource.
-        // Without useSerialSource gate, non-pooling UNPARTITIONED exchanges 
would be treated
-        // as serial, causing incorrect PASS_TO_ONE insertion in broadcast 
joins.
         ConnectContext ctx = ConnectContext.get();
         if (ctx == null || fragment == null) {
             return false;
@@ -169,14 +172,22 @@ public class ExchangeNode extends PlanNode {
         if (!fragment.useSerialSource(ctx)) {
             return false;
         }
-        boolean staticSerial = (ctx.getSessionVariable().isUseSerialExchange()
+        return isStaticSerialOperator() || fragment.hasSerialScanNode();
+    }
+
+    /** Static serial check without fragment context. Used by 
hasSerialChildren()
+     *  to avoid infinite recursion: isSerialOperator → useSerialSource → 
hasSerialChildren
+     *  → isSerialOperator. */
+    private boolean isStaticSerialOperator() {
+        ConnectContext ctx = ConnectContext.get();
+        return (ctx != null && ctx.getSessionVariable().isUseSerialExchange()
                 || partitionType == TPartitionType.UNPARTITIONED) && mergeInfo 
== null;
-        return staticSerial || fragment.hasSerialScanNode();
     }
 
     @Override
     public boolean hasSerialChildren() {
-        return isSerialOperator();
+        // Use static check to avoid recursion through useSerialSource → 
hasSerialScanNode
+        return isStaticSerialOperator();
     }
 
     @Override


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to