From 08713665c01116455f6e36e9d89a37095e88f40d Mon Sep 17 00:00:00 2001 From: huangzhaobo Date: Sat, 6 Jan 2024 00:47:17 +0800 Subject: [PATCH] HDFS-17315. Optimize the namenode format code logic. (#6400) Signed-off-by: Takanobu Asanuma --- .../org/apache/hadoop/hdfs/server/namenode/NameNode.java | 6 +----- 1 file changed, 1 insertion(+), 5 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 c93bda2a00..a48cfdbe59 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 @@ -1380,7 +1380,6 @@ private static boolean format(Configuration conf, boolean force, } Collection nameDirsToFormat = FSNamesystem.getNamespaceDirs(conf); - List sharedDirs = FSNamesystem.getSharedEditsDirs(conf); List editDirsToFormat = FSNamesystem.getNamespaceEditsDirs(conf); @@ -1392,10 +1391,8 @@ private static boolean format(Configuration conf, boolean force, } LOG.info("Formatting using clusterid: {}", clusterId); - - FSImage fsImage = new FSImage(conf, nameDirsToFormat, editDirsToFormat); FSNamesystem fsn = null; - try { + try (FSImage fsImage = new FSImage(conf, nameDirsToFormat, editDirsToFormat)) { fsn = new FSNamesystem(conf, fsImage); fsImage.getEditLog().initJournalsForWrite(); @@ -1423,7 +1420,6 @@ private static boolean format(Configuration conf, boolean force, LOG.warn("Encountered exception during format", ioe); throw ioe; } finally { - fsImage.close(); if (fsn != null) { fsn.close(); }