You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ta...@apache.org on 2023/08/10 12:38:24 UTC
[iotdb] branch enhance_loadservice created (now 39dd255c369)
This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a change to branch enhance_loadservice
in repository https://gitbox.apache.org/repos/asf/iotdb.git
at 39dd255c369 enhance
This branch includes the following new commits:
new 39dd255c369 enhance
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[iotdb] 01/01: enhance
Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch enhance_loadservice
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 39dd255c36968a9205057406a3b38d6a3ad79688
Author: OneSizeFitQuorum <ta...@apache.org>
AuthorDate: Thu Aug 10 20:38:10 2023 +0800
enhance
Signed-off-by: OneSizeFitQuorum <ta...@apache.org>
---
.../apache/iotdb/confignode/manager/load/LoadManager.java | 8 ++++++--
.../confignode/manager/load/balancer/RouteBalancer.java | 4 ++--
.../confignode/manager/load/service/StatisticsService.java | 14 +++++++++-----
.../org/apache/iotdb/commons/concurrent/ThreadName.java | 3 ++-
4 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManager.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManager.java
index 450a19adad2..b52a2d5a1dc 100644
--- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManager.java
+++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManager.java
@@ -26,6 +26,8 @@ import org.apache.iotdb.common.rpc.thrift.TSeriesPartitionSlot;
import org.apache.iotdb.commons.cluster.NodeStatus;
import org.apache.iotdb.commons.cluster.NodeType;
import org.apache.iotdb.commons.cluster.RegionStatus;
+import org.apache.iotdb.commons.concurrent.IoTDBThreadPoolFactory;
+import org.apache.iotdb.commons.concurrent.ThreadName;
import org.apache.iotdb.commons.partition.DataPartitionTable;
import org.apache.iotdb.commons.partition.SchemaPartitionTable;
import org.apache.iotdb.confignode.consensus.request.write.region.CreateRegionGroupsPlan;
@@ -49,7 +51,6 @@ import com.google.common.eventbus.EventBus;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -73,7 +74,10 @@ public class LoadManager {
private final StatisticsService statisticsService;
private final EventBus loadPublisher =
- new AsyncEventBus("Cluster-LoadPublisher-Thread", Executors.newFixedThreadPool(5));
+ new AsyncEventBus(
+ ThreadName.CONFIG_NODE_LOAD_PUBLISHER.getName(),
+ IoTDBThreadPoolFactory.newFixedThreadPool(
+ 5, ThreadName.CONFIG_NODE_LOAD_PUBLISHER.getName()));
public LoadManager(IManager configManager) {
this.configManager = configManager;
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java
index c7f94691b10..6380045be5b 100644
--- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java
+++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java
@@ -138,7 +138,7 @@ public class RouteBalancer {
// Collect the latest data and generate the optimal leader distribution
Map<TConsensusGroupId, Integer> currentLeaderMap = getLoadManager().getRegionLeaderMap();
- Map<TConsensusGroupId, Integer> optimalLeadderMap =
+ Map<TConsensusGroupId, Integer> optimalLeaderMap =
leaderBalancer.generateOptimalLeaderDistribution(
getPartitionManager().getAllReplicaSetsMap(regionGroupType),
currentLeaderMap,
@@ -154,7 +154,7 @@ public class RouteBalancer {
AtomicInteger requestId = new AtomicInteger(0);
AsyncClientHandler<TRegionLeaderChangeReq, TSStatus> clientHandler =
new AsyncClientHandler<>(DataNodeRequestType.CHANGE_REGION_LEADER);
- optimalLeadderMap.forEach(
+ optimalLeaderMap.forEach(
(regionGroupId, newLeaderId) -> {
if (newLeaderId != -1 && !newLeaderId.equals(currentLeaderMap.get(regionGroupId))) {
String consensusProtocolClass;
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/service/StatisticsService.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/service/StatisticsService.java
index feb01ee04ef..be9603bfdc9 100644
--- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/service/StatisticsService.java
+++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/service/StatisticsService.java
@@ -136,18 +136,17 @@ public class StatisticsService implements IClusterStatusSubscriber {
// Map<RegionGroupId, Pair<old leader index, new leader index>>
Map<TConsensusGroupId, Pair<Integer, Integer>> differentRegionLeaderMap =
loadCache.updateRegionGroupLeader();
- if (!differentRegionLeaderMap.isEmpty()) {
- isNeedBroadcast = true;
- }
- if (isNeedBroadcast || loadCache.existUnreadyRegionGroup()) {
+ if (!differentRegionLeaderMap.isEmpty() || loadCache.existUnreadyRegionGroup()) {
// Update RegionRoute if cluster statistics changed or some RegionGroups are unready
differentRegionLeaderMap.putAll(routeBalancer.balanceRegionLeader());
// Update RegionPriority
// Map<RegionGroupId, Pair<old priority, new priority>>
Map<TConsensusGroupId, Pair<TRegionReplicaSet, TRegionReplicaSet>>
differentRegionPriorityMap = routeBalancer.balanceRegionPriority();
- if (!differentRegionLeaderMap.isEmpty() || !differentRegionPriorityMap.isEmpty()) {
+
+ if (containsChangeEvent(differentRegionLeaderMap)
+ || containsChangeEvent(differentRegionPriorityMap)) {
eventBus.post(new RouteChangeEvent(differentRegionLeaderMap, differentRegionPriorityMap));
}
}
@@ -159,6 +158,11 @@ public class StatisticsService implements IClusterStatusSubscriber {
}
}
+ private static <T> boolean containsChangeEvent(Map<TConsensusGroupId, Pair<T, T>> map) {
+ return !map.isEmpty()
+ && map.values().stream().anyMatch(pair -> !Objects.equals(pair.getLeft(), pair.getRight()));
+ }
+
public void broadcastLatestRegionRouteMap() {
Map<TConsensusGroupId, TRegionReplicaSet> regionPriorityMap =
getLoadManager().getRegionPriorityMap();
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java
index 0382f963a42..38968b66659 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java
@@ -86,6 +86,7 @@ public enum ThreadName {
ASYNC_DATANODE_HEARTBEAT_CLIENT_POOL("AsyncDataNodeHeartbeatServiceClientPool"),
// -------------------------- ConfigNode-LoadBalance --------------------------
CONFIG_NODE_LOAD_STATISTIC("Cluster-LoadStatistics-Service"),
+ CONFIG_NODE_LOAD_PUBLISHER("Cluster-LoadStatistics-Publisher"),
// -------------------------- ConfigNode-RegionManagement --------------------------
CONFIG_NODE_REGION_MAINTAINER("IoTDB-Region-Maintainer"),
// -------------------------- ConfigNode-Recover --------------------------
@@ -310,7 +311,7 @@ public enum ThreadName {
ASYNC_DATANODE_HEARTBEAT_CLIENT_POOL));
private static final Set<ThreadName> configNodeLoadBalanceThreadNames =
- new HashSet<>(Arrays.asList(CONFIG_NODE_LOAD_STATISTIC));
+ new HashSet<>(Arrays.asList(CONFIG_NODE_LOAD_STATISTIC, CONFIG_NODE_LOAD_PUBLISHER));
private static final Set<ThreadName> configNodeRegionManagementThreadNames =
new HashSet<>(Arrays.asList(CONFIG_NODE_REGION_MAINTAINER));