You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2023/02/27 09:05:56 UTC

[iotdb] branch master updated: [IOTDB-5462] Optimize the memory estimation of ExchangeOperator in the pipelin

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

jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 12d9e73d6f [IOTDB-5462] Optimize the memory estimation of ExchangeOperator in the pipelin
12d9e73d6f is described below

commit 12d9e73d6f7cb9bb7be4e4311011138d269308a5
Author: liuminghui233 <36...@users.noreply.github.com>
AuthorDate: Mon Feb 27 17:05:49 2023 +0800

    [IOTDB-5462] Optimize the memory estimation of ExchangeOperator in the pipelin
---
 .../operator/source/ExchangeOperator.java          | 23 ++++++++++++++++++++--
 .../db/mpp/plan/planner/OperatorTreeGenerator.java |  6 ++++--
 .../mpp/execution/operator/OperatorMemoryTest.java | 15 ++++++++++++++
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/ExchangeOperator.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/ExchangeOperator.java
index ba57e1ff07..8699c3e135 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/ExchangeOperator.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/ExchangeOperator.java
@@ -37,6 +37,8 @@ public class ExchangeOperator implements SourceOperator {
 
   private ListenableFuture<?> isBlocked = NOT_BLOCKED;
 
+  private long maxReturnSize = DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES;
+
   public ExchangeOperator(
       OperatorContext operatorContext, ISourceHandle sourceHandle, PlanNodeId sourceId) {
     this.operatorContext = operatorContext;
@@ -44,6 +46,23 @@ public class ExchangeOperator implements SourceOperator {
     this.sourceId = sourceId;
   }
 
+  /**
+   * For ExchangeOperator in pipeline, the maxReturnSize is equal to the maxReturnSize of the child
+   * operator.
+   *
+   * @param maxReturnSize max return size of child operator
+   */
+  public ExchangeOperator(
+      OperatorContext operatorContext,
+      ISourceHandle sourceHandle,
+      PlanNodeId sourceId,
+      long maxReturnSize) {
+    this.operatorContext = operatorContext;
+    this.sourceHandle = sourceHandle;
+    this.sourceId = sourceId;
+    this.maxReturnSize = maxReturnSize;
+  }
+
   @Override
   public OperatorContext getOperatorContext() {
     return operatorContext;
@@ -66,12 +85,12 @@ public class ExchangeOperator implements SourceOperator {
 
   @Override
   public long calculateMaxPeekMemory() {
-    return DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES;
+    return maxReturnSize;
   }
 
   @Override
   public long calculateMaxReturnSize() {
-    return DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES;
+    return maxReturnSize;
   }
 
   @Override
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/OperatorTreeGenerator.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/OperatorTreeGenerator.java
index f56794b004..eb53954cfa 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/OperatorTreeGenerator.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/OperatorTreeGenerator.java
@@ -2504,7 +2504,8 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
             MPP_DATA_EXCHANGE_MANAGER.createLocalSourceHandleForPipeline(
                 ((LocalSinkChannel) localSinkChannel).getSharedTsBlockQueue(),
                 context.getDriverContext()),
-            childNode.getPlanNodeId());
+            childNode.getPlanNodeId(),
+            childOperation.calculateMaxReturnSize());
 
     context.getTimeSliceAllocator().recordExecutionWeight(sourceOperator.getOperatorContext(), 1);
     context.addExchangeOperator(sourceOperator);
@@ -2582,7 +2583,8 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
                   MPP_DATA_EXCHANGE_MANAGER.createLocalSourceHandleForPipeline(
                       ((LocalSinkChannel) localSinkChannel).getSharedTsBlockQueue(),
                       context.getDriverContext()),
-                  childNode.getPlanNodeId());
+                  childNode.getPlanNodeId(),
+                  childOperation.calculateMaxReturnSize());
           context
               .getTimeSliceAllocator()
               .recordExecutionWeight(sourceOperator.getOperatorContext(), 1);
diff --git a/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/OperatorMemoryTest.java b/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/OperatorMemoryTest.java
index 864bae8d9b..d6343d3392 100644
--- a/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/OperatorMemoryTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/OperatorMemoryTest.java
@@ -225,6 +225,21 @@ public class OperatorMemoryTest {
     assertEquals(0, exchangeOperator.calculateRetainedSizeAfterCallingNext());
   }
 
+  @Test
+  public void pipelineExchangeOperatorTest() {
+    Operator child = Mockito.mock(Operator.class);
+    Mockito.when(child.calculateMaxPeekMemory()).thenReturn(2048L);
+    Mockito.when(child.calculateMaxReturnSize()).thenReturn(1024L);
+    Mockito.when(child.calculateRetainedSizeAfterCallingNext()).thenReturn(512L);
+
+    ExchangeOperator exchangeOperator =
+        new ExchangeOperator(null, null, null, child.calculateMaxReturnSize());
+
+    assertEquals(1024L, exchangeOperator.calculateMaxPeekMemory());
+    assertEquals(1024L, exchangeOperator.calculateMaxReturnSize());
+    assertEquals(0, exchangeOperator.calculateRetainedSizeAfterCallingNext());
+  }
+
   @Test
   public void lastCacheScanOperatorTest() {
     TsBlock tsBlock = Mockito.mock(TsBlock.class);