From 5685eb30bbf4ee5badcda9c58f050e013bb211f4 Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Sun, 15 Jul 2012 19:48:15 +0000 Subject: [PATCH] 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/branches/branch-2@1361777 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/hadoop/util/ExitUtil.java | 20 +++++++++++++++---- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../apache/hadoop/hdfs/MiniDFSCluster.java | 8 +++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java index 0db972c89ae..837e4f3c9de 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java @@ -30,7 +30,7 @@ public final class ExitUtil { private final static Log LOG = LogFactory.getLog(ExitUtil.class.getName()); private static volatile boolean systemExitDisabled = false; - private static volatile boolean terminateCalled = false; + private static volatile ExitException firstExitException; public static class ExitException extends RuntimeException { private static final long serialVersionUID = 1L; @@ -53,7 +53,15 @@ public static void disableSystemExit() { * @return true if terminate has been called */ 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 static boolean terminateCalled() { */ public static void terminate(int status, String msg) throws ExitException { LOG.info("Exiting with status " + status); - terminateCalled = true; 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); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 33a617b6251..ccdd1d08f66 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -148,6 +148,9 @@ Release 2.0.1-alpha - UNRELEASED HDFS-3610. fuse_dfs: Provide a way to use the default (configured) NN URI. (Colin Patrick McCabe via eli) + HDFS-3663. MiniDFSCluster should capture the code path that led to + the first ExitException. (eli) + OPTIMIZATIONS HDFS-2982. Startup performance suffers when there are many edit log 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 0da0b82003e..3c6f5834360 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 @@ -1291,9 +1291,11 @@ public int getNameNodeServicePort(int nnIndex) { public void shutdown() { LOG.info("Shutting down the Mini HDFS Cluster"); if (checkExitOnShutdown) { - if (ExitUtil.terminateCalled()) { - throw new AssertionError("Test resulted in an unexpected exit"); - } + if (ExitUtil.terminateCalled()) { + LOG.fatal("Test resulted in an unexpected exit", + ExitUtil.getFirstExitException()); + throw new AssertionError("Test resulted in an unexpected exit"); + } } shutdownDataNodes(); for (NameNodeInfo nnInfo : nameNodes) {