smengcl commented on code in PR #11954:
URL: https://github.com/apache/ozone/pull/11954#discussion_r4491275984
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/StorageContainerServiceProviderImpl.java:
##########
@@ -183,9 +204,121 @@ 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);
}
+ private void downloadSCMDBCheckpointOverGrpc(String hostAddress, File
targetFile, SecurityConfig secConf)
+ throws IOException {
+ int grpcPort =
+ configuration.getInt(ScmConfigKeys.OZONE_SCM_GRPC_PORT_KEY,
ScmConfigKeys.OZONE_SCM_GRPC_PORT_DEFAULT);
+ 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);
+ }
+ }
+
+ /**
+ * Downloads the SCM DB checkpoint over HTTP(S), authenticated with SPNEGO
when SCM requires it.
+ * Used when gRPC TLS is enabled, because the inter-SCM gRPC server then
accepts SCM certificates only.
+ */
+ private void downloadSCMDBCheckpoint(String url, File targetFile) throws
IOException {
+ LOG.info("Downloading SCM DB checkpoint from {}", url);
+ int connectTimeout = (int)
configuration.getTimeDuration(OZONE_RECON_SCM_SNAPSHOT_CONNECTION_TIMEOUT,
+ OZONE_RECON_SCM_SNAPSHOT_CONNECTION_TIMEOUT_DEFAULT,
TimeUnit.MILLISECONDS);
+ int readTimeout = (int)
configuration.getTimeDuration(OZONE_RECON_SCM_SNAPSHOT_READ_TIMEOUT,
+ OZONE_RECON_SCM_SNAPSHOT_READ_TIMEOUT_DEFAULT, TimeUnit.MILLISECONDS);
+ URLConnectionFactory connectionFactory =
+ URLConnectionFactory.newDefaultURLConnectionFactory(connectTimeout,
readTimeout, configuration);
+ boolean spnegoEnabled =
"kerberos".equals(configuration.get(HDDS_SCM_HTTP_AUTH_TYPE, "simple"));
+ AtomicBoolean cancelled = new AtomicBoolean();
+ // Download in another thread, so that the sync can return as soon as it
is cancelled (interrupted).
+ ExecutorService executor = Executors.newSingleThreadExecutor(
+ new
ThreadFactoryBuilder().setNameFormat("ReconSCMDBDownload-%d").setDaemon(true).build());
+ Future<?> download = executor.submit(() -> SecurityUtil.doAsLoginUser(()
-> {
+ HttpURLConnection connection = null;
+ try {
+ connection = reconUtils.makeHttpCall(connectionFactory, url,
spnegoEnabled);
+ try (InputStream in = connection.getInputStream();
+ OutputStream out = Files.newOutputStream(targetFile.toPath())) {
+ byte[] buffer = new byte[IOUtils.DEFAULT_BUFFER_SIZE];
+ for (int n; (n = in.read(buffer)) != -1;) {
+ if (cancelled.get()) {
+ throw new InterruptedIOException("SCM DB checkpoint download
cancelled");
+ }
+ out.write(buffer, 0, n);
+ }
+ }
+ } catch (Exception e) {
+ FileUtils.deleteQuietly(targetFile);
+ throw e;
+ } finally {
Review Comment:
Good catch, done in a2404a37e7c: the download thread now also deletes the
target in its `finally` when cancelled. The stalled-download test is now
parameterized, and the new case cancels before SCM responds and then gets an
empty body. It fails without the fix and passes with it.
_🤖 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]