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

WIP: Proof of concept support for GET_LOCK #33361

Closed
wants to merge 6 commits into from
Closed

Conversation

morgo
Copy link
Contributor

@morgo morgo commented Mar 23, 2022

What problem does this PR solve?

Issue Number: ref #14994

Problem Summary:

This is a draft implementation for GET_LOCK / RELEASE_LOCK / RELEASE_ALL_LOCKS. It doesn't handle all corner cases yet, like deadlocks.

What is changed and how it works?

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

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@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 release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 23, 2022
@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 23, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Mar 24, 2022

@morgo
Copy link
Contributor Author

morgo commented Mar 24, 2022

/run-unit-test

@bb7133
Copy link
Member

bb7133 commented Mar 24, 2022

This implementation is great!

@morgo morgo mentioned this pull request Mar 24, 2022
12 tasks
@yahonda
Copy link
Member

yahonda commented Mar 25, 2022

Thanks for the great work. I have found an implementation differences between this pull request and MySQL. Lock names in TiDB is case-sensitive, while MySQL one is case insensitive.

Here are steps to reproduce.

TiDB

  1. Build TiDB Server and validate the TiDB commit hash is 7bdc76b2c186b53eb2e5aa3938141b9c1cca5a05
git clone https://github.com/pingcap/tidb
cd tidb
gh pr checkout 33361
make server
./bin/tidb-server
mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v6.1.0-alpha-31-g7bdc76b2c-dirty
Edition: Community
Git Commit Hash: 7bdc76b2c186b53eb2e5aa3938141b9c1cca5a05
Git Branch: get-lock
UTC Build Time: 2022-03-25 02:57:19
GoVersion: go1.16
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

mysql>
  1. Open a new session and get an advisory lock called 'foo' all lowercase.
mysql --comments --host 127.0.0.1 --port 4000 -u root
mysql> select get_lock('foo', -1);
+---------------------+
| get_lock('foo', -1) |
+---------------------+
|                   1 |
+---------------------+
1 row in set (0.00 sec)

mysql>
  1. Open another new session and get another lock called 'FOO' all uppercase
mysql --comments --host 127.0.0.1 --port 4000 -u root
mysql>  select get_lock('FOO', -1);
+---------------------+
| get_lock('FOO', -1) |
+---------------------+
|                   1 |
+---------------------+
1 row in set (0.00 sec)

mysql>

Advisory lock 'foo' and 'FOO' are handled separately.

MySQL

Tested with the same scenario with MySQL, the lock name looks case insensitive.

  1. Start MySQL Server
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.28    |
+-----------+
1 row in set (0.00 sec)
  1. Open a new session get an advisory lock called 'foo' all lowercase.
mysql> select get_lock('foo', -1);
+---------------------+
| get_lock('foo', -1) |
+---------------------+
|                   1 |
+---------------------+
1 row in set (0.00 sec)

mysql>
  1. Open another session and get another lock called 'FOO' all uppercase
mysql> select get_lock('FOO', -1);

It waits the lock released named 'foo', it looks like MySQL lock names are case insensitive.

@morgo
Copy link
Contributor Author

morgo commented Mar 25, 2022

Lock names in TiDB is case-sensitive, while MySQL one is case insensitive.

I have fixed this. PTAL again :-)

@yahonda
Copy link
Member

yahonda commented Mar 28, 2022

Validated that the advisory lock name is case insensitive. Thanks for the fix.

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v6.1.0-alpha-32-g3ac96c310-dirty
Edition: Community
Git Commit Hash: 3ac96c310bddd3973fdf000e6f76228e01556747
Git Branch: get-lock
UTC Build Time: 2022-03-28 01:49:17
GoVersion: go1.16
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

mysql>

@bb7133
Copy link
Member

bb7133 commented Mar 29, 2022

This draft implementation LGTM.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 29, 2022
@ti-chi-bot
Copy link
Member

@morgo: 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.

@morgo
Copy link
Contributor Author

morgo commented Mar 31, 2022

I am going to close this draft for now. I opened it to prove that it is possible to get this working using pessimistic locks :-) I will clean it up and merge after the proposal has been approved.

@morgo morgo closed this Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. 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.

5 participants