Skip to content
Permalink
Browse files
MDEV-16519 : mariabackup should fail if MDL could not be acquired wit…
…h lock-ddl-per-table

There is a tiny chance for race condition during MDL acquisition.

If table is renamed just prior to
SELECT 1 FROM <table_name> LIMIT 0

then this query would  fail, yet mariabackup --backup does not handle
it as fatal error and continues, only to fail later during file copy.

The fix is to die on error, of MDL lock query fails.
  • Loading branch information
vaintroub committed Jun 22, 2018
1 parent 0d74534 commit ecc4682
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
@@ -186,6 +186,7 @@ xb_mysql_query(MYSQL *connection, const char *query, bool use_result,

if (!use_result) {
mysql_free_result(mysql_result);
mysql_result = NULL;
}
}

@@ -1783,12 +1784,17 @@ mdl_lock_table(ulint space_id)
MYSQL_RES *mysql_result = xb_mysql_query(mdl_con, oss.str().c_str(), true, true);

while (MYSQL_ROW row = mysql_fetch_row(mysql_result)) {

DBUG_EXECUTE_IF("rename_during_mdl_lock_table",
if (strcmp(row[0], "test/t1") == 0)
xb_mysql_query(mysql_connection, "RENAME TABLE test.t1 to test.t2", false, true
););

std::string full_table_name = ut_get_name(0,row[0]);
std::ostringstream lock_query;
lock_query << "SELECT 1 FROM " << full_table_name << " LIMIT 0";

msg_ts("Locking MDL for %s\n", full_table_name.c_str());
xb_mysql_query(mdl_con, lock_query.str().c_str(), false, false);
xb_mysql_query(mdl_con, lock_query.str().c_str(), false, true);
}

pthread_mutex_unlock(&mdl_lock_con_mutex);
@@ -0,0 +1,3 @@
CREATE TABLE t1(i int) ENGINE INNODB;
FOUND 1 /failed to execute query SELECT 1 FROM/ in backup.log
DROP TABLE t2;
@@ -0,0 +1,13 @@
--source include/have_debug.inc
let $targetdir=$MYSQLTEST_VARDIR/backup;
mkdir $targetdir;
CREATE TABLE t1(i int) ENGINE INNODB;
--error 1
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir --lock-ddl-per-table --dbug=+d,rename_during_mdl_lock_table 2>$targetdir/backup.log;

let SEARCH_FILE=$targetdir/backup.log;
let SEARCH_PATTERN=failed to execute query SELECT 1 FROM;
source include/search_pattern_in_file.inc;

DROP TABLE t2;
rmdir $targetdir;

0 comments on commit ecc4682

Please sign in to comment.