Class LoadManager
java.lang.Object
org.apache.iotdb.confignode.manager.load.LoadManager
The
LoadManager at ConfigNodeGroup-Leader is active. It proactively implements the
cluster dynamic load balancing policy and passively accepts the PartitionTable expansion request.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final IManagerprotected HeartbeatServiceprotected final LoadCacheCluster load services. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionallocateDataPartition(Map<String, Map<TSeriesPartitionSlot, TTimeSlotList>> unassignedDataPartitionSlotsMap) Allocate DataPartitions.allocateRegionGroups(Map<String, Integer> allotmentMap, TConsensusGroupType consensusGroupType) Generate an optimal CreateRegionGroupsPlan.allocateSchemaPartition(Map<String, List<TSeriesPartitionSlot>> unassignedSchemaPartitionSlotsMap) Allocate SchemaPartitions.voidclearDataPartitionPolicyTable(String database) intcountRegionWithSpecifiedStatus(TConsensusGroupType type, RegionStatus... status) Count the number of cluster Regions with specified RegionStatus.filterConfigNodeThroughStatus(NodeStatus... status) Filter ConfigNodes through the specified NodeStatus.filterDataNodeThroughStatus(NodeStatus... status) Filter DataNodes through the specified NodeStatus.filterRegionGroupThroughStatus(RegionGroupStatus... status) Filter the RegionGroups through the RegionGroupStatus.voidforceUpdateConsensusGroupCache(Map<TConsensusGroupId, ConsensusGroupHeartbeatSample> heartbeatSampleMap) Force update the specified ConsensusGroups' cache.voidforceUpdateNodeCache(NodeType nodeType, int nodeId, NodeHeartbeatSample heartbeatSample) Force update the specified Node's cache, update statistics and broadcast statistics change event if necessary.voidforceUpdateRegionCache(TConsensusGroupId regionGroupId, int dataNodeId, RegionStatus regionStatus) Force update the specified Region's cache, update statistics and broadcast statistics change event if necessary.voidforceUpdateRegionGroupCache(Map<TConsensusGroupId, Map<Integer, RegionHeartbeatSample>> heartbeatSampleMap) Force update the specified RegionGroups' cache, update statistics and broadcast statistics change event if necessary.doublegetFreeDiskSpace(int dataNodeId) Get the free disk space of the specified DataNode.intGet the lowest loadScore DataNode.intgetLowestLoadDataNode(List<Integer> dataNodeIds) Get the lowest loadScore DataNode from the specified DataNodes.getNodeStatus(int nodeId) Safely get NodeStatus by NodeId.Get all Node's current status with reason.getNodeStatusWithReason(int nodeId) Safely get the specified Node's current status with reason.intgetRegionGroupLeaderCount(int dataNodeId, TConsensusGroupType type) Get the number of RegionGroup-leaders in the specified DataNode.getRegionGroupStatus(List<TConsensusGroupId> consensusGroupIds) Safely get RegionGroupStatus.getRegionGroupStatus(TConsensusGroupId consensusGroupId) Safely get RegionGroupStatus.Get the latest RegionLeaderMap.Get the latest RegionPriorityMap.getRegionStatus(TConsensusGroupId consensusGroupId, int dataNodeId) Safely get RegionStatus.voidreBalanceDataPartitionPolicy(String database) Re-balance the DataPartitionPolicyTable.voidremoveNodeCache(int nodeId) Remove the NodeHeartbeatCache of the specified Node, update statistics and broadcast statistics change event if necessary.voidremoveRegionCache(TConsensusGroupId regionGroupId, int dataNodeId) Remove the cache of the specified Region in the specified RegionGroup, update statistics and broadcast statistics change event if necessary.voidremoveRegionGroupRelatedCache(TConsensusGroupId consensusGroupId) Remove the specified RegionGroup's related cache, update statistics and broadcast statistics change event if necessary.protected voidsetHeartbeatService(IManager configManager, LoadCache loadCache) voidvoidvoidwaitForRegionGroupReady(List<TConsensusGroupId> regionGroupIds) Wait for the specified RegionGroups to finish leader election and priority update.
-
Field Details
-
configManager
-
loadCache
Cluster load services. -
heartbeatService
-
-
Constructor Details
-
LoadManager
-
-
Method Details
-
setHeartbeatService
-
allocateRegionGroups
public CreateRegionGroupsPlan allocateRegionGroups(Map<String, Integer> allotmentMap, TConsensusGroupType consensusGroupType) throws NotEnoughDataNodeException, DatabaseNotExistsExceptionGenerate 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 DataNodesDatabaseNotExistsException- If some specific StorageGroups don't exist
-
allocateSchemaPartition
public Map<String,SchemaPartitionTable> allocateSchemaPartition(Map<String, List<TSeriesPartitionSlot>> unassignedSchemaPartitionSlotsMap) throws NoAvailableRegionGroupExceptionAllocate SchemaPartitions.- Parameters:
unassignedSchemaPartitionSlotsMap- SchemaPartitionSlots that should be assigned- Returns:
- Map<DatabaseName, SchemaPartitionTable>, the allocating result
- Throws:
NoAvailableRegionGroupException
-
allocateDataPartition
public Map<String,DataPartitionTable> allocateDataPartition(Map<String, Map<TSeriesPartitionSlot, throws DatabaseNotExistsException, NoAvailableRegionGroupExceptionTTimeSlotList>> unassignedDataPartitionSlotsMap) Allocate DataPartitions.- Parameters:
unassignedDataPartitionSlotsMap- DataPartitionSlots that should be assigned- Returns:
- Map<DatabaseName, DataPartitionTable>, the allocating result
- Throws:
DatabaseNotExistsException- If some specific Databases don't existNoAvailableRegionGroupException- If there are no available RegionGroups
-
reBalanceDataPartitionPolicy
Re-balance the DataPartitionPolicyTable.- Parameters:
database- Database name
-
startLoadServices
public void startLoadServices() -
stopLoadServices
public void stopLoadServices() -
clearDataPartitionPolicyTable
-
getNodeStatus
Safely get NodeStatus by NodeId.- Parameters:
nodeId- The specified NodeId- Returns:
- NodeStatus of the specified Node. Unknown if cache doesn't exist.
-
getNodeStatusWithReason
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
Get all Node's current status with reason.- Returns:
- Map<NodeId, NodeStatus with reason>
-
filterConfigNodeThroughStatus
Filter ConfigNodes through the specified NodeStatus.- Parameters:
status- The specified NodeStatus- Returns:
- Filtered ConfigNodes with the specified NodeStatus
-
filterDataNodeThroughStatus
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
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 NodeTypenodeId- Specified NodeIdheartbeatSample- 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
Safely get RegionStatus.- Parameters:
consensusGroupId- Specified RegionGroupIddataNodeId- Specified RegionReplicaId- Returns:
- Corresponding RegionStatus if cache exists, Unknown otherwise
-
getRegionGroupStatus
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
Filter the RegionGroups through the RegionGroupStatus.- Parameters:
status- The specified RegionGroupStatus- Returns:
- Filtered RegionGroups with the specified RegionGroupStatus
-
countRegionWithSpecifiedStatus
Count the number of cluster Regions with specified RegionStatus.- Parameters:
type- The specified RegionGroupTypestatus- 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 RegionGroupdataNodeId- The DataNodeId where the specified Region is locatedregionStatus- The specified RegionStatus
-
removeRegionCache
Remove the cache of the specified Region in the specified RegionGroup, update statistics and broadcast statistics change event if necessary.- Parameters:
regionGroupId- the specified RegionGroupdataNodeId- the specified DataNode
-
removeRegionGroupRelatedCache
Remove the specified RegionGroup's related cache, update statistics and broadcast statistics change event if necessary.- Parameters:
consensusGroupId- The specified RegionGroup
-
getRegionLeaderMap
Get the latest RegionLeaderMap.- Returns:
- Map<RegionGroupId, leaderId>
-
getRegionPriorityMap
Get the latest RegionPriorityMap.- Returns:
- Map<RegionGroupId, RegionPriority>.
-
getRegionGroupLeaderCount
Get the number of RegionGroup-leaders in the specified DataNode.- Parameters:
dataNodeId- The specified DataNodetype- SchemaRegion or DataRegion- Returns:
- The number of RegionGroup-leaders
-
waitForRegionGroupReady
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
-
getRouteBalancer
-
getEventService
-