Skip to content

feat(transaction): add Transaction::start_ts and scan_unbounded - #554

Open
ariesdevil wants to merge 1 commit into
tikv:masterfrom
ariesdevil:dev_ariesdevil
Open

feat(transaction): add Transaction::start_ts and scan_unbounded#554
ariesdevil wants to merge 1 commit into
tikv:masterfrom
ariesdevil:dev_ariesdevil

Conversation

@ariesdevil

@ariesdevil ariesdevil commented Jul 24, 2026

Copy link
Copy Markdown
  • start_ts exposes the transaction's TSO start timestamp, matching client-go's KVTxn.StartTS.

  • scan_unbounded (on Transaction and Snapshot) returns all pairs in a range by paginating internally in batches of 1024, matching client-go's KVSnapshot.
    Iter semantics: a short page means the range is exhausted, a full page advances past the last key.

Summary by CodeRabbit

  • New Features
    • Added unbounded range scanning for both snapshots and transactions via a new lazy scanner that fetches results in batches until completion.
    • Introduced a public scanner API for iterating over key-value pairs.
    • Exposed the scanner type as part of the public transaction surface.
  • Tests
    • Added/updated tests for the transaction start timestamp.
    • Added coverage for unbounded scan pagination, validating batch size, ordering, and returned values.

@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign marsishandsome for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found 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 added contribution This PR is from a community contributor. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. dco-signoff: no Indicates the PR's author has not signed dco. labels Jul 24, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

Welcome @ariesdevil!

It looks like this is your first PR to tikv/client-rust 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to tikv/client-rust. 😃

@ti-chi-bot ti-chi-bot Bot added the first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. label Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0dd388ce-1d42-4cb9-91a8-844f51733b49

📥 Commits

Reviewing files that changed from the base of the PR and between f2bd080 and 69be17a.

📒 Files selected for processing (4)
  • src/lib.rs
  • src/transaction/mod.rs
  • src/transaction/snapshot.rs
  • src/transaction/transaction.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/lib.rs
  • src/transaction/mod.rs
  • src/transaction/snapshot.rs

📝 Walkthrough

Walkthrough

Transaction adds lazy, paginated unbounded range scanning through a public Scanner. Snapshot delegates the API, Scanner is re-exported publicly, and tests validate pagination and transaction timestamp behavior.

Changes

Transaction scanning

Layer / File(s) Summary
Transaction scan implementation
src/transaction/transaction.rs
Adds lazy scanner construction and 256-item pagination using buffered results, successor keys, and short-page EOF detection.
Snapshot and public API surface
src/transaction/snapshot.rs, src/transaction/mod.rs, src/lib.rs
Adds Snapshot delegation and re-exports Scanner from the transaction module and crate root.
Scanner and timestamp validation
src/transaction/transaction.rs
Tests timestamp access, scan limits, pagination calls, ordering, and returned values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Snapshot
  participant Transaction
  participant PdClient
  Snapshot->>Transaction: scan_unbounded(range)
  Transaction->>PdClient: scan(start, end, batch size)
  PdClient-->>Transaction: page of KvPair results
  Transaction->>PdClient: scan(next key, end, batch size)
  PdClient-->>Transaction: final page of KvPair results
  Transaction-->>Snapshot: KvPair results
Loading

Suggested reviewers: eduralph, iosmanthus

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding transaction start timestamp access and unbounded scan support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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 Jul 24, 2026

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/transaction/transaction.rs`:
- Around line 122-127: Update the documentation for the transaction start
timestamp accessor to describe start_ts solely as the transaction’s read
timestamp. Remove claims that writes become visible at this timestamp or that
its physical component is suitable for commit, lease, or fencing semantics;
clarify that visibility is determined by the commit timestamp.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e1b0c858-08d6-4555-82b4-3d9b87eec3e9

📥 Commits

Reviewing files that changed from the base of the PR and between 2c0f2f3 and dd640ed.

📒 Files selected for processing (2)
  • src/transaction/snapshot.rs
  • src/transaction/transaction.rs

Comment thread src/transaction/transaction.rs Outdated
@ariesdevil
ariesdevil force-pushed the dev_ariesdevil branch 3 times, most recently from 2bfa214 to 297da6c Compare July 27, 2026 09:36

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

rest LGTM

Comment thread src/transaction/transaction.rs Outdated
if let Some(last) = page.last() {
start = last.key().clone().next_key();
}
out.extend(page);

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.

We can't estimate the data size in a range, so buffer them in memory is danger to me, it can easily cause OOM in the client side.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed, aligned to the client-go's behavior, PTAL again.

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/transaction/transaction.rs`:
- Around line 122-134: Consolidate the duplicate accessors by making either
start_ts or the existing start_timestamp delegate to the other, with both
preserving the current timestamp value and public API behavior. Prefer retaining
the established accessor unless the project’s compatibility policy explicitly
phases it out, and avoid maintaining two independent implementations.
- Around line 1246-1248: Reconcile SCAN_UNBOUNDED_BATCH_SIZE with the documented
scan batch size: choose the intended value (256 or 1024), update the constant or
its description accordingly, and replace the inaccurate client-go
DefaultScanBatchSize reference with a valid upstream source or remove the
attribution.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 20b28e3b-75ad-4ce5-894d-12ed305a281b

📥 Commits

Reviewing files that changed from the base of the PR and between 297da6c and f2bd080.

📒 Files selected for processing (4)
  • src/lib.rs
  • src/transaction/mod.rs
  • src/transaction/snapshot.rs
  • src/transaction/transaction.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/transaction/snapshot.rs

Comment thread src/transaction/transaction.rs Outdated
Comment thread src/transaction/transaction.rs
Signed-off-by: Yijun Zhao <ariesdevil77@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. dco-signoff: yes Indicates the PR's author has signed the dco. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants