Skip to content

Commit

Permalink
FB8-104: enabling subsecond lock_wait_timeout (facebook#980) (faceboo…
Browse files Browse the repository at this point in the history
…k#980)

Summary:
For a first review, I only added the code changes to this pull request for two reasons:
* a full test is still running, and I'll have to check the results (I do see a few non output only failures because timeouts, so looks like I missed some nsec-sec conversion in this diff - I'll fix that and update). And checking output changes / rerecording will take time.
* compared to the 5.6 patch, the code change for 8.0 is huge, and affects the service api - reviewing only the code changes is probably a good idea

Jira ticket: https://jira.percona.com/browse/FB8-104

Reference commit: facebook@c21adb7
Reference commit: facebook@25f0f276d13

Currently lock_wait_timeout is an integer type variable which only have
seconds resolution. We would want to extend the variable to double/decimal
type, so it can have milliseconds or microseconds resolution, such as
lock_wait_timeout = 1.23. The integral part should still mean seconds to
keep backward compatibility.

The range of valid values expanded to [ 0 .. 604800 ] to allow timeouts below
1 second; such as lock_wait_timeout = 0.005.  Values that are too small
will effectively mean not waiting for locks.

This update also changes the output of lock_wait_timeout to be decimal;
note the extra .000000 appended to the seconds.

    SELECT global.lock_wait_timeout;
    global.lock_wait_timeout
    604800.000000
Pull Request resolved: facebook#980

Reviewed By: lloyd

Differential Revision: D14349342

Pulled By: lth
  • Loading branch information
dutow authored and inikep committed Aug 2, 2024
1 parent 003ea94 commit 491da4c
Show file tree
Hide file tree
Showing 106 changed files with 891 additions and 759 deletions.
4 changes: 2 additions & 2 deletions components/example/test_backup_lock_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ extern REQUIRES_SERVICE_PLACEHOLDER(mysql_backup_lock);
*/

mysql_service_status_t test_backup_lock_service_init() {
return mysql_service_mysql_backup_lock->acquire(
nullptr, BACKUP_LOCK_SERVICE_DEFAULT, 100);
return mysql_service_mysql_backup_lock->acquire_nsec(
nullptr, BACKUP_LOCK_SERVICE_DEFAULT, 100 * 1000000000ULL);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions include/mysql/components/services/backup_lock_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#define BACKUP_LOCK_SERVICE_H
#include <mysql/components/service.h>
#include <stddef.h>
#include "my_inttypes.h"

/**
Kind of Backup Lock to be acquired. In future we might
Expand Down Expand Up @@ -59,9 +60,9 @@ BEGIN_SERVICE_DEFINITION(mysql_backup_lock)
@retval true Failure
*/

DECLARE_BOOL_METHOD(acquire,
DECLARE_BOOL_METHOD(acquire_nsec,
(MYSQL_THD, enum enum_backup_lock_service_lock_kind,
unsigned long /* lock_timeout*/));
ulonglong /* lock_timeout*/));

/**
Service API to release Backup Lock.
Expand Down
14 changes: 8 additions & 6 deletions include/mysql/service_locking.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class THD;
#define MYSQL_THD void *
#endif

#include "my_inttypes.h"

/**
Types of locking service locks.
LOCKING_SERVICE_READ is compatible with LOCKING_SERVICE_READ.
Expand Down Expand Up @@ -105,22 +107,22 @@ typedef int (*mysql_release_locks_t)(MYSQL_THD opaque_thd,
of metadata will be detected using the MDL deadlock detector.
*/
extern "C" struct mysql_locking_service_st {
mysql_acquire_locks_t mysql_acquire_locks;
mysql_acquire_locks_t mysql_acquire_locks_nsec;
mysql_release_locks_t mysql_release_locks;
} * mysql_locking_service;

#ifdef MYSQL_DYNAMIC_PLUGIN

#define mysql_acquire_locking_service_locks(_THD, _NAMESPACE, _NAMES, _NUM, \
_TYPE, _TIMEOUT) \
mysql_locking_service->mysql_acquire_locks(_THD, _NAMESPACE, _NAMES, _NUM, \
_TYPE, _TIMEOUT)
#define mysql_acquire_locking_service_locks_nsec(_THD, _NAMESPACE, _NAMES, \
_NUM, _TYPE, _TIMEOUT) \
mysql_locking_service->mysql_acquire_locks_nsec(_THD, _NAMESPACE, _NAMES, \
_NUM, _TYPE, _TIMEOUT)
#define mysql_release_locking_service_locks(_THD, _NAMESPACE) \
mysql_locking_service->mysql_release_locks(_THD, _NAMESPACE)

#else

int mysql_acquire_locking_service_locks(
int mysql_acquire_locking_service_locks_nsec(
MYSQL_THD opaque_thd, const char *lock_namespace, const char **lock_names,
size_t lock_num, enum enum_locking_service_lock_type lock_type,
uint64_t lock_timeout);
Expand Down
5 changes: 3 additions & 2 deletions include/mysql/services.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
enum cs_text_or_binary text_or_binary,
void *service_callbacks_ctx);
#include <mysql/service_locking.h>
#include "my_inttypes.h"
enum enum_locking_service_lock_type {
LOCKING_SERVICE_READ,
LOCKING_SERVICE_WRITE
Expand All @@ -224,10 +225,10 @@
typedef int (*mysql_release_locks_t)(void * opaque_thd,
const char *lock_namespace);
extern "C" struct mysql_locking_service_st {
mysql_acquire_locks_t mysql_acquire_locks;
mysql_acquire_locks_t mysql_acquire_locks_nsec;
mysql_release_locks_t mysql_release_locks;
} * mysql_locking_service;
int mysql_acquire_locking_service_locks(
int mysql_acquire_locking_service_locks_nsec(
void * opaque_thd, const char *lock_namespace, const char **lock_names,
size_t lock_num, enum enum_locking_service_lock_type lock_type,
uint64_t lock_timeout);
Expand Down
15 changes: 8 additions & 7 deletions include/thr_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,15 @@ void thr_lock_init(THR_LOCK *lock);
void thr_lock_delete(THR_LOCK *lock);
void thr_lock_data_init(THR_LOCK *lock, THR_LOCK_DATA *data,
void *status_param);
enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data, THR_LOCK_INFO *owner,
enum thr_lock_type lock_type,
ulong lock_wait_timeout);
enum enum_thr_lock_result thr_lock_nsec(THR_LOCK_DATA *data,
THR_LOCK_INFO *owner,
enum thr_lock_type lock_type,
ulonglong lock_wait_timeout_nsec);
void thr_unlock(THR_LOCK_DATA *data);
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data, uint count,
THR_LOCK_INFO *owner,
ulong lock_wait_timeout,
THR_LOCK_DATA **error_pos);
enum enum_thr_lock_result thr_multi_lock_nsec(THR_LOCK_DATA **data, uint count,
THR_LOCK_INFO *owner,
ulonglong lock_wait_timeout_nsec,
THR_LOCK_DATA **error_pos);
void thr_multi_unlock(THR_LOCK_DATA **data, uint count);
void thr_lock_merge_status(THR_LOCK_DATA **data, uint count);
void thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread);
Expand Down
5 changes: 3 additions & 2 deletions mysql-test/r/mysqld--help-notwin.result
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ The following options may be given as the first argument:
--local-infile Enable LOAD DATA LOCAL INFILE
--lock-wait-timeout=#
Timeout in seconds to wait for a lock before returning an
error.
error. The argument will be treated as a decimal value
with nanosecond precision.
--log-bin[=name] Configures the name prefix to use for binary log files.
If the --log-bin option is not supplied, the name prefix
defaults to "binlog". If the --log-bin option is supplied
Expand Down Expand Up @@ -2406,7 +2407,7 @@ large-pages FALSE
lc-messages en_US
lc-time-names en_US
local-infile FALSE
lock-wait-timeout 31536000
lock-wait-timeout 3.1536e+07
log-bin (No default value)
log-bin-index (No default value)
log-bin-trust-function-creators FALSE
Expand Down
6 changes: 3 additions & 3 deletions mysql-test/r/opt_hints_set_var.result
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ UNLOCK TABLES;
DROP TABLE t1;
CALL test_hint("SET_VAR(lock_wait_timeout=1)", "lock_wait_timeout");
VARIABLE_VALUE
31536000
31536000.000000
VARIABLE_VALUE
1
1.000000
VARIABLE_VALUE
31536000
31536000.000000
CREATE TABLE t1(f1 INT);
EXPLAIN SELECT /*+ SET_VAR(max_error_count=0) SET_VAR(optimizer_switch = 'batched_key_acces=off') SET_VAR(range_alloc_block_size=amba)*/ * FROM t1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/clone/r/error_ddl_lock.result
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Variable_name Value
clone_ddl_timeout 1
SHOW VARIABLES LIKE "lock_wait_timeout";
Variable_name Value
lock_wait_timeout 1
lock_wait_timeout 1.000000
# In connection DEFAULT
# 1A. Clone while CREATE TABLE in progress
# In connection CON1
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/clone/r/remote_error_ddl_lock.result
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Variable_name Value
clone_ddl_timeout 1
SHOW VARIABLES LIKE "lock_wait_timeout";
Variable_name Value
lock_wait_timeout 1
lock_wait_timeout 1.000000
# In connection DEFAULT
# 1A. Clone while CREATE TABLE in progress
# In connection CON1
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/parts/r/partition-dml-1-10-innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SET @lock_timeout= @@global.lock_wait_timeout;
SET @@global.lock_wait_timeout= 1;
SELECT @@global.lock_wait_timeout;
@@global.lock_wait_timeout
1
1.000000
SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
SET @@global.innodb_lock_wait_timeout= 1;
# Additional tests for WL#5217 by QA, testplan 1.1
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/parts/r/partition-dml-1-4-innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SET @lock_timeout= @@global.lock_wait_timeout;
SET @@global.lock_wait_timeout= 1;
SELECT @@global.lock_wait_timeout;
@@global.lock_wait_timeout
1
1.000000
SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
SET @@global.innodb_lock_wait_timeout= 1;
SELECT @@global.innodb_lock_wait_timeout;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/parts/r/partition-dml-1-5-innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SET @lock_timeout= @@global.lock_wait_timeout;
SET @@global.lock_wait_timeout= 1;
SELECT @@global.lock_wait_timeout;
@@global.lock_wait_timeout
1
1.000000
SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
SET @@global.innodb_lock_wait_timeout= 1;
SELECT @@global.innodb_lock_wait_timeout;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/parts/r/partition-dml-1-6-innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SET @lock_timeout= @@global.lock_wait_timeout;
SET @@global.lock_wait_timeout= 1;
SELECT @@global.lock_wait_timeout;
@@global.lock_wait_timeout
1
1.000000
SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
SET @@global.innodb_lock_wait_timeout= 1;
SELECT @@global.innodb_lock_wait_timeout;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/parts/r/partition-dml-1-7-innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SET @lock_timeout= @@global.lock_wait_timeout;
SET @@global.lock_wait_timeout= 1;
SELECT @@global.lock_wait_timeout;
@@global.lock_wait_timeout
1
1.000000
SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
SET @@global.innodb_lock_wait_timeout= 1;
# Additional tests for WL#5217 by QA, testplan 1.1
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/parts/r/partition-dml-1-8-innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SET @lock_timeout= @@global.lock_wait_timeout;
SET @@global.lock_wait_timeout= 1;
SELECT @@global.lock_wait_timeout;
@@global.lock_wait_timeout
1
1.000000
SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
SET @@global.innodb_lock_wait_timeout= 1;
# Additional tests for WL#5217 by QA, testplan 1.1
Expand Down
Loading

0 comments on commit 491da4c

Please sign in to comment.