ChenSammi commented on code in PR #4294:
URL: https://github.com/apache/ozone/pull/4294#discussion_r1174756654
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis_snapshot/OmRatisSnapshotProvider.java:
##########
@@ -115,78 +109,64 @@ public OmRatisSnapshotProvider(MutableConfigurationSource
conf,
}
/**
- * Download the latest checkpoint from OM Leader via HTTP.
- * @param leaderOMNodeID leader OM Node ID.
- * @return the DB checkpoint (including the ratis snapshot index)
+ * When a new OM is bootstrapped, add it to the peerNode map.
*/
- public DBCheckpoint getOzoneManagerDBSnapshot(String leaderOMNodeID)
- throws IOException {
- String snapshotTime = Long.toString(System.currentTimeMillis());
- String snapshotFileName = OM_DB_NAME + "-" + leaderOMNodeID
- + "-" + snapshotTime;
- String snapshotFilePath = Paths.get(omSnapshotDir.getAbsolutePath(),
- snapshotFileName).toFile().getAbsolutePath();
- File targetFile = new File(snapshotFilePath + ".tar");
+ public void addNewPeerNode(OMNodeDetails newOMNode) {
+ peerNodesMap.put(newOMNode.getNodeId(), newOMNode);
+ }
- String omCheckpointUrl = peerNodesMap.get(leaderOMNodeID)
- .getOMDBCheckpointEnpointUrl(httpPolicy.isHttpEnabled());
+ /**
+ * When an OM is decommissioned, remove it from the peerNode map.
+ */
+ public void removeDecommissionedPeerNode(String decommNodeId) {
+ peerNodesMap.remove(decommNodeId);
+ }
+ @Override
+ public void downloadSnapshot(String leaderNodeID, File targetFile)
+ throws IOException {
+ OMNodeDetails leader = peerNodesMap.get(leaderNodeID);
+ URL omCheckpointUrl = leader.getOMDBCheckpointEndpointUrl(
+ httpPolicy.isHttpEnabled(), true,
+ HAUtils.getExistingSstFiles(getCandidateDir()));
LOG.info("Downloading latest checkpoint from Leader OM {}. Checkpoint " +
- "URL: {}", leaderOMNodeID, omCheckpointUrl);
+ "URL: {}", leaderNodeID, omCheckpointUrl);
SecurityUtil.doAsCurrentUser(() -> {
- HttpURLConnection httpURLConnection = (HttpURLConnection)
- connectionFactory.openConnection(new URL(omCheckpointUrl),
- spnegoEnabled);
- httpURLConnection.connect();
- int errorCode = httpURLConnection.getResponseCode();
+ HttpURLConnection connection = (HttpURLConnection)
+ connectionFactory.openConnection(omCheckpointUrl, spnegoEnabled);
+ connection.setRequestMethod("GET");
+ connection.connect();
+ int errorCode = connection.getResponseCode();
if ((errorCode != HTTP_OK) && (errorCode != HTTP_CREATED)) {
throw new IOException("Unexpected exception when trying to reach " +
"OM to download latest checkpoint. Checkpoint URL: " +
omCheckpointUrl + ". ErrorCode: " + errorCode);
}
- try (InputStream inputStream = httpURLConnection.getInputStream()) {
+ try (InputStream inputStream = connection.getInputStream()) {
FileUtils.copyInputStreamToFile(inputStream, targetFile);
} catch (IOException ex) {
- LOG.error("OM snapshot {} cannot be downloaded.", targetFile, ex);
boolean deleted = FileUtils.deleteQuietly(targetFile);
if (!deleted) {
LOG.error("OM snapshot which failed to download {} cannot be
deleted",
targetFile);
}
+ throw ex;
+ } finally {
+ connection.disconnect();
}
return null;
});
-
- // Untar the checkpoint file.
- Path untarredDbDir = Paths.get(snapshotFilePath);
- FileUtil.unTar(targetFile, untarredDbDir.toFile());
- FileUtils.deleteQuietly(targetFile);
-
- LOG.info("Successfully downloaded latest checkpoint from leader OM: {}",
- leaderOMNodeID);
-
- RocksDBCheckpoint omCheckpoint = new RocksDBCheckpoint(untarredDbDir);
- return omCheckpoint;
}
- public void stop() {
+ @Override
+ public void close() throws IOException {
if (connectionFactory != null) {
connectionFactory.destroy();
}
}
- /**
- * When a new OM is bootstrapped, add it to the peerNode map.
- */
- public void addNewPeerNode(OMNodeDetails newOMNode) {
- peerNodesMap.put(newOMNode.getNodeId(), newOMNode);
- }
-
- /**
- * When an OM is decommissioned, remove it from the peerNode map.
- */
- public void removeDecommissionedPeerNode(String decommNodeId) {
- peerNodesMap.remove(decommNodeId);
+ public void stop() throws IOException {
Review Comment:
We can remove this duplicate stop function, call close instead.
--
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]