Skip to content

BP-69: Inherit LedgerHandle logger context in ledger operations#4767

Merged
lhotari merged 2 commits into
apache:masterfrom
merlimat:bp-69-ops-ledger-context
May 5, 2026
Merged

BP-69: Inherit LedgerHandle logger context in ledger operations#4767
lhotari merged 2 commits into
apache:masterfrom
merlimat:bp-69-ops-ledger-context

Conversation

@merlimat

Copy link
Copy Markdown
Contributor

Summary

  • Operations created within the context of a LedgerHandle (PendingAddOp, PendingReadOp, BatchedReadOp, ReadOpBase, ForceLedgerOp, TryReadLastConfirmedOp, ReadLastConfirmedAndEntryOp, LedgerRecoveryOp, PendingReadLacOp, PendingWriteLacOp) now inherit the parent ledger's logger context on every emitted event, via Event.ctx(lh.log).
  • Static @CustomLog loggers are kept; using per-event ctx() rather than constructing a child Logger per op avoids per-operation Logger allocations while still propagating ledger-scoped attrs (ledgerId, etc.) to every log line.
  • ReadLastConfirmedAndEntryOp and LedgerRecoveryOp previously built an instance-scoped Logger; they're switched to the static-logger + ctx(lh.log) pattern, removing one Logger allocation per operation.
  • Redundant .attr("ledgerId", ...) calls — the value is already in LedgerHandle.log's context — are removed at the same sites.

Test plan

  • mvn -pl bookkeeper-server compile passes.
  • Existing client integration tests continue to pass on CI.

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).
@merlimat merlimat force-pushed the bp-69-ops-ledger-context branch from b932a28 to 7ab2bba Compare April 29, 2026 00:12
@lhotari lhotari merged commit de34d14 into apache:master May 5, 2026
20 checks passed
@hangc0276 hangc0276 added this to the 4.18.0 milestone May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants