bookkeeper icon indicating copy to clipboard operation
bookkeeper copied to clipboard

Issue 4800: Reuse metadata driver for over-replicated ledger GC

Open gaozhangmin opened this issue 6 months ago • 2 comments

Descriptions of the changes in this PR:

Main Issue: #xyz

Motivation

Over-replicated ledger cleanup currently instantiates a metadata bookie driver each time the scan-and-compare garbage collector checks for over-replicated ledgers. This repeatedly creates metadata client resources during GC cycles, which is unnecessary and can add overhead to the cleanup path.

Changes

  • Reuse a metadata bookie driver and ledger manager factory inside ScanAndCompareGarbageCollector for over-replicated ledger cleanup.
  • Make ScanAndCompareGarbageCollector closeable and release the cached metadata driver when GarbageCollectorThread shuts down.
  • Keep the existing GC metadata operation rate limiter behavior while reusing the metadata driver.
  • Add a focused unit test to verify the metadata driver is reused across calls and closed correctly.

In order to uphold a high standard for quality for code contributions, Apache BookKeeper runs various precommit checks for pull requests. A pull request can only be merged when it passes precommit checks.


Be sure to do all the following to help us incorporate your contribution quickly and easily:

Otherwise:

  • [ ] Make sure the PR title is formatted like: <Issue #>: Description of pull request e.g. Issue 123: Description ...
  • [ ] Make sure tests pass via mvn clean apache-rat:check install spotbugs:check.
  • [ ] Replace <Issue #> in the title with the actual Issue number.

gaozhangmin avatar May 27 '26 07:05 gaozhangmin

@hangc0276 PTAL

gaozhangmin avatar May 27 '26 07:05 gaozhangmin

Thanks for improving this path and avoiding repeated metadata driver initialization.

One thing that might be worth considering is whether we can wire in the bookie server’s existing MetadataBookieDriver or LedgerManagerFactory here. Since the server already creates and owns those resources through its lifecycle, GC could potentially borrow the factory and only create/close the per-run LedgerUnderreplicationManager. That would keep the ownership/close semantics centralized while still achieving the reuse goal.

void-ptr974 avatar May 27 '26 14:05 void-ptr974

Thanks for improving this path and avoiding repeated metadata driver initialization.

One thing that might be worth considering is whether we can wire in the bookie server’s existing MetadataBookieDriver or LedgerManagerFactory here. Since the server already creates and owns those resources through its lifecycle, GC could potentially borrow the factory and only create/close the per-run LedgerUnderreplicationManager. That would keep the ownership/close semantics centralized while still achieving the reuse goal.

PTAL @void-ptr974

gaozhangmin avatar Jul 13 '26 08:07 gaozhangmin