smengcl commented on code in PR #11954:
URL: https://github.com/apache/ozone/pull/11954#discussion_r4486296912


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/StorageContainerServiceProviderImpl.java:
##########
@@ -183,9 +171,63 @@ private RocksDBCheckpoint getRocksDBCheckpoint(String 
snapshotFileName, File tar
         snapshotFileName);
     reconUtils.untarCheckpointFile(targetFile, untarredDbDir);
     FileUtils.deleteQuietly(targetFile);
+    // SCM writes this flag last, so a checkpoint without it was cut short.
+    if (!ratisSnapshotComplete(untarredDbDir)) {
+      FileUtils.deleteQuietly(untarredDbDir.toFile());
+      throw new IOException("Incomplete SCM DB checkpoint: " + 
OZONE_RATIS_SNAPSHOT_COMPLETE_FLAG_NAME + " not found");
+    }
     return new RocksDBCheckpoint(untarredDbDir);
   }
 
+  /**
+   * Downloads the SCM DB checkpoint over HTTP(S), authenticated with SPNEGO 
when SCM requires it.
+   * SCM's inter-SCM gRPC endpoint is not used, because it accepts SCM 
certificates only.
+   */
+  private void downloadSCMDBCheckpoint(String url, File targetFile) throws 
IOException {
+    LOG.info("Downloading SCM DB checkpoint from {}", url);
+    URLConnectionFactory connectionFactory = 
URLConnectionFactory.newDefaultURLConnectionFactory(configuration);
+    boolean spnegoEnabled = 
"kerberos".equals(configuration.get(HDDS_SCM_HTTP_AUTH_TYPE, "simple"));
+    try {
+      SecurityUtil.doAsLoginUser(() -> {
+        try (InputStream inputStream = 
reconUtils.makeHttpCall(connectionFactory, url, spnegoEnabled)
+            .getInputStream()) {
+          FileUtils.copyInputStreamToFile(inputStream, targetFile);
+        }
+        return null;
+      });
+    } finally {
+      connectionFactory.destroy();
+    }
+  }
+
+  /**
+   * Returns the DB checkpoint URL of the SCM at {@code host}. The HTTP(S) 
port is taken from the address configured
+   * for the SCM node with that host, else from the common SCM HTTP(S) address.
+   */
+  private String getSCMDBCheckpointUrl(String host) {
+    boolean httpsEnabled = 
HttpConfig.getHttpPolicy(configuration).isHttpsEnabled();
+    SecurityConfig securityConfig = new SecurityConfig(configuration);
+    if (!httpsEnabled && securityConfig.isSecurityEnabled() && 
securityConfig.isGrpcTlsEnabled()) {
+      LOG.warn("Downloading the SCM DB unencrypted over HTTP although {} is 
true. Set {} to HTTPS_ONLY or "
+          + "HTTP_AND_HTTPS to encrypt it.", HDDS_GRPC_TLS_ENABLED, 
OZONE_HTTP_POLICY_KEY);
+    }
+    String addressKey = httpsEnabled ? OZONE_SCM_HTTPS_ADDRESS_KEY : 
OZONE_SCM_HTTP_ADDRESS_KEY;
+    List<String> addressKeys = new ArrayList<>();
+    String serviceId = HddsUtils.getScmServiceId(configuration);
+    if (serviceId != null) {
+      for (String nodeId : HddsUtils.getSCMNodeIds(configuration, serviceId)) {
+        if 
(host.equals(configuration.getTrimmed(ConfUtils.addKeySuffixes(OZONE_SCM_ADDRESS_KEY,
 serviceId, nodeId)))) {

Review Comment:
   Fixed in 10dcffb3b55: the configured SCM address is now parsed with 
`HddsUtils.getHostName`/`getHostPort`, so a `host:port` value matches. 
`testGetSCMDBSnapshotUsesLeaderHttpAddress` now has a `host:port` node.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/StorageContainerServiceProviderImpl.java:
##########
@@ -183,9 +171,63 @@ private RocksDBCheckpoint getRocksDBCheckpoint(String 
snapshotFileName, File tar
         snapshotFileName);
     reconUtils.untarCheckpointFile(targetFile, untarredDbDir);
     FileUtils.deleteQuietly(targetFile);
+    // SCM writes this flag last, so a checkpoint without it was cut short.
+    if (!ratisSnapshotComplete(untarredDbDir)) {
+      FileUtils.deleteQuietly(untarredDbDir.toFile());
+      throw new IOException("Incomplete SCM DB checkpoint: " + 
OZONE_RATIS_SNAPSHOT_COMPLETE_FLAG_NAME + " not found");
+    }
     return new RocksDBCheckpoint(untarredDbDir);
   }
 
+  /**
+   * Downloads the SCM DB checkpoint over HTTP(S), authenticated with SPNEGO 
when SCM requires it.
+   * SCM's inter-SCM gRPC endpoint is not used, because it accepts SCM 
certificates only.
+   */
+  private void downloadSCMDBCheckpoint(String url, File targetFile) throws 
IOException {
+    LOG.info("Downloading SCM DB checkpoint from {}", url);
+    URLConnectionFactory connectionFactory = 
URLConnectionFactory.newDefaultURLConnectionFactory(configuration);
+    boolean spnegoEnabled = 
"kerberos".equals(configuration.get(HDDS_SCM_HTTP_AUTH_TYPE, "simple"));
+    try {
+      SecurityUtil.doAsLoginUser(() -> {
+        try (InputStream inputStream = 
reconUtils.makeHttpCall(connectionFactory, url, spnegoEnabled)
+            .getInputStream()) {
+          FileUtils.copyInputStreamToFile(inputStream, targetFile);
+        }
+        return null;
+      });
+    } finally {
+      connectionFactory.destroy();
+    }
+  }
+
+  /**
+   * Returns the DB checkpoint URL of the SCM at {@code host}. The HTTP(S) 
port is taken from the address configured
+   * for the SCM node with that host, else from the common SCM HTTP(S) address.
+   */
+  private String getSCMDBCheckpointUrl(String host) {
+    boolean httpsEnabled = 
HttpConfig.getHttpPolicy(configuration).isHttpsEnabled();
+    SecurityConfig securityConfig = new SecurityConfig(configuration);
+    if (!httpsEnabled && securityConfig.isSecurityEnabled() && 
securityConfig.isGrpcTlsEnabled()) {
+      LOG.warn("Downloading the SCM DB unencrypted over HTTP although {} is 
true. Set {} to HTTPS_ONLY or "
+          + "HTTP_AND_HTTPS to encrypt it.", HDDS_GRPC_TLS_ENABLED, 
OZONE_HTTP_POLICY_KEY);
+    }
+    String addressKey = httpsEnabled ? OZONE_SCM_HTTPS_ADDRESS_KEY : 
OZONE_SCM_HTTP_ADDRESS_KEY;
+    List<String> addressKeys = new ArrayList<>();
+    String serviceId = HddsUtils.getScmServiceId(configuration);
+    if (serviceId != null) {
+      for (String nodeId : HddsUtils.getSCMNodeIds(configuration, serviceId)) {
+        if 
(host.equals(configuration.getTrimmed(ConfUtils.addKeySuffixes(OZONE_SCM_ADDRESS_KEY,
 serviceId, nodeId)))) {
+          addressKeys.add(ConfUtils.addKeySuffixes(addressKey, serviceId, 
nodeId));

Review Comment:
   Fixed in 10dcffb3b55: the leader node is now matched by host and Ratis port 
(taken from `ozone.scm.address` or `ozone.scm.ratis.port`, as 
`SCMHANodeDetails` does), so SCMs sharing a host resolve to their own HTTP(S) 
address. The test now puts two SCMs on one host.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



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