HDFS-15124. Crashing bugs in NameNode when using a valid configuration for . Contributed by Ctest.

This commit is contained in:
Ayush Saxena 2020-02-27 22:19:35 +05:30
parent 57aa048516
commit cd2c6b1aac
3 changed files with 32 additions and 1 deletions

View File

@ -1110,6 +1110,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
Collection<String> alClasses =
conf.getTrimmedStringCollection(DFS_NAMENODE_AUDIT_LOGGERS_KEY);
List<AuditLogger> auditLoggers = Lists.newArrayList();
boolean topAuditLoggerAdded = false;
if (alClasses != null && !alClasses.isEmpty()) {
for (String className : alClasses) {
try {
@ -1118,9 +1119,16 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
logger = new FSNamesystemAuditLogger();
} else {
logger = (AuditLogger) Class.forName(className).newInstance();
if (TopAuditLogger.class.getName().equals(
logger.getClass().getName())) {
topAuditLoggerAdded = true;
}
}
logger.initialize(conf);
auditLoggers.add(logger);
} catch (InstantiationException e) {
LOG.error("{} instantiation failed.", className, e);
throw new RuntimeException(e);
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
@ -1137,7 +1145,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
// Add audit logger to calculate top users
if (topConf.isEnabled) {
if (topConf.isEnabled && !topAuditLoggerAdded) {
topMetrics = new TopMetrics(conf, topConf.nntopReportingPeriodsMs);
if (DefaultMetricsSystem.instance().getSource(
TOPMETRICS_METRICS_SOURCE_NAME) == null) {

View File

@ -23,12 +23,16 @@ import com.google.common.base.Preconditions;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.server.namenode.AuditLogger;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics;
import static org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics.TOPMETRICS_METRICS_SOURCE_NAME;
/**
* An {@link AuditLogger} that sends logged data directly to the metrics
* systems. It is used when the top service is used directly by the name node
@ -39,6 +43,17 @@ public class TopAuditLogger implements AuditLogger {
private final TopMetrics topMetrics;
public TopAuditLogger() {
Configuration conf = new HdfsConfiguration();
TopConf topConf = new TopConf(conf);
this.topMetrics = new TopMetrics(conf, topConf.nntopReportingPeriodsMs);
if (DefaultMetricsSystem.instance().getSource(
TOPMETRICS_METRICS_SOURCE_NAME) == null) {
DefaultMetricsSystem.instance().register(TOPMETRICS_METRICS_SOURCE_NAME,
"Top N operations by user", topMetrics);
}
}
public TopAuditLogger(TopMetrics topMetrics) {
Preconditions.checkNotNull(topMetrics, "Cannot init with a null " +
"TopMetrics");

View File

@ -303,6 +303,14 @@ public class TestFSNamesystem {
.or(instanceOf(TopAuditLogger.class))
.or(instanceOf(DummyAuditLogger.class)));
}
// Test Configuring TopAuditLogger.
conf.set(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY,
"org.apache.hadoop.hdfs.server.namenode.top.TopAuditLogger");
fsn = new FSNamesystem(conf, fsImage);
auditLoggers = fsn.getAuditLoggers();
assertEquals(1, auditLoggers.size());
assertThat(auditLoggers.get(0), instanceOf(TopAuditLogger.class));
}
static class DummyAuditLogger implements AuditLogger {