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

RFC: Locking functions #6367

Closed
systay opened this issue Jun 24, 2020 · 1 comment · Fixed by #6370
Closed

RFC: Locking functions #6367

systay opened this issue Jun 24, 2020 · 1 comment · Fixed by #6370
Labels
Milestone

Comments

@systay
Copy link
Collaborator

systay commented Jun 24, 2020

Locking Functions

Supporting the advisory locking functions in MySQL is important, given that they are used by common applications and frameworks.

Functions covered

  • GET_LOCK()
  • IS_FREE_LOCK()
  • IS_USED_LOCK()
  • RELEASE_ALL_LOCKS()
  • RELEASE_LOCK()

Restrictions

Vitess will initially only support locking functions with these limitations:

  • Can only be used in SELECT queries
  • The queries can either have only the table dual, or have no FROM clause.

Functionality

Locking function evaluation will have a simple and consistent routing scheme, making sure all requests happen at the same target. This way, locks will be executed on the same mysqld.
The locking function evaluation always be routed to the first shard in the first keyspace known to the VTGate, sorted alphabetically.

Using any of the locking functions will force the session to use a reserved connection - a dedicated connection to mysqld for that session, so that get_lock()/release_lock() happen on the same connection, and so that COM_QUIT releases any lingering locks.

Examples of valid queries

SELECT GET_LOCK('lock1',10);
SELECT RELEASE_LOCK('lock1');
SELECT GET_LOCK('lock1',10), GET_LOCK('lock2',10);
SELECT RELEASE_ALL_LOCKS()
SELECT GET_LOCK(@customVariable, 10);

Examples of queries not supported in the first implementation

SELECT GET_LOCK(user_name,10) FROM users;
INSERT INTO T (id) VALUES (GET_LOCK('lock2',10));
DO GET_LOCK('lock1',10);
@shlomi-noach
Copy link
Contributor

  • Can only be used in SELECT queries
  • The queries can either have only the table dual, or have no FROM clause.

I think these are reasonable restrictions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants