Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,9 @@ iotdb-core/tsfile/src/main/antlr4/org/apache/tsfile/parser/gen/
# Develocity
.mvn/.gradle-enterprise/
.mvn/.develocity/
.run/CN1.run.xml
.run/CN-ide.run.xml
.run/DN1.run.xml
.run/DN2.run.xml
.run/DN3.run.xml
.run/DN-ide.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ private void loadProperties(TrimProperties properties) throws BadNodeUrlExceptio
.getProperty("leader_distribution_policy", conf.getLeaderDistributionPolicy())
.trim();
if (AbstractLeaderBalancer.GREEDY_POLICY.equals(leaderDistributionPolicy)
|| AbstractLeaderBalancer.CFD_POLICY.equals(leaderDistributionPolicy)) {
|| AbstractLeaderBalancer.CFD_POLICY.equals(leaderDistributionPolicy)
|| AbstractLeaderBalancer.HASH_POLICY.equals(leaderDistributionPolicy)) {
conf.setLeaderDistributionPolicy(leaderDistributionPolicy);
} else {
throw new IOException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ private void checkGlobalConfig() throws ConfigurationException {

// The leader distribution policy is limited
if (!AbstractLeaderBalancer.GREEDY_POLICY.equals(CONF.getLeaderDistributionPolicy())
&& !AbstractLeaderBalancer.CFD_POLICY.equals(CONF.getLeaderDistributionPolicy())) {
&& !AbstractLeaderBalancer.CFD_POLICY.equals(CONF.getLeaderDistributionPolicy())
&& !AbstractLeaderBalancer.HASH_POLICY.equals(CONF.getLeaderDistributionPolicy())) {
throw new ConfigurationException(
"leader_distribution_policy",
CONF.getRoutePriorityPolicy(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.iotdb.confignode.manager.load.LoadManager;
import org.apache.iotdb.confignode.manager.load.balancer.router.leader.AbstractLeaderBalancer;
import org.apache.iotdb.confignode.manager.load.balancer.router.leader.GreedyLeaderBalancer;
import org.apache.iotdb.confignode.manager.load.balancer.router.leader.HashLeaderBalancer;
import org.apache.iotdb.confignode.manager.load.balancer.router.leader.MinCostFlowLeaderBalancer;
import org.apache.iotdb.confignode.manager.load.balancer.router.priority.GreedyPriorityBalancer;
import org.apache.iotdb.confignode.manager.load.balancer.router.priority.IPriorityBalancer;
Expand Down Expand Up @@ -134,6 +135,9 @@ public RouteBalancer(IManager configManager) {
case AbstractLeaderBalancer.GREEDY_POLICY:
this.leaderBalancer = new GreedyLeaderBalancer();
break;
case AbstractLeaderBalancer.HASH_POLICY:
this.leaderBalancer = new HashLeaderBalancer();
break;
case AbstractLeaderBalancer.CFD_POLICY:
default:
this.leaderBalancer = new MinCostFlowLeaderBalancer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public abstract class AbstractLeaderBalancer {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractLeaderBalancer.class);
public static final String GREEDY_POLICY = "GREEDY";
public static final String CFD_POLICY = "CFD";
public static final String HASH_POLICY = "HASH";

// Set<RegionGroupId>
protected final Set<TConsensusGroupId> regionGroupIntersection;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iotdb.confignode.manager.load.balancer.router.leader;

import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
import org.apache.iotdb.commons.cluster.NodeStatus;
import org.apache.iotdb.confignode.manager.load.cache.node.NodeStatistics;
import org.apache.iotdb.confignode.manager.load.cache.region.RegionStatistics;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class HashLeaderBalancer extends AbstractLeaderBalancer {
@Override
public Map<TConsensusGroupId, Integer> generateOptimalLeaderDistribution(
Map<String, List<TConsensusGroupId>> databaseRegionGroupMap,
Map<TConsensusGroupId, Set<Integer>> regionLocationMap,
Map<TConsensusGroupId, Integer> regionLeaderMap,
Map<Integer, NodeStatistics> dataNodeStatisticsMap,
Map<TConsensusGroupId, Map<Integer, RegionStatistics>> regionStatisticsMap) {
Map<TConsensusGroupId, Integer> result = new HashMap<>();
regionLocationMap.forEach(
(gid, nodeSet) -> {
List<Integer> nodeList = new ArrayList<>(nodeSet);
nodeList.sort(null);
int startNodeIndex = Math.abs(gid.hashCode()) % nodeList.size();
int finalNodeId = nodeList.get(startNodeIndex);
for (int i = 0; i < nodeList.size(); i++) {
int currentNodeIndex = (startNodeIndex + i) % nodeList.size();
int currentNodeId = nodeList.get(currentNodeIndex);
NodeStatistics nodeStatistics = dataNodeStatisticsMap.get(currentNodeId);
if (nodeStatistics != null && nodeStatistics.getStatus() == NodeStatus.Running) {
finalNodeId = currentNodeId;
break;
}
}
result.put(gid, finalNodeId);
});
return result;
}
}
Loading