瀏覽代碼

HDFS-16697. Add logs if resources are not available in NameNodeResourcePolicy. (#5569). Contributed by ECFuzz.

Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
Keyao Li 2 年之前
父節點
當前提交
0914b3e792

+ 13 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeResourcePolicy.java

@@ -20,6 +20,8 @@ package org.apache.hadoop.hdfs.server.namenode;
 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<? extends CheckableNameNodeResource> resources,
       int minimumRedundantResources) {
@@ -73,8 +78,14 @@ final class NameNodeResourcePolicy {
       // 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;
     }
   }
 }

+ 13 - 1
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourcePolicy.java

@@ -27,8 +27,20 @@ import java.util.Collection;
 
 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 class TestNameNodeResourcePolicy {
     assertFalse(testResourceScenario(2, 2, 1, 1, 1));
     assertFalse(testResourceScenario(2, 2, 2, 1, 1));
   }
-  
+
   private static boolean testResourceScenario(
       int numRedundantResources,
       int numRequiredResources,