Issue 4800: Reuse metadata driver for over-replicated ledger GC
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
ScanAndCompareGarbageCollectorfor over-replicated ledger cleanup. - Make
ScanAndCompareGarbageCollectorcloseable and release the cached metadata driver whenGarbageCollectorThreadshuts 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 requeste.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.
@hangc0276 PTAL
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.
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