Class 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 Detail

      • 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)
      • isAllSgReady

        public boolean isAllSgReady()
      • setAllSgReady

        public void setAllSgReady​(boolean allSgReady)
      • recover

        public void recover()
      • start

        public void start()
        Specified by:
        start in interface org.apache.iotdb.commons.service.IService
      • stop

        public void stop()
        Specified by:
        stop in interface org.apache.iotdb.commons.service.IService
      • shutdown

        public void shutdown​(long milliseconds)
                      throws org.apache.iotdb.commons.exception.ShutdownException
        Specified by:
        shutdown in interface org.apache.iotdb.commons.service.IService
        Throws:
        org.apache.iotdb.commons.exception.ShutdownException
      • rebootTimedService

        public void rebootTimedService()
                                throws org.apache.iotdb.commons.exception.ShutdownException
        reboot timed flush sequence/unsequence memetable thread
        Throws:
        org.apache.iotdb.commons.exception.ShutdownException
      • getID

        public org.apache.iotdb.commons.service.ServiceType getID()
        Specified by:
        getID in interface org.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 path
        dataRegionId - 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
      • getLockInfo

        public java.util.List<java.lang.String> getLockInfo​(java.util.List<org.apache.iotdb.commons.path.PartialPath> pathList)
                                                     throws StorageEngineException
        get 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. 1
        logicalStorageGroupName - 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:
        StorageEngineException
        org.apache.iotdb.commons.exception.MetadataException
      • syncCloseAllProcessor

        public void syncCloseAllProcessor()
        flush command Sync asyncCloseOneProcessor all file node processors.
      • 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 name
        partitionId - the partition id
        isSeq - is sequence tsfile or unsequence tsfile
        isSync - close tsfile synchronously or asynchronously
        Throws:
        StorageGroupNotSetException
      • countUpgradeFiles

        public int countUpgradeFiles()
        count all Tsfiles which need to be upgraded
        Returns:
        total num of the tsfiles which need to be upgraded
      • setSettling

        public void setSettling​(org.apache.iotdb.commons.path.PartialPath sgPath,
                                boolean isSettling)
      • 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)
      • deleteTsfile

        public boolean deleteTsfile​(java.io.File deletedTsfile)
                             throws StorageEngineException,
                                    org.apache.iotdb.commons.exception.IllegalPathException
        Throws:
        StorageEngineException
        org.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:
        StorageEngineException
        org.apache.iotdb.commons.exception.IllegalPathException
      • getSgByEngineFile

        public java.lang.String getSgByEngineFile​(java.io.File file,
                                                  boolean needCheck)
                                           throws org.apache.iotdb.commons.exception.IllegalPathException
        The internal file means that the file is in the engine, which is different from those external files which are not loaded.
        Parameters:
        file - internal file
        needCheck - 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.IllegalPathException
        The internal file means that the file is in the engine, which is different from those external files which are not loaded.
        Parameters:
        file - internal file
        needCheck - 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 StorageEngineException
        Get the virtual storage group name.
        Returns:
        virtual storage group name, like root.sg1/0
        Throws:
        StorageEngineException