Class TsFileResource
- java.lang.Object
-
- org.apache.iotdb.db.engine.storagegroup.TsFileResource
-
public class TsFileResource extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected longmaxPlanIndexMaximum index of plans executed within this TsFile.protected longminPlanIndexMinimum index of plans executed within this TsFile.protected TsFileResourcenextprotected TsFileResourceprevUsed inTsFileResourceListstatic java.lang.StringRESOURCE_SUFFIXprotected TsFileResourceStatusstatusprotected ITimeIndextimeIndextime indexstatic byteVERSION_NUMBERversion number
-
Constructor Summary
Constructors Constructor Description TsFileResource()TsFileResource(java.io.File file)for sealed TsFile, call setClosed to close TsFileResourceTsFileResource(java.io.File file, java.util.Map<java.lang.String,java.lang.Integer> deviceToIndex, long[] startTimes, long[] endTimes)TsFileResource(java.io.File file, TsFileProcessor processor)unsealed TsFile, for writterTsFileResource(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)unsealed TsFile, for queryTsFileResource(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)unsealed TsFile, for queryTsFileResource(TsFileResource other)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longcalculateRamSize()voidclose()static intcompareFileName(TsFileResource o1, TsFileResource o2)intcompareIndexDegradePriority(TsFileResource tsFileResource)TsFileResourcecreateHardlink()Create a hardlink for the TsFile and modification file (if exists) The hardlink will have a suffix like ".{sysTime}_{randomLong}"longdegradeTimeIndex()the DeviceTimeIndex degrade to FileTimeIndex and release memoryvoiddelete()voiddeserialize()deserialize from diskvoiddeserializeFromOldFile()deserialize tsfile resource from old filebooleanequals(java.lang.Object o)java.util.List<org.apache.iotdb.tsfile.file.metadata.IChunkMetadata>getChunkMetadataList(org.apache.iotdb.commons.path.PartialPath seriesPath)ModificationFilegetCompactionModFile()java.util.Set<java.lang.String>getDevices()longgetEndTime(java.lang.String deviceId)open file's end time is Long.MIN_VALUElonggetFileEndTime()open file's end time is Long.MIN_VALUElonggetFileStartTime()static intgetInnerCompactionCount(java.lang.String fileName)longgetMaxPlanIndex()longgetMinPlanIndex()ModificationFilegetModFile()longgetOrderTime(java.lang.String deviceId, boolean ascending)longgetRamSize()java.util.List<ReadOnlyMemChunk>getReadOnlyMemChunk(org.apache.iotdb.commons.path.PartialPath seriesPath)DataRegion.SettleTsFileCallBackgetSettleTsFileCallBack()longgetStartTime(java.lang.String deviceId)TsFileResourceStatusgetStatus()bytegetTimeIndexType()longgetTimePartition()make sure Either the deviceToIndex is not empty Or the path contains a partition folderlonggetTimePartitionWithCheck()Used when load new TsFiles not generated by the server Check and get the time partitionorg.apache.iotdb.tsfile.file.metadata.ITimeSeriesMetadatagetTimeSeriesMetadata(org.apache.iotdb.commons.path.PartialPath seriesPath)Get a timeseriesMetadata by path.java.io.FilegetTsFile()java.lang.StringgetTsFilePath()longgetTsFileSize()java.util.List<TsFileResource>getUpgradedResources()DataRegion.UpgradeTsFileResourceCallBackgetUpgradeTsFileResourceCallBack()longgetVersion()inthashCode()booleanisClosed()booleanisCompacting()booleanisCompactionCandidate()booleanisDeleted()booleanisDeviceIdExist(java.lang.String deviceId)booleanisFileInList()booleanisPlanIndexOverlap(TsFileResource another)booleanisPlanRangeCovers(TsFileResource another)booleanisSatisfied(java.lang.String deviceId, org.apache.iotdb.tsfile.read.filter.basic.Filter timeFilter, boolean isSeq, long ttl, boolean debug)booleanisSatisfied(java.lang.String deviceId, org.apache.iotdb.tsfile.read.filter.basic.Filter timeFilter, TsFileFilter fileFilter, boolean isSeq, boolean debug)booleanisSeq()booleanisSpanMultiTimePartitions()Check whether the tsFile spans multiple time partitions.booleanmayContainsDevice(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 devicevoidreadLock()If originTsFileResource is not null, we should acquire the read lock of originTsFileResource before construct the current TsFileResourcevoidreadUnlock()booleanremove()Remove the data file, its resource file, and its modification file physically.voidremoveModFile()booleanremoveResourceFile()voidresetModFile()booleanresourceFileExists()voidserialize()voidsetFile(java.io.File file)voidsetMaxPlanIndex(long maxPlanIndex)voidsetMinPlanIndex(long minPlanIndex)voidsetModFile(ModificationFile modFile)voidsetProcessor(TsFileProcessor processor)voidsetSeq(boolean seq)voidsetSettleTsFileCallBack(DataRegion.SettleTsFileCallBack settleTsFileCallBack)voidsetStatus(TsFileResourceStatus status)voidsetTimeIndex(ITimeIndex timeIndex)voidsetTimeIndexType(byte type)voidsetTimeSeriesMetadata(org.apache.iotdb.commons.path.PartialPath path, org.apache.iotdb.tsfile.file.metadata.ITimeSeriesMetadata timeSeriesMetadata)voidsetUpgradedResources(java.util.List<TsFileResource> upgradedResources)voidsetUpgradeTsFileResourceCallBack(DataRegion.UpgradeTsFileResourceCallBack upgradeTsFileResourceCallBack)voidsetVersion(long version)booleanstillLives(long timeLowerBound)check if any of the device lives over the given time bound.java.lang.StringtoString()booleantryReadLock()booleantryWriteLock()voidupdateEndTime(java.lang.String device, long time)voidupdatePlanIndexes(long planIndex)voidupdatePlanIndexes(TsFileResource another)For merge, the index range of the new file should be the union of all files' in this merge.voidupdateStartTime(java.lang.String device, long time)voidwriteLock()voidwriteUnlock()
-
-
-
Field Detail
-
RESOURCE_SUFFIX
public static final java.lang.String RESOURCE_SUFFIX
- See Also:
- Constant Field Values
-
VERSION_NUMBER
public static final byte VERSION_NUMBER
version number- See Also:
- Constant Field Values
-
prev
protected TsFileResource prev
Used inTsFileResourceList
-
next
protected TsFileResource next
-
timeIndex
protected ITimeIndex timeIndex
time index
-
status
protected volatile TsFileResourceStatus status
-
maxPlanIndex
protected long maxPlanIndex
Maximum index of plans executed within this TsFile.
-
minPlanIndex
protected long minPlanIndex
Minimum index of plans executed within this TsFile.
-
-
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.IOExceptionunsealed 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.IOExceptiondeserialize from disk- Throws:
java.io.IOException
-
deserializeFromOldFile
public void deserializeFromOldFile() throws java.io.IOExceptiondeserialize 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)
-
getModFile
public ModificationFile getModFile()
-
getCompactionModFile
public ModificationFile getCompactionModFile()
-
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:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
isDeleted
public boolean isDeleted()
-
isCompacting
public boolean isCompacting()
-
isCompactionCandidate
public boolean isCompactionCandidate()
-
setStatus
public void setStatus(TsFileResourceStatus status)
-
getStatus
public TsFileResourceStatus getStatus()
-
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
-
setProcessor
public void setProcessor(TsFileProcessor processor)
-
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()
-
setUpgradeTsFileResourceCallBack
public void setUpgradeTsFileResourceCallBack(DataRegion.UpgradeTsFileResourceCallBack upgradeTsFileResourceCallBack)
-
getUpgradeTsFileResourceCallBack
public DataRegion.UpgradeTsFileResourceCallBack getUpgradeTsFileResourceCallBack()
-
getSettleTsFileCallBack
public DataRegion.SettleTsFileCallBack getSettleTsFileCallBack()
-
setSettleTsFileCallBack
public void setSettleTsFileCallBack(DataRegion.SettleTsFileCallBack settleTsFileCallBack)
-
getTimePartition
public long getTimePartition()
make sure Either the deviceToIndex is not empty Or the path contains a partition folder
-
getTimePartitionWithCheck
public long getTimePartitionWithCheck() throws PartitionViolationExceptionUsed 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.
-
setModFile
public void setModFile(ModificationFile modFile)
-
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)
-
compareFileName
public static int compareFileName(TsFileResource o1, TsFileResource o2)
-
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
-
-