Class RegionMaintainHandler

java.lang.Object
org.apache.iotdb.confignode.procedure.env.RegionMaintainHandler

public class RegionMaintainHandler extends Object
  • Constructor Details

    • RegionMaintainHandler

      public RegionMaintainHandler(ConfigManager configManager)
  • Method Details

    • getIdWithRpcEndpoint

      public static String getIdWithRpcEndpoint(TDataNodeLocation location)
    • simplifiedLocation

      public static String simplifiedLocation(TDataNodeLocation dataNodeLocation)
    • findDestDataNode

      public TDataNodeLocation findDestDataNode(TConsensusGroupId regionId)
      Find dest data node.
      Parameters:
      regionId - region id
      Returns:
      dest data node location
    • createNewRegionPeer

      public TSStatus createNewRegionPeer(TConsensusGroupId regionId, TDataNodeLocation destDataNode)
      Create a new RegionReplica and build the ConsensusGroup on the destined DataNode

      createNewRegionPeer should be invoked on a DataNode that doesn't contain any peer of the specific ConsensusGroup, in order to avoid there exists one DataNode who has more than one RegionReplica.

      Parameters:
      regionId - The given ConsensusGroup
      destDataNode - The destined DataNode where the new peer will be created
      Returns:
      status
    • submitAddRegionPeerTask

      public TSStatus submitAddRegionPeerTask(long procedureId, TDataNodeLocation destDataNode, TConsensusGroupId regionId, TDataNodeLocation coordinator)
      Order the specific ConsensusGroup to add peer for the new RegionReplica.

      The add peer interface could be invoked at any DataNode who contains one of the RegionReplica of the specified ConsensusGroup except the new one

      Parameters:
      destDataNode - The DataNodeLocation where the new RegionReplica is created
      regionId - region id
      Returns:
      TSStatus
    • submitRemoveRegionPeerTask

      public TSStatus submitRemoveRegionPeerTask(long procedureId, TDataNodeLocation originalDataNode, TConsensusGroupId regionId, TDataNodeLocation coordinator)
      Order the specific ConsensusGroup to remove peer for the old RegionReplica.

      The remove peer interface could be invoked at any DataNode who contains one of the RegionReplica of the specified ConsensusGroup except the origin one

      Parameters:
      originalDataNode - The DataNodeLocation who contains the original RegionReplica
      regionId - region id
      Returns:
      TSStatus
    • submitDeleteOldRegionPeerTask

      public TSStatus submitDeleteOldRegionPeerTask(long procedureId, TDataNodeLocation originalDataNode, TConsensusGroupId regionId)
      Delete a Region peer in the given ConsensusGroup and all of its data on the specified DataNode

      If the originalDataNode is down, we should delete local data and do other cleanup works manually.

      Parameters:
      originalDataNode - The DataNodeLocation who contains the original RegionReplica
      regionId - region id
      Returns:
      TSStatus
    • resetPeerList

      public Map<Integer,TSStatus> resetPeerList(TConsensusGroupId regionId, List<TDataNodeLocation> correctDataNodeLocations, Map<Integer,TDataNodeLocation> dataNodeLocationMap)
    • waitTaskFinish

      public TRegionMigrateResult waitTaskFinish(long taskId, TDataNodeLocation dataNodeLocation)
    • addRegionLocation

      public void addRegionLocation(TConsensusGroupId regionId, TDataNodeLocation newLocation)
    • forceUpdateRegionCache

      public void forceUpdateRegionCache(TConsensusGroupId regionId, TDataNodeLocation newLocation, RegionStatus regionStatus)
    • removeRegionLocation

      public void removeRegionLocation(TConsensusGroupId regionId, TDataNodeLocation deprecatedLocation)
    • findRegionLocations

      public List<TDataNodeLocation> findRegionLocations(TConsensusGroupId regionId)
      Find all DataNodes which contains the given regionId
      Parameters:
      regionId - region id
      Returns:
      DataNode locations
    • getRegionReplicaSet

      public Optional<TRegionReplicaSet> getRegionReplicaSet(TConsensusGroupId regionId)
    • getRegionReplicaSetString

      public String getRegionReplicaSetString(TConsensusGroupId regionId)
    • isSucceed

      public boolean isSucceed(TSStatus status)
    • isFailed

      public boolean isFailed(TSStatus status)
    • transferRegionLeader

      public void transferRegionLeader(TConsensusGroupId regionId, TDataNodeLocation originalDataNode, TDataNodeLocation coodinator) throws ProcedureException, InterruptedException
      Change the leader of given Region.

      For IOT_CONSENSUS, using `changeLeaderForIoTConsensus` method to change the regionLeaderMap maintained in ConfigNode.

      For RATIS_CONSENSUS, invoking `changeRegionLeader` DataNode RPC method to change the leader.

      Parameters:
      regionId - The region to be migrated
      originalDataNode - The DataNode where the region locates
      Throws:
      ProcedureException
      InterruptedException
    • filterDataNodeWithOtherRegionReplica

      public Optional<TDataNodeLocation> filterDataNodeWithOtherRegionReplica(TConsensusGroupId regionId, TDataNodeLocation filterLocation)
      Filter a DataNode who contains other RegionReplica excepts the given one.

      Choose the RUNNING status datanode firstly, if no RUNNING status datanode match the condition, then we choose the REMOVING status datanode.

      `addRegionPeer`, `removeRegionPeer` and `changeRegionLeader` invoke this method.

      Parameters:
      regionId - The specific RegionId
      filterLocation - The DataNodeLocation that should be filtered
      Returns:
      A DataNodeLocation that contains other RegionReplica and different from the filterLocation
    • filterDataNodeWithOtherRegionReplica

      public Optional<TDataNodeLocation> filterDataNodeWithOtherRegionReplica(TConsensusGroupId regionId, List<TDataNodeLocation> filterLocations)
    • filterDataNodeWithOtherRegionReplica

      public Optional<TDataNodeLocation> filterDataNodeWithOtherRegionReplica(TConsensusGroupId regionId, TDataNodeLocation filterLocation, NodeStatus... allowingStatus)
    • filterDataNodeWithOtherRegionReplica

      public Optional<TDataNodeLocation> filterDataNodeWithOtherRegionReplica(TConsensusGroupId regionId, List<TDataNodeLocation> excludeLocations, NodeStatus... allowingStatus)