Skip to content

CLUSTERSCAN MATCH pattern maps to a specific slot optimizations#3380

Merged
hpatro merged 1 commit into
valkey-io:unstablefrom
nmvk:cscan-match
Mar 19, 2026
Merged

CLUSTERSCAN MATCH pattern maps to a specific slot optimizations#3380
hpatro merged 1 commit into
valkey-io:unstablefrom
nmvk:cscan-match

Conversation

@nmvk

@nmvk nmvk commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

When a MATCH pattern maps to a specific slot, CLUSTERSCAN can skip directly to that slot
instead of walking through all slots one by one.

  • On cursor 0, starts directly at the matching slot
  • If cursor is behind the matching slot, jumps forward
  • If cursor is ahead of the matching slot, we conclude the scan as we cannot match keys
  • If both SLOT and MATCH are provided but target different slots, returns 0 immediately

Follow-up of #2934

@codecov

codecov Bot commented Mar 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.43%. Comparing base (afe6ee1) to head (88f29ba).
⚠️ Report is 74 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3380      +/-   ##
============================================
- Coverage     74.82%   74.43%   -0.39%     
============================================
  Files           130      130              
  Lines         72730    72748      +18     
============================================
- Hits          54418    54150     -268     
- Misses        18312    18598     +286     
Files with missing lines Coverage Δ
src/cluster.c 92.16% <100.00%> (-0.08%) ⬇️

... and 23 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

LGTM overall.

Need some clarification around the test.

Comment thread tests/unit/cluster/clusterscan.tcl
Comment thread tests/unit/cluster/clusterscan.tcl Outdated
When a MATCH pattern maps to a specific slot, `CLUSTERSCAN` can skip directly to that slot
instead of walking through all slots one by one.

- On `cursor 0`, starts directly at the matching slot
- If cursor is behind the matching slot, jumps forward
- If cursor is past the matching slot, we conclude the scan as we cannot match keys
- If slot and match slot mismatch do not perform cluster walk.

Signed-off-by: nmvk <r@nmvk.com>
@nmvk nmvk requested a review from hpatro March 19, 2026 02:09
@hpatro hpatro merged commit cd0b4c5 into valkey-io:unstable Mar 19, 2026
58 checks passed
@github-project-automation github-project-automation Bot moved this to To be backported in Valkey 9.1 Apr 7, 2026
sarthakaggarwal97 pushed a commit to sarthakaggarwal97/valkey that referenced this pull request Apr 16, 2026
…ey-io#3380)

When a MATCH pattern maps to a specific slot, `CLUSTERSCAN` can skip
directly to that slot
instead of walking through all slots one by one.

- On `cursor 0`, starts directly at the matching slot
- If cursor is behind the matching slot, jumps forward
- If cursor is ahead of the matching slot, we conclude the scan as we
cannot match keys
- If both SLOT and MATCH are provided but target different slots,
returns 0 immediately

Signed-off-by: nmvk <r@nmvk.com>
madolson pushed a commit that referenced this pull request Apr 27, 2026
When a MATCH pattern maps to a specific slot, `CLUSTERSCAN` can skip
directly to that slot
instead of walking through all slots one by one.

- On `cursor 0`, starts directly at the matching slot
- If cursor is behind the matching slot, jumps forward
- If cursor is ahead of the matching slot, we conclude the scan as we
cannot match keys
- If both SLOT and MATCH are provided but target different slots,
returns 0 immediately

Signed-off-by: nmvk <r@nmvk.com>
@sarthakaggarwal97 sarthakaggarwal97 added the release-notes This issue should get a line item in the release notes label Apr 28, 2026
valkeyrie-ops Bot pushed a commit that referenced this pull request May 18, 2026
When a MATCH pattern maps to a specific slot, `CLUSTERSCAN` can skip
directly to that slot
instead of walking through all slots one by one.

- On `cursor 0`, starts directly at the matching slot
- If cursor is behind the matching slot, jumps forward
- If cursor is ahead of the matching slot, we conclude the scan as we
cannot match keys
- If both SLOT and MATCH are provided but target different slots,
returns 0 immediately

Signed-off-by: nmvk <r@nmvk.com>
madolson pushed a commit that referenced this pull request May 19, 2026
When a MATCH pattern maps to a specific slot, `CLUSTERSCAN` can skip
directly to that slot
instead of walking through all slots one by one.

- On `cursor 0`, starts directly at the matching slot
- If cursor is behind the matching slot, jumps forward
- If cursor is ahead of the matching slot, we conclude the scan as we
cannot match keys
- If both SLOT and MATCH are provided but target different slots,
returns 0 immediately

Signed-off-by: nmvk <r@nmvk.com>
@sarthakaggarwal97 sarthakaggarwal97 moved this from To be backported to Done in Valkey 9.1 May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes This issue should get a line item in the release notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants