This is an automated email from the ASF dual-hosted git repository.

nanda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 14db15cd67 HDDS-12376. Remove scmRatisEnabled from ScmInfo. (#7931)
14db15cd67 is described below

commit 14db15cd679c0c94c3dc04785037870119958c1e
Author: Nandakumar Vadivelu <[email protected]>
AuthorDate: Tue Mar 4 13:50:00 2025 +0530

    HDDS-12376. Remove scmRatisEnabled from ScmInfo. (#7931)
---
 .../java/org/apache/hadoop/hdds/scm/ScmInfo.java   | 30 ++--------
 .../apache/hadoop/hdds/scm/client/ScmClient.java   | 13 +----
 ...inerLocationProtocolClientSideTranslatorPB.java | 19 +------
 .../interface-client/src/main/proto/hdds.proto     |  1 -
 ...inerLocationProtocolServerSideTranslatorPB.java |  3 +-
 .../hdds/scm/server/SCMClientProtocolServer.java   | 17 +-----
 .../hdds/scm/cli/ContainerOperationClient.java     |  9 +--
 .../impl/StorageContainerServiceProviderImpl.java  | 64 +++++++---------------
 .../admin/scm/GetScmRatisRolesSubcommand.java      | 25 +++------
 .../ozone/scm/TestGetScmRatisRolesSubcommand.java  | 23 +-------
 10 files changed, 44 insertions(+), 160 deletions(-)

diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmInfo.java 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmInfo.java
index 5c43517e1d..93e1f8c1e0 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmInfo.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmInfo.java
@@ -29,7 +29,6 @@ public final class ScmInfo {
   private final String clusterId;
   private final String scmId;
   private final List<String> peerRoles;
-  private final boolean scmRatisEnabled;
 
   /**
    * Builder for ScmInfo.
@@ -38,7 +37,6 @@ public static class Builder {
     private String clusterId;
     private String scmId;
     private final List<String> peerRoles;
-    private boolean scmRatisEnabled;
 
     public Builder() {
       peerRoles = new ArrayList<>();
@@ -66,36 +64,23 @@ public Builder setScmId(String id) {
 
     /**
      * Set peer address in Scm HA.
-     * @param roles ratis peer address in the format of [ip|hostname]:port
+     * @param roles peer address in the format of [ip|hostname]:port
      * @return  Builder for scmInfo
      */
-    public Builder setRatisPeerRoles(List<String> roles) {
+    public Builder setPeerRoles(List<String> roles) {
       peerRoles.addAll(roles);
       return this;
     }
 
-    /**
-     * Set whether SCM enables Ratis.
-     *
-     * @param ratisEnabled If it is true, it means that the Ratis mode is 
turned on.
-     * If it is false, it means that the Ratis mode is not turned on.
-     * @return Builder for scmInfo
-     */
-    public Builder setScmRatisEnabled(boolean ratisEnabled) {
-      scmRatisEnabled = ratisEnabled;
-      return this;
-    }
-
     public ScmInfo build() {
-      return new ScmInfo(clusterId, scmId, peerRoles, scmRatisEnabled);
+      return new ScmInfo(clusterId, scmId, peerRoles);
     }
   }
 
-  private ScmInfo(String clusterId, String scmId, List<String> peerRoles, 
boolean ratisEnabled) {
+  private ScmInfo(String clusterId, String scmId, List<String> peerRoles) {
     this.clusterId = clusterId;
     this.scmId = scmId;
     this.peerRoles = Collections.unmodifiableList(peerRoles);
-    this.scmRatisEnabled = ratisEnabled;
   }
 
   /**
@@ -115,14 +100,11 @@ public String getScmId() {
   }
 
   /**
-   * Gets the list of peer roles (currently address) in Scm HA.
+   * Gets the list of peer roles (currently address) in SCM.
    * @return List of peer address
    */
-  public List<String> getRatisPeerRoles() {
+  public List<String> getPeerRoles() {
     return peerRoles;
   }
 
-  public boolean getScmRatisEnabled() {
-    return scmRatisEnabled;
-  }
 }
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/client/ScmClient.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/client/ScmClient.java
index 766d259450..c79b3123ef 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/client/ScmClient.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/client/ScmClient.java
@@ -389,18 +389,9 @@ StartContainerBalancerResponseProto startContainerBalancer(
   ContainerBalancerStatusInfoResponseProto getContainerBalancerStatusInfo() 
throws IOException;
 
   /**
-   * returns the list of ratis peer roles. Currently only include peer address.
+   * returns the list of SCM peer roles. Currently only include peer address.
    */
-  List<String> getScmRatisRoles() throws IOException;
-
-  /**
-   * Get the current SCM mode.
-   *
-   * @return `true` indicates that it is in RATIS mode,
-   * while `false` indicates that it is in STANDALONE mode.
-   * @throws IOException  an I/O exception of some sort has occurred.
-   */
-  boolean isScmRatisEnable() throws IOException;
+  List<String> getScmRoles() throws IOException;
 
   /**
    * Force generates new secret keys (rotate).
diff --git 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/protocolPB/StorageContainerLocationProtocolClientSideTranslatorPB.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/protocolPB/StorageContainerLocationProtocolClientSideTranslatorPB.java
index df1e483566..d5cbc979cf 100644
--- 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/protocolPB/StorageContainerLocationProtocolClientSideTranslatorPB.java
+++ 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/protocolPB/StorageContainerLocationProtocolClientSideTranslatorPB.java
@@ -771,24 +771,7 @@ public ScmInfo getScmInfo() throws IOException {
     ScmInfo.Builder builder = new ScmInfo.Builder()
         .setClusterId(resp.getClusterId())
         .setScmId(resp.getScmId())
-        .setRatisPeerRoles(resp.getPeerRolesList());
-
-    // By default, we assume that SCM Ratis is not enabled.
-
-    // If the response contains the `ScmRatisEnabled` field,
-    // we will set it directly; otherwise,
-    // we will determine if Ratis is enabled based on
-    // whether the `peerRolesList` contains the keywords 'leader' or 
'follower'.
-    if (resp.hasScmRatisEnabled()) {
-      builder.setScmRatisEnabled(resp.getScmRatisEnabled());
-    } else {
-      List<String> peerRolesList = resp.getPeerRolesList();
-      if (!peerRolesList.isEmpty()) {
-        boolean containsScmRoles = 
peerRolesList.stream().map(String::toLowerCase)
-            .anyMatch(scmRatisRolesToCheck::contains);
-        builder.setScmRatisEnabled(containsScmRoles);
-      }
-    }
+        .setPeerRoles(resp.getPeerRolesList());
     return builder.build();
   }
 
diff --git a/hadoop-hdds/interface-client/src/main/proto/hdds.proto 
b/hadoop-hdds/interface-client/src/main/proto/hdds.proto
index 28c8a71349..6cf58d3b1e 100644
--- a/hadoop-hdds/interface-client/src/main/proto/hdds.proto
+++ b/hadoop-hdds/interface-client/src/main/proto/hdds.proto
@@ -269,7 +269,6 @@ message GetScmInfoResponseProto {
     required string clusterId = 1;
     required string scmId = 2;
     repeated string peerRoles = 3;
-    optional bool scmRatisEnabled = 4;
 }
 
 message AddScmRequestProto {
diff --git 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/protocol/StorageContainerLocationProtocolServerSideTranslatorPB.java
 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/protocol/StorageContainerLocationProtocolServerSideTranslatorPB.java
index 8ead0501dd..b2722fe47a 100644
--- 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/protocol/StorageContainerLocationProtocolServerSideTranslatorPB.java
+++ 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/protocol/StorageContainerLocationProtocolServerSideTranslatorPB.java
@@ -1000,8 +1000,7 @@ public HddsProtos.GetScmInfoResponseProto getScmInfo(
     return HddsProtos.GetScmInfoResponseProto.newBuilder()
         .setClusterId(scmInfo.getClusterId())
         .setScmId(scmInfo.getScmId())
-        .addAllPeerRoles(scmInfo.getRatisPeerRoles())
-        .setScmRatisEnabled(scmInfo.getScmRatisEnabled())
+        .addAllPeerRoles(scmInfo.getPeerRoles())
         .build();
   }
 
diff --git 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java
 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java
index afaab94f02..376286c119 100644
--- 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java
+++ 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java
@@ -39,7 +39,6 @@
 import java.net.InetSocketAddress;
 import java.time.Duration;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -812,20 +811,8 @@ public ScmInfo getScmInfo() {
       ScmInfo.Builder builder =
           new ScmInfo.Builder()
               .setClusterId(scm.getScmStorageConfig().getClusterID())
-              .setScmId(scm.getScmStorageConfig().getScmId());
-      if (scm.getScmHAManager().getRatisServer() != null) {
-        builder.setRatisPeerRoles(
-            scm.getScmHAManager().getRatisServer().getRatisRoles());
-        builder.setScmRatisEnabled(true);
-      } else {
-        // In case, there is no ratis, there is no ratis role.
-        // This will just print the hostname with ratis port as the default
-        // behaviour.
-        String address = scm.getSCMHANodeDetails().getLocalNodeDetails()
-            .getRatisHostPortStr();
-        builder.setRatisPeerRoles(Arrays.asList(address));
-        builder.setScmRatisEnabled(false);
-      }
+              .setScmId(scm.getScmStorageConfig().getScmId())
+              
.setPeerRoles(scm.getScmHAManager().getRatisServer().getRatisRoles());
       return builder.build();
     } catch (Exception ex) {
       auditSuccess = false;
diff --git 
a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerOperationClient.java
 
b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerOperationClient.java
index afce9669fb..cae95d069b 100644
--- 
a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerOperationClient.java
+++ 
b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerOperationClient.java
@@ -532,13 +532,8 @@ public ContainerBalancerStatusInfoResponseProto 
getContainerBalancerStatusInfo()
   }
 
   @Override
-  public List<String> getScmRatisRoles() throws IOException {
-    return storageContainerLocationClient.getScmInfo().getRatisPeerRoles();
-  }
-
-  @Override
-  public boolean isScmRatisEnable() throws IOException {
-    return storageContainerLocationClient.getScmInfo().getScmRatisEnabled();
+  public List<String> getScmRoles() throws IOException {
+    return storageContainerLocationClient.getScmInfo().getPeerRoles();
   }
 
   @Override
diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/StorageContainerServiceProviderImpl.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/StorageContainerServiceProviderImpl.java
index 06dfb973a5..d2757035c0 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/StorageContainerServiceProviderImpl.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/StorageContainerServiceProviderImpl.java
@@ -29,7 +29,6 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.List;
@@ -60,7 +59,6 @@
 import org.apache.hadoop.ozone.recon.scm.ReconStorageConfig;
 import org.apache.hadoop.ozone.recon.security.ReconCertificateClient;
 import org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider;
-import org.apache.hadoop.security.SecurityUtil;
 import org.apache.ratis.proto.RaftProtos;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -184,39 +182,30 @@ public DBCheckpoint getSCMDBSnapshot() {
         ".tar");
     try {
       try {
-        List<String> ratisRoles = scmClient.getScmInfo().getRatisPeerRoles();
+        List<String> ratisRoles = scmClient.getScmInfo().getPeerRoles();
         for (String ratisRole : ratisRoles) {
           String[] role = ratisRole.split(":");
-          // This explicit role length check is to support older versions 
where we cannot change the default value
-          // without breaking backward compatibility during upgrade, because 
if Ratis is not enabled then the roles
-          // command output is generated outside of Ratis. It will not have 
the Ratis terminologies.
-          if (role.length > 2) {
-            if (role[2].equals(RaftProtos.RaftPeerRole.LEADER.toString())) {
-              String hostAddress = role[4].trim();
-              int grpcPort = configuration.getInt(
-                  ScmConfigKeys.OZONE_SCM_GRPC_PORT_KEY,
-                  ScmConfigKeys.OZONE_SCM_GRPC_PORT_DEFAULT);
-
-              SecurityConfig secConf = new SecurityConfig(configuration);
-              SCMSecurityProtocolClientSideTranslatorPB scmSecurityClient =
-                  getScmSecurityClientWithMaxRetry(
-                      configuration, getCurrentUser());
-              try (ReconCertificateClient certClient =
-                       new ReconCertificateClient(
-                           secConf, scmSecurityClient, reconStorage, null, 
null);
-                   SCMSnapshotDownloader downloadClient = new 
InterSCMGrpcClient(
-                       hostAddress, grpcPort, configuration, certClient)) {
-                downloadClient.download(targetFile.toPath()).get();
-              } catch (ExecutionException | InterruptedException e) {
-                LOG.error("Rocks DB checkpoint downloading failed: {}", e);
-                throw new IOException(e);
-              }
-              LOG.info("Downloaded SCM Snapshot from Leader SCM");
-              break;
+          if (role[2].equals(RaftProtos.RaftPeerRole.LEADER.toString())) {
+            String hostAddress = role[4].trim();
+            int grpcPort = configuration.getInt(
+                ScmConfigKeys.OZONE_SCM_GRPC_PORT_KEY,
+                ScmConfigKeys.OZONE_SCM_GRPC_PORT_DEFAULT);
+
+            SecurityConfig secConf = new SecurityConfig(configuration);
+            SCMSecurityProtocolClientSideTranslatorPB scmSecurityClient =
+                getScmSecurityClientWithMaxRetry(
+                    configuration, getCurrentUser());
+            try (ReconCertificateClient certClient =
+                     new ReconCertificateClient(
+                         secConf, scmSecurityClient, reconStorage, null, null);
+                 SCMSnapshotDownloader downloadClient = new InterSCMGrpcClient(
+                     hostAddress, grpcPort, configuration, certClient)) {
+              downloadClient.download(targetFile.toPath()).get();
+            } catch (ExecutionException | InterruptedException e) {
+              LOG.error("Rocks DB checkpoint downloading failed: {}", e);
+              throw new IOException(e);
             }
-          } else {
-            fetchSCMDBSnapshotUsingHttpClient(targetFile);
-            LOG.info("Downloaded SCM Snapshot from SCM");
+            LOG.info("Downloaded SCM Snapshot from Leader SCM");
             break;
           }
         }
@@ -233,17 +222,6 @@ public DBCheckpoint getSCMDBSnapshot() {
     return null;
   }
 
-  private void fetchSCMDBSnapshotUsingHttpClient(File targetFile) throws 
IOException {
-    SecurityUtil.doAsLoginUser(() -> {
-      try (InputStream inputStream = reconUtils.makeHttpCall(
-          connectionFactory, getScmDBSnapshotUrl(),
-          isOmSpnegoEnabled()).getInputStream()) {
-        FileUtils.copyInputStreamToFile(inputStream, targetFile);
-      }
-      return null;
-    });
-  }
-
   @NotNull
   private RocksDBCheckpoint getRocksDBCheckpoint(String snapshotFileName, File 
targetFile) throws IOException {
     Path untarredDbDir = Paths.get(scmSnapshotDBParentDir.getAbsolutePath(),
diff --git 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java
 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java
index 3692d475f3..da3076306d 100644
--- 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java
+++ 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java
@@ -58,30 +58,21 @@ public class GetScmRatisRolesSubcommand extends 
ScmSubcommand {
 
   private static final String SCM_ROLES_TITLE = "Storage Container Manager 
Roles";
 
-  private static final List<String> RATIS_SCM_ROLES_HEADER = Arrays.asList(
+  private static final List<String> SCM_ROLES_HEADER = Arrays.asList(
       "Host Name", "Ratis Port", "Role",  "Node ID", "Host Address");
 
-  private static final List<String> STANDALONE_SCM_ROLES_HEADER = 
Arrays.asList("Host Name", "Port");
-
   @Override
   public void execute(ScmClient scmClient) throws IOException {
-    List<String> ratisRoles = scmClient.getScmRatisRoles();
-    boolean isRatisEnabled = scmClient.isScmRatisEnable();
+    List<String> peerRoles = scmClient.getScmRoles();
     if (json) {
-      Map<String, Map<String, String>> scmRoles = parseScmRoles(ratisRoles);
+      Map<String, Map<String, String>> scmRoles = parseScmRoles(peerRoles);
       System.out.print(
           JsonUtils.toJsonStringWithDefaultPrettyPrinter(scmRoles));
     } else if (table) {
       FormattingCLIUtils formattingCLIUtils = new 
FormattingCLIUtils(SCM_ROLES_TITLE);
+      formattingCLIUtils.addHeaders(SCM_ROLES_HEADER);
 
-      // Determine which header to use based on whether Ratis is enabled or 
not.
-      if (isRatisEnabled) {
-        formattingCLIUtils.addHeaders(RATIS_SCM_ROLES_HEADER);
-      } else {
-        formattingCLIUtils.addHeaders(STANDALONE_SCM_ROLES_HEADER);
-      }
-
-      for (String role : ratisRoles) {
+      for (String role : peerRoles) {
         String[] roleItems = role.split(":");
         if (roleItems.length < 2) {
           err.println("Invalid response received for ScmRatisRoles.");
@@ -90,16 +81,16 @@ public void execute(ScmClient scmClient) throws IOException 
{
       }
       System.out.println(formattingCLIUtils.render());
     } else {
-      for (String role: ratisRoles) {
+      for (String role: peerRoles) {
         System.out.println(role);
       }
     }
   }
 
   private Map<String, Map<String, String>> parseScmRoles(
-      List<String> ratisRoles) {
+      List<String> peerRoles) {
     Map<String, Map<String, String>> allRoles = new HashMap<>();
-    for (String role : ratisRoles) {
+    for (String role : peerRoles) {
       Map<String, String> roleDetails = new HashMap<>();
       String[] roles = role.split(":");
       if (roles.length < 2) {
diff --git 
a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/scm/TestGetScmRatisRolesSubcommand.java
 
b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/scm/TestGetScmRatisRolesSubcommand.java
index a8ba590536..c622a1ff3d 100644
--- 
a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/scm/TestGetScmRatisRolesSubcommand.java
+++ 
b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/scm/TestGetScmRatisRolesSubcommand.java
@@ -47,8 +47,7 @@ public void testGetScmHARatisRoles() throws Exception {
     
result.add("bigdata-ozone-online32:9894:LEADER:e428ca07-b2a3-4756-bf9b-a4abb033c7d1:100.3.192.89");
     
result.add("bigdata-ozone-online30:9894:FOLLOWER:41f90734-b3ee-4284-ad96-40a286654952:100.3.196.51");
 
-    when(client.getScmRatisRoles()).thenAnswer(invocation -> result);
-    when(client.isScmRatisEnable()).thenAnswer(invocation -> true);
+    when(client.getScmRoles()).thenAnswer(invocation -> result);
 
     try (GenericTestUtils.SystemOutCapturer capture =
         new GenericTestUtils.SystemOutCapturer()) {
@@ -62,24 +61,4 @@ public void testGetScmHARatisRoles() throws Exception {
     }
   }
 
-  @Test
-  public void testGetScmStandAloneRoles() throws Exception {
-
-    GetScmRatisRolesSubcommand cmd = new GetScmRatisRolesSubcommand();
-    ScmClient client = mock(ScmClient.class);
-    CommandLine c = new CommandLine(cmd);
-    c.parseArgs("--table");
-
-    List<String> result = new ArrayList<>();
-    result.add("bigdata-ozone-online31:9894");
-
-    when(client.getScmRatisRoles()).thenAnswer(invocation -> result);
-    when(client.isScmRatisEnable()).thenAnswer(invocation -> false);
-
-    try (GenericTestUtils.SystemOutCapturer capture =
-        new GenericTestUtils.SystemOutCapturer()) {
-      cmd.execute(client);
-      assertThat(capture.getOutput()).contains("| bigdata-ozone-online31 | 
9894 |");
-    }
-  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to