anuragp010 commented on code in PR #12062:
URL: https://github.com/apache/ozone/pull/12062#discussion_r4641932275
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/balancer/TestContainerBalancerTask.java:
##########
@@ -762,9 +775,400 @@ private ContainerReplica createReplica(ContainerID
containerID,
.setOriginNodeId(datanodeDetails.getID())
.setSequenceId(1000L)
.setBytesUsed(usedBytes)
+ .setStorageType(StorageType.DISK)
+ .setVolumeStorageType(StorageType.DISK)
.build();
}
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ public void testRejectedCandidatesAreNotRecheckedForStorageType(boolean
differentStorageType) throws Exception {
+ DatanodeUsageInfo source = storageTypeNode(80, 80);
+ DatanodeUsageInfo target = storageTypeNode(20, 80);
+ StorageType rejectedType = differentStorageType ? StorageType.DISK :
StorageType.SSD;
+ List<ContainerID> rejected = new ArrayList<>();
+ for (int i = 0; i < 200; i++) {
+ long id = 1000L + i;
+ addStorageTypeContainer(source, id, rejectedType, 2 * OzoneConsts.MB);
+ ContainerID containerID = ContainerID.valueOf(id);
+ if (!differentStorageType) {
+ cidToInfoMap.get(containerID).setState(HddsProtos.LifeCycleState.OPEN);
+ }
+ rejected.add(containerID);
+ }
+ for (int i = 0; i < 100; i++) {
+ addStorageTypeContainer(source, 2000L + i, StorageType.SSD,
OzoneConsts.MB);
+ }
+ List<StorageType> order = new ArrayList<>();
+ configureStorageTypeCluster(Arrays.asList(source, target), 0, order);
+ balancerConfiguration.setMaxSizeToMovePerIteration(100 * OzoneConsts.MB);
+ startBalancer(balancerConfiguration);
+
+ assertThat(order).hasSize(100).containsOnly(StorageType.SSD);
+ for (ContainerID containerID : rejected) {
+ verify(scm.getContainerManager(),
times(1)).getContainerReplicas(containerID);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ public void
testRejectedContainerRemainsAvailableForAnotherStorageType(boolean
exceedsSsdLimit) throws Exception {
Review Comment:
nit: The scenario being tested here is that a `DISK` container retrieved
during the `SSD` pass is rejected because of the `storageType` mismatch but
this rejection doesn't mean the container can't be used in the `DISK` pass.
Should we add a comment on top of this test highlighting this scenario?
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/balancer/ContainerBalancerTask.java:
##########
@@ -557,56 +560,45 @@ private boolean initializeIteration() {
this.totalNodesInCluster = datanodeUsageInfos.size();
- double clusterAvgUtilisation = calculateAvgUtilization(datanodeUsageInfos);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Average utilization of the cluster is {}",
clusterAvgUtilisation);
+ // Node include/exclude filters have already been applied above.
+ ContainerBalancerClusterSnapshot analysis =
ContainerBalancerClusterAnalyzer.analyze(datanodeUsageInfos.stream()
+ .map(node ->
node.toProto(ClientVersion.DEFAULT_VERSION)).collect(Collectors.toList()),
+ config.getThresholdAsRatio(), Collections.emptySet(),
Collections.emptySet());
+ if (analysis.hasIncompleteStorageTypeUsage()) {
+ lastInitializationFailureDetail = "Incomplete storage-type usage
reports; cannot safely select typed moves";
+ LOG.warn(lastInitializationFailureDetail);
+ return false;
}
-
- double threshold = config.getThresholdAsRatio();
- // over utilized nodes have utilization(that is, used / capacity) greater
than upper limit
- this.upperLimit = ContainerBalancerClusterAnalyzer.computeUpperLimit(
- clusterAvgUtilisation, threshold);
- // under utilized nodes have utilization(that is, used / capacity) less
than lower limit
- this.lowerLimit = ContainerBalancerClusterAnalyzer.computeLowerLimit(
- clusterAvgUtilisation, threshold);
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("Lower limit for utilization is {} and Upper limit for
utilization is {}", lowerLimit, upperLimit);
+ if (analysis.getStorageTypeSnapshots().isEmpty()) {
+ storageTypeStates.add(new StorageTypeBalancingState(null,
analysis.getLowerLimit(), analysis.getUpperLimit(),
+ datanodeUsageInfos, analysis.getSourceDatanodes(),
analysis.getTargetDatanodes()));
+ } else {
+ analysis.getStorageTypeSnapshots().forEach((type, snapshot) ->
+ storageTypeStates.add(new StorageTypeBalancingState(type,
snapshot.getLowerLimit(), snapshot.getUpperLimit(),
+ datanodeUsageInfos, snapshot.getSourceDatanodes(),
snapshot.getTargetDatanodes())));
}
-
- long totalOverUtilizedBytes = 0L, totalUnderUtilizedBytes = 0L;
- // find over and under utilized nodes
- for (DatanodeUsageInfo datanodeUsageInfo : datanodeUsageInfos) {
+ Set<DatanodeDetails> sources = new HashSet<>();
+ Set<DatanodeDetails> targets = new HashSet<>();
Review Comment:
Right. Preserving the behaviour makes sense. Thanks for adding the tests to
confirm the same too.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]