Class PartitionManager

java.lang.Object
org.apache.iotdb.confignode.manager.partition.PartitionManager

public class PartitionManager extends Object
The PartitionManager manages cluster PartitionTable read and write requests.
  • Field Details

  • Constructor Details

  • Method Details

    • getSchemaPartition

      public SchemaPartitionResp getSchemaPartition(GetSchemaPartitionPlan req)
      Thread-safely get SchemaPartition.
      Parameters:
      req - SchemaPartitionPlan with partitionSlotsMap
      Returns:
      SchemaPartitionDataSet that contains only existing SchemaPartition
    • getDataPartition

      public DataPartitionResp getDataPartition(GetDataPartitionPlan req)
      Thread-safely get DataPartition
      Parameters:
      req - DataPartitionPlan with Map<StorageGroupName, Map<SeriesPartitionSlot, TTimeSlotList>>
      Returns:
      DataPartitionDataSet that contains only existing DataPartition
    • getOrCreateSchemaPartition

      public SchemaPartitionResp getOrCreateSchemaPartition(GetOrCreateSchemaPartitionPlan req)
      Get SchemaPartition and create a new one if it does not exist.
      Parameters:
      req - SchemaPartitionPlan with partitionSlotsMap
      Returns:
      SchemaPartitionResp with DataPartition and TSStatus. SUCCESS_STATUS if all process finish. NOT_ENOUGH_DATA_NODE if the DataNodes is not enough to create new Regions. STORAGE_GROUP_NOT_EXIST if some StorageGroup don't exist.
    • getOrCreateDataPartition

      public DataPartitionResp getOrCreateDataPartition(GetOrCreateDataPartitionPlan req)
      Get DataPartition and create a new one if it does not exist.
      Parameters:
      req - DataPartitionPlan with Map<StorageGroupName, Map <SeriesPartitionSlot, List<TimePartitionSlot>> >
      Returns:
      DataPartitionResp with DataPartition and TSStatus. TSStatusCode.SUCCESS_STATUS if all process finish. TSStatusCode.NO_ENOUGH_DATANODE if the DataNodes is not enough to create new Regions. TSStatusCode.DATABASE_NOT_EXIST if some database does not exist.
    • getSuccessorDataPartition

      public TConsensusGroupId getSuccessorDataPartition(String database, TSeriesPartitionSlot seriesPartitionSlot, TTimePartitionSlot timePartitionSlot)
      Only leader use this interface. Checks whether the specified DataPartition has a successor and returns if it does.
      Parameters:
      database - DatabaseName
      seriesPartitionSlot - Corresponding SeriesPartitionSlot
      timePartitionSlot - Corresponding TimePartitionSlot
      Returns:
      The specific DataPartition's successor if exists, null otherwise
    • getPredecessorDataPartition

      public TConsensusGroupId getPredecessorDataPartition(String database, TSeriesPartitionSlot seriesPartitionSlot, TTimePartitionSlot timePartitionSlot)
      Only leader use this interface. Checks whether the specified DataPartition has a predecessor and returns if it does.
      Parameters:
      database - DatabaseName
      seriesPartitionSlot - Corresponding SeriesPartitionSlot
      timePartitionSlot - Corresponding TimePartitionSlot
      Returns:
      The specific DataPartition's predecessor if exists, null otherwise
    • getDatabaseRelatedDataNodes

      public Set<TDataNodeLocation> getDatabaseRelatedDataNodes(String database, TConsensusGroupType type)
      Get the DataNodes who contain the specified Database's Schema or Data.
      Parameters:
      database - The specific Database's name
      type - SchemaRegion or DataRegion
      Returns:
      Set <TDataNodeLocation>, the related DataNodes
    • getAllReplicaSetsMap

      public Map<TConsensusGroupId,TRegionReplicaSet> getAllReplicaSetsMap(TConsensusGroupType type)
      Only leader use this interface.
      Parameters:
      type - The specified TConsensusGroupType
      Returns:
      Deep copy of all Regions' RegionReplicaSet and organized to Map
    • getAllReplicaSets

      public List<TRegionReplicaSet> getAllReplicaSets()
      Only leader use this interface.
      Returns:
      Deep copy of all Regions' RegionReplicaSet
    • getAllReplicaSets

      public List<TRegionReplicaSet> getAllReplicaSets(TConsensusGroupType type)
      Only leader use this interface.
      Parameters:
      type - The specified TConsensusGroupType
      Returns:
      Deep copy of all Regions' RegionReplicaSet with the specified TConsensusGroupType
    • getAllReplicaSets

      public List<TRegionReplicaSet> getAllReplicaSets(String database)
      Only leader use this interface.
      Parameters:
      database - The specified Database
      Returns:
      All Regions' RegionReplicaSet of the specified Database
    • getAllReplicaSets

      public List<TRegionReplicaSet> getAllReplicaSets(String database, TConsensusGroupType type)
      Only leader use this interface.
      Parameters:
      database - The specified Database
      type - SchemaRegion or DataRegion
      Returns:
      Deep copy of all Regions' RegionReplicaSet with the specified Database and TConsensusGroupType
    • getAllReplicaSets

      public List<TRegionReplicaSet> getAllReplicaSets(int dataNodeId)
      Get all RegionGroups currently owned by the specified Database.
      Parameters:
      dataNodeId - The specified dataNodeId
      Returns:
      Deep copy of all RegionGroups' RegionReplicaSet with the specified dataNodeId
    • getReplicaSets

      public List<TRegionReplicaSet> getReplicaSets(String database, List<TConsensusGroupId> regionGroupIds)
      Only leader use this interface.
      Parameters:
      database - The specified Database
      regionGroupIds - The specified RegionGroupIds
      Returns:
      All Regions' RegionReplicaSet of the specified Database
    • isDataNodeContainsRegion

      public boolean isDataNodeContainsRegion(int dataNodeId, TConsensusGroupId regionId)
    • getRegionCount

      public int getRegionCount(int dataNodeId, TConsensusGroupType type)
      Only leader use this interface.

      Get the number of Regions currently owned by the specified DataNode

      Parameters:
      dataNodeId - The specified DataNode
      type - SchemaRegion or DataRegion
      Returns:
      The number of Regions currently owned by the specified DataNode
    • countDataNodeScatterWidth

      public int countDataNodeScatterWidth(int dataNodeId, TConsensusGroupType type)
      Only leader use this interface.

      Count the scatter width of the specified DataNode

      Parameters:
      dataNodeId - The specified DataNode
      type - SchemaRegion or DataRegion
      Returns:
      The schema/data scatter width of the specified DataNode. The scatter width refers to the number of other DataNodes in the cluster which have at least one identical schema/data replica as the specified DataNode.
    • getRegionGroupCount

      public int getRegionGroupCount(String database, TConsensusGroupType type) throws DatabaseNotExistsException
      Only leader use this interface.

      Get the number of RegionGroups currently owned by the specified Database

      Parameters:
      database - DatabaseName
      type - SchemaRegion or DataRegion
      Returns:
      Number of Regions currently owned by the specified Database
      Throws:
      DatabaseNotExistsException - When the specified Database doesn't exist
    • getAllRegionGroupIdMap

      public Map<String,List<TConsensusGroupId>> getAllRegionGroupIdMap(TConsensusGroupType type)
      Only leader use this interface.

      Get the all RegionGroups currently in the cluster

      Parameters:
      type - SchemaRegion or DataRegion
      Returns:
      Map<Database, List>
    • getAllRegionGroupIds

      public List<TConsensusGroupId> getAllRegionGroupIds(String database, TConsensusGroupType type) throws DatabaseNotExistsException
      Only leader use this interface.

      Get all the RegionGroups currently owned by the specified Database

      Parameters:
      database - DatabaseName
      type - SchemaRegion or DataRegion
      Returns:
      List of TConsensusGroupId
      Throws:
      DatabaseNotExistsException - When the specified Database doesn't exist
    • isDatabaseExist

      public boolean isDatabaseExist(String database)
      Check if the specified Database exists.
      Parameters:
      database - The specified Database
      Returns:
      True if the DatabaseSchema is exists and the Database is not pre-deleted
    • filterUnExistDatabases

      public List<PartialPath> filterUnExistDatabases(List<PartialPath> databases)
      Filter the un-exist Databases.
      Parameters:
      databases - the Databases to check
      Returns:
      List of PartialPath the Databases that not exist
    • getAssignedSeriesPartitionSlotsCount

      public int getAssignedSeriesPartitionSlotsCount(String database)
      Only leader use this interface.

      Get the assigned SeriesPartitionSlots count in the specified Database

      Parameters:
      database - The specified Database
      Returns:
      The assigned SeriesPartitionSlots count
    • getAssignedTimePartitionSlotsCount

      public long getAssignedTimePartitionSlotsCount(String database)
      Only leader use this interface.

      Get the assigned TimePartitionSlots count in the specified Database

      Parameters:
      database - The specified Database
      Returns:
      The assigned TimePartitionSlots count
    • getSortedRegionGroupSlotsCounter

      public List<org.apache.tsfile.utils.Pair<Long,TConsensusGroupId>> getSortedRegionGroupSlotsCounter(String database, TConsensusGroupType type) throws NoAvailableRegionGroupException
      Only leader use this interface.
      Parameters:
      database - DatabaseName
      type - SchemaRegion or DataRegion
      Returns:
      The specific StorageGroup's Regions that sorted by the number of allocated slots
      Throws:
      NoAvailableRegionGroupException - When all RegionGroups within the specified StorageGroup are unavailable currently
    • getAllSchemaPartition

      public Set<Integer> getAllSchemaPartition()
      Only leader use this interface.
      Returns:
      Integer set of all schemaengine region id
    • generateNextRegionGroupId

      public int generateNextRegionGroupId()
      Only leader use this interface.
      Returns:
      the next RegionGroupId
    • generateTConsensusGroupIdByRegionId

      public Optional<TConsensusGroupId> generateTConsensusGroupIdByRegionId(int regionId)
    • getNodePathsPartition

      public SchemaNodeManagementResp getNodePathsPartition(GetNodePathsPartitionPlan physicalPlan)
      GetNodePathsPartition.
      Parameters:
      physicalPlan - GetNodesPathsPartitionReq
      Returns:
      SchemaNodeManagementPartitionDataSet that contains only existing matched SchemaPartition and matched child paths aboveMTree
    • preDeleteDatabase

      public void preDeleteDatabase(String database, PreDeleteDatabasePlan.PreDeleteType preDeleteType)
    • isDatabasePreDeleted

      public boolean isDatabasePreDeleted(String database)
    • getSeriesPartitionSlot

      public TSeriesPartitionSlot getSeriesPartitionSlot(String devicePath)
      Get TSeriesPartitionSlot.
      Parameters:
      devicePath - Full path ending with device name
      Returns:
      SeriesPartitionSlot
    • getRegionInfoList

      public RegionInfoListResp getRegionInfoList(GetRegionInfoListPlan req)
    • isRegionGroupExists

      public boolean isRegionGroupExists(TConsensusGroupId regionGroupId)
      Check if the specified RegionGroup exists.
      Parameters:
      regionGroupId - The specified RegionGroup
    • addRegionLocation

      public TSStatus addRegionLocation(AddRegionLocationPlan req)
    • removeRegionLocation

      public TSStatus removeRegionLocation(RemoveRegionLocationPlan req)
    • getRegionId

      public GetRegionIdResp getRegionId(TGetRegionIdReq req)
    • getTimeSlotList

      public GetTimeSlotListResp getTimeSlotList(TGetTimeSlotListReq req)
    • countTimeSlotList

      public CountTimeSlotListResp countTimeSlotList(TCountTimeSlotListReq req)
    • getSeriesSlotList

      public GetSeriesSlotListResp getSeriesSlotList(TGetSeriesSlotListReq req)
    • getRegionDatabase

      public String getRegionDatabase(TConsensusGroupId regionId)
      Get database for region.
      Parameters:
      regionId - regionId
      Returns:
      database name
    • maintainRegionReplicas

      public void maintainRegionReplicas()
      Called by regionMaintainer.

      Periodically maintain the RegionReplicas to be created or deleted

    • startRegionCleaner

      public void startRegionCleaner()
    • stopRegionCleaner

      public void stopRegionCleaner()
    • filterRegionGroupThroughStatus

      public List<TRegionReplicaSet> filterRegionGroupThroughStatus(String database, RegionGroupStatus... status)
      Filter the RegionGroups in the specified Database through the RegionGroupStatus.
      Parameters:
      database - The specified Database
      status - The specified RegionGroupStatus
      Returns:
      Filtered RegionGroups with the specified RegionGroupStatus
    • getSchemaRegionIds

      public void getSchemaRegionIds(List<String> databases, Map<String,List<Integer>> schemaRegionIds)
    • getDataRegionIds

      public void getDataRegionIds(List<String> databases, Map<String,List<Integer>> dataRegionIds)
    • getRegionType

      public Optional<TConsensusGroupType> getRegionType(int regionId)
      Get the TConsensusGroupType of the given integer regionId.
      Parameters:
      regionId - The specified integer regionId
      Returns:
      Optional.of(Object tConsensusGroupType) of the given integer regionId, or Optional.empty() if the integer regionId does not match any of the regionGroups.
    • getLastDataAllotTable

      public Map<TSeriesPartitionSlot,TConsensusGroupId> getLastDataAllotTable(String database)
      Get the last DataAllotTable of the specified Database.
      Parameters:
      database - The specified Database
      Returns:
      The last DataAllotTable
    • getRegionMaintainer

      public ScheduledExecutorService getRegionMaintainer()