Class TsFileResource


  • public class TsFileResource
    extends java.lang.Object
    • Constructor Detail

      • TsFileResource

        public TsFileResource()
      • TsFileResource

        public TsFileResource​(TsFileResource other)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • TsFileResource

        public TsFileResource​(java.io.File file)
        for sealed TsFile, call setClosed to close TsFileResource
      • TsFileResource

        public TsFileResource​(java.io.File file,
                              TsFileProcessor processor)
        unsealed TsFile, for writter
      • TsFileResource

        public TsFileResource​(org.apache.iotdb.commons.path.PartialPath path,
                              java.util.List<ReadOnlyMemChunk> readOnlyMemChunk,
                              java.util.List<org.apache.iotdb.tsfile.file.metadata.IChunkMetadata> chunkMetadataList,
                              TsFileResource originTsFileResource)
                       throws java.io.IOException
        unsealed TsFile, for query
        Throws:
        java.io.IOException
      • TsFileResource

        public TsFileResource​(java.util.Map<org.apache.iotdb.commons.path.PartialPath,​java.util.List<ReadOnlyMemChunk>> pathToReadOnlyMemChunkMap,
                              java.util.Map<org.apache.iotdb.commons.path.PartialPath,​java.util.List<org.apache.iotdb.tsfile.file.metadata.IChunkMetadata>> pathToChunkMetadataListMap,
                              TsFileResource originTsFileResource)
                       throws java.io.IOException
        unsealed TsFile, for query
        Throws:
        java.io.IOException
      • TsFileResource

        public TsFileResource​(java.io.File file,
                              java.util.Map<java.lang.String,​java.lang.Integer> deviceToIndex,
                              long[] startTimes,
                              long[] endTimes)
    • Method Detail

      • serialize

        public void serialize()
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • deserialize

        public void deserialize()
                         throws java.io.IOException
        deserialize from disk
        Throws:
        java.io.IOException
      • deserializeFromOldFile

        public void deserializeFromOldFile()
                                    throws java.io.IOException
        deserialize tsfile resource from old file
        Throws:
        java.io.IOException
      • updateStartTime

        public void updateStartTime​(java.lang.String device,
                                    long time)
      • updateEndTime

        public void updateEndTime​(java.lang.String device,
                                  long time)
      • resourceFileExists

        public boolean resourceFileExists()
      • getChunkMetadataList

        public java.util.List<org.apache.iotdb.tsfile.file.metadata.IChunkMetadata> getChunkMetadataList​(org.apache.iotdb.commons.path.PartialPath seriesPath)
      • getReadOnlyMemChunk

        public java.util.List<ReadOnlyMemChunk> getReadOnlyMemChunk​(org.apache.iotdb.commons.path.PartialPath seriesPath)
      • resetModFile

        public void resetModFile()
      • setFile

        public void setFile​(java.io.File file)
      • getTsFile

        public java.io.File getTsFile()
      • getTsFilePath

        public java.lang.String getTsFilePath()
      • getTsFileSize

        public long getTsFileSize()
      • getStartTime

        public long getStartTime​(java.lang.String deviceId)
      • getEndTime

        public long getEndTime​(java.lang.String deviceId)
        open file's end time is Long.MIN_VALUE
      • getOrderTime

        public long getOrderTime​(java.lang.String deviceId,
                                 boolean ascending)
      • getFileStartTime

        public long getFileStartTime()
      • getFileEndTime

        public long getFileEndTime()
        open file's end time is Long.MIN_VALUE
      • getDevices

        public java.util.Set<java.lang.String> getDevices()
      • mayContainsDevice

        public boolean mayContainsDevice​(java.lang.String device)
        Whether this TsFileResource contains this device, if false, it must not contain this device, if true, it may or may not contain this device
      • isClosed

        public boolean isClosed()
      • close

        public void close()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • writeLock

        public void writeLock()
      • writeUnlock

        public void writeUnlock()
      • readLock

        public void readLock()
        If originTsFileResource is not null, we should acquire the read lock of originTsFileResource before construct the current TsFileResource
      • readUnlock

        public void readUnlock()
      • tryWriteLock

        public boolean tryWriteLock()
      • tryReadLock

        public boolean tryReadLock()
      • removeModFile

        public void removeModFile()
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • remove

        public boolean remove()
        Remove the data file, its resource file, and its modification file physically.
      • removeResourceFile

        public boolean removeResourceFile()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • isDeleted

        public boolean isDeleted()
      • isCompacting

        public boolean isCompacting()
      • isCompactionCandidate

        public boolean isCompactionCandidate()
      • stillLives

        public boolean stillLives​(long timeLowerBound)
        check if any of the device lives over the given time bound. If the file is not closed, then return true.
      • isDeviceIdExist

        public boolean isDeviceIdExist​(java.lang.String deviceId)
      • isSatisfied

        public boolean isSatisfied​(java.lang.String deviceId,
                                   org.apache.iotdb.tsfile.read.filter.basic.Filter timeFilter,
                                   boolean isSeq,
                                   long ttl,
                                   boolean debug)
        Returns:
        true if the device is contained in the TsFile and it lives beyond TTL
      • isSatisfied

        public boolean isSatisfied​(java.lang.String deviceId,
                                   org.apache.iotdb.tsfile.read.filter.basic.Filter timeFilter,
                                   TsFileFilter fileFilter,
                                   boolean isSeq,
                                   boolean debug)
        Returns:
        true if the device is contained in the TsFile
      • getTimeSeriesMetadata

        public org.apache.iotdb.tsfile.file.metadata.ITimeSeriesMetadata getTimeSeriesMetadata​(org.apache.iotdb.commons.path.PartialPath seriesPath)
        Get a timeseriesMetadata by path.
        Returns:
        TimeseriesMetadata or the first ValueTimeseriesMetadata in VectorTimeseriesMetadata
      • setTimeSeriesMetadata

        public void setTimeSeriesMetadata​(org.apache.iotdb.commons.path.PartialPath path,
                                          org.apache.iotdb.tsfile.file.metadata.ITimeSeriesMetadata timeSeriesMetadata)
      • setUpgradedResources

        public void setUpgradedResources​(java.util.List<TsFileResource> upgradedResources)
      • getUpgradedResources

        public java.util.List<TsFileResource> getUpgradedResources()
      • getTimePartition

        public long getTimePartition()
        make sure Either the deviceToIndex is not empty Or the path contains a partition folder
      • getTimePartitionWithCheck

        public long getTimePartitionWithCheck()
                                       throws PartitionViolationException
        Used when load new TsFiles not generated by the server Check and get the time partition
        Throws:
        PartitionViolationException - if the data of the file spans partitions or it is empty
      • isSpanMultiTimePartitions

        public boolean isSpanMultiTimePartitions()
        Check whether the tsFile spans multiple time partitions.
      • createHardlink

        public TsFileResource createHardlink()
        Create a hardlink for the TsFile and modification file (if exists) The hardlink will have a suffix like ".{sysTime}_{randomLong}"
        Returns:
        a new TsFileResource with its file changed to the hardlink or null the hardlink cannot be created.
      • calculateRamSize

        public long calculateRamSize()
        Returns:
        resource map size
      • delete

        public void delete()
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • getMaxPlanIndex

        public long getMaxPlanIndex()
      • getMinPlanIndex

        public long getMinPlanIndex()
      • updatePlanIndexes

        public void updatePlanIndexes​(long planIndex)
      • getInnerCompactionCount

        public static int getInnerCompactionCount​(java.lang.String fileName)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • updatePlanIndexes

        public void updatePlanIndexes​(TsFileResource another)
        For merge, the index range of the new file should be the union of all files' in this merge.
      • isPlanIndexOverlap

        public boolean isPlanIndexOverlap​(TsFileResource another)
      • isPlanRangeCovers

        public boolean isPlanRangeCovers​(TsFileResource another)
      • setMaxPlanIndex

        public void setMaxPlanIndex​(long maxPlanIndex)
      • setMinPlanIndex

        public void setMinPlanIndex​(long minPlanIndex)
      • setVersion

        public void setVersion​(long version)
      • getVersion

        public long getVersion()
      • setTimeIndex

        public void setTimeIndex​(ITimeIndex timeIndex)
      • setSeq

        public void setSeq​(boolean seq)
      • isSeq

        public boolean isSeq()
      • compareIndexDegradePriority

        public int compareIndexDegradePriority​(TsFileResource tsFileResource)
      • getTimeIndexType

        public byte getTimeIndexType()
      • setTimeIndexType

        public void setTimeIndexType​(byte type)
      • getRamSize

        public long getRamSize()
      • degradeTimeIndex

        public long degradeTimeIndex()
        the DeviceTimeIndex degrade to FileTimeIndex and release memory
      • isFileInList

        public boolean isFileInList()
        Returns:
        is this tsfile resource in a TsFileResourceList