@@ -75,7 +75,6 @@ public class ContainerBalancerTask implements Runnable {
7575 private OzoneConfiguration ozoneConfiguration ;
7676 private ContainerBalancer containerBalancer ;
7777 private final SCMContext scmContext ;
78- private double threshold ;
7978 private int totalNodesInCluster ;
8079 private double maxDatanodesRatioToInvolvePerIteration ;
8180 private long maxSizeToMovePerIteration ;
@@ -84,17 +83,13 @@ public class ContainerBalancerTask implements Runnable {
8483 // count actual size moved in bytes
8584 private long sizeActuallyMovedInLatestIteration ;
8685 private int iterations ;
87- private List <DatanodeUsageInfo > unBalancedNodes ;
88- private List <DatanodeUsageInfo > overUtilizedNodes ;
89- private List <DatanodeUsageInfo > underUtilizedNodes ;
86+ private final List <DatanodeUsageInfo > overUtilizedNodes ;
87+ private final List <DatanodeUsageInfo > underUtilizedNodes ;
9088 private List <DatanodeUsageInfo > withinThresholdUtilizedNodes ;
9189 private Set <String > excludeNodes ;
9290 private Set <String > includeNodes ;
9391 private ContainerBalancerConfiguration config ;
9492 private ContainerBalancerMetrics metrics ;
95- private long clusterCapacity ;
96- private long clusterRemaining ;
97- private double clusterAvgUtilisation ;
9893 private PlacementPolicyValidateProxy placementPolicyValidateProxy ;
9994 private NetworkTopology networkTopology ;
10095 private double upperLimit ;
@@ -150,7 +145,6 @@ public ContainerBalancerTask(StorageContainerManager scm,
150145 this .overUtilizedNodes = new ArrayList <>();
151146 this .underUtilizedNodes = new ArrayList <>();
152147 this .withinThresholdUtilizedNodes = new ArrayList <>();
153- this .unBalancedNodes = new ArrayList <>();
154148 this .placementPolicyValidateProxy = scm .getPlacementPolicyValidateProxy ();
155149 this .networkTopology = scm .getClusterMap ();
156150 this .nextIterationIndex = nextIterationIndex ;
@@ -348,7 +342,6 @@ private boolean initializeIteration() {
348342 return false ;
349343 }
350344
351- this .threshold = config .getThresholdAsRatio ();
352345 this .maxDatanodesRatioToInvolvePerIteration =
353346 config .getMaxDatanodesRatioToInvolvePerIteration ();
354347 this .maxSizeToMovePerIteration = config .getMaxSizeToMovePerIteration ();
@@ -368,22 +361,19 @@ private boolean initializeIteration() {
368361
369362 this .totalNodesInCluster = datanodeUsageInfos .size ();
370363
371- clusterAvgUtilisation = calculateAvgUtilization (datanodeUsageInfos );
364+ double clusterAvgUtilisation = calculateAvgUtilization (datanodeUsageInfos );
372365 if (LOG .isDebugEnabled ()) {
373- LOG .debug ("Average utilization of the cluster is {}" ,
374- clusterAvgUtilisation );
366+ LOG .debug ("Average utilization of the cluster is {}" , clusterAvgUtilisation );
375367 }
376368
377- // over utilized nodes have utilization(that is, used / capacity) greater
378- // than upper limit
369+ double threshold = config . getThresholdAsRatio ();
370+ // over utilized nodes have utilization(that is, used / capacity) greater than upper limit
379371 this .upperLimit = clusterAvgUtilisation + threshold ;
380- // under utilized nodes have utilization(that is, used / capacity) less
381- // than lower limit
372+ // under utilized nodes have utilization(that is, used / capacity) less than lower limit
382373 this .lowerLimit = clusterAvgUtilisation - threshold ;
383374
384375 if (LOG .isDebugEnabled ()) {
385- LOG .debug ("Lower limit for utilization is {} and Upper limit for " +
386- "utilization is {}" , lowerLimit , upperLimit );
376+ LOG .debug ("Lower limit for utilization is {} and Upper limit for utilization is {}" , lowerLimit , upperLimit );
387377 }
388378
389379 long totalOverUtilizedBytes = 0L , totalUnderUtilizedBytes = 0L ;
@@ -433,12 +423,7 @@ private boolean initializeIteration() {
433423 OzoneConsts .GB );
434424 Collections .reverse (underUtilizedNodes );
435425
436- unBalancedNodes = new ArrayList <>(
437- overUtilizedNodes .size () + underUtilizedNodes .size ());
438- unBalancedNodes .addAll (overUtilizedNodes );
439- unBalancedNodes .addAll (underUtilizedNodes );
440-
441- if (unBalancedNodes .isEmpty ()) {
426+ if (overUtilizedNodes .isEmpty () && underUtilizedNodes .isEmpty ()) {
442427 LOG .info ("Did not find any unbalanced Datanodes." );
443428 return false ;
444429 }
@@ -487,7 +472,7 @@ private IterationResult doIteration() {
487472 findTargetStrategy .reInitialize (potentialTargets , config , upperLimit );
488473 findSourceStrategy .reInitialize (getPotentialSources (), config , lowerLimit );
489474
490- moveSelectionToFutureMap = new HashMap <>(unBalancedNodes .size ());
475+ moveSelectionToFutureMap = new HashMap <>(underUtilizedNodes . size () + overUtilizedNodes .size ());
491476 boolean isMoveGeneratedInThisIteration = false ;
492477 iterationResult = IterationResult .ITERATION_COMPLETED ;
493478 boolean canAdaptWhenNearingLimits = true ;
@@ -965,8 +950,8 @@ private long ratioToBytes(Long nodeCapacity, double utilizationRatio) {
965950 * @return Average utilization value
966951 */
967952 @ VisibleForTesting
968- double calculateAvgUtilization (List <DatanodeUsageInfo > nodes ) {
969- if (nodes .size () == 0 ) {
953+ public static double calculateAvgUtilization (List <DatanodeUsageInfo > nodes ) {
954+ if (nodes .isEmpty () ) {
970955 LOG .warn ("No nodes to calculate average utilization for in " +
971956 "ContainerBalancer." );
972957 return 0 ;
@@ -976,8 +961,8 @@ private long ratioToBytes(Long nodeCapacity, double utilizationRatio) {
976961 for (DatanodeUsageInfo node : nodes ) {
977962 aggregatedStats .add (node .getScmNodeStat ());
978963 }
979- clusterCapacity = aggregatedStats .getCapacity ().get ();
980- clusterRemaining = aggregatedStats .getRemaining ().get ();
964+ long clusterCapacity = aggregatedStats .getCapacity ().get ();
965+ long clusterRemaining = aggregatedStats .getRemaining ().get ();
981966
982967 return (clusterCapacity - clusterRemaining ) / (double ) clusterCapacity ;
983968 }
@@ -1060,11 +1045,8 @@ private void incSizeSelectedForMoving(DatanodeDetails source,
10601045 */
10611046 private void resetState () {
10621047 moveManager .resetState ();
1063- this .clusterCapacity = 0L ;
1064- this .clusterRemaining = 0L ;
10651048 this .overUtilizedNodes .clear ();
10661049 this .underUtilizedNodes .clear ();
1067- this .unBalancedNodes .clear ();
10681050 this .containerToSourceMap .clear ();
10691051 this .containerToTargetMap .clear ();
10701052 this .selectedSources .clear ();
@@ -1090,15 +1072,14 @@ private boolean isBalancerRunning() {
10901072 return taskStatus == Status .RUNNING ;
10911073 }
10921074
1093- /**
1094- * Gets the list of unBalanced nodes, that is, the over and under utilized
1095- * nodes in the cluster.
1096- *
1097- * @return List of DatanodeUsageInfo containing unBalanced nodes.
1098- */
10991075 @ VisibleForTesting
1100- List <DatanodeUsageInfo > getUnBalancedNodes () {
1101- return unBalancedNodes ;
1076+ public List <DatanodeUsageInfo > getOverUtilizedNodes () {
1077+ return overUtilizedNodes ;
1078+ }
1079+
1080+ @ VisibleForTesting
1081+ public List <DatanodeUsageInfo > getUnderUtilizedNodes () {
1082+ return underUtilizedNodes ;
11021083 }
11031084
11041085 /**
0 commit comments