sarvekshayr commented on code in PR #11342:
URL: https://github.com/apache/ozone/pull/11342#discussion_r4132632527
##########
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/scm/container/balancer/TestContainerBalancerAdvisor.java:
##########
@@ -240,6 +256,119 @@ void testEstimateFailsWhenClusterBalanced() {
new ContainerBalancerAdvisor.AdvisorRequest().setNodes(balanced)));
}
+ @Test
+ void testRecommendReturnsThreeProfiles() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ List<ContainerBalancerRecommendation> results =
ContainerBalancerAdvisor.recommend(
+ conf,
+ new
ContainerBalancerAdvisor.AdvisorRequest().setNodes(buildCluster(70, 14, 14)));
+
+ assertEquals(3, results.size());
+ assertEquals(ContainerBalancerProfile.SLOW, results.get(0).getProfile());
+ assertEquals(ContainerBalancerProfile.MEDIUM, results.get(1).getProfile());
+ assertEquals(ContainerBalancerProfile.FAST, results.get(2).getProfile());
+ for (ContainerBalancerRecommendation result : results) {
+ assertTrue(result.succeeded());
+ assertNotNull(result.getEstimation());
+ assertTrue(result.getEstimation().succeeded());
+ assertTrue(result.getRecommendedIterations() >=
result.getEstimation().getEstimatedIterations());
+ assertFalse(result.getRationale().isEmpty());
+ }
+ }
+
+ @Test
+ void testComputeRecommendedMaxSizeToMoveFloorsAtProfileLimits() {
+ ContainerBalancerEstimation estimation =
ContainerBalancerEstimation.newBuilder()
+ .setProfile(ContainerBalancerProfile.SLOW)
+ .setPerIterationBytes(8L * OzoneConsts.GB)
+ .setMaxSizeEnteringTarget(10L * OzoneConsts.GB)
+ .setMaxSizeLeavingSource(10L * OzoneConsts.GB)
+ .build();
+
+ assertEquals(10L * OzoneConsts.GB,
+ ContainerBalancerAdvisor.computeRecommendedMaxSizeToMove(500L *
OzoneConsts.GB, estimation));
+ }
+
+ @Test
+ void testComputeRecommendedMaxSizeToMoveUsesPerIterationWhenLarger() {
+ ContainerBalancerEstimation estimation =
ContainerBalancerEstimation.newBuilder()
+ .setProfile(ContainerBalancerProfile.MEDIUM)
+ .setPerIterationBytes(182L * OzoneConsts.GB)
+ .setMaxSizeEnteringTarget(26L * OzoneConsts.GB)
+ .setMaxSizeLeavingSource(26L * OzoneConsts.GB)
+ .build();
+
+ assertEquals(182L * OzoneConsts.GB,
+ ContainerBalancerAdvisor.computeRecommendedMaxSizeToMove(500L *
OzoneConsts.GB, estimation));
+ }
+
+ @Test
+ void testRecommendReturnsSingleProfileWhenProfileSet() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ List<ContainerBalancerRecommendation> results =
ContainerBalancerAdvisor.recommend(
+ conf,
+ new ContainerBalancerAdvisor.AdvisorRequest()
+ .setNodes(buildCluster(70, 14, 14))
+ .setProfile(ContainerBalancerProfile.MEDIUM));
+
+ assertEquals(1, results.size());
+ assertEquals(ContainerBalancerProfile.MEDIUM, results.get(0).getProfile());
+ assertTrue(results.get(0).succeeded());
+ }
+
+ @Test
+ void testRecommendUsesProfileDefaults() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ ContainerBalancerRecommendation slow = ContainerBalancerAdvisor.recommend(
+ conf,
+ new
ContainerBalancerAdvisor.AdvisorRequest().setNodes(buildCluster(70, 14, 14)))
+ .get(0);
+
+ assertEquals(10, slow.getMaxDatanodesPercentage());
+ assertEquals(10L * OzoneConsts.GB, slow.getMaxSizeEnteringTarget());
+ assertEquals(10L * OzoneConsts.GB, slow.getMaxSizeLeavingSource());
+ assertEquals(30L * OzoneConsts.GB, slow.getMaxSizeToMovePerIteration());
+ assertTrue(slow.getMaxSizeToMovePerIteration() >=
slow.getMaxSizeEnteringTarget());
+ assertTrue(slow.getMaxSizeToMovePerIteration() >=
slow.getMaxSizeLeavingSource());
+ }
+
+ @Test
+ void testRecommendRespectsThresholdOverride() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ List<DatanodeUsageInfoProto> nodes = buildCluster(70, 14, 14);
+
+ long defaultBytesToMove = ContainerBalancerAdvisor.recommend(
+ conf,
+ new ContainerBalancerAdvisor.AdvisorRequest().setNodes(nodes))
+ .get(0)
+ .getEstimation()
+ .getBytesToMove();
+
+ long tighterBytesToMove = ContainerBalancerAdvisor.recommend(
+ conf,
+ new ContainerBalancerAdvisor.AdvisorRequest()
+ .setNodes(nodes)
+ .setThresholdPercent(5.0))
+ .get(0)
+ .getEstimation()
+ .getBytesToMove();
+
+ assertTrue(tighterBytesToMove > defaultBytesToMove);
+ }
+
+ @Test
+ void testRecommendFailsWhenClusterBalanced() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ List<DatanodeUsageInfoProto> balanced = new ArrayList<>();
+ balanced.add(proto("dn-1", OzoneConsts.TB, (long) (0.70 *
OzoneConsts.TB)));
+ balanced.add(proto("dn-2", OzoneConsts.TB, (long) (0.70 *
OzoneConsts.TB)));
+
+ assertThrows(IllegalArgumentException.class, () ->
+ ContainerBalancerAdvisor.recommend(
+ conf,
+ new ContainerBalancerAdvisor.AdvisorRequest().setNodes(balanced)));
+ }
Review Comment:
If the nodes are balanced, we should treat it as a successful check (e.g.,
log / print that the cluster is balanced and return no actions) instead of
throwing an exception.
What do you think?
--
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]