Skip to content

Commit d7822f2

Browse files
committed
Fix enable_audit_log configuration not taking effect
The audit log configuration (enable_audit_log) was not taking effect because the configuration values were stored as static final fields in AbstractAuditLogger, which were initialized at class loading time before the configuration file was fully loaded. This fix changes the static final fields to dynamic method calls: - IS_AUDIT_LOG_ENABLED -> isAuditLogEnabled() - AUDITABLE_OPERATION_TYPE -> getAuditableOperationType() - AUDITABLE_OPERATION_LEVEL -> getAuditableOperationLevel() - AUDITABLE_OPERATION_RESULT -> getAuditableOperationResult() This ensures that the configuration values are read dynamically at runtime, after the configuration file has been properly loaded. Fixes: #16706
1 parent c77bb57 commit d7822f2

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/audit/CNAuditLogger.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@ public CNAuditLogger(ConfigManager configManager) {
4242
}
4343

4444
@Override
45-
public void log(IAuditEntity auditLogFields, Supplier<String> log) {}
45+
public void log(IAuditEntity auditLogFields, Supplier<String> log) {
46+
if (!isAuditLogEnabled()) {
47+
return;
48+
}
49+
}
4650
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/audit/DNAuditLogger.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,18 @@ private static InsertRowStatement generateInsertStatement(
5757
public void createViewIfNecessary() {}
5858

5959
@Override
60-
public synchronized void log(IAuditEntity auditLogFields, Supplier<String> log) {}
60+
public synchronized void log(IAuditEntity auditLogFields, Supplier<String> log) {
61+
if (!isAuditLogEnabled()) {
62+
return;
63+
}
64+
}
6165

6266
public void logFromCN(AuditLogFields auditLogFields, String log, int nodeId)
63-
throws IllegalPathException {}
67+
throws IllegalPathException {
68+
if (!isAuditLogEnabled()) {
69+
return;
70+
}
71+
}
6472

6573
private static class DNAuditLoggerHolder {
6674

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/audit/AbstractAuditLogger.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ public abstract class AbstractAuditLogger {
4040
public static final String AUDIT_LOG_LOG = "log";
4141

4242
private static final CommonConfig CONFIG = CommonDescriptor.getInstance().getConfig();
43-
protected static final boolean IS_AUDIT_LOG_ENABLED = CONFIG.isEnableAuditLog();
43+
44+
/**
45+
* Check if audit log is enabled. This method reads the configuration dynamically instead of using
46+
* a static final field to ensure that the configuration is properly loaded before being used.
47+
*
48+
* @return true if audit log is enabled, false otherwise
49+
*/
50+
protected static boolean isAuditLogEnabled() {
51+
return CONFIG.isEnableAuditLog();
52+
}
4453

4554
public abstract void log(IAuditEntity auditLogFields, Supplier<String> log);
4655

0 commit comments

Comments
 (0)