This is an automated email from the ASF dual-hosted git repository.

ayushsaxena pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 0914b3e7920 HDFS-16697. Add logs if resources are not available in 
NameNodeResourcePolicy. (#5569). Contributed by ECFuzz.
0914b3e7920 is described below

commit 0914b3e7920835cfd9b938b510e03532b3145095
Author: Keyao Li <38782735+lik...@users.noreply.github.com>
AuthorDate: Fri May 19 21:08:01 2023 +0800

    HDFS-16697. Add logs if resources are not available in 
NameNodeResourcePolicy. (#5569). Contributed by ECFuzz.
    
    Signed-off-by: Ayush Saxena <ayushsax...@apache.org>
---
 .../hdfs/server/namenode/NameNodeResourcePolicy.java      | 15 +++++++++++++--
 .../hdfs/server/namenode/TestNameNodeResourcePolicy.java  | 14 +++++++++++++-
 2 files changed, 26 insertions(+), 3 deletions(-)

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 03f226c23b7..014b9436b77 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 @@ 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;
     }
   }
 }
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 6e0657c8d6d..073ee377819 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 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,


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to