Class DataRegion
- java.lang.Object
-
- org.apache.iotdb.db.engine.storagegroup.DataRegion
-
public class DataRegion extends java.lang.ObjectFor sequence data, a DataRegion has some TsFileProcessors, in which there is only one TsFileProcessor in the working status.
There are two situations to set the working TsFileProcessor to closing status:
(1) when inserting data into the TsFileProcessor, and the TsFileProcessor shouldFlush() (or shouldClose())
(2) someone calls syncCloseAllWorkingTsFileProcessors(). (up to now, only flush command from cli will call this method)
UnSequence data has the similar process as above.
When a sequence TsFileProcessor is submitted to be flushed, the updateLatestFlushTimeCallback() method will be called as a callback.
When a TsFileProcessor is closed, the closeUnsealedTsFileProcessorCallBack() method will be called as a callback.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceDataRegion.CloseTsFileCallBackstatic interfaceDataRegion.CompactionRecoverCallBackstatic interfaceDataRegion.SettleTsFileCallBackstatic interfaceDataRegion.TimePartitionFilterstatic interfaceDataRegion.UpdateEndTimeCallBackstatic interfaceDataRegion.UpgradeTsFileResourceCallBack
-
Field Summary
Fields Modifier and Type Field Description static longCOMPACTION_TASK_SUBMIT_DELAY
-
Constructor Summary
Constructors Constructor Description DataRegion(java.lang.String storageGroupName, java.lang.String id)DataRegion(java.lang.String systemDir, java.lang.String dataRegionId, TsFileFlushPolicy fileFlushPolicy, java.lang.String storageGroupName)constrcut a storage group processor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabortCompaction()voidaddSettleFilesToList(java.util.List<TsFileResource> seqResourcesToBeSettled, java.util.List<TsFileResource> unseqResourcesToBeSettled, java.util.List<java.lang.String> tsFilePaths)voidasyncCloseAllWorkingTsFileProcessors()close all working tsfile processorsvoidasyncCloseOneTsFileProcessor(boolean sequence, TsFileProcessor tsFileProcessor)close one tsfile processor, thread-safety should be ensured by callervoidcheckFilesTTL()Iterate each TsFile and try to lock and remove those out of TTL.voidcloseAllResources()close all tsfile resourcejava.util.List<java.io.File>collectHistoryTsFileForSync(ISyncManager syncManager, long dataStartTime)Used to collect history TsFiles(i.e.voidcompact()merge file under this storage group processorintcountUpgradeFiles()count all Tsfiles in the storage group which need to be upgradedvoiddelete(org.apache.iotdb.commons.path.PartialPath path, long startTime, long endTime, long planIndex, DataRegion.TimePartitionFilter timePartitionFilter)Delete data whose timestamp <= 'timestamp' and belongs to the time series deviceId.measurementId.voiddeleteByDevice(org.apache.iotdb.commons.path.PartialPath pattern, long startTime, long endTime, long searchIndex, DataRegion.TimePartitionFilter timePartitionFilter)voiddeleteFolder(java.lang.String systemDir)delete the storageGroup's own folder in folder data/system/storage_groupsbooleandeleteTsfile(java.io.File tsfieToBeDeleted)Delete tsfile if it exists.voidforceCloseAllWorkingTsFileProcessors()force close all working tsfile processorsjava.lang.StringgetDataRegionId()IDTablegetIdTable()java.lang.StringgetInsertWriteLockHolder()java.util.concurrent.atomic.AtomicBooleangetIsSettling()ILastFlushTimeManagergetLastFlushTimeManager()longgetPartitionMaxFileVersions(long partitionId)java.util.List<TsFileResource>getSequenceFileList()StorageGroupInfogetStorageGroupInfo()java.lang.StringgetStorageGroupName()java.lang.StringgetStorageGroupPath()Get the storageGroupPath with dataRegionId.java.util.concurrent.ScheduledExecutorServicegetTimedCompactionScheduleTask()java.util.List<java.lang.Long>getTimePartitions()TsFileManagergetTsFileManager()TsFileManagergetTsFileResourceManager()java.util.List<TsFileResource>getUnSequenceFileList()IWALNodegetWALNode()This method could only be used in multi-leader consensusjava.util.Collection<TsFileProcessor>getWorkSequenceTsFileProcessors()get all working sequence tsfile processorsjava.util.Collection<TsFileProcessor>getWorkUnsequenceTsFileProcessors()get all working unsequence tsfile processorsvoidinsert(InsertRowNode insertRowNode)insert one row of datavoidinsert(InsertRowsNode insertRowsNode)insert batch of rows belongs to multiple devicesvoidinsert(InsertRowsOfOneDeviceNode insertRowsOfOneDeviceNode)insert batch of rows belongs to one devicevoidinsert(InsertRowPlan insertRowPlan)insert one row of datavoidinsert(InsertRowsOfOneDevicePlan insertRowsOfOneDevicePlan)insert batch of rows belongs to one devicevoidinsertTablet(InsertTabletNode insertTabletNode)Insert a tablet (rows belonging to the same devices) into this storage group.voidinsertTablet(InsertTabletPlan insertTabletPlan)Insert a tablet (rows belonging to the same devices) into this storage group.voidinsertTablets(InsertMultiTabletsNode insertMultiTabletsNode)insert batch of tablets belongs to multiple devicesbooleanisFileAlreadyExist(TsFileResource tsFileResource, long partitionNum)Check if the data of "tsFileResource" all exist locally by comparing planIndexes in the partition of "partitionNumber".booleanisReady()voidloadNewTsFile(TsFileResource newTsFileResource, boolean deleteOriginFile)Load a new tsfile to storage group processor.voidmarkDeleted()Release all threads waiting for this data region successfully deletedQueryDataSourcequery(java.util.List<org.apache.iotdb.commons.path.PartialPath> pathList, java.lang.String singleDeviceId, QueryContext context, QueryFileManager filePathsManager, org.apache.iotdb.tsfile.read.filter.basic.Filter timeFilter)build query data source by searching all tsfile which fit in query filterQueryDataSourcequery(java.util.List<org.apache.iotdb.commons.path.PartialPath> pathList, java.lang.String singleDeviceId, QueryContext context, org.apache.iotdb.tsfile.read.filter.basic.Filter timeFilter)used for mppvoidreadLock()lock the read lock of the insert lockvoidreadUnlock()unlock the read lock of insert lockvoidremoveFullyOverlapFiles(TsFileResource resource)If the historical versions of a file is a sub-set of the given file's, (close and) remove it to reduce unnecessary merge.voidremovePartitions(DataRegion.TimePartitionFilter filter)remove all partitions that satisfy a filter.voidsetAllowCompaction(boolean allowCompaction)voidsetCustomCloseFileListeners(java.util.List<CloseFileListener> customCloseFileListeners)voidsetCustomFlushListeners(java.util.List<FlushListener> customFlushListeners)voidsetDataTTL(long dataTTL)voidsetPartitionFileVersionToMax(long partition, long version)Set the version in "partition" to "version" if "version" is larger than the current version.voidsetReady(boolean ready)voidsetSettling(boolean isSettling)booleansubmitAFlushTask(long timeRangeId, boolean sequence, IMemTable memTable)WAL module uses this method to flush memTablevoidsubmitAFlushTaskWhenShouldFlush(TsFileProcessor tsFileProcessor)mem control module uses this method to flush memTablevoidsyncCloseAllWorkingTsFileProcessors()This method will be blocked until all tsfile processors are closed.voidsyncCloseOneTsFileProcessor(boolean sequence, TsFileProcessor tsFileProcessor)close one tsfile processorvoidsyncDeleteDataFiles()delete tsfilevoidtimedFlushSeqMemTable()voidtimedFlushUnseqMemTable()booleanunloadTsfile(java.io.File fileToBeUnloaded, java.io.File targetDir)Unload tsfile and move it to the target directory if it exists.voidupdateNewlyFlushedPartitionLatestFlushedTimeForEachDevice(long partitionId, java.lang.String deviceId, long time)used for upgradingvoidupgrade()upgrade all files belongs to this storage groupvoidwaitForDeleted()Wait for this data region successfully deletedvoidwriteLock(java.lang.String holder)lock the write lock of the insert lockvoidwriteUnlock()unlock the write lock of the insert lock
-
-
-
Field Detail
-
COMPACTION_TASK_SUBMIT_DELAY
public static final long COMPACTION_TASK_SUBMIT_DELAY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DataRegion
public DataRegion(java.lang.String systemDir, java.lang.String dataRegionId, TsFileFlushPolicy fileFlushPolicy, java.lang.String storageGroupName) throws DataRegionExceptionconstrcut a storage group processor- Parameters:
systemDir- system dir pathdataRegionId- data region id e.g. 1fileFlushPolicy- file flush policystorageGroupName- logical storage group name e.g. root.sg1- Throws:
DataRegionException
-
DataRegion
public DataRegion(java.lang.String storageGroupName, java.lang.String id)
-
-
Method Detail
-
getStorageGroupName
public java.lang.String getStorageGroupName()
-
isReady
public boolean isReady()
-
setReady
public void setReady(boolean ready)
-
getIsSettling
public java.util.concurrent.atomic.AtomicBoolean getIsSettling()
-
setSettling
public void setSettling(boolean isSettling)
-
insert
public void insert(InsertRowPlan insertRowPlan) throws WriteProcessException, TriggerExecutionException
insert one row of data- Parameters:
insertRowPlan- one row of data- Throws:
WriteProcessExceptionTriggerExecutionException
-
insert
public void insert(InsertRowNode insertRowNode) throws WriteProcessException, TriggerExecutionException
insert one row of data- Parameters:
insertRowNode- one row of data- Throws:
WriteProcessExceptionTriggerExecutionException
-
insertTablet
public void insertTablet(InsertTabletPlan insertTabletPlan) throws BatchProcessException, TriggerExecutionException
Insert a tablet (rows belonging to the same devices) into this storage group.- Throws:
BatchProcessException- if some of the rows failed to be insertedTriggerExecutionException
-
insertTablet
public void insertTablet(InsertTabletNode insertTabletNode) throws TriggerExecutionException, BatchProcessException, WriteProcessException
Insert a tablet (rows belonging to the same devices) into this storage group.- Throws:
BatchProcessException- if some of the rows failed to be insertedTriggerExecutionExceptionWriteProcessException
-
submitAFlushTask
public boolean submitAFlushTask(long timeRangeId, boolean sequence, IMemTable memTable)WAL module uses this method to flush memTable- Returns:
- True if flush task is submitted successfully
-
submitAFlushTaskWhenShouldFlush
public void submitAFlushTaskWhenShouldFlush(TsFileProcessor tsFileProcessor)
mem control module uses this method to flush memTable- Parameters:
tsFileProcessor- tsfile processor in which memTable to be flushed
-
syncCloseOneTsFileProcessor
public void syncCloseOneTsFileProcessor(boolean sequence, TsFileProcessor tsFileProcessor)close one tsfile processor- Parameters:
sequence- whether this tsfile processor is sequence or nottsFileProcessor- tsfile processor
-
asyncCloseOneTsFileProcessor
public void asyncCloseOneTsFileProcessor(boolean sequence, TsFileProcessor tsFileProcessor)close one tsfile processor, thread-safety should be ensured by caller- Parameters:
sequence- whether this tsfile processor is sequence or nottsFileProcessor- tsfile processor
-
deleteFolder
public void deleteFolder(java.lang.String systemDir)
delete the storageGroup's own folder in folder data/system/storage_groups- Parameters:
systemDir- system dir
-
closeAllResources
public void closeAllResources()
close all tsfile resource
-
syncDeleteDataFiles
public void syncDeleteDataFiles()
delete tsfile
-
checkFilesTTL
public void checkFilesTTL()
Iterate each TsFile and try to lock and remove those out of TTL.
-
timedFlushSeqMemTable
public void timedFlushSeqMemTable()
-
timedFlushUnseqMemTable
public void timedFlushUnseqMemTable()
-
syncCloseAllWorkingTsFileProcessors
public void syncCloseAllWorkingTsFileProcessors()
This method will be blocked until all tsfile processors are closed.
-
asyncCloseAllWorkingTsFileProcessors
public void asyncCloseAllWorkingTsFileProcessors()
close all working tsfile processors
-
forceCloseAllWorkingTsFileProcessors
public void forceCloseAllWorkingTsFileProcessors() throws TsFileProcessorExceptionforce close all working tsfile processors- Throws:
TsFileProcessorException
-
query
public QueryDataSource query(java.util.List<org.apache.iotdb.commons.path.PartialPath> pathList, java.lang.String singleDeviceId, QueryContext context, QueryFileManager filePathsManager, org.apache.iotdb.tsfile.read.filter.basic.Filter timeFilter) throws QueryProcessException
build query data source by searching all tsfile which fit in query filter- Parameters:
pathList- data pathscontext- query contexttimeFilter- time filtersingleDeviceId- selected deviceId (not null only when all the selected series are under the same device)- Returns:
- query data source
- Throws:
QueryProcessException
-
query
public QueryDataSource query(java.util.List<org.apache.iotdb.commons.path.PartialPath> pathList, java.lang.String singleDeviceId, QueryContext context, org.apache.iotdb.tsfile.read.filter.basic.Filter timeFilter) throws QueryProcessException
used for mpp- Throws:
QueryProcessException
-
readLock
public void readLock()
lock the read lock of the insert lock
-
readUnlock
public void readUnlock()
unlock the read lock of insert lock
-
writeLock
public void writeLock(java.lang.String holder)
lock the write lock of the insert lock
-
writeUnlock
public void writeUnlock()
unlock the write lock of the insert lock
-
delete
public void delete(org.apache.iotdb.commons.path.PartialPath path, long startTime, long endTime, long planIndex, DataRegion.TimePartitionFilter timePartitionFilter) throws java.io.IOExceptionDelete data whose timestamp <= 'timestamp' and belongs to the time series deviceId.measurementId.- Parameters:
path- the timeseries path of the to be deleted.startTime- the startTime of delete range.endTime- the endTime of delete range.timePartitionFilter-- Throws:
java.io.IOException
-
deleteByDevice
public void deleteByDevice(org.apache.iotdb.commons.path.PartialPath pattern, long startTime, long endTime, long searchIndex, DataRegion.TimePartitionFilter timePartitionFilter) throws java.io.IOException- Parameters:
pattern- Must be a pattern start with a precise device pathstartTime-endTime-searchIndex-timePartitionFilter-- Throws:
java.io.IOException
-
updateNewlyFlushedPartitionLatestFlushedTimeForEachDevice
public void updateNewlyFlushedPartitionLatestFlushedTimeForEachDevice(long partitionId, java.lang.String deviceId, long time)used for upgrading
-
countUpgradeFiles
public int countUpgradeFiles()
count all Tsfiles in the storage group which need to be upgraded- Returns:
- total num of the tsfiles which need to be upgraded in the storage group
-
upgrade
public void upgrade()
upgrade all files belongs to this storage group
-
compact
public void compact()
merge file under this storage group processor
-
loadNewTsFile
public void loadNewTsFile(TsFileResource newTsFileResource, boolean deleteOriginFile) throws LoadFileException
Load a new tsfile to storage group processor. Tne file may have overlap with other files.that there has no file which is overlapping with the new file.
Firstly, determine the loading type of the file, whether it needs to be loaded in sequence list or unsequence list.
Secondly, execute the loading process by the type.
Finally, update the latestTimeForEachDevice and partitionLatestFlushedTimeForEachDevice.
- Parameters:
newTsFileResource- tsfile resource @UsedBy load external tsfile moduledeleteOriginFile- whether to delete origin tsfile- Throws:
LoadFileException
-
setPartitionFileVersionToMax
public void setPartitionFileVersionToMax(long partition, long version)Set the version in "partition" to "version" if "version" is larger than the current version.
-
removeFullyOverlapFiles
public void removeFullyOverlapFiles(TsFileResource resource)
If the historical versions of a file is a sub-set of the given file's, (close and) remove it to reduce unnecessary merge. Only used when the file sender and the receiver share the same file close policy. Warning: DO NOT REMOVE
-
deleteTsfile
public boolean deleteTsfile(java.io.File tsfieToBeDeleted)
Delete tsfile if it exists.Firstly, remove the TsFileResource from sequenceFileList/unSequenceFileList.
Secondly, delete the tsfile and .resource file.
- Parameters:
tsfieToBeDeleted- tsfile to be deleted- Returns:
- whether the file to be deleted exists. @UsedBy sync module, load external tsfile module.
-
getWorkSequenceTsFileProcessors
public java.util.Collection<TsFileProcessor> getWorkSequenceTsFileProcessors()
get all working sequence tsfile processors- Returns:
- all working sequence tsfile processors
-
unloadTsfile
public boolean unloadTsfile(java.io.File fileToBeUnloaded, java.io.File targetDir)Unload tsfile and move it to the target directory if it exists.Firstly, unload the TsFileResource from sequenceFileList/unSequenceFileList.
Secondly, move the tsfile and .resource file to the target directory.
- Parameters:
fileToBeUnloaded- tsfile to be unloaded- Returns:
- whether the file to be unloaded exists. @UsedBy load external tsfile module.
-
getWorkUnsequenceTsFileProcessors
public java.util.Collection<TsFileProcessor> getWorkUnsequenceTsFileProcessors()
get all working unsequence tsfile processors- Returns:
- all working unsequence tsfile processors
-
setDataTTL
public void setDataTTL(long dataTTL)
-
getSequenceFileList
public java.util.List<TsFileResource> getSequenceFileList()
-
getUnSequenceFileList
public java.util.List<TsFileResource> getUnSequenceFileList()
-
getDataRegionId
public java.lang.String getDataRegionId()
-
getStorageGroupPath
public java.lang.String getStorageGroupPath()
Get the storageGroupPath with dataRegionId.- Returns:
- data region path, like root.sg1/0
-
getStorageGroupInfo
public StorageGroupInfo getStorageGroupInfo()
-
isFileAlreadyExist
public boolean isFileAlreadyExist(TsFileResource tsFileResource, long partitionNum)
Check if the data of "tsFileResource" all exist locally by comparing planIndexes in the partition of "partitionNumber". This is available only when the IoTDB instances which generated "tsFileResource" have the same plan indexes as the local one.- Returns:
- true if any file contains plans with indexes no less than the max plan index of "tsFileResource", otherwise false.
-
removePartitions
public void removePartitions(DataRegion.TimePartitionFilter filter)
remove all partitions that satisfy a filter.
-
abortCompaction
public void abortCompaction()
-
getTsFileResourceManager
public TsFileManager getTsFileResourceManager()
-
insert
public void insert(InsertRowsOfOneDevicePlan insertRowsOfOneDevicePlan) throws WriteProcessException, TriggerExecutionException
insert batch of rows belongs to one device- Parameters:
insertRowsOfOneDevicePlan- batch of rows belongs to one device- Throws:
WriteProcessExceptionTriggerExecutionException
-
insert
public void insert(InsertRowsOfOneDeviceNode insertRowsOfOneDeviceNode) throws WriteProcessException, TriggerExecutionException, BatchProcessException
insert batch of rows belongs to one device- Parameters:
insertRowsOfOneDeviceNode- batch of rows belongs to one device- Throws:
WriteProcessExceptionTriggerExecutionExceptionBatchProcessException
-
insert
public void insert(InsertRowsNode insertRowsNode) throws BatchProcessException
insert batch of rows belongs to multiple devices- Parameters:
insertRowsNode- batch of rows belongs to multiple devices- Throws:
BatchProcessException
-
insertTablets
public void insertTablets(InsertMultiTabletsNode insertMultiTabletsNode) throws BatchProcessException
insert batch of tablets belongs to multiple devices- Parameters:
insertMultiTabletsNode- batch of tablets belongs to multiple devices- Throws:
BatchProcessException
-
getPartitionMaxFileVersions
public long getPartitionMaxFileVersions(long partitionId)
-
addSettleFilesToList
public void addSettleFilesToList(java.util.List<TsFileResource> seqResourcesToBeSettled, java.util.List<TsFileResource> unseqResourcesToBeSettled, java.util.List<java.lang.String> tsFilePaths)
-
collectHistoryTsFileForSync
public java.util.List<java.io.File> collectHistoryTsFileForSync(ISyncManager syncManager, long dataStartTime)
Used to collect history TsFiles(i.e. the tsfile whose memtable == null).- Parameters:
syncManager- ISyncManager which invokes to collect history TsFiledataStartTime- only collect history TsFiles which contains the data after the dataStartTime- Returns:
- A list, which contains TsFile path
-
setCustomCloseFileListeners
public void setCustomCloseFileListeners(java.util.List<CloseFileListener> customCloseFileListeners)
-
setCustomFlushListeners
public void setCustomFlushListeners(java.util.List<FlushListener> customFlushListeners)
-
setAllowCompaction
public void setAllowCompaction(boolean allowCompaction)
-
getTimePartitions
public java.util.List<java.lang.Long> getTimePartitions()
-
getInsertWriteLockHolder
public java.lang.String getInsertWriteLockHolder()
-
getTimedCompactionScheduleTask
public java.util.concurrent.ScheduledExecutorService getTimedCompactionScheduleTask()
-
getIdTable
public IDTable getIdTable()
-
getWALNode
public IWALNode getWALNode()
This method could only be used in multi-leader consensus
-
waitForDeleted
public void waitForDeleted()
Wait for this data region successfully deleted
-
markDeleted
public void markDeleted()
Release all threads waiting for this data region successfully deleted
-
getLastFlushTimeManager
public ILastFlushTimeManager getLastFlushTimeManager()
-
getTsFileManager
public TsFileManager getTsFileManager()
-
-