This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new c866c0fb2cd Rectify the input parameters of LeaderBalancer (#12998)
c866c0fb2cd is described below
commit c866c0fb2cdf9729400fe2c211dcac41c36c0280
Author: Yongzao <[email protected]>
AuthorDate: Wed Jul 24 10:23:06 2024 +0800
Rectify the input parameters of LeaderBalancer (#12998)
* commit for test
* re run
* update logs
---
.../manager/load/balancer/RouteBalancer.java | 3 ++-
.../router/leader/AbstractLeaderBalancer.java | 20 ++++++++++++++++++++
.../confignode/manager/load/cache/LoadCache.java | 18 ++++++++++++++++++
.../ConsensusGroupStatisticsChangeEvent.java | 8 ++++++++
4 files changed, 48 insertions(+), 1 deletion(-)
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 36f85afcbef..94e1e5c0eb6 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
@@ -155,7 +155,8 @@ public class RouteBalancer implements
IClusterStatusSubscriber {
private void balanceRegionLeader(
TConsensusGroupType regionGroupType, String consensusProtocolClass) {
// Collect the latest data and generate the optimal leader distribution
- Map<TConsensusGroupId, Integer> currentLeaderMap =
getLoadManager().getRegionLeaderMap();
+ Map<TConsensusGroupId, Integer> currentLeaderMap =
+ getLoadManager().getLoadCache().getRegionLeaderMap(regionGroupType);
Map<TConsensusGroupId, Integer> optimalLeaderMap =
leaderBalancer.generateOptimalLeaderDistribution(
getLoadManager().getLoadCache().getCurrentDatabaseRegionGroupMap(regionGroupType),
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/router/leader/AbstractLeaderBalancer.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/router/leader/AbstractLeaderBalancer.java
index 6ba7a97957d..e545d8b4ff1 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/router/leader/AbstractLeaderBalancer.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/router/leader/AbstractLeaderBalancer.java
@@ -93,6 +93,26 @@ public abstract class AbstractLeaderBalancer {
LOGGER.warn(
"[LeaderBalancer] The following RegionGroups' leader cannot be
selected because their corresponding caches are incomplete: {}",
differenceSet);
+ Set<TConsensusGroupId> databaseRegionGroupUnionSet =
+ databaseRegionGroupMap.values().stream()
+ .flatMap(List::stream)
+ .collect(Collectors.toSet());
+ differenceSet.forEach(
+ regionId -> {
+ if (!databaseRegionGroupUnionSet.contains(regionId)) {
+ LOGGER.warn("[LeaderBalancer] Region: {} not in
databaseRegionGroupMap", regionId);
+ }
+ if (!regionLocationMap.containsKey(regionId)) {
+ LOGGER.warn("[LeaderBalancer] Region: {} not in
regionLocationMap", regionId);
+ }
+ if (!regionLeaderMap.containsKey(regionId)) {
+
+ LOGGER.warn("[LeaderBalancer] Region: {} not in
regionLeaderMap", regionId);
+ }
+ if (!regionStatisticsMap.containsKey(regionId)) {
+ LOGGER.warn("[LeaderBalancer] Region: {} not in
regionStatisticsMap", regionId);
+ }
+ });
}
}
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/cache/LoadCache.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/cache/LoadCache.java
index 1227b07ca5e..e51d6907387 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/cache/LoadCache.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/cache/LoadCache.java
@@ -668,6 +668,24 @@ public class LoadCache {
return regionLeaderMap;
}
+ /**
+ * Safely get the latest RegionLeaderMap.
+ *
+ * @param consensusGroupType DataRegion or SchemaRegion
+ * @return Map<RegionGroupId, leaderId>, leaderId will be -1 if the
RegionGroup has no leader yet.
+ */
+ public Map<TConsensusGroupId, Integer> getRegionLeaderMap(
+ TConsensusGroupType consensusGroupType) {
+ Map<TConsensusGroupId, Integer> regionLeaderMap = new
ConcurrentHashMap<>();
+ consensusGroupCacheMap.forEach(
+ (regionGroupId, consensusGroupCache) -> {
+ if (regionGroupId.getType().equals(consensusGroupType)) {
+ regionLeaderMap.put(regionGroupId,
consensusGroupCache.getLeaderId());
+ }
+ });
+ return regionLeaderMap;
+ }
+
/**
* Wait for the specified RegionGroups to finish leader election.
*
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/subscriber/ConsensusGroupStatisticsChangeEvent.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/subscriber/ConsensusGroupStatisticsChangeEvent.java
index a3051305b31..49d1564f6d9 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/subscriber/ConsensusGroupStatisticsChangeEvent.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/subscriber/ConsensusGroupStatisticsChangeEvent.java
@@ -43,4 +43,12 @@ public class ConsensusGroupStatisticsChangeEvent {
getDifferentConsensusGroupStatisticsMap() {
return differentConsensusGroupStatisticsMap;
}
+
+ @Override
+ public String toString() {
+ return "ConsensusGroupStatisticsChangeEvent{"
+ + "differentConsensusGroupStatisticsMap="
+ + differentConsensusGroupStatisticsMap
+ + '}';
+ }
}