You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "zncleon (via GitHub)" <gi...@apache.org> on 2023/09/19 09:39:00 UTC
[GitHub] [kvrocks] zncleon opened a new pull request, #1768: Add the support of the BF.INSERT command
zncleon opened a new pull request, #1768:
URL: https://github.com/apache/kvrocks/pull/1768
This PR:
1. Introduce the bloom BF.INSERT command
2. Change the parameter parser error return to unified and explicit msg (e.g. `"Bad capacity"`)
[1] [https://redis.io/commands/bf.insert/](https://redis.io/commands/bf.insert/)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] PragmaTwice commented on pull request #1768: Add the support of the BF.INSERT command
Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#issuecomment-1730976036
Thank you for your contribution!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1333891796
##########
src/types/redis_bloom_chain.h:
##########
@@ -57,18 +64,21 @@ class BloomChain : public Database {
public:
BloomChain(engine::Storage *storage, const std::string &ns) : Database(storage, ns) {}
rocksdb::Status Reserve(const Slice &user_key, uint32_t capacity, double error_rate, uint16_t expansion);
- rocksdb::Status Add(const Slice &user_key, const Slice &item, BloomFilterAddResult *ret);
- rocksdb::Status MAdd(const Slice &user_key, const std::vector<Slice> &items, std::vector<BloomFilterAddResult> *rets);
- rocksdb::Status Exists(const Slice &user_key, const Slice &item, bool *exist);
- rocksdb::Status MExists(const Slice &user_key, const std::vector<Slice> &items, std::vector<bool> *exists);
+ rocksdb::Status Add(const Slice &user_key, const std::string &item, BloomFilterAddResult *ret);
+ rocksdb::Status MAdd(const Slice &user_key, const std::vector<std::string> &items,
+ std::vector<BloomFilterAddResult> *rets);
+ rocksdb::Status InsertCommon(const Slice &user_key, const std::vector<std::string> &items,
Review Comment:
I wonder why it is called `InsertCommon` instead of `Insert`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] zncleon commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "zncleon (via GitHub)" <gi...@apache.org>.
zncleon commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1332899721
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -147,6 +151,103 @@ class CommandBFMAdd : public Commander {
std::vector<Slice> items_;
};
+class CommandBFInsert : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ bool is_nonscaling = false;
+ bool has_expansion = false;
+ while (parser.Good()) {
+ if (parser.EatEqICase("capacity")) {
+ auto parse_capacity = parser.TakeInt<uint32_t>();
+ if (!parse_capacity.IsOK()) {
+ return {Status::RedisParseErr, "Bad capacity"};
+ }
+ insert_options_.capacity = parse_capacity.GetValue();
+ if (insert_options_.capacity <= 0) {
+ return {Status::RedisParseErr, "capacity should be larger than 0"};
+ }
+ } else if (parser.EatEqICase("error")) {
+ auto parse_error_rate = parser.TakeFloat<double>();
+ if (!parse_error_rate.IsOK()) {
+ return {Status::RedisParseErr, "Bad error rate"};
+ }
+ insert_options_.error_rate = parse_error_rate.GetValue();
+ if (insert_options_.error_rate >= 1 || insert_options_.error_rate <= 0) {
+ return {Status::RedisParseErr, "error rate should be between 0 and 1"};
+ }
+ } else if (parser.EatEqICase("nocreate")) {
+ insert_options_.auto_create = false;
+ } else if (parser.EatEqICase("nonscaling")) {
+ is_nonscaling = true;
+ insert_options_.expansion = 0;
+ } else if (parser.EatEqICase("expansion")) {
+ has_expansion = true;
+ auto parse_expansion = parser.TakeInt<uint16_t>();
+ if (!parse_expansion.IsOK()) {
+ return {Status::RedisParseErr, "Bad expansion"};
+ }
+ insert_options_.expansion = parse_expansion.GetValue();
+ if (insert_options_.expansion < 1) {
+ return {Status::RedisParseErr, "expansion should be greater or equal to 1"};
+ }
+ } else if (parser.EatEqICase("items")) {
+ break;
+ } else {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ }
+
+ if (is_nonscaling && has_expansion) {
+ return {Status::RedisParseErr, "nonscaling filters cannot expand"};
+ }
+
+ auto items_begin =
+ find_if(args.begin(), args.end(), [](std::string_view lhs) { return lhs == "items" || lhs == "ITEMS"; });
+
+ if (items_begin == args.end()) {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ items_.reserve(args_.end() - items_begin);
+ for (auto item_iter = items_begin + 1; item_iter < args.end(); ++item_iter) {
+ items_.emplace_back(*item_iter);
+ }
Review Comment:
Sure, I think vector<string> would be more intutive
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1332398425
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -147,6 +151,103 @@ class CommandBFMAdd : public Commander {
std::vector<Slice> items_;
};
+class CommandBFInsert : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ bool is_nonscaling = false;
+ bool has_expansion = false;
+ while (parser.Good()) {
+ if (parser.EatEqICase("capacity")) {
+ auto parse_capacity = parser.TakeInt<uint32_t>();
+ if (!parse_capacity.IsOK()) {
+ return {Status::RedisParseErr, "Bad capacity"};
+ }
+ insert_options_.capacity = parse_capacity.GetValue();
+ if (insert_options_.capacity <= 0) {
+ return {Status::RedisParseErr, "capacity should be larger than 0"};
+ }
+ } else if (parser.EatEqICase("error")) {
+ auto parse_error_rate = parser.TakeFloat<double>();
+ if (!parse_error_rate.IsOK()) {
+ return {Status::RedisParseErr, "Bad error rate"};
+ }
+ insert_options_.error_rate = parse_error_rate.GetValue();
+ if (insert_options_.error_rate >= 1 || insert_options_.error_rate <= 0) {
+ return {Status::RedisParseErr, "error rate should be between 0 and 1"};
+ }
+ } else if (parser.EatEqICase("nocreate")) {
+ insert_options_.auto_create = false;
+ } else if (parser.EatEqICase("nonscaling")) {
+ is_nonscaling = true;
+ insert_options_.expansion = 0;
+ } else if (parser.EatEqICase("expansion")) {
+ has_expansion = true;
+ auto parse_expansion = parser.TakeInt<uint16_t>();
+ if (!parse_expansion.IsOK()) {
+ return {Status::RedisParseErr, "Bad expansion"};
+ }
+ insert_options_.expansion = parse_expansion.GetValue();
+ if (insert_options_.expansion < 1) {
+ return {Status::RedisParseErr, "expansion should be greater or equal to 1"};
+ }
+ } else if (parser.EatEqICase("items")) {
+ break;
+ } else {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ }
+
+ if (is_nonscaling && has_expansion) {
+ return {Status::RedisParseErr, "nonscaling filters cannot expand"};
+ }
+
+ auto items_begin =
+ find_if(args.begin(), args.end(), [](std::string_view lhs) { return lhs == "items" || lhs == "ITEMS"; });
+
+ if (items_begin == args.end()) {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ items_.reserve(args_.end() - items_begin);
+ for (auto item_iter = items_begin + 1; item_iter < args.end(); ++item_iter) {
+ items_.emplace_back(*item_iter);
+ }
Review Comment:
```suggestion
} else if (parser.EatEqICase("items")) {
has_items = true;
break;
} else {
return {Status::RedisParseErr, errInvalidSyntax};
}
}
if (is_nonscaling && has_expansion) {
return {Status::RedisParseErr, "nonscaling filters cannot expand"};
}
if (not has_items) {
return {Status::RedisParseErr, errInvalidSyntax};
}
while (parser.Good()) {
items_.emplace_back(GET_OR_RET(parser.TakeStr()));
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1333904011
##########
src/types/redis_bloom_chain.h:
##########
@@ -57,18 +64,21 @@ class BloomChain : public Database {
public:
BloomChain(engine::Storage *storage, const std::string &ns) : Database(storage, ns) {}
rocksdb::Status Reserve(const Slice &user_key, uint32_t capacity, double error_rate, uint16_t expansion);
- rocksdb::Status Add(const Slice &user_key, const Slice &item, BloomFilterAddResult *ret);
- rocksdb::Status MAdd(const Slice &user_key, const std::vector<Slice> &items, std::vector<BloomFilterAddResult> *rets);
- rocksdb::Status Exists(const Slice &user_key, const Slice &item, bool *exist);
- rocksdb::Status MExists(const Slice &user_key, const std::vector<Slice> &items, std::vector<bool> *exists);
+ rocksdb::Status Add(const Slice &user_key, const std::string &item, BloomFilterAddResult *ret);
+ rocksdb::Status MAdd(const Slice &user_key, const std::vector<std::string> &items,
+ std::vector<BloomFilterAddResult> *rets);
+ rocksdb::Status InsertCommon(const Slice &user_key, const std::vector<std::string> &items,
Review Comment:
Got it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] zncleon commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "zncleon (via GitHub)" <gi...@apache.org>.
zncleon commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1333894295
##########
src/types/redis_bloom_chain.h:
##########
@@ -57,18 +64,21 @@ class BloomChain : public Database {
public:
BloomChain(engine::Storage *storage, const std::string &ns) : Database(storage, ns) {}
rocksdb::Status Reserve(const Slice &user_key, uint32_t capacity, double error_rate, uint16_t expansion);
- rocksdb::Status Add(const Slice &user_key, const Slice &item, BloomFilterAddResult *ret);
- rocksdb::Status MAdd(const Slice &user_key, const std::vector<Slice> &items, std::vector<BloomFilterAddResult> *rets);
- rocksdb::Status Exists(const Slice &user_key, const Slice &item, bool *exist);
- rocksdb::Status MExists(const Slice &user_key, const std::vector<Slice> &items, std::vector<bool> *exists);
+ rocksdb::Status Add(const Slice &user_key, const std::string &item, BloomFilterAddResult *ret);
+ rocksdb::Status MAdd(const Slice &user_key, const std::vector<std::string> &items,
+ std::vector<BloomFilterAddResult> *rets);
+ rocksdb::Status InsertCommon(const Slice &user_key, const std::vector<std::string> &items,
Review Comment:
It's named as RedisBloom do. I think it indicate not only `Insert` but `Madd` share this function.
##########
src/types/redis_bloom_chain.h:
##########
@@ -57,18 +64,21 @@ class BloomChain : public Database {
public:
BloomChain(engine::Storage *storage, const std::string &ns) : Database(storage, ns) {}
rocksdb::Status Reserve(const Slice &user_key, uint32_t capacity, double error_rate, uint16_t expansion);
- rocksdb::Status Add(const Slice &user_key, const Slice &item, BloomFilterAddResult *ret);
- rocksdb::Status MAdd(const Slice &user_key, const std::vector<Slice> &items, std::vector<BloomFilterAddResult> *rets);
- rocksdb::Status Exists(const Slice &user_key, const Slice &item, bool *exist);
- rocksdb::Status MExists(const Slice &user_key, const std::vector<Slice> &items, std::vector<bool> *exists);
+ rocksdb::Status Add(const Slice &user_key, const std::string &item, BloomFilterAddResult *ret);
+ rocksdb::Status MAdd(const Slice &user_key, const std::vector<std::string> &items,
+ std::vector<BloomFilterAddResult> *rets);
+ rocksdb::Status InsertCommon(const Slice &user_key, const std::vector<std::string> &items,
Review Comment:
It's named as RedisBloom do. I think it indicates not only `Insert` but `Madd` share this function.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] mapleFU commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1333894512
##########
src/types/redis_bloom_chain.h:
##########
@@ -57,18 +64,21 @@ class BloomChain : public Database {
public:
BloomChain(engine::Storage *storage, const std::string &ns) : Database(storage, ns) {}
rocksdb::Status Reserve(const Slice &user_key, uint32_t capacity, double error_rate, uint16_t expansion);
- rocksdb::Status Add(const Slice &user_key, const Slice &item, BloomFilterAddResult *ret);
- rocksdb::Status MAdd(const Slice &user_key, const std::vector<Slice> &items, std::vector<BloomFilterAddResult> *rets);
- rocksdb::Status Exists(const Slice &user_key, const Slice &item, bool *exist);
- rocksdb::Status MExists(const Slice &user_key, const std::vector<Slice> &items, std::vector<bool> *exists);
+ rocksdb::Status Add(const Slice &user_key, const std::string &item, BloomFilterAddResult *ret);
+ rocksdb::Status MAdd(const Slice &user_key, const std::vector<std::string> &items,
+ std::vector<BloomFilterAddResult> *rets);
+ rocksdb::Status InsertCommon(const Slice &user_key, const std::vector<std::string> &items,
Review Comment:
I guess this is extended from RedisBloom, lol
We can separate underlying impl and interface @zncleon
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1332789272
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -147,6 +151,103 @@ class CommandBFMAdd : public Commander {
std::vector<Slice> items_;
};
+class CommandBFInsert : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ bool is_nonscaling = false;
+ bool has_expansion = false;
+ while (parser.Good()) {
+ if (parser.EatEqICase("capacity")) {
+ auto parse_capacity = parser.TakeInt<uint32_t>();
+ if (!parse_capacity.IsOK()) {
+ return {Status::RedisParseErr, "Bad capacity"};
+ }
+ insert_options_.capacity = parse_capacity.GetValue();
+ if (insert_options_.capacity <= 0) {
+ return {Status::RedisParseErr, "capacity should be larger than 0"};
+ }
+ } else if (parser.EatEqICase("error")) {
+ auto parse_error_rate = parser.TakeFloat<double>();
+ if (!parse_error_rate.IsOK()) {
+ return {Status::RedisParseErr, "Bad error rate"};
+ }
+ insert_options_.error_rate = parse_error_rate.GetValue();
+ if (insert_options_.error_rate >= 1 || insert_options_.error_rate <= 0) {
+ return {Status::RedisParseErr, "error rate should be between 0 and 1"};
+ }
+ } else if (parser.EatEqICase("nocreate")) {
+ insert_options_.auto_create = false;
+ } else if (parser.EatEqICase("nonscaling")) {
+ is_nonscaling = true;
+ insert_options_.expansion = 0;
+ } else if (parser.EatEqICase("expansion")) {
+ has_expansion = true;
+ auto parse_expansion = parser.TakeInt<uint16_t>();
+ if (!parse_expansion.IsOK()) {
+ return {Status::RedisParseErr, "Bad expansion"};
+ }
+ insert_options_.expansion = parse_expansion.GetValue();
+ if (insert_options_.expansion < 1) {
+ return {Status::RedisParseErr, "expansion should be greater or equal to 1"};
+ }
+ } else if (parser.EatEqICase("items")) {
+ break;
+ } else {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ }
+
+ if (is_nonscaling && has_expansion) {
+ return {Status::RedisParseErr, "nonscaling filters cannot expand"};
+ }
+
+ auto items_begin =
+ find_if(args.begin(), args.end(), [](std::string_view lhs) { return lhs == "items" || lhs == "ITEMS"; });
+
+ if (items_begin == args.end()) {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ items_.reserve(args_.end() - items_begin);
+ for (auto item_iter = items_begin + 1; item_iter < args.end(); ++item_iter) {
+ items_.emplace_back(*item_iter);
+ }
Review Comment:
If you want a most intuitive way, you can let args_ typed `vector<string>`.
Another way is to use RawTake().
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] PragmaTwice merged pull request #1768: Add the support of the BF.INSERT command
Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice merged PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] zncleon commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "zncleon (via GitHub)" <gi...@apache.org>.
zncleon commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1333897297
##########
src/types/redis_bloom_chain.h:
##########
@@ -57,18 +64,21 @@ class BloomChain : public Database {
public:
BloomChain(engine::Storage *storage, const std::string &ns) : Database(storage, ns) {}
rocksdb::Status Reserve(const Slice &user_key, uint32_t capacity, double error_rate, uint16_t expansion);
- rocksdb::Status Add(const Slice &user_key, const Slice &item, BloomFilterAddResult *ret);
- rocksdb::Status MAdd(const Slice &user_key, const std::vector<Slice> &items, std::vector<BloomFilterAddResult> *rets);
- rocksdb::Status Exists(const Slice &user_key, const Slice &item, bool *exist);
- rocksdb::Status MExists(const Slice &user_key, const std::vector<Slice> &items, std::vector<bool> *exists);
+ rocksdb::Status Add(const Slice &user_key, const std::string &item, BloomFilterAddResult *ret);
+ rocksdb::Status MAdd(const Slice &user_key, const std::vector<std::string> &items,
+ std::vector<BloomFilterAddResult> *rets);
+ rocksdb::Status InsertCommon(const Slice &user_key, const std::vector<std::string> &items,
Review Comment:
But the main logic of these two function is same(only some judge differ, in other words, `Madd` is a special case of `Insert`). If we separate them, we would have many redundant codes. @mapleFU
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] mapleFU commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1332387021
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -147,6 +151,103 @@ class CommandBFMAdd : public Commander {
std::vector<Slice> items_;
};
+class CommandBFInsert : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ bool is_nonscaling = false;
+ bool has_expansion = false;
+ while (parser.Good()) {
+ if (parser.EatEqICase("capacity")) {
+ auto parse_capacity = parser.TakeInt<uint32_t>();
+ if (!parse_capacity.IsOK()) {
+ return {Status::RedisParseErr, "Bad capacity"};
Review Comment:
ditto, this can be add in a anonymous namespace as constants
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -147,6 +151,103 @@ class CommandBFMAdd : public Commander {
std::vector<Slice> items_;
};
+class CommandBFInsert : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ bool is_nonscaling = false;
+ bool has_expansion = false;
+ while (parser.Good()) {
+ if (parser.EatEqICase("capacity")) {
+ auto parse_capacity = parser.TakeInt<uint32_t>();
+ if (!parse_capacity.IsOK()) {
+ return {Status::RedisParseErr, "Bad capacity"};
+ }
+ insert_options_.capacity = parse_capacity.GetValue();
+ if (insert_options_.capacity <= 0) {
+ return {Status::RedisParseErr, "capacity should be larger than 0"};
+ }
+ } else if (parser.EatEqICase("error")) {
+ auto parse_error_rate = parser.TakeFloat<double>();
+ if (!parse_error_rate.IsOK()) {
+ return {Status::RedisParseErr, "Bad error rate"};
+ }
+ insert_options_.error_rate = parse_error_rate.GetValue();
+ if (insert_options_.error_rate >= 1 || insert_options_.error_rate <= 0) {
+ return {Status::RedisParseErr, "error rate should be between 0 and 1"};
+ }
+ } else if (parser.EatEqICase("nocreate")) {
+ insert_options_.auto_create = false;
+ } else if (parser.EatEqICase("nonscaling")) {
+ is_nonscaling = true;
+ insert_options_.expansion = 0;
+ } else if (parser.EatEqICase("expansion")) {
+ has_expansion = true;
+ auto parse_expansion = parser.TakeInt<uint16_t>();
+ if (!parse_expansion.IsOK()) {
+ return {Status::RedisParseErr, "Bad expansion"};
+ }
+ insert_options_.expansion = parse_expansion.GetValue();
+ if (insert_options_.expansion < 1) {
+ return {Status::RedisParseErr, "expansion should be greater or equal to 1"};
+ }
+ } else if (parser.EatEqICase("items")) {
+ break;
+ } else {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ }
+
+ if (is_nonscaling && has_expansion) {
+ return {Status::RedisParseErr, "nonscaling filters cannot expand"};
+ }
+
+ auto items_begin =
+ find_if(args.begin(), args.end(), [](std::string_view lhs) { return lhs == "items" || lhs == "ITEMS"; });
Review Comment:
Can we use `toLower` and check `lower(lhs) == "items"` here?
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -147,6 +151,103 @@ class CommandBFMAdd : public Commander {
std::vector<Slice> items_;
};
+class CommandBFInsert : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ bool is_nonscaling = false;
+ bool has_expansion = false;
+ while (parser.Good()) {
+ if (parser.EatEqICase("capacity")) {
+ auto parse_capacity = parser.TakeInt<uint32_t>();
+ if (!parse_capacity.IsOK()) {
+ return {Status::RedisParseErr, "Bad capacity"};
+ }
+ insert_options_.capacity = parse_capacity.GetValue();
+ if (insert_options_.capacity <= 0) {
+ return {Status::RedisParseErr, "capacity should be larger than 0"};
+ }
+ } else if (parser.EatEqICase("error")) {
+ auto parse_error_rate = parser.TakeFloat<double>();
+ if (!parse_error_rate.IsOK()) {
+ return {Status::RedisParseErr, "Bad error rate"};
+ }
+ insert_options_.error_rate = parse_error_rate.GetValue();
+ if (insert_options_.error_rate >= 1 || insert_options_.error_rate <= 0) {
+ return {Status::RedisParseErr, "error rate should be between 0 and 1"};
+ }
+ } else if (parser.EatEqICase("nocreate")) {
+ insert_options_.auto_create = false;
+ } else if (parser.EatEqICase("nonscaling")) {
+ is_nonscaling = true;
+ insert_options_.expansion = 0;
+ } else if (parser.EatEqICase("expansion")) {
+ has_expansion = true;
+ auto parse_expansion = parser.TakeInt<uint16_t>();
+ if (!parse_expansion.IsOK()) {
+ return {Status::RedisParseErr, "Bad expansion"};
+ }
+ insert_options_.expansion = parse_expansion.GetValue();
+ if (insert_options_.expansion < 1) {
+ return {Status::RedisParseErr, "expansion should be greater or equal to 1"};
+ }
+ } else if (parser.EatEqICase("items")) {
+ break;
+ } else {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ }
+
+ if (is_nonscaling && has_expansion) {
+ return {Status::RedisParseErr, "nonscaling filters cannot expand"};
+ }
+
+ auto items_begin =
+ find_if(args.begin(), args.end(), [](std::string_view lhs) { return lhs == "items" || lhs == "ITEMS"; });
+
+ if (items_begin == args.end()) {
Review Comment:
Hmmm
```suggestion
if (items_begin == args.end() || items_begin + 1 == args.end()) {
```
?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] mapleFU commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1333207697
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -136,15 +152,113 @@ class CommandBFMAdd : public Commander {
*output += redis::Integer(0);
break;
case BloomFilterAddResult::kFull:
- *output += redis::Error("ERR nonscaling filter is full");
+ *output += redis::Error(errFilterFull);
+ break;
+ }
+ }
+ return Status::OK();
+ }
+
+ private:
+ std::vector<std::string> items_;
+};
+
+class CommandBFInsert : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ bool is_nonscaling = false;
+ bool has_expansion = false;
+ bool has_items = false;
+ while (parser.Good()) {
+ if (parser.EatEqICase("capacity")) {
+ auto parse_capacity = parser.TakeInt<uint32_t>();
+ if (!parse_capacity.IsOK()) {
+ return {Status::RedisParseErr, errBadCapacity};
+ }
+ insert_options_.capacity = parse_capacity.GetValue();
+ if (insert_options_.capacity <= 0) {
+ return {Status::RedisParseErr, errInvalidCapacity};
+ }
+ } else if (parser.EatEqICase("error")) {
+ auto parse_error_rate = parser.TakeFloat<double>();
+ if (!parse_error_rate.IsOK()) {
+ return {Status::RedisParseErr, errBadErrorRate};
+ }
+ insert_options_.error_rate = parse_error_rate.GetValue();
+ if (insert_options_.error_rate >= 1 || insert_options_.error_rate <= 0) {
+ return {Status::RedisParseErr, errInvalidErrorRate};
+ }
+ } else if (parser.EatEqICase("nocreate")) {
+ insert_options_.auto_create = false;
+ } else if (parser.EatEqICase("nonscaling")) {
+ is_nonscaling = true;
+ insert_options_.expansion = 0;
+ } else if (parser.EatEqICase("expansion")) {
+ has_expansion = true;
+ auto parse_expansion = parser.TakeInt<uint16_t>();
+ if (!parse_expansion.IsOK()) {
+ return {Status::RedisParseErr, errBadExpansion};
+ }
+ insert_options_.expansion = parse_expansion.GetValue();
+ if (insert_options_.expansion < 1) {
+ return {Status::RedisParseErr, errInvalidExpansion};
+ }
+ } else if (parser.EatEqICase("items")) {
+ has_items = true;
+ break;
+ } else {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ }
+
+ if (is_nonscaling && has_expansion) {
+ return {Status::RedisParseErr, errNonscalingButExpand};
+ }
+
+ if (not has_items) {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+
+ items_.reserve(args_.size() - 3);
Review Comment:
Emmm just `emplace_back` is ok here...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] zncleon commented on pull request #1768: Add the support of the BF.INSERT command
Posted by "zncleon (via GitHub)" <gi...@apache.org>.
zncleon commented on PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#issuecomment-1725175080
The reasons Why I change the msg are:
1. If I direct parse (e.g. capacity) in `BF.Reserve` and use parser's `take` and `GET_OR_RET` in `BF.INSERT`, the error msg would be differentiated.
2. Now the parse error msg is the same as the RedisBloom.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1333891796
##########
src/types/redis_bloom_chain.h:
##########
@@ -57,18 +64,21 @@ class BloomChain : public Database {
public:
BloomChain(engine::Storage *storage, const std::string &ns) : Database(storage, ns) {}
rocksdb::Status Reserve(const Slice &user_key, uint32_t capacity, double error_rate, uint16_t expansion);
- rocksdb::Status Add(const Slice &user_key, const Slice &item, BloomFilterAddResult *ret);
- rocksdb::Status MAdd(const Slice &user_key, const std::vector<Slice> &items, std::vector<BloomFilterAddResult> *rets);
- rocksdb::Status Exists(const Slice &user_key, const Slice &item, bool *exist);
- rocksdb::Status MExists(const Slice &user_key, const std::vector<Slice> &items, std::vector<bool> *exists);
+ rocksdb::Status Add(const Slice &user_key, const std::string &item, BloomFilterAddResult *ret);
+ rocksdb::Status MAdd(const Slice &user_key, const std::vector<std::string> &items,
+ std::vector<BloomFilterAddResult> *rets);
+ rocksdb::Status InsertCommon(const Slice &user_key, const std::vector<std::string> &items,
Review Comment:
Why is it called `InsertCommon` instead of `Insert`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1332395938
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -147,6 +151,103 @@ class CommandBFMAdd : public Commander {
std::vector<Slice> items_;
};
+class CommandBFInsert : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ bool is_nonscaling = false;
+ bool has_expansion = false;
+ while (parser.Good()) {
+ if (parser.EatEqICase("capacity")) {
+ auto parse_capacity = parser.TakeInt<uint32_t>();
+ if (!parse_capacity.IsOK()) {
+ return {Status::RedisParseErr, "Bad capacity"};
+ }
+ insert_options_.capacity = parse_capacity.GetValue();
+ if (insert_options_.capacity <= 0) {
+ return {Status::RedisParseErr, "capacity should be larger than 0"};
+ }
+ } else if (parser.EatEqICase("error")) {
+ auto parse_error_rate = parser.TakeFloat<double>();
+ if (!parse_error_rate.IsOK()) {
+ return {Status::RedisParseErr, "Bad error rate"};
+ }
+ insert_options_.error_rate = parse_error_rate.GetValue();
+ if (insert_options_.error_rate >= 1 || insert_options_.error_rate <= 0) {
+ return {Status::RedisParseErr, "error rate should be between 0 and 1"};
+ }
+ } else if (parser.EatEqICase("nocreate")) {
+ insert_options_.auto_create = false;
+ } else if (parser.EatEqICase("nonscaling")) {
+ is_nonscaling = true;
+ insert_options_.expansion = 0;
+ } else if (parser.EatEqICase("expansion")) {
+ has_expansion = true;
+ auto parse_expansion = parser.TakeInt<uint16_t>();
+ if (!parse_expansion.IsOK()) {
+ return {Status::RedisParseErr, "Bad expansion"};
+ }
+ insert_options_.expansion = parse_expansion.GetValue();
+ if (insert_options_.expansion < 1) {
+ return {Status::RedisParseErr, "expansion should be greater or equal to 1"};
+ }
+ } else if (parser.EatEqICase("items")) {
+ break;
+ } else {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ }
+
+ if (is_nonscaling && has_expansion) {
+ return {Status::RedisParseErr, "nonscaling filters cannot expand"};
+ }
+
+ auto items_begin =
+ find_if(args.begin(), args.end(), [](std::string_view lhs) { return lhs == "items" || lhs == "ITEMS"; });
Review Comment:
`util::EqualICase` is a better choice.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1333891796
##########
src/types/redis_bloom_chain.h:
##########
@@ -57,18 +64,21 @@ class BloomChain : public Database {
public:
BloomChain(engine::Storage *storage, const std::string &ns) : Database(storage, ns) {}
rocksdb::Status Reserve(const Slice &user_key, uint32_t capacity, double error_rate, uint16_t expansion);
- rocksdb::Status Add(const Slice &user_key, const Slice &item, BloomFilterAddResult *ret);
- rocksdb::Status MAdd(const Slice &user_key, const std::vector<Slice> &items, std::vector<BloomFilterAddResult> *rets);
- rocksdb::Status Exists(const Slice &user_key, const Slice &item, bool *exist);
- rocksdb::Status MExists(const Slice &user_key, const std::vector<Slice> &items, std::vector<bool> *exists);
+ rocksdb::Status Add(const Slice &user_key, const std::string &item, BloomFilterAddResult *ret);
+ rocksdb::Status MAdd(const Slice &user_key, const std::vector<std::string> &items,
+ std::vector<BloomFilterAddResult> *rets);
+ rocksdb::Status InsertCommon(const Slice &user_key, const std::vector<std::string> &items,
Review Comment:
I wonder why is it called `InsertCommon` instead of `Insert`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] zncleon commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "zncleon (via GitHub)" <gi...@apache.org>.
zncleon commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1332561546
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -147,6 +151,103 @@ class CommandBFMAdd : public Commander {
std::vector<Slice> items_;
};
+class CommandBFInsert : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ bool is_nonscaling = false;
+ bool has_expansion = false;
+ while (parser.Good()) {
+ if (parser.EatEqICase("capacity")) {
+ auto parse_capacity = parser.TakeInt<uint32_t>();
+ if (!parse_capacity.IsOK()) {
+ return {Status::RedisParseErr, "Bad capacity"};
+ }
+ insert_options_.capacity = parse_capacity.GetValue();
+ if (insert_options_.capacity <= 0) {
+ return {Status::RedisParseErr, "capacity should be larger than 0"};
+ }
+ } else if (parser.EatEqICase("error")) {
+ auto parse_error_rate = parser.TakeFloat<double>();
+ if (!parse_error_rate.IsOK()) {
+ return {Status::RedisParseErr, "Bad error rate"};
+ }
+ insert_options_.error_rate = parse_error_rate.GetValue();
+ if (insert_options_.error_rate >= 1 || insert_options_.error_rate <= 0) {
+ return {Status::RedisParseErr, "error rate should be between 0 and 1"};
+ }
+ } else if (parser.EatEqICase("nocreate")) {
+ insert_options_.auto_create = false;
+ } else if (parser.EatEqICase("nonscaling")) {
+ is_nonscaling = true;
+ insert_options_.expansion = 0;
+ } else if (parser.EatEqICase("expansion")) {
+ has_expansion = true;
+ auto parse_expansion = parser.TakeInt<uint16_t>();
+ if (!parse_expansion.IsOK()) {
+ return {Status::RedisParseErr, "Bad expansion"};
+ }
+ insert_options_.expansion = parse_expansion.GetValue();
+ if (insert_options_.expansion < 1) {
+ return {Status::RedisParseErr, "expansion should be greater or equal to 1"};
+ }
+ } else if (parser.EatEqICase("items")) {
+ break;
+ } else {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ }
+
+ if (is_nonscaling && has_expansion) {
+ return {Status::RedisParseErr, "nonscaling filters cannot expand"};
+ }
+
+ auto items_begin =
+ find_if(args.begin(), args.end(), [](std::string_view lhs) { return lhs == "items" || lhs == "ITEMS"; });
+
+ if (items_begin == args.end()) {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ items_.reserve(args_.end() - items_begin);
+ for (auto item_iter = items_begin + 1; item_iter < args.end(); ++item_iter) {
+ items_.emplace_back(*item_iter);
+ }
Review Comment:
It's great. But it will have some bugs for the `items_` is `vector<Slice>` and `Slice` will not maintain the data . Whether the parser can return the reference of `args_` (or we should do this) ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] zncleon commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "zncleon (via GitHub)" <gi...@apache.org>.
zncleon commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1333897297
##########
src/types/redis_bloom_chain.h:
##########
@@ -57,18 +64,21 @@ class BloomChain : public Database {
public:
BloomChain(engine::Storage *storage, const std::string &ns) : Database(storage, ns) {}
rocksdb::Status Reserve(const Slice &user_key, uint32_t capacity, double error_rate, uint16_t expansion);
- rocksdb::Status Add(const Slice &user_key, const Slice &item, BloomFilterAddResult *ret);
- rocksdb::Status MAdd(const Slice &user_key, const std::vector<Slice> &items, std::vector<BloomFilterAddResult> *rets);
- rocksdb::Status Exists(const Slice &user_key, const Slice &item, bool *exist);
- rocksdb::Status MExists(const Slice &user_key, const std::vector<Slice> &items, std::vector<bool> *exists);
+ rocksdb::Status Add(const Slice &user_key, const std::string &item, BloomFilterAddResult *ret);
+ rocksdb::Status MAdd(const Slice &user_key, const std::vector<std::string> &items,
+ std::vector<BloomFilterAddResult> *rets);
+ rocksdb::Status InsertCommon(const Slice &user_key, const std::vector<std::string> &items,
Review Comment:
But the main logic of these two function is same(only some judge differ). If we separate them, we would have many redundant codes. @mapleFU
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] zncleon commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "zncleon (via GitHub)" <gi...@apache.org>.
zncleon commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1333897297
##########
src/types/redis_bloom_chain.h:
##########
@@ -57,18 +64,21 @@ class BloomChain : public Database {
public:
BloomChain(engine::Storage *storage, const std::string &ns) : Database(storage, ns) {}
rocksdb::Status Reserve(const Slice &user_key, uint32_t capacity, double error_rate, uint16_t expansion);
- rocksdb::Status Add(const Slice &user_key, const Slice &item, BloomFilterAddResult *ret);
- rocksdb::Status MAdd(const Slice &user_key, const std::vector<Slice> &items, std::vector<BloomFilterAddResult> *rets);
- rocksdb::Status Exists(const Slice &user_key, const Slice &item, bool *exist);
- rocksdb::Status MExists(const Slice &user_key, const std::vector<Slice> &items, std::vector<bool> *exists);
+ rocksdb::Status Add(const Slice &user_key, const std::string &item, BloomFilterAddResult *ret);
+ rocksdb::Status MAdd(const Slice &user_key, const std::vector<std::string> &items,
+ std::vector<BloomFilterAddResult> *rets);
+ rocksdb::Status InsertCommon(const Slice &user_key, const std::vector<std::string> &items,
Review Comment:
But the main logic of these two function is same. If we separate them, we would have many redundant codes. @mapleFU
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1332789272
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -147,6 +151,103 @@ class CommandBFMAdd : public Commander {
std::vector<Slice> items_;
};
+class CommandBFInsert : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ bool is_nonscaling = false;
+ bool has_expansion = false;
+ while (parser.Good()) {
+ if (parser.EatEqICase("capacity")) {
+ auto parse_capacity = parser.TakeInt<uint32_t>();
+ if (!parse_capacity.IsOK()) {
+ return {Status::RedisParseErr, "Bad capacity"};
+ }
+ insert_options_.capacity = parse_capacity.GetValue();
+ if (insert_options_.capacity <= 0) {
+ return {Status::RedisParseErr, "capacity should be larger than 0"};
+ }
+ } else if (parser.EatEqICase("error")) {
+ auto parse_error_rate = parser.TakeFloat<double>();
+ if (!parse_error_rate.IsOK()) {
+ return {Status::RedisParseErr, "Bad error rate"};
+ }
+ insert_options_.error_rate = parse_error_rate.GetValue();
+ if (insert_options_.error_rate >= 1 || insert_options_.error_rate <= 0) {
+ return {Status::RedisParseErr, "error rate should be between 0 and 1"};
+ }
+ } else if (parser.EatEqICase("nocreate")) {
+ insert_options_.auto_create = false;
+ } else if (parser.EatEqICase("nonscaling")) {
+ is_nonscaling = true;
+ insert_options_.expansion = 0;
+ } else if (parser.EatEqICase("expansion")) {
+ has_expansion = true;
+ auto parse_expansion = parser.TakeInt<uint16_t>();
+ if (!parse_expansion.IsOK()) {
+ return {Status::RedisParseErr, "Bad expansion"};
+ }
+ insert_options_.expansion = parse_expansion.GetValue();
+ if (insert_options_.expansion < 1) {
+ return {Status::RedisParseErr, "expansion should be greater or equal to 1"};
+ }
+ } else if (parser.EatEqICase("items")) {
+ break;
+ } else {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ }
+
+ if (is_nonscaling && has_expansion) {
+ return {Status::RedisParseErr, "nonscaling filters cannot expand"};
+ }
+
+ auto items_begin =
+ find_if(args.begin(), args.end(), [](std::string_view lhs) { return lhs == "items" || lhs == "ITEMS"; });
+
+ if (items_begin == args.end()) {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ items_.reserve(args_.end() - items_begin);
+ for (auto item_iter = items_begin + 1; item_iter < args.end(); ++item_iter) {
+ items_.emplace_back(*item_iter);
+ }
Review Comment:
If you want a most intuitive way, you can let args_ typed vector<string>.
Another way is to use RawTake().
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kvrocks] mapleFU commented on a diff in pull request #1768: Add the support of the BF.INSERT command
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1331085608
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -31,7 +31,7 @@ class CommandBFReserve : public Commander {
Status Parse(const std::vector<std::string> &args) override {
auto parse_error_rate = ParseFloat<double>(args[2]);
if (!parse_error_rate) {
- return {Status::RedisParseErr, errValueIsNotFloat};
+ return {Status::RedisParseErr, "Bad error rate"};
Review Comment:
We can use some constant here, e.g., in `cmd_bloom_filter.cc`
```
namespace {
errBadErrorRate = "Bad error rate";
...
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org