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

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

commit 37f7ba0233f9f62ac36bc277abb597f7ab796790
Author: Alima777 <[email protected]>
AuthorDate: Fri May 27 12:26:29 2022 +0800

    use move method in iotdb
---
 .../java/org/apache/iotdb/RewriteBadFileTool.java  | 27 ++++++++++------------
 .../org/apache/iotdb/TsFileValidationTool.java     |  8 +++++--
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git 
a/rewriteBadFile/src/main/java/org/apache/iotdb/RewriteBadFileTool.java 
b/rewriteBadFile/src/main/java/org/apache/iotdb/RewriteBadFileTool.java
index 13d157e967..24cf25d94a 100644
--- a/rewriteBadFile/src/main/java/org/apache/iotdb/RewriteBadFileTool.java
+++ b/rewriteBadFile/src/main/java/org/apache/iotdb/RewriteBadFileTool.java
@@ -22,7 +22,6 @@ package org.apache.iotdb;
 import org.apache.iotdb.db.engine.modification.Deletion;
 import org.apache.iotdb.db.engine.modification.Modification;
 import org.apache.iotdb.db.engine.modification.ModificationFile;
-import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
 import org.apache.iotdb.db.exception.metadata.IllegalPathException;
 import org.apache.iotdb.db.metadata.PartialPath;
 import org.apache.iotdb.rpc.IoTDBConnectionException;
@@ -86,14 +85,19 @@ public class RewriteBadFileTool {
     pw = new PrintWriter(new FileWriter(outputLogFilePath));
     try {
       moveAndRewriteBadFile();
-    } catch (IoTDBConnectionException | IOException e) {
+    } catch (IoTDBConnectionException
+        | IOException
+        | StatementExecutionException
+        | InterruptedException e) {
       e.printStackTrace();
     } finally {
       pw.close();
     }
   }
 
-  public static void moveAndRewriteBadFile() throws IOException, 
IoTDBConnectionException {
+  public static void moveAndRewriteBadFile()
+      throws IOException, IoTDBConnectionException, 
StatementExecutionException,
+          InterruptedException {
     Session session = new Session(HostIP, rpcPort, user, password);
     session.open(false);
 
@@ -104,25 +108,18 @@ public class RewriteBadFileTool {
         continue;
       }
       String badFilePath = line.replace("-- Find the bad file ", "");
+
       printBoth(String.format("Start moving %s to backup dir.", badFilePath));
-      String targetFilePath =
-          backUpDirPath + File.separator + "sequence" + 
badFilePath.split("sequence")[1];
+      session.executeNonQueryStatement(String.format("move '%s' '%s'", 
badFilePath, backUpDirPath));
+      String[] dirs = badFilePath.split("/");
+      String targetFilePath = backUpDirPath + dirs[dirs.length - 1];
       File targetFile = new File(targetFilePath);
-      if (!targetFile.getParentFile().exists()) {
-        targetFile.getParentFile().mkdir();
-      }
-      // move tsfile
-      fsFactory.moveFile(new File(badFilePath), targetFile);
-      // move resource file
-      fsFactory.moveFile(
-          new File(badFilePath + TsFileResource.RESOURCE_SUFFIX),
-          new File(targetFilePath + TsFileResource.RESOURCE_SUFFIX));
       // move mods file
       File modsFile = new File(badFilePath + ModificationFile.FILE_SUFFIX);
       if (modsFile.exists()) {
         fsFactory.moveFile(modsFile, new File(targetFilePath + 
ModificationFile.FILE_SUFFIX));
       }
-      printBoth("Finish moving.");
+      printBoth(String.format("Finish unloading %s.", badFilePath));
       // rewriteFile
       try {
         printBoth(String.format("Start rewriting %s to iotdb.", badFilePath));
diff --git 
a/rewriteBadFile/src/main/java/org/apache/iotdb/TsFileValidationTool.java 
b/rewriteBadFile/src/main/java/org/apache/iotdb/TsFileValidationTool.java
index 58c02f359c..1483edaf4b 100644
--- a/rewriteBadFile/src/main/java/org/apache/iotdb/TsFileValidationTool.java
+++ b/rewriteBadFile/src/main/java/org/apache/iotdb/TsFileValidationTool.java
@@ -121,8 +121,12 @@ public class TsFileValidationTool {
             continue;
           }
           // get time partition dirs and sort them
-          List<File> timePartitionDirs =
-              Arrays.asList(Objects.requireNonNull(dataRegionDir.listFiles()));
+          List<File> timePartitionDirs = new ArrayList<>();
+          for (File file : Objects.requireNonNull(dataRegionDir.listFiles())) {
+            if (file != null && !file.getName().endsWith(".DS_Store")) {
+              timePartitionDirs.add(file);
+            }
+          }
           timePartitionDirs.sort(
               (f1, f2) ->
                   Long.compareUnsigned(Long.parseLong(f1.getName()), 
Long.parseLong(f2.getName())));

Reply via email to