Skip to content

Commit d05d156

Browse files
authored
HDFS-15906. Close FSImage and FSNamesystem after formatting is complete (#2800)
1 parent 96fe9d2 commit d05d156

File tree

1 file changed

+9
-2
lines changed
  • hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode

1 file changed

+9
-2
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,8 +1204,9 @@ private static boolean format(Configuration conf, boolean force,
12041204
System.out.println("Formatting using clusterid: " + clusterId);
12051205

12061206
FSImage fsImage = new FSImage(conf, nameDirsToFormat, editDirsToFormat);
1207+
FSNamesystem fsn = null;
12071208
try {
1208-
FSNamesystem fsn = new FSNamesystem(conf, fsImage);
1209+
fsn = new FSNamesystem(conf, fsImage);
12091210
fsImage.getEditLog().initJournalsForWrite();
12101211

12111212
// Abort NameNode format if reformat is disabled and if
@@ -1230,8 +1231,14 @@ private static boolean format(Configuration conf, boolean force,
12301231
fsImage.format(fsn, clusterId, force);
12311232
} catch (IOException ioe) {
12321233
LOG.warn("Encountered exception during format: ", ioe);
1233-
fsImage.close();
12341234
throw ioe;
1235+
} finally {
1236+
if (fsImage != null) {
1237+
fsImage.close();
1238+
}
1239+
if (fsn != null) {
1240+
fsn.close();
1241+
}
12351242
}
12361243
return false;
12371244
}

0 commit comments

Comments
 (0)