Uh oh!
There was an error while loading. Please reload this page.
branch-4.1: [fix](cloud) Use bthread-aware shared mutex for tablet header lock - #66020
Conversation
### What problem does this PR solve? Issue Number: None Related PR: apache#64574 Problem Summary: The tablet header lock used a thread-affine shared mutex. In cloud mode, a bthread could suspend while holding the write lock and resume on another worker pthread, leaving the lock permanently wedged. Replace the tablet header lock with BthreadSharedMutex, which uses bthread-aware synchronization and supports cross-worker resume safely. Keep unrelated shared mutexes unchanged. ### Release note Fix a potential permanent tablet header lock wedge after bthread migration in cloud mode. ### Check List (For Author) - Test: Unit Test - ./run-be-ut.sh --run --filter=BthreadSharedMutexTest.* -j 32 (7 tests passed) - Behavior changed: Yes. The tablet header lock is now bthread-aware. - Does this need documentation: No
hello-stephen
commented
Jul 24, 2026
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Ports the tablet header lock from std::shared_mutex to a bthread-aware BthreadSharedMutex to avoid cross-thread unlock UB / wedges and writer-preferring recursive shared-lock deadlocks, and updates call sites accordingly.
Changes:
- Added
BthreadSharedMutex(bthread mutex/CV-based shared mutex) plus a dedicated unit test suite. - Replaced tablet/header lock types and updated lock guards (
std::lock_guard/std::unique_lock/std::shared_lock) to use the new mutex. - Introduced “*_unlocked” helper variants to avoid recursive shared acquisition under a writer-preferring lock.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| be/src/util/bthread_shared_mutex.h | Adds the bthread-compatible shared mutex implementation. |
| be/test/util/bthread_shared_mutex_test.cpp | Adds behavioral + regression tests for the new mutex (writer pending, migration, cross-thread unlock). |
| be/src/storage/tablet/base_tablet.h | Switches _meta_lock to BthreadSharedMutex and adds an unlocked compaction score accessor. |
| be/src/storage/tablet/base_tablet.cpp | Implements get_real_compaction_score_unlocked() and routes the locked version through it. |
| be/src/storage/tablet/tablet.h | Updates header lock accessor type and adds unlocked compaction rowset-picking declarations. |
| be/src/storage/tablet/tablet.cpp | Replaces lock types and avoids recursive shared locking via unlocked helpers. |
| be/src/storage/task/index_builder.cpp | Updates header lock guards to use the new lock type (CTAD). |
| be/src/storage/task/engine_clone_task.cpp | Updates header lock guard to use the new lock type (CTAD). |
| be/src/storage/tablet/tablet_manager.cpp | Updates header lock guard to use the new lock type (CTAD). |
| be/src/storage/schema_change/schema_change.cpp | Updates header lock guards to use the new lock type (CTAD). |
| be/src/storage/rowset_builder.cpp | Updates header lock guard to use the new lock type (CTAD). |
| be/src/storage/compaction/compaction.cpp | Updates header lock guards to use the new lock type (CTAD). |
| be/src/storage/compaction/full_compaction.cpp | Updates header lock guard to use the new lock type (CTAD). |
| be/src/storage/compaction/cumulative_compaction_time_series_policy.cpp | Switches to unlocked rowset-picking to avoid recursive shared acquisition. |
| be/src/cloud/cloud_tablet.h | Updates lock-typed parameters and adds unlocked rowset-picking APIs. |
| be/src/cloud/cloud_tablet.cpp | Removes inner shared locking in some paths and introduces unlocked rowset-picking implementations. |
| be/src/cloud/cloud_meta_mgr.h | Updates fill_version_holes to accept unique_lock<BthreadSharedMutex>&. |
| be/src/cloud/cloud_meta_mgr.cpp | Updates header-lock guards and fill_version_holes signature/usage. |
| be/src/cloud/cloud_base_compaction.cpp | Uses unlocked candidate selection under an existing shared header lock. |
| be/src/cloud/cloud_full_compaction.cpp | Uses unlocked candidate selection under an existing shared header lock. |
| be/src/cloud/cloud_cumulative_compaction.cpp | Switches traversal to an unlocked variant under an existing lock. |
| be/test/cloud/cloud_tablet_test.cpp | Updates test lock guards to use the new lock type (CTAD). |
| be/test/cloud/cloud_meta_mgr_test.cpp | Updates test lock guards to use the new lock type (CTAD). |
| be/test/cloud/cloud_empty_rowset_compaction_test.cpp | Updates test lock guards to use the new lock type (CTAD). |
| be/src/cloud/cloud_tablet.h | Updates stats comment to reflect BthreadSharedMutex. |
Comments suppressed due to low confidence (1)
be/src/cloud/cloud_tablet.cpp:1
- Same issue as
capture_versions_prefer_cache: the internal_meta_lockacquisition has been removed, turning this into an implicitly*_unlockedmethod without changing its name/signature. Recommendation (mandatory): provide an explicit locked entrypoint and a separate*_unlockedvariant (or rename this one to*_unlocked) so callers can’t accidentally invoke it without holding_meta_lock.
// Licensed to the Apache Software Foundation (ASF) under one
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
liaoxin01
commented
Jul 27, 2026
run buildall |
hello-stephen
commented
Jul 27, 2026
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
hello-stephen
commented
Jul 27, 2026
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
Uh oh!
There was an error while loading. Please reload this page.
Pick #64574