branch-4.0: [Enhancement](recyclebin) Optimize lock granularity in CatalogRecycleBin #61366#61674
Merged
yiguolei merged 1 commit intoapache:branch-4.0from Mar 25, 2026
Merged
Conversation
…Bin (apache#61366) All methods in `CatalogRecycleBin.java` use `synchronized` (single monitor lock), creating extremely coarse lock granularity. When `erasePartition()` runs slowly with many partitions, other `synchronized` methods block waiting for the lock. Callers like `recyclePartition()` hold TABLE WRITE LOCK while waiting, causing cascading blocking that can bring down the entire Doris metadata service. Two complementary optimizations: - **Lock-free** (8 methods): Simple ConcurrentHashMap lookups (`isRecyclePartition`, `getRecycleTimeById`, etc.) - **Read lock** (4 methods): Read-only iterations (`allTabletsInRecycledStatus`, `getInfo`, `write`, etc.) - **Write lock** (11 methods): Map mutations (`recycleDatabase/Table/Partition`, `recover*`, `clearAll`) Refactored all 12 erase methods to process items **one at a time** with lock release between items: - **Inside write lock (per item)**: cleanup RPCs + map removal + edit log write - **Release lock between items**: other operations can proceed This reduces lock hold time from **O(N × T)** (all items) to **O(T)** (one item) per acquisition. Changed 4 internal maps from `HashMap` to `ConcurrentHashMap` to enable lock-free reads. 1. **NPE in `getIdListToEraseByRecycleTime`**: Used `getOrDefault` to handle stale IDs that may be concurrently removed between snapshot and processing 2. **DdlException in cascade erase**: Added try-catch in `eraseDatabaseInstantly`/`eraseTableInstantly` for partitions/tables concurrently erased by daemon - All 24 existing unit tests pass - Added 3 new concurrency tests: - `testConcurrentReadsDoNotBlock` — 10 concurrent reader threads - `testConcurrentRecycleAndRead` — writer + 5 readers simultaneously - `testMicrobatchEraseReleasesLockBetweenItems` — verifies recyclePartition succeeds during erase --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
run buildall |
Contributor
FE UT Coverage ReportIncrement line coverage |
yiguolei
approved these changes
Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
picked from #61366