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

Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
Keyao Li 2023-05-19 21:08:01 +08:00 committed by GitHub
parent 339bc7b3a6
commit 0914b3e792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -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<? extends CheckableNameNodeResource> 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;
}
}
}

View File

@ -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,