Skip to content

Commit 6258405

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) (cherry picked from commit 9123f92)
1 parent b89aff6 commit 6258405

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
@@ -597,6 +597,10 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
597597
public static final boolean DFS_NAMENODE_AUDIT_LOG_TOKEN_TRACKING_ID_DEFAULT = false;
598598
public static final String DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY = "dfs.namenode.audit.log.async";
599599
public static final boolean DFS_NAMENODE_AUDIT_LOG_ASYNC_DEFAULT = false;
600+
public static final String DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_KEY = "dfs.namenode.audit.log.async.blocking";
601+
public static final boolean DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_DEFAULT = true;
602+
public static final String DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_KEY = "dfs.namenode.audit.log.async.buffer.size";
603+
public static final int DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_DEFAULT = 128;
600604
public static final String DFS_NAMENODE_AUDIT_LOG_DEBUG_CMDLIST = "dfs.namenode.audit.log.debug.cmdlist";
601605
public static final String DFS_NAMENODE_METRICS_LOGGER_PERIOD_SECONDS_KEY =
602606
"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
@@ -783,7 +783,7 @@ static FSNamesystem loadFromDisk(Configuration conf) throws IOException {
783783
if (conf.getBoolean(DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY,
784784
DFS_NAMENODE_AUDIT_LOG_ASYNC_DEFAULT)) {
785785
LOG.info("Enabling async auditlog");
786-
enableAsyncAuditLog();
786+
enableAsyncAuditLog(conf);
787787
}
788788
fsLock = new FSNamesystemLock(conf, detailedLockHoldTimeMetrics);
789789
cond = fsLock.newWriteLockCondition();
@@ -8019,7 +8019,7 @@ public void logAuditMessage(String message) {
80198019
}
80208020
}
80218021

8022-
private static void enableAsyncAuditLog() {
8022+
private static void enableAsyncAuditLog(Configuration conf) {
80238023
if (!(auditLog instanceof Log4JLogger)) {
80248024
LOG.warn("Log4j is required to enable async auditlog");
80258025
return;
@@ -8030,6 +8030,14 @@ private static void enableAsyncAuditLog() {
80308030
// failsafe against trying to async it more than once
80318031
if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
80328032
AsyncAppender asyncAppender = new AsyncAppender();
8033+
asyncAppender.setBlocking(conf.getBoolean(
8034+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_KEY,
8035+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_DEFAULT
8036+
));
8037+
asyncAppender.setBufferSize(conf.getInt(
8038+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_KEY,
8039+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_DEFAULT
8040+
));
80338041
// change logger to have an async appender containing all the
80348042
// previously configured appenders
80358043
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
@@ -4339,6 +4339,27 @@
43394339
</description>
43404340
</property>
43414341

4342+
<property>
4343+
<name>dfs.namenode.audit.log.async.blocking</name>
4344+
<value>true</value>
4345+
<description>
4346+
Only used when enables asynchronous audit log. Sets whether audit log async
4347+
appender should wait if there is no space available in the event buffer or
4348+
immediately return. Default value is true.
4349+
</description>
4350+
</property>
4351+
4352+
<property>
4353+
<name>dfs.namenode.audit.log.async.buffer.size</name>
4354+
<value>128</value>
4355+
<description>
4356+
Only used when enables asynchronous audit log. Sets the number of audit
4357+
logs allowed in the event buffer before the calling thread is blocked
4358+
(if dfs.namenode.audit.log.async.blocking is true) or until logs are
4359+
summarized and discarded. Default value is 128.
4360+
</description>
4361+
</property>
4362+
43424363
<property>
43434364
<name>dfs.namenode.audit.log.token.tracking.id</name>
43444365
<value>false</value>

0 commit comments

Comments
 (0)