Skip to content

chore: add cuckoo to compact object - #7645

Merged
kostasrim merged 1 commit into
mainfrom
kcuckoo2
Jun 22, 2026
Merged

chore: add cuckoo to compact object#7645
kostasrim merged 1 commit into
mainfrom
kcuckoo2

Conversation

@kostasrim

@kostasrim kostasrim commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

integrate CuckooFilter to CompactObject

resolves #7579

@kostasrim kostasrim self-assigned this Jun 18, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. RDB save crashes on cuckoo 🐞 Bug ≡ Correctness
Description
CompactObj::ObjType() can now return OBJ_CUCKOOFILTER, but RdbObjectType() in rdb_save.cc has no
case for it and falls through to LOG(FATAL), crashing during snapshot/backup when such a value is
saved.
Code

src/core/compact_object.cc[R946-947]

+    case CUCKOO_FILTER_TAG:
+      return OBJ_CUCKOOFILTER;
Evidence
The PR makes cuckoo filters a first-class CompactObj type (ObjType can return OBJ_CUCKOOFILTER). The
RDB save code enumerates supported types and then unconditionally LOG(FATAL)s for unknown ones;
since OBJ_CUCKOOFILTER is not handled, encountering it during snapshot/backup will crash.

src/core/compact_object.cc[911-952]
src/redis/redis_aux.h[9-20]
src/server/rdb_save.cc[165-212]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`CompactObj` can now represent `OBJ_CUCKOOFILTER` (via `CUCKOO_FILTER_TAG`), but the RDB serialization dispatch (`RdbObjectType`/`SaveObject` and the loader side) does not recognize this type. If a cuckoo-filter value is present during snapshot/backup, `RdbObjectType()` will hit its fallback `LOG(FATAL)` path and terminate the process.

## Issue Context
Dragonfly uses custom DF RDB types for module-like objects (JSON/SBF/CMS/TOPK). CuckooFilter needs the same end-to-end wiring: type id, save path, and load path.

## Fix Focus Areas
- src/server/rdb_extensions.h[11-25]
- src/server/rdb_save.cc[165-212]
- src/server/rdb_save.cc[334-376]
- src/server/rdb_load.cc[1261-1294]
- src/core/compact_object.cc[911-952]

## What to implement
1. Introduce a new DF RDB type constant (e.g. `RDB_TYPE_CUCKOOFILTER = 37`) and include it in `rdbIsObjectTypeDF`.
2. Update `RdbObjectType(const CompactObj&)` to map `OBJ_CUCKOOFILTER` to `RDB_TYPE_CUCKOOFILTER`.
3. Add `SaveCuckooFilterObject(const PrimeValue&)` and dispatch it from `SaveObject()` when `obj_type == OBJ_CUCKOOFILTER`.
4. Update `RdbLoaderBase` switch to recognize `RDB_TYPE_CUCKOOFILTER` and implement `ReadCuckooFilter()` that reconstructs `PrimeValue` via `SetCuckooFilter(...)` and restores the filter contents.
5. Add a save+load roundtrip test similar to SBF/CMS/TOPK to ensure snapshots work with cuckoo filters.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Cuckoo type label typo 🐞 Bug ◔ Observability
Description
ObjTypeToString maps OBJ_CUCKOOFILTER to "MCuckooFIlter-TYPE" (typo/casing), which will surface in
metrics labels and debug outputs that rely on ObjTypeToString().
Code

src/core/compact_object.cc[R2051-2052]

+    {OBJ_TOPK, "TopK-TYPE"sv},
+    {OBJ_CUCKOOFILTER, "MCuckooFIlter-TYPE"sv}};
Evidence
The PR adds the new ObjType->string mapping with a typo. The server’s metrics exporter uses
ObjTypeToString() to emit per-type memory usage labels, so the typo becomes externally visible.

src/core/compact_object.cc[2040-2053]
src/server/server_family.cc[1827-1838]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`ObjTypeToString()` exports a misspelled/inconsistently-cased string for `OBJ_CUCKOOFILTER` ("MCuckooFIlter-TYPE"). This string is used in user-visible/debug output and as a metrics label value, so the typo leaks externally and can create inconsistent labeling.

## Issue Context
Per-type memory metrics use `ObjTypeToString(type)` as the label value.

## Fix Focus Areas
- src/core/compact_object.cc[2040-2053]
- src/server/server_family.cc[1827-1838]

## What to change
- Replace "MCuckooFIlter-TYPE" with the intended canonical spelling (e.g. "MCuckooFilter-TYPE"), matching the style of existing module-like labels (SBF/CMS/TOPK).
- (Optional but recommended) Add/extend a small unit test that validates `ObjTypeFromString(ObjTypeToString(x)) == x` for `OBJ_CUCKOOFILTER` to prevent future label regressions.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment on lines +946 to +947
case CUCKOO_FILTER_TAG:
return OBJ_CUCKOOFILTER;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Rdb save crashes on cuckoo 🐞 Bug ≡ Correctness

CompactObj::ObjType() can now return OBJ_CUCKOOFILTER, but RdbObjectType() in rdb_save.cc has no
case for it and falls through to LOG(FATAL), crashing during snapshot/backup when such a value is
saved.
Agent Prompt
## Issue description
`CompactObj` can now represent `OBJ_CUCKOOFILTER` (via `CUCKOO_FILTER_TAG`), but the RDB serialization dispatch (`RdbObjectType`/`SaveObject` and the loader side) does not recognize this type. If a cuckoo-filter value is present during snapshot/backup, `RdbObjectType()` will hit its fallback `LOG(FATAL)` path and terminate the process.

## Issue Context
Dragonfly uses custom DF RDB types for module-like objects (JSON/SBF/CMS/TOPK). CuckooFilter needs the same end-to-end wiring: type id, save path, and load path.

## Fix Focus Areas
- src/server/rdb_extensions.h[11-25]
- src/server/rdb_save.cc[165-212]
- src/server/rdb_save.cc[334-376]
- src/server/rdb_load.cc[1261-1294]
- src/core/compact_object.cc[911-952]

## What to implement
1. Introduce a new DF RDB type constant (e.g. `RDB_TYPE_CUCKOOFILTER = 37`) and include it in `rdbIsObjectTypeDF`.
2. Update `RdbObjectType(const CompactObj&)` to map `OBJ_CUCKOOFILTER` to `RDB_TYPE_CUCKOOFILTER`.
3. Add `SaveCuckooFilterObject(const PrimeValue&)` and dispatch it from `SaveObject()` when `obj_type == OBJ_CUCKOOFILTER`.
4. Update `RdbLoaderBase` switch to recognize `RDB_TYPE_CUCKOOFILTER` and implement `ReadCuckooFilter()` that reconstructs `PrimeValue` via `SetCuckooFilter(...)` and restores the filter contents.
5. Add a save+load roundtrip test similar to SBF/CMS/TOPK to ensure snapshots work with cuckoo filters.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@augmentcode

augmentcode Bot commented Jun 18, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR adds Cuckoo Filter support to Dragonfly’s CompactObj value representation (resolving #7579).

Changes:

  • Introduced CUCKOO_FILTER_TAG/OBJ_CUCKOOFILTER and wired them into Size(), ObjType(), Free(), and MallocUsed()
  • Added SetCuckooFilter/GetCuckooFilter APIs and corresponding union storage
  • Implemented CuckooFilter::MallocUsed() (renaming the prior helper) and updated unit tests
  • Extended ObjTypeToString mapping and compact object tests to cover the new type

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/core/compact_object.cc Outdated
@kostasrim
kostasrim force-pushed the kcuckoo2 branch 2 times, most recently from fe039aa to c13082f Compare June 18, 2026 15:41
Signed-off-by: Kostas Kyrimis <kostas@dragonflydb.io>
Comment thread src/core/cuckoo.cc
[](const SubFilter& sf) { return sf.size(); });
size_t CuckooFilter::MallocUsed() const {
size_t res = sizeof(CuckooFilter) + filters_.capacity() * sizeof(SubFilter);
for (const SubFilter& sf : filters_) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dranikpg never again, I accept my defeat 😄

@kostasrim

Copy link
Copy Markdown
Contributor Author

augment review

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/core/compact_object.h
void SetCMS(uint32_t width, uint32_t depth);
CMS* GetCMS() const;

void SetCuckooFilter(CuckooFilter* cf) {

@augmentcode augmentcode Bot Jun 18, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SetCuckooFilter(CuckooFilter* cf) stores a raw pointer, but CompactObj::Free() later calls DeleteMR<CuckooFilter>, which assumes cf was allocated via CompactObj::AllocateMR (same thread-local MR). Without an explicit ownership/allocator contract here, it’s easy for a future caller to pass a differently-allocated filter and trigger invalid deallocation.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@kostasrim
kostasrim requested review from abhijat and dranikpg June 19, 2026 09:24
@kostasrim
kostasrim merged commit 05060af into main Jun 22, 2026
17 of 23 checks passed
@kostasrim
kostasrim deleted the kcuckoo2 branch June 22, 2026 06:37
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.

Cuckoo family

2 participants