*: implement shared lock for foreign key#65752
*: implement shared lock for foreign key#65752ti-chi-bot[bot] merged 18 commits intopingcap:masterfrom
Conversation
|
Hi @you06. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with 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. |
There was a problem hiding this comment.
Pull request overview
This PR introduces shared-lock support for foreign key checks in TiDB and wires basic observability for shared locks.
Changes:
- Add a new session/global system variable
tidb_foreign_key_check_in_shared_lockand associated session fields to control whether foreign key checks use shared locks. - Extend the pessimistic DML locking path and foreign key checker to distinguish between exclusive and shared “unchanged” keys, defer FK locks into
handlePessimisticDML, and propagate a newInShareModeflag down to the TiKV lock RPCs and coprocessor lock resolution. - Add shared-lock-related execution details and metrics (
SharedLockKeysDetail,StatementSharedLockKeysCount) and expose them via Prometheus and a new Grafana panel, plus basic integration into runtime stats.
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/util/execdetails/runtime_stats.go |
Adds SharedLockKeys to RuntimeStatsWithCommit so commit/runtime stats can carry shared-lock execution details. |
pkg/util/execdetails/execdetails.go |
Extends ExecDetails/SyncExecDetails with SharedLockKeysDetail, LockKeysDuration, and a MergeSharedLockKeysExecDetails helper. |
pkg/store/copr/coprocessor.go |
Updates coprocessor lock error handling to resolve either a single lock or a set of shared locks via LockInfo.GetSharedLockInfos(). |
pkg/sessionctx/variable/sysvar.go |
Registers the new tidb_foreign_key_check_in_shared_lock sysvar and plumbs it into SessionVars. |
pkg/sessionctx/variable/session.go |
Changes TxnCtxNoNeedToRestore.unchangedKeys to map[string]bool and adds helpers to record and split unchanged keys into exclusive vs shared lock sets; adds ForeignKeyCheckInSharedLock to SessionVars. |
pkg/sessionctx/vardef/tidb_vars.go |
Defines the name and default (false) for TiDBForeignKeyCheckInSharedLock. |
pkg/sessionctx/stmtctx/stmtctx.go |
Extends StatementContext with counters/durations for pessimistic locking, including SharedLockKeysCount. |
pkg/metrics/session.go |
Introduces the StatementSharedLockKeysCount histogram for counting keys locked in shared mode per statement. |
pkg/metrics/metrics.go |
Registers the new StatementSharedLockKeysCount Prometheus metric. |
pkg/metrics/grafana/tidb.json |
Adds a Grafana heatmap panel that visualizes the distribution of statement_shared_lock_keys_count. |
pkg/executor/write.go |
Updates unchanged-key tracking for row/unique keys to mark them as exclusive (shared=false) in the new AddUnchangedKeyForLock API. |
pkg/executor/select.go |
Extends newLockCtx to accept an inSharedMode flag and propagate it to LockCtx.InShareMode; adjusts callers accordingly. |
pkg/executor/point_get.go |
Adapts point get pessimistic locking to the new newLockCtx(..., inSharedMode bool) signature (currently always false). |
pkg/executor/insert_common.go |
Marks duplicate-key unchanged locks as exclusive via the new AddUnchangedKeyForLock(key, false) signature. |
pkg/executor/foreign_key.go |
Changes FK check locking: for pessimistic txns, collects keys into TxnCtx.unchangedKeys as shared; for optimistic txns, continues to lock immediately using newLockCtx(..., false). |
pkg/executor/batch_point_get.go |
Updates batch point get pessimistic locking to the new newLockCtx signature. |
pkg/executor/adapter.go |
Refactors handlePessimisticDML to reset and then split unchanged keys into exclusive vs shared passes, honoring ForeignKeyCheckInSharedLock; records shared-lock metrics and attaches SharedLockKeys exec details into runtime stats. |
go.mod |
Bumps github.com/tikv/pd/client version, promotes some AliCloud dependencies to direct, and adds a replace to use github.com/you06/client-go/v2 for github.com/tikv/client-go/v2. |
go.sum |
Synchronizes module checksums with the updated go.mod (including the new client-go fork and pd client version). |
a77818d to
4ca8a65
Compare
|
/retest |
|
@you06: PRs from untrusted users cannot be marked as trusted with DetailsIn 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. |
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
dca7e8a to
520e7ce
Compare
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
|
/retest |
1 similar comment
|
/retest |
Signed-off-by: you06 <you1474600@gmail.com>
|
/retest |
2 similar comments
|
/retest |
|
/retest |
Signed-off-by: you06 <you1474600@gmail.com>
|
/retest |
Signed-off-by: you06 <you1474600@gmail.com>
|
/retest |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cfzjywxk, yudongusa, YuJuncen, zimulala, zyguan 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 |
|
/retest |
1 similar comment
|
/retest |
What problem does this PR solve?
Issue Number: close #66154
ref tikv/tikv#19087
Problem Summary:
What changed and how does it work?
Add shared lock support in TiDB.
tidb_foreign_key_check_in_shared_lockas the feature switch, default off.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.