sreejasahithi commented on code in PR #9376:
URL: https://github.com/apache/ozone/pull/9376#discussion_r2668760107


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/SCMSafeModeManager.java:
##########
@@ -225,6 +244,97 @@ public double getCurrentContainerThreshold() {
         .getCurrentContainerThreshold();
   }
 
+  private synchronized void startSafeModePeriodicLogger() {
+    if (!getInSafeMode()) {
+      return;
+    }
+    if (safeModeLogExecutor == null) {
+      safeModeLogExecutor = Executors.newScheduledThreadPool(1,
+          new ThreadFactoryBuilder()
+              .setNameFormat(scmContext.threadNamePrefix() + 
"SCM-SafeMode-Log-%d")
+              .setDaemon(true)
+              .build());
+    }
+
+    if (safeModeLogTask != null && !safeModeLogTask.isDone()) {
+      safeModeLogTask.cancel(false);
+    }
+    safeModeLogTask = safeModeLogExecutor.scheduleAtFixedRate(() -> {
+      try {
+        logSafeModeStatus();
+      } catch (Throwable t) {
+        LOG.warn("Safe mode periodic logger encountered an error", t);
+      }
+    }, 0L, safeModeLogIntervalMs, TimeUnit.MILLISECONDS);
+    LOG.info("Started periodic Safe Mode logging with interval {} ms", 
safeModeLogIntervalMs);
+  }
+
+  private synchronized void logSafeModeStatus() {
+    SafeModeStatus safeModeStatus = status.get();
+    int validatedCount = validatedRules.size();
+    int preCheckValidatedCount = validatedPreCheckRules.size();
+    StringBuilder statusLog = new StringBuilder();
+    statusLog.append(String.format(
+        "%nSCM SafeMode Status | state=%s preCheckComplete=%s 
validatedPreCheckRules=%d/%d validatedRules=%d/%d",
+        safeModeStatus.isInSafeMode() ? 
+            (safeModeStatus.isPreCheckComplete() ? "PRE_CHECKS_PASSED" : 
"INITIAL") : "OUT_OF_SAFE_MODE",
+        safeModeStatus.isPreCheckComplete(), preCheckValidatedCount, 
preCheckRules.size(), validatedCount,
+        exitRules.size()));
+    
+    for (SafeModeExitRule<?> rule : exitRules.values()) {
+      String name = rule.getRuleName();
+      boolean isValidated = validatedRules.contains(name);
+      String statusText = rule.getStatusText();
+      
+      if (statusText.endsWith(";")) {
+        statusText = statusText.substring(0, statusText.length() - 1);
+      }
+
+      statusLog.append(String.format("%nSCM SafeMode Status | %s (%s) %s",
+          name,
+          isValidated ? "validated" : "waiting",
+          statusText));
+    }
+
+    LOG.info(statusLog.toString());
+    if (!getInSafeMode()) {
+      stopSafeModePeriodicLogger();
+    }
+  }
+
+  private synchronized void stopSafeModePeriodicLogger() {

Review Comment:
   yes , this is already satisfied for normal exit in validateSafeModeExitRules:
   ```
   if (validatedRules.size() == exitRules.size()
           && status.compareAndSet(SafeModeStatus.PRE_CHECKS_PASSED, 
SafeModeStatus.OUT_OF_SAFE_MODE)) {
         logSafeModeStatus(); <-- by making a call here
   ```
   will add similarly for force exit as well.



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