sumitagrawl commented on code in PR #3782:
URL: https://github.com/apache/ozone/pull/3782#discussion_r990390247


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/balancer/ContainerBalancer.java:
##########
@@ -1072,15 +295,15 @@ private void validateState(boolean expectedRunning)
       LOG.warn("SCM is in safe mode");
       throw new IllegalContainerBalancerStateException("SCM is in safe mode");
     }
-    lock.lock();
-    try {
-      if (isBalancerRunning() != expectedRunning) {
-        throw new IllegalContainerBalancerStateException(
-            "Expect ContainerBalancer running state to be " + expectedRunning +
-                ", but running state is actually " + isBalancerRunning());
-      }
-    } finally {
-      lock.unlock();
+    if (!expectedRunning && !canBalancerStart()) {
+      throw new IllegalContainerBalancerStateException(
+          "Expect ContainerBalancer as not running state" +
+              ", but running state is actually " + getBalancerStatus());
+    }
+    if (expectedRunning && !canBalancerStop()) {
+      throw new IllegalContainerBalancerStateException(
+          "Expect ContainerBalancer as running state" +
+              ", but running state is actually " + getBalancerStatus());

Review Comment:
   This is required, as per state machine
   Start should be triggered --> when nothing present or Stopped. But not allow 
when stopping. So canStart() do this job
   
   Stop should be triggered --> when its running. Else no need call stop and 
throw exception for case of stopping or nothing present.
   
   IsBalancerRunning just check for runningState, but not considering case of 
stopping.



-- 
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]

Reply via email to