Skip to content

Commit 9bd3c9b

Browse files
authored
HDFS-15720 namenode audit async logger should add some log4j config (#2532)
1 parent 3ec01b1 commit 9bd3c9b

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
@@ -679,6 +679,10 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
679679
public static final boolean DFS_NAMENODE_AUDIT_LOG_TOKEN_TRACKING_ID_DEFAULT = false;
680680
public static final String DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY = "dfs.namenode.audit.log.async";
681681
public static final boolean DFS_NAMENODE_AUDIT_LOG_ASYNC_DEFAULT = false;
682+
public static final String DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_KEY = "dfs.namenode.audit.log.async.blocking";
683+
public static final boolean DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_DEFAULT = true;
684+
public static final String DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_KEY = "dfs.namenode.audit.log.async.buffer.size";
685+
public static final int DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_DEFAULT = 128;
682686
public static final String DFS_NAMENODE_AUDIT_LOG_DEBUG_CMDLIST = "dfs.namenode.audit.log.debug.cmdlist";
683687
public static final String DFS_NAMENODE_METRICS_LOGGER_PERIOD_SECONDS_KEY =
684688
"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
@@ -829,7 +829,7 @@ static FSNamesystem loadFromDisk(Configuration conf) throws IOException {
829829
if (conf.getBoolean(DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY,
830830
DFS_NAMENODE_AUDIT_LOG_ASYNC_DEFAULT)) {
831831
LOG.info("Enabling async auditlog");
832-
enableAsyncAuditLog();
832+
enableAsyncAuditLog(conf);
833833
}
834834
fsLock = new FSNamesystemLock(conf, detailedLockHoldTimeMetrics);
835835
cond = fsLock.newWriteLockCondition();
@@ -8709,7 +8709,7 @@ public void logAuditMessage(String message) {
87098709
}
87108710
}
87118711

8712-
private static void enableAsyncAuditLog() {
8712+
private static void enableAsyncAuditLog(Configuration conf) {
87138713
if (!(auditLog instanceof Log4JLogger)) {
87148714
LOG.warn("Log4j is required to enable async auditlog");
87158715
return;
@@ -8720,6 +8720,14 @@ private static void enableAsyncAuditLog() {
87208720
// failsafe against trying to async it more than once
87218721
if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
87228722
AsyncAppender asyncAppender = new AsyncAppender();
8723+
asyncAppender.setBlocking(conf.getBoolean(
8724+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_KEY,
8725+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BLOCKING_DEFAULT
8726+
));
8727+
asyncAppender.setBufferSize(conf.getInt(
8728+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_KEY,
8729+
DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_BUFFER_SIZE_DEFAULT
8730+
));
87238731
// change logger to have an async appender containing all the
87248732
// previously configured appenders
87258733
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
@@ -4857,6 +4857,27 @@
48574857
</description>
48584858
</property>
48594859

4860+
<property>
4861+
<name>dfs.namenode.audit.log.async.blocking</name>
4862+
<value>true</value>
4863+
<description>
4864+
Only used when enables asynchronous audit log. Sets whether audit log async
4865+
appender should wait if there is no space available in the event buffer or
4866+
immediately return. Default value is true.
4867+
</description>
4868+
</property>
4869+
4870+
<property>
4871+
<name>dfs.namenode.audit.log.async.buffer.size</name>
4872+
<value>128</value>
4873+
<description>
4874+
Only used when enables asynchronous audit log. Sets the number of audit
4875+
logs allowed in the event buffer before the calling thread is blocked
4876+
(if dfs.namenode.audit.log.async.blocking is true) or until logs are
4877+
summarized and discarded. Default value is 128.
4878+
</description>
4879+
</property>
4880+
48604881
<property>
48614882
<name>dfs.namenode.audit.log.token.tracking.id</name>
48624883
<value>false</value>

0 commit comments

Comments
 (0)