java.lang.Object
org.apache.iotdb.confignode.persistence.partition.PartitionInfo
All Implemented Interfaces:
SnapshotProcessor

public class PartitionInfo extends Object implements SnapshotProcessor
The PartitionInfo stores cluster PartitionTable.

The PartitionTable includes:

1. regionMap: location of Region member

2. schemaPartition: location of schemaEngine

3. dataPartition: location of data

  • Constructor Details

    • PartitionInfo

      public PartitionInfo()
  • Method Details

    • generateNextRegionGroupId

      public int generateNextRegionGroupId()
    • updateDataNode

      public TSStatus updateDataNode(UpdateDataNodePlan updateDataNodePlan)
      Thread-safely update DataNodeLocation in RegionGroup.
      Parameters:
      updateDataNodePlan - UpdateDataNodePlan
      Returns:
      TSStatusCode.SUCCESS_STATUS if the DataNodeLocations are updated successfully.
    • createDatabase

      public TSStatus createDatabase(DatabaseSchemaPlan plan)
      Thread-safely create new DatabasePartitionTable.
      Parameters:
      plan - DatabaseSchemaPlan
      Returns:
      TSStatusCode.SUCCESS_STATUS if the new DatabasePartitionTable is created successfully.
    • createRegionGroups

      public TSStatus createRegionGroups(CreateRegionGroupsPlan plan)
      Thread-safely cache allocation result of new RegionGroups.
      Parameters:
      plan - CreateRegionGroupsPlan
      Returns:
      TSStatusCode.SUCCESS_STATUS
    • offerRegionMaintainTasks

      public TSStatus offerRegionMaintainTasks(OfferRegionMaintainTasksPlan offerRegionMaintainTasksPlan)
      Offer a batch of RegionMaintainTasks for the RegionMaintainer.
      Returns:
      TSStatusCode.SUCCESS_STATUS
    • pollRegionMaintainTask

      public TSStatus pollRegionMaintainTask()
      Poll the head of RegionMaintainTasks from the regionMaintainTaskList after it's executed successfully.
      Returns:
      TSStatusCode.SUCCESS_STATUS
    • pollSpecificRegionMaintainTask

      public TSStatus pollSpecificRegionMaintainTask(PollSpecificRegionMaintainTaskPlan plan)
      Poll the head of RegionMaintainTasks of target regions from regionMaintainTaskList after they are executed successfully. Tasks of each region group are treated as single independent queue.
      Parameters:
      plan - provides target region ids
      Returns:
      TSStatusCode.SUCCESS_STATUS
    • getRegionMaintainEntryList

      public List<RegionMaintainTask> getRegionMaintainEntryList()
      Get a deep copy of RegionCleanList for RegionCleaner to maintain cluster RegionReplicas.
      Returns:
      A deep copy of RegionCleanList
    • preDeleteDatabase

      public TSStatus preDeleteDatabase(PreDeleteDatabasePlan preDeleteDatabasePlan)
      Thread-safely pre-delete the specific database.
      Parameters:
      preDeleteDatabasePlan - PreDeleteStorageGroupPlan
      Returns:
      TSStatusCode.SUCCESS_STATUS
    • isDatabasePreDeleted

      public boolean isDatabasePreDeleted(String database)
    • deleteDatabase

      public void deleteDatabase(DeleteDatabasePlan plan)
      Thread-safely delete database.
      Parameters:
      plan - DeleteDatabasePlan
    • getSchemaPartition

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

      public DataSet getDataPartition(GetDataPartitionPlan plan)
      Thread-safely get DataPartition.
      Parameters:
      plan - DataPartitionPlan with partitionSlotsMap
      Returns:
      DataPartitionDataSet that contains only existing DataPartition
    • getSuccessorDataPartition

      public TConsensusGroupId getSuccessorDataPartition(String database, TSeriesPartitionSlot seriesPartitionSlot, TTimePartitionSlot timePartitionSlot)
      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)
      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
    • isDatabaseExisted

      public boolean isDatabaseExisted(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
    • createSchemaPartition

      public TSStatus createSchemaPartition(CreateSchemaPartitionPlan plan)
      Create SchemaPartition.
      Parameters:
      plan - CreateSchemaPartitionPlan with SchemaPartition assigned result
      Returns:
      TSStatusCode.SUCCESS_STATUS
    • createDataPartition

      public TSStatus createDataPartition(CreateDataPartitionPlan plan)
      Create DataPartition.
      Parameters:
      plan - CreateDataPartitionPlan with DataPartition assigned result
      Returns:
      TSStatusCode.SUCCESS_STATUS
    • autoCleanPartitionTable

      public TSStatus autoCleanPartitionTable(AutoCleanPartitionTablePlan plan)
      Remove PartitionTable where the TimeSlot is expired.
      Parameters:
      plan - Including TTL and current TimeSlot
    • getSchemaNodeManagementPartition

      public DataSet getSchemaNodeManagementPartition(List<String> matchedDatabases)
      Get SchemaNodeManagementPartition through matched Database.
    • getRegionInfoList

      public DataSet getRegionInfoList(GetRegionInfoListPlan regionsInfoPlan)
      Get Region information.
    • isRegionGroupExisted

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

      public TSStatus updateRegionLocation(UpdateRegionLocationPlan req)
    • addRegionLocation

      public TSStatus addRegionLocation(AddRegionLocationPlan req)
      The region has expanded to a new DataNode, now update the databasePartitionTable.
    • removeRegionLocation

      public TSStatus removeRegionLocation(RemoveRegionLocationPlan req)
      The region is no longer located on a DataNode, now update the databasePartitionTable.
    • getRegionDatabase

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

      public Map<String,List<TSeriesPartitionSlot>> filterUnassignedSchemaPartitionSlots(Map<String,List<TSeriesPartitionSlot>> partitionSlotsMap)
      Only Leader use this interface. Filter unassigned SchemaPartitionSlots.
      Parameters:
      partitionSlotsMap - Map<database, List>
      Returns:
      Map<database, List>, SchemaPartitionSlots that is not assigned in partitionSlotsMap
    • filterUnassignedDataPartitionSlots

      public Map<String,Map<TSeriesPartitionSlot,TTimeSlotList>> filterUnassignedDataPartitionSlots(Map<String,Map<TSeriesPartitionSlot,TTimeSlotList>> partitionSlotsMap)
      Only Leader use this interface. Filter unassigned SchemaPartitionSlots
      Parameters:
      partitionSlotsMap - Map<database, Map<TSeriesPartitionSlot, TTimeSlotList>>
      Returns:
      Map<database, Map<TSeriesPartitionSlot, TTimeSlotList>>, DataPartitionSlots that is not assigned in partitionSlotsMap
    • 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
    • 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, int clusterNodeCount)
      Only leader use this interface.

      Count the scatter width of the specified DataNode

      Parameters:
      dataNodeId - The specified DataNode
      type - SchemaRegion or DataRegion
      clusterNodeCount - The number of registeredNodes
      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 specific database
      Throws:
      DatabaseNotExistsException - When the specific 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
    • 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
    • getDatabaseRelatedDataNodes

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

      public List<org.apache.tsfile.utils.Pair<Long,TConsensusGroupId>> getRegionGroupSlotsCounter(String database, TConsensusGroupType type)
      Only leader use this interface.
      Parameters:
      database - DatabaseName
      type - SchemaRegion or DataRegion
      Returns:
      The database's Running or Available Regions that sorted by the number of allocated slots
    • getAllSchemaPartition

      public Set<Integer> getAllSchemaPartition()
      Only leader use this interface.
      Returns:
      Integer set of all schemaEngine region id
    • 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
    • processTakeSnapshot

      public boolean processTakeSnapshot(File snapshotDir) throws org.apache.thrift.TException, IOException
      Specified by:
      processTakeSnapshot in interface SnapshotProcessor
      Throws:
      org.apache.thrift.TException
      IOException
    • processLoadSnapshot

      public void processLoadSnapshot(File snapshotDir) throws org.apache.thrift.TException, IOException
      Specified by:
      processLoadSnapshot in interface SnapshotProcessor
      Throws:
      org.apache.thrift.TException
      IOException
    • getRegionId

      public DataSet getRegionId(GetRegionIdPlan plan)
      Get the RegionId of the specific Database or seriesSlotId(device).
      Parameters:
      plan - GetRegionIdPlan with the specific Database ,seriesSlotId(device) , timeSlotId.
      Returns:
      GetRegionIdResp with TSStatus and List<TConsensusGroupId >.
    • getTimeSlotList

      public DataSet getTimeSlotList(GetTimeSlotListPlan plan)
      Get the timePartition of the specific Database or seriesSlotId(device) or regionId.
      Parameters:
      plan - GetRegionIdPlan with the specific Database ,seriesSlotId(device) , regionId.
      Returns:
      GetRegionIdResp with STATUS and List<TTimePartitionSlot>.
    • countTimeSlotList

      public DataSet countTimeSlotList(CountTimeSlotListPlan plan)
    • getSeriesSlotList

      public DataSet getSeriesSlotList(GetSeriesSlotListPlan plan)
    • 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)
    • clear

      public void clear()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object