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/05/23 06:42:50 UTC

[iotdb] 01/02: fix DataDirViewer

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

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

commit 5eca8644026172cb01ffd5e64a89a691bbf4060a
Author: HTHou <hh...@outlook.com>
AuthorDate: Tue May 23 09:52:18 2023 +0800

    fix DataDirViewer
---
 .../apache/iotdb/db/tools/IoTDBDataDirViewer.java  | 41 +++++++++++++++-------
 1 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/tools/IoTDBDataDirViewer.java b/server/src/main/java/org/apache/iotdb/db/tools/IoTDBDataDirViewer.java
index b3999965d0a..197fe6f67e1 100644
--- a/server/src/main/java/org/apache/iotdb/db/tools/IoTDBDataDirViewer.java
+++ b/server/src/main/java/org/apache/iotdb/db/tools/IoTDBDataDirViewer.java
@@ -40,7 +40,7 @@ public class IoTDBDataDirViewer {
     String[] data_dir;
     String outFile = "IoTDB_data_dir_overview.txt";
     if (args.length == 0) {
-      String path = "data/data";
+      String path = "data/datanode/data";
       data_dir = path.split(","); // multiple data dirs separated by comma
     } else if (args.length == 1) {
       data_dir = args[0].split(",");
@@ -56,7 +56,7 @@ public class IoTDBDataDirViewer {
       for (String dir : data_dir) {
         File dirFile = FSFactoryProducer.getFSFactory().getFile(dir);
         File[] seqAndUnseqDirs = dirFile.listFiles();
-        if (seqAndUnseqDirs == null || seqAndUnseqDirs.length != 2) {
+        if (seqAndUnseqDirs == null) {
           throw new IOException(
               "Irregular data dir structure.There should be a sequence and unsequence directory "
                   + "under the data directory "
@@ -64,20 +64,20 @@ public class IoTDBDataDirViewer {
         }
         List<File> fileList = Arrays.asList(seqAndUnseqDirs);
         fileList.sort((Comparator.comparing(File::getName)));
-        if (!"sequence".equals(seqAndUnseqDirs[0].getName())
-            || !"unsequence".equals(seqAndUnseqDirs[1].getName())) {
+        if (!"sequence".equals(seqAndUnseqDirs[1].getName())
+            || !"unsequence".equals(seqAndUnseqDirs[2].getName())) {
           throw new IOException(
               "Irregular data dir structure.There should be a sequence and unsequence directory "
                   + "under the data directory "
-                  + dirFile.getName());
+                  + dirFile.getPath());
         }
 
         printlnBoth(pw, "|==============================================================");
         printlnBoth(pw, "|" + dir);
         printlnBoth(pw, "|--sequence");
-        printFilesInSeqOrUnseqDir(seqAndUnseqDirs[0], pw);
-        printlnBoth(pw, "|--unsequence");
         printFilesInSeqOrUnseqDir(seqAndUnseqDirs[1], pw);
+        printlnBoth(pw, "|--unsequence");
+        printFilesInSeqOrUnseqDir(seqAndUnseqDirs[2], pw);
       }
       printlnBoth(pw, "|==============================================================");
     }
@@ -105,14 +105,31 @@ public class IoTDBDataDirViewer {
     File[] files = storageGroup.listFiles();
     if (files == null) {
       throw new IOException(
-          "Irregular data dir structure.There should be timeInterval directories under "
+          "Irregular data dir structure.There should be dataRegion directories under "
               + "the database directory "
               + storageGroup.getName());
     }
     List<File> fileList = Arrays.asList(files);
     fileList.sort((Comparator.comparing(File::getName)));
-    for (File file : files) {
+    for (File file : fileList) {
       printlnBoth(pw, "|  |  |--" + file.getName());
+      printFilesInDataRegionDir(file, pw);
+    }
+  }
+
+  private static void printFilesInDataRegionDir(File dataRegion, PrintWriter pw)
+      throws IOException {
+    File[] files = dataRegion.listFiles();
+    if (files == null) {
+      throw new IOException(
+          "Irregular data dir structure.There should be timeInterval directories under "
+              + "the database directory "
+              + dataRegion.getName());
+    }
+    List<File> fileList = Arrays.asList(files);
+    fileList.sort((Comparator.comparing(File::getName)));
+    for (File file : fileList) {
+      printlnBoth(pw, "|  |  |  |--" + file.getName());
       printFilesInTimeInterval(file, pw);
     }
   }
@@ -128,8 +145,8 @@ public class IoTDBDataDirViewer {
     }
     List<File> fileList = Arrays.asList(files);
     fileList.sort((Comparator.comparing(File::getName)));
-    for (File file : files) {
-      printlnBoth(pw, "|  |  |  |--" + file.getName());
+    for (File file : fileList) {
+      printlnBoth(pw, "|  |  |  |  |--" + file.getName());
 
       // To print the content if it is a tsfile.resource
       if (file.getName().endsWith(".tsfile.resource")) {
@@ -148,7 +165,7 @@ public class IoTDBDataDirViewer {
       printlnBoth(
           pw,
           String.format(
-              "|  |  |  |  |--device %s, start time %d (%s), end time %d (%s)",
+              "|  |  |  |  |  |--device %s, start time %d (%s), end time %d (%s)",
               device,
               resource.getStartTime(device),
               DateTimeUtils.convertLongToDate(resource.getStartTime(device)),