feat(CuckooFilter): Add CF.INSERT command - #3593
Conversation
|
Hi @geetanshjuneja, Thank you for your pull request. Please review our Contributing Guide. Please make sure you understand your changes and explain your reasoning in this pull request. Low-quality pull requests may be closed. |
|
Hi @jihuayu @nagisa-kunhah |
There was a problem hiding this comment.
Pull request overview
Adds RedisBloom-compatible CF.INSERT support to the Cuckoo Filter implementation.
Changes:
- Adds command parsing, execution, and registration.
- Introduces bulk insertion options/results and updates
CF.ADD. - Adds C++ and Go coverage for insertion behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/commands/cmd_cuckoo_filter.cc |
Implements and registers CF.INSERT. |
src/types/redis_cuckoo_chain.h |
Defines bulk insertion API and result types. |
src/types/redis_cuckoo_chain.cc |
Implements bulk Cuckoo Filter insertion. |
tests/cppunit/types/cuckoo_filter_test.cc |
Adds storage-level insertion tests. |
tests/cppunit/disk_test.cc |
Updates the disk test for the new result type. |
tests/gocase/unit/type/bloom/cuckoo_filter_test.go |
Adds command-level integration coverage. |
Suppressed comments (1)
src/commands/cmd_cuckoo_filter.cc:210
- This second
kExistbranch also aborts the server for a value permitted byCuckooFilterInsertResult. Return an execution error instead so an unexpected internal result cannot cause a process-wide outage.
case CuckooFilterInsertResult::kExist:
std::cout << "Item exists result in add command is not possible" << std::endl;
std::abort();
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Adds one item to the cuckoo filter. | ||
| // Duplicate items are allowed, so added is true whenever insertion succeeds. | ||
| rocksdb::Status Add(engine::Context &ctx, const Slice &user_key, const Slice &item, bool *added); | ||
| rocksdb::Status Add(engine::Context &ctx, const Slice &user_key, const std::string &item, CuckooFilterInsertResult &res); |
|
Hi @geetanshjuneja , @jihuayu , regarding the multiple batch writes issue, could we consider moving the page manager, which currently belongs to the subfilter, up to the CuckooFilterChain level? This would allow multiple insert operations within the same chain operation to share the same page manager and potentially commit the changes in a single batch. It might also be reusable for future Cuckoo Filter compaction operations. |
|
@nagisa-kunhah Sounds good. We can have a try. @geetanshjuneja Plz make sure the CI pass before review |
| auto s = pages_->GetBucketSlot(filter_index_, num_buckets_, current_bucket_idx, victim_slot, &old_fp); | ||
| if (!s.ok()) { | ||
| pages_.DiscardCachedPages(); | ||
| pages_->DiscardCachedPages(); | ||
| return s; | ||
| } | ||
| s = pages_.SetBucketSlot(filter_index_, num_buckets_, current_bucket_idx, victim_slot, current_fp); | ||
| s = pages_->SetBucketSlot(filter_index_, num_buckets_, current_bucket_idx, victim_slot, current_fp); | ||
| if (!s.ok()) { | ||
| pages_.DiscardCachedPages(); | ||
| pages_->DiscardCachedPages(); |
There was a problem hiding this comment.
For the INSERT command, I think we may not be able to simply discard the cached pages here. Since an INSERT can involve multiple items, some items may have already been inserted successfully before a later insertion fails.
Do we need a rollback/restore mechanism here to preserve the changes from the previous successful insertions? Sorry I missed this in the original design.
Links to #3552
This PR adds CF.INSERT command.
I have used Gemini 3.7 to generate unit tests.