Skip to content

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

Open
merlimat wants to merge 2 commits intoapache:masterfrom
merlimat:bp-69-ops-ledger-context
Open

BP-69: Inherit LedgerHandle logger context in ledger operations#4767
merlimat wants to merge 2 commits intoapache: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
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.

1 participant