This is an automated email from the ASF dual-hosted git repository.
ycycse pushed a commit to branch ycy/memoryIssueFix
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/ycy/memoryIssueFix by this
push:
new 3d3c6e72072 fix: the incorrect way to calculate
3d3c6e72072 is described below
commit 3d3c6e7207269020b35c63dc5d86aa58c5fdfab6
Author: ycycse <[email protected]>
AuthorDate: Wed Jun 12 20:54:57 2024 +0800
fix: the incorrect way to calculate
---
.../iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java | 13 ++++++++++---
.../org/apache/iotdb/commons/utils/TimePartitionUtils.java | 4 ++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
index 914df45d4e6..08d2958fe9e 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
@@ -2054,9 +2054,6 @@ public class AnalyzeVisitor extends
StatementVisitor<Analysis, MPPQueryContext>
int index = 0;
int size = timeRangeList.size();
- context.reserveMemoryForFrontEnd(
- timeRangeList.size() *
RamUsageEstimator.shallowSizeOfInstance(TTimePartitionSlot.class));
-
if (timeRangeList.get(0).getMin() == Long.MIN_VALUE) {
needLeftAll = true;
endTime =
TimePartitionUtils.getTimePartitionUpperBound(timeRangeList.get(0).getMax());
@@ -2075,6 +2072,7 @@ public class AnalyzeVisitor extends
StatementVisitor<Analysis, MPPQueryContext>
}
List<TTimePartitionSlot> result = new ArrayList<>();
+ reserveMemoryForTimePartitionSlot(timeRangeList.get(index).getMax(),
context);
while (index < size) {
long curLeft = timeRangeList.get(index).getMin();
long curRight = timeRangeList.get(index).getMax();
@@ -2090,6 +2088,9 @@ public class AnalyzeVisitor extends
StatementVisitor<Analysis, MPPQueryContext>
endTime = endTime + TimePartitionUtils.getTimePartitionInterval();
} else {
index++;
+ if (index < size) {
+ reserveMemoryForTimePartitionSlot(timeRangeList.get(index).getMax(),
context);
+ }
}
}
result.add(timePartitionSlot);
@@ -2105,6 +2106,12 @@ public class AnalyzeVisitor extends
StatementVisitor<Analysis, MPPQueryContext>
return new Pair<>(result, new Pair<>(needLeftAll, needRightAll));
}
+ private static void reserveMemoryForTimePartitionSlot(long maxTime,
MPPQueryContext context) {
+ long size = TimePartitionUtils.getTimePartitionSize(maxTime);
+ context.reserveMemoryForFrontEnd(
+ RamUsageEstimator.shallowSizeOfInstance(TTimePartitionSlot.class) *
size);
+ }
+
private void analyzeInto(
Analysis analysis,
QueryStatement queryStatement,
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TimePartitionUtils.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TimePartitionUtils.java
index fe20e6ba155..f1d840b6981 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TimePartitionUtils.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TimePartitionUtils.java
@@ -82,4 +82,8 @@ public class TimePartitionUtils {
public static void setTimePartitionInterval(long timePartitionInterval) {
TimePartitionUtils.timePartitionInterval = timePartitionInterval;
}
+
+ public static long getTimePartitionSize(long endTime) {
+ return endTime / timePartitionInterval + 1;
+ }
}