java.lang.Object
org.apache.iotdb.confignode.manager.load.cache.LoadCache

public class LoadCache extends Object
Maintain all kinds of heartbeat samples and statistics.
  • Constructor Details

    • LoadCache

      public LoadCache()
  • Method Details

    • initHeartbeatCache

      public void initHeartbeatCache(IManager configManager)
    • clearHeartbeatCache

      public void clearHeartbeatCache()
    • checkAndSetHeartbeatProcessing

      public boolean checkAndSetHeartbeatProcessing(int nodeId)
      Check if the specified Node is processing heartbeat. And set the processing flag to true.
      Parameters:
      nodeId - The specified NodeId.
      Returns:
      False if the previous heartbeat is completed, true otherwise.
    • createNodeHeartbeatCache

      public void createNodeHeartbeatCache(NodeType nodeType, int nodeId)
      Create a new NodeHeartbeatCache for the specified Node.
      Parameters:
      nodeType - The specified NodeType
      nodeId - The specified NodeId
    • cacheConfigNodeHeartbeatSample

      public void cacheConfigNodeHeartbeatSample(int nodeId, NodeHeartbeatSample sample)
      Cache the latest heartbeat sample of a ConfigNode.
      Parameters:
      nodeId - the id of the ConfigNode
      sample - the latest heartbeat sample
    • cacheDataNodeHeartbeatSample

      public void cacheDataNodeHeartbeatSample(int nodeId, NodeHeartbeatSample sample)
      Cache the latest heartbeat sample of a DataNode.
      Parameters:
      nodeId - the id of the DataNode
      sample - the latest heartbeat sample
    • cacheAINodeHeartbeatSample

      public void cacheAINodeHeartbeatSample(int nodeId, NodeHeartbeatSample sample)
      Cache the latest heartbeat sample of a AINode.
      Parameters:
      nodeId - the id of the AINode
      sample - the latest heartbeat sample
    • resetHeartbeatProcessing

      public void resetHeartbeatProcessing(int nodeId)
    • removeNodeCache

      public void removeNodeCache(int nodeId)
      Remove the NodeHeartbeatCache of the specified Node.
      Parameters:
      nodeId - the index of the specified Node
    • createRegionGroupHeartbeatCache

      public void createRegionGroupHeartbeatCache(String database, TConsensusGroupId regionGroupId, Set<Integer> dataNodeIds)
      Create a new RegionGroupCache and a new ConsensusGroupCache for the specified RegionGroup.
      Parameters:
      database - the Database where the RegionGroup belonged
      regionGroupId - the index of the RegionGroup
      dataNodeIds - the index of the DataNodes where the Regions resided
    • createRegionCache

      public void createRegionCache(TConsensusGroupId regionGroupId, int dataNodeId)
      Create a new RegionCache for the specified Region in the specified RegionGroup.
      Parameters:
      regionGroupId - the index of the RegionGroup
      dataNodeId - the index of the DataNode where the Region resides
    • cacheRegionHeartbeatSample

      public void cacheRegionHeartbeatSample(TConsensusGroupId regionGroupId, int nodeId, RegionHeartbeatSample sample, boolean overwrite)
      Cache the latest heartbeat sample of a RegionGroup.
      Parameters:
      regionGroupId - the id of the RegionGroup
      nodeId - the id of the DataNode where specified Region resides
      sample - the latest heartbeat sample
    • getRegionCacheLastSampleStatus

      public RegionStatus getRegionCacheLastSampleStatus(TConsensusGroupId regionGroupId, int nodeId)
    • removeRegionCache

      public void removeRegionCache(TConsensusGroupId regionGroupId, int dataNodeId)
      Remove the cache of the specified Region in the specified RegionGroup.
      Parameters:
      regionGroupId - the specified RegionGroup
      dataNodeId - the specified DataNode
    • cacheConsensusSample

      public void cacheConsensusSample(TConsensusGroupId regionGroupId, ConsensusGroupHeartbeatSample sample)
      Cache the latest leader of a RegionGroup.
      Parameters:
      regionGroupId - the id of the RegionGroup
      sample - the latest heartbeat sample
    • updateNodeStatistics

      public void updateNodeStatistics(boolean forceUpdate)
      Update the NodeStatistics of all Nodes.
    • updateRegionGroupStatistics

      public void updateRegionGroupStatistics()
      Update the RegionGroupStatistics of all RegionGroups.
    • updateConsensusGroupStatistics

      public void updateConsensusGroupStatistics()
      Update the ConsensusGroupStatistics of all RegionGroups.
    • getCurrentNodeStatisticsMap

      public Map<Integer,NodeStatistics> getCurrentNodeStatisticsMap()
      Get the NodeStatistics of all Nodes.
      Returns:
      a map of NodeStatistics
    • getCurrentDataNodeStatisticsMap

      public Map<Integer,NodeStatistics> getCurrentDataNodeStatisticsMap()
      Get the NodeStatistics of all DataNodes.
      Returns:
      a map of all DataNodes' NodeStatistics
    • getCurrentDatabaseRegionGroupMap

      public Map<String,List<TConsensusGroupId>> getCurrentDatabaseRegionGroupMap(TConsensusGroupType type)
      Get a map of cached RegionGroups of all Databases.
      Parameters:
      type - SchemaRegion or DataRegion
      Returns:
      Map<Database, List>
    • getCurrentRegionLocationMap

      public Map<TConsensusGroupId,Set<Integer>> getCurrentRegionLocationMap(TConsensusGroupType type)
      Get a map of cached RegionGroups
      Parameters:
      type - SchemaRegion or DataRegion
      Returns:
      Map<RegionGroupId, Set>
    • getCurrentRegionGroupStatisticsMap

      public Map<TConsensusGroupId,RegionGroupStatistics> getCurrentRegionGroupStatisticsMap()
      Get the RegionGroupStatistics of all RegionGroups.
      Returns:
      a map of RegionGroupStatistics
    • getCurrentRegionStatisticsMap

      public Map<TConsensusGroupId,Map<Integer,RegionStatistics>> getCurrentRegionStatisticsMap(TConsensusGroupType type)
      Get the RegionStatistics of all Regions.
      Parameters:
      type - DataRegion or SchemaRegion
      Returns:
      a map of RegionStatistics
    • getCurrentConsensusGroupStatisticsMap

      public Map<TConsensusGroupId,ConsensusGroupStatistics> getCurrentConsensusGroupStatisticsMap()
      Get the ConsensusGroupStatistics of all RegionGroups.
      Returns:
      a map of ConsensusGroupStatistics
    • 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.
    • 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
    • removeRegionGroupCache

      public void removeRegionGroupCache(TConsensusGroupId consensusGroupId)
      Remove the specified RegionGroup's cache.
    • getRegionLeaderMap

      public Map<TConsensusGroupId,Integer> getRegionLeaderMap()
      Safely get the latest RegionLeaderMap.
      Returns:
      Map<RegionGroupId, leaderId>, leaderId will be -1 if the RegionGroup has no leader yet.
    • getRegionLeaderMap

      public Map<TConsensusGroupId,Integer> getRegionLeaderMap(TConsensusGroupType consensusGroupType)
      Safely get the latest RegionLeaderMap.
      Parameters:
      consensusGroupType - DataRegion or SchemaRegion
      Returns:
      Map<RegionGroupId, leaderId>, leaderId will be -1 if the RegionGroup has no leader yet.
    • waitForLeaderElection

      public void waitForLeaderElection(List<TConsensusGroupId> regionGroupIds)
      Wait for the specified RegionGroups to finish leader election.
      Parameters:
      regionGroupIds - Specified RegionGroupIds
    • updateConfirmedConfigNodeEndPoints

      public void updateConfirmedConfigNodeEndPoints(int dataNodeId, Set<TEndPoint> configNodeEndPoints)
    • getConfirmedConfigNodeEndPoints

      public Set<TEndPoint> getConfirmedConfigNodeEndPoints(int dataNodeId)
    • updateRegionSizeMap

      public void updateRegionSizeMap(int dataNodeId, Map<Integer,Long> regionSizeMap)
    • getRegionSizeMap

      public Map<Integer,Map<Integer,Long>> getRegionSizeMap()