HDFS-3663. MiniDFSCluster should capture the code path that led to the first ExitException. Contributed by Eli Collins

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1361775 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eli Collins 2012-07-15 19:43:39 +00:00
parent 7351a01259
commit 64fc2cb03d
3 changed files with 24 additions and 7 deletions

View File

@ -30,7 +30,7 @@ import org.apache.hadoop.classification.InterfaceStability;
public final class ExitUtil { public final class ExitUtil {
private final static Log LOG = LogFactory.getLog(ExitUtil.class.getName()); private final static Log LOG = LogFactory.getLog(ExitUtil.class.getName());
private static volatile boolean systemExitDisabled = false; private static volatile boolean systemExitDisabled = false;
private static volatile boolean terminateCalled = false; private static volatile ExitException firstExitException;
public static class ExitException extends RuntimeException { public static class ExitException extends RuntimeException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -53,7 +53,15 @@ public final class ExitUtil {
* @return true if terminate has been called * @return true if terminate has been called
*/ */
public static boolean terminateCalled() { public static boolean terminateCalled() {
return terminateCalled; // Either we set this member or we actually called System#exit
return firstExitException != null;
}
/**
* @return the first ExitException thrown, null if none thrown yet
*/
public static ExitException getFirstExitException() {
return firstExitException;
} }
/** /**
@ -65,9 +73,13 @@ public final class ExitUtil {
*/ */
public static void terminate(int status, String msg) throws ExitException { public static void terminate(int status, String msg) throws ExitException {
LOG.info("Exiting with status " + status); LOG.info("Exiting with status " + status);
terminateCalled = true;
if (systemExitDisabled) { if (systemExitDisabled) {
throw new ExitException(status, msg); ExitException ee = new ExitException(status, msg);
LOG.fatal("Terminate called", ee);
if (null == firstExitException) {
firstExitException = ee;
}
throw ee;
} }
System.exit(status); System.exit(status);
} }

View File

@ -327,6 +327,9 @@ Branch-2 ( Unreleased changes )
HDFS-3610. fuse_dfs: Provide a way to use the default (configured) NN URI. HDFS-3610. fuse_dfs: Provide a way to use the default (configured) NN URI.
(Colin Patrick McCabe via eli) (Colin Patrick McCabe via eli)
HDFS-3663. MiniDFSCluster should capture the code path that led to
the first ExitException. (eli)
OPTIMIZATIONS OPTIMIZATIONS
HDFS-2982. Startup performance suffers when there are many edit log HDFS-2982. Startup performance suffers when there are many edit log

View File

@ -1316,9 +1316,11 @@ public class MiniDFSCluster {
public void shutdown() { public void shutdown() {
LOG.info("Shutting down the Mini HDFS Cluster"); LOG.info("Shutting down the Mini HDFS Cluster");
if (checkExitOnShutdown) { if (checkExitOnShutdown) {
if (ExitUtil.terminateCalled()) { if (ExitUtil.terminateCalled()) {
throw new AssertionError("Test resulted in an unexpected exit"); LOG.fatal("Test resulted in an unexpected exit",
} ExitUtil.getFirstExitException());
throw new AssertionError("Test resulted in an unexpected exit");
}
} }
shutdownDataNodes(); shutdownDataNodes();
for (NameNodeInfo nnInfo : nameNodes) { for (NameNodeInfo nnInfo : nameNodes) {