-
Notifications
You must be signed in to change notification settings - Fork 669
feat(cf): add CF.COUNT command #3650
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
base: unstable
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| */ | ||
|
Comment on lines
+162
to
+166
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this. |
||
| REDIS_REGISTER_COMMANDS(CuckooFilter, MakeCmdAttr<CommandCFReserve>("cf.reserve", -3, "write", 1, 1, 1), | ||
| MakeCmdAttr<CommandCFAdd>("cf.add", 3, "write", 1, 1, 1)) | ||
| MakeCmdAttr<CommandCFAdd>("cf.add", 3, "write", 1, 1, 1), | ||
| MakeCmdAttr<CommandCFCount>("cf.count", 3, "read-only", 1, 1, 1)) | ||
|
|
||
| } // namespace redis | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| } | ||
|
Comment on lines
+113
to
+117
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Referring to the RedisBloom implementation: https://github.com/RedisBloom/RedisBloom/blob/a89aac8e75da4a1fbbb59a307ea2f3b4ae87870d/src/cuckoo.c#L197 , when
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a bug in RedisBloom, and we don't need to follow its behavior. |
||
|
|
||
| return rocksdb::Status::OK(); | ||
| } | ||
|
|
||
| uint32_t CuckooSubFilter::getPrimaryBucketIndex(uint64_t hash) const { return hash % num_buckets_; } | ||
|
|
||
| uint32_t CuckooSubFilter::getSecondaryBucketIndex(uint64_t hash, uint8_t fingerprint) const { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.