Skip to content

Commit

Permalink
[fix](audit) fix the delay in loading audit log (apache#46175)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

The following conditions exist: 

A query is placed in the audit log queue, and the AuditLoader does not
reach the refresh time, and the query does not arrive for a long time,
then the previous audit data will remain in the queue until the next
audit data arrives
Co-authored-by: garenshi <[email protected]>
  • Loading branch information
qzsee authored Dec 31, 2024
1 parent 7a7259d commit 8670378
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ private void fillLogBuffer(AuditEvent event, StringBuilder logBuffer) {
public synchronized void loadIfNecessary(boolean force) {
long currentTime = System.currentTimeMillis();

if (force || auditLogBuffer.length() >= GlobalVariable.auditPluginMaxBatchBytes
|| currentTime - lastLoadTimeAuditLog >= GlobalVariable.auditPluginMaxBatchInternalSec * 1000) {
if (auditLogBuffer.length() != 0 && (force || auditLogBuffer.length() >= GlobalVariable.auditPluginMaxBatchBytes
|| currentTime - lastLoadTimeAuditLog >= GlobalVariable.auditPluginMaxBatchInternalSec * 1000)) {
// begin to load
try {
String token = "";
Expand Down Expand Up @@ -229,9 +229,9 @@ public void run() {
AuditEvent event = auditEventQueue.poll(5, TimeUnit.SECONDS);
if (event != null) {
assembleAudit(event);
// process all audit logs
loadIfNecessary(false);
}
// process all audit logs
loadIfNecessary(false);
} catch (InterruptedException ie) {
if (LOG.isDebugEnabled()) {
LOG.debug("encounter exception when loading current audit batch", ie);
Expand Down

0 comments on commit 8670378

Please sign in to comment.