Class LoadManager

java.lang.Object
org.apache.iotdb.confignode.manager.load.LoadManager

public class LoadManager extends Object
The LoadManager at ConfigNodeGroup-Leader is active. It proactively implements the cluster dynamic load balancing policy and passively accepts the PartitionTable expansion request.
  • Field Details

    • configManager

      protected final IManager configManager
    • loadCache

      protected final LoadCache loadCache
      Cluster load services.
    • heartbeatService

      protected HeartbeatService heartbeatService
  • Constructor Details

    • LoadManager

      public LoadManager(IManager configManager)
  • Method Details

    • setHeartbeatService

      protected void setHeartbeatService(IManager configManager, LoadCache loadCache)
    • allocateRegionGroups

      public CreateRegionGroupsPlan allocateRegionGroups(Map<String,Integer> allotmentMap, TConsensusGroupType consensusGroupType) throws NotEnoughDataNodeException, DatabaseNotExistsException
      Generate an optimal CreateRegionGroupsPlan.
      Parameters:
      allotmentMap - Map<DatabaseName, Region allotment>
      consensusGroupType - TConsensusGroupType of RegionGroup to be allocated
      Returns:
      CreateRegionGroupsPlan
      Throws:
      NotEnoughDataNodeException - If there are not enough DataNodes
      DatabaseNotExistsException - If some specific StorageGroups don't exist
    • allocateSchemaPartition

      public Map<String,SchemaPartitionTable> allocateSchemaPartition(Map<String,List<TSeriesPartitionSlot>> unassignedSchemaPartitionSlotsMap) throws NoAvailableRegionGroupException
      Allocate SchemaPartitions.
      Parameters:
      unassignedSchemaPartitionSlotsMap - SchemaPartitionSlots that should be assigned
      Returns:
      Map<DatabaseName, SchemaPartitionTable>, the allocating result
      Throws:
      NoAvailableRegionGroupException
    • allocateDataPartition

      Allocate DataPartitions.
      Parameters:
      unassignedDataPartitionSlotsMap - DataPartitionSlots that should be assigned
      Returns:
      Map<DatabaseName, DataPartitionTable>, the allocating result
      Throws:
      DatabaseNotExistsException - If some specific Databases don't exist
      NoAvailableRegionGroupException - If there are no available RegionGroups
    • reBalanceDataPartitionPolicy

      public void reBalanceDataPartitionPolicy(String database)
      Re-balance the DataPartitionPolicyTable.
      Parameters:
      database - Database name
    • startLoadServices

      public void startLoadServices()
    • stopLoadServices

      public void stopLoadServices()
    • clearDataPartitionPolicyTable

      public void clearDataPartitionPolicyTable(String database)
    • getNodeStatus

      public NodeStatus getNodeStatus(int nodeId)
      Safely get NodeStatus by NodeId.
      Parameters:
      nodeId - The specified NodeId
      Returns:
      NodeStatus of the specified Node. Unknown if cache doesn't exist.
    • getNodeStatusWithReason

      public String getNodeStatusWithReason(int nodeId)
      Safely get the specified Node's current status with reason.
      Parameters:
      nodeId - The specified NodeId
      Returns:
      The specified Node's current status if the nodeCache contains it, Unknown otherwise
    • getNodeStatusWithReason

      public Map<Integer,String> getNodeStatusWithReason()
      Get all Node's current status with reason.
      Returns:
      Map<NodeId, NodeStatus with reason>
    • filterConfigNodeThroughStatus

      public List<Integer> filterConfigNodeThroughStatus(NodeStatus... status)
      Filter ConfigNodes through the specified NodeStatus.
      Parameters:
      status - The specified NodeStatus
      Returns:
      Filtered ConfigNodes with the specified NodeStatus
    • filterDataNodeThroughStatus

      public List<Integer> filterDataNodeThroughStatus(NodeStatus... status)
      Filter DataNodes through the specified NodeStatus.
      Parameters:
      status - The specified NodeStatus
      Returns:
      Filtered DataNodes with the specified NodeStatus
    • getFreeDiskSpace

      public double getFreeDiskSpace(int dataNodeId)
      Get the free disk space of the specified DataNode.
      Parameters:
      dataNodeId - The index of the specified DataNode
      Returns:
      The free disk space that sample through heartbeat, 0 if no heartbeat received
    • getLowestLoadDataNode

      public int getLowestLoadDataNode()
      Get the lowest loadScore DataNode.
      Returns:
      The index of the lowest loadScore DataNode. -1 if no DataNode heartbeat received.
    • getLowestLoadDataNode

      public int getLowestLoadDataNode(List<Integer> dataNodeIds)
      Get the lowest loadScore DataNode from the specified DataNodes.
      Parameters:
      dataNodeIds - The specified DataNodes
      Returns:
      The index of the lowest loadScore DataNode. -1 if no DataNode heartbeat received.
    • forceUpdateNodeCache

      public void forceUpdateNodeCache(NodeType nodeType, int nodeId, NodeHeartbeatSample heartbeatSample)
      Force update the specified Node's cache, update statistics and broadcast statistics change event if necessary.
      Parameters:
      nodeType - Specified NodeType
      nodeId - Specified NodeId
      heartbeatSample - Specified NodeHeartbeatSample
    • removeNodeCache

      public void removeNodeCache(int nodeId)
      Remove the NodeHeartbeatCache of the specified Node, update statistics and broadcast statistics change event if necessary.
      Parameters:
      nodeId - the index of the specified Node
    • getRegionStatus

      public RegionStatus getRegionStatus(TConsensusGroupId consensusGroupId, int dataNodeId)
      Safely get RegionStatus.
      Parameters:
      consensusGroupId - Specified RegionGroupId
      dataNodeId - Specified RegionReplicaId
      Returns:
      Corresponding RegionStatus if cache exists, Unknown otherwise
    • getRegionGroupStatus

      public RegionGroupStatus getRegionGroupStatus(TConsensusGroupId consensusGroupId)
      Safely get RegionGroupStatus.
      Parameters:
      consensusGroupId - Specified RegionGroupId
      Returns:
      Corresponding RegionGroupStatus if cache exists, Disabled otherwise
    • getRegionGroupStatus

      public Map<TConsensusGroupId,RegionGroupStatus> getRegionGroupStatus(List<TConsensusGroupId> consensusGroupIds)
      Safely get RegionGroupStatus.
      Parameters:
      consensusGroupIds - Specified RegionGroupIds
      Returns:
      Corresponding RegionGroupStatus if cache exists, Disabled otherwise
    • filterRegionGroupThroughStatus

      public List<TConsensusGroupId> filterRegionGroupThroughStatus(RegionGroupStatus... status)
      Filter the RegionGroups through the RegionGroupStatus.
      Parameters:
      status - The specified RegionGroupStatus
      Returns:
      Filtered RegionGroups with the specified RegionGroupStatus
    • countRegionWithSpecifiedStatus

      public int countRegionWithSpecifiedStatus(TConsensusGroupType type, RegionStatus... status)
      Count the number of cluster Regions with specified RegionStatus.
      Parameters:
      type - The specified RegionGroupType
      status - The specified statues
      Returns:
      The number of cluster Regions with specified RegionStatus
    • forceUpdateRegionGroupCache

      public void forceUpdateRegionGroupCache(Map<TConsensusGroupId,Map<Integer,RegionHeartbeatSample>> heartbeatSampleMap)
      Force update the specified RegionGroups' cache, update statistics and broadcast statistics change event if necessary.
      Parameters:
      heartbeatSampleMap - Map<RegionGroupId, Map<DataNodeId, RegionHeartbeatSample>>
    • forceUpdateRegionCache

      public void forceUpdateRegionCache(TConsensusGroupId regionGroupId, int dataNodeId, RegionStatus regionStatus)
      Force update the specified Region's cache, update statistics and broadcast statistics change event if necessary.
      Parameters:
      regionGroupId - The specified RegionGroup
      dataNodeId - The DataNodeId where the specified Region is located
      regionStatus - The specified RegionStatus
    • removeRegionCache

      public void removeRegionCache(TConsensusGroupId regionGroupId, int dataNodeId)
      Remove the cache of the specified Region in the specified RegionGroup, update statistics and broadcast statistics change event if necessary.
      Parameters:
      regionGroupId - the specified RegionGroup
      dataNodeId - the specified DataNode
    • removeRegionGroupRelatedCache

      public void removeRegionGroupRelatedCache(TConsensusGroupId consensusGroupId)
      Remove the specified RegionGroup's related cache, update statistics and broadcast statistics change event if necessary.
      Parameters:
      consensusGroupId - The specified RegionGroup
    • getRegionLeaderMap

      public Map<TConsensusGroupId,Integer> getRegionLeaderMap()
      Get the latest RegionLeaderMap.
      Returns:
      Map<RegionGroupId, leaderId>
    • getRegionPriorityMap

      public Map<TConsensusGroupId,TRegionReplicaSet> getRegionPriorityMap()
      Get the latest RegionPriorityMap.
      Returns:
      Map<RegionGroupId, RegionPriority>.
    • getRegionGroupLeaderCount

      public int getRegionGroupLeaderCount(int dataNodeId, TConsensusGroupType type)
      Get the number of RegionGroup-leaders in the specified DataNode.
      Parameters:
      dataNodeId - The specified DataNode
      type - SchemaRegion or DataRegion
      Returns:
      The number of RegionGroup-leaders
    • waitForRegionGroupReady

      public void waitForRegionGroupReady(List<TConsensusGroupId> regionGroupIds)
      Wait for the specified RegionGroups to finish leader election and priority update.
      Parameters:
      regionGroupIds - Specified RegionGroupIds
    • forceUpdateConsensusGroupCache

      public void forceUpdateConsensusGroupCache(Map<TConsensusGroupId,ConsensusGroupHeartbeatSample> heartbeatSampleMap)
      Force update the specified ConsensusGroups' cache.
      Parameters:
      heartbeatSampleMap - Map<RegionGroupId, ConsensusGroupHeartbeatSample>
    • getLoadCache

      public LoadCache getLoadCache()
    • getRouteBalancer

      public RouteBalancer getRouteBalancer()
    • getEventService

      public EventService getEventService()