HDFS-15906. Close FSImage and FSNamesystem after formatting is complete (#2800)

(cherry picked from commit d05d15620e)
This commit is contained in:
litao 2021-03-23 17:45:24 +08:00 committed by Takanobu Asanuma
parent c1b25422a5
commit 75f2d47ff5
1 changed files with 9 additions and 2 deletions

View File

@ -1200,8 +1200,9 @@ public class NameNode extends ReconfigurableBase implements
System.out.println("Formatting using clusterid: " + clusterId);
FSImage fsImage = new FSImage(conf, nameDirsToFormat, editDirsToFormat);
FSNamesystem fsn = null;
try {
FSNamesystem fsn = new FSNamesystem(conf, fsImage);
fsn = new FSNamesystem(conf, fsImage);
fsImage.getEditLog().initJournalsForWrite();
// Abort NameNode format if reformat is disabled and if
@ -1226,8 +1227,14 @@ public class NameNode extends ReconfigurableBase implements
fsImage.format(fsn, clusterId);
} catch (IOException ioe) {
LOG.warn("Encountered exception during format: ", ioe);
fsImage.close();
throw ioe;
} finally {
if (fsImage != null) {
fsImage.close();
}
if (fsn != null) {
fsn.close();
}
}
return false;
}