GET_LOCK()

Overview

Attempt to create a user-level lock and return the success status as a boolean.

USAGE

GET_LOCK(lock_name, timeout)

Argument Name

Description

lock_name

Required. The string argument that identifies a lock to acquire

timeout

Required. The timeout in seconds for which the named lock is tried to be acquired

DETAILS

GET_LOCK() is a locking function that acquires the named user-level lock and returns a boolean (1 or 0) to indicate success or failure.

The lock names are determined by the user, and can be used in any desired programming logic.

The lock only remains locked as long as the calling user's session remains connected to the database. It can also be released using RELEASE_LOCK().

If the calling user already holds a user level lock, calling GET_LOCK() again succeeds.

If anyone else is holding the lock, the function waits for the given number of seconds for the lock to become available and returns 0 if time ran out before acquiring the lock.

Other related locking functions include IS_FREE_LOCK(), RELEASE_LOCK(), and IS_USED_LOCK().

An error is generated if the argument is NULL.

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

Simple Locking Idiom

An example use of GET_LOCK() is to implement an agreed upon restriction, such as serializing the use of several related tables using a single lock name.

Let user1 acquire the user lock contacts_lck with the GET_LOCK() function:

SELECT GET_LOCK("contacts_lck", 10);
+------------------------------+
| GET_LOCK("contacts_lck", 10) |
+------------------------------+
|                            1 |
+------------------------------+

After user1 has acquired the contacts_lck user level lock, if user2 tries to acquire the contacts_lck lock it is not able to acquire the contacts_lck lock:

SELECT GET_LOCK("contacts_lck", 10);
+------------------------------+
| GET_LOCK("contacts_lck", 10) |
+------------------------------+
|                            0 |
+------------------------------+
ERROR 1 (HY000): [24576] Unknown prepared param type: "t_null"

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.09

  • Present starting in MariaDB Xpand 23.09.1.

6.1

  • Present starting in MariaDB Xpand 6.1.0.

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.1

  • Present starting in MariaDB Xpand 6.1.0.

EXTERNAL REFERENCES