Uh oh!
There was an error while loading. Please reload this page.
branch-4.0: [fix](cloud) Use bthread-aware shared mutex for tablet header lock - #66019
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.
This PR backports #64574 to replace the tablet header/meta lock with a bthread-migration-safe shared mutex, and updates call sites to avoid self-deadlock from recursive shared acquisition under writer-preferring semantics.
Changes:
- Introduces
BthreadSharedMutex(bthread-basedstd::shared_mutexanalogue) and adds dedicated unit tests. - Replaces
std::shared_mutextablet header locks withBthreadSharedMutexand updates locking at key metadata mutation/read sites. - Adds/uses
_unlockedAPIs in tablet/cloud-tablet paths to prevent recursive lock acquisition under a shared lock.
Reviewed changes
Copilot reviewed 23 out of 23 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 bthread-aware shared mutex implementation. |
| be/test/util/bthread_shared_mutex_test.cpp | Adds correctness/regression/stress coverage for the new mutex. |
| be/src/olap/base_tablet.h | Switches meta lock type to BthreadSharedMutex; adds “_unlocked” score API declaration. |
| be/src/olap/base_tablet.cpp | Refactors compaction score calculation into locked + unlocked variants. |
| be/src/olap/tablet.h | Switches header lock return type; adds unlocked rowset-pick APIs to avoid recursive locking. |
| be/src/olap/tablet.cpp | Updates lock usage and routes through unlocked helper paths under existing shared locks. |
| be/src/cloud/cloud_tablet.h | Updates APIs taking header locks to use BthreadSharedMutex; introduces unlocked pick APIs. |
| be/src/cloud/cloud_tablet.cpp | Removes inner re-locking in “caller already holds lock” paths; updates lock types and pick APIs. |
| be/src/cloud/cloud_meta_mgr.h | Updates fill_version_holes lock parameter type. |
| be/src/cloud/cloud_meta_mgr.cpp | Updates lock type usage related to tablet header lock. |
| be/src/olap/task/index_builder.cpp | Updates header lock guard type to match new mutex. |
| be/src/olap/task/engine_clone_task.cpp | Updates header lock guard type to match new mutex. |
| be/src/olap/tablet_manager.cpp | Updates header lock guard type to match new mutex. |
| be/src/olap/schema_change.cpp | Updates header lock guard type to match new mutex. |
| be/src/olap/rowset_builder.cpp | Updates header lock guard type to match new mutex. |
| be/src/olap/full_compaction.cpp | Updates header lock guard type to match new mutex. |
| be/src/olap/compaction.cpp | Updates header lock guard type to match new mutex. |
| be/src/olap/cumulative_compaction_time_series_policy.cpp | Uses unlocked tablet API when caller already holds _meta_lock. |
| be/src/cloud/cloud_full_compaction.cpp | Uses unlocked cloud-tablet API under an existing shared header lock. |
| be/src/cloud/cloud_base_compaction.cpp | Uses unlocked cloud-tablet API under an existing shared header lock. |
| be/src/cloud/cloud_cumulative_compaction.cpp | Switches traversal call to unlocked variant in locked context. |
| be/test/cloud/cloud_meta_mgr_test.cpp | Updates tests to lock with new header lock type (via CTAD). |
| be/test/cloud/cloud_empty_rowset_compaction_test.cpp | Updates tests to lock with new header lock type (via CTAD). |
💡 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
|
liaoxin01
commented
Jul 27, 2026
run buildall |
PR approved by at least one committer and no changes requested. |
PR approved by anyone and no changes requested. |
hello-stephen
commented
Jul 27, 2026
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
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
|
1 similar comment
hello-stephen
commented
Jul 27, 2026
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
hello-stephen
commented
Jul 27, 2026
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
hello-stephen
commented
Jul 27, 2026
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
liaoxin01
commented
Jul 27, 2026
run p0 |
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