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

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


The following commit(s) were added to refs/heads/master by this push:
     new 01a0f6325e6 fix lose data when recover data dir onto a new iotdb 
(#11848)
01a0f6325e6 is described below

commit 01a0f6325e627efee5be7d997deb50a962300e45
Author: Zhijia Cao <[email protected]>
AuthorDate: Thu Jan 4 18:46:57 2024 +0800

    fix lose data when recover data dir onto a new iotdb (#11848)
---
 .../dataregion/wal/recover/WALRecoverManager.java          | 11 +++++++----
 .../storageengine/dataregion/wal/utils/WALFileUtils.java   | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/recover/WALRecoverManager.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/recover/WALRecoverManager.java
index 5ed0e19e0aa..c3a09020e27 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/recover/WALRecoverManager.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/recover/WALRecoverManager.java
@@ -48,6 +48,8 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 
+import static 
org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALFileUtils.getTsFileRelativePath;
+
 /** First set allVsgScannedLatch, then call recover method. */
 public class WALRecoverManager {
   private static final Logger logger = 
LoggerFactory.getLogger(WALRecoverManager.class);
@@ -187,8 +189,10 @@ public class WALRecoverManager {
       return null;
     } else {
       try {
-        String canonicalPath = 
recoverPerformer.getTsFileResource().getTsFile().getCanonicalPath();
-        absolutePath2RecoverPerformer.put(canonicalPath, recoverPerformer);
+        String tsFileRelativePath =
+            getTsFileRelativePath(
+                
recoverPerformer.getTsFileResource().getTsFile().getCanonicalPath());
+        absolutePath2RecoverPerformer.put(tsFileRelativePath, 
recoverPerformer);
       } catch (IOException e) {
         logger.error(
             "Fail to add recover performer for file {}",
@@ -201,8 +205,7 @@ public class WALRecoverManager {
 
   UnsealedTsFileRecoverPerformer removeRecoverPerformer(File file) {
     try {
-      String canonicalPath = file.getCanonicalPath();
-      return absolutePath2RecoverPerformer.remove(canonicalPath);
+      return 
absolutePath2RecoverPerformer.remove(getTsFileRelativePath(file.getCanonicalPath()));
     } catch (IOException e) {
       logger.error("Fail to remove recover performer for file {}", file, e);
     }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALFileUtils.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALFileUtils.java
index 027d4b160a6..117f06c7644 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALFileUtils.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALFileUtils.java
@@ -21,6 +21,7 @@ package 
org.apache.iotdb.db.storageengine.dataregion.wal.utils;
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.nio.file.Path;
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.regex.Matcher;
@@ -168,4 +169,17 @@ public class WALFileUtils {
   public static String getLogFileName(long versionId, long startSearchIndex, 
WALFileStatus status) {
     return String.format(WAL_FILE_NAME_FORMAT, versionId, startSearchIndex, 
status.getCode());
   }
+
+  /**
+   * get tsFile relative path from sequence or unsequence dir. <br>
+   * eg: <br>
+   * input: <br>
+   * 
/iotdb/absolute/path/data/datanode/data/sequence/root.db/1/2818/1704354353829-1-0-0.tsfile
+   * output: <br>
+   * sequence/root.db/1/2818/1704354353829-1-0-0.tsfile
+   */
+  public static String getTsFileRelativePath(String absolutePath) {
+    Path path = new File(absolutePath).toPath();
+    return path.subpath(path.getNameCount() - 5, 
path.getNameCount()).toString();
+  }
 }

Reply via email to