OneSizeFitsQuorum commented on code in PR #11784:
URL: https://github.com/apache/iotdb/pull/11784#discussion_r1436700588
##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyCopySetRegionGroupAllocator.java:
##########
@@ -26,31 +26,69 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.BitSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Random;
+import java.util.stream.Collectors;
+
+import static java.util.Map.Entry.comparingByValue;
/** Allocate Region through Greedy and CopySet Algorithm. */
public class GreedyCopySetRegionGroupAllocator implements
IRegionGroupAllocator {
- int replicationFactor;
- // RegionGroup allocation BitSet
- private List<BitSet> allocatedBitSets;
- // Map<DataNodeId, RegionGroup count>
- private Map<Integer, Integer> regionCounter;
- // Available DataNodeIds
- private Integer[] dataNodeIds;
+ private int replicationFactor;
+ // Sorted available DataNodeIds
+ private int[] dataNodeIds;
+ // The number of allocated Regions in each DataNode
+ private int[] regionCounter;
+ // The number of 2-Region combinations in current cluster
+ private int[][] combinationCounter;
// First Key: the sum of Regions at the DataNodes in the allocation result
is minimal
int optimalRegionSum;
- // Second Key: the sum of intersected Regions with other allocated
RegionGroups is minimal
- int optimalIntersectionSum;
+ // Second Key: the sum of overlapped 2-Region combination Regions with other
allocated
+ // RegionGroups is minimal
+ int optimalCombinationSum;
List<int[]> optimalReplicaSets;
+ private static final int MAX_OPTIMAL_PLAN_NUM = 10;
+
+ private final Random random;
+
+ private class DataNodeEntry {
+
+ private final int dataNodeId;
+
+ // First key: the number of Regions in the DataNode
+ private final int regionCount;
+ // Second key: the scatter width of the DataNode
+ private final int scatterWidth;
+ // Third key: a random weight
+ private final int randomWeight;
+
+ public DataNodeEntry(int dataNodeId, int regionCount, int scatterWidth) {
+ this.dataNodeId = dataNodeId;
+ this.regionCount = regionCount;
+ this.scatterWidth = scatterWidth;
+ this.randomWeight = random.nextInt();
+ }
+
+ public int getDataNodeId() {
+ return dataNodeId;
+ }
+
+ public int compare(DataNodeEntry e) {
+ return regionCount != e.regionCount
+ ? Integer.compare(regionCount, e.regionCount)
+ : scatterWidth != e.scatterWidth
+ ? Integer.compare(scatterWidth, e.scatterWidth)
+ : Integer.compare(randomWeight, e.randomWeight);
+ }
+ }
public GreedyCopySetRegionGroupAllocator() {
- // Empty constructor
+ this.random = new Random();
Review Comment:
how about making it a static field
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]