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

[iotdb] branch rel/0.12 updated: [To rel/0.12] Using cached pool to reduce the String memory size in TsFileResourse (#3550)

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

qiaojialin pushed a commit to branch rel/0.12
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rel/0.12 by this push:
     new 8d48298  [To rel/0.12] Using cached pool to reduce the String memory size in TsFileResourse (#3550)
8d48298 is described below

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

    [To rel/0.12] Using cached pool to reduce the String memory size in TsFileResourse (#3550)
---
 .../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 86d7dc6..1d103a7 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 7c3f6ec..0b06750 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