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 2023/08/14 07:19:29 UTC

[iotdb] 01/01: Fix a concurrent bug when recover last flush time and compact (#10839)

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

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

commit 4c069f42cb7cda254ade3b3fb93ffa2b96d8ed0f
Author: Haonan <hh...@outlook.com>
AuthorDate: Mon Aug 14 14:50:59 2023 +0800

    Fix a concurrent bug when recover last flush time and compact (#10839)
---
 .../storageengine/dataregion/HashLastFlushTimeMap.java  | 15 +--------------
 .../storageengine/dataregion/tsfile/TsFileManager.java  | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/HashLastFlushTimeMap.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/HashLastFlushTimeMap.java
index c1dca62f747..d8b2631d38d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/HashLastFlushTimeMap.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/HashLastFlushTimeMap.java
@@ -20,15 +20,12 @@
 package org.apache.iotdb.db.storageengine.dataregion;
 
 import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileManager;
-import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 public class HashLastFlushTimeMap implements ILastFlushTimeMap {
 
@@ -228,19 +225,9 @@ public class HashLastFlushTimeMap implements ILastFlushTimeMap {
   }
 
   private long recoverFlushTime(long partitionId, String devicePath) {
-    List<TsFileResource> tsFileResourceList =
-        tsFileManager.getOrCreateSequenceListByTimePartition(partitionId);
-
-    for (int i = tsFileResourceList.size() - 1; i >= 0; i--) {
-      Set<String> deviceSet = tsFileResourceList.get(i).getDevices();
-      if (deviceSet.contains(devicePath)) {
-        return tsFileResourceList.get(i).getEndTime(devicePath);
-      }
-    }
-
     long memCost = HASHMAP_NODE_BASIC_SIZE + 2L * devicePath.length();
     memCostForEachPartition.compute(partitionId, (k, v) -> v == null ? memCost : v + memCost);
-    return Long.MIN_VALUE;
+    return tsFileManager.recoverFlushTimeFromTsFileResource(partitionId, devicePath);
   }
 
   @Override
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileManager.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileManager.java
index 0f4616fc8ae..77ea57a4096 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileManager.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileManager.java
@@ -92,6 +92,23 @@ public class TsFileManager {
     }
   }
 
+  public long recoverFlushTimeFromTsFileResource(long partitionId, String devicePath) {
+    writeLock("recoverFlushTimeFromTsFileResource");
+    try {
+      List<TsFileResource> tsFileResourceList =
+          sequenceFiles.computeIfAbsent(partitionId, l -> new TsFileResourceList());
+      for (int i = tsFileResourceList.size() - 1; i >= 0; i--) {
+        Set<String> deviceSet = tsFileResourceList.get(i).getDevices();
+        if (deviceSet.contains(devicePath)) {
+          return tsFileResourceList.get(i).getEndTime(devicePath);
+        }
+      }
+    } finally {
+      writeUnlock();
+    }
+    return Long.MIN_VALUE;
+  }
+
   public Iterator<TsFileResource> getIterator(boolean sequence) {
     readLock();
     try {