Commit 74f677fc authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-13802 mariabackup --lock-ddl-per-table fails when table names contain backticks

use ut_get_name() for formatting database/table names.
parent bb7ab405
...@@ -55,6 +55,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA ...@@ -55,6 +55,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "encryption_plugin.h" #include "encryption_plugin.h"
#include <sstream> #include <sstream>
#include <sql_error.h> #include <sql_error.h>
#include <ut0ut.h>
char *tool_name; char *tool_name;
...@@ -1665,38 +1666,28 @@ static void check_mdl_lock_works(const char *table_name) ...@@ -1665,38 +1666,28 @@ static void check_mdl_lock_works(const char *table_name)
free(query); free(query);
} }
#endif #endif
extern void
dict_fs2utf8(const char*, char*, size_t, char*, size_t);
void void
mdl_lock_table(ulint space_id) mdl_lock_table(ulint space_id)
{ {
static const char q[] = "SELECT NAME " std::ostringstream oss;
oss << "SELECT NAME "
"FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES " "FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES "
"WHERE SPACE = " ULINTPF " AND NAME LIKE '%%/%%'"; "WHERE SPACE = " << space_id << " AND NAME LIKE '%%/%%'";
char query[22 + sizeof q];
snprintf(query, sizeof query, q, space_id);
pthread_mutex_lock(&mdl_lock_con_mutex); pthread_mutex_lock(&mdl_lock_con_mutex);
MYSQL_RES *mysql_result = xb_mysql_query(mdl_con, query, true, true); MYSQL_RES *mysql_result = xb_mysql_query(mdl_con, oss.str().c_str(), true, true);
while (MYSQL_ROW row = mysql_fetch_row(mysql_result)) {
char full_table_name[2*FN_REFLEN +2];
char db_utf8[FN_REFLEN];
char table_utf8[FN_REFLEN];
static const char lq[] = "SELECT * FROM %s LIMIT 0";
char lock_query[sizeof full_table_name + sizeof lq];
dict_fs2utf8(row[0], db_utf8, sizeof db_utf8,table_utf8,sizeof table_utf8); while (MYSQL_ROW row = mysql_fetch_row(mysql_result)) {
snprintf(full_table_name,sizeof(full_table_name),"`%s`.`%s`",db_utf8,table_utf8); std::string full_table_name = ut_get_name(0,row[0]);
msg_ts("Locking MDL for %s\n", full_table_name); std::ostringstream lock_query;
snprintf(lock_query, sizeof lock_query, lq, full_table_name); lock_query << "SELECT * FROM " << full_table_name << " LIMIT 0";
xb_mysql_query(mdl_con, lock_query, false, false); msg_ts("Locking MDL for %s\n", full_table_name.c_str());
xb_mysql_query(mdl_con, lock_query.str().c_str(), false, false);
DBUG_EXECUTE_IF("check_mdl_lock_works", DBUG_EXECUTE_IF("check_mdl_lock_works",
check_mdl_lock_works(full_table_name);); check_mdl_lock_works(full_table_name.c_str()););
} }
pthread_mutex_unlock(&mdl_lock_con_mutex); pthread_mutex_unlock(&mdl_lock_con_mutex);
......
...@@ -1148,17 +1148,12 @@ static void append_export_table(const char *dbname, const char *tablename, bool ...@@ -1148,17 +1148,12 @@ static void append_export_table(const char *dbname, const char *tablename, bool
if(dbname && tablename && !is_remote) if(dbname && tablename && !is_remote)
{ {
char buf[3*FN_REFLEN]; char buf[3*FN_REFLEN];
char db_utf8[FN_REFLEN];
char table_utf8[FN_REFLEN];
snprintf(buf,sizeof(buf),"%s/%s",dbname, tablename); snprintf(buf,sizeof(buf),"%s/%s",dbname, tablename);
// trim .ibd // trim .ibd
char *p=strrchr(buf, '.'); char *p=strrchr(buf, '.');
if (p) *p=0; if (p) *p=0;
dict_fs2utf8(buf, db_utf8, sizeof(db_utf8),table_utf8,sizeof(table_utf8)); tables_for_export.push_back(ut_get_name(0,buf));
snprintf(buf,sizeof(buf),"`%s`.`%s`",db_utf8,table_utf8);
tables_for_export.push_back(buf);
} }
} }
...@@ -2753,6 +2748,7 @@ static dberr_t enumerate_ibd_files(process_single_tablespace_func_t callback) ...@@ -2753,6 +2748,7 @@ static dberr_t enumerate_ibd_files(process_single_tablespace_func_t callback)
os_file_stat_t dbinfo; os_file_stat_t dbinfo;
os_file_stat_t fileinfo; os_file_stat_t fileinfo;
dberr_t err = DB_SUCCESS; dberr_t err = DB_SUCCESS;
size_t len;
/* The datadir of MySQL is always the default directory of mysqld */ /* The datadir of MySQL is always the default directory of mysqld */
...@@ -2792,7 +2788,7 @@ static dberr_t enumerate_ibd_files(process_single_tablespace_func_t callback) ...@@ -2792,7 +2788,7 @@ static dberr_t enumerate_ibd_files(process_single_tablespace_func_t callback)
/* We found a symlink or a directory; try opening it to see /* We found a symlink or a directory; try opening it to see
if a symlink is a directory */ if a symlink is a directory */
size_t len = strlen(fil_path_to_mysql_datadir) len = strlen(fil_path_to_mysql_datadir)
+ strlen (dbinfo.name) + 2; + strlen (dbinfo.name) + 2;
if (len > dbpath_len) { if (len > dbpath_len) {
dbpath_len = len; dbpath_len = len;
...@@ -2832,10 +2828,8 @@ static dberr_t enumerate_ibd_files(process_single_tablespace_func_t callback) ...@@ -2832,10 +2828,8 @@ static dberr_t enumerate_ibd_files(process_single_tablespace_func_t callback)
continue; continue;
} }
size_t len = strlen(fileinfo.name);
/* We found a symlink or a file */ /* We found a symlink or a file */
if (len > 4) { if (strlen(fileinfo.name) > 4) {
bool is_isl= false; bool is_isl= false;
if (ends_with(fileinfo.name, ".ibd") || ((is_isl = ends_with(fileinfo.name, ".ibd")))) if (ends_with(fileinfo.name, ".ibd") || ((is_isl = ends_with(fileinfo.name, ".ibd"))))
(*callback)(dbinfo.name, fileinfo.name, is_isl); (*callback)(dbinfo.name, fileinfo.name, is_isl);
......
...@@ -5,8 +5,16 @@ INSERT INTO t VALUES(1); ...@@ -5,8 +5,16 @@ INSERT INTO t VALUES(1);
echo # xtrabackup backup; echo # xtrabackup backup;
let $targetdir=$MYSQLTEST_VARDIR/tmp/backup; let $targetdir=$MYSQLTEST_VARDIR/tmp/backup;
CREATE TABLE `bobby``tables` (id INT, name VARCHAR(50), purchased DATE) ENGINE INNODB PARTITION BY RANGE( YEAR(purchased) ) (
PARTITION p0 VALUES LESS THAN (1990),
PARTITION p1 VALUES LESS THAN (1995),
PARTITION p2 VALUES LESS THAN (2000),
PARTITION p3 VALUES LESS THAN (2005)
) ;
--disable_result_log --disable_result_log
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir --lock-ddl-per-table=1 --dbug=+d,check_mdl_lock_works; exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir --lock-ddl-per-table=1 --dbug=+d,check_mdl_lock_works;
--enable_result_log --enable_result_log
DROP TABLE t; DROP TABLE t;
DROP TABLE `bobby``tables`;
rmdir $targetdir; rmdir $targetdir;
\ No newline at end of file
--innodb --loose-changed_page_bitmaps --innodb-file-format=Barracuda --innodb-sys-tables --innodb --loose-changed_page_bitmaps --innodb-file-format=Barracuda --innodb-sys-tables --partition
\ No newline at end of file \ No newline at end of file
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