Package org.apache.iotdb.db.engine
Class StorageEngine
- java.lang.Object
-
- org.apache.iotdb.db.engine.StorageEngine
-
- All Implemented Interfaces:
org.apache.iotdb.commons.service.IService
public class StorageEngine extends java.lang.Object implements org.apache.iotdb.commons.service.IService
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidblockInsertionIfReject(TsFileProcessor tsFileProcessor)block insertion if the insertion is rejected by memory controlDataRegionbuildNewStorageGroupProcessor(org.apache.iotdb.commons.path.PartialPath logicalStorageGroupName, IStorageGroupMNode storageGroupMNode, java.lang.String virtualStorageGroupId)build a new storage group processorvoidcloseStorageGroupProcessor(org.apache.iotdb.commons.path.PartialPath storageGroupPath, boolean isSeq, boolean isSync)voidcloseStorageGroupProcessor(org.apache.iotdb.commons.path.PartialPath storageGroupPath, long partitionId, boolean isSeq, boolean isSync)static longconvertMilliWithPrecision(long milliTime)intcountUpgradeFiles()count all Tsfiles which need to be upgradedvoiddelete(org.apache.iotdb.commons.path.PartialPath path, long startTime, long endTime, long planIndex, DataRegion.TimePartitionFilter timePartitionFilter)booleandeleteAll()delete all data of storage groups' timeseries.voiddeleteAllDataFilesInOneStorageGroup(org.apache.iotdb.commons.path.PartialPath storageGroupPath)delete all data files (both memory data and file on disk) in a storage group.voiddeleteStorageGroup(org.apache.iotdb.commons.path.PartialPath storageGroupPath)voiddeleteTimeseries(org.apache.iotdb.commons.path.PartialPath path, long planIndex, DataRegion.TimePartitionFilter timePartitionFilter)delete data of timeseries "{deviceId}.{measurementId}"booleandeleteTsfile(java.io.File deletedTsfile)voidforceCloseAllProcessor()java.util.Map<org.apache.iotdb.commons.path.PartialPath,java.util.Map<java.lang.Long,java.util.List<TsFileResource>>>getAllClosedStorageGroupTsFile()Get all the closed tsfiles of each storage group.intgetDataRegionIdByEngineFile(java.io.File file, boolean needCheck)The internal file means that the file is in the engine, which is different from those external files which are not loaded.org.apache.iotdb.commons.service.ServiceTypegetID()static StorageEnginegetInstance()java.util.List<java.lang.String>getLockInfo(java.util.List<org.apache.iotdb.commons.path.PartialPath> pathList)get lock holder for each sgDataRegiongetProcessor(org.apache.iotdb.commons.path.PartialPath path)This method is for insert and query or sth like them, this may get a virtual storage groupDataRegiongetProcessorByDataRegionId(org.apache.iotdb.commons.path.PartialPath path, int dataRegionId)DataRegiongetProcessorDirectly(org.apache.iotdb.commons.path.PartialPath path)This method is for sync, delete tsfile or sth like them, just get storage group directly by sg nameDataRegiongetProcessorDirectly(org.apache.iotdb.commons.path.PartialPath path, int dataRegionId)This method is for sync, delete tsfile or sth like them, just get storage group directly by dataRegionIdjava.util.Map<org.apache.iotdb.commons.path.PartialPath,StorageGroupManager>getProcessorMap()voidgetResourcesToBeSettled(org.apache.iotdb.commons.path.PartialPath sgPath, java.util.List<TsFileResource> seqResourcesToBeSettled, java.util.List<TsFileResource> unseqResourcesToBeSettled, java.util.List<java.lang.String> tsFilePaths)protected voidgetSeriesSchemas(InsertPlan insertPlan, DataRegion processor)java.lang.StringgetSgByEngineFile(java.io.File file, boolean needCheck)The internal file means that the file is in the engine, which is different from those external files which are not loaded.java.lang.StringgetStorageGroupPath(org.apache.iotdb.commons.path.PartialPath path)Get the virtual storage group name.static longgetTimePartition(long time)static longgetTimePartitionInterval()java.util.Map<java.lang.String,java.util.List<org.apache.iotdb.tsfile.utils.Pair<java.lang.Long,java.lang.Boolean>>>getWorkingStorageGroupPartitions()Get a map indicating which storage groups have working TsFileProcessors and its associated partitionId and whether it is sequence or not.voidinsert(InsertRowPlan insertRowPlan)insert an InsertRowPlan to a storage group.voidinsert(InsertRowsOfOneDevicePlan insertRowsOfOneDevicePlan)voidinsertTablet(InsertTabletPlan insertTabletPlan)insert a InsertTabletPlan to a storage groupbooleanisAllSgReady()static booleanisEnablePartition()booleanisFileAlreadyExist(TsFileResource tsFileResource, org.apache.iotdb.commons.path.PartialPath storageGroup, long partitionNum)voidloadNewTsFile(TsFileResource newTsFileResource, boolean deleteOriginFile)voidmergeAll()merge all storage groups.org.apache.iotdb.tsfile.utils.Pair<java.util.List<DataRegion>,java.util.Map<DataRegion,java.util.List<org.apache.iotdb.commons.path.PartialPath>>>mergeLock(java.util.List<org.apache.iotdb.commons.path.PartialPath> pathList)get all merge lock of the storage group processor related to the queryvoidmergeUnLock(java.util.List<DataRegion> list)unlock all merge lock of the storage group processor related to the queryvoidrebootTimedService()reboot timed flush sequence/unsequence memetable threadvoidrecover()voidregisterCloseFileListener(CloseFileListener listener)Add a listener to listen file close events.voidregisterFlushListener(FlushListener listener)Add a listener to listen flush start/end events.voidremovePartitions(org.apache.iotdb.commons.path.PartialPath storageGroupPath, DataRegion.TimePartitionFilter filter)voidreset()This function is just for unit test.voidsetAllSgReady(boolean allSgReady)static voidsetEnablePartition(boolean enablePartition)voidsetFileFlushPolicy(TsFileFlushPolicy fileFlushPolicy)voidsetPartitionVersionToMax(org.apache.iotdb.commons.path.PartialPath storageGroup, long partitionId, long newMaxVersion)Set the version of given partition to newMaxVersion if it is larger than the current version.voidsetSettling(org.apache.iotdb.commons.path.PartialPath sgPath, boolean isSettling)static voidsetTimePartitionInterval(long timePartitionInterval)voidsetTTL(org.apache.iotdb.commons.path.PartialPath storageGroup, long dataTTL)voidshutdown(long milliseconds)voidstart()voidstop()voidsyncCloseAllProcessor()flush command Sync asyncCloseOneProcessor all file node processors.booleanunloadTsfile(java.io.File tsfileToBeUnloaded, java.io.File targetDir)voidupgradeAll()upgrade all storage groups.
-
-
-
Method Detail
-
getInstance
public static StorageEngine getInstance()
-
convertMilliWithPrecision
public static long convertMilliWithPrecision(long milliTime)
-
getTimePartitionInterval
public static long getTimePartitionInterval()
-
setTimePartitionInterval
public static void setTimePartitionInterval(long timePartitionInterval)
-
getTimePartition
public static long getTimePartition(long time)
-
isEnablePartition
public static boolean isEnablePartition()
-
setEnablePartition
public static void setEnablePartition(boolean enablePartition)
-
blockInsertionIfReject
public static void blockInsertionIfReject(TsFileProcessor tsFileProcessor) throws WriteProcessRejectException
block insertion if the insertion is rejected by memory control- Throws:
WriteProcessRejectException
-
isAllSgReady
public boolean isAllSgReady()
-
setAllSgReady
public void setAllSgReady(boolean allSgReady)
-
recover
public void recover()
-
start
public void start()
- Specified by:
startin interfaceorg.apache.iotdb.commons.service.IService
-
stop
public void stop()
- Specified by:
stopin interfaceorg.apache.iotdb.commons.service.IService
-
shutdown
public void shutdown(long milliseconds) throws org.apache.iotdb.commons.exception.ShutdownException- Specified by:
shutdownin interfaceorg.apache.iotdb.commons.service.IService- Throws:
org.apache.iotdb.commons.exception.ShutdownException
-
rebootTimedService
public void rebootTimedService() throws org.apache.iotdb.commons.exception.ShutdownExceptionreboot timed flush sequence/unsequence memetable thread- Throws:
org.apache.iotdb.commons.exception.ShutdownException
-
getID
public org.apache.iotdb.commons.service.ServiceType getID()
- Specified by:
getIDin interfaceorg.apache.iotdb.commons.service.IService
-
getProcessorDirectly
public DataRegion getProcessorDirectly(org.apache.iotdb.commons.path.PartialPath path) throws StorageEngineException
This method is for sync, delete tsfile or sth like them, just get storage group directly by sg name- Parameters:
path- storage group path- Returns:
- storage group processor
- Throws:
StorageEngineException
-
getProcessorDirectly
public DataRegion getProcessorDirectly(org.apache.iotdb.commons.path.PartialPath path, int dataRegionId) throws StorageEngineException
This method is for sync, delete tsfile or sth like them, just get storage group directly by dataRegionId- Parameters:
path- storage group pathdataRegionId- dataRegionId- Returns:
- storage group processor
- Throws:
StorageEngineException
-
getProcessor
public DataRegion getProcessor(org.apache.iotdb.commons.path.PartialPath path) throws StorageEngineException
This method is for insert and query or sth like them, this may get a virtual storage group- Parameters:
path- device path- Returns:
- storage group processor
- Throws:
StorageEngineException
-
getProcessorByDataRegionId
public DataRegion getProcessorByDataRegionId(org.apache.iotdb.commons.path.PartialPath path, int dataRegionId) throws StorageEngineException
- Throws:
StorageEngineException
-
getLockInfo
public java.util.List<java.lang.String> getLockInfo(java.util.List<org.apache.iotdb.commons.path.PartialPath> pathList) throws StorageEngineExceptionget lock holder for each sg- Returns:
- storage group processor
- Throws:
StorageEngineException
-
buildNewStorageGroupProcessor
public DataRegion buildNewStorageGroupProcessor(org.apache.iotdb.commons.path.PartialPath logicalStorageGroupName, IStorageGroupMNode storageGroupMNode, java.lang.String virtualStorageGroupId) throws DataRegionException
build a new storage group processor- Parameters:
virtualStorageGroupId- virtual storage group id e.g. 1logicalStorageGroupName- logical storage group name e.g. root.sg1- Throws:
DataRegionException
-
reset
public void reset()
This function is just for unit test.
-
insert
public void insert(InsertRowPlan insertRowPlan) throws StorageEngineException, org.apache.iotdb.commons.exception.MetadataException
insert an InsertRowPlan to a storage group.- Parameters:
insertRowPlan- physical plan of insertion- Throws:
StorageEngineExceptionorg.apache.iotdb.commons.exception.MetadataException
-
insert
public void insert(InsertRowsOfOneDevicePlan insertRowsOfOneDevicePlan) throws StorageEngineException, org.apache.iotdb.commons.exception.MetadataException
- Throws:
StorageEngineExceptionorg.apache.iotdb.commons.exception.MetadataException
-
insertTablet
public void insertTablet(InsertTabletPlan insertTabletPlan) throws StorageEngineException, BatchProcessException, org.apache.iotdb.commons.exception.MetadataException
insert a InsertTabletPlan to a storage group- Throws:
StorageEngineExceptionBatchProcessExceptionorg.apache.iotdb.commons.exception.MetadataException
-
syncCloseAllProcessor
public void syncCloseAllProcessor()
flush command Sync asyncCloseOneProcessor all file node processors.
-
forceCloseAllProcessor
public void forceCloseAllProcessor() throws TsFileProcessorException- Throws:
TsFileProcessorException
-
closeStorageGroupProcessor
public void closeStorageGroupProcessor(org.apache.iotdb.commons.path.PartialPath storageGroupPath, boolean isSeq, boolean isSync)
-
closeStorageGroupProcessor
public void closeStorageGroupProcessor(org.apache.iotdb.commons.path.PartialPath storageGroupPath, long partitionId, boolean isSeq, boolean isSync) throws StorageGroupNotSetException- Parameters:
storageGroupPath- the storage group namepartitionId- the partition idisSeq- is sequence tsfile or unsequence tsfileisSync- close tsfile synchronously or asynchronously- Throws:
StorageGroupNotSetException
-
delete
public void delete(org.apache.iotdb.commons.path.PartialPath path, long startTime, long endTime, long planIndex, DataRegion.TimePartitionFilter timePartitionFilter) throws StorageEngineException- Throws:
StorageEngineException
-
deleteTimeseries
public void deleteTimeseries(org.apache.iotdb.commons.path.PartialPath path, long planIndex, DataRegion.TimePartitionFilter timePartitionFilter) throws StorageEngineExceptiondelete data of timeseries "{deviceId}.{measurementId}"- Throws:
StorageEngineException
-
countUpgradeFiles
public int countUpgradeFiles()
count all Tsfiles which need to be upgraded- Returns:
- total num of the tsfiles which need to be upgraded
-
upgradeAll
public void upgradeAll() throws StorageEngineExceptionupgrade all storage groups.- Throws:
StorageEngineException- StorageEngineException
-
getResourcesToBeSettled
public void getResourcesToBeSettled(org.apache.iotdb.commons.path.PartialPath sgPath, java.util.List<TsFileResource> seqResourcesToBeSettled, java.util.List<TsFileResource> unseqResourcesToBeSettled, java.util.List<java.lang.String> tsFilePaths) throws StorageEngineException- Throws:
StorageEngineException
-
setSettling
public void setSettling(org.apache.iotdb.commons.path.PartialPath sgPath, boolean isSettling)
-
mergeAll
public void mergeAll() throws StorageEngineExceptionmerge all storage groups.- Throws:
StorageEngineException- StorageEngineException
-
deleteAllDataFilesInOneStorageGroup
public void deleteAllDataFilesInOneStorageGroup(org.apache.iotdb.commons.path.PartialPath storageGroupPath)
delete all data files (both memory data and file on disk) in a storage group. It is used when there is no timeseries (which are all deleted) in this storage group)
-
deleteAll
public boolean deleteAll()
delete all data of storage groups' timeseries.
-
setTTL
public void setTTL(org.apache.iotdb.commons.path.PartialPath storageGroup, long dataTTL)
-
deleteStorageGroup
public void deleteStorageGroup(org.apache.iotdb.commons.path.PartialPath storageGroupPath)
-
loadNewTsFile
public void loadNewTsFile(TsFileResource newTsFileResource, boolean deleteOriginFile) throws LoadFileException, StorageEngineException, org.apache.iotdb.commons.exception.MetadataException
- Throws:
LoadFileExceptionStorageEngineExceptionorg.apache.iotdb.commons.exception.MetadataException
-
deleteTsfile
public boolean deleteTsfile(java.io.File deletedTsfile) throws StorageEngineException, org.apache.iotdb.commons.exception.IllegalPathException- Throws:
StorageEngineExceptionorg.apache.iotdb.commons.exception.IllegalPathException
-
unloadTsfile
public boolean unloadTsfile(java.io.File tsfileToBeUnloaded, java.io.File targetDir) throws StorageEngineException, org.apache.iotdb.commons.exception.IllegalPathException- Throws:
StorageEngineExceptionorg.apache.iotdb.commons.exception.IllegalPathException
-
getSgByEngineFile
public java.lang.String getSgByEngineFile(java.io.File file, boolean needCheck) throws org.apache.iotdb.commons.exception.IllegalPathExceptionThe internal file means that the file is in the engine, which is different from those external files which are not loaded.- Parameters:
file- internal fileneedCheck- check if the tsfile is an internal TsFile. If you make sure it is inside, no need to check- Returns:
- sg name
- Throws:
org.apache.iotdb.commons.exception.IllegalPathException- throw if tsfile is not an internal TsFile
-
getDataRegionIdByEngineFile
public int getDataRegionIdByEngineFile(java.io.File file, boolean needCheck) throws org.apache.iotdb.commons.exception.IllegalPathExceptionThe internal file means that the file is in the engine, which is different from those external files which are not loaded.- Parameters:
file- internal fileneedCheck- check if the tsfile is an internal TsFile. If you make sure it is inside, no need to check- Returns:
- dataRegionId
- Throws:
org.apache.iotdb.commons.exception.IllegalPathException- throw if tsfile is not an internal TsFile
-
getAllClosedStorageGroupTsFile
public java.util.Map<org.apache.iotdb.commons.path.PartialPath,java.util.Map<java.lang.Long,java.util.List<TsFileResource>>> getAllClosedStorageGroupTsFile()
Get all the closed tsfiles of each storage group.- Returns:
- TsFiles (seq or unseq) grouped by their storage group and partition number.
-
setFileFlushPolicy
public void setFileFlushPolicy(TsFileFlushPolicy fileFlushPolicy)
-
isFileAlreadyExist
public boolean isFileAlreadyExist(TsFileResource tsFileResource, org.apache.iotdb.commons.path.PartialPath storageGroup, long partitionNum)
-
setPartitionVersionToMax
public void setPartitionVersionToMax(org.apache.iotdb.commons.path.PartialPath storageGroup, long partitionId, long newMaxVersion)Set the version of given partition to newMaxVersion if it is larger than the current version.
-
removePartitions
public void removePartitions(org.apache.iotdb.commons.path.PartialPath storageGroupPath, DataRegion.TimePartitionFilter filter)
-
getProcessorMap
public java.util.Map<org.apache.iotdb.commons.path.PartialPath,StorageGroupManager> getProcessorMap()
-
getWorkingStorageGroupPartitions
public java.util.Map<java.lang.String,java.util.List<org.apache.iotdb.tsfile.utils.Pair<java.lang.Long,java.lang.Boolean>>> getWorkingStorageGroupPartitions()
Get a map indicating which storage groups have working TsFileProcessors and its associated partitionId and whether it is sequence or not.- Returns:
- storage group -> a list of partitionId-isSequence pairs
-
registerFlushListener
public void registerFlushListener(FlushListener listener)
Add a listener to listen flush start/end events. Notice that this addition only applies to TsFileProcessors created afterwards.- Parameters:
listener-
-
registerCloseFileListener
public void registerCloseFileListener(CloseFileListener listener)
Add a listener to listen file close events. Notice that this addition only applies to TsFileProcessors created afterwards.- Parameters:
listener-
-
mergeLock
public org.apache.iotdb.tsfile.utils.Pair<java.util.List<DataRegion>,java.util.Map<DataRegion,java.util.List<org.apache.iotdb.commons.path.PartialPath>>> mergeLock(java.util.List<org.apache.iotdb.commons.path.PartialPath> pathList) throws StorageEngineException
get all merge lock of the storage group processor related to the query- Throws:
StorageEngineException
-
mergeUnLock
public void mergeUnLock(java.util.List<DataRegion> list)
unlock all merge lock of the storage group processor related to the query
-
getStorageGroupPath
public java.lang.String getStorageGroupPath(org.apache.iotdb.commons.path.PartialPath path) throws StorageEngineExceptionGet the virtual storage group name.- Returns:
- virtual storage group name, like root.sg1/0
- Throws:
StorageEngineException
-
getSeriesSchemas
protected void getSeriesSchemas(InsertPlan insertPlan, DataRegion processor) throws StorageEngineException, org.apache.iotdb.commons.exception.MetadataException
- Throws:
StorageEngineExceptionorg.apache.iotdb.commons.exception.MetadataException
-
-