Skip to content

Commit 221ced9

Browse files
committed
MDEV-4875 Can't restore a mysqldump if --add-drop-database meets general_log
or slow query log when the log_output=TABLE. When this happens, we temporary disable by changing log_output until we've created the general_log and slow_log tables again. Move </database> in xml mode until after the transaction_registry. General_log and slow_log tables where moved to be first to be dumped so that the disabling of the general/slow queries is minimal.
1 parent 9fe3bc2 commit 221ced9

File tree

3 files changed

+305
-121
lines changed

3 files changed

+305
-121
lines changed

client/mysqldump.c

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5229,6 +5229,55 @@ int init_dumping_views(char *qdatabase __attribute__((unused)))
52295229
} /* init_dumping_views */
52305230

52315231

5232+
/*
5233+
mysql specific database initialization.
5234+
5235+
SYNOPSIS
5236+
init_dumping_mysql_tables
5237+
5238+
protections around dumping general/slow query log
5239+
qdatabase quoted name of the "mysql" database
5240+
5241+
RETURN VALUES
5242+
0 Success.
5243+
1 Failure.
5244+
*/
5245+
static int init_dumping_mysql_tables(char *qdatabase)
5246+
{
5247+
DBUG_ENTER("init_dumping_mysql_tables");
5248+
5249+
if (opt_drop_database)
5250+
fprintf(md_result_file,
5251+
"\n/*!50106 SET @save_log_output=@@LOG_OUTPUT*/;\n"
5252+
"/*M!100203 EXECUTE IMMEDIATE IF(@@LOG_OUTPUT='TABLE' AND (@@SLOW_QUERY_LOG=1 OR @@GENERAL_LOG=1),"
5253+
"\"SET GLOBAL LOG_OUTPUT='NONE'\", \"DO 0\") */;\n");
5254+
5255+
DBUG_RETURN(init_dumping_tables(qdatabase));
5256+
}
5257+
5258+
5259+
static void dump_first_mysql_tables(char *database)
5260+
{
5261+
char table_type[NAME_LEN];
5262+
char ignore_flag;
5263+
DBUG_ENTER("dump_first_mysql_tables");
5264+
5265+
if (!get_table_structure((char *) "general_log",
5266+
database, table_type, &ignore_flag) )
5267+
verbose_msg("-- Warning: get_table_structure() failed with some internal "
5268+
"error for 'general_log' table\n");
5269+
if (!get_table_structure((char *) "slow_log",
5270+
database, table_type, &ignore_flag) )
5271+
verbose_msg("-- Warning: get_table_structure() failed with some internal "
5272+
"error for 'slow_log' table\n");
5273+
/* general and slow query logs exist now */
5274+
if (opt_drop_database)
5275+
fprintf(md_result_file,
5276+
"\n/*!50106 SET GLOBAL LOG_OUTPUT=@save_log_output*/;\n\n");
5277+
DBUG_VOID_RETURN;
5278+
}
5279+
5280+
52325281
/*
52335282
Table Specific database initialization.
52345283
@@ -5335,19 +5384,22 @@ static int dump_all_tables_in_db(char *database)
53355384
char table_buff[NAME_LEN*2+3];
53365385
char hash_key[2*NAME_LEN+2]; /* "db.tablename" */
53375386
char *afterdot;
5338-
my_bool general_log_table_exists= 0, slow_log_table_exists=0;
53395387
my_bool transaction_registry_table_exists= 0;
53405388
int using_mysql_db= !my_strcasecmp(charset_info, database, "mysql");
53415389
DBUG_ENTER("dump_all_tables_in_db");
53425390

53435391
afterdot= strmov(hash_key, database);
53445392
*afterdot++= '.';
53455393

5346-
if (init_dumping(database, init_dumping_tables))
5394+
if (init_dumping(database, using_mysql_db ? init_dumping_mysql_tables
5395+
: init_dumping_tables))
53475396
DBUG_RETURN(1);
53485397
if (opt_xml)
53495398
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
53505399

5400+
if (using_mysql_db)
5401+
dump_first_mysql_tables(database);
5402+
53515403
if (lock_tables)
53525404
{
53535405
DYNAMIC_STRING query;
@@ -5436,24 +5488,16 @@ static int dump_all_tables_in_db(char *database)
54365488
else
54375489
{
54385490
/*
5439-
If general_log and slow_log exists in the 'mysql' database,
5491+
If transaction_registry exists in the 'mysql' database,
54405492
we should dump the table structure. But we cannot
54415493
call get_table_structure() here as 'LOCK TABLES' query got executed
54425494
above on the session and that 'LOCK TABLES' query does not contain
5443-
'general_log' and 'slow_log' tables. (you cannot acquire lock
5444-
on log tables). Hence mark the existence of these log tables here and
5495+
'transaction_registry'. Hence mark the existence of the table here and
54455496
after 'UNLOCK TABLES' query is executed on the session, get the table
54465497
structure from server and dump it in the file.
54475498
*/
5448-
if (using_mysql_db)
5449-
{
5450-
if (!my_strcasecmp(charset_info, table, "general_log"))
5451-
general_log_table_exists= 1;
5452-
else if (!my_strcasecmp(charset_info, table, "slow_log"))
5453-
slow_log_table_exists= 1;
5454-
else if (!my_strcasecmp(charset_info, table, "transaction_registry"))
5455-
transaction_registry_table_exists= 1;
5456-
}
5499+
if (using_mysql_db && !my_strcasecmp(charset_info, table, "transaction_registry"))
5500+
transaction_registry_table_exists= 1;
54575501
}
54585502
}
54595503

@@ -5474,39 +5518,25 @@ static int dump_all_tables_in_db(char *database)
54745518
DBUG_PRINT("info", ("Dumping routines for database %s", database));
54755519
dump_routines_for_db(database);
54765520
}
5477-
if (opt_xml)
5478-
{
5479-
fputs("</database>\n", md_result_file);
5480-
check_io(md_result_file);
5481-
}
54825521
if (lock_tables)
54835522
(void) mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES");
54845523
if (using_mysql_db)
54855524
{
5486-
char table_type[NAME_LEN];
5487-
char ignore_flag;
5488-
if (general_log_table_exists)
5489-
{
5490-
if (!get_table_structure((char *) "general_log",
5491-
database, table_type, &ignore_flag) )
5492-
verbose_msg("-- Warning: get_table_structure() failed with some internal "
5493-
"error for 'general_log' table\n");
5494-
}
5495-
if (slow_log_table_exists)
5496-
{
5497-
if (!get_table_structure((char *) "slow_log",
5498-
database, table_type, &ignore_flag) )
5499-
verbose_msg("-- Warning: get_table_structure() failed with some internal "
5500-
"error for 'slow_log' table\n");
5501-
}
55025525
if (transaction_registry_table_exists)
55035526
{
5527+
char table_type[NAME_LEN];
5528+
char ignore_flag;
55045529
if (!get_table_structure((char *) "transaction_registry",
55055530
database, table_type, &ignore_flag) )
55065531
verbose_msg("-- Warning: get_table_structure() failed with some internal "
55075532
"error for 'transaction_registry' table\n");
55085533
}
55095534
}
5535+
if (opt_xml)
5536+
{
5537+
fputs("</database>\n", md_result_file);
5538+
check_io(md_result_file);
5539+
}
55105540
if (flush_privileges && using_mysql_db)
55115541
{
55125542
fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");

0 commit comments

Comments
 (0)