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: abnormal log output when exec slaveof no one #2801

Merged

Conversation

cheniujh
Copy link
Collaborator

@cheniujh cheniujh commented Jul 12, 2024

该PR修复了 Issue #2800

问题原因:执行slaveof no one时会执行RemoveMaster流程,会调一个LostConnect函数,其流程是:

1 这个函数把SyncMasterDB遍历一遍,移除MasterIp:port所对应的slaveNode(实际上slave端根本没有这样一个slaveNode,只是移除行为是一个map的erase,即使没有命中也不会报错,当然也没有实际的危害)。于是每次做完一个移除行为就会打印一条日志告知Remove了slaveNode

2 遍历一遍SyncSlaveDB,都执行Deactivate行为。

实际上在执行slaveof no one时,只做第二步就行了,所以把第二步的行为抽出了一个函数用来替代这个位置对于LostConnect的调用

This PR fixes Issue #2800.

Cause: When executing slaveof no one, the RemoveMaster process is triggered, which calls a LostConnect function. The process of this function is as follows:

  1. The function iterates through SyncMasterDB and removes the slaveNode corresponding to MasterIp:port. In fact, there is no such slaveNode on the slave side. The removal is essentially a map erase operation. Even if there is no match, it does not report an error, and it does not cause any real harm.

  2. It iterates through SyncSlaveDB and performs a Deactivate operation on each entry.

In reality, when executing slaveof no one, only the second step is necessary. Therefore, a new function was created to extract the second step's behavior to replace the call to LostConnect in this context.

Copy link

coderabbitai bot commented Jul 12, 2024

Walkthrough

A new method DeactivateSyncSlaveDB was added to the PikaReplicaManager class to disable synchronization with a slave database. This method replaces the previous LostConnection call in the PikaServer::RemoveMaster function, aiming to handle deactivations more gracefully and explicitly.

Changes

File Path Change Summary
include/pika_rm.h Added DeactivateSyncSlaveDB method to PikaReplicaManager class.
src/pika_rm.cc Implemented DeactivateSyncSlaveDB and modified LostConnection call.
src/pika_server.cc Replaced g_pika_rm->LostConnection with g_pika_rm->DeactivateSyncSlaveDB.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PikaServer
    participant PikaReplicaManager
    Client->>PikaServer: RemoveMaster(ip, port)
    PikaServer->>PikaReplicaManager: DeactivateSyncSlaveDB(ip, port)
    PikaReplicaManager->>PikaServer: Deactivation Status
    PikaServer->>Client: Acknowledgement
Loading

Poem

In the code where bits do play,
A new method finds its way,
To deactivate, not lost, it’s true,
Sync slave DB bids adieu.
The flow is clear, the logic bright,
Pika’s future, shining light.
🎉🐰✨


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 Jul 12, 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 057812f and a5fefa0.

Files selected for processing (3)
  • include/pika_rm.h (1 hunks)
  • src/pika_rm.cc (1 hunks)
  • src/pika_server.cc (1 hunks)
Additional comments not posted (3)
include/pika_rm.h (1)

169-169: New Method Added: DeactivateSyncSlaveDB.

The method DeactivateSyncSlaveDB has been added to the PikaReplicaManager class. Ensure it is used correctly in the codebase and that it handles all necessary scenarios for deactivating sync slave databases.

src/pika_rm.cc (1)

729-738: LGTM! Verify the function usage in the codebase.

The code changes are approved. The method DeactivateSyncSlaveDB correctly iterates through sync_slave_dbs and deactivates the matching slave database based on IP and port.

However, ensure that all calls to DeactivateSyncSlaveDB are correctly implemented in the codebase.

src/pika_server.cc (1)

662-662: Verify the correctness of the method replacement.

The method DeactivateSyncSlaveDB is used instead of LostConnection. Ensure that DeactivateSyncSlaveDB correctly handles all necessary deactivation processes that LostConnection was responsible for.

Verification successful

Verified the correctness of the method replacement.

The method DeactivateSyncSlaveDB correctly handles the deactivation process by acquiring a shared lock and deactivating the relevant sync slave database. This replacement is appropriate and should function as intended.

  • include/pika_rm.h: Definition of DeactivateSyncSlaveDB.
  • src/pika_rm.cc: Implementation of DeactivateSyncSlaveDB.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the method replacement.

# Test: Search for the implementation of `DeactivateSyncSlaveDB`. Expect: Correct handling of deactivation processes.
ast-grep --lang cpp --pattern $'class PikaReplicaManager {
  $$$
  Status DeactivateSyncSlaveDB(const std::string& ip, int port) {
    $$$
  }
  $$$  
}'

Length of output: 499


Script:

#!/bin/bash
# Refined search pattern for the implementation of the DeactivateSyncSlaveDB method within the PikaReplicaManager class.
ast-grep --lang cpp --pattern $'class PikaReplicaManager {
  Status DeactivateSyncSlaveDB(const std::string& ip, int port) {
    $$$
  }
}'

Length of output: 140


Script:

#!/bin/bash
# Broaden the search scope to locate the DeactivateSyncSlaveDB method in the codebase.
rg 'DeactivateSyncSlaveDB' -A 5

Length of output: 1147

@AlexStocks AlexStocks merged commit f4cfbde into OpenAtomFoundation:unstable Jul 18, 2024
14 checks passed
chejinge pushed a commit that referenced this pull request Aug 1, 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
☢️ Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants