From 1b84a3a02356933e1f17690275099e94ee046b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 7 Aug 2023 08:52:22 +0200 Subject: [PATCH 1/5] Update docs for newly added locking functions --- functions-and-operators/locking-functions.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/functions-and-operators/locking-functions.md b/functions-and-operators/locking-functions.md index 549e14bf8765d..7985954622370 100644 --- a/functions-and-operators/locking-functions.md +++ b/functions-and-operators/locking-functions.md @@ -12,16 +12,15 @@ TiDB supports most of the user-level [locking functions](https://dev.mysql.com/d | Name | Description | |:---------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------| | [`GET_LOCK(lockName, timeout)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_get-lock) | Acquires an advisory lock. The `lockName` parameter must be NO longer than 64 characters. Waits maximum `timeout` seconds before timing out and returns a failure. | -| [`RELEASE_LOCK(lockName)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_release-lock) | Releases a previously acquired lock. The `lockName` parameter must be NO longer than 64 characters. | +| [`IS_FREE_LOCK()`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_is-free-lock) | Tests if a lock is free. | +| [`IS_USED_LOCK()`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_is-used-lock) | Tests if a lock is used. Returns connection id if true. | | [`RELEASE_ALL_LOCKS()`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_release-all-locks) | Releases all locks held by the current session. | +| [`RELEASE_LOCK(lockName)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_release-lock) | Releases a previously acquired lock. The `lockName` parameter must be NO longer than 64 characters. | + + ## MySQL compatibility * The minimum timeout permitted by TiDB is 1 second, and the maximum timeout is 1 hour (3600 seconds). This differs from MySQL, where both 0 second and unlimited timeouts (`timeout=-1`) are permitted. TiDB will automatically convert out-of-range values to the nearest permitted value and convert `timeout=-1` to 3600 seconds. * TiDB does not automatically detect deadlocks caused by user-level locks. Deadlocked sessions will timeout after a maximum of 1 hour, but can also be manually resolved by using `KILL` on one of the affected sessions. You can also prevent deadlocks by always acquiring user-level locks in the same order. * Locks take effect on all TiDB servers in the cluster. This differs from MySQL Cluster and Group Replication where locks are local to a single server. - -## Unsupported functions - -* `IS_FREE_LOCK()` -* `IS_USED_LOCK()` From cad30eed429f05d88a47b23123fd7c8764f00442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 7 Aug 2023 10:19:16 +0200 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: Aolin --- functions-and-operators/locking-functions.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/functions-and-operators/locking-functions.md b/functions-and-operators/locking-functions.md index 7985954622370..86ae3223110ae 100644 --- a/functions-and-operators/locking-functions.md +++ b/functions-and-operators/locking-functions.md @@ -12,13 +12,11 @@ TiDB supports most of the user-level [locking functions](https://dev.mysql.com/d | Name | Description | |:---------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------| | [`GET_LOCK(lockName, timeout)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_get-lock) | Acquires an advisory lock. The `lockName` parameter must be NO longer than 64 characters. Waits maximum `timeout` seconds before timing out and returns a failure. | -| [`IS_FREE_LOCK()`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_is-free-lock) | Tests if a lock is free. | -| [`IS_USED_LOCK()`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_is-used-lock) | Tests if a lock is used. Returns connection id if true. | +| [`IS_FREE_LOCK(lockName)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_is-free-lock) | Checks if a lock is free. | +| [`IS_USED_LOCK(lockName)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_is-used-lock) | Checks if a lock is in use. If true, it returns the corresponding connection ID. | | [`RELEASE_ALL_LOCKS()`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_release-all-locks) | Releases all locks held by the current session. | | [`RELEASE_LOCK(lockName)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_release-lock) | Releases a previously acquired lock. The `lockName` parameter must be NO longer than 64 characters. | - - ## MySQL compatibility * The minimum timeout permitted by TiDB is 1 second, and the maximum timeout is 1 hour (3600 seconds). This differs from MySQL, where both 0 second and unlimited timeouts (`timeout=-1`) are permitted. TiDB will automatically convert out-of-range values to the nearest permitted value and convert `timeout=-1` to 3600 seconds. From 69fbc4aaeef68dda9da71401038387534a9f720e Mon Sep 17 00:00:00 2001 From: Aolin Date: Mon, 7 Aug 2023 16:56:37 +0800 Subject: [PATCH 3/5] fix format --- functions-and-operators/locking-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/locking-functions.md b/functions-and-operators/locking-functions.md index 86ae3223110ae..991c202608e8b 100644 --- a/functions-and-operators/locking-functions.md +++ b/functions-and-operators/locking-functions.md @@ -13,7 +13,7 @@ TiDB supports most of the user-level [locking functions](https://dev.mysql.com/d |:---------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------| | [`GET_LOCK(lockName, timeout)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_get-lock) | Acquires an advisory lock. The `lockName` parameter must be NO longer than 64 characters. Waits maximum `timeout` seconds before timing out and returns a failure. | | [`IS_FREE_LOCK(lockName)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_is-free-lock) | Checks if a lock is free. | -| [`IS_USED_LOCK(lockName)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_is-used-lock) | Checks if a lock is in use. If true, it returns the corresponding connection ID. | +| [`IS_USED_LOCK(lockName)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_is-used-lock) | Checks if a lock is in use. If true, it returns the corresponding connection ID. | | [`RELEASE_ALL_LOCKS()`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_release-all-locks) | Releases all locks held by the current session. | | [`RELEASE_LOCK(lockName)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_release-lock) | Releases a previously acquired lock. The `lockName` parameter must be NO longer than 64 characters. | From 8b06a88a28adb9463829afa1029249e3ba028e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 7 Aug 2023 13:35:28 +0200 Subject: [PATCH 4/5] Add note about compatibility --- functions-and-operators/locking-functions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/functions-and-operators/locking-functions.md b/functions-and-operators/locking-functions.md index 991c202608e8b..429838fc3ee98 100644 --- a/functions-and-operators/locking-functions.md +++ b/functions-and-operators/locking-functions.md @@ -22,3 +22,4 @@ TiDB supports most of the user-level [locking functions](https://dev.mysql.com/d * The minimum timeout permitted by TiDB is 1 second, and the maximum timeout is 1 hour (3600 seconds). This differs from MySQL, where both 0 second and unlimited timeouts (`timeout=-1`) are permitted. TiDB will automatically convert out-of-range values to the nearest permitted value and convert `timeout=-1` to 3600 seconds. * TiDB does not automatically detect deadlocks caused by user-level locks. Deadlocked sessions will timeout after a maximum of 1 hour, but can also be manually resolved by using `KILL` on one of the affected sessions. You can also prevent deadlocks by always acquiring user-level locks in the same order. * Locks take effect on all TiDB servers in the cluster. This differs from MySQL Cluster and Group Replication where locks are local to a single server. +* `IS_USED_LOCK()` returns `1` if it is called from another session and is unable to return process ID of the process that is holding the lock. From 21a370a3cc9008405fc8c32e2a62ab26f0e2aaf8 Mon Sep 17 00:00:00 2001 From: Aolin Date: Tue, 8 Aug 2023 11:43:03 +0800 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: xixirangrang --- functions-and-operators/locking-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/locking-functions.md b/functions-and-operators/locking-functions.md index 429838fc3ee98..1567b9fce7953 100644 --- a/functions-and-operators/locking-functions.md +++ b/functions-and-operators/locking-functions.md @@ -22,4 +22,4 @@ TiDB supports most of the user-level [locking functions](https://dev.mysql.com/d * The minimum timeout permitted by TiDB is 1 second, and the maximum timeout is 1 hour (3600 seconds). This differs from MySQL, where both 0 second and unlimited timeouts (`timeout=-1`) are permitted. TiDB will automatically convert out-of-range values to the nearest permitted value and convert `timeout=-1` to 3600 seconds. * TiDB does not automatically detect deadlocks caused by user-level locks. Deadlocked sessions will timeout after a maximum of 1 hour, but can also be manually resolved by using `KILL` on one of the affected sessions. You can also prevent deadlocks by always acquiring user-level locks in the same order. * Locks take effect on all TiDB servers in the cluster. This differs from MySQL Cluster and Group Replication where locks are local to a single server. -* `IS_USED_LOCK()` returns `1` if it is called from another session and is unable to return process ID of the process that is holding the lock. +* `IS_USED_LOCK()` returns `1` if it is called from another session and is unable to return the ID of the process that is holding the lock.