Skip to content

Fix dangling TxnStatus pointer in LockResolver - #247

Merged
ti-chi-bot[bot] merged 2 commits into
tikv:masterfrom
gengliqi:fix-txn-status-get
Jul 21, 2026
Merged

Fix dangling TxnStatus pointer in LockResolver#247
ti-chi-bot[bot] merged 2 commits into
tikv:masterfrom
gengliqi:fix-txn-status-get

Conversation

@gengliqi

@gengliqi gengliqi commented Jul 21, 2026

Copy link
Copy Markdown
Member

fix #246
Return a copy of the cached TxnStatus to keep it valid after concurrent cache eviction.

Summary by CodeRabbit

  • Refactor
    • Updated lock-resolution cache retrieval to use an “absence vs. present” return pattern, improving reliability when cached transaction information is missing.
    • Ensured cached statuses are returned consistently without relying on null pointer checks.
  • Bug Fixes
    • Fixed transaction lock-status handling to better reflect resolved-state availability, reducing the risk of incorrect or stale status reads.

Signed-off-by: gengliqi <gengliqiii@gmail.com>
@ti-chi-bot ti-chi-bot Bot added dco-signoff: yes Indicates the PR's author has signed the dco. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fa729238-f543-480e-b85f-e38f51128c4d

📥 Commits

Reviewing files that changed from the base of the PR and between dc5fe53 and 662f740.

📒 Files selected for processing (2)
  • include/pingcap/kv/LockResolver.h
  • src/kv/LockResolver.cc
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/kv/LockResolver.cc

📝 Walkthrough

Walkthrough

LockResolver now returns cached transaction statuses by value through std::optional, and getTxnStatus checks for an available cached value before returning it.

Changes

Lock status cache

Layer / File(s) Summary
Optional cached status lookup
include/pingcap/kv/LockResolver.h, src/kv/LockResolver.cc
getResolved returns std::nullopt or a copied TxnStatus, and getTxnStatus handles the optional result.

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

Suggested reviewers: windtalker

🚥 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 matches the main change: fixing a dangling TxnStatus pointer in LockResolver.
Linked Issues check ✅ Passed The change returns a copy of the cached TxnStatus, which prevents a dangling pointer when the cache is evicted concurrently.
Out of Scope Changes check ✅ Passed The PR stays focused on the LockResolver cache lookup and its call site, with no clear unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jul 21, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

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

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 Jul 21, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-21 10:15:29.938842417 +0000 UTC m=+1313515.974937474: ☑️ agreed by ekexium.
  • 2026-07-21 10:46:43.689627016 +0000 UTC m=+1315389.725722072: ☑️ agreed by overvenus.

@gengliqi

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ti-chi-bot
ti-chi-bot Bot merged commit 78a557e into tikv:master Jul 21, 2026
5 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/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LockResolver may access a dangling TxnStatus pointer

3 participants