Issue 4800: Reuse metadata driver for over-replicated ledger GC#4801
Issue 4800: Reuse metadata driver for over-replicated ledger GC#4801gaozhangmin wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds lifecycle management for metadata resources used during over-replicated ledger GC by reusing a single MetadataBookieDriver/LedgerManagerFactory and explicitly closing them during shutdown.
Changes:
- Cache and reuse
MetadataBookieDriver/LedgerManagerFactoryinScanAndCompareGarbageCollectorinstead of recreating them per GC run. - Add
close()toScanAndCompareGarbageCollectorand invoke it fromGarbageCollectorThread.shutdown(). - Add a unit test validating driver reuse and cleanup behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/GarbageCollectorThreadTest.java | Adds a test to ensure the metadata driver is reused and then closed/reset. |
| bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/ScanAndCompareGarbageCollector.java | Introduces cached metadata driver/factory, lazy initialization, and explicit close logic. |
| bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java | Ensures the garbage collector’s metadata resources are closed during thread shutdown. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@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. |
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
ScanAndCompareGarbageCollectorfor over-replicated ledger cleanup.ScanAndCompareGarbageCollectorcloseable and release the cached metadata driver whenGarbageCollectorThreadshuts down.