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

hxd pushed a commit to branch feature_read_data_from_unclosed_tsfile
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to 
refs/heads/feature_read_data_from_unclosed_tsfile by this push:
     new 975909b  check wheter a file is tsfile format
975909b is described below

commit 975909b32ab920827959a6a7cc7fa6eaa8af814b
Author: xiangdong huang <[email protected]>
AuthorDate: Thu Mar 7 17:34:50 2019 +0800

    check wheter a file is tsfile format
---
 .../iotdb/tsfile/write/writer/NativeRestorableIOWriter.java   | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/NativeRestorableIOWriter.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/NativeRestorableIOWriter.java
index 14893b8..a63ca84 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/NativeRestorableIOWriter.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/NativeRestorableIOWriter.java
@@ -48,7 +48,7 @@ public class NativeRestorableIOWriter extends TsFileIOWriter {
   private long truncatedPosition = -1;
   private Map<String, MeasurementSchema> knownSchemas = new HashMap<>();
 
-  public long getTruncatedPosition() {
+  long getTruncatedPosition() {
     return truncatedPosition;
   }
 
@@ -93,7 +93,12 @@ public class NativeRestorableIOWriter extends TsFileIOWriter 
{
       truncatedPosition = magicStringBytes.length;
       return;
     }
-    if (reader.readTailMagic().equals(reader.readHeadMagic(true))) {
+    String magic = reader.readHeadMagic(true);
+    if (!magic.equals(new String(magicStringBytes))) {
+      throw new IOException(String
+          .format("%s is not using TsFile format, and will be ignored...", 
file.getAbsolutePath()));
+    }
+    if (reader.readTailMagic().equals(magic)) {
       LOGGER.debug("{} is an complete TsFile.", file.getAbsolutePath());
       canWrite = false;
       reader.close();
@@ -172,7 +177,7 @@ public class NativeRestorableIOWriter extends 
TsFileIOWriter {
             break;
 
           default:
-            // it is impossible taht we read an incorrect data.
+            // it is impossible that we read an incorrect data.
             MetaMarker.handleUnexpectedMarker(marker);
             goon = false;
         }

Reply via email to