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
#include "encryption_plugin.h"
#include <sstream>
#include <sql_error.h>
#include <ut0ut.h>
char *tool_name;
......@@ -1665,38 +1666,28 @@ static void check_mdl_lock_works(const char *table_name)
free(query);
}
#endif
extern void
dict_fs2utf8(const char*, char*, size_t, char*, size_t);
void
mdl_lock_table(ulint space_id)
{
static const char q[] = "SELECT NAME "
std::ostringstream oss;
oss << "SELECT NAME "
"FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES "
"WHERE SPACE = " ULINTPF " AND NAME LIKE '%%/%%'";
char query[22 + sizeof q];
snprintf(query, sizeof query, q, space_id);
"WHERE SPACE = " << space_id << " AND NAME LIKE '%%/%%'";
pthread_mutex_lock(&mdl_lock_con_mutex);
MYSQL_RES *mysql_result = xb_mysql_query(mdl_con, query, 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];
MYSQL_RES *mysql_result = xb_mysql_query(mdl_con, oss.str().c_str(), true, true);
dict_fs2utf8(row[0], db_utf8, sizeof db_utf8,table_utf8,sizeof table_utf8);
snprintf(full_table_name,sizeof(full_table_name),"`%s`.`%s`",db_utf8,table_utf8);
msg_ts("Locking MDL for %s\n", full_table_name);
snprintf(lock_query, sizeof lock_query, lq, full_table_name);
while (MYSQL_ROW row = mysql_fetch_row(mysql_result)) {
std::string full_table_name = ut_get_name(0,row[0]);
std::ostringstream lock_query;
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",
check_mdl_lock_works(full_table_name););
check_mdl_lock_works(full_table_name.c_str()););
}
pthread_mutex_unlock(&mdl_lock_con_mutex);
......
......@@ -1148,17 +1148,12 @@ static void append_export_table(const char *dbname, const char *tablename, bool
if(dbname && tablename && !is_remote)
{
char buf[3*FN_REFLEN];
char db_utf8[FN_REFLEN];
char table_utf8[FN_REFLEN];
snprintf(buf,sizeof(buf),"%s/%s",dbname, tablename);
// trim .ibd
char *p=strrchr(buf, '.');
if (p) *p=0;
dict_fs2utf8(buf, db_utf8, sizeof(db_utf8),table_utf8,sizeof(table_utf8));
snprintf(buf,sizeof(buf),"`%s`.`%s`",db_utf8,table_utf8);
tables_for_export.push_back(buf);
tables_for_export.push_back(ut_get_name(0,buf));
}
}
......@@ -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 fileinfo;
dberr_t err = DB_SUCCESS;
size_t len;
/* 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)
/* We found a symlink or a directory; try opening it to see
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;
if (len > dbpath_len) {
dbpath_len = len;
......@@ -2832,10 +2828,8 @@ static dberr_t enumerate_ibd_files(process_single_tablespace_func_t callback)
continue;
}
size_t len = strlen(fileinfo.name);
/* We found a symlink or a file */
if (len > 4) {
if (strlen(fileinfo.name) > 4) {
bool is_isl= false;
if (ends_with(fileinfo.name, ".ibd") || ((is_isl = ends_with(fileinfo.name, ".ibd"))))
(*callback)(dbinfo.name, fileinfo.name, is_isl);
......
......@@ -5,8 +5,16 @@ INSERT INTO t VALUES(1);
echo # xtrabackup 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
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
DROP TABLE t;
DROP TABLE `bobby``tables`;
rmdir $targetdir;
\ No newline at end of file
--innodb --loose-changed_page_bitmaps --innodb-file-format=Barracuda --innodb-sys-tables
\ No newline at end of file
--innodb --loose-changed_page_bitmaps --innodb-file-format=Barracuda --innodb-sys-tables --partition
\ 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