8000 [BugFix] Fix concurrent issue in committed_rs_map (backport #58504) by mergify[bot] · Pull Request #58550 · StarRocks/starrocks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[BugFix] Fix concurrent issue in committed_rs_map (backport #58504) #58550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025

Conversation

mergify[bot]
Copy link
Contributor
@mergify mergify bot commented Apr 29, 2025

Why I'm doing:

The committed_rs_map uses phmap::parallel_flat_hash_map with segmented locking to achieve thread-safe concurrent operations. However, in the function add_committed_rowset, the current implementation performs ​​non-atomic​​ operations:

_committed_rs_map[rowset->rowset_id()] = rowset; 

This bypasses the map's built-in locking mechanism because:

  1. The operation splits into ​​two steps​​: a lookup (locked) followed by an assignment (protected)
  2. Between these steps, other threads may modify the map(e.g erase) and the return value of first look up maybe invalid, causing race conditions

The crash stack is like:

*** SIGSEGV (@0x0) received by PID 189038 (TID 0x153ccc5fd640) from PID 0; stack trace: ***
    @     0x153d7348ee18 __pthread_once_slow
    @          0x7d9f940 google::(anonymous namespace)::FailureSignalHandler(int, siginfo_t*, void*)
    @     0x153d7442b9b9 os::Linux::chained_handler(int, siginfo_t*, void*)
    @     0x153d74431c7a JVM_handle_linux_signal
    @     0x153d74423a4c signalHandler(int, siginfo_t*, void*)
    @     0x153d7343e6f0 (/usr/lib64/libc.so.6+0x3e6ef)
    @          0x61ac885 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_count<(__gnu_cxx::_Lock_policy)2> const&) [clone .isra.0]
    @          0x61bf20b starrocks::Tablet::add_committed_rowset(std::shared_ptr<starrocks::Rowset> const&)
    @          0x626f365 starrocks::TxnManager::commit_txn(starrocks::KVStore*, long, long, long, int, starrocks::UniqueId const&, starrocks::PUniqueId co
nst&, std::shared_ptr<starrocks::Rowset> const&, bool)
    @          0x626f9b0 starrocks::TxnManager::commit_txn(long, std::shared_ptr<starrocks::Tablet> const&, long, starrocks::PUniqueId const&, std::shared
_ptr<starrocks::Rowset> const&, bool)
    @          0x636c0f9 starrocks::DeltaWriter::commit()
    @          0x60db507 starrocks::SegmentFlushTask::run()
    @          0x397eab3 starrocks::ThreadPool::dispatch_thread()
    @          0x3976d56 starrocks::Thread::supervise_thread(void*)
    @     0x153d73489c02 start_thread
    @     0x153d7350ec40 __clone3

What I'm doing:

Replace with insert_or_assign() which is ​​fully atomic​​ under phmap's segmented lock:

// Thread-safe atomic operation
_committed_rs_map.insert_or_assign(rowset->rowset_id(), rowset);

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.5
    • 3.4
    • 3.3
    • 3.2
    • 3.1

This is an automatic backport of pull request #58504 done by [Mergify](https://mergify.com).

Signed-off-by: sevev <qiangzh95@gmail.com>
(cherry picked from commit 1b315cf)
@wanpengfei-git wanpengfei-git merged commit 8adebbd into branch-3.3 Apr 29, 2025
40 of 41 checks passed
@wanpengfei-git wanpengfei-git deleted the mergify/bp/branch-3.3/pr-58504 branch April 29, 2025 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0