shuwenwei commented on code in PR #13773:
URL: https://github.com/apache/iotdb/pull/13773#discussion_r1802258444


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/batch/utils/BatchCompactionPlan.java:
##########
@@ -21,18 +21,53 @@
 
 import 
org.apache.iotdb.db.storageengine.dataregion.compaction.execute.utils.executor.ModifiedStatus;
 
+import org.apache.tsfile.file.metadata.ChunkMetadata;
+import org.apache.tsfile.read.TsFileSequenceReader;
+import org.apache.tsfile.read.common.Chunk;
 import org.apache.tsfile.read.common.TimeRange;
+import org.apache.tsfile.utils.Pair;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 public class BatchCompactionPlan {
+  public static final long MAX_CACHED_TIME_CHUNKS_SIZE = 2 * 1024 * 1024;
   private final List<CompactChunkPlan> compactChunkPlans = new ArrayList<>();
   private final Map<String, Map<TimeRange, ModifiedStatus>> 
alignedPageModifiedStatusCache =
       new HashMap<>();
+  private final Map<Pair<String, Long>, Chunk> cachedTimeChunks = new 
HashMap<>();
+  private long cachedTimeChunkSize = 0;
+
+  public Chunk getTimeChunkFromCache(TsFileSequenceReader reader, 
ChunkMetadata chunkMetadata)
+      throws IOException {
+    Pair<String, Long> key =
+        new Pair<>(reader.getFileName(), 
chunkMetadata.getOffsetOfChunkHeader());
+    Chunk chunk = cachedTimeChunks.get(key);
+    if (chunk == null) {
+      chunk = reader.readMemChunk(chunkMetadata);
+    }
+    chunk.getData().flip();
+    return chunk;
+  }
+
+  public void addTimeChunkToCache(String file, long offset, Chunk chunk) {
+    if (cachedTimeChunkSize >= MAX_CACHED_TIME_CHUNKS_SIZE) {
+      return;
+    }
+    cachedTimeChunks.put(
+        new Pair<>(file, offset),
+        new Chunk(
+            chunk.getHeader(),
+            chunk.getData(),
+            chunk.getDeleteIntervalList(),
+            chunk.getChunkStatistic(),
+            chunk.getDecryptor()));

Review Comment:
   To prevent potential modifications to the chunk content in the subsequent 
process, although there should be none at present.



-- 
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]

Reply via email to