You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2019/03/14 15:29:23 UTC

[GitHub] [incubator-iotdb] MyXOF commented on a change in pull request #98: [IOTDB-39] Added autoRepair functionality to TsFileSequenceReader.

MyXOF commented on a change in pull request #98: [IOTDB-39] Added autoRepair functionality to TsFileSequenceReader.
URL: https://github.com/apache/incubator-iotdb/pull/98#discussion_r265627329
 
 

 ##########
 File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
 ##########
 @@ -64,13 +72,45 @@ public TsFileSequenceReader(String file) throws IOException {
    * @param loadMetadataSize -load meta data size
    */
   public TsFileSequenceReader(String file, boolean loadMetadataSize) throws IOException {
+    this(file, loadMetadataSize, false);
+  }
+
+  /**
+   * construct function for TsFileSequenceReader.
+   *
+   * @param file -given file name
+   * @param loadMetadataSize -load meta data size
+   * @param autoRepair if true it tries to automatically repair a damaged file (by changing it!)
+   *                   before reading
+   */
+  public TsFileSequenceReader(String file, boolean loadMetadataSize, boolean autoRepair) throws IOException {
     this.file = file;
-    tsFileInput = new DefaultTsFileInput(Paths.get(file));
+    final Path path = Paths.get(file);
+    tsFileInput = new DefaultTsFileInput(path);
+    if (autoRepair) {
+      checkAndRepair(file, path);
+    }
     if (loadMetadataSize) {
       loadMetadataSize();
     }
   }
 
+  /**
+   * Checks if the file is incomplete, and if so, tries to repair it.
+   */
+  private void checkAndRepair(String file, Path path) throws IOException {
+    // Check if file is damaged
+    if (!TSFileConfig.MAGIC_STRING.equals(readTailMagic())) {
+      // Try to close it
+      LOGGER.info(String.format("File %s has no correct tail magic, try to repair...",
 
 Review comment:
   you can use `LOGGER.info("File {} has no correct tail magic, try to repair...", path.toAbsolutePath()),` directly

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services