Skip to content
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

fix: fix data race around PikaServer::statistic_::server_stat::exec_count_db #2671

Merged
merged 2 commits into from
May 29, 2024

Conversation

cheniujh
Copy link
Collaborator

该PR修复了 Issue #2670
Issue #2670 发生的原因
在PikaServer::statistic_::server_stat::exec_count_db 这个map上有高度并发,但是map本身没有mutex保护,第一批命令打到Pika时,这个map的insert会被并发调用。
该PR所做的修复
在Pika启动时对这个map进行主动insert,确保所有的cmd_name在该map内部都有个对应pair,这样后面针对该map进行并发时,就只会触发其查询接口,而不会调用Insert, 这样就算没有额外加锁,也是线程安全的。

This PR fixes Issue #2670
Cause of Issue #2670:
There is high concurrency on the map PikaServer::statistic_::server_stat::exec_count_db, but the map itself lacks mutex protection. When the first batch of commands hits Pika, the insert operation on this map is called concurrently.

Fix implemented in this PR:
During Pika startup, proactively insert into this map to ensure that every cmd_name has a corresponding pair within the map. This way, subsequent concurrent operations on the map will only trigger its query interface instead of calling insert. This approach ensures thread safety even without additional locking.

@github-actions github-actions bot added the ☢️ Bug Something isn't working label May 22, 2024
@AlexStocks AlexStocks merged commit efee7df into OpenAtomFoundation:unstable May 29, 2024
14 checks passed
@cheniujh cheniujh deleted the db_stat_multi_thread branch June 24, 2024 03:21
chejinge pushed a commit that referenced this pull request Jul 31, 2024
cheniujh added a commit to cheniujh/pika that referenced this pull request Sep 24, 2024
cheniujh added a commit to cheniujh/pika that referenced this pull request Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.5.5 4.0.0 ☢️ Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants