ashishkumar50 commented on code in PR #10681:
URL: https://github.com/apache/ozone/pull/10681#discussion_r3568284234


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/balancer/ContainerBalancerTask.java:
##########
@@ -417,21 +430,85 @@ private long getCurrentIterationDuration() {
   /**
    * Logs the reason for stop and save configuration and stop the task.
    * 
-   * @param stopReason a string specifying the reason for stop
+   * @param reason stop reason
    */
-  private void tryStopWithSaveConfiguration(String stopReason) {
+  private void tryStopWithSaveConfiguration(ContainerBalancerStopReason 
reason) {
+    tryStopWithSaveConfiguration(reason, null);
+  }
+
+  /**
+   * Logs the reason for stop and save configuration and stop the task.
+   *
+   * @param reason stable stop reason code
+   * @param details optional details appended to the human-readable message
+   */
+  private void tryStopWithSaveConfiguration(ContainerBalancerStopReason 
reason, String details) {
     synchronized (this) {
       try {
-        LOG.info("Save Configuration for stopping. Reason: {}", stopReason);
         saveConfiguration(config, false, 0);
+        recordStopReason(reason, details);
+        LOG.info("Save Configuration for stopping. Reason: {}, Message: {}",
+            reason.name(), stopMessage);
         stop();
       } catch (IOException | TimeoutException e) {
         LOG.warn("Save configuration failed. Reason for " +
-            "stopping: {}", stopReason, e);
+                "stopping: {}", reason.name(), e);
       }
     }
   }
 
+  /**
+   * Records the reason why the balancer task is stopping.
+   *
+   * @param reason stop reason
+   */
+  public void recordStopReason(ContainerBalancerStopReason reason) {
+    recordStopReason(reason, null);
+  }
+
+  /**
+   * Records the reason why the balancer task is stopping.
+   *
+   * @param reason stop reason
+   * @param details optional details appended to the message
+   */
+  public void recordStopReason(ContainerBalancerStopReason reason, String 
details) {

Review Comment:
   This has to be synchronized or else two thread can enter and then reason and 
message can go different.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/balancer/ContainerBalancerTask.java:
##########
@@ -264,8 +277,8 @@ private void balance() {
           return;
         }
         // otherwise, try to stop balancer
-        tryStopWithSaveConfiguration("Could not initialize " +
-            "ContainerBalancer's iteration number " + i);
+        
tryStopWithSaveConfiguration(ContainerBalancerStopReason.INITIALIZATION_FAILED,

Review Comment:
   Add more descriptive reason why initialization failed? and not just 
INITIALIZATION_FAILED which is not useful for user. Get reason from 
`initializeIteration()`



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/balancer/ContainerBalancerStopReason.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdds.scm.container.balancer;
+
+/**
+ * Stop reason codes and messages for ContainerBalancer.
+ */
+public enum ContainerBalancerStopReason {
+  USER_REQUESTED("Stopped by user request."),
+  SCM_STATE_CHANGE("Stopped because SCM state changed."),
+  COMPLETED_ALL_ITERATIONS("Completed all configured number of iterations."),
+  CAN_NOT_BALANCE_ANY_MORE("No more eligible container moves were found."),
+  INITIALIZATION_FAILED("Failed to initialize a container balancer 
iteration."),
+  STOPPED("Stopped."),

Review Comment:
   What this `STOPPED` is for? If it is UNKNOWN, let it be with UNKNOWN.



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