Skip to content

Commit

Permalink
FB8-104: enabling subsecond lock_wait_timeout
Browse files Browse the repository at this point in the history
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

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
GitHub Author: Zsolt Parragi <zsolt.parragi@percona.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.

Reviewers: abhinavsharma, mung

Reviewed By: mung

Subscribers: butterflybot, vinaybhat, webscalesql-eng@fb.com

Differential Revision: https://phabricator.intern.facebook.com/D14349342

Signature: 14349342:1553906565:8be92e1706427e00eabc88bc2366ba87f449e05e
  • Loading branch information
facebook-github-bot authored and Herman Lee committed Nov 18, 2019
1 parent 4e9dfec commit f740c16
Show file tree
Hide file tree
Showing 95 changed files with 788 additions and 670 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 @@ -38,8 +38,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
42 changes: 21 additions & 21 deletions components/mysql_server/mysql_backup_lock.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

#ifndef MYSQL_BACKUP_LOCK_INCLUDED
#define MYSQL_BACKUP_LOCK_INCLUDED
Expand All @@ -39,10 +39,10 @@
@retval true Failure
*/

DEFINE_BOOL_METHOD(mysql_acquire_backup_lock,
DEFINE_BOOL_METHOD(mysql_acquire_backup_lock_nsec,
(MYSQL_THD opaque_thd,
enum enum_backup_lock_service_lock_kind lock_kind,
unsigned long lock_timeout));
ulonglong lock_timeout));

/**
Service API to release Backup Lock.
Expand Down
2 changes: 1 addition & 1 deletion components/mysql_server/server_component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ BEGIN_SERVICE_IMPLEMENTATION(mysql_server, system_variable_source)
mysql_system_variable_source_imp::get END_SERVICE_IMPLEMENTATION();

BEGIN_SERVICE_IMPLEMENTATION(mysql_server, mysql_backup_lock)
mysql_acquire_backup_lock,
mysql_acquire_backup_lock_nsec,
mysql_release_backup_lock END_SERVICE_IMPLEMENTATION();

BEGIN_SERVICE_IMPLEMENTATION(mysql_server, clone_protocol)
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 @@ -42,6 +42,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 @@ -92,7 +94,7 @@ extern "C" struct mysql_locking_service_st {
@sa acquire_locking_service_locks, MDL_context::acquire_locks
*/
mysql_acquire_locks_t mysql_acquire_locks;
mysql_acquire_locks_t mysql_acquire_locks_nsec;
/**
Release all lock service locks taken by the given connection
in the given namespace.
Expand All @@ -110,16 +112,16 @@ extern "C" struct mysql_locking_service_st {

#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 @@ -221,6 +221,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 @@ -232,10 +233,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 @@ -483,7 +483,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 @@ -1591,7 +1592,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 @@ -309,11 +309,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/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 f740c16

Please sign in to comment.