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/07/08 14:48:19 UTC

[GitHub] [incubator-iotdb] jixuan1989 commented on issue #188: [IOTDB-109]Fix native restore tsfile writer if file is complete and append=true

jixuan1989 commented on issue #188: [IOTDB-109]Fix native restore tsfile writer if file is complete and append=true
URL: https://github.com/apache/incubator-iotdb/pull/188#issuecomment-509256894
 
 
   Well, as the class is renamed as RestorableTsFileIOWriter and does not support append at the end of a complete TsFile anymore, I think we can provide a new function to support appending data at the end of a tsfile:
   
   ```java
     RestorableTsFileIOWriter createRestorableTsFileIOWriter(File file) throws IOException {
       long position = file.length();
   
       try (TsFileSequenceReader reader = new TsFileSequenceReader(file.getAbsolutePath(), false)) {
         // this tsfile is complete
         if (reader.isComplete()) {
           TsFileMetaData metaData = reader.readFileMetadata();
           for (TsDeviceMetadataIndex deviceMetadata : metaData.getDeviceMap().values()) {
             if (position > deviceMetadata.getOffset()){
               position = deviceMetadata.getOffset();
             }
           }
         }
       }
   
       if (position != file.length()) {
         // if the file is complete, we will remove all file metadatas
         try (FileChannel channel = FileChannel.open(Paths.get(file.getAbsolutePath()), StandardOpenOption.WRITE)){
           channel.truncate(position - 1);//remove the last marker.
         }
       }
       return new RestorableTsFileIOWriter(file);
     }
   ```

----------------------------------------------------------------
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