From fdf7b182475050aaf67765eb53aaf342ebaebe8b Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Thu, 26 Jan 2012 23:48:08 +0000 Subject: [PATCH] HDFS-2838. NPE in FSNamesystem when in safe mode. Contributed by Gregory Chanan git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1623@1236450 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-hdfs/CHANGES.HDFS-1623.txt | 2 ++ .../hdfs/server/namenode/FSNamesystem.java | 3 +-- .../hadoop/hdfs/TestMiniDFSCluster.java | 20 ++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt index bf685c91cf2..c8a760336a9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt @@ -131,3 +131,5 @@ HDFS-2804. Should not mark blocks under-replicated when exiting safemode (todd) HDFS-2807. Service level authorizartion for HAServiceProtocol. (jitendra) HDFS-2809. Add test to verify that delegation tokens are honored after failover. (jitendra and atm) + +HDFS-2838. NPE in FSNamesystem when in safe mode. (Gregory Chanan via eli) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index 85ae12d4bd0..b3b3dbdaf31 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -3623,11 +3623,10 @@ public class FSNamesystem implements Namesystem, FSClusterStats, assert assertsOn = true; // set to true if asserts are on if (!assertsOn) return; - - int activeBlocks = blockManager.getActiveBlockCount(); if (blockTotal == -1 && blockSafe == -1) { return; // manual safe mode } + int activeBlocks = blockManager.getActiveBlockCount(); if ((blockTotal != activeBlocks) && !(blockSafe >= 0 && blockSafe <= blockTotal)) { throw new AssertionError( diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMiniDFSCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMiniDFSCluster.java index 5a3524495b4..0eec0d18774 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMiniDFSCluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMiniDFSCluster.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs; import junit.framework.Assert; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hdfs.protocol.FSConstants; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -37,6 +38,7 @@ public class TestMiniDFSCluster { private static final String CLUSTER_1 = "cluster1"; private static final String CLUSTER_2 = "cluster2"; private static final String CLUSTER_3 = "cluster3"; + private static final String CLUSTER_4 = "cluster4"; protected String testDataPath; protected File testDataDir; @Before @@ -104,5 +106,21 @@ public class TestMiniDFSCluster { } } - + @Test(timeout=100000) + public void testIsClusterUpAfterShutdown() throws Throwable { + Configuration conf = new HdfsConfiguration(); + File testDataCluster4 = new File(testDataPath, CLUSTER_4); + String c4Path = testDataCluster4.getAbsolutePath(); + conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, c4Path); + MiniDFSCluster cluster4 = new MiniDFSCluster.Builder(conf).build(); + try { + DistributedFileSystem dfs = (DistributedFileSystem) cluster4.getFileSystem(); + dfs.setSafeMode(FSConstants.SafeModeAction.SAFEMODE_ENTER); + cluster4.shutdown(); + } finally { + while(cluster4.isClusterUp()){ + Thread.sleep(1000); + } + } + } }