-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: Add support for GET_LOCK() / RELEASE_LOCK() / RELEASE_ALL_LOCKS() #33947
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
/run-unit-test |
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/08d449ecf38f4bc7e660cbc95c0ca79f1654e6e6 |
add similar validation for release_lock lockname as get_lock
Let me confirm if my understanding is correct that based on this implementation, the maximum value of advisory lock timeout only depends on |
It looks like the get_lock timeout is limited by 1 hour.
mysql> select get_lock('foo', 3800);
+-----------------------+
| get_lock('foo', 3800) |
+-----------------------+
| 1 |
+-----------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select get_lock('FOO', -1);
+---------------------+
| get_lock('FOO', -1) |
+---------------------+
| 0 |
+---------------------+
1 row in set, 1 warning (1 hour 0.01 sec)
mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1292 | Truncated incorrect get_lock value: '%!s(int64=-00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001)' |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
|
The maximum for For this: mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1292 | Truncated incorrect get_lock value: '%!s(int64=-00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001)' |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec) I'll fix the message. But the warning is intentional - it's not a MySQL behavior, but since we can't do unlimited I thought this was important. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a TiDB server with advisory locks (or any pessimistic transaction) dies (kill -9 for example) how are those locks handled? I did not find any documentation on this...
Mostly questions and still looks good to me, so approved, feel free to consider my suggestions.
tk.MustQuery("SELECT get_lock('mygloballock', 0)").Check(testkit.Rows("0")) // someone else has the lock | ||
tk.MustQuery("SELECT release_lock('mygloballock')").Check(testkit.Rows("0")) // never had the lock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could not this be used for implementing IS_FREE_LOCK()?
I.e. first check if the session already have the lock, if not do a get_lock with 0 timeout and if we got the lock immediately release it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I guess that's possible.
But it's not the most elegant. If I learn the transaction code, I assume I could implement this correctly by checking in TiKV if the lock is held. So I will try and keep out of scope for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this a little more. I think you are right: some implementation is better than no implementation. We know IS_FREE_LOCK()
is used in the rails test suite (but not in rails itself).
I will plan to add it for this sprint, but in a separate PR as this one is already getting large.
For clean shutdown and kill, I've verified it works. For unsafe shutdown it could take up to the 1hr timeout to clear, I'm not sure if there are mechanisms in place which could shorten it. |
@mjonss thanks for the review. PTAL again :-) |
Understood the limitation and show warning is helpful when users specified lock timeout value longer than 1 hour. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 3f7646accea4fc737634eea39c47094a1b982206
|
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 1911dcf
|
TiDB MergeCI notify
|
What problem does this PR solve?
Issue Number: close #14994
Problem Summary:
This supports the
GET_LOCK()
/RELEASE_LOCK()
/RELEASE_ALL_LOCKS()
functions previously proposed in the design document @ #33406What is changed and how it works?
Functions
GET_LOCK
,RELEASE_LOCK
,RELEASE_ALL_LOCKS
are no longer noops. The functionality is now implemented.Check List
Tests
Deployed 2x tidb, 1x tidb/pd. Confirmed functionality works correctly.
Side effects
Documentation
Changes the behavior of
tidb_enable_noop_funcs
, so documentation needs updating.Release note
Please refer to Release Notes Language Style Guide to write a quality release note.