Skip to content

Skip journal flush-trace loop when debug logging is disabled#4835

Open
merlimat wants to merge 1 commit into
apache:masterfrom
merlimat:journal-lazy-flush-trace
Open

Skip journal flush-trace loop when debug logging is disabled#4835
merlimat wants to merge 1 commit into
apache:masterfrom
merlimat:journal-lazy-flush-trace

Conversation

@merlimat

Copy link
Copy Markdown
Contributor

Motivation

After every journal flush, a second pass iterates the whole toFlush list purely to emit per-entry DEBUG trace lines. When DEBUG is disabled (the normal production configuration), the loop still runs: it allocates an Iterator per flush and walks the full list doing null checks for nothing.

Changes

Wrap the trace loop in slog's lazy consumer form, log.debug(e -> { ... }), which returns immediately without invoking the consumer when DEBUG is disabled — no iteration, no iterator. A local alias of toFlush is captured since the field variable is reassigned after the hand-off to the force-write thread (not effectively final).

Verified with BookieJournalTest and BookieJournalForceTest (22/22 pass) and module checkstyle.

@void-ptr974 void-ptr974 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants