You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2021/07/13 07:40:16 UTC

[iotdb] 01/01: Using cached pool to reduce the String memory size in TsFileResourse

This is an automated email from the ASF dual-hosted git repository.

haonan pushed a commit to branch stirngmem
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 036d273067c720638eaa350b384cbc49f6579e3f
Author: Haonan <hh...@outlook.com>
AuthorDate: Tue Jul 13 14:10:59 2021 +0800

    Using cached pool to reduce the String memory size in TsFileResourse
---
 .../iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java     | 6 +++++-
 .../iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java       | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java
index c0556a9..36d42e9 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java
@@ -88,13 +88,17 @@ public class DeviceTimeIndex implements ITimeIndex {
       ReadWriteIOUtils.write(endTimes[i], outputStream);
     }
 
+    Map<String, Integer> stringMemoryReducedMap = new ConcurrentHashMap<>();
     for (Entry<String, Integer> stringIntegerEntry : deviceToIndex.entrySet()) {
       String deviceName = stringIntegerEntry.getKey();
-      deviceName = cachedDevicePool.computeIfAbsent(deviceName, k -> k);
       int index = stringIntegerEntry.getValue();
+      // To reduce the String number in memory,
+      // use the deviceId from cached pool
+      stringMemoryReducedMap.put(cachedDevicePool.computeIfAbsent(deviceName, k -> k), index);
       ReadWriteIOUtils.write(deviceName, outputStream);
       ReadWriteIOUtils.write(index, outputStream);
     }
+    deviceToIndex = stringMemoryReducedMap;
   }
 
   @Override
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java
index d8baafe..1cd35d6 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java
@@ -66,12 +66,16 @@ public class FileTimeIndex implements ITimeIndex {
   @Override
   public void serialize(OutputStream outputStream) throws IOException {
     ReadWriteIOUtils.write(devices.size(), outputStream);
+    Set<String> stringMemoryReducedSet = new ConcurrentSet<>();
     for (String device : devices) {
-      device = cachedDevicePool.computeIfAbsent(device, k -> k);
+      // To reduce the String number in memory,
+      // use the deviceId from cached pool
+      stringMemoryReducedSet.add(cachedDevicePool.computeIfAbsent(device, k -> k));
       ReadWriteIOUtils.write(device, outputStream);
     }
     ReadWriteIOUtils.write(startTime, outputStream);
     ReadWriteIOUtils.write(endTime, outputStream);
+    devices = stringMemoryReducedSet;
   }
 
   @Override