From bc2bdee76c1dc2a3d8bee7306f128ff6bdd10a9c Mon Sep 17 00:00:00 2001 From: litao Date: Mon, 22 Mar 2021 19:29:17 +0800 Subject: [PATCH] HDFS-15906. Close FSImage and FSNamesystem after formatting is complete (#2788) (cherry picked from commit 343ce8a8c955dcf64ad453e441947e8761247a5b) --- .../apache/hadoop/hdfs/server/namenode/NameNode.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java index 48eb0c18644..1e70a45ea73 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java @@ -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; }