mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
BUG#20839 Illegal error code: 155 returned downgrading from 5.1.12-> 5.1.11
Update mysqldump to dump the needed tablespaces to create the tables for either the dbs or tables we're dumping. With --all-tablespaces, we still dump everything.
This commit is contained in:
@ -99,7 +99,7 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
|
|||||||
opt_replace_into= 0,
|
opt_replace_into= 0,
|
||||||
opt_dump_triggers= 0, opt_routines=0, opt_tz_utc=1,
|
opt_dump_triggers= 0, opt_routines=0, opt_tz_utc=1,
|
||||||
opt_events= 0,
|
opt_events= 0,
|
||||||
opt_alltspcs=0;
|
opt_alltspcs=0, opt_notspcs= 0;
|
||||||
static ulong opt_max_allowed_packet, opt_net_buffer_length;
|
static ulong opt_max_allowed_packet, opt_net_buffer_length;
|
||||||
static MYSQL mysql_connection,*mysql=0;
|
static MYSQL mysql_connection,*mysql=0;
|
||||||
static my_bool insert_pat_inited=0;
|
static my_bool insert_pat_inited=0;
|
||||||
@ -170,6 +170,10 @@ static struct my_option my_long_options[] =
|
|||||||
"Dump all the tablespaces.",
|
"Dump all the tablespaces.",
|
||||||
(gptr*) &opt_alltspcs, (gptr*) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
|
(gptr*) &opt_alltspcs, (gptr*) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
|
||||||
0, 0},
|
0, 0},
|
||||||
|
{"no-tablespaces", 'y',
|
||||||
|
"Do not dump any tablespace information.",
|
||||||
|
(gptr*) &opt_notspcs, (gptr*) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
|
||||||
|
0, 0},
|
||||||
{"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
|
{"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
|
||||||
(gptr*) &opt_drop_database, (gptr*) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
|
(gptr*) &opt_drop_database, (gptr*) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
|
||||||
0},
|
0},
|
||||||
@ -446,6 +450,10 @@ char check_if_ignore_table(const char *table_name, char *table_type);
|
|||||||
static char *primary_key_fields(const char *table_name);
|
static char *primary_key_fields(const char *table_name);
|
||||||
static my_bool get_view_structure(char *table, char* db);
|
static my_bool get_view_structure(char *table, char* db);
|
||||||
static my_bool dump_all_views_in_db(char *database);
|
static my_bool dump_all_views_in_db(char *database);
|
||||||
|
static int dump_all_tablespaces();
|
||||||
|
static int dump_tablespaces_for_tables(char *db, char **table_names, int tables);
|
||||||
|
static int dump_tablespaces_for_databases(char** databases);
|
||||||
|
static int dump_tablespaces(char* ts_where);
|
||||||
|
|
||||||
#include <help_start.h>
|
#include <help_start.h>
|
||||||
|
|
||||||
@ -2745,10 +2753,101 @@ static char *getTableName(int reset)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int dump_all_tablespaces()
|
static int dump_all_tablespaces()
|
||||||
|
{
|
||||||
|
return dump_tablespaces(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dump_tablespaces_for_tables(char *db, char **table_names, int tables)
|
||||||
|
{
|
||||||
|
char *where;
|
||||||
|
int r;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
size_t sz= 200+tables*(NAME_LEN*2+3);
|
||||||
|
where= my_malloc(sz, MYF(MY_WME));
|
||||||
|
|
||||||
|
if (!where)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
char name_buff[NAME_LEN*2+3];
|
||||||
|
mysql_real_escape_string(mysql, name_buff, db, strlen(db));
|
||||||
|
|
||||||
|
snprintf(where,sz-1,
|
||||||
|
" AND TABLESPACE_NAME IN ("
|
||||||
|
"SELECT DISTINCT TABLESPACE_NAME FROM"
|
||||||
|
" INFORMATION_SCHEMA.PARTITIONS"
|
||||||
|
" WHERE"
|
||||||
|
" TABLE_SCHEMA='%s'"
|
||||||
|
" AND TABLE_NAME IN (", name_buff);
|
||||||
|
|
||||||
|
for (i=0 ; i<tables ; i++)
|
||||||
|
{
|
||||||
|
mysql_real_escape_string(mysql, name_buff,
|
||||||
|
table_names[i], strlen(table_names[i]));
|
||||||
|
strncat(where,"'",sz-3);
|
||||||
|
strncat(where,name_buff,sz-3);
|
||||||
|
strncat(where,"'",sz-3);
|
||||||
|
strncat(where,",",sz-3);
|
||||||
|
}
|
||||||
|
sz= strlen(where);
|
||||||
|
where[sz-1]= ')';
|
||||||
|
where[sz]= ')';
|
||||||
|
where[sz+1]= '\0';
|
||||||
|
|
||||||
|
DBUG_PRINT("info",("Dump TS for Tables where: %s",where));
|
||||||
|
r= dump_tablespaces(where);
|
||||||
|
my_free(where, MYF(0));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dump_tablespaces_for_databases(char** databases)
|
||||||
|
{
|
||||||
|
char *where;
|
||||||
|
int r;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
size_t sz= 150;
|
||||||
|
for (i=0 ; databases[i]!=NULL ; i++)
|
||||||
|
sz+=(strlen(databases[i])*2)+3+1;
|
||||||
|
|
||||||
|
where= my_malloc(sz, MYF(MY_WME));
|
||||||
|
if(!where)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
strncpy(where,
|
||||||
|
" AND TABLESPACE_NAME IN ("
|
||||||
|
"SELECT DISTINCT TABLESPACE_NAME FROM"
|
||||||
|
" INFORMATION_SCHEMA.PARTITIONS"
|
||||||
|
" WHERE"
|
||||||
|
" TABLE_SCHEMA IN (", sz-1);
|
||||||
|
|
||||||
|
for (i=0 ; databases[i]!=NULL ; i++)
|
||||||
|
{
|
||||||
|
char db_name_buff[NAME_LEN*2+3];
|
||||||
|
mysql_real_escape_string(mysql, db_name_buff,
|
||||||
|
databases[i], strlen(databases[i]));
|
||||||
|
strncat(where,"'",sz-3);
|
||||||
|
strncat(where,db_name_buff,sz-3);
|
||||||
|
strncat(where,"'",sz-3);
|
||||||
|
strncat(where,",",sz-3);
|
||||||
|
}
|
||||||
|
sz= strlen(where);
|
||||||
|
where[sz-1]= ')';
|
||||||
|
where[sz]= ')';
|
||||||
|
where[sz+1]= '\0';
|
||||||
|
|
||||||
|
DBUG_PRINT("info",("Dump TS for DBs where: %s",where));
|
||||||
|
r= dump_tablespaces(where);
|
||||||
|
my_free(where, MYF(0));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dump_tablespaces(char* ts_where)
|
||||||
{
|
{
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
MYSQL_RES *tableres;
|
MYSQL_RES *tableres;
|
||||||
char buf[FN_REFLEN];
|
char buf[FN_REFLEN];
|
||||||
|
char sqlbuf[1024];
|
||||||
int first;
|
int first;
|
||||||
/*
|
/*
|
||||||
The following are used for parsing the EXTRA field
|
The following are used for parsing the EXTRA field
|
||||||
@ -2757,20 +2856,28 @@ static int dump_all_tablespaces()
|
|||||||
char *ubs;
|
char *ubs;
|
||||||
char *endsemi;
|
char *endsemi;
|
||||||
|
|
||||||
if (mysql_query_with_error_report(mysql, &tableres,
|
snprintf(sqlbuf,sizeof(sqlbuf),"%s%s%s%s%s",
|
||||||
"SELECT"
|
"SELECT LOGFILE_GROUP_NAME,"
|
||||||
" LOGFILE_GROUP_NAME,"
|
" FILE_NAME,"
|
||||||
" FILE_NAME,"
|
" TOTAL_EXTENTS,"
|
||||||
" TOTAL_EXTENTS,"
|
" INITIAL_SIZE,"
|
||||||
" INITIAL_SIZE,"
|
" ENGINE,"
|
||||||
" ENGINE,"
|
" EXTRA"
|
||||||
" EXTRA"
|
" FROM INFORMATION_SCHEMA.FILES"
|
||||||
" FROM INFORMATION_SCHEMA.FILES"
|
" WHERE FILE_TYPE = 'UNDO LOG'"
|
||||||
" WHERE FILE_TYPE = \"UNDO LOG\""
|
" AND FILE_NAME IS NOT NULL",
|
||||||
" AND FILE_NAME IS NOT NULL"
|
(ts_where)?
|
||||||
" GROUP BY LOGFILE_GROUP_NAME, FILE_NAME"
|
" AND LOGFILE_GROUP_NAME IN ("
|
||||||
", ENGINE"
|
"SELECT DISTINCT LOGFILE_GROUP_NAME"
|
||||||
" ORDER BY LOGFILE_GROUP_NAME"))
|
" FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'DATAFILE'"
|
||||||
|
:"",
|
||||||
|
(ts_where)?ts_where:"",
|
||||||
|
(ts_where)?")":"",
|
||||||
|
" GROUP BY LOGFILE_GROUP_NAME, FILE_NAME"
|
||||||
|
", ENGINE"
|
||||||
|
" ORDER BY LOGFILE_GROUP_NAME");
|
||||||
|
|
||||||
|
if (mysql_query_with_error_report(mysql, &tableres,sqlbuf))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
buf[0]= 0;
|
buf[0]= 0;
|
||||||
@ -2822,17 +2929,19 @@ static int dump_all_tablespaces()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mysql_query_with_error_report(mysql, &tableres,
|
snprintf(sqlbuf,sizeof(sqlbuf),"%s%s%s",
|
||||||
"SELECT DISTINCT"
|
"SELECT DISTINCT TABLESPACE_NAME,"
|
||||||
" TABLESPACE_NAME,"
|
" FILE_NAME,"
|
||||||
" FILE_NAME,"
|
" LOGFILE_GROUP_NAME,"
|
||||||
" LOGFILE_GROUP_NAME,"
|
" EXTENT_SIZE,"
|
||||||
" EXTENT_SIZE,"
|
" INITIAL_SIZE,"
|
||||||
" INITIAL_SIZE,"
|
" ENGINE"
|
||||||
" ENGINE"
|
" FROM INFORMATION_SCHEMA.FILES"
|
||||||
" FROM INFORMATION_SCHEMA.FILES"
|
" WHERE FILE_TYPE = 'DATAFILE'",
|
||||||
" WHERE FILE_TYPE = \"DATAFILE\""
|
(ts_where)?ts_where:"",
|
||||||
" ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME"))
|
" ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME");
|
||||||
|
|
||||||
|
if (mysql_query_with_error_report(mysql, &tableres,sqlbuf))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
buf[0]= 0;
|
buf[0]= 0;
|
||||||
@ -3924,15 +4033,23 @@ int main(int argc, char **argv)
|
|||||||
dump_all_tablespaces();
|
dump_all_tablespaces();
|
||||||
|
|
||||||
if (opt_alldbs)
|
if (opt_alldbs)
|
||||||
|
{
|
||||||
|
if (!opt_alltspcs && !opt_notspcs)
|
||||||
|
dump_all_tablespaces();
|
||||||
dump_all_databases();
|
dump_all_databases();
|
||||||
|
}
|
||||||
else if (argc > 1 && !opt_databases)
|
else if (argc > 1 && !opt_databases)
|
||||||
{
|
{
|
||||||
/* Only one database and selected table(s) */
|
/* Only one database and selected table(s) */
|
||||||
|
if (!opt_alltspcs && !opt_notspcs)
|
||||||
|
dump_tablespaces_for_tables(*argv, (argv + 1), (argc -1));
|
||||||
dump_selected_tables(*argv, (argv + 1), (argc - 1));
|
dump_selected_tables(*argv, (argv + 1), (argc - 1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* One or more databases, all tables */
|
/* One or more databases, all tables */
|
||||||
|
if (!opt_alltspcs && !opt_notspcs)
|
||||||
|
dump_tablespaces_for_databases(argv);
|
||||||
dump_databases(argv);
|
dump_databases(argv);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_SMEM
|
#ifdef HAVE_SMEM
|
||||||
|
@ -3889,6 +3889,7 @@ static void collect_partition_expr(List<char> &field_list, String *str)
|
|||||||
|
|
||||||
|
|
||||||
static void store_schema_partitions_record(THD *thd, TABLE *table,
|
static void store_schema_partitions_record(THD *thd, TABLE *table,
|
||||||
|
TABLE *show_table,
|
||||||
partition_element *part_elem,
|
partition_element *part_elem,
|
||||||
handler *file, uint part_id)
|
handler *file, uint part_id)
|
||||||
{
|
{
|
||||||
@ -3942,11 +3943,21 @@ static void store_schema_partitions_record(THD *thd, TABLE *table,
|
|||||||
table->field[23]->store((longlong) part_elem->nodegroup_id, TRUE);
|
table->field[23]->store((longlong) part_elem->nodegroup_id, TRUE);
|
||||||
else
|
else
|
||||||
table->field[23]->store(STRING_WITH_LEN("default"), cs);
|
table->field[23]->store(STRING_WITH_LEN("default"), cs);
|
||||||
|
|
||||||
|
table->field[24]->set_notnull();
|
||||||
if (part_elem->tablespace_name)
|
if (part_elem->tablespace_name)
|
||||||
table->field[24]->store(part_elem->tablespace_name,
|
table->field[24]->store(part_elem->tablespace_name,
|
||||||
strlen(part_elem->tablespace_name), cs);
|
strlen(part_elem->tablespace_name), cs);
|
||||||
else
|
else
|
||||||
table->field[24]->store(STRING_WITH_LEN("default"), cs);
|
{
|
||||||
|
DBUG_PRINT("info",("FOO"));
|
||||||
|
char *ts= show_table->file->get_tablespace_name(thd);
|
||||||
|
if(ts)
|
||||||
|
table->field[24]->store(ts, strlen(ts), cs);
|
||||||
|
else
|
||||||
|
table->field[24]->set_null();
|
||||||
|
my_free(ts, MYF(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -4129,7 +4140,7 @@ static int get_schema_partitions_record(THD *thd, struct st_table_list *tables,
|
|||||||
table->field[6]->store((longlong) ++subpart_pos, TRUE);
|
table->field[6]->store((longlong) ++subpart_pos, TRUE);
|
||||||
table->field[6]->set_notnull();
|
table->field[6]->set_notnull();
|
||||||
|
|
||||||
store_schema_partitions_record(thd, table, subpart_elem,
|
store_schema_partitions_record(thd, table, show_table, subpart_elem,
|
||||||
file, part_id);
|
file, part_id);
|
||||||
part_id++;
|
part_id++;
|
||||||
if(schema_table_store_record(thd, table))
|
if(schema_table_store_record(thd, table))
|
||||||
@ -4138,7 +4149,7 @@ static int get_schema_partitions_record(THD *thd, struct st_table_list *tables,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
store_schema_partitions_record(thd, table, part_elem,
|
store_schema_partitions_record(thd, table, show_table, part_elem,
|
||||||
file, part_id);
|
file, part_id);
|
||||||
part_id++;
|
part_id++;
|
||||||
if(schema_table_store_record(thd, table))
|
if(schema_table_store_record(thd, table))
|
||||||
@ -4150,7 +4161,7 @@ static int get_schema_partitions_record(THD *thd, struct st_table_list *tables,
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
store_schema_partitions_record(thd, table, 0, file, 0);
|
store_schema_partitions_record(thd, table, show_table, 0, file, 0);
|
||||||
if(schema_table_store_record(thd, table))
|
if(schema_table_store_record(thd, table))
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
}
|
}
|
||||||
@ -5334,7 +5345,7 @@ ST_FIELD_INFO partitions_fields_info[]=
|
|||||||
{"CHECKSUM", 21 , MYSQL_TYPE_LONG, 0, 1, 0},
|
{"CHECKSUM", 21 , MYSQL_TYPE_LONG, 0, 1, 0},
|
||||||
{"PARTITION_COMMENT", 80, MYSQL_TYPE_STRING, 0, 0, 0},
|
{"PARTITION_COMMENT", 80, MYSQL_TYPE_STRING, 0, 0, 0},
|
||||||
{"NODEGROUP", 12 , MYSQL_TYPE_STRING, 0, 0, 0},
|
{"NODEGROUP", 12 , MYSQL_TYPE_STRING, 0, 0, 0},
|
||||||
{"TABLESPACE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
|
{"TABLESPACE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0},
|
||||||
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
|
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user