Skip to content

storage: fix wrong commit_ts in Get/TableScan when latest write is Op_Lock (#19374) (#19394)#19397

Merged
ti-chi-bot[bot] merged 1 commit intotikv:release-8.5from
ti-chi-bot:cherry-pick-19394-to-release-8.5
Feb 27, 2026
Merged

storage: fix wrong commit_ts in Get/TableScan when latest write is Op_Lock (#19374) (#19394)#19397
ti-chi-bot[bot] merged 1 commit intotikv:release-8.5from
ti-chi-bot:cherry-pick-19394-to-release-8.5

Conversation

@ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #19394

What is changed and how it works?

Issue Number: Close #19393

What's Changed:

storage: fix wrong commit_ts in Get/TableScan when latest write is Op_Lock

Problem Summary:
- When `load_commit_ts=true` and a key has newer committed `Op_Lock` versions on top of the visible `Op_Put`, TiKV may return the lock commit_ts instead of the put commit_ts.

What changed:
- Fix `PointGetter` to return the commit_ts of the actual write version loaded by `last_change` shortcut, instead of the current cursor version.
- Fix backward scanner to only update `loaded_commit_ts` when selecting a `Put` version, avoiding ts overwrite from `Lock/Rollback` versions.

Tests:
- Add `test_point_get_load_commit_ts_with_top_lock_versions` in `point_getter.rs`.
- Add `test_load_commit_ts_with_top_lock_versions` in `scanner/backward.rs`.
- Verify existing related tests:
  - `test_point_get_load_commit_ts`
  - `test_scan_with_load_commit_ts`

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Release note

Fix wrong commit_ts returned by Get and TableScan when `load_commit_ts` is enabled and newer `Op_Lock` versions exist above the latest `Op_Put`.

Summary by CodeRabbit

  • New Features

    • Added configuration option to enable or disable commit timestamp loading during scan operations.
  • Bug Fixes

    • Fixed commit timestamp handling in backward scans and point queries to correctly cache and reuse timestamp values, preventing incorrect results in edge cases involving lock versions and deletion markers.
  • Tests

    • Expanded test coverage for commit timestamp loading across various scan scenarios and lock configurations.

@ti-chi-bot ti-chi-bot added dco-signoff: yes Indicates the PR's author has signed the dco. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. labels Feb 26, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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 and usage tips.

…_Lock (tikv#19374)

close tikv#19312

storage: fix wrong commit_ts in Get/TableScan when latest write is Op_Lock

Problem Summary:
- When `load_commit_ts=true` and a key has newer committed `Op_Lock` versions on top of the visible `Op_Put`, TiKV may return the lock commit_ts instead of the put commit_ts.

What changed:
- Fix `PointGetter` to return the commit_ts of the actual write version loaded by `last_change` shortcut, instead of the current cursor version.
- Fix backward scanner to only update `loaded_commit_ts` when selecting a `Put` version, avoiding ts overwrite from `Lock/Rollback` versions.

Tests:
- Add `test_point_get_load_commit_ts_with_top_lock_versions` in `point_getter.rs`.
- Add `test_load_commit_ts_with_top_lock_versions` in `scanner/backward.rs`.
- Verify existing related tests:
  - `test_point_get_load_commit_ts`
  - `test_scan_with_load_commit_ts`

Signed-off-by: Chao Wang <cclcwangchao@hotmail.com>
@lcwangchao lcwangchao force-pushed the cherry-pick-19394-to-release-8.5 branch from 475bea7 to 4060f1d Compare February 27, 2026 02:36
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 27, 2026

@lcwangchao: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Feb 27, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 27, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, ekexium, lcwangchao

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 added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 27, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 27, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-27 07:07:49.148316051 +0000 UTC m=+425141.663110660: ☑️ agreed by cfzjywxk.
  • 2026-02-27 07:43:22.629476191 +0000 UTC m=+427275.144270790: ☑️ agreed by ekexium.

@ti-chi-bot ti-chi-bot bot merged commit 64a6764 into tikv:release-8.5 Feb 27, 2026
6 checks passed
@ti-chi-bot ti-chi-bot bot deleted the cherry-pick-19394-to-release-8.5 branch February 27, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved cherry-pick-approved Cherry pick PR approved by release team. dco-signoff: yes Indicates the PR's author has signed the dco. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants