Skip to content

Commit 9123f92

Browse files
Neilxznjojochuang
authored andcommitted
HDFS-15720 namenode audit async logger should add some log4j config (#2532)
(cherry picked from commit 9bd3c9b) (cherry picked from commit bc5458b)
1 parent 76316c4 commit 9123f92

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,10 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
610610
public static final boolean DFS_NAMENODE_AUDIT_LOG_TOKEN_TRACKING_ID_DEFAULT = false;
611611
public static final String DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY = "dfs.namenode.audit.log.async";
612612
public static final boolean DFS_NAMENODE_AUDIT_LOG_ASYNC_DEFAULT = false;
613+
public static final String DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_KEY = "dfs.namenode.audit.log.async.blocking";
614+
public static final boolean DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_DEFAULT = true;
615+
public static final String DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_KEY = "dfs.namenode.audit.log.async.buffer.size";
616+
public static final int DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_DEFAULT = 128;
613617
public static final String DFS_NAMENODE_AUDIT_LOG_DEBUG_CMDLIST = "dfs.namenode.audit.log.debug.cmdlist";
614618
public static final String DFS_NAMENODE_METRICS_LOGGER_PERIOD_SECONDS_KEY =
615619
"dfs.namenode.metrics.logger.period.seconds";

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ static FSNamesystem loadFromDisk(Configuration conf) throws IOException {
786786
if (conf.getBoolean(DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY,
787787
DFS_NAMENODE_AUDIT_LOG_ASYNC_DEFAULT)) {
788788
LOG.info("Enabling async auditlog");
789-
enableAsyncAuditLog();
789+
enableAsyncAuditLog(conf);
790790
}
791791
fsLock = new FSNamesystemLock(conf, detailedLockHoldTimeMetrics);
792792
cond = fsLock.newWriteLockCondition();
@@ -8146,7 +8146,7 @@ public void logAuditMessage(String message) {
81468146
}
81478147
}
81488148

8149-
private static void enableAsyncAuditLog() {
8149+
private static void enableAsyncAuditLog(Configuration conf) {
81508150
if (!(auditLog instanceof Log4JLogger)) {
81518151
LOG.warn("Log4j is required to enable async auditlog");
81528152
return;
@@ -8157,6 +8157,14 @@ private static void enableAsyncAuditLog() {
81578157
// failsafe against trying to async it more than once
81588158
if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
81598159
AsyncAppender asyncAppender = new AsyncAppender();
8160+
asyncAppender.setBlocking(conf.getBoolean(
8161+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_KEY,
8162+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_DEFAULT
8163+
));
8164+
asyncAppender.setBufferSize(conf.getInt(
8165+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_KEY,
8166+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_DEFAULT
8167+
));
81608168
// change logger to have an async appender containing all the
81618169
// previously configured appenders
81628170
for (Appender appender : appenders) {

hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4367,6 +4367,27 @@
43674367
</description>
43684368
</property>
43694369

4370+
<property>
4371+
<name>dfs.namenode.audit.log.async.blocking</name>
4372+
<value>true</value>
4373+
<description>
4374+
Only used when enables asynchronous audit log. Sets whether audit log async
4375+
appender should wait if there is no space available in the event buffer or
4376+
immediately return. Default value is true.
4377+
</description>
4378+
</property>
4379+
4380+
<property>
4381+
<name>dfs.namenode.audit.log.async.buffer.size</name>
4382+
<value>128</value>
4383+
<description>
4384+
Only used when enables asynchronous audit log. Sets the number of audit
4385+
logs allowed in the event buffer before the calling thread is blocked
4386+
(if dfs.namenode.audit.log.async.blocking is true) or until logs are
4387+
summarized and discarded. Default value is 128.
4388+
</description>
4389+
</property>
4390+
43704391
<property>
43714392
<name>dfs.namenode.audit.log.token.tracking.id</name>
43724393
<value>false</value>

0 commit comments

Comments
 (0)