diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeResourcePolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeResourcePolicy.java index 03f226c23b..014b9436b7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeResourcePolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeResourcePolicy.java @@ -20,6 +20,8 @@ import java.util.Collection; import org.apache.hadoop.classification.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Given a set of checkable resources, this class is capable of determining @@ -38,6 +40,9 @@ final class NameNodeResourcePolicy { * @return true if and only if there are sufficient NN resources to * continue logging edits. */ + private static final Logger LOG = + LoggerFactory.getLogger(NameNodeResourcePolicy.class.getName()); + static boolean areResourcesAvailable( Collection resources, int minimumRedundantResources) { @@ -73,8 +78,14 @@ static boolean areResourcesAvailable( // required resources available. return requiredResourceCount > 0; } else { - return redundantResourceCount - disabledRedundantResourceCount >= - minimumRedundantResources; + final boolean areResourceAvailable = + redundantResourceCount - disabledRedundantResourceCount >= minimumRedundantResources; + if (!areResourceAvailable) { + LOG.info("Resources not available. Details: redundantResourceCount={}," + + " disabledRedundantResourceCount={}, minimumRedundantResources={}.", + redundantResourceCount, disabledRedundantResourceCount, minimumRedundantResources); + } + return areResourceAvailable; } } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourcePolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourcePolicy.java index 6e0657c8d6..073ee37781 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourcePolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourcePolicy.java @@ -27,8 +27,20 @@ import org.junit.Test; +import org.slf4j.LoggerFactory; +import org.apache.hadoop.test.GenericTestUtils.LogCapturer; + public class TestNameNodeResourcePolicy { + @Test + public void testExcessiveMinimumRedundantResources() { + LogCapturer logCapturer = + LogCapturer.captureLogs(LoggerFactory.getLogger(NameNodeResourcePolicy.class)); + assertFalse(testResourceScenario(1, 0, 0, 0, 2)); + logCapturer.stopCapturing(); + assertTrue(logCapturer.getOutput().contains("Resources not available.")); + } + @Test public void testSingleRedundantResource() { assertTrue(testResourceScenario(1, 0, 0, 0, 1)); @@ -71,7 +83,7 @@ public void testRedundantWithRequiredResources() { assertFalse(testResourceScenario(2, 2, 1, 1, 1)); assertFalse(testResourceScenario(2, 2, 2, 1, 1)); } - + private static boolean testResourceScenario( int numRedundantResources, int numRequiredResources,