Purpose
This function checks whether a lock named by the string str is free, that is, whether it is held by another session.
Syntax
IS_FREE_LOCK('str')
Description
Parameters
str: The name of the lock to be checked, in string format.
Return value
Return 1: The lock is free, meaning no session holds it.
Return 0: The lock is held by a session, meaning it is not free.
Examples
Check whether the lock named my_lock is available.
obclient [(none)]> SELECT IS_FREE_LOCK('my_lock');
The return result is as follows:
+-------------------------+
| IS_FREE_LOCK('my_lock') |
+-------------------------+
| 0 |
+-------------------------+
1 row in set
A return value of 0 indicates that the lock my_lock is already held by a session. You can execute IS_USED_LOCK() to query the connection identifier (session ID) of the session holding this lock, as shown in the following example:
obclient [(none)]> SELECT IS_USED_LOCK('my_lock');
The return result is as follows:
+-------------------------+
| IS_USED_LOCK('my_lock') |
+-------------------------+
| 3221487701 |
+-------------------------+
1 row in set