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

feat:thread purge #2697

Merged
merged 8 commits into from
Jun 19, 2024
Merged

Conversation

chejinge
Copy link
Collaborator

@chejinge chejinge commented Jun 5, 2024

  • 去掉CliProcessorBgThread,根据配置启动线程
  • set class Thread与BgThread 线程名
  • slow_cmd设置线程启动开关,根据配置启动或者销毁线程
  • 快慢命令避免启动线程太多

快慢命令线程池的退出会判断队列的大小是否为0,不为0会循环去等待直到为0,线程池会退出

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration parameter slow-cmd-pool to control the separation of fast and slow commands with options yes or no.
  • Improvements

    • Added support for configuring the "slow-cmd-pool" setting in the admin interface.
    • Enhanced thread management by setting descriptive thread names across various components for easier debugging and monitoring.
  • Removals

    • Removed the method SetLoopDBStateMachine from the PikaServer class.
  • Bug Fixes

    • Improved configuration handling to better manage command thread pools.

@github-actions github-actions bot added the ✏️ Feature New feature or request label Jun 5, 2024
Copy link

coderabbitai bot commented Jun 5, 2024

Walkthrough

This update introduces a new feature into the Pika project to manage a separate thread pool for slow commands. Key changes include adding the slow-cmd-pool configuration in the pika.conf file, which allows toggling this feature. Corresponding methods were added and modified in various classes like PikaConf, PikaServer, and PikaAdmin to support this configuration and manage the slow command thread pool accordingly.

Changes

Files Change Summary
include/pika_conf.h Added SetSlowCmdPool method in PikaConf to handle slow_cmd_pool_ property.
conf/pika.conf Introduced slow-cmd-pool parameter for configuring slow command pool.
include/pika_server.h Added SetSlowCmdThreadPoolFlag(bool flag) method, removed SetLoopDBStateMachine, and modified other methods.
src/pika_admin.cc Updated ConfigGet and ConfigSet to handle slow-cmd-pool configuration.
src/pika_conf.cc Modified PikaConf::Load to handle slow-cmd-pool and adjusted validation for slow-cmd-thread-pool-size_.
src/pika_server.cc Added slow_cmd_thread_pool_flag_ member and related logic, updated various scheduling methods to set thread names.
src/rsync_client.cc Set thread name in RsyncClient::Init method before starting the thread.

Poem

In the code where threads do dance,
A slow command pool now gets its chance.
Splitting tasks, both fast and slow,
With careful checks, our system grows.
Toggle on in pika.conf, oh what a scene!
Efficiency reigns, where once was routine.
Cheers to progress, in code, we dream! 🎉🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1705916 and 1e86940.

Files selected for processing (9)
  • conf/pika.conf (1 hunks)
  • include/pika_client_processor.h (1 hunks)
  • include/pika_conf.h (3 hunks)
  • include/pika_server.h (4 hunks)
  • src/net/src/net_thread.cc (1 hunks)
  • src/pika_admin.cc (3 hunks)
  • src/pika_client_processor.cc (2 hunks)
  • src/pika_conf.cc (2 hunks)
  • src/pika_server.cc (5 hunks)
Additional comments not posted (11)
include/pika_server.h (1)

98-98: Addition of SetSlowCmdThreadPoolFlag method aligns with PR objectives.

The new method SetSlowCmdThreadPoolFlag is a good addition for managing the separation of slow and fast commands as described in the PR objectives.

conf/pika.conf (1)

30-33: Addition of slow-cmd-pool configuration parameter is well-documented and clear.

The new configuration parameter slow-cmd-pool is clearly documented and aligns with the PR objectives to manage the separation of slow and fast commands effectively.

src/pika_conf.cc (1)

162-166: Configuration validation for slow-cmd-thread-pool-size is implemented correctly.

This ensures that the thread pool size is within a reasonable range, preventing potential resource exhaustion.

include/pika_conf.h (3)

189-192: The getter method for slow_cmd_pool is correctly implemented with thread safety using std::shared_lock. This ensures that the value can be read concurrently without race conditions.


581-585: The setter method for slow_cmd_pool is correctly implemented with thread safety using std::lock_guard. The use of TryPushDiffCommands to log the change is consistent with other configuration setters in the class.


856-856: The declaration of slow_cmd_pool_ as std::atomic<bool> is appropriate for ensuring thread safety in concurrent environments. This is consistent with the atomic usage for other similar configuration flags in the class.

src/pika_server.cc (3)

46-46: Initialization of slow_cmd_thread_pool_flag_ in constructor.

This change aligns with the PR's objective to manage slow command pools. The flag is correctly initialized to false, indicating that the slow command pool is disabled by default.


104-104: Setting the slow command thread pool flag based on configuration.

This line correctly sets the slow_cmd_thread_pool_flag_ based on the configuration value retrieved from g_pika_conf->slow_cmd_pool(). This is a crucial part of integrating the new configuration parameter into the system.


204-217: Implementation of SetSlowCmdThreadPoolFlag method.

This method correctly handles the enabling and disabling of the slow command thread pool based on the provided flag. It also includes error handling for thread pool startup failures, which is a good practice.

src/pika_admin.cc (2)

1603-1607: Add handling for the new configuration parameter slow-cmd-pool.

The implementation correctly handles the new configuration parameter slow-cmd-pool by encoding its value as a string and appending it to the configuration body. This is consistent with the handling of other configuration parameters in the system.


Line range hint 2138-2310: Ensure proper handling of the slow-cmd-pool configuration in the ConfigSet function.

The ConfigSet function now includes handling for the slow-cmd-pool configuration parameter. This change allows the system to enable or disable a pool for slow commands based on the configuration. It is important to verify that this new configuration is being handled correctly throughout the system.

Verification successful

The ConfigSet function is defined and used in the src/pika_admin.cc file and declared in the include/pika_admin.h file. To ensure that the slow-cmd-pool configuration is properly handled, we need to verify the implementation of the ConfigSet function in src/pika_admin.cc.


The previous attempt to extract the implementation of the ConfigSet function did not produce any output. This might be due to a syntax issue or an incorrect pattern in the ast-grep command. To ensure we get the correct implementation, let's refine our approach by using rg to search for the function definition directly in the src/pika_admin.cc file.


The ConfigSet function implementation in src/pika_admin.cc includes handling for the slow-cmd-pool configuration. This confirms that the configuration parameter is recognized and processed within the function.

  • The slow-cmd-pool configuration is listed among other configuration parameters in the ConfigSet function.

Based on the gathered information, the handling of the slow-cmd-pool configuration appears to be correctly integrated into the ConfigSet function.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `slow-cmd-pool` configuration is properly handled in the `ConfigSet` function.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type python $'ConfigSet'

Length of output: 59



Script:

#!/bin/bash
# Description: Verify that the `slow-cmd-pool` configuration is properly handled in the `ConfigSet` function.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type cc $'ConfigSet'

Length of output: 51



Script:

#!/bin/bash
# Description: Verify that the `slow-cmd-pool` configuration is properly handled in the `ConfigSet` function.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type cpp $'ConfigSet'

Length of output: 196



Script:

#!/bin/bash
# Description: Verify the implementation of the `ConfigSet` function in `src/pika_admin.cc` to ensure proper handling of the `slow-cmd-pool` configuration.

# Extract the implementation of the `ConfigSet` function from `src/pika_admin.cc`.
ast-grep --lang cpp --pattern $'void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
  $$$
}' src/pika_admin.cc

Length of output: 111



Script:

#!/bin/bash
# Description: Verify the implementation of the `ConfigSet` function in `src/pika_admin.cc` to ensure proper handling of the `slow-cmd-pool` configuration.

# Extract the implementation of the `ConfigSet` function from `src/pika_admin.cc`.
rg --context 20 'void ConfigCmd::ConfigSet' src/pika_admin.cc

Length of output: 1382

ret = pika_slow_cmd_thread_pool_->start_thread_pool();
if (ret != net::kSuccess) {
dbs_.clear();
LOG(FATAL) << "Start PikaLowLevelThreadPool Error: " << ret
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG(FATAL)会导致进程abort退出,这个函数可以通过发命令的方式调用到,这个时候如果进程退出就不太好了。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG(FATAL)会导致进程abort退出,这个函数可以通过发命令的方式调用到,这个时候如果进程退出就不太好了。
done

<< (ret == net::kCreateThreadError ? ": create thread error " : ": other error");
}
} else {
pika_slow_cmd_thread_pool_->stop_thread_pool();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stop_thread_pool应该是不会等队列里的任务被执行完成再结束,stop_thread_pool的时候队列里还有任务,那这些任务就被丢掉了。进而对应连接就不会被再次唤醒了。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stop_thread_pool应该是不会等队列里的任务被执行完成再结束,stop_thread_pool的时候队列里还有任务,那这些任务就被丢掉了。进而对应连接就不会被再次唤醒了。

done

dbs_.clear();
LOG(FATAL) << "Start PikaLowLevelThreadPool Error: " << ret
<< (ret == net::kCreateThreadError ? ": create thread error " : ": other error");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pika_slow_cmd_thread_pool_->Schedule()的地方建议加个判断,因为现在is_slow_cmd和你开启slowcmdthreadpool是两个配置参数,如果is_slow_cmd判断为true,但是没有开slowcmdthreadpool,就会有问题。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pika_slow_cmd_thread_pool_->Schedule()的地方建议加个判断,因为现在is_slow_cmd和你开启slowcmdthreadpool是两个配置参数,如果is_slow_cmd判断为true,但是没有开slowcmdthreadpool,就会有问题。

done

@OpenAtomFoundation OpenAtomFoundation deleted a comment from coderabbitai bot Jun 5, 2024
@OpenAtomFoundation OpenAtomFoundation deleted a comment from coderabbitai bot Jun 5, 2024
@AlexStocks
Copy link
Collaborator

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Review 🔍

⏱️ Estimated effort to review [1-5]

3, because the PR involves changes across multiple files and layers of the application, including thread management and configuration settings. Understanding the impact of these changes on the system's behavior and performance requires a thorough review.

🧪 Relevant tests

No

⚡ Possible issues

Thread Naming: The PR sets all thread names to "pika" unconditionally, which could lead to confusion when debugging or monitoring threads, as it removes the ability to distinguish between different types of threads based on their names.

Configuration Validation: The validation for slow-cmd-pool in ConfigSet method only checks for 'yes' or 'no', but does not handle other invalid inputs robustly, potentially leading to misconfigurations or errors.

🔒 Security concerns

No

Code feedback:
relevant filesrc/net/src/net_thread.cc
suggestion      

Consider preserving the ability to set custom thread names for better traceability and debugging. You could append "pika" as a prefix or suffix to the original thread name instead of replacing it entirely. [important]

relevant lineSetThreadName(pthread_self(), "pika");

relevant filesrc/pika_admin.cc
suggestion      

Add more robust validation for the slow-cmd-pool configuration setting in the ConfigSet method. Consider handling cases where the input is neither 'yes' nor 'no', to prevent potential misconfigurations. [important]

relevant line} else {

@AlexStocks
Copy link
Collaborator

@CodiumAI-Agent /improve

@CodiumAI-Agent
Copy link

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
Possible issue
Replace hardcoded thread name with dynamic thread name

Replace the hardcoded thread name "pika" with the thread's actual name from the thread
object to maintain the dynamic naming functionality.

src/net/src/net_thread.cc [20]

-SetThreadName(pthread_self(), "pika");
+SetThreadName(pthread_self(), thread->thread_name().c_str());
 
Suggestion importance[1-10]: 10

Why: The suggestion correctly identifies a potential issue with hardcoding the thread name and provides a solution that maintains the dynamic naming functionality, which is crucial for debugging and monitoring.

10
Possible bug
Check for initialization of the thread pool pointer before using it

Ensure that pika_slow_cmd_thread_pool_ is initialized before calling start_thread_pool or
stop_thread_pool on it to avoid calling methods on an uninitialized pointer.

src/pika_server.cc [208-215]

-pika_slow_cmd_thread_pool_->start_thread_pool();
-pika_slow_cmd_thread_pool_->stop_thread_pool();
+if (pika_slow_cmd_thread_pool_) {
+  pika_slow_cmd_thread_pool_->start_thread_pool();
+  pika_slow_cmd_thread_pool_->stop_thread_pool();
+} else {
+  // Handle uninitialized pointer scenario
+}
 
Suggestion importance[1-10]: 9

Why: Ensuring that pika_slow_cmd_thread_pool_ is initialized before calling its methods is crucial to avoid undefined behavior. This suggestion addresses a potential bug and enhances code safety.

9
Add null checks for global pointers to prevent dereferencing null pointers

Add a check for g_pika_conf and g_pika_server being non-null before using them to prevent
potential null pointer dereferences.

src/pika_admin.cc [1606-2302]

-EncodeString(&config_body, g_pika_conf->slow_cmd_pool() ? "yes" : "no");
-g_pika_server->SetSlowCmdThreadPoolFlag(SlowCmdPool);
+if (g_pika_conf && g_pika_server) {
+  EncodeString(&config_body, g_pika_conf->slow_cmd_pool() ? "yes" : "no");
+  g_pika_server->SetSlowCmdThreadPoolFlag(SlowCmdPool);
+} else {
+  // Handle null pointer scenario
+}
 
Suggestion importance[1-10]: 8

Why: Adding null checks for global pointers is a good practice to prevent potential null pointer dereferences, which can lead to crashes. This suggestion addresses a possible bug and improves the robustness of the code.

8
Enhancement
Use std::clamp to ensure thread pool size is within a valid range

Refactor the conditional logic for setting slow_cmd_thread_pool_size_ to ensure that the
value is always within the valid range [0, 50].

src/pika_conf.cc [163-167]

-if (slow_cmd_thread_pool_size_ < 0) {
-  slow_cmd_thread_pool_size_ = 8;
-}
-if (slow_cmd_thread_pool_size_ > 50) {
-  slow_cmd_thread_pool_size_ = 50;
-}
+slow_cmd_thread_pool_size_ = std::clamp(slow_cmd_thread_pool_size_, 0, 50);
 
Suggestion importance[1-10]: 7

Why: The use of std::clamp simplifies the code and ensures that the thread pool size is always within the valid range. This is a minor enhancement that improves code readability and maintainability.

7

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1e86940 and 53c81c0.

Files selected for processing (10)
  • conf/pika.conf (1 hunks)
  • include/pika_client_processor.h (1 hunks)
  • include/pika_conf.h (3 hunks)
  • include/pika_server.h (4 hunks)
  • src/net/src/net_thread.cc (1 hunks)
  • src/pika_admin.cc (3 hunks)
  • src/pika_client_processor.cc (2 hunks)
  • src/pika_conf.cc (2 hunks)
  • src/pika_server.cc (5 hunks)
  • src/rsync_server.cc (1 hunks)
Files skipped from review as they are similar to previous changes (8)
  • conf/pika.conf
  • include/pika_client_processor.h
  • include/pika_conf.h
  • src/net/src/net_thread.cc
  • src/pika_admin.cc
  • src/pika_client_processor.cc
  • src/pika_conf.cc
  • src/pika_server.cc
Additional comments not posted (2)
include/pika_server.h (2)

98-98: The addition of SetSlowCmdThreadPoolFlag method is correctly implemented.


649-649: Ensure slow_cmd_thread_pool_flag_ is initialized in the PikaServer constructor.

@@ -33,6 +33,7 @@ void RsyncWriteResp(RsyncService::RsyncResponse& response, std::shared_ptr<net::
RsyncServer::RsyncServer(const std::set<std::string>& ips, const int port) {
work_thread_ = std::make_unique<net::ThreadPool>(2, 100000);
rsync_server_thread_ = std::make_unique<RsyncServerThread>(ips, port, 1 * 1000, this);
rsync_server_thread_->set_thread_name("RsyncServer");
Copy link

@coderabbitai coderabbitai bot Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using dynamic thread names for better traceability.

-  rsync_server_thread_->set_thread_name("RsyncServer");
+  rsync_server_thread_->set_thread_name("RsyncServer-" + std::to_string(port));

This change appends the port number to the thread name, making it easier to identify in logs and monitoring tools.

Committable suggestion was skipped due to low confidence.

@chejinge chejinge closed this Jun 5, 2024
@chejinge chejinge reopened this Jun 5, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 53c81c0 and d6cb38d.

Files selected for processing (1)
  • src/pika_server.cc (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/pika_server.cc

@chejinge
Copy link
Collaborator Author

chejinge commented Jun 6, 2024

  • 去掉CliProcessorBgThread,根据配置启动线程
  • set class Thread与BgThread 线程名
  • slow_cmd设置线程启动开关,根据配置启动或者销毁线程
  • 快慢命令避免启动线程太多

Summary by CodeRabbit

  • New Features

    • Introduced a configuration parameter slow-cmd-pool to manage fast and slow command separation.
    • Added support for configuring the slow-cmd-pool setting via ConfigGet and ConfigSet commands.
  • Improvements

    • Enhanced thread naming consistency by setting all thread names to "pika".
  • Refactor

    • Modified internal handling of background threads, including the removal of certain thread management methods and initialization steps.
  • Bug Fixes

    • Adjusted configuration handling for slow-cmd-thread-pool-size limits.

@@ -17,7 +17,7 @@ Thread::~Thread() = default;
void* Thread::RunThread(void* arg) {
auto thread = reinterpret_cast<Thread*>(arg);
if (!(thread->thread_name().empty())) {
SetThreadName(pthread_self(), thread->thread_name());
SetThreadName(pthread_self(), "pika");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.修改ThreadPoolWorke 命名
2.修改继承thread/bgthread的命名
根据各自功能命名

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.修改ThreadPoolWorke 命名 2.修改继承thread/bgthread的命名 根据各自功能命名

done

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d6cb38d and 58df896.

Files selected for processing (14)
  • src/net/include/backend_thread.h (1 hunks)
  • src/net/include/client_thread.h (1 hunks)
  • src/net/include/net_thread.h (1 hunks)
  • src/net/include/server_thread.h (1 hunks)
  • src/net/src/backend_thread.cc (1 hunks)
  • src/net/src/client_thread.cc (1 hunks)
  • src/net/src/net_thread_name.h (1 hunks)
  • src/net/src/net_util.cc (1 hunks)
  • src/net/src/net_util.h (1 hunks)
  • src/net/src/server_thread.cc (1 hunks)
  • src/net/src/thread_pool.cc (2 hunks)
  • src/pika_repl_server.cc (1 hunks)
  • src/pika_server.cc (9 hunks)
  • src/rsync_server.cc (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/net/src/client_thread.cc
Files skipped from review as they are similar to previous changes (2)
  • src/pika_server.cc
  • src/rsync_server.cc
Additional comments not posted (4)
src/net/src/net_util.h (1)

83-83: Proper use of method overriding for set_thread_name.

This ensures that the base class functionality is preserved while allowing for extension in the derived class.

src/net/src/net_util.cc (1)

129-129: Setting the thread name to "TimerTaskThread" enhances traceability and debugging. Ensure this naming convention is consistent across all threads for uniformity.

Verification successful

The thread naming convention is consistent and descriptive across the system, supporting the change made in src/net/src/net_util.cc.

  • tools/pika-port/pika_port_3/trysync_thread.h: TrysyncThread
  • src/pika_dispatch_thread.cc: Dispatcher
  • src/pika_repl_client.cc: PikaReplClient
  • src/pika_repl_bgworker.cc: ReplBgWorker
  • src/rsync_server.cc: RsyncServerThread
  • src/pika_repl_server.cc: PikaReplServer
  • src/pika_server.cc: BGSaveTaskThread, PurgelogsTaskThread, PurgeDirTaskThread, KeyScanTaskThread, Bgslotsreload
  • src/pika_cache_load_thread.cc: PikaCacheLoadThread
  • src/net/src/client_thread.cc: ClientThread
  • src/net/src/server_thread.cc: ServerThread
  • src/net/src/net_util.cc: TimerTaskThread
  • src/net/src/net_pubsub.cc: PubSubThread
  • src/net/src/dispatch_thread.cc: WorkerThread
  • include/pika_slaveping_thread.h: SlavePingThread
  • include/pika_auxiliary_thread.h: AuxiliaryThread
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify consistency of thread naming across the system.

# Test: Search for thread naming patterns. Expect: Consistent naming convention.
rg --type cpp 'set_thread_name'

Length of output: 2118

src/pika_repl_server.cc (1)

20-20: Initializing the thread pool with the name "PikaReplServer" enhances manageability and traceability. Ensure that this naming convention does not conflict with other named resources in the system.

Verification successful

The naming of the thread pool as "PikaReplServer" is consistent with other components and does not cause any conflicts.

  • src/pika_repl_server.cc: The thread pool is named "PikaReplServer".
  • include/pika_repl_server_thread.h: The thread name is set to "PikaReplServer".
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of the "PikaReplServer" thread pool with the rest of the system.

# Test: Search for the usage of "PikaReplServer" in thread-related configurations. Expect: No conflicts or redundant definitions.
rg --type cpp 'PikaReplServer'

Length of output: 5685

src/net/include/server_thread.h (1)

153-153: The override of set_thread_name ensures that server threads can have specific names, which is crucial for debugging and monitoring. Consider adding a comment explaining why this override is necessary, especially if the behavior differs from the base class.

@@ -110,6 +110,7 @@ class BackendThread : public Thread {
*/
int StartThread() override;
int StopThread() override;
void set_thread_name(const std::string& name) override { Thread::set_thread_name(name); }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properly overriding the set_thread_name method in BackendThread allows for dynamic and specific thread naming, which is crucial for debugging. Consider encapsulating thread naming logic within the Thread class to avoid redundancy across derived classes.

- void set_thread_name(const std::string& name) override { Thread::set_thread_name(name); }
+ // This method is now handled in the base class to avoid redundancy.

Committable suggestion was skipped due to low confidence.

@@ -110,6 +110,7 @@ class ClientThread : public Thread {
*/
int StartThread() override;
int StopThread() override;
void set_thread_name(const std::string& name) override { Thread::set_thread_name(name); }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensuring that ClientThread can have its thread name set dynamically aids in monitoring and debugging. As with BackendThread, consider centralizing thread naming logic to reduce redundancy.

- void set_thread_name(const std::string& name) override { Thread::set_thread_name(name); }
+ // This method is now handled in the base class to avoid redundancy.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void set_thread_name(const std::string& name) override { Thread::set_thread_name(name); }
// This method is now handled in the base class to avoid redundancy.

@@ -123,6 +123,7 @@ int ServerThread::StartThread() {
if (ret != kSuccess) {
return ret;
}
set_thread_name("ServerThread");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the thread name to "ServerThread" is hardcoded here, which could limit flexibility and clarity in debugging. Consider using a dynamic naming strategy that incorporates unique identifiers or conditions to enhance traceability.

- set_thread_name("ServerThread");
+ set_thread_name("ServerThread-" + std::to_string(port_));
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set_thread_name("ServerThread");
set_thread_name("ServerThread-" + std::to_string(port_));

@@ -48,6 +48,8 @@ int BackendThread::StartThread() {
if (res) {
return res;
}
set_thread_name("BackendThread");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the server thread, setting the thread name to "BackendThread" is hardcoded. Consider using a dynamic naming strategy here as well to improve monitoring and debugging capabilities.

- set_thread_name("BackendThread");
+ set_thread_name("BackendThread-" + std::to_string(port_));
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set_thread_name("BackendThread");
set_thread_name("BackendThread-" + std::to_string(port_));

@@ -34,7 +34,7 @@ class Thread : public pstd::noncopyable {

std::string thread_name() const { return thread_name_; }

void set_thread_name(const std::string& name) { thread_name_ = name; }
virtual void set_thread_name(const std::string& name) { thread_name_ = name; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding synchronization to set_thread_name.

To ensure thread safety when multiple threads might be setting the thread name simultaneously, consider using a mutex:

+ std::lock_guard<std::mutex> lock(name_mutex_);
  thread_name_ = name;

Add a private member std::mutex name_mutex_; to the Thread class to support this.

Committable suggestion was skipped due to low confidence.

Comment on lines +28 to +29
std::string thread_id_str = std::to_string(reinterpret_cast<unsigned long>(thread_id_));
SetThreadName(thread_id_, thread_pool_->thread_pool_name() + "_Worker_" + thread_id_str);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider improving portability of thread ID conversion.

The current method of casting pthread_t to unsigned long may not be portable across different platforms where pthread_t is not an integer type. Consider using a portable method to obtain a string representation of pthread_t:

- std::string thread_id_str = std::to_string(reinterpret_cast<unsigned long>(thread_id_));
+ std::string thread_id_str = std::to_string(std::hash<std::thread::id>()(std::thread::id(thread_id_)));

This uses the standard library's hash function to convert the thread ID to a string in a more portable manner.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
std::string thread_id_str = std::to_string(reinterpret_cast<unsigned long>(thread_id_));
SetThreadName(thread_id_, thread_pool_->thread_pool_name() + "_Worker_" + thread_id_str);
std::string thread_id_str = std::to_string(std::hash<std::thread::id>()(std::thread::id(thread_id_)));
SetThreadName(thread_id_, thread_pool_->thread_pool_name() + "_Worker_" + thread_id_str);

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 267179d and 013f51a.

Files selected for processing (19)
  • include/pika_repl_bgworker.h (1 hunks)
  • src/net/include/backend_thread.h (1 hunks)
  • src/net/include/client_thread.h (1 hunks)
  • src/net/include/net_thread.h (1 hunks)
  • src/net/include/server_thread.h (1 hunks)
  • src/net/src/backend_thread.cc (1 hunks)
  • src/net/src/client_thread.cc (1 hunks)
  • src/net/src/dispatch_thread.cc (1 hunks)
  • src/net/src/holy_thread.cc (1 hunks)
  • src/net/src/holy_thread.h (1 hunks)
  • src/net/src/net_thread_name.h (1 hunks)
  • src/net/src/net_util.cc (1 hunks)
  • src/net/src/net_util.h (1 hunks)
  • src/net/src/thread_pool.cc (2 hunks)
  • src/pika_repl_client.cc (1 hunks)
  • src/pika_repl_server.cc (2 hunks)
  • src/pika_server.cc (13 hunks)
  • src/rsync_client.cc (1 hunks)
  • src/rsync_server.cc (2 hunks)
Files skipped from review as they are similar to previous changes (17)
  • src/net/include/backend_thread.h
  • src/net/include/client_thread.h
  • src/net/include/net_thread.h
  • src/net/include/server_thread.h
  • src/net/src/backend_thread.cc
  • src/net/src/client_thread.cc
  • src/net/src/holy_thread.cc
  • src/net/src/holy_thread.h
  • src/net/src/net_thread_name.h
  • src/net/src/net_util.cc
  • src/net/src/net_util.h
  • src/net/src/thread_pool.cc
  • src/pika_repl_client.cc
  • src/pika_repl_server.cc
  • src/pika_server.cc
  • src/rsync_client.cc
  • src/rsync_server.cc

Comment on lines 31 to 33
void SetThreadName(std::string& thread_name) {
bg_thread_.set_thread_name(thread_name);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider changing the parameter of SetThreadName to a const reference.

- void SetThreadName(std::string& thread_name) {
+ void SetThreadName(const std::string& thread_name) {
    bg_thread_.set_thread_name(thread_name);
  }

This change ensures that the input string is not modified by the method, aligning with common C++ best practices for setter functions.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void SetThreadName(std::string& thread_name) {
bg_thread_.set_thread_name(thread_name);
}
void SetThreadName(const std::string& thread_name) {
bg_thread_.set_thread_name(thread_name);
}

@@ -66,7 +66,7 @@ int DispatchThread::StartThread() {
// Adding timer tasks and run timertaskThread
timerTaskThread_.AddTimerTask("blrpop_blocking_info_scan", 250, true,
[this] { this->ScanExpiredBlockedConnsOfBlrpop(); });

timerTaskThread_.set_thread_name("TimerTaskThread");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the thread name before starting the thread is a good practice.

Consider allowing dynamic thread naming for greater flexibility, especially useful in environments with multiple timer tasks.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 013f51a and 526affd.

Files selected for processing (19)
  • include/pika_repl_bgworker.h (1 hunks)
  • src/net/include/backend_thread.h (1 hunks)
  • src/net/include/client_thread.h (1 hunks)
  • src/net/include/net_thread.h (1 hunks)
  • src/net/include/server_thread.h (1 hunks)
  • src/net/src/backend_thread.cc (1 hunks)
  • src/net/src/client_thread.cc (1 hunks)
  • src/net/src/dispatch_thread.cc (1 hunks)
  • src/net/src/holy_thread.cc (1 hunks)
  • src/net/src/holy_thread.h (1 hunks)
  • src/net/src/net_thread_name.h (1 hunks)
  • src/net/src/net_util.cc (1 hunks)
  • src/net/src/net_util.h (1 hunks)
  • src/net/src/thread_pool.cc (2 hunks)
  • src/pika_repl_client.cc (1 hunks)
  • src/pika_repl_server.cc (2 hunks)
  • src/pika_server.cc (13 hunks)
  • src/rsync_client.cc (1 hunks)
  • src/rsync_server.cc (2 hunks)
Files skipped from review as they are similar to previous changes (18)
  • include/pika_repl_bgworker.h
  • src/net/include/backend_thread.h
  • src/net/include/client_thread.h
  • src/net/include/net_thread.h
  • src/net/include/server_thread.h
  • src/net/src/backend_thread.cc
  • src/net/src/client_thread.cc
  • src/net/src/dispatch_thread.cc
  • src/net/src/holy_thread.cc
  • src/net/src/holy_thread.h
  • src/net/src/net_thread_name.h
  • src/net/src/net_util.cc
  • src/net/src/net_util.h
  • src/net/src/thread_pool.cc
  • src/pika_repl_client.cc
  • src/pika_repl_server.cc
  • src/rsync_client.cc
  • src/rsync_server.cc
Additional comments not posted (1)
src/pika_server.cc (1)

104-104: Ensure SetSlowCmdThreadPoolFlag is correctly initializing the slow command thread pool based on configuration.

Verification successful

The SetSlowCmdThreadPoolFlag function is used in two places:

  1. In the PikaServer constructor to initialize the slow command thread pool based on the configuration.
  2. In pika_admin.cc to dynamically set the slow command thread pool flag based on user input.

The function SetSlowCmdThreadPoolFlag itself sets the slow_cmd_thread_pool_flag_ and starts the thread pool if the flag is true. This indicates that the function is correctly designed to initialize the thread pool based on the configuration.

Given this context, the placement of SetSlowCmdThreadPoolFlag in the constructor appears to be correct and ensures that the thread pool is initialized based on the configuration provided by g_pika_conf->slow_cmd_pool().

No further verification is needed as the function is correctly used to initialize the thread pool based on the configuration.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `SetSlowCmdThreadPoolFlag` correctly initializes the thread pool based on the configuration.

# Test: Search for the method usage and configuration handling.
rg --type cpp --context 5 'SetSlowCmdThreadPoolFlag'

Length of output: 2186

@@ -707,17 +721,13 @@ void PikaServer::SetFirstMetaSync(bool v) {
}

void PikaServer::ScheduleClientPool(net::TaskFunc func, void* arg, bool is_slow_cmd) {
if (is_slow_cmd) {
if (is_slow_cmd && g_pika_conf->slow_cmd_pool()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add safety checks to ensure pika_slow_cmd_thread_pool_ is initialized before scheduling tasks in ScheduleClientPool.

+ if (!pika_slow_cmd_thread_pool_) {
+   LOG(WARNING) << "Slow command thread pool is not initialized";
+   return;
+ }
  if (is_slow_cmd && g_pika_conf->slow_cmd_pool()) {
    pika_slow_cmd_thread_pool_->Schedule(func, arg);
    return;
  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (is_slow_cmd && g_pika_conf->slow_cmd_pool()) {
if (!pika_slow_cmd_thread_pool_) {
LOG(WARNING) << "Slow command thread pool is not initialized";
return;
}
if (is_slow_cmd && g_pika_conf->slow_cmd_pool()) {
pika_slow_cmd_thread_pool_->Schedule(func, arg);
return;
}

Comment on lines +204 to +220
void PikaServer::SetSlowCmdThreadPoolFlag(bool flag) {
slow_cmd_thread_pool_flag_ = flag;
int ret = 0;
if (flag) {
ret = pika_slow_cmd_thread_pool_->start_thread_pool();
if (ret != net::kSuccess) {
dbs_.clear();
LOG(ERROR) << "Start PikaLowLevelThreadPool Error: " << ret
<< (ret == net::kCreateThreadError ? ": create thread error " : ": other error");
}
} else {
while (SlowCmdThreadPoolCurQueueSize() != 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
pika_slow_cmd_thread_pool_->stop_thread_pool();
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider enhancing error handling in SetSlowCmdThreadPoolFlag to include recovery mechanisms or retries when starting the thread pool fails.

+ try {
    ret = pika_slow_cmd_thread_pool_->start_thread_pool();
    if (ret != net::kSuccess) {
      dbs_.clear();
      LOG(ERROR) << "Start PikaLowLevelThreadPool Error: " << ret
                 << (ret == net::kCreateThreadError ? ": create thread error " : ": other error");
    }
+ } catch (const std::exception& e) {
+   LOG(ERROR) << "Exception caught while starting thread pool: " << e.what();
+   // Implement recovery or retry logic here
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void PikaServer::SetSlowCmdThreadPoolFlag(bool flag) {
slow_cmd_thread_pool_flag_ = flag;
int ret = 0;
if (flag) {
ret = pika_slow_cmd_thread_pool_->start_thread_pool();
if (ret != net::kSuccess) {
dbs_.clear();
LOG(ERROR) << "Start PikaLowLevelThreadPool Error: " << ret
<< (ret == net::kCreateThreadError ? ": create thread error " : ": other error");
}
} else {
while (SlowCmdThreadPoolCurQueueSize() != 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
pika_slow_cmd_thread_pool_->stop_thread_pool();
}
}
void PikaServer::SetSlowCmdThreadPoolFlag(bool flag) {
slow_cmd_thread_pool_flag_ = flag;
int ret = 0;
if (flag) {
try {
ret = pika_slow_cmd_thread_pool_->start_thread_pool();
if (ret != net::kSuccess) {
dbs_.clear();
LOG(ERROR) << "Start PikaLowLevelThreadPool Error: " << ret
<< (ret == net::kCreateThreadError ? ": create thread error " : ": other error");
}
} catch (const std::exception& e) {
LOG(ERROR) << "Exception caught while starting thread pool: " << e.what();
// Implement recovery or retry logic here
}
} else {
while (SlowCmdThreadPoolCurQueueSize() != 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
pika_slow_cmd_thread_pool_->stop_thread_pool();
}
}

@@ -749,11 +759,13 @@
}

void PikaServer::BGSaveTaskSchedule(net::TaskFunc func, void* arg) {
bgsave_thread_.set_thread_name("BGSaveTask");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Add error handling or logging after starting the thread in BGSaveTaskSchedule to ensure the thread starts successfully.

  • File: src/pika_server.cc
  • Lines: 762-762
Analysis chain

Verify that the thread successfully starts in BGSaveTaskSchedule before scheduling tasks.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check if the thread starts successfully in `BGSaveTaskSchedule`.

# Test: Search for error handling after thread start.
rg --type cpp --context 5 'bgsave_thread_.StartThread()'

Length of output: 1153

@@ -844,6 +853,7 @@ class PikaConf : public pstd::BaseConf {
std::string bgsave_path_;
std::string bgsave_prefix_;
std::string pidfile_;
std::atomic<bool> slow_cmd_pool_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原子变量不用加锁保护,不要使用原子变量

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原子变量不用加锁保护,不要使用原子变量

done

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 526affd and 13f1d46.

Files selected for processing (1)
  • include/pika_conf.h (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • include/pika_conf.h

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 13f1d46 and a3f779b.

Files selected for processing (1)
  • include/pika_conf.h (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • include/pika_conf.h

@@ -75,6 +75,7 @@ int HolyThread::StartThread() {
if (ret) {
return ret;
}
set_thread_name("HolyThread");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HolyThread是其他类的父类,你在这里设置。会不会其他类设置的名字被这个替代了。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HolyThread是其他类的父类,你在这里设置。会不会其他类设置的名字被这个替代了。

已修复

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a3f779b and 6a1c80d.

Files selected for processing (6)
  • conf/pika.conf (1 hunks)
  • include/pika_conf.h (3 hunks)
  • include/pika_server.h (4 hunks)
  • src/pika_admin.cc (3 hunks)
  • src/pika_conf.cc (2 hunks)
  • src/pika_server.cc (13 hunks)
Files skipped from review as they are similar to previous changes (5)
  • conf/pika.conf
  • include/pika_conf.h
  • src/pika_admin.cc
  • src/pika_conf.cc
  • src/pika_server.cc
Additional comments not posted (1)
include/pika_server.h (1)

651-651: Ensure slow_cmd_thread_pool_flag_ is properly initialized and thread-safe.

@@ -97,6 +97,7 @@ class PikaServer : public pstd::noncopyable {
bool force_full_sync();
void SetForceFullSync(bool v);
void SetDispatchQueueLimit(int queue_limit);
void SetSlowCmdThreadPoolFlag(bool flag);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Ensure thread safety when toggling slow_cmd_thread_pool_flag_. The current implementation lacks mutex locks or atomic operations, which could lead to race conditions.

  • src/pika_server.cc: PikaServer::SetSlowCmdThreadPoolFlag
Analysis chain

Ensure thread safety when toggling slow_cmd_thread_pool_flag_.


Ensure thread safety around slow_cmd_thread_pool_flag_ usage by checking for mutex locks or atomic operations.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check for potential race conditions related to `slow_cmd_thread_pool_flag_`.

# Test: Search for occurrences of `slow_cmd_thread_pool_flag_` being accessed.
rg --type cpp --context 5 'slow_cmd_thread_pool_flag_' src/

Length of output: 1088



Script:

#!/bin/bash
# Description: Check for thread safety mechanisms around `slow_cmd_thread_pool_flag_` usage.

# Test: Search for mutex locks or atomic operations related to `slow_cmd_thread_pool_flag_`.
rg --type cpp --context 5 'slow_cmd_thread_pool_flag_' src/ | grep -E 'std::mutex|std::lock_guard|std::atomic'

Length of output: 110

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6a1c80d and 49b0358.

Files selected for processing (1)
  • src/rsync_client.cc (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/rsync_client.cc

@@ -17,7 +17,7 @@ Thread::~Thread() = default;
void* Thread::RunThread(void* arg) {
auto thread = reinterpret_cast<Thread*>(arg);
if (!(thread->thread_name().empty())) {
SetThreadName(pthread_self(), thread->thread_name());
SetThreadName(pthread_self(), "pika");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里直接改成pika不合适吧?Thread应该是个基类,之前的那种方式看起来更合理点。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里直接改成pika不合适吧?Thread应该是个基类,之前的那种方式看起来更合理点。

这个代码 没有吧 应该已经没有改

res_.AppendStringRaw( "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'slow-cmd-pool'\r\n");
return;
}
g_pika_conf->SetSlowCmdPool(SlowCmdPool);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你schedule判断是否把请求塞给慢队列的时候,会读取g_pika_conf->slow_cmd_pool,setslowcmdthreadpoolflag中会等待慢队列为空然后才会stop线程池,那么这里就应该先改pika conf,保证不再有新的请求塞到队列里,然后你在等待队列都消费完之后返回。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setslowcmdthreadpoolflag

done

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 49b0358 and 8bac0c6.

Files selected for processing (2)
  • src/pika_admin.cc (3 hunks)
  • src/rsync_client.cc (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/pika_admin.cc
  • src/rsync_client.cc

@chejinge chejinge merged commit 09e9673 into OpenAtomFoundation:unstable Jun 19, 2024
13 checks passed
@chejinge chejinge deleted the feat_thread_purge branch June 24, 2024 06:05
chejinge added a commit that referenced this pull request Aug 1, 2024
* feat:thread purge

---------

Co-authored-by: chejinge <chejinge@360.cn>
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 ✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants