You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "ChaseForward (via GitHub)" <gi...@apache.org> on 2026/09/27 08:56:57 UTC
[PR] feat(cf): add CF.COUNT command [kvrocks]
ChaseForward opened a new pull request, #3650:
URL: https://github.com/apache/kvrocks/pull/3650
# Description
This PR adds the CF.COUNT command, bringing RedisBloom compatibility to the cuckoo filter. It returns the number of occurrences of an item in a cuckoo filter by scanning the primary and secondary buckets of every sub-filter. Returns 0 if the filter does not exist.
# Related
Split from #3591 as suggested (one command per PR). Builds on the cuckoo filter infrastructure from #3481.
--
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
Re: [PR] feat(cf): add CF.COUNT command [kvrocks]
Posted by "jihuayu (via GitHub)" <gi...@apache.org>.
jihuayu commented on PR #3650:
URL: https://github.com/apache/kvrocks/pull/3650#issuecomment-5867140504
Hi @ChaseForward Can you resolved the conficts. Thanks
--
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
Re: [PR] feat(cf): add CF.COUNT command [kvrocks]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3650:
URL: https://github.com/apache/kvrocks/pull/3650#issuecomment-5854418185
Hi @ChaseForward,
Thank you for your pull request. Please review our [Contributing Guide](https://kvrocks.apache.org/community/contributing/).
Please make sure you understand your changes and explain your reasoning in this pull request. Low-quality pull requests may be closed.
--
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
Re: [PR] feat(cf): add CF.COUNT command [kvrocks]
Posted by "jihuayu (via GitHub) via issues" <is...@kvrocks.apache.org>.
jihuayu merged PR #3650:
URL: https://github.com/apache/kvrocks/pull/3650
--
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
Re: [PR] feat(cf): add CF.COUNT command [kvrocks]
Posted by "ChaseForward (via GitHub)" <gi...@apache.org>.
ChaseForward commented on PR #3650:
URL: https://github.com/apache/kvrocks/pull/3650#issuecomment-5882750508
Thanks for your review and suggestion. I plan to complete these unit tests during the National Day holiday. My apologies for the prolonged delay.
--
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
Re: [PR] feat(cf): add CF.COUNT command [kvrocks]
Posted by "ChaseForward (via GitHub)" <gi...@apache.org>.
ChaseForward commented on code in PR #3650:
URL: https://github.com/apache/kvrocks/pull/3650#discussion_r4133994057
##########
src/commands/cmd_cuckoo_filter.cc:
##########
@@ -131,8 +131,41 @@ class CommandCFAdd : public Commander {
}
};
-// Register the CF.RESERVE and CF.ADD commands
+class CommandCFCount : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ // CF.COUNT key item
+ if (args.size() != 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ return Commander::Parse(args);
+ }
+
+ Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
+ redis::CuckooChain cuckoo_db(srv->storage, conn->GetNamespace());
+ uint64_t count = 0;
+ auto s = cuckoo_db.Count(ctx, args_[1], args_[2], &count);
+
+ if (s.IsNotFound()) {
+ *output = redis::Integer(0);
+ return Status::OK();
+ }
+ if (!s.ok()) {
+ return {Status::RedisExecErr, s.ToString()};
+ }
+
+ *output = redis::Integer(count);
+ return Status::OK();
+ }
+};
+
+/* Register commands
+ CF.RESERVE
+ CF.ADD
+ CF.COUNT
+*/
Review Comment:
Sure, this part can be deleted.
--
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
Re: [PR] feat(cf): add CF.COUNT command [kvrocks]
Posted by "nagisa-kunhah (via GitHub)" <gi...@apache.org>.
nagisa-kunhah commented on code in PR #3650:
URL: https://github.com/apache/kvrocks/pull/3650#discussion_r4115099497
##########
src/commands/cmd_cuckoo_filter.cc:
##########
@@ -131,8 +131,41 @@ class CommandCFAdd : public Commander {
}
};
-// Register the CF.RESERVE and CF.ADD commands
+class CommandCFCount : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ // CF.COUNT key item
+ if (args.size() != 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ return Commander::Parse(args);
+ }
+
+ Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
+ redis::CuckooChain cuckoo_db(srv->storage, conn->GetNamespace());
+ uint64_t count = 0;
+ auto s = cuckoo_db.Count(ctx, args_[1], args_[2], &count);
+
+ if (s.IsNotFound()) {
+ *output = redis::Integer(0);
+ return Status::OK();
+ }
+ if (!s.ok()) {
+ return {Status::RedisExecErr, s.ToString()};
+ }
+
+ *output = redis::Integer(count);
+ return Status::OK();
+ }
+};
+
+/* Register commands
+ CF.RESERVE
+ CF.ADD
+ CF.COUNT
+*/
Review Comment:
Are these comments necessary? If not, can we remove them?
##########
src/types/cuckoo_filter_sub_filter.cc:
##########
@@ -97,6 +97,28 @@ rocksdb::Status CuckooSubFilter::WriteToBatch(rocksdb::WriteBatchBase *batch) {
return pages_.WriteBackDirtyPages(batch);
}
+rocksdb::Status CuckooSubFilter::Count(uint64_t hash, uint8_t fingerprint, uint32_t *count) {
+ uint32_t bucket1_idx = getPrimaryBucketIndex(hash);
+ uint32_t bucket2_idx = getSecondaryBucketIndex(hash, fingerprint);
+
+ auto s = pages_.PrefetchBuckets(filter_index_, num_buckets_, bucket1_idx, bucket2_idx);
+ if (!s.ok()) return s;
+
+ uint32_t c1 = 0, c2 = 0;
+ s = pages_.CountInBucket(filter_index_, num_buckets_, bucket1_idx, fingerprint, &c1);
+ if (!s.ok()) return s;
+
+ *count += c1;
+
+ if (bucket1_idx != bucket2_idx) {
+ s = pages_.CountInBucket(filter_index_, num_buckets_, bucket2_idx, fingerprint, &c2);
+ if (!s.ok()) return s;
+ *count += c2;
+ }
Review Comment:
Referring to the RedisBloom implementation: https://github.com/RedisBloom/RedisBloom/blob/a89aac8e75da4a1fbbb59a307ea2f3b4ae87870d/src/cuckoo.c#L197 , when `bucket1_idx == bucket2_idx`, RedisBloom may count the item twice. Should we follow RedisBloom's semantics? cc @jihuayu
--
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
Re: [PR] feat(cf): add CF.COUNT command [kvrocks]
Posted by "jihuayu (via GitHub)" <gi...@apache.org>.
jihuayu commented on code in PR #3650:
URL: https://github.com/apache/kvrocks/pull/3650#discussion_r4118239024
##########
src/types/cuckoo_filter_sub_filter.cc:
##########
@@ -97,6 +97,28 @@ rocksdb::Status CuckooSubFilter::WriteToBatch(rocksdb::WriteBatchBase *batch) {
return pages_.WriteBackDirtyPages(batch);
}
+rocksdb::Status CuckooSubFilter::Count(uint64_t hash, uint8_t fingerprint, uint32_t *count) {
+ uint32_t bucket1_idx = getPrimaryBucketIndex(hash);
+ uint32_t bucket2_idx = getSecondaryBucketIndex(hash, fingerprint);
+
+ auto s = pages_.PrefetchBuckets(filter_index_, num_buckets_, bucket1_idx, bucket2_idx);
+ if (!s.ok()) return s;
+
+ uint32_t c1 = 0, c2 = 0;
+ s = pages_.CountInBucket(filter_index_, num_buckets_, bucket1_idx, fingerprint, &c1);
+ if (!s.ok()) return s;
+
+ *count += c1;
+
+ if (bucket1_idx != bucket2_idx) {
+ s = pages_.CountInBucket(filter_index_, num_buckets_, bucket2_idx, fingerprint, &c2);
+ if (!s.ok()) return s;
+ *count += c2;
+ }
Review Comment:
I think this is a bug in RedisBloom, and we don't need to follow its behavior.
--
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
Re: [PR] feat(cf): add CF.COUNT command [kvrocks]
Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #3650:
URL: https://github.com/apache/kvrocks/pull/3650#discussion_r4151889331
##########
src/commands/cmd_cuckoo_filter.cc:
##########
@@ -131,8 +131,41 @@ class CommandCFAdd : public Commander {
}
};
-// Register the CF.RESERVE and CF.ADD commands
+class CommandCFCount : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ // CF.COUNT key item
+ if (args.size() != 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ return Commander::Parse(args);
+ }
+
+ Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
+ redis::CuckooChain cuckoo_db(srv->storage, conn->GetNamespace());
+ uint64_t count = 0;
+ auto s = cuckoo_db.Count(ctx, args_[1], args_[2], &count);
+
+ if (s.IsNotFound()) {
+ *output = redis::Integer(0);
+ return Status::OK();
+ }
+ if (!s.ok()) {
+ return {Status::RedisExecErr, s.ToString()};
+ }
+
+ *output = redis::Integer(count);
+ return Status::OK();
+ }
+};
+
+/* Register commands
+ CF.RESERVE
+ CF.ADD
+ CF.COUNT
+*/
Review Comment:
Please remove 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
Re: [PR] feat(cf): add CF.COUNT command [kvrocks]
Posted by "jihuayu (via GitHub)" <gi...@apache.org>.
jihuayu commented on PR #3650:
URL: https://github.com/apache/kvrocks/pull/3650#issuecomment-6291293917
Hi @ChaseForward, could you please sync this PR with the latest unstable and resolve the merge conflicts? Thanks!
--
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