@@ -184,6 +184,7 @@ public void processMetadataSnapshotRequest(HttpServletRequest request, HttpServl
184184 }
185185 } catch (IOException e ) {
186186 LOG .error ("unable to write to archive stream" , e );
187+ response .setStatus (HttpServletResponse .SC_INTERNAL_SERVER_ERROR );
187188 } finally {
188189 try {
189190 if (tmpdir != null ) {
@@ -269,8 +270,6 @@ public void collectDbDataToTransfer(HttpServletRequest request,
269270 if (shouldContinue ) {
270271 // we finished transferring files from snapshot DB's by now and
271272 // this is the last step where we transfer the active om.db contents
272- Map <String , String > hardLinkFileMap = new HashMap <>();
273- omdbArchiver .setHardLinkFileMap (hardLinkFileMap );
274273 SnapshotCache snapshotCache = om .getOmSnapshotManager ().getSnapshotCache ();
275274 OmSnapshotLocalDataManager localDataManager = om .getOmSnapshotManager ().getSnapshotLocalDataManager ();
276275 /*
@@ -376,9 +375,7 @@ void collectSnapshotData(Set<String> sstFilesToExclude, Collection<Path> snapsho
376375 }
377376 for (Path snapshotLocalPropertyYaml : snapshotLocalPropertyFiles ) {
378377 File yamlFile = snapshotLocalPropertyYaml .toFile ();
379- if (omdbArchiver .getHardLinkFileMap () != null ) {
380- omdbArchiver .getHardLinkFileMap ().put (yamlFile .getAbsolutePath (), yamlFile .getName ());
381- }
378+ omdbArchiver .recordHardLinkMapping (yamlFile .getAbsolutePath (), yamlFile .getName ());
382379 omdbArchiver .recordFileEntry (yamlFile , yamlFile .getName ());
383380 }
384381 }
@@ -410,17 +407,26 @@ private static void cleanupCheckpoint(DBCheckpoint checkpoint) {
410407 static void writeHardlinkFile (OzoneConfiguration conf , Map <String , String > hardlinkFileMap ,
411408 ArchiveOutputStream <TarArchiveEntry > archiveOutputStream ) throws IOException {
412409 Path data = Files .createTempFile (DATA_PREFIX , DATA_SUFFIX );
413- Path metaDirPath = OMStorage .getOmDbDir (conf ).toPath ();
414- StringBuilder sb = new StringBuilder ();
415-
416- for (Map .Entry <String , String > entry : hardlinkFileMap .entrySet ()) {
417- Path p = Paths .get (entry .getKey ());
418- String fileId = entry .getValue ();
419- Path relativePath = metaDirPath .relativize (p );
420- sb .append (relativePath ).append ('\t' ).append (fileId ).append ('\n' );
410+ try {
411+ Path metaDirPath = OMStorage .getOmDbDir (conf ).toPath ()
412+ .toAbsolutePath ().normalize ();
413+ StringBuilder sb = new StringBuilder ();
414+
415+ for (Map .Entry <String , String > entry : hardlinkFileMap .entrySet ()) {
416+ Path p = new File (entry .getKey ()).toPath ();
417+ if (!p .isAbsolute ()) {
418+ p = metaDirPath .resolve (p );
419+ }
420+ p = p .toAbsolutePath ().normalize ();
421+ String fileId = entry .getValue ();
422+ Path relativePath = metaDirPath .relativize (p );
423+ sb .append (relativePath ).append ('\t' ).append (fileId ).append ('\n' );
424+ }
425+ Files .write (data , sb .toString ().getBytes (StandardCharsets .UTF_8 ), StandardOpenOption .TRUNCATE_EXISTING );
426+ includeFile (data .toFile (), OmSnapshotManager .OM_HARDLINK_FILE , archiveOutputStream );
427+ } finally {
428+ Files .deleteIfExists (data );
421429 }
422- Files .write (data , sb .toString ().getBytes (StandardCharsets .UTF_8 ), StandardOpenOption .TRUNCATE_EXISTING );
423- includeFile (data .toFile (), OmSnapshotManager .OM_HARDLINK_FILE , archiveOutputStream );
424430 }
425431
426432 /**
@@ -500,14 +506,12 @@ private boolean collectFilesFromDir(Set<String> sstFilesToExclude, Stream<Path>
500506 continue ;
501507 }
502508 String fileId = OmSnapshotUtils .getFileInodeAndLastModifiedTimeString (dbFile );
503- if (omdbArchiver .getHardLinkFileMap () != null ) {
504- String path = dbFile .toFile ().getAbsolutePath ();
505- // if the file is in the om checkpoint dir, then we need to change the path to point to the OM DB.
506- if (path .contains (OM_CHECKPOINT_DIR )) {
507- path = getDbStore ().getDbLocation ().toPath ().resolve (dbFile .getFileName ()).toAbsolutePath ().toString ();
508- }
509- omdbArchiver .getHardLinkFileMap ().put (path , fileId );
509+ String path = dbFile .toFile ().getAbsolutePath ();
510+ // if the file is in the om checkpoint dir, then we need to change the path to point to the OM DB.
511+ if (path .contains (OM_CHECKPOINT_DIR )) {
512+ path = getDbStore ().getDbLocation ().toPath ().resolve (dbFile .getFileName ()).toAbsolutePath ().toString ();
510513 }
514+ omdbArchiver .recordHardLinkMapping (path , fileId );
511515 if (!sstFilesToExclude .contains (fileId )) {
512516 long fileSize = Files .size (dbFile );
513517 if (maxTotalSstSize .get () - fileSize <= 0 ) {
0 commit comments