Skip to content

Commit fc5812b

Browse files
committed
Adapt ready-first collect to Apache master
1 parent 1cd73b3 commit fc5812b

10 files changed

Lines changed: 49 additions & 8 deletions

File tree

‎iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/CollectOperator.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ public ListenableFuture<?> isBlocked() {
9191
if (!inited) {
9292
inited = true;
9393
for (Operator child : children) {
94-
child.isBlocked();
94+
if (child != null) {
95+
child.isBlocked();
96+
}
9597
}
9698
}
9799
if (children.isEmpty()) {

‎iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/plan/planner/memory/MemoryReservationManager.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public interface MemoryReservationManager {
5454
*/
5555
void releaseMemoryImmediately(final long size);
5656

57+
/** Flushes any batched release accumulated by {@link #releaseMemoryCumulatively(long)}. */
58+
default void releaseMemoryImmediately() {
59+
// Implementations that batch releases override this method.
60+
}
61+
5762
/**
5863
* Release all reserved memory immediately. Make sure this method is called when the lifecycle of
5964
* this manager ends, Or the memory to be released in the batch may not be released correctly.

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/exchange/SharedTsBlockQueue.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void setMemoryReservationGroupId(String reservationPlanNodeId) {
159159
// Collect group. Restore the fragment-instance limit so the shared reservation key, rather
160160
// than an individual queue, is the group-wide limit.
161161
this.maxBytesCanReserve =
162-
IoTDBDescriptor.getInstance().getConfig().getMaxBytesPerFragmentInstance();
162+
IoTDBDescriptor.getInstance().getMemoryConfig().getMaxBytesPerFragmentInstance();
163163
}
164164
}
165165

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/exchange/source/SourceHandle.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ public synchronized void setMemoryReservationGroupId(String reservationPlanNodeI
567567
// Collect group. Restore the fragment-instance limit so the shared reservation key, rather
568568
// than an individual handle, is the group-wide limit.
569569
this.maxBytesCanReserve =
570-
IoTDBDescriptor.getInstance().getConfig().getMaxBytesPerFragmentInstance();
570+
IoTDBDescriptor.getInstance().getMemoryConfig().getMaxBytesPerFragmentInstance();
571571
}
572572
localMemoryManager
573573
.getQueryPool()

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/DataNodeTableOperatorGenerator.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.iotdb.commons.queryengine.plan.relational.metadata.QualifiedObjectName;
4848
import org.apache.iotdb.commons.queryengine.plan.relational.planner.Symbol;
4949
import org.apache.iotdb.commons.queryengine.plan.relational.planner.node.AggregationNode;
50+
import org.apache.iotdb.commons.queryengine.plan.relational.planner.node.CollectNode;
5051
import org.apache.iotdb.commons.queryengine.plan.relational.planner.node.TopKNode;
5152
import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.Expression;
5253
import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.FunctionCall;
@@ -229,6 +230,16 @@ public DataNodeTableOperatorGenerator(Metadata metadata) {
229230
super(metadata);
230231
}
231232

233+
@Override
234+
public Operator visitCollect(CollectNode node, LocalExecutionPlanContext context) {
235+
CollectQuotaGroup quotaGroup = context.enterCollectQuotaGroup(node.getPlanNodeId().getId());
236+
try {
237+
return super.visitCollect(node, context);
238+
} finally {
239+
context.exitCollectQuotaGroup(quotaGroup);
240+
}
241+
}
242+
232243
/**
233244
* Producer side: register a shared {@link TopKRuntimeFilter} before visiting TopK children so
234245
* nested Scan nodes can resolve the same instance during operator generation.
@@ -385,6 +396,7 @@ public Operator visitTableExchange(ExchangeNode node, LocalExecutionPlanContext
385396
if (!isSameNode) {
386397
context.addExchangeSumNum(1);
387398
}
399+
context.registerExchangeSourceHandle(sourceHandle);
388400
sourceHandle.setMaxBytesCanReserve(context.getMaxBytesOneHandleCanReserve());
389401
ExchangeOperator exchangeOperator =
390402
new ExchangeOperator(operatorContext, sourceHandle, node.getUpstreamPlanNodeId());

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LocalExecutionPlanContext.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ public void setMaxBytesOneHandleCanReserve() {
299299
exchangeSumNum);
300300
java.util.Set<ISourceHandle> groupedSourceHandles =
301301
Collections.newSetFromMap(new IdentityHashMap<>());
302-
long maxBytesPerFI = IoTDBDescriptor.getInstance().getConfig().getMaxBytesPerFragmentInstance();
302+
long maxBytesPerFI =
303+
IoTDBDescriptor.getInstance().getMemoryConfig().getMaxBytesPerFragmentInstance();
303304
for (CollectQuotaGroup group : collectQuotaGroups) {
304305
for (ISourceHandle sourceHandle : group.getSourceHandles()) {
305306
groupedSourceHandles.add(sourceHandle);

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,13 @@ public Operator visitCollect(CollectNode node, LocalExecutionPlanContext context
11811181
context.getNextOperatorId(),
11821182
node.getPlanNodeId(),
11831183
CollectOperator.class.getSimpleName());
1184-
return new CollectOperator(operatorContext, dealWithConsumeChildrenOneByOneNode(node, context));
1184+
CollectQuotaGroup quotaGroup = context.enterCollectQuotaGroup(node.getPlanNodeId().getId());
1185+
try {
1186+
return new CollectOperator(
1187+
operatorContext, dealWithConsumeChildrenOneByOneNode(node, context));
1188+
} finally {
1189+
context.exitCollectQuotaGroup(quotaGroup);
1190+
}
11851191
}
11861192

11871193
@Override

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/memory/NotThreadSafeMemoryReservationManager.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ public void releaseMemoryImmediately(final long size) {
143143
}
144144
}
145145

146+
@Override
147+
public void releaseMemoryImmediately() {
148+
if (bytesToBeReleased > 0) {
149+
releaseBytesImmediately(bytesToBeReleased);
150+
bytesToBeReleased = 0;
151+
}
152+
}
153+
146154
private void releaseBytesImmediately(final long size) {
147155
long poolBytes = deductReleaseAccounting(size);
148156
if (poolBytes > 0) {

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/memory/ThreadSafeMemoryReservationManager.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public synchronized void releaseMemoryImmediately(long size) {
5656
super.releaseMemoryImmediately(size);
5757
}
5858

59+
@Override
60+
public synchronized void releaseMemoryImmediately() {
61+
super.releaseMemoryImmediately();
62+
}
63+
5964
@Override
6065
public synchronized void releaseAllReservedMemory() {
6166
super.releaseAllReservedMemory();

‎iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/CollectOperatorTest.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
package org.apache.iotdb.db.queryengine.execution.operator;
2121

22-
import org.apache.iotdb.db.queryengine.execution.operator.process.CollectOperator;
22+
import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
23+
import org.apache.iotdb.calc.execution.operator.Operator;
24+
import org.apache.iotdb.calc.execution.operator.process.CollectOperator;
2325

2426
import com.google.common.util.concurrent.ListenableFuture;
2527
import com.google.common.util.concurrent.SettableFuture;
@@ -81,7 +83,7 @@ private static TsBlock block(int value) {
8183
private static final class TestOperator implements Operator {
8284
private final List<TsBlock> blocks;
8385
private final ListenableFuture<?> blocked;
84-
private final OperatorContext operatorContext = Mockito.mock(OperatorContext.class);
86+
private final CommonOperatorContext operatorContext = Mockito.mock(CommonOperatorContext.class);
8587
private int index;
8688

8789
private TestOperator(TsBlock block, ListenableFuture<?> blocked) {
@@ -94,7 +96,7 @@ private TestOperator(List<TsBlock> blocks, ListenableFuture<?> blocked) {
9496
}
9597

9698
@Override
97-
public OperatorContext getOperatorContext() {
99+
public CommonOperatorContext getOperatorContext() {
98100
return operatorContext;
99101
}
100102

0 commit comments

Comments
 (0)