You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2019/09/29 11:30:23 UTC

[incubator-iotdb] branch dev_preallocate_data_file updated: change file open mode

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

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


The following commit(s) were added to refs/heads/dev_preallocate_data_file by this push:
     new ecdab5d  change file open mode
ecdab5d is described below

commit ecdab5dcb2b1772c8722a7152386417da6b879be
Author: jt <jt...@163.com>
AuthorDate: Sun Sep 29 19:18:25 2019 +0800

    change file open mode
---
 .../org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java | 9 ++++-----
 .../iotdb/tsfile/write/writer/RestorableTsFileIOWriter.java      | 8 ++++++--
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java
index 2e25521..853b59b 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java
@@ -126,15 +126,14 @@ public class TsFileProcessor {
     this.schema = schema;
     this.tsFileResource = new TsFileResource(tsfile, this);
     this.versionController = versionController;
-    this.writer = new RestorableTsFileIOWriter(tsfile);
+    if (IoTDBDescriptor.getInstance().getConfig().isPreAllocateDataFile()) {
+      preAllocateTsFile(tsfile);
+    }
+    this.writer = new RestorableTsFileIOWriter(tsfile, false);
     this.closeTsFileCallback = closeTsFileCallback;
     this.updateLatestFlushTimeCallback = updateLatestFlushTimeCallback;
     this.sequence = sequence;
     logger.info("create a new tsfile processor {}", tsfile.getAbsolutePath());
-
-    if (IoTDBDescriptor.getInstance().getConfig().isPreAllocateDataFile()) {
-      preAllocateTsFile(tsfile);
-    }
   }
 
   private void preAllocateTsFile(File tsFile) throws IOException {
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/RestorableTsFileIOWriter.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/RestorableTsFileIOWriter.java
index b988f12..1f48511 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/RestorableTsFileIOWriter.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/RestorableTsFileIOWriter.java
@@ -66,13 +66,17 @@ public class RestorableTsFileIOWriter extends TsFileIOWriter {
     return truncatedPosition;
   }
 
+  public RestorableTsFileIOWriter(File file) throws IOException {
+    this(file, true);
+  }
+
   /**
    * @param file a given tsfile path you want to (continue to) write
    * @throws IOException if write failed, or the file is broken but autoRepair==false.
    */
-  public RestorableTsFileIOWriter(File file) throws IOException {
+  public RestorableTsFileIOWriter(File file, boolean append) throws IOException {
     this.file = file;
-    this.out = FileOutputFactory.INSTANCE.getTsFileOutput(file.getPath(), true);
+    this.out = FileOutputFactory.INSTANCE.getTsFileOutput(file.getPath(), append);
 
     // file doesn't exist
     if (file.length() == 0) {