Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txn: add http api to change the unique index lock behaviour #25722

Closed
wants to merge 3 commits into from

Conversation

cfzjywxk
Copy link
Contributor

@cfzjywxk cfzjywxk commented Jun 23, 2021

What problem does this PR solve?

Issue Number:
Related to #25659.

Problem Summary:
Since #21229, all the unique index keys will be locked if they are used in the for update read access path. The for update read with point get on non-clusetered unique index keys may leave many LOCK records which affect the performance a lot.

What is changed and how it works?

What's Changed:
Add a http switch to control the behaviour, it's possible to turn off the change introduced by #21229 by setting the variable to 0.
This is a temporary solution to workaround the performance issue, to solve it it's still needed to optimize the LOCK and ROLLBACK records in the tikv-side. It could be used as a hotfix patch if the users encounter such performance issues.

How it Works:

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Manually test
    With the point/batch point get unique index for update read, check the mvcc record.

Side effects

Release note

  • Add a http switch to control the unique index key lock behaviour for pessimistic transactions.

@cfzjywxk cfzjywxk added the sig/transaction SIG:Transaction label Jun 23, 2021
@cfzjywxk cfzjywxk requested a review from a team as a code owner June 23, 2021 12:13
@cfzjywxk cfzjywxk requested review from lzmhhh123 and removed request for a team June 23, 2021 12:13
@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has not been approved.

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 23, 2021
@github-actions github-actions bot added sig/execution SIG execution sig/sql-infra SIG: SQL Infra labels Jun 23, 2021
@cfzjywxk cfzjywxk requested review from coocood and jackysp June 25, 2021 09:22
Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

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

rest LGTM

writeError(w, errors.New("illegal argument, please use 0 or 1 for this"))
return
}
}
} else {
writeData(w, config.GetGlobalConfig())
Copy link
Contributor

@lysu lysu Jun 25, 2021

Choose a reason for hiding this comment

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

maybe we need a way to get the current configuration value..

for example: someone reports a oncall issue and we want to confirm is it running in false or true status~?

or maybe we can write some log to indicate someone changed it to help to do this

Copy link
Member

Choose a reason for hiding this comment

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

select @@tidb_lock_unique_key won't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logs are added changing the config, it may need more work to track the status infomation in the tidb log file.

Copy link
Member

Choose a reason for hiding this comment

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

I see, tidb_lock_unique_key is not a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jackysp
It's a http api
curl -X POST -d "tidb_lock_unique_key=1" http://127.0.0.1:10080/settings
As it's a temporary solution, better not to add system variables or configurations.

Copy link
Member

Choose a reason for hiding this comment

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

So it is not necessary to update the docs of http api?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not quite sure, as it's temporary solution better not to make it very public. Also it's expected to be optimized or solved in the next release if possible.

if !e.ctx.GetSessionVars().IsPessimisticReadConsistency() {
if !keyExist {
lockIndexKey = true
} else if keyExist && enableLockIdxKey {
Copy link
Member

Choose a reason for hiding this comment

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

in else the keyExist always true.

@@ -751,6 +751,7 @@ var (
ReportIntervalSeconds: atomic.NewInt64(DefTiDBTopSQLReportIntervalSeconds),
}
EnableLocalTxn = atomic.NewBool(DefTiDBEnableLocalTxn)
LockUniqueKeys = atomic.NewBool(true)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jackysp @coocood @youjiali1995 @lysu
Or do we need to change it to false to change the behaviour back with v4.0.9 and earlier versions, but this could affect the users using v5.0 release versions if they rely on the new behaviours.

@lzmhhh123 lzmhhh123 removed their request for review June 28, 2021 06:15
@ti-chi-bot
Copy link
Member

@cfzjywxk: PR needs rebase.

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/test-infra repository.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 16, 2021
@cfzjywxk
Copy link
Contributor Author

#25730 has been merged, close this.

@cfzjywxk cfzjywxk closed this Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. sig/execution SIG execution sig/sql-infra SIG: SQL Infra sig/transaction SIG:Transaction size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants