CRZbulabula commented on code in PR #11572:
URL: https://github.com/apache/iotdb/pull/11572#discussion_r1418901924


##########
iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyCopySetRegionGroupAllocatorTest.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.region;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
+import org.apache.iotdb.common.rpc.thrift.TDataNodeConfiguration;
+import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
+import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
+import org.apache.iotdb.confignode.conf.ConfigNodeDescriptor;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class GreedyCopySetRegionGroupAllocatorTest {
+
+  private static final Logger LOGGER =
+      LoggerFactory.getLogger(GreedyCopySetRegionGroupAllocatorTest.class);
+
+  private static final GreedyRegionGroupAllocator GREEDY_ALLOCATOR =
+      new GreedyRegionGroupAllocator();
+  private static final GreedyCopySetRegionGroupAllocator 
GREEDY_COPY_SET_ALLOCATOR =
+      new GreedyCopySetRegionGroupAllocator();
+
+  private static final int TEST_DATA_NODE_NUM = 21;
+  private static final int DATA_REGION_PER_DATA_NODE =
+      (int) 
ConfigNodeDescriptor.getInstance().getConf().getDataRegionPerDataNode();
+  private static final Map<Integer, TDataNodeConfiguration> 
AVAILABLE_DATA_NODE_MAP =
+      new HashMap<>();
+  private static final Map<Integer, Double> FREE_SPACE_MAP = new HashMap<>();
+
+  @BeforeClass
+  public static void setUp() {
+    // Construct 21 DataNodes
+    Random random = new Random();
+    for (int i = 1; i <= TEST_DATA_NODE_NUM; i++) {
+      AVAILABLE_DATA_NODE_MAP.put(
+          i, new TDataNodeConfiguration().setLocation(new 
TDataNodeLocation().setDataNodeId(i)));
+      FREE_SPACE_MAP.put(i, random.nextDouble());
+    }
+  }
+
+  @Test
+  public void test2Factor() {
+    testRegionDistributionAndScatterWidth(2);
+  }
+
+  @Test
+  public void test3Factor() {
+    testRegionDistributionAndScatterWidth(3);
+  }
+
+  private void testRegionDistributionAndScatterWidth(int replicationFactor) {
+    final int dataRegionGroupNum =
+        DATA_REGION_PER_DATA_NODE * TEST_DATA_NODE_NUM / replicationFactor;
+
+    /* Allocate DataRegionGroups */
+    List<TRegionReplicaSet> greedyResult = new ArrayList<>();
+    List<TRegionReplicaSet> greedyCopySetResult = new ArrayList<>();
+    for (int index = 0; index < dataRegionGroupNum; index++) {
+      greedyResult.add(
+          GREEDY_ALLOCATOR.generateOptimalRegionReplicasDistribution(
+              AVAILABLE_DATA_NODE_MAP,
+              FREE_SPACE_MAP,
+              greedyResult,
+              replicationFactor,
+              new TConsensusGroupId(TConsensusGroupType.DataRegion, index)));
+      greedyCopySetResult.add(
+          GREEDY_COPY_SET_ALLOCATOR.generateOptimalRegionReplicasDistribution(
+              AVAILABLE_DATA_NODE_MAP,
+              FREE_SPACE_MAP,
+              greedyCopySetResult,
+              replicationFactor,
+              new TConsensusGroupId(TConsensusGroupType.DataRegion, index)));
+    }
+
+    /* Statistics result */
+    // Map<DataNodeId, RegionGroup Count> for greedy algorithm
+    Map<Integer, AtomicInteger> greedyRegionCounter = new HashMap<>();

Review Comment:
   Fixed



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RegionBalancer.java:
##########
@@ -147,6 +151,7 @@ private LoadManager getLoadManager() {
 
   public enum RegionGroupAllocatePolicy {
     COPY_SET,

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to