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: Resolve the inconsistency between member configuration and log index in snapshot meta #386

Conversation

panlei-coder
Copy link
Collaborator

@panlei-coder panlei-coder commented Jul 27, 2024

优先合并:pikiwidb/braft#8 braft
1、解决在真正生成快照时,snapshot meta 保存的成员配置信息和实际的快照数据不一致问题,可能导致新加入的节点跳过成员变更日志,出现配置信息不一致的问题。#385
2、修改 set_self_replay_point 接口为 set_last_applied_index_and_term。

Summary by CodeRabbit

Summary by CodeRabbit

  • 新特性

    • PRaft类中新增了一个用于根据索引获取配置的公共方法GetConfigurationByIndex,提升了配置条目的动态访问能力。
    • 改进了快照元数据更新过程,以更准确地反映当前配置状态,包括活动和学习者节点。
    • 更新了braft库的版本标签至v1.1.2.1,以确保使用更稳定的库版本。
    • save_load.sh脚本进行了重构,使用变量替代硬编码路径,提升了可维护性和适应性。
  • 样式

    • pikiwidb.conf文件中的raft-port-offsetuse-raft设置进行了微小的空格调整,确保配置一致性。
  • 修复

    • 修改了Redis集群加入命令的格式,确保与前面的命令格式一致,增强了脚本的可读性。

@github-actions github-actions bot added the ☢️ Bug Something isn't working label Jul 27, 2024
Copy link

coderabbitai bot commented Jul 27, 2024

Warning

Rate limit exceeded

@panlei-coder has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 5 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between f409652 and 90c1358.

Walkthrough

此次更改涉及多个文件,主要集中在外部项目配置的更新、功能的新增以及现有方法的优化。braft项目的Git标签已更新为更稳定的版本,确保系统的可靠性。此外,PRaft类中新增了一个用于获取配置的方法,并改进了快照处理逻辑,以更准确地反映当前的配置状态。save_load.sh脚本也进行了重构,以提高可读性和适应性。

Changes

文件 更改摘要
cmake/braft.cmake 更新外部项目的Git仓库和标签,仓库从https://github.com/pikiwidb/braft.git更改为https://github.com/panlei-coder/braft.git,标签从v1.1.2-alpha2更改为v1.1.2.1
src/praft/praft.cc 新增GetConfigurationByIndex方法,更新快照加载逻辑,修正相关方法名称。
src/praft/praft.h PRaft类中新增GetConfigurationByIndex声明。
src/praft/psnapshot.cc 改进快照元数据更新过程,新增对学习者配置的处理,确保配置准确。
etc/script/build.sh 在case语句的关闭;;前添加空格,未改变功能。
etc/script/save_load.sh 重构代码,引入变量以简化路径处理,未改变功能。
pikiwidb.conf raft-port-offsetuse-raft设置中调整空格,未改变功能。

Poem

在草地上跳跃的小兔,
新功能在欢快中出炉;
配置变化样样俱全,
处理快照更灵活,
欢庆代码的每一步,
让我们一起享受这美好时刻! 🐇✨


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 Configuration 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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2848690 and 4b989e6.

Files selected for processing (6)
  • cmake/braft.cmake (1 hunks)
  • pikiwidb.conf (1 hunks)
  • save_load.sh (1 hunks)
  • src/praft/praft.cc (2 hunks)
  • src/praft/praft.h (2 hunks)
  • src/praft/psnapshot.cc (2 hunks)
Files skipped from review due to trivial changes (2)
  • pikiwidb.conf
  • save_load.sh
Additional comments not posted (8)
cmake/braft.cmake (2)

23-23: 更新外部项目的Git标签

已将braft项目的Git标签从v1.1.2-alpha2更改为get_configuration。请确保新标签指向正确的版本,并且该版本包含所有必要的功能和修复。


22-22: 更新外部项目的Git仓库

已将braft项目的Git仓库从https://github.com/pikiwidb/braft.git更改为https://github.com/panlei-coder/braft.git。请确保新仓库是可信的,并且包含所需的所有依赖项和功能。

Verification successful

更新外部项目的Git仓库

已验证braft项目的新Git仓库https://github.com/panlei-coder/braft.git。该仓库包含所有必要的文件和依赖项,结构完整。

  • 仓库包含构建脚本、源代码、文档、示例和测试文件。
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new Git repository URL.

# Test: Clone the repository to check if it's accessible and contains the necessary files.
git clone https://github.com/panlei-coder/braft.git

Length of output: 139


Script:

#!/bin/bash
# Description: Verify the contents of the cloned repository to ensure it includes necessary files and dependencies.

# List the contents of the cloned repository
ls -R braft

Length of output: 3984

src/praft/psnapshot.cc (2)

13-14: 包含新头文件

引入了braft/configuration.hbraft/configuration_manager.h头文件。这些文件用于处理配置相关的操作。


84-106: 更新快照元数据的逻辑

更新了快照的最后日志索引、最后日志任期以及配置和学习者信息。这些更改确保了快照元数据准确反映当前的配置状态,改进了系统的可靠性和一致性。

src/praft/praft.h (2)

17-17: 包含新头文件

引入了braft/configuration_manager.h头文件,用于管理配置。


144-145: 新增方法:GetConfigurationByIndex

PRaft类中新增了GetConfigurationByIndex方法,该方法根据日志索引获取配置和学习者配置。这增强了类的功能,使其能够更动态地访问配置条目。

src/praft/praft.cc (2)

676-678: 代码看起来不错!但请验证新方法的使用情况。

代码更改已批准。

请确保新方法 set_last_applied_index_and_term 已正确实现并使用。


262-270: 代码看起来不错!但请验证函数的使用情况。

代码更改已批准。

请确保在调用此函数之前,node_ 已正确初始化。

@Tangruilin Tangruilin marked this pull request as draft July 27, 2024 13:18
@panlei-coder panlei-coder marked this pull request as ready for review July 27, 2024 23:48
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 4b989e6 and 08f323e.

Files selected for processing (3)
  • build.sh (1 hunks)
  • pikiwidb.conf (1 hunks)
  • src/pikiwidb.cc (2 hunks)
Files skipped from review due to trivial changes (2)
  • build.sh
  • pikiwidb.conf
Additional comments not posted (2)
src/pikiwidb.cc (2)

230-230: 更改警告信息以提高清晰度

警告信息现在包含了当前限制值的占位符,这有助于用户了解PikiwiDB重新配置的具体限制。


285-285: 验证注释掉的 InitLimit() 调用的影响

InitLimit() 调用被注释掉,表明在程序启动时存在导致“直接段错误”的问题。请确保此更改不会影响程序正确处理文件描述符的能力。

Verification successful

验证注释掉的 InitLimit() 调用的影响

InitLimit() 调用被注释掉,表明在程序启动时存在导致“直接段错误”的问题。通过检查代码库,发现 src/pstd/env.cc 文件中有类似的逻辑来设置文件描述符限制。这表明可能存在替代机制或后备方法来设置这些限制,从而减轻了注释掉 InitLimit() 的影响。

  • src/pikiwidb.cc: 包含 InitLimit() 函数的定义和逻辑。
  • src/pstd/env.cc: 包含类似的文件描述符限制设置逻辑。

请确保这些替代机制能够正确处理文件描述符限制,以避免潜在问题。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of commenting out `InitLimit()` on program startup behavior.

# Test: Search for the `InitLimit` function usage. Expect: Only occurrences of the commented-out function call.
rg --type cpp -A 5 $'InitLimit'

Length of output: 609


Script:

#!/bin/bash
# Description: Search for alternative methods or configurations related to setting resource limits, particularly for file descriptors.

# Test: Search for usage of `rlimit` and `RLIMIT_NOFILE` across the codebase to identify any other mechanisms for setting file descriptor limits.
rg --type cpp -A 5 'rlimit|RLIMIT_NOFILE'

Length of output: 1545

cmake/braft.cmake 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 08f323e and bae5da6.

Files selected for processing (1)
  • cmake/braft.cmake (1 hunks)
Additional comments not posted (1)
cmake/braft.cmake (1)

23-23: 更改 Git 标签以使用更稳定的版本。

将 Git 标签从 v1.1.2-alpha2 更新为 v1.1.2.1,这表明转向了一个更稳定或最终的版本。这有助于提高项目的稳定性和功能性。

AlexStocks
AlexStocks previously approved these changes Jul 28, 2024
auto& new_meta = const_cast<braft::SnapshotMeta&>(snapshot_meta_memtable.meta());
auto last_log_index = PSTORE.GetBackend(db_id)->GetStorage()->GetSmallestFlushedLogIndex();
new_meta.set_last_included_index(last_log_index);
auto last_log_term = PRAFT.GetTerm(last_log_index);
new_meta.set_last_included_term(last_log_term);
braft::ConfigurationEntry conf_entry;
Copy link
Collaborator

Choose a reason for hiding this comment

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

在github看着好像代码没对齐

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

braft::ConfigurationEntry learner_conf_entry;
PRAFT.GetConfigurationByIndex(last_log_index, &conf_entry, &learner_conf_entry);
new_meta.clear_peers();
for (braft::Configuration::const_iterator iter = conf_entry.conf.begin(); iter != conf_entry.conf.end(); ++iter) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里使用iter类型写作auto应该就可以了。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

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

Outside diff range, codebase verification and nitpick comments (1)
src/praft/psnapshot.cc (1)

Line range hint 113-133: 优化文件添加逻辑以提高性能。

AddAllFiles 函数递归地处理每个目录和文件,这在目录结构深或文件数量多的情况下可能会影响性能。建议考虑使用非递归方法或并行处理文件添加操作,以提高效率。

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bae5da6 and 46eb978.

Files selected for processing (1)
  • src/praft/psnapshot.cc (2 hunks)

Comment on lines +84 to +104
// update snapshot last log index, last_log_term, conf of last log index and learners
auto& new_meta = const_cast<braft::SnapshotMeta&>(snapshot_meta_memtable.meta());
auto last_log_index = PSTORE.GetBackend(db_id)->GetStorage()->GetSmallestFlushedLogIndex();
new_meta.set_last_included_index(last_log_index);
auto last_log_term = PRAFT.GetTerm(last_log_index);
new_meta.set_last_included_term(last_log_term);
braft::ConfigurationEntry conf_entry;
braft::ConfigurationEntry learner_conf_entry;
PRAFT.GetConfigurationByIndex(last_log_index, &conf_entry, &learner_conf_entry);
new_meta.clear_peers();
for (auto iter = conf_entry.conf.begin(); iter != conf_entry.conf.end(); ++iter) {
*new_meta.add_peers() = iter->to_string();
}
new_meta.clear_old_peers();
for (auto iter = conf_entry.old_conf.begin(); iter != conf_entry.old_conf.end(); ++iter) {
*new_meta.add_old_peers() = iter->to_string();
}
new_meta.clear_learners();
for (auto iter = learner_conf_entry.conf.begin(); iter != learner_conf_entry.conf.end(); ++iter) {
*new_meta.add_learners() = iter->to_string();
}
Copy link

Choose a reason for hiding this comment

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

优化快照元数据更新逻辑。

代码中使用了 const_cast 来修改 snapshot_meta_memtable.meta(),这可能导致未定义的行为,建议寻找替代方法来处理不可变对象的修改。
此外,更新快照元数据的逻辑看起来正确,但建议添加更多的错误处理和日志记录,以便在更新过程中捕获和诊断可能的问题。

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 46eb978 and f7f3608.

Files selected for processing (2)
  • etc/script/build.sh (1 hunks)
  • etc/script/save_load.sh (1 hunks)
Files skipped from review due to trivial changes (2)
  • etc/script/build.sh
  • etc/script/save_load.sh

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 f7f3608 and f409652.

Files selected for processing (1)
  • save_load.sh (1 hunks)
Additional comments not posted (1)
save_load.sh (1)

7-10: 使用变量替代硬编码路径

通过引入变量来存储当前工作目录、项目主目录、二进制路径和配置文件路径,脚本变得更加适应不同环境,降低了因路径变更导致的错误风险。

save_load.sh Outdated
cd leader && ulimit -n 99999 && rm -fr * && ../bin/pikiwidb ../pikiwidb.conf --port 7777 &
cd follower1 && ulimit -n 99999 && rm -fr * && ../bin/pikiwidb ../pikiwidb.conf --port 8888 &

PWD=`pwd`
Copy link

Choose a reason for hiding this comment

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

建议使用现代的命令替代方式

建议使用 $(...) 替代过时的反引号 `,以提高可读性和支持嵌套命令。

- PWD=`pwd`
+ PWD=$(pwd)
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
PWD=`pwd`
PWD=$(pwd)

save_load.sh Outdated
Comment on lines 11 to 12
cd leader && ulimit -n 99999 && rm -fr * && ${BIN} ${CONF} --port 7777 &
cd follower1 && ulimit -n 99999 && rm -fr * && ${BIN} ${CONF} --port 8888 &
Copy link

Choose a reason for hiding this comment

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

增加错误处理

当前脚本在执行过程中缺乏错误处理,这可能导致生产环境中的静默失败。建议在每个关键命令后添加错误检查,以提高脚本的健壮性。

+ set -e
+ trap "echo 'An error occurred.'; exit 1" ERR
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
cd leader && ulimit -n 99999 && rm -fr * && ${BIN} ${CONF} --port 7777 &
cd follower1 && ulimit -n 99999 && rm -fr * && ${BIN} ${CONF} --port 8888 &
set -e
trap "echo 'An error occurred.'; exit 1" ERR
cd leader && ulimit -n 99999 && rm -fr * && ${BIN} ${CONF} --port 7777 &
cd follower1 && ulimit -n 99999 && rm -fr * && ${BIN} ${CONF} --port 8888 &

@AlexStocks AlexStocks closed this Aug 26, 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.

3 participants