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: slotmigrate return not correct #2741

Merged
merged 5 commits into from
Jun 18, 2024

Conversation

chejinge
Copy link
Collaborator

@chejinge chejinge commented Jun 17, 2024

Summary by CodeRabbit

  • Bug Fixes
    • Improved return logic in migration requests to handle specific data types more accurately.
    • Updated logging messages for better clarity during migration processes.

Copy link

coderabbitai bot commented Jun 17, 2024

Walkthrough

The recent modifications focus on altering the return logic of the PikaMigrateThread::ReqMigrateOne function and removing a case in the SlotsMgrtExecWrapperCmd::Do method. Notably, the ReqMigrateOne function now returns different values based on the data type (kNones or not) and includes a new call to NotifyRequestMigrate under specific conditions. These changes enhance the control flow and logging messages, thereby potentially improving debugging and functionality.

Changes

File Change Summary
src/pika_migrate_thread.cc Modified return logic of PikaMigrateThread::ReqMigrateOne and updated logging message. Added a call to NotifyRequestMigrate under certain conditions.
src/pika_slot_command.cc Removed the case -2: statement within the SlotsMgrtExecWrapperCmd::Do method.

Poem

In the land of code, where functions run,
Return zero for none, the change is done.
Logs now tell a different tale,
For those who read, no debugging shall fail.
Migration beckons with a notify call,
Binary paths, we conquer them all.


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.

@github-actions github-actions bot added the ☢️ Bug Something isn't working label Jun 17, 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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d562abd and 3a0a5bf.

Files selected for processing (2)
  • src/pika_migrate_thread.cc (1 hunks)
  • src/pika_slot_command.cc (1 hunks)

Comment on lines 657 to 664
return 0;
} else {
LOG(WARNING) << "PikaMigrateThread::ReqMigrateOne key: "<< key <<" type: " << static_cast<int>(type) << " is illegal";
return -1;
}
if (slot_id != slot_id_) {
LOG(WARNING) << "PikaMigrateThread::ReqMigrateOne Slot : " << slot_id << " is not the migrating slot:" << slot_id_;
return -2;
return -1;
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

The extracted code indicates that there is a logical inconsistency. Specifically, the else block following the check for type == storage::DataType::kNones contains a return statement that would prevent the subsequent if (slot_id != slot_id_) check from ever being executed. This could lead to unintended behavior.

  • Lines 657-664: The else block with return -1; prevents the if (slot_id != slot_id_) condition from being checked.

This needs to be addressed to ensure the correct sequence of operations.

Analysis chain

Updated return logic and logging for different data types in ReqMigrateOne function.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the consistency of return values and logging messages across the codebase.

# Test: Search for similar patterns in other migration-related functions.
rg --type cpp "PikaMigrateThread::ReqMigrateOne"

Length of output: 1177



Script:

#!/bin/bash
# Extract the full implementation of the ReqMigrateOne function from the source file.
ast-grep --lang cpp --pattern 'int PikaMigrateThread::ReqMigrateOne($$$) { $$$ }' src/pika_migrate_thread.cc

Length of output: 110



Script:

#!/bin/bash
# Search for the ReqMigrateOne function signature and surrounding lines to capture the full implementation.
rg --type cpp -A 50 -B 10 "int PikaMigrateThread::ReqMigrateOne" src/pika_migrate_thread.cc

Length of output: 2129

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 3a0a5bf and a59b022.

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

@chejinge chejinge force-pushed the slotmigrateone branch 2 times, most recently from d3a0430 to cc8de39 Compare June 17, 2024 10:16
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 a59b022 and d3a0430.

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

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 d3a0430 and 3041372.

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

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 3041372 and 469e78c.

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

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 469e78c and fad0e59.

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

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 fad0e59 and 6166e47.

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

}

if (slot_id != slot_id_) {
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.

这个判断还需要加吗?

不对slot_id校验直接走下面逻辑塞进队列?

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个判断还需要加吗?

不对slot_id校验直接走下面逻辑塞进队列?

嗯嗯,等于是不管这个 key 所属的 slot 是否在迁移,我都能把这个 key 迁走

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

这个判断还需要加吗?

不对slot_id校验直接走下面逻辑塞进队列?

嗯嗯,等于是不管这个 key 所属的 slot 是否在迁移,我都能把这个 key 迁走

如果你不是所属迁移的slot你也不会进入到这里来吧,因为你不可能是migrating状态

@@ -675,7 +676,7 @@ int PikaMigrateThread::ReqMigrateOne(const std::string& key, const std::shared_p
is_migrating_ = true;
usleep(100);
}
} else {
}
// check the key is migrating
std::pair<const char, std::string> kpair = std::make_pair(key_type, key);
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

@@ -934,7 +934,9 @@ void *PikaMigrateThread::ThreadMain() {
{
std::unique_lock lw(workers_mutex_);
while (!should_exit_ && is_task_success_ && send_num_ != response_num_) {
workers_cond_.wait(lw);
if (workers_cond_.wait_for(lw, std::chrono::minutes(3)) == std::cv_status::timeout) {
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.

!should_exit_ && is_task_success_ 这里我觉得不能删除 毕竟这个参数是异步赋值的如果没有赋值成功那线程就不会销毁 占用,

src/pika_migrate_thread.cc Outdated Show resolved Hide resolved
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 6166e47 and 57cea70.

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

@AlexStocks AlexStocks merged commit e7e2f41 into OpenAtomFoundation:unstable Jun 18, 2024
13 checks passed
@chejinge chejinge deleted the slotmigrateone branch June 24, 2024 06:05
chejinge added a commit that referenced this pull request Jul 29, 2024
Co-authored-by: chejinge <chejinge@360.cn>
cheniujh pushed a commit to cheniujh/pika that referenced this pull request Sep 24, 2024
* fix: slotmigrate return not correct

* fix: slotmigrate return not correct

* fix codestyle

---------

Co-authored-by: chejinge <chejinge@360.cn>
cheniujh pushed a commit to cheniujh/pika that referenced this pull request Sep 24, 2024
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 ☢️ Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants