tikvrpc: clear ReplicaRead when falling back to leader read after meeting a lock - #2097
Conversation
…ting a lock DisableStaleReadMeetLock switches a request to leader read after it meets a lock, but it leaves ReplicaRead untouched. TiDB's coprocessor calls it for every lock fallback (meetLockFallback), and the retry request is built with NewReplicaReadRequest, so for prefer-leader/follower/mixed reads it has ReplicaRead=true. The leader selector never resets the flag when it picks the leader, so the leader receives a replica read request. TiKV v8.5 drops the in-memory engine snapshot for any replica read request, so these lock retries scan RocksDB on the leader even when the region is cached. Clear ReplicaRead together with StaleRead. If the leader selector later falls back to a follower, it sets ReplicaRead=true itself. ref pingcap/tidb#71705 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Sanket Kedia <sanket.kedia@airbnb.com>
|
Hi @sanketkedia. Thanks for your PR. I'm waiting for a tikv member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
|
Welcome @sanketkedia! |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthroughWhen a key is locked, ChangesLock-triggered leader-read fallback
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to Lock-retry requests will now be sent as plain leader reads instead of carrying a leftover replica-read flag. That should avoid the extra latency reported on TiKV v8.5. No merge-blocking risk was identified. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The correction aligns lock retries with their existing leader-read intent. No introduced access-control bypass or privilege increase was identified. Later recovery behavior, concurrent request reuse, and server-side handling remain only partially verified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Connor1996, LykxSassinator The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
ref pingcap/tidb#71705
What problem does this PR solve?
DisableStaleReadMeetLock()switches a request to leader read after it meets a lock, but leavesReplicaReaduntouched.TiDB's coprocessor calls it for every lock fallback (
meetLockFallback), not only for stale reads, and the retry request hasReplicaRead = true.nextForReplicaReadLeadernever resets the flag when it picks the leader, so the leader receivesreplica_read = true.TiKV v8.5 drops the In-Memory Engine snapshot for any request with
replica_readset. Every lock retry therefore scans RocksDB on the leader even when the region is cached in IME. More details in pingcap/tidb#71705.What is changed and how does it work?
Clear
ReplicaReadtogether withStaleReadinDisableStaleReadMeetLock(), matchingEnableStaleWithMixedReplicaRead(), which already sets it explicitly.This is safe for leader mode: if the selector later falls back to a follower (busy leader, or a leader deadline error),
nextForReplicaReadLeadersetsReplicaRead = trueitself.Tests
TestLockFallbackLeaderReadClearsReplicaReadbuilds requests infollower,mixed,prefer-leader,learnerand stale-read modes, callsDisableStaleReadMeetLock(), and asserts the selector picks the leader withReplicaRead = falseandStaleRead = false. It fails without this change.go test ./internal/locate/ ./tikvrpc/ ./txnkv/txnsnapshot/passes.🤖 Generated with Claude Code