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

(cherry picked from commit 343ce8a8c9)
This commit is contained in:
litao 2021-03-22 19:29:17 +08:00 committed by Takanobu Asanuma
parent 23082ac6c7
commit bc2bdee76c
1 changed files with 9 additions and 2 deletions

View File

@ -1249,8 +1249,9 @@ public class NameNode extends ReconfigurableBase implements
LOG.info("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
@ -1275,8 +1276,14 @@ public class NameNode extends ReconfigurableBase implements
fsImage.format(fsn, clusterId, force);
} 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;
}