Skip to content

feat(CuckooFilter): Add CF.INSERT command - #3593

Open
geetanshjuneja wants to merge 5 commits into
apache:unstablefrom
geetanshjuneja:feature/cf-insert-command
Open

feat(CuckooFilter): Add CF.INSERT command#3593
geetanshjuneja wants to merge 5 commits into
apache:unstablefrom
geetanshjuneja:feature/cf-insert-command

Conversation

@geetanshjuneja

Copy link
Copy Markdown

Links to #3552

This PR adds CF.INSERT command.

CF.INSERT key [CAPACITY capacity] [NOCREATE] ITEMS item [item ...]

I have used Gemini 3.7 to generate unit tests.

@github-actions

Copy link
Copy Markdown

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.

@geetanshjuneja

Copy link
Copy Markdown
Author

Hi @jihuayu @nagisa-kunhah
Can you pls take a look at this PR? To implement CF.INSERT I have basically looped over the code of CF.ADD. But it looks like looping over all the items and adding it in CF leads to multiple batch writes to storage engine, which I think can be done only once after all the items are inserted.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 kExist branch also aborts the server for a value permitted by CuckooFilterInsertResult. 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.

Comment thread src/types/redis_cuckoo_chain.cc Outdated
Comment thread src/types/redis_cuckoo_chain.cc
Comment thread src/commands/cmd_cuckoo_filter.cc Outdated
Comment thread src/types/redis_cuckoo_chain.h Outdated
Comment on lines +58 to +60
// 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);
@nagisa-kunhah

Copy link
Copy Markdown
Contributor

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.

@jihuayu

jihuayu commented Aug 19, 2026

Copy link
Copy Markdown
Member

@nagisa-kunhah Sounds good. We can have a try.

@geetanshjuneja Plz make sure the CI pass before review

Comment on lines +54 to +61
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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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.

4 participants