Class RestorableTsFileIOWriter

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class RestorableTsFileIOWriter
    extends TsFileIOWriter
    This writer is for opening and recover a TsFile

    (1) If the TsFile is closed normally, hasCrashed()=false and canWrite()=false

    (2) Otherwise, the writer generates metadata for already flushed Chunks and truncate crashed data. The hasCrashed()=true and canWrite()=true

    Notice!!! If you want to query this file through the generated metadata, remember to call the makeMetadataVisible()

    • Constructor Detail

      • RestorableTsFileIOWriter

        public RestorableTsFileIOWriter​(java.io.File file)
                                 throws java.io.IOException
        Parameters:
        file - a given tsfile path you want to (continue to) write
        Throws:
        java.io.IOException - if write failed, or the file is broken but autoRepair==false.
      • RestorableTsFileIOWriter

        public RestorableTsFileIOWriter​(java.io.File file,
                                        long maxMetadataSize)
                                 throws java.io.IOException
        Parameters:
        file - a given tsfile path you want to (continue to) write
        Throws:
        java.io.IOException - if write failed, or the file is broken but autoRepair==false.
      • RestorableTsFileIOWriter

        public RestorableTsFileIOWriter​(java.io.File file,
                                        boolean truncate)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getWriterForAppendingDataOnCompletedTsFile

        public static RestorableTsFileIOWriter getWriterForAppendingDataOnCompletedTsFile​(java.io.File file)
                                                                                   throws java.io.IOException
        Given a TsFile, generate a writable RestorableTsFileIOWriter. That is, for a complete TsFile, the function erases all FileMetadata and supports writing new data; For a incomplete TsFile, the function supports writing new data directly. However, it is more efficient using the construction function of RestorableTsFileIOWriter, if the tsfile is incomplete.
        Parameters:
        file - a TsFile
        Returns:
        a writable RestorableTsFileIOWriter
        Throws:
        java.io.IOException
      • getVisibleMetadataList

        public java.util.List<ChunkMetadata> getVisibleMetadataList​(java.lang.String deviceId,
                                                                    java.lang.String measurementId,
                                                                    TSDataType dataType)
        For query.

        get chunks' metadata from memory.

        Parameters:
        deviceId - the device id
        measurementId - the measurement id
        dataType - the value type
        Returns:
        chunks' metadata
      • getMetadatasForQuery

        public java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.util.List<ChunkMetadata>>> getMetadatasForQuery()
      • makeMetadataVisible

        public void makeMetadataVisible()
        add all appendChunkMetadatas into memory. After calling this method, other classes can read these metadata.
      • hasCrashed

        public boolean hasCrashed()
        Whether this TsFile is crashed.
        Returns:
        false when this TsFile is complete