From d03dac743206046c2db7b73d09e177310e217dcb Mon Sep 17 00:00:00 2001 From: Aaron Myers Date: Mon, 20 Feb 2012 04:12:01 +0000 Subject: [PATCH] HDFS-2974. MiniDFSCluster does not delete standby NN name dirs during format. Contributed by Aaron T. Myers. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1623@1291126 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-hdfs/CHANGES.HDFS-1623.txt | 2 ++ .../java/org/apache/hadoop/hdfs/MiniDFSCluster.java | 13 +++++++++++-- .../hadoop/hdfs/server/namenode/TestCheckpoint.java | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt index 36faf4e569c..4d96857e727 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt @@ -218,3 +218,5 @@ HDFS-2937. TestDFSHAAdmin needs tests with MiniDFSCluster. (Brandon Li via sures HDFS-2586. Add protobuf service and implementation for HAServiceProtocol. (suresh via atm) HDFS-2952. NN should not start with upgrade option or with a pending an unfinalized upgrade. (atm) + +HDFS-2974. MiniDFSCluster does not delete standby NN name dirs during format. (atm) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java index 4511095cb45..7d40ed6108a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java @@ -626,6 +626,15 @@ public class MiniDFSCluster { for (NNConf nn : nameservice.getNNs()) { initNameNodeConf(conf, nsId, nn.getNnId(), manageNameDfsDirs, nnCounterForFormat); + Collection namespaceDirs = FSNamesystem.getNamespaceDirs(conf); + if (format) { + for (URI nameDirUri : namespaceDirs) { + File nameDir = new File(nameDirUri); + if (nameDir.exists() && !FileUtil.fullyDelete(nameDir)) { + throw new IOException("Could not fully delete " + nameDir); + } + } + } boolean formatThisOne = format; if (format && i++ > 0) { @@ -635,14 +644,14 @@ public class MiniDFSCluster { // from the first one. formatThisOne = false; assert (null != prevNNDirs); - copyNameDirs(prevNNDirs, FSNamesystem.getNamespaceDirs(conf), conf); + copyNameDirs(prevNNDirs, namespaceDirs, conf); } nnCounterForFormat++; if (formatThisOne) { DFSTestUtil.formatNameNode(conf); } - prevNNDirs = FSNamesystem.getNamespaceDirs(conf); + prevNNDirs = namespaceDirs; } // Start all Namenodes diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java index c1277299899..b298fd48b0f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java @@ -655,6 +655,7 @@ public class TestCheckpoint extends TestCase { sdToLock.lock(); try { MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) + .format(false) .manageNameDfsDirs(false) .numDataNodes(0) .build();