Class TsFileIOWriter

    • Field Detail

      • MAGIC_STRING_BYTES

        protected static final byte[] MAGIC_STRING_BYTES
      • VERSION_NUMBER_BYTE

        public static final byte VERSION_NUMBER_BYTE
      • canWrite

        protected boolean canWrite
      • file

        protected File file
      • currentChunkMetadata

        protected ChunkMetadata currentChunkMetadata
      • maxMetadataSize

        protected long maxMetadataSize
      • currentChunkMetadataSize

        protected long currentChunkMetadataSize
      • chunkMetadataTempFile

        protected File chunkMetadataTempFile
      • hasChunkMetadataInDisk

        protected volatile boolean hasChunkMetadataInDisk
      • pathCount

        protected int pathCount
      • enableMemoryControl

        protected boolean enableMemoryControl
      • endPosInCMTForDevice

        protected LinkedList<Long> endPosInCMTForDevice
    • Constructor Detail

      • TsFileIOWriter

        protected TsFileIOWriter()
        empty construct function.
      • TsFileIOWriter

        public TsFileIOWriter​(File file)
                       throws IOException
        for writing a new tsfile.
        Parameters:
        file - be used to output written data
        Throws:
        IOException - if I/O error occurs
      • TsFileIOWriter

        public TsFileIOWriter​(TsFileOutput output)
                       throws IOException
        for writing a new tsfile.
        Parameters:
        output - be used to output written data
        Throws:
        IOException
      • TsFileIOWriter

        public TsFileIOWriter​(TsFileOutput output,
                              boolean test)
        for test only
      • TsFileIOWriter

        public TsFileIOWriter​(File file,
                              boolean enableMemoryControl,
                              long maxMetadataSize)
                       throws IOException
        for write with memory control
        Throws:
        IOException
    • Method Detail

      • writeBytesToStream

        public void writeBytesToStream​(PublicBAOS bytes)
                                throws IOException
        Writes given bytes to output stream. This method is called when total memory size exceeds the chunk group size threshold.
        Parameters:
        bytes - - data of several pages which has been packed
        Throws:
        IOException - if an I/O error occurs.
      • endChunkGroup

        public void endChunkGroup()
                           throws IOException
        end chunk and write some log. If there is no data in the chunk group, nothing will be flushed.
        Throws:
        IOException
      • isWritingChunkGroup

        public boolean isWritingChunkGroup()
        For TsFileReWriteTool / UpgradeTool. Use this method to determine if needs to start a ChunkGroup.
        Returns:
        isWritingChunkGroup
      • startFlushChunk

        public void startFlushChunk​(String measurementId,
                                    CompressionType compressionCodecName,
                                    TSDataType tsDataType,
                                    TSEncoding encodingType,
                                    Statistics<? extends Serializable> statistics,
                                    int dataSize,
                                    int numOfPages,
                                    int mask)
                             throws IOException
        start a ChunkMetaData.
        Parameters:
        measurementId - - measurementId of this time series
        compressionCodecName - - compression name of this time series
        tsDataType - - data type
        statistics - - Chunk statistics
        dataSize - - the serialized size of all pages
        mask - - 0x80 for time chunk, 0x40 for value chunk, 0x00 for common chunk
        Throws:
        IOException - if I/O error occurs
      • writeChunk

        public void writeChunk​(Chunk chunk,
                               ChunkMetadata chunkMetadata)
                        throws IOException
        Write a whole chunk in another file into this file. Providing fast merge for IoTDB.
        Throws:
        IOException
      • endCurrentChunk

        public void endCurrentChunk()
        end chunk and write some log.
      • getPos

        public long getPos()
                    throws IOException
        get the length of normal OutputStream.
        Returns:
        - length of normal OutputStream
        Throws:
        IOException - if I/O error occurs
      • canWrite

        public boolean canWrite()
      • close

        public void close()
                   throws IOException
        close the outputStream or file channel without writing FileMetadata. This is just used for Testing.
        Specified by:
        close in interface AutoCloseable
        Throws:
        IOException
      • getFile

        public File getFile()
      • setFile

        public void setFile​(File file)
      • filterChunks

        public void filterChunks​(Map<Path,​List<Long>> chunkStartTimes)
        Remove such ChunkMetadata that its startTime is not in chunkStartTimes
      • getIOWriterOut

        public TsFileOutput getIOWriterOut()
        this function is only for Test.
        Returns:
        TsFileOutput
      • getChunkMetadataListOfCurrentDeviceInMemory

        public List<ChunkMetadata> getChunkMetadataListOfCurrentDeviceInMemory()
        This method should be called before flushing chunk group metadata list, otherwise, it will return null.
      • getDeviceTimeseriesMetadataMap

        public Map<String,​List<TimeseriesMetadata>> getDeviceTimeseriesMetadataMap()
        this function is for Upgrade Tool and Split Tool.
        Returns:
        DeviceTimeseriesMetadataMap
      • getMinPlanIndex

        public long getMinPlanIndex()
      • setMinPlanIndex

        public void setMinPlanIndex​(long minPlanIndex)
      • getMaxPlanIndex

        public long getMaxPlanIndex()
      • setMaxPlanIndex

        public void setMaxPlanIndex​(long maxPlanIndex)
      • checkMetadataSizeAndMayFlush

        public int checkMetadataSizeAndMayFlush()
                                         throws IOException
        Check if the size of chunk metadata in memory is greater than the given threshold. If so, the chunk metadata will be written to a temp files. Notice! If you are writing a aligned device in row, you should make sure all data of current writing device has been written before this method is called. For writing not aligned series or writing aligned series in column, you should make sure that all data of one series is written before you call this function.
        Throws:
        IOException
      • sortAndFlushChunkMetadata

        protected int sortAndFlushChunkMetadata()
                                         throws IOException
        Sort the chunk metadata by the lexicographical order and the start time of the chunk, then flush them to a temp file.
        Throws:
        IOException
      • getCurrentChunkGroupDeviceId

        public String getCurrentChunkGroupDeviceId()