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

chungen 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 6c3558fa35f HDDS-14629. Code cleanup after HDDS-13906 (#9773)
6c3558fa35f is described below

commit 6c3558fa35f74ce18d9e507793a8f1c52b09a416
Author: Russole <[email protected]>
AuthorDate: Mon Feb 23 23:11:56 2026 +0800

    HDDS-14629. Code cleanup after HDDS-13906 (#9773)
---
 .../org/apache/hadoop/ozone/om/OMDBArchiver.java   | 12 ++----
 .../om/OMDBCheckpointServletInodeBasedXfer.java    | 48 ++++++++++++----------
 .../apache/hadoop/ozone/om/TestOMDBArchiver.java   |  7 +---
 3 files changed, 32 insertions(+), 35 deletions(-)

diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBArchiver.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBArchiver.java
index 636bdf24b41..9a2ec9ec87d 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBArchiver.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBArchiver.java
@@ -47,14 +47,14 @@ public class OMDBArchiver {
 
   private Path tmpDir;
   private Map<String, File> filesToWriteIntoTarball;
-  private Map<String, String> hardLinkFileMap;
+  private final Map<String, String> hardLinkFileMap;
   private static final Logger LOG = 
LoggerFactory.getLogger(OMDBArchiver.class);
   private boolean completed;
 
   public OMDBArchiver() {
     this.tmpDir = null;
     this.filesToWriteIntoTarball = new HashMap<>();
-    this.hardLinkFileMap = null;
+    this.hardLinkFileMap = new HashMap<>();
     this.completed = false;
   }
 
@@ -66,16 +66,12 @@ public Path getTmpDir() {
     return tmpDir;
   }
 
-  public Map<String, String> getHardLinkFileMap() {
-    return hardLinkFileMap;
-  }
-
   public Map<String, File> getFilesToWriteIntoTarball() {
     return filesToWriteIntoTarball;
   }
 
-  public void setHardLinkFileMap(Map<String, String> hardLinkFileMap) {
-    this.hardLinkFileMap = hardLinkFileMap;
+  public void recordHardLinkMapping(String absolutePath, String fileId) {
+    hardLinkFileMap.put(absolutePath, fileId);
   }
 
   public boolean isCompleted() {
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBCheckpointServletInodeBasedXfer.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBCheckpointServletInodeBasedXfer.java
index 3c77cea5b15..817dfc30b44 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBCheckpointServletInodeBasedXfer.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBCheckpointServletInodeBasedXfer.java
@@ -184,6 +184,7 @@ public void 
processMetadataSnapshotRequest(HttpServletRequest request, HttpServl
       }
     } catch (IOException e) {
       LOG.error("unable to write to archive stream", e);
+      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
     } finally {
       try {
         if (tmpdir != null) {
@@ -269,8 +270,6 @@ public void collectDbDataToTransfer(HttpServletRequest 
request,
       if (shouldContinue) {
         // we finished transferring files from snapshot DB's by now and
         // this is the last step where we transfer the active om.db contents
-        Map<String, String> hardLinkFileMap = new HashMap<>();
-        omdbArchiver.setHardLinkFileMap(hardLinkFileMap);
         SnapshotCache snapshotCache = 
om.getOmSnapshotManager().getSnapshotCache();
         OmSnapshotLocalDataManager localDataManager = 
om.getOmSnapshotManager().getSnapshotLocalDataManager();
         /*
@@ -376,9 +375,7 @@ void collectSnapshotData(Set<String> sstFilesToExclude, 
Collection<Path> snapsho
     }
     for (Path snapshotLocalPropertyYaml : snapshotLocalPropertyFiles) {
       File yamlFile = snapshotLocalPropertyYaml.toFile();
-      if (omdbArchiver.getHardLinkFileMap() != null) {
-        omdbArchiver.getHardLinkFileMap().put(yamlFile.getAbsolutePath(), 
yamlFile.getName());
-      }
+      omdbArchiver.recordHardLinkMapping(yamlFile.getAbsolutePath(), 
yamlFile.getName());
       omdbArchiver.recordFileEntry(yamlFile, yamlFile.getName());
     }
   }
@@ -410,17 +407,26 @@ private static void cleanupCheckpoint(DBCheckpoint 
checkpoint) {
   static void writeHardlinkFile(OzoneConfiguration conf, Map<String, String> 
hardlinkFileMap,
       ArchiveOutputStream<TarArchiveEntry> archiveOutputStream) throws 
IOException {
     Path data = Files.createTempFile(DATA_PREFIX, DATA_SUFFIX);
-    Path metaDirPath = OMStorage.getOmDbDir(conf).toPath();
-    StringBuilder sb = new StringBuilder();
-
-    for (Map.Entry<String, String> entry : hardlinkFileMap.entrySet()) {
-      Path p = Paths.get(entry.getKey());
-      String fileId = entry.getValue();
-      Path relativePath = metaDirPath.relativize(p);
-      sb.append(relativePath).append('\t').append(fileId).append('\n');
+    try {
+      Path metaDirPath = OMStorage.getOmDbDir(conf).toPath()
+          .toAbsolutePath().normalize();
+      StringBuilder sb = new StringBuilder();
+
+      for (Map.Entry<String, String> entry : hardlinkFileMap.entrySet()) {
+        Path p = new File(entry.getKey()).toPath();
+        if (!p.isAbsolute()) {
+          p = metaDirPath.resolve(p);
+        }
+        p = p.toAbsolutePath().normalize();
+        String fileId = entry.getValue();
+        Path relativePath = metaDirPath.relativize(p);
+        sb.append(relativePath).append('\t').append(fileId).append('\n');
+      }
+      Files.write(data, sb.toString().getBytes(StandardCharsets.UTF_8), 
StandardOpenOption.TRUNCATE_EXISTING);
+      includeFile(data.toFile(), OmSnapshotManager.OM_HARDLINK_FILE, 
archiveOutputStream);
+    } finally {
+      Files.deleteIfExists(data);
     }
-    Files.write(data, sb.toString().getBytes(StandardCharsets.UTF_8), 
StandardOpenOption.TRUNCATE_EXISTING);
-    includeFile(data.toFile(), OmSnapshotManager.OM_HARDLINK_FILE, 
archiveOutputStream);
   }
 
   /**
@@ -500,14 +506,12 @@ private boolean collectFilesFromDir(Set<String> 
sstFilesToExclude, Stream<Path>
           continue;
         }
         String fileId = 
OmSnapshotUtils.getFileInodeAndLastModifiedTimeString(dbFile);
-        if (omdbArchiver.getHardLinkFileMap() != null) {
-          String path = dbFile.toFile().getAbsolutePath();
-          // if the file is in the om checkpoint dir, then we need to change 
the path to point to the OM DB.
-          if (path.contains(OM_CHECKPOINT_DIR)) {
-            path = 
getDbStore().getDbLocation().toPath().resolve(dbFile.getFileName()).toAbsolutePath().toString();
-          }
-          omdbArchiver.getHardLinkFileMap().put(path, fileId);
+        String path = dbFile.toFile().getAbsolutePath();
+        // if the file is in the om checkpoint dir, then we need to change the 
path to point to the OM DB.
+        if (path.contains(OM_CHECKPOINT_DIR)) {
+          path = 
getDbStore().getDbLocation().toPath().resolve(dbFile.getFileName()).toAbsolutePath().toString();
         }
+        omdbArchiver.recordHardLinkMapping(path, fileId);
         if (!sstFilesToExclude.contains(fileId)) {
           long fileSize = Files.size(dbFile);
           if (maxTotalSstSize.get() - fileSize <= 0) {
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOMDBArchiver.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOMDBArchiver.java
index 5d2093e1f68..8fb121c55b1 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOMDBArchiver.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOMDBArchiver.java
@@ -27,9 +27,7 @@
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.Optional;
 import java.util.stream.Stream;
 import org.apache.hadoop.fs.FileUtil;
@@ -86,15 +84,14 @@ public void testWriteToArchive(boolean completed) throws 
IOException {
     omdbArchiver.setTmpDir(tmpDir);
     assertThat(omdbArchiver.getFilesToWriteIntoTarball()).isNotNull();
     assertThat(omdbArchiver.getTmpDir()).isEqualTo(tmpDir);
-    Map<String, String> hardLinkFileMap = new HashMap<String, String>();
     for (int i = 0; i < 10; i++) {
       String fileName = "hardlink-" + i;
       File dummyFile = new File(tmpDir.toFile(), fileName);
       Files.write(dummyFile.toPath(), 
"dummy".getBytes(StandardCharsets.UTF_8));
       omdbArchiver.getFilesToWriteIntoTarball().put(fileName, dummyFile);
-      hardLinkFileMap.put(dummyFile.getAbsolutePath(), dummyFile.getName());
+      omdbArchiver.recordHardLinkMapping(dummyFile.getAbsolutePath(),
+          dummyFile.getName());
     }
-    omdbArchiver.setHardLinkFileMap(hardLinkFileMap);
 
     File tarFile = new File(folder.toFile(), "test-archive.tar");
     OzoneConfiguration conf = new OzoneConfiguration();


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

Reply via email to