Skip to content

8.12 cms - #1066

Merged
AvivDavid23 merged 3 commits into
8.12from
8.12-cms
Sep 9, 2026
Merged

AvivDavid23 merged 3 commits into
8.12from
8.12-cms

Conversation

@AvivDavid23

@AvivDavid23 AvivDavid23 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Note

Medium Risk
Changes CMS command semantics (overflow/underflow, new RDB field) and persistence format v1; backward compatible for existing data via encver 0, but clients depending on old saturation behavior will see errors instead.

Overview
This PR extends Count-Min Sketch (CMS) with configurable per-cell width, decrement support, and stricter overflow semantics on the Redis command surface and in persistence.

CMS.INITBYDIM / CMS.INITBYPROB accept an optional CELL_SIZE argument (1, 2, 4, or 8 bytes; default 4). CMS.INFO reports cell_size, and CMS.MERGE requires matching width, depth, and cell size. Command metadata (commands.json, cms_info.c) reflects the new arity and docs.

CMS.INCRBY allows negative increments; failures return CMS: INCRBY overflow or CMS: INCRBY underflow instead of saturating cells at UINT32_MAX. Rejected updates roll back partial row updates and leave the sketch unchanged. Overflow limits depend on cell size and total count (capped at INT64_MAX for RESP).

The sketch implementation stores counts in variable-width cells, bumps RDB encoding to version 1 (persists cell_size; v0 loads as 4-byte cells), and CMS_ValidateLoaded rejects crafted RESTORE payloads with impossible counters or cell values. Patch version 8.11.81 and broad flow/unit tests cover cell sizes, decrements, merge rules, and corruption cases.

Reviewed by Cursor Bugbot for commit 56864ae. Bugbot is set up for automated code reviews on this repo. Configure here.

AvivDavid23 and others added 3 commits September 9, 2026 10:21
* MOD-17398 CMS Extention

* add test

* fixes

* incrby summery change

* opt - cache some values(capped) to skip calculating hash twice in `CMS_IncrBy`

* Undo writes on error instead

* move undo incrs to a function
* cms info renamke cell size key

* fix test
@AvivDavid23
AvivDavid23 merged commit d13bffe into 8.12 Sep 9, 2026
12 checks passed
@AvivDavid23
AvivDavid23 deleted the 8.12-cms branch September 9, 2026 07:31
@sonarqubecloud

sonarqubecloud Bot commented Sep 9, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.38462% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.70%. Comparing base (61f4f36) to head (56864ae).
⚠️ Report is 1 commits behind head on 8.12.

Additional details and impacted files
@@            Coverage Diff             @@
##             8.12    #1066      +/-   ##
==========================================
+ Coverage   82.97%   83.70%   +0.72%     
==========================================
  Files          21       21              
  Lines        3360     3455      +95     
==========================================
+ Hits         2788     2892     +104     
+ Misses        572      563       -9     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 56864ae. Configure here.

Comment thread src/cms.c
// headroom as INT64_MAX - counter, which wraps if counter is already above it.
if (cms->counter > (uint64_t)INT64_MAX) {
return -1;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Upgrade rejects large CMS counters

Medium Severity

CMS_ValidateLoaded treats a total counter above INT64_MAX as impossible and refuses the sketch. The previous CMS.INCRBY path still advanced counter after cells saturated at UINT32_MAX, so a few large increments could legally exceed that bound. Loading that RDB (or replicating it) can fail after upgrade, including during full dataset load.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 56864ae. Configure here.

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.

1 participant