jt2594838 commented on code in PR #16739:
URL: https://github.com/apache/iotdb/pull/16739#discussion_r2517347260
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/memory/PipeMemoryWeightUtil.java:
##########
@@ -203,66 +210,99 @@ private static Pair<Integer, Integer>
calculateTabletRowCountAndMemoryBySize(
}
}
- public static long calculateTabletSizeInBytes(Tablet tablet) {
+ public static long calculateTabletSizeInBytes(final Tablet tablet) {
long totalSizeInBytes = 0;
if (tablet == null) {
return totalSizeInBytes;
}
+ totalSizeInBytes +=
+ TABLET_SIZE
+ + RamUsageEstimator.sizeOf(tablet.getDeviceId())
+ + RamUsageEstimator.sizeOf(tablet.getTimestamps())
+ + getListSize(tablet.getColumnTypes());
- long[] timestamps = tablet.getTimestamps();
- Object[] tabletValues = tablet.getValues();
-
- // timestamps
- if (timestamps != null) {
- totalSizeInBytes += timestamps.length * 8L;
- }
+ final Object[] tabletValues = tablet.getValues();
// values
- final List<IMeasurementSchema> timeseries = tablet.getSchemas();
- if (timeseries != null) {
- for (int column = 0; column < timeseries.size(); column++) {
- final IMeasurementSchema measurementSchema = timeseries.get(column);
+ final List<IMeasurementSchema> timeSeries = tablet.getSchemas();
+
+ if (timeSeries != null) {
+ totalSizeInBytes += getListSize(timeSeries);
+ for (int column = 0; column < timeSeries.size(); column++) {
+ final IMeasurementSchema measurementSchema = timeSeries.get(column);
if (measurementSchema == null) {
continue;
}
+ // Measurement schema size, refer to SchemaCacheEntry
+ totalSizeInBytes += 75;
Review Comment:
Better to add a constant reference.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/memory/PipeMemoryWeightUtil.java:
##########
@@ -203,66 +210,99 @@ private static Pair<Integer, Integer>
calculateTabletRowCountAndMemoryBySize(
}
}
- public static long calculateTabletSizeInBytes(Tablet tablet) {
+ public static long calculateTabletSizeInBytes(final Tablet tablet) {
long totalSizeInBytes = 0;
if (tablet == null) {
return totalSizeInBytes;
}
+ totalSizeInBytes +=
+ TABLET_SIZE
+ + RamUsageEstimator.sizeOf(tablet.getDeviceId())
+ + RamUsageEstimator.sizeOf(tablet.getTimestamps())
+ + getListSize(tablet.getColumnTypes());
- long[] timestamps = tablet.getTimestamps();
- Object[] tabletValues = tablet.getValues();
-
- // timestamps
- if (timestamps != null) {
- totalSizeInBytes += timestamps.length * 8L;
- }
+ final Object[] tabletValues = tablet.getValues();
// values
- final List<IMeasurementSchema> timeseries = tablet.getSchemas();
- if (timeseries != null) {
- for (int column = 0; column < timeseries.size(); column++) {
- final IMeasurementSchema measurementSchema = timeseries.get(column);
+ final List<IMeasurementSchema> timeSeries = tablet.getSchemas();
+
+ if (timeSeries != null) {
+ totalSizeInBytes += getListSize(timeSeries);
+ for (int column = 0; column < timeSeries.size(); column++) {
+ final IMeasurementSchema measurementSchema = timeSeries.get(column);
if (measurementSchema == null) {
continue;
}
+ // Measurement schema size, refer to SchemaCacheEntry
+ totalSizeInBytes += 75;
final TSDataType tsDataType = measurementSchema.getType();
if (tsDataType == null) {
continue;
}
- if (tsDataType.isBinary()) {
- if (tabletValues == null || tabletValues.length <= column) {
- continue;
- }
- final Binary[] values = ((Binary[]) tabletValues[column]);
- if (values == null) {
- continue;
- }
- for (Binary value : values) {
- totalSizeInBytes += value == null ? 8 : value.ramBytesUsed();
- }
- } else {
- totalSizeInBytes += (long) tablet.getMaxRowNumber() *
tsDataType.getDataTypeSize();
+ if (tabletValues == null || tabletValues.length <= column) {
+ continue;
+ }
+ switch (tsDataType) {
+ case INT64:
+ case TIMESTAMP:
+ totalSizeInBytes += RamUsageEstimator.sizeOf((long[])
tabletValues[column]);
+ break;
+ case DATE:
+ totalSizeInBytes += getLocalDateSize((LocalDate[])
tabletValues[column]);
+ break;
+ case INT32:
+ totalSizeInBytes += RamUsageEstimator.sizeOf((int[])
tabletValues[column]);
+ break;
+ case DOUBLE:
+ totalSizeInBytes += RamUsageEstimator.sizeOf((double[])
tabletValues[column]);
+ break;
+ case FLOAT:
+ totalSizeInBytes += RamUsageEstimator.sizeOf((float[])
tabletValues[column]);
+ break;
+ case BOOLEAN:
+ totalSizeInBytes += RamUsageEstimator.sizeOf((boolean[])
tabletValues[column]);
+ break;
+ case STRING:
+ case TEXT:
+ case BLOB:
+ totalSizeInBytes += getBinarySize((Binary[]) tabletValues[column]);
+ break;
}
}
}
// bitMaps
- BitMap[] bitMaps = tablet.getBitMaps();
- if (bitMaps != null) {
- for (int i = 0; i < bitMaps.length; i++) {
- totalSizeInBytes += bitMaps[i] == null ? 0 : bitMaps[i].getSize();
- }
- }
+ totalSizeInBytes +=
InsertNodeMemoryEstimator.sizeOfBitMapArray(tablet.getBitMaps());
- // estimate other dataStructures size
- totalSizeInBytes += 100;
+ // estimate tag & columnIndexes size
+ totalSizeInBytes += 300;
Review Comment:
Explain this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]