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 issue #1521] wrong param sequence of lpushx&rpushx #1525

Merged
merged 4 commits into from
Jun 25, 2023

Conversation

ForestLH
Copy link
Contributor

@ForestLH ForestLH commented May 19, 2023

fix #1521
解决lpushx和rpushx多元素插入的问题

@AlexStocks AlexStocks changed the title Fix/1521 [Fix issue #1521] wrong param sequence of lpushx&rpushx May 19, 2023
@AlexStocks
Copy link
Collaborator

@ForestLH 处理下文件冲突

@@ -711,7 +711,7 @@ TEST_F(ListsTest, LPushxTest) {
ASSERT_TRUE(elements_match(&db, "GP1_LPUSHX_KEY", {"o", "o", "o"}));

// "x" -> "o" -> "o" -> "o"
s = db.LPushx("GP1_LPUSHX_KEY", "x", &num);
s = db.LPushx("GP1_LPUSHX_KEY", {"x"}, &num);
Copy link
Collaborator

Choose a reason for hiding this comment

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

既然支持的是多个 elements,那下面每个测试用例都再补加上这么几个 case:
1 插入的 元素格式为空;
2 插入的元素个数是3;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我加了部分,不知道够不够

Copy link
Collaborator

Choose a reason for hiding this comment

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

我加了部分,不知道够不够

尽可能的多加些能想到的 case

Copy link
Collaborator

Choose a reason for hiding this comment

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

既然支持的是多个 elements,那下面每个测试用例都再补加上这么几个 case: 1 插入的 元素格式为空; 2 插入的元素个数是 3;

不知道这俩测试 case 添加了吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

既然支持的是多个 elements,那下面每个测试用例都再补加上这么几个 case: 1 插入的 元素格式为空; 2 插入的元素个数是 3;

不知道这俩测试 case 添加了吗?

抱歉,我给忘了,我周末再加可以吗,周中有点儿忙

Copy link
Collaborator

Choose a reason for hiding this comment

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

既然支持的是多个 elements,那下面每个测试用例都再补加上这么几个 case: 1 插入的 元素格式为空; 2 插入的元素个数是 3;

不知道这俩测试 case 添加了吗?

抱歉,我给忘了,我周末再加可以吗,周中有点儿忙

当然可以呀,哈哈

std::string value_;
void DoInitial() override;
std::vector<std::string> values_;
virtual void DoInitial() override;
};
#endif
Copy link

Choose a reason for hiding this comment

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

From the code patch provided, it seems that two commands, LPushxCmd and RPushxCmd, have been modified. The changes involve replacing a single value string argument with a vector of strings to store multiple values.

Assuming that the rest of the code implementation is correct, this change should reduce the possibility of bugs caused by incorrect usage of the command with multiple values. However, the implementation details of the DoInitial function are not provided, so any suggestions for improving performance or reducing risk related to this function cannot be made.

std::make_unique<RPushxCmd>(kCmdNameRPushx, 3, kCmdFlagsWrite | kCmdFlagsSingleSlot | kCmdFlagsList);
std::unique_ptr<Cmd> rpushxptr =
std::make_unique<RPushxCmd>(kCmdNameRPushx, -3, kCmdFlagsWrite | kCmdFlagsSingleSlot | kCmdFlagsList);

cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNameRPushx, std::move(rpushxptr)));

// Zset
Copy link

Choose a reason for hiding this comment

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

The code patch involves initializing a command table. The changes made are to modify the number of arguments required for two commands (LPushx and RPushx) from 3 to -3, allowing them to accept variable arguments.

The modification appears to be valid and makes sense if the commands are designed to accept variable arguments. However, it's difficult to comment on whether there are any bug risks or improvements that can be made without knowing more context about the overall system and its functionality.

A suggestion for improvement could be to ensure that there are appropriate checks in place to handle the variable number of arguments that the modified commands can now accept, to avoid potential issues related to memory allocation and usage.

}
void RPushxCmd::Do(std::shared_ptr<Slot> slot) {
uint64_t llen = 0;
rocksdb::Status s = slot->db()->RPushx(key_, value_, &llen);
rocksdb::Status s = slot->db()->RPushx(key_, values_, &llen);
if (s.ok() || s.IsNotFound()) {
res_.AppendInteger(llen);
} else {
Copy link

Choose a reason for hiding this comment

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

The code seems to be adding support for pushing multiple values to the Redis lists using the commands LPUSHX and RPUSHX. Here are some improvements and bug risks that can be considered:

  1. It's a good practice to include comments that describe what the functions do, e.g., DoInitial() and Do().
  2. The variable pos could be improved to be more descriptive, like arg_index, so it would be easier to understand its purpose.
  3. There is no check for whether there are any elements to push into the list or not. When argv_.size() <= 2, the code still tries to access index 2 for values_ which will cause an out-of-bounds error.
  4. It's unclear how argv_[2] should be handled, since it is no longer assigned to value_. Should it be ignored, added to values_, or throw an error?
  5. It's unclear whether all of the elements in values_ should be pushed onto the list together as a batch in a single database operation, or they should each result in their own individual database operation, effectively pushing them separately. This could have implications on performance and atomicity guarantees.

Regarding potential bugs:

  1. When rocksdb::Status s = slot->db()->RPushx(key_, values_, &llen); is called, it is not clear whether this function handles empty or null lists correctly.
  2. Any non-integer arguments input could produce strange errors down the line.
  3. If the key_ parameter is not of type list, a Redis exception should be thrown.

Overall, improving documentation, handling edge cases, and clarifying behavior in corner cases would improve the overall robustness and reliability of this codebase.

@AlexStocks
Copy link
Collaborator

在等两三天吧,如果确实没啥时间添加 ut,我就 merge 了

@AlexStocks AlexStocks merged commit b70b258 into OpenAtomFoundation:unstable Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rpushx 提示参数不对
2 participants