summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorVenkata Sidagam <venkata.sidagam@oracle.com>2012-05-07 16:46:44 +0530
committerVenkata Sidagam <venkata.sidagam@oracle.com>2012-05-07 16:46:44 +0530
commit14aa2c020e8ce930f42f5ee9e50843c58c2df6ef (patch)
treed21be3e05106f2dfc5fb9c85f166666aa83eaf7a /client
parentd90207321b0fac0052baa65a3c9396c385d874a9 (diff)
downloadmariadb-git-14aa2c020e8ce930f42f5ee9e50843c58c2df6ef.tar.gz
Bug #11754178 45740: MYSQLDUMP DOESN'T DUMP GENERAL_LOG AND SLOW_QUERY
CAUSES RESTORE PROBLEM Problem Statement: ------------------ mysqldump is not having the dump stmts for general_log and slow_log tables. That is because of the fix for Bug#26121. Hence, after dropping the mysql database, and applying the dump by enabling the logging, "'general_log' table not found" errors are logged into the server log file. Analysis: --------- As part of the fix for Bug#26121, we skipped the dumping of tables for general_log and slow_log, because the data dump of those tables are taking LOCKS, which is not allowed for log tables. Fix: ---- We came up with an approach that instead of taking both meta data and data dump information for those tables, take only the meta data dump which doesn't need LOCKS. As part of fixing the issue we came up with below algorithm. Design before fix: 1) mysql database is having tables like db, event,... general_log, ... slow_log... 2) Skip general_log and slow_log while preparing the tables list 3) Take the TL_READ lock on tables which are present in the table list and do 'show create table'. 4) Release the lock. Design with the fix: 1) mysql database is having tables like db, event,... general_log, ... slow_log... 2) Skip general_log and slow_log while preparing the tables list 3) Explicitly call the 'show create table' for general_log and slow_log 3) Take the TL_READ lock on tables which are present in the table list and do 'show create table'. 4) Release the lock. While taking the meta data dump for general_log and slow_log the "CREATE TABLE" is replaced with "CREATE TABLE IF NOT EXISTS". This is because we skipped "DROP TABLE" for those tables, "DROP TABLE" fails for these tables if logging is enabled. Customer is applying the dump by enabling logging so, if the dump has "DROP TABLE" it will fail. Hence, removed the "DROP TABLE" stmts for those tables. After the fix we could observe "Table 'mysql.general_log' doesn't exist" errors initially that is because in the customer scenario they are dropping the mysql database by enabling the logging, Hence, those errors are expected. Once we apply the dump which is taken before the "drop database mysql", the errors will not be there.
Diffstat (limited to 'client')
-rw-r--r--client/mysqldump.c58
1 files changed, 50 insertions, 8 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 8601b533849..dc124f1b335 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -84,6 +84,15 @@
#define IGNORE_DATA 0x01 /* don't dump data for this table */
#define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */
+/* general_log or slow_log tables under mysql database */
+static inline my_bool general_log_or_slow_log_tables(const char *db,
+ const char *table)
+{
+ return (strcmp(db, "mysql") == 0) &&
+ ((strcmp(table, "general_log") == 0) ||
+ (strcmp(table, "slow_log") == 0));
+}
+
static void add_load_option(DYNAMIC_STRING *str, const char *option,
const char *option_value);
static ulong find_set(TYPELIB *lib, const char *x, uint length,
@@ -2458,6 +2467,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
"TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'";
FILE *sql_file= md_result_file;
int len;
+ my_bool is_log_table;
MYSQL_RES *result;
MYSQL_ROW row;
DBUG_ENTER("get_table_structure");
@@ -2542,9 +2552,12 @@ static uint get_table_structure(char *table, char *db, char *table_type,
/*
Even if the "table" is a view, we do a DROP TABLE here. The
view-specific code below fills in the DROP VIEW.
+ We will skip the DROP TABLE for general_log and slow_log, since
+ those stmts will fail, in case we apply dump by enabling logging.
*/
- fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
- opt_quoted_table);
+ if (!general_log_or_slow_log_tables(db, table))
+ fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
+ opt_quoted_table);
check_io(sql_file);
}
@@ -2656,12 +2669,25 @@ static uint get_table_structure(char *table, char *db, char *table_type,
row= mysql_fetch_row(result);
- fprintf(sql_file, (opt_compatible_mode & 3) ? "%s;\n" :
- "/*!40101 SET @saved_cs_client = @@character_set_client */;\n"
- "/*!40101 SET character_set_client = utf8 */;\n"
- "%s;\n"
- "/*!40101 SET character_set_client = @saved_cs_client */;\n",
- row[1]);
+ is_log_table= general_log_or_slow_log_tables(db, table);
+ if (is_log_table)
+ row[1]+= 13; /* strlen("CREATE TABLE ")= 13 */
+ if (opt_compatible_mode & 3)
+ {
+ fprintf(sql_file,
+ is_log_table ? "CREATE TABLE IF NOT EXISTS %s;\n" : "%s;\n",
+ row[1]);
+ }
+ else
+ {
+ fprintf(sql_file,
+ "/*!40101 SET @saved_cs_client = @@character_set_client */;\n"
+ "/*!40101 SET character_set_client = utf8 */;\n"
+ "%s%s;\n"
+ "/*!40101 SET character_set_client = @saved_cs_client */;\n",
+ is_log_table ? "CREATE TABLE IF NOT EXISTS " : "",
+ row[1]);
+ }
check_io(sql_file);
mysql_free_result(result);
@@ -4261,6 +4287,22 @@ static int dump_all_tables_in_db(char *database)
if (opt_xml)
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
+ if (strcmp(database, "mysql") == 0)
+ {
+ char table_type[NAME_LEN];
+ char ignore_flag;
+ uint num_fields;
+ num_fields= get_table_structure((char *) "general_log",
+ database, table_type, &ignore_flag);
+ if (num_fields == 0)
+ verbose_msg("-- Warning: get_table_structure() failed with some internal "
+ "error for 'general_log' table\n");
+ num_fields= get_table_structure((char *) "slow_log",
+ database, table_type, &ignore_flag);
+ if (num_fields == 0)
+ verbose_msg("-- Warning: get_table_structure() failed with some internal "
+ "error for 'slow_log' table\n");
+ }
if (lock_tables)
{
DYNAMIC_STRING query;