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
This commit is contained in:
Eli Collins 2012-01-26 23:48:08 +00:00
parent 1c95060a72
commit fdf7b18247
3 changed files with 22 additions and 3 deletions

View File

@ -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)

View File

@ -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(

View File

@ -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);
}
}
}
}