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: add type.tcl and quit.tcl files, fix some bug #398

Merged

Conversation

luky116
Copy link
Collaborator

@luky116 luky116 commented Jul 31, 2024

改动如下:
1、匹配 sub cmd 命令之前,统一使用小写字母进行比较;
2、和 Redis 的返回值规范进行了适配,比如 unknow command 和 unknown sub command 等

Summary by CodeRabbit

  • 新特性

    • 引入新的命令响应类型,提供更清晰的错误处理。
    • 改进命令处理逻辑,增强对未知命令和子命令的反馈。
  • 错误修复

    • 更新错误处理逻辑,确保用户获得更准确的错误信息。

Copy link

coderabbitai bot commented Jul 31, 2024

Walkthrough

本次更改主要集中在命令处理逻辑的改进,尤其是错误处理机制的增强。引入新的命令响应枚举值,使系统能够更清晰地区分和报告未知命令及其子命令的错误。此外,多个文件中的命令处理逻辑已被修改,以确保返回更准确的错误代码,从而提升用户反馈的清晰度和友好性。

Changes

文件 更改摘要
src/base_cmd.cc 修改了 DoInitial 方法中的错误处理逻辑,将未知子命令的错误响应从 kSyntaxErr 改为 kErrOther,增强了错误分类。
src/client.h 添加了新的枚举值 kUnknownCmdkUnknownSubCmdCmdRes 类,以改善命令处理的错误和状态反馈。
src/cmd_keys.cc TypeCmd::DoCmd 函数中初始化 type 变量,避免未初始化变量可能导致的未定义行为。
src/cmd_table_manager.cc 修改了命令处理逻辑,返回更准确的错误代码,如将未找到命令的返回值改为 kUnknownCmd,将子命令未找到的返回值改为 kUnknownSubCmd
src/cmd_thread_pool_worker.cc 优化了 Work() 方法中的错误响应逻辑,针对 kUnknownCmdkUnknownSubCmd 引入具体检查,提供更清晰的错误报告。
tests/test_helper.tcl 解开注释以包含 unit/quitunit/type 测试用例,提升测试覆盖率。
tests/unit/command.tcl 移除版权声明,添加注释说明 Pikiwidb 不支持 docs 命令。
tests/unit/dump.tcl 添加注释,说明 Pikiwidb 不支持 restore 命令。
tests/unit/geo.tcl 添加注释,说明 Pikiwidb 不支持 geo 命令。
tests/unit/hyperloglog.tcl 添加注释,说明 Pikiwidb 不支持 pfadd 命令。
tests/unit/introspection.tcl 添加注释,说明 Pikiwidb 不支持 client 命令。
tests/unit/latency-monitor.tcl 添加注释,阐明某些参数在 Pika 中不可用。
tests/unit/maxmemory.tcl 添加注释,说明特定内存管理参数在 Pika 数据库系统中不可用。
tests/unit/type.tcl 注释掉与 ptype 命令相关的测试用例,表明该命令不受支持。

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.

@github-actions github-actions bot added Invalid PR Title ☢️ Bug Something isn't working labels Jul 31, 2024
@luky116 luky116 changed the title Fix type.tcl quit.tcl fix: add type.tcl quit.tcl, fix some bug Jul 31, 2024
@luky116 luky116 changed the title fix: add type.tcl quit.tcl, fix some bug fix: add type.tcl and quit.tcl files, fix some bug Jul 31, 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 ee3d1f5 and 48d1a5a.

Files selected for processing (14)
  • src/base_cmd.cc (1 hunks)
  • src/client.h (1 hunks)
  • src/cmd_keys.cc (1 hunks)
  • src/cmd_table_manager.cc (2 hunks)
  • src/cmd_thread_pool_worker.cc (1 hunks)
  • tests/test_helper.tcl (1 hunks)
  • tests/unit/command.tcl (1 hunks)
  • tests/unit/dump.tcl (1 hunks)
  • tests/unit/geo.tcl (1 hunks)
  • tests/unit/hyperloglog.tcl (1 hunks)
  • tests/unit/introspection.tcl (1 hunks)
  • tests/unit/latency-monitor.tcl (4 hunks)
  • tests/unit/maxmemory.tcl (4 hunks)
  • tests/unit/type.tcl (1 hunks)
Files skipped from review due to trivial changes (8)
  • tests/unit/command.tcl
  • tests/unit/dump.tcl
  • tests/unit/geo.tcl
  • tests/unit/hyperloglog.tcl
  • tests/unit/introspection.tcl
  • tests/unit/latency-monitor.tcl
  • tests/unit/maxmemory.tcl
  • tests/unit/type.tcl
Additional comments not posted (9)
src/cmd_thread_pool_worker.cc (1)

24-29: 改进命令错误处理逻辑

新的错误处理逻辑通过区分未知命令和未知子命令,提升了错误报告的清晰度。确保在其他地方也有相应的处理。

Verification successful

改进命令错误处理逻辑

新的错误处理逻辑通过区分未知命令和未知子命令,提升了错误报告的清晰度。确保在其他地方也有相应的处理。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistency of error handling logic for unknown commands and subcommands.

# Test: Search for usage of CmdRes::kUnknownCmd and CmdRes::kUnknownSubCmd. Expect: Consistent handling across the codebase.
rg --type cpp 'CmdRes::kUnknownCmd|CmdRes::kUnknownSubCmd'

Length of output: 423


Script:

#!/bin/bash
# Extract and review relevant code segments in src/cmd_table_manager.cc for consistency in handling CmdRes::kUnknownCmd and CmdRes::kUnknownSubCmd.

# Extract lines around the usage of CmdRes::kUnknownCmd and CmdRes::kUnknownSubCmd
rg --type cpp -A 5 -B 5 'CmdRes::kUnknownCmd|CmdRes::kUnknownSubCmd' src/cmd_table_manager.cc

Length of output: 620


Script:

#!/bin/bash
# Search for the usage of CmdTableManager methods that return CmdRes::kUnknownCmd and CmdRes::kUnknownSubCmd.

# Find where CmdTableManager methods are called
rg --type cpp 'CmdTableManager' -A 5 -B 5

Length of output: 5590


Script:

#!/bin/bash
# Extract and review relevant code segments in src/cmd_thread_pool_worker.cc and src/client.cc for consistency in handling CmdRes::kUnknownCmd and CmdRes::kUnknownSubCmd.

# Extract lines around the usage of CmdTableManager in src/cmd_thread_pool_worker.cc
rg --type cpp -A 10 -B 10 'cmd_table_manager_' src/cmd_thread_pool_worker.cc

# Extract lines around the commented code in src/client.cc
rg --type cpp -A 10 -B 10 'GetCmdTableManager' src/client.cc

Length of output: 1522

src/base_cmd.cc (1)

109-110: 改进子命令错误处理逻辑

将未知子命令的错误响应从 CmdRes::kSyntaxErr 更改为 CmdRes::kErrOther,使错误分类更加准确。确保在其他地方也有相应的处理。

Verification successful

改进子命令错误处理逻辑

将未知子命令的错误响应从 CmdRes::kSyntaxErr 更改为 CmdRes::kErrOther,使错误分类更加准确。该更改在代码库中的其他地方也有相应的一致处理。

  • src/cmd_thread_pool_worker.cc 中处理未知命令和子命令时使用了 CmdRes::kErrOther
  • src/base_cmd.cc 中也有类似的处理逻辑。
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistency of error handling logic for unknown subcommands.

# Test: Search for usage of CmdRes::kErrOther. Expect: Consistent handling across the codebase.
rg --type cpp 'CmdRes::kErrOther'

Length of output: 10741

src/cmd_table_manager.cc (3)

194-194: 改进未知命令错误处理逻辑

将未知命令的错误代码从 CmdRes::kSyntaxErr 更改为 CmdRes::kUnknownCmd,使错误分类更加准确。


201-201: 改进未知子命令错误处理逻辑

将未知子命令的错误代码从 CmdRes::kSyntaxErr 更改为 CmdRes::kUnknownSubCmd,使错误分类更加准确。


203-203: 改进命令获取成功处理逻辑

将成功获取命令的返回值从 CmdRes::kSyntaxErr 更改为 CmdRes::kOK,提升了控制流的清晰度。

src/client.h (1)

49-50: 新增的枚举值看起来不错!

新增的 kUnknownCmdkUnknownSubCmd 枚举值与现有的枚举值保持一致,命名清晰且符合风格。

src/cmd_keys.cc (1)

66-66: 初始化变量是个好习惯!

type 变量初始化为 storage::DataType::kNones 可以防止未初始化变量的潜在问题。

tests/test_helper.tcl (2)

19-19: 启用 unit/quit 测试用例。

取消注释 unit/quit 测试用例将确保与退出相关的功能在测试期间得到验证。


26-26: 启用 unit/type 测试用例。

取消注释 unit/type 测试用例将确保与类型处理相关的功能在测试期间得到验证。

@github-actions github-actions bot added the ✏️ Feature New feature or request label Jul 31, 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 48d1a5a and ab864d3.

Files selected for processing (1)
  • src/base_cmd.cc (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/base_cmd.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 ab864d3 and 7743948.

Files selected for processing (1)
  • src/cmd_thread_pool_worker.cc (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/cmd_thread_pool_worker.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 7743948 and 25c10ac.

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

r sadd key1 key1
assert_equal {string hash list zset set} [r ptype key1]
}
#Pikiwidb does not support the ptype command
Copy link
Collaborator

Choose a reason for hiding this comment

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

ptype这个可以直接删掉了,这个是之前多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.

done

if (ret == CmdRes::kUnknownCmd) {
task->Client()->SetRes(CmdRes::kErrOther, "unknown command '" + task->CmdName() + "'");
} else if (ret == CmdRes::kUnknownSubCmd) {
task->Client()->SetRes(CmdRes::kErrOther, "unknown sub command '" + task->Client().get()->argv_[1] + "'");
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里是不是应该需要检查一下task->Client().get()中argv[]的大小,避免访问非法内存地址

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image
如果满足 ret == CmdRes::kUnknownSubCmd ,说明一定有多个参数

}
return std::pair(cmd->second.get(), CmdRes::kSyntaxErr);
return std::pair(cmd->second.get(), CmdRes::kOK);
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里为什么返回改为OK了,是不是原来的逻辑是错的

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

这个方法的逻辑,前面把所有的异常逻辑都 retuen,如果走到最后,应该是正常的 case

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 25c10ac and 142b0c0.

Files selected for processing (1)
  • tests/unit/type.tcl (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/unit/type.tcl

@AlexStocks AlexStocks merged commit 694e225 into OpenAtomFoundation:unstable Aug 8, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☢️ Bug Something isn't working ✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants