Skip to content

raw: stop scanning at the end of the keyspace - #569

Merged
ti-chi-bot[bot] merged 2 commits into
tikv:masterfrom
lance6716:lance6716/fix-raw-scan-empty-next-key
Oct 13, 2026
Merged

ti-chi-bot[bot] merged 2 commits into
tikv:masterfrom
lance6716:lance6716/fix-raw-scan-empty-next-key

Conversation

@lance6716

@lance6716 lance6716 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

For an API v2 keyspace scan, an open-ended range has an encoded upper bound at the next keyspace prefix. The final TiKV region has an empty end key, so the existing range comparison does not stop the scan. The client can then send another request starting at the empty key.

Stop after processing the final region response. This is in the shared path used by scan and scan_reverse.

Regression test

A mocked final region returns one key with a requested limit of two. The parameterized test asserts that both scan and scan_reverse return that key after exactly one request. Applied to the previous upstream code, both cases fail because they issue a second request; both pass with this fix.

Verification

  • cargo fmt --all -- --check
  • cargo test --lib — 104 passed
  • git diff --check

The integration suite requires a running PD/TiKV cluster and was not run locally.

Summary by CodeRabbit

  • Bug Fixes
    • Open-ended scans now stop when they reach the final region and no further scan key is available. This prevents an unnecessary additional scan request and ensures scanning ends correctly even when the range has no explicit end key.
    • Forward and reverse scans both return the final key-value pair when reaching the end of the scanned range.

Copilot AI balanced review requested due to automatic review settings October 10, 2026 07:23
@ti-chi-bot ti-chi-bot Bot added dco-signoff: no Indicates the PR's author has not signed dco. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 10, 2026
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 364e1433-969b-47a8-9bb4-e2b9af976744



📥 Commits

Reviewing files that changed from the base of the PR and between b0e351e and 930e46a.




📒 Files selected for processing (1)
  • src/raw/client.rs



Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.





📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

scan_inner now stops when a scan response contains an empty next_key. A forward and reverse scan test checks the returned key-value pair and confirms that each scan dispatches one request.

Changes

Scan termination

Layer / File(s) Summary
Empty next-key check
src/raw/client.rs
scan_inner exits when next_key is empty. The test covers forward and reverse open-ended scans and checks that each returns the decoded key-value pair after one request.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: eduralph





Merge Risk: ⚪ Minimal · up to 9634d

Scans stop after the final region without an extra request. No merge-blocking risk is established.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: stopping scans when the client reaches the end of the keyspace.



✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lance6716
lance6716 force-pushed the lance6716/fix-raw-scan-empty-next-key branch from 86dfa2f to 983ba67 Compare October 10, 2026 07:24
@ti-chi-bot ti-chi-bot Bot added dco-signoff: yes Indicates the PR's author has signed the dco. and removed dco-signoff: no Indicates the PR's author has not signed dco. labels Oct 10, 2026

Copilot AI 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.

🟡 Changes recommended

The new termination behavior needs regression coverage for under-limit forward and reverse scans.

1 open finding
What changed in this PR

Stops RawKV scans after processing the final TiKV region, preventing repeated scans at the keyspace boundary.

Changes:

  • Detects an empty next-region key and terminates forward or reverse scans.
File Description
src/​raw/​client.rs Stops scanning when the final region is reached.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/raw/client.rs
@lance6716
lance6716 force-pushed the lance6716/fix-raw-scan-empty-next-key branch from 983ba67 to 51b4bf0 Compare October 10, 2026 07:25
@lance6716
lance6716 force-pushed the lance6716/fix-raw-scan-empty-next-key branch from 51b4bf0 to b0e351e Compare October 10, 2026 07:31
@ti-chi-bot ti-chi-bot Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 10, 2026
For an API v2 keyspace scan, an open-ended range is bounded by the next
keyspace prefix. The final TiKV region has an empty end key, so comparing
it to that nonempty range bound does not terminate the scan. Another
request starts at the empty key.

Stop after processing the final region response, and test that a scan
with remaining limit sends only one request.

Signed-off-by: lance6716 <lance6716@gmail.com>
@lance6716
lance6716 force-pushed the lance6716/fix-raw-scan-empty-next-key branch from b0e351e to 930e46a Compare October 10, 2026 14:40
@ti-chi-bot ti-chi-bot Bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Oct 12, 2026
Signed-off-by: lance6716 <lance6716@gmail.com>
@ti-chi-bot ti-chi-bot Bot added the lgtm label Oct 13, 2026
@ti-chi-bot

ti-chi-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ekexium, iosmanthus

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Oct 13, 2026
@ti-chi-bot

ti-chi-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-10-12 02:13:18.005697767 +0000 UTC m=+610807.752928716: ☑️ agreed by ekexium.
  • 2026-10-13 12:57:36.505222449 +0000 UTC m=+735866.252453338: ☑️ agreed by iosmanthus.

@ti-chi-bot
ti-chi-bot Bot merged commit 547a216 into tikv:master Oct 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants