BP-69: Inherit LedgerHandle logger context in ledger operations#4767
Open
merlimat wants to merge 2 commits intoapache:masterfrom
Open
BP-69: Inherit LedgerHandle logger context in ledger operations#4767merlimat wants to merge 2 commits intoapache:masterfrom
merlimat wants to merge 2 commits intoapache:masterfrom
Conversation
Operations created in the context of a LedgerHandle (PendingAddOp,
PendingReadOp, BatchedReadOp, ReadOpBase, ForceLedgerOp,
TryReadLastConfirmedOp, ReadLastConfirmedAndEntryOp, LedgerRecoveryOp,
PendingReadLacOp, PendingWriteLacOp) now attach LedgerHandle.log's
context (ledgerId, etc.) to every emitted event via Event.ctx(lh.log).
Using per-event ctx() rather than building a child Logger per op keeps
the static @CustomLog field allocation-free at the call site, while
still ensuring every operation log carries its parent ledger context.
ReadLastConfirmedAndEntryOp and LedgerRecoveryOp previously built an
instance-scoped Logger to carry the ledger context; they now use the
static @CustomLog logger plus per-event ctx(lh.log), removing one
Logger allocation per operation.
Redundant .attr("ledgerId", ...) calls (already provided by
LedgerHandle.log's context) are removed.
slog 0.9.9 makes Event.ctx(null) a no-op instead of throwing NPE, which lets the operation classes call .ctx(lh.log) directly even when the parent logger is unset (e.g. tests using mock LedgerHandle where the log field is null).
b932a28 to
7ab2bba
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LedgerHandle(PendingAddOp, PendingReadOp, BatchedReadOp, ReadOpBase, ForceLedgerOp, TryReadLastConfirmedOp, ReadLastConfirmedAndEntryOp, LedgerRecoveryOp, PendingReadLacOp, PendingWriteLacOp) now inherit the parent ledger's logger context on every emitted event, viaEvent.ctx(lh.log).@CustomLogloggers are kept; using per-eventctx()rather than constructing a childLoggerper op avoids per-operationLoggerallocations while still propagating ledger-scoped attrs (ledgerId, etc.) to every log line.ReadLastConfirmedAndEntryOpandLedgerRecoveryOppreviously built an instance-scopedLogger; they're switched to the static-logger +ctx(lh.log)pattern, removing oneLoggerallocation per operation..attr("ledgerId", ...)calls — the value is already inLedgerHandle.log's context — are removed at the same sites.Test plan
mvn -pl bookkeeper-server compilepasses.