aryangupta1998 commented on code in PR #9611:
URL: https://github.com/apache/ozone/pull/9611#discussion_r2711408445


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java:
##########
@@ -1033,6 +1033,42 @@ public Map<String, Pair<Boolean, String>> 
getSafeModeRuleStatuses()
     }
   }
 
+  @Override
+  public boolean inSafeModeForNode(String nodeId) throws IOException {
+    Map<String, String> auditMap = Maps.newHashMap();
+    auditMap.put("nodeId", nodeId);
+    try {
+      boolean result = inSafeMode();

Review Comment:
   ```suggestion
         boolean result = scm.isInSafeMode();
   ```
   It’s better to use `scm.isInSafeMode()` instead of `inSafeMode()`, since 
inSafeMode() is a generic API and may evolve in the future (for example, to 
include leader-level logic). Using scm.isInSafeMode() makes it explicit that we 
are returning the local SCM node’s safe mode state.



##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/SafeModeCheckSubcommand.java:
##########
@@ -33,24 +42,181 @@
     mixinStandardHelpOptions = true,
     versionProvider = HddsVersionProvider.class)
 public class SafeModeCheckSubcommand extends ScmSubcommand {
+  @CommandLine.Option(names = {"--all", "-a"},
+      description = "Show safe mode status for all SCM nodes in the service. " 
+
+          "When multiple SCM service IDs are configured, --service-id must be 
specified.")
+  private boolean allNodes;
+
+  private String serviceId;
+  private List<SCMNodeInfo> nodes;
 
   @Override
   public void execute(ScmClient scmClient) throws IOException {
-    boolean execReturn = scmClient.inSafeMode();
+    OzoneConfiguration conf = getOzoneConf();
+    serviceId = HddsUtils.getScmServiceId(conf);
+    String scmAddress = getScmOption().getScm();
+    if (serviceId != null) {
+      nodes = SCMNodeInfo.buildNodeInfo(conf);
+    }
+    
+    if (allNodes) {
+      executeForAllNodes(scmClient);
+    } else if (StringUtils.isNotEmpty(scmAddress)) {
+      executeForSpecificNode(scmClient, scmAddress);
+    } else {
+      executeForSingleNode(scmClient);
+    }
+  }
+
+  private void executeForSingleNode(ScmClient scmClient) throws IOException {
+    boolean inSafeMode;
+    Map<String, Pair<Boolean, String>> rules = null;
+    String leaderNodeId;
 
-    // Output data list
-    if (execReturn) {
+    // If SCM HA mode, query the leader node.
+    if (serviceId != null) {
+      leaderNodeId = findLeaderNodeId(scmClient);

Review Comment:
   ```suggestion
         leaderNodeId = findLeaderNodeId(scmClient);
   if (leaderNodeId == null) {
     throw new IOException("Unable to determine SCM leader for the service");
   }
   ```



##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/protocol/StorageContainerLocationProtocol.java:
##########
@@ -73,6 +73,14 @@ public interface StorageContainerLocationProtocol extends 
Closeable {
       Type.StopReplicationManager,
       Type.ForceExitSafeMode));
 
+  /**
+   * Read-only commands that can execute on followers without leader check.
+   * These commands respect the --scm parameter and query the specified SCM.
+   */
+  Set<Type> FOLLOWER_READABLE_COMMAND_TYPE = 
Collections.unmodifiableSet(EnumSet.of(

Review Comment:
   nit: FOLLOWER_READABLE_COMMAND_TYPES



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