Skip to content

Commit a6554c9

Browse files
committed
fix: Fix the memory calculation for Optional and other fields
1 parent f3df840 commit a6554c9

36 files changed

+83
-228
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AsofJoinOn.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ public List<Node> getNodes() {
168168
public long ramBytesUsed() {
169169
long size = INSTANCE_SIZE;
170170
size += ramBytesUsedExcludingInstanceSize();
171-
if (asofExpression != null) {
172-
size += asofExpression.ramBytesUsed();
173-
}
171+
size += AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(asofExpression);
174172
return size;
175173
}
176174
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AstMemoryEstimationHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ public static long getEstimatedSizeOfIntegerList(@Nullable final List<Integer> i
9191
return size;
9292
}
9393

94+
public static long getEstimatedSizeOfLongList(@Nullable final List<Long> longs) {
95+
if (longs == null || longs.isEmpty()) {
96+
return 0L;
97+
}
98+
long size = RamUsageEstimator.shallowSizeOf(longs);
99+
for (Long longValue : longs) {
100+
if (longValue != null) {
101+
size += Long.BYTES;
102+
}
103+
}
104+
return size;
105+
}
106+
94107
public static long getEstimatedSizeOfObjectArrayList(
95108
@Nullable final List<Object[]> objectArrayList) {
96109
if (objectArrayList == null || objectArrayList.isEmpty()) {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ClearCache.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.Set;
3030

3131
import static com.google.common.base.MoreObjects.toStringHelper;
32-
import static java.util.stream.Collectors.toList;
3332

3433
public class ClearCache extends Statement {
3534
private static final long INSTANCE_SIZE =
@@ -89,10 +88,7 @@ public String toString() {
8988
public long ramBytesUsed() {
9089
long size = INSTANCE_SIZE;
9190
size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
92-
if (options != null) {
93-
size +=
94-
RamUsageEstimator.shallowSizeOf(options.stream().map(Enum::ordinal).collect(toList()));
95-
}
91+
size += RamUsageEstimator.sizeOfCollection(options);
9692
return size;
9793
}
9894
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CountStatement.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ public long ramBytesUsed() {
9292
long size = INSTANCE_SIZE;
9393
size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
9494
size += RamUsageEstimator.sizeOf(tableName);
95-
if (where.isPresent()) {
96-
size += AstMemoryEstimationHelper.OPTIONAL_INSTANCE_SIZE;
97-
size += where.get() == null ? 0L : where.get().ramBytesUsed();
98-
}
95+
size += AstMemoryEstimationHelper.OPTIONAL_INSTANCE_SIZE;
96+
size += AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(where.orElse(null));
9997
return size;
10098
}
10199
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CreateIndex.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ public long ramBytesUsed() {
117117
size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
118118
size += tableName == null ? 0L : tableName.ramBytesUsed();
119119
size += AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(indexName);
120-
size += RamUsageEstimator.shallowSizeOf(columnList);
121-
for (Identifier column : columnList) {
122-
size += column == null ? 0L : column.ramBytesUsed();
123-
}
120+
size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(columnList);
124121
return size;
125122
}
126123
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ExcludedPattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public boolean shallowEquals(Node other) {
8484
public long ramBytesUsed() {
8585
long size = INSTANCE_SIZE;
8686
size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
87-
size += pattern == null ? 0L : pattern.ramBytesUsed();
87+
size += AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(pattern);
8888
return size;
8989
}
9090
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ExtendRegion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public int getDataNodeId() {
8282
public long ramBytesUsed() {
8383
long size = INSTANCE_SIZE;
8484
size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
85-
size += RamUsageEstimator.shallowSizeOf(regionIds);
85+
size += AstMemoryEstimationHelper.getEstimatedSizeOfIntegerList(regionIds);
8686
return size;
8787
}
8888
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/Flush.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
2323
import org.apache.iotdb.db.queryengine.plan.statement.Statement;
2424

25-
import org.apache.tsfile.utils.RamUsageEstimator;
26-
2725
public class Flush extends WrappedStatement {
28-
private static final long INSTANCE_SIZE = RamUsageEstimator.shallowSizeOfInstance(Flush.class);
2926

3027
public Flush(final Statement innerTreeStatement, final MPPQueryContext context) {
3128
super(innerTreeStatement, context);

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/FrameBound.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,8 @@ public FrameBound(ByteBuffer byteBuffer) {
145145
public long ramBytesUsed() {
146146
long size = INSTANCE_SIZE;
147147
size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
148-
if (value.isPresent()) {
149-
size += AstMemoryEstimationHelper.OPTIONAL_INSTANCE_SIZE;
150-
size += AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(value.get());
151-
}
148+
size += AstMemoryEstimationHelper.OPTIONAL_INSTANCE_SIZE;
149+
size += AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(value.orElse(null));
152150
return size;
153151
}
154152
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/FunctionCall.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,20 +344,15 @@ public long ramBytesUsed() {
344344
size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal());
345345
size += name == null ? 0L : name.ramBytesUsed();
346346
size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeList(arguments);
347+
size += 3 * AstMemoryEstimationHelper.OPTIONAL_INSTANCE_SIZE;
347348
if (window.isPresent()) {
348-
size += AstMemoryEstimationHelper.OPTIONAL_INSTANCE_SIZE;
349349
Window windowValue = window.get();
350350
if (windowValue instanceof Node) {
351351
size += ((Node) windowValue).ramBytesUsed();
352352
}
353353
}
354-
if (processingMode.isPresent()) {
355-
size += AstMemoryEstimationHelper.OPTIONAL_INSTANCE_SIZE;
356-
size += processingMode.get().ramBytesUsed();
357-
}
358-
if (nullTreatment.isPresent()) {
359-
size += AstMemoryEstimationHelper.OPTIONAL_INSTANCE_SIZE;
360-
}
354+
size +=
355+
AstMemoryEstimationHelper.getEstimatedSizeOfAccountableObject(processingMode.orElse(null));
361356
return size;
362357
}
363358
}

0 commit comments

Comments
 (0)