This is an automated email from the ASF dual-hosted git repository.
justinchen pushed a commit to branch rm-ul-c
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rm-ul-c by this push:
new ba9860aa331 fix
ba9860aa331 is described below
commit ba9860aa331d6955291b37c634b77049aaa27c65
Author: Caideyipi <[email protected]>
AuthorDate: Fri Nov 28 16:58:30 2025 +0800
fix
---
.../plan/analyze/cache/schema/DeviceLastCache.java | 47 +++++++++++++---------
.../analyze/cache/schema/DeviceNormalSchema.java | 4 +-
2 files changed, 31 insertions(+), 20 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DeviceLastCache.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DeviceLastCache.java
index 36fc39c3286..ede16ea5bbd 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DeviceLastCache.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DeviceLastCache.java
@@ -98,13 +98,11 @@ public class DeviceLastCache {
measurement,
(measurementKey, tvPair) -> {
if (Objects.isNull(newPair)) {
- diff.addAndGet(
- -((int) RamUsageEstimator.sizeOf(measurement) +
getTVPairEntrySize(tvPair)));
+ diff.addAndGet(-(sizeOf(measurement) +
getTVPairEntrySize(tvPair)));
return null;
}
if (Objects.isNull(tvPair)) {
- diff.addAndGet(
- (int) RamUsageEstimator.sizeOf(measurement) +
getTVPairEntrySize(newPair));
+ diff.addAndGet(sizeOf(measurement) +
getTVPairEntrySize(newPair));
return newPair;
}
return tvPair;
@@ -113,6 +111,10 @@ public class DeviceLastCache {
return diff.get();
}
+ private int sizeOf(String s) {
+ return s == "" ? 0 : (int) RamUsageEstimator.sizeOf(s);
+ }
+
int tryUpdate(
final @Nonnull String[] measurements, final @Nonnull TimeValuePair[]
timeValuePairs) {
return tryUpdate(measurements, timeValuePairs, false);
@@ -128,7 +130,9 @@ public class DeviceLastCache {
for (int i = 0; i < measurements.length; ++i) {
if (Objects.isNull(timeValuePairs[i])) {
if (invalidateNull) {
- measurement2CachedLastMap.remove(measurements[i]);
+ diff.addAndGet(
+ sizeOf(measurements[i])
+ +
getTVPairEntrySize(measurement2CachedLastMap.remove(measurements[i])));
}
continue;
}
@@ -164,7 +168,7 @@ public class DeviceLastCache {
measurement2CachedLastMap.computeIfPresent(
measurement,
(s, timeValuePair) -> {
- diff.set((int) RamUsageEstimator.sizeOf(s) +
getTVPairEntrySize(timeValuePair));
+ diff.set(sizeOf(s) + getTVPairEntrySize(timeValuePair));
time.set(timeValuePair.getTimestamp());
return null;
});
@@ -175,7 +179,7 @@ public class DeviceLastCache {
"",
(s, timeValuePair) -> {
if (timeValuePair.getTimestamp() <= time.get()) {
- diff.addAndGet(getTVPairEntrySize(timeValuePair));
+ diff.addAndGet(sizeOf(s) + getTVPairEntrySize(timeValuePair));
return null;
}
return timeValuePair;
@@ -184,13 +188,18 @@ public class DeviceLastCache {
return diff.get();
}
- private int getTVPairEntrySize(final TimeValuePair tvPair) {
- return (int) RamUsageEstimator.HASHTABLE_RAM_BYTES_PER_ENTRY
- + ((Objects.isNull(tvPair)
- || tvPair == PLACEHOLDER_TIME_VALUE_PAIR
- || tvPair == EMPTY_TIME_VALUE_PAIR)
- ? 0
- : tvPair.getSize());
+ private static int getTVPairEntrySize(final TimeValuePair tvPair) {
+ return (int) RamUsageEstimator.HASHTABLE_RAM_BYTES_PER_ENTRY +
getTVPairSize(tvPair);
+ }
+
+ private static int getTVPairSize(final TimeValuePair tvPair) {
+ return isEmptyTVPair(tvPair) ? 0 : tvPair.getSize();
+ }
+
+ private static boolean isEmptyTVPair(final TimeValuePair tvPair) {
+ return Objects.isNull(tvPair)
+ || tvPair == PLACEHOLDER_TIME_VALUE_PAIR
+ || tvPair == EMPTY_TIME_VALUE_PAIR;
}
@Nullable
@@ -203,15 +212,17 @@ public class DeviceLastCache {
return INSTANCE_SIZE
+ (int) RamUsageEstimator.HASHTABLE_RAM_BYTES_PER_ENTRY *
measurement2CachedLastMap.size()
+ measurement2CachedLastMap.values().stream()
- .mapToInt(TimeValuePair::getSize)
+ .mapToInt(DeviceLastCache::getTVPairSize)
.reduce(0, Integer::sum);
}
private static int getDiffSize(
final TimeValuePair oldTimeValuePair, final TimeValuePair
newTimeValuePair) {
- if (oldTimeValuePair == EMPTY_TIME_VALUE_PAIR
- || oldTimeValuePair == PLACEHOLDER_TIME_VALUE_PAIR) {
- return newTimeValuePair.getSize();
+ if (isEmptyTVPair(oldTimeValuePair)) {
+ return getTVPairSize(newTimeValuePair);
+ }
+ if (isEmptyTVPair(newTimeValuePair)) {
+ return -getTVPairSize(oldTimeValuePair);
}
final TsPrimitiveType oldValue = oldTimeValuePair.getValue();
final TsPrimitiveType newValue = newTimeValuePair.getValue();
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DeviceNormalSchema.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DeviceNormalSchema.java
index 5ce2ca06fcd..6d50905bbca 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DeviceNormalSchema.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DeviceNormalSchema.java
@@ -99,13 +99,13 @@ public class DeviceNormalSchema implements IDeviceSchema {
public int estimateSize() {
// Do not need to calculate database because it is interned
return INSTANCE_SIZE
+ + measurementMap.size() * (int)
RamUsageEstimator.HASHTABLE_RAM_BYTES_PER_ENTRY
+ measurementMap.entrySet().stream()
.mapToInt(
entry ->
Math.toIntExact(
RamUsageEstimator.sizeOf(entry.getKey())
- + SchemaCacheEntry.estimateSize(entry.getValue())
- + RamUsageEstimator.HASHTABLE_RAM_BYTES_PER_ENTRY))
+ + SchemaCacheEntry.estimateSize(entry.getValue())))
.reduce(0, Integer::sum);
}
}