You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/06/28 08:58:45 UTC

[GitHub] [ozone] lokeshj1703 commented on a diff in pull request #3535: HDDS-6928. ozone container balancer CLI went in hung state due to deadlock

lokeshj1703 commented on code in PR #3535:
URL: https://github.com/apache/ozone/pull/3535#discussion_r908222198


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/balancer/ContainerBalancer.java:
##########
@@ -1032,16 +1048,30 @@ private void validateState(boolean expectedRunning)
    */
   @Override
   public void stop() {
+    Thread balancingThread;
     lock.lock();
     try {
       if (!isBalancerRunning()) {
         LOG.warn("Cannot stop Container Balancer because it's not running");
         return;
       }
-      stopBalancingThread();
+      balancingThread = currentBalancingThread;
+      currentBalancingThread = null;
     } finally {
       lock.unlock();
     }
+
+    // wait for balancingThread to die
+    if (balancingThread != null &&

Review Comment:
   Can we add a preconditions check here that lock is not held by the current thread? There is an api for it.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/balancer/ContainerBalancer.java:
##########
@@ -839,20 +850,34 @@ private void resetState() {
   @Override
   public void notifyStatusChanged() {
     if (!scmContext.isLeader() || scmContext.isInSafeMode()) {
-      if (isBalancerRunning()) {
+      boolean shouldStop = false;
+
+      // lock here to ensure no change is made to the balancing thread while
+      // we're reading it
+      lock.lock();
+      try {
+        shouldStop = isBalancerRunning();

Review Comment:
   I would suggest merging the two lock sections and afterwards stop can be called.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org