Skip to content

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

Merged
ti-chi-bot[bot] merged 3 commits intotikv:release-8.5-20260121-v8.5.5from
lcwangchao:fix_commit_ts_with_lock
Feb 14, 2026
Merged

storage: fix wrong commit_ts in Get/TableScan when latest write is Op_Lock#19374
ti-chi-bot[bot] merged 3 commits intotikv:release-8.5-20260121-v8.5.5from
lcwangchao:fix_commit_ts_with_lock

Conversation

@lcwangchao
Copy link
Contributor

@lcwangchao lcwangchao commented Feb 14, 2026

What is changed and how it works?

Issue Number: Close #19312, 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`.

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has signed the dco. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 14, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 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

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.

Signed-off-by: Chao Wang <cclcwangchao@hotmail.com>
@lcwangchao lcwangchao force-pushed the fix_commit_ts_with_lock branch from b6953d6 to a76b33f Compare February 14, 2026 04:56
Signed-off-by: Chao Wang <cclcwangchao@hotmail.com>
}
if current_ts <= last_checked_commit_ts {
// We reach the last handled key
return self.handle_last_version(last_version, user_key, loaded_commit_ts);
Copy link
Member

Choose a reason for hiding this comment

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

What if it hits this branch, the loaded_commit_ts is not updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. In this branch we return last_version (captured during the initial prev() loop), not the write at current_ts. loaded_commit_ts is updated together with last_version (only for PUT/DELETE), so it already matches what we return here. Not updating it for LOCK/ROLLBACK is intentional to avoid the original bug where commit_ts could be taken from a newer LOCK. Added test_load_commit_ts_with_top_lock_versions to cover the case (many committed LOCKs on top of a visible PUT) and it asserts the returned commit_ts comes from the PUT.

@lcwangchao
Copy link
Contributor Author

/retest

Copy link
Member

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 14, 2026
Signed-off-by: Chao Wang <cclcwangchao@hotmail.com>
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 14, 2026
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 14, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 14, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, Connor1996

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:
  • OWNERS [Connor1996,cfzjywxk]

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
Copy link
Contributor

ti-chi-bot bot commented Feb 14, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-14 05:49:45.768687408 +0000 UTC m=+74753.515081436: ☑️ agreed by Connor1996.
  • 2026-02-14 06:02:57.622292298 +0000 UTC m=+75545.368686331: ☑️ agreed by cfzjywxk.

@ti-chi-bot ti-chi-bot bot merged commit 055c58f into tikv:release-8.5-20260121-v8.5.5 Feb 14, 2026
5 checks passed
@lcwangchao lcwangchao deleted the fix_commit_ts_with_lock branch February 14, 2026 06:34
lcwangchao added a commit to lcwangchao/tikv that referenced this pull request Feb 25, 2026
…_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>
ti-chi-bot bot pushed a commit that referenced this pull request Feb 26, 2026
…_Lock (#19374) (#19394)

close #19393

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>
ti-chi-bot pushed a commit to ti-chi-bot/tikv that referenced this pull request Feb 26, 2026
…_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 added a commit to ti-chi-bot/tikv that referenced this pull request Feb 27, 2026
…_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>
ti-chi-bot bot pushed a commit that referenced this pull request Feb 27, 2026
…_Lock (#19374) (#19394) (#19397)

close #19393

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>

Co-authored-by: Chao Wang <cclcwangchao@hotmail.com>
mittalrishabh pushed a commit to mittalrishabh/tikv that referenced this pull request Mar 7, 2026
…_Lock (tikv#19374) (tikv#19394)

close tikv#19393

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>
mittalrishabh pushed a commit to mittalrishabh/tikv that referenced this pull request Mar 7, 2026
…_Lock (tikv#19374) (tikv#19394)

close tikv#19393

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>
Signed-off-by: rishabh mittal <mittalrishabh@gmail.com>
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 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants