GeorgeJahad commented on code in PR #3980:
URL: https://github.com/apache/ozone/pull/3980#discussion_r1131547663


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBCheckpointServlet.java:
##########
@@ -82,4 +112,165 @@ public void init() throws ServletException {
         allowedGroups,
         om.isSpnegoEnabled());
   }
+
+  @Override
+  public void writeDbDataToStream(DBCheckpoint checkpoint,
+                                  HttpServletRequest request,
+                                  OutputStream destination)
+      throws IOException, InterruptedException, CompressorException {
+    // Map of inodes to path
+    HashMap<Object, Path> copyFiles = new HashMap<>();
+    // Map of link to path
+    HashMap<Path, Path> hardLinkFiles = new HashMap<>();
+
+    getFilesForArchive(checkpoint, copyFiles, hardLinkFiles,
+        includeSnapshotData(request));
+
+    try (CompressorOutputStream gzippedOut = new CompressorStreamFactory()
+        .createCompressorOutputStream(CompressorStreamFactory.GZIP,
+            destination)) {
+
+      try (TarArchiveOutputStream archiveOutputStream =
+          new TarArchiveOutputStream(gzippedOut)) {
+        archiveOutputStream
+            .setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
+
+        writeFilesToArchive(copyFiles, hardLinkFiles, archiveOutputStream);
+      }
+    } catch (CompressorException e) {
+      throw new IOException(
+          "Can't compress the checkpoint: " +
+              checkpoint.getCheckpointLocation(), e);
+    }
+  }
+
+  private void getFilesForArchive(DBCheckpoint checkpoint,
+                                  Map<Object, Path> copyFiles,
+                                  Map<Path, Path> hardLinkFiles,
+                                  boolean includeSnapshotData)
+      throws IOException, InterruptedException {
+
+    // Get the active fs files
+    Path dir = checkpoint.getCheckpointLocation();
+    processDir(dir, copyFiles, hardLinkFiles);
+
+    if (!includeSnapshotData) {
+      return;
+    }
+
+    // Get the snapshot files
+    waitForSnapshotDirs(checkpoint);
+    Path snapshotDir = Paths.get(OMStorage.getOmDbDir(getConf()).toString(),
+        OM_SNAPSHOT_DIR);
+    processDir(snapshotDir, copyFiles, hardLinkFiles);
+  }
+
+  // The snapshotInfo table may contain a snapshot that
+  //  doesn't yet exist on the fs, so wait a few seconds for it
+  private void waitForSnapshotDirs(DBCheckpoint checkpoint)
+      throws IOException, InterruptedException {
+
+    OzoneConfiguration conf = getConf();
+
+    // get snapshotInfo entries
+    OmMetadataManagerImpl checkpointMetadataManager =
+        OmMetadataManagerImpl.createCheckpointMetadataManager(
+            conf, checkpoint);
+    try (TableIterator<String, ? extends Table.KeyValue<String, SnapshotInfo>>
+        iterator = checkpointMetadataManager
+        .getSnapshotInfoTable().iterator()) {
+
+      // for each entry, wait for corresponding directory
+      while (iterator.hasNext()) {
+        Table.KeyValue<String, SnapshotInfo> entry = iterator.next();
+        Path path = Paths.get(getSnapshotPath(conf, entry.getValue()));
+        waitForDirToExist(path);
+      }
+    }
+  }
+
+  private void waitForDirToExist(Path dir)
+      throws IOException, InterruptedException {
+    long endTime = System.currentTimeMillis() +
+        Duration.parse(DURATION_TO_WAIT_FOR_DIRECTORY).toMillis();
+    while (!dir.toFile().exists()) {
+      Thread.sleep(100);
+      if (System.currentTimeMillis() > endTime) {
+        break;
+      }
+    }
+    if (System.currentTimeMillis() > endTime) {
+      throw new IOException("snapshot dir doesn't exist: " + dir);

Review Comment:
   fixed (now line 198)



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