lokeshj1703 commented on code in PR #3423:
URL: https://github.com/apache/ozone/pull/3423#discussion_r879181122
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/balancer/ContainerBalancer.java:
##########
@@ -179,19 +188,53 @@ private void balance() {
}
}
- // stop balancing if iteration is not initialized
+ // initialize this iteration. stop balancing on initialization failure
if (!initializeIteration()) {
- stopBalancer();
+ // just return if the reason for initialization failure is that
+ // balancer has been stopped in another thread
+ if (!isBalancerRunning()) {
+ return;
+ }
+ // otherwise, try to stop balancer
+ try {
+ stopBalancer();
+ } catch (IOException | IllegalContainerBalancerStateException e) {
+ LOG.warn("Tried and failed to stop Container Balancer when it " +
+ "could not initialize an iteration", e);
+ }
return;
}
- //if no new move option is generated, it means the cluster can
- //not be balanced any more , so just stop
IterationResult iR = doIteration();
metrics.incrementNumIterations(1);
LOG.info("Result of this iteration of Container Balancer: {}", iR);
+
+ // persist next iteration index
+ if (iR == IterationResult.ITERATION_COMPLETED) {
+ lock.lock();
+ try {
+ saveConfiguration(
+ config.toProtobufBuilder()
+ .setShouldRun(true)
+ .setNextIterationIndex(i + 1)
+ .build());
+ } catch (IOException e) {
+ LOG.warn("Could not persist next iteration index value for " +
+ "ContainerBalancer after completing an iteration", e);
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ // if no new move option is generated, it means the cluster cannot be
+ // balanced anymore; so just stop balancer
if (iR == IterationResult.CAN_NOT_BALANCE_ANY_MORE) {
- stopBalancer();
+ try {
+ stopBalancer();
+ } catch (IOException | IllegalContainerBalancerStateException e) {
+ LOG.warn("Tried and failed to stop Container Balancer when result " +
+ "of the latest iteration was " + iR, e);
+ }
Review Comment:
You have different logs based on when stop is called. So I am suggesting to
make it a parameter.
--
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]