Commit ecc46826 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-16519 : mariabackup should fail if MDL could not be acquired with 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.
parent 0d745343
......@@ -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);
......
CREATE TABLE t1(i int) ENGINE INNODB;
FOUND 1 /failed to execute query SELECT 1 FROM/ in backup.log
DROP TABLE t2;
--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;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment