summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Lesin <vlad_lesin@mail.ru>2020-04-27 21:46:05 +0300
committerVlad Lesin <vlad_lesin@mail.ru>2020-04-27 22:29:24 +0300
commit3e4f8f19ac610bde7e2c6fed31ce1e39615543f5 (patch)
tree82e5d1d97dcdba036d909c660a291a856cd5bf6f
parentb63446984c2c8441c19fc646f6652a9bc3076304 (diff)
downloadmariadb-git-bb-10.4-MDEV-20230-ftwrl-wait-timeout.tar.gz
MDEV-20230: mariabackup --ftwrl-wait-timeout never times out on explicitbb-10.4-MDEV-20230-ftwrl-wait-timeout
lock --ftwrl-wait-timeout does not finish mariabackup execution when acquired backup lock can't be grabbed for the certain amount of time, it just waits for a long queries finishing before acquiring the lock to avoid unnecessary locking. This commit extends --ftwrl-wait-timeout so, that mariabackup execution is finished if it waits for backup lock during certain amount of time.
-rw-r--r--extra/mariabackup/backup_mysql.cc88
-rw-r--r--mysql-test/suite/mariabackup/backup_lock_wait_timeout.result11
-rw-r--r--mysql-test/suite/mariabackup/backup_lock_wait_timeout.test28
3 files changed, 89 insertions, 38 deletions
diff --git a/extra/mariabackup/backup_mysql.cc b/extra/mariabackup/backup_mysql.cc
index 0e51068c372..e008b2352a7 100644
--- a/extra/mariabackup/backup_mysql.cc
+++ b/extra/mariabackup/backup_mysql.cc
@@ -884,54 +884,66 @@ Function acquires either a backup tables lock, if supported
by the server, or a global read lock (FLUSH TABLES WITH READ LOCK)
otherwise.
@returns true if lock acquired */
-bool
-lock_tables(MYSQL *connection)
+bool lock_tables(MYSQL *connection)
{
- if (have_lock_wait_timeout) {
- /* Set the maximum supported session value for
- lock_wait_timeout to prevent unnecessary timeouts when the
- global value is changed from the default */
- xb_mysql_query(connection,
- "SET SESSION lock_wait_timeout=31536000", false);
- }
-
- if (have_backup_locks) {
- msg("Executing LOCK TABLES FOR BACKUP...");
- xb_mysql_query(connection, "LOCK TABLES FOR BACKUP", false);
- return(true);
- }
+ if (have_lock_wait_timeout || opt_lock_wait_timeout)
+ {
+ char buf[FN_REFLEN];
+ /* Set the maximum supported session value for
+ lock_wait_timeout if opt_lock_wait_timeout is not set to prevent
+ unnecessary timeouts when the global value is changed from the default */
+ snprintf(buf, sizeof(buf), "SET SESSION lock_wait_timeout=%u",
+ opt_lock_wait_timeout ? opt_lock_wait_timeout : 31536000);
+ xb_mysql_query(connection, buf, false);
+ }
- if (opt_lock_wait_timeout) {
- if (!wait_for_no_updates(connection, opt_lock_wait_timeout,
- opt_lock_wait_threshold)) {
- return(false);
- }
- }
+ if (have_backup_locks)
+ {
+ msg("Executing LOCK TABLES FOR BACKUP...");
+ xb_mysql_query(connection, "LOCK TABLES FOR BACKUP", false);
+ return (true);
+ }
- msg("Acquiring BACKUP LOCKS...");
+ if (opt_lock_wait_timeout)
+ {
+ if (!wait_for_no_updates(connection, opt_lock_wait_timeout,
+ opt_lock_wait_threshold))
+ {
+ return (false);
+ }
+ }
- if (opt_kill_long_queries_timeout) {
- start_query_killer();
- }
+ msg("Acquiring BACKUP LOCKS...");
- if (have_galera_enabled) {
- xb_mysql_query(connection,
- "SET SESSION wsrep_causal_reads=0", false);
- }
+ if (opt_kill_long_queries_timeout)
+ {
+ start_query_killer();
+ }
- xb_mysql_query(connection, "BACKUP STAGE START", true);
- //xb_mysql_query(connection, "BACKUP STAGE FLUSH", true);
- //xb_mysql_query(connection, "BACKUP STAGE BLOCK_DDL", true);
- xb_mysql_query(connection, "BACKUP STAGE BLOCK_COMMIT", true);
+ if (have_galera_enabled)
+ {
+ xb_mysql_query(connection, "SET SESSION wsrep_causal_reads=0", false);
+ }
- if (opt_kill_long_queries_timeout) {
- stop_query_killer();
- }
+ xb_mysql_query(connection, "BACKUP STAGE START", true);
+ // xb_mysql_query(connection, "BACKUP STAGE FLUSH", true);
+ // xb_mysql_query(connection, "BACKUP STAGE BLOCK_DDL", true);
+ xb_mysql_query(connection, "BACKUP STAGE BLOCK_COMMIT", true);
+ /* Set the maximum supported session value for
+ lock_wait_timeout to prevent unnecessary timeouts when the
+ global value is changed from the default */
+ if (opt_lock_wait_timeout)
+ xb_mysql_query(connection, "SET SESSION lock_wait_timeout=31536000",
+ false);
+
+ if (opt_kill_long_queries_timeout)
+ {
+ stop_query_killer();
+ }
- return(true);
+ return (true);
}
-
/*********************************************************************//**
If backup locks are used, execute LOCK BINLOG FOR BACKUP provided that we are
not in the --no-lock mode and the lock has not been acquired already.
diff --git a/mysql-test/suite/mariabackup/backup_lock_wait_timeout.result b/mysql-test/suite/mariabackup/backup_lock_wait_timeout.result
new file mode 100644
index 00000000000..9806bc29b47
--- /dev/null
+++ b/mysql-test/suite/mariabackup/backup_lock_wait_timeout.result
@@ -0,0 +1,11 @@
+CREATE TABLE t(i INT) ENGINE INNODB;
+connect con1,localhost,root,,;
+BEGIN;
+LOCK TABLES t WRITE;
+connection default;
+# xtrabackup backup
+connection con1;
+COMMIT;
+connection default;
+disconnect con1;
+DROP TABLE t;
diff --git a/mysql-test/suite/mariabackup/backup_lock_wait_timeout.test b/mysql-test/suite/mariabackup/backup_lock_wait_timeout.test
new file mode 100644
index 00000000000..e0f43910ef6
--- /dev/null
+++ b/mysql-test/suite/mariabackup/backup_lock_wait_timeout.test
@@ -0,0 +1,28 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+
+CREATE TABLE t(i INT) ENGINE INNODB;
+
+connect (con1,localhost,root,,);
+BEGIN;
+LOCK TABLES t WRITE;
+
+--connection default
+
+echo # xtrabackup backup;
+let $targetdir=$MYSQLTEST_VARDIR/tmp/backup;
+
+--disable_result_log
+--error 1
+exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --ftwrl-wait-timeout=1 --target-dir=$targetdir;
+--enable_result_log
+
+--connection con1
+COMMIT;
+
+--connection default
+--disconnect con1
+
+DROP TABLE t;
+rmdir $targetdir;
+--source include/wait_until_count_sessions.inc