@@ -740,7 +740,7 @@ static void write_header(FILE *sql_file, const char *db_name)
740
740
}
741
741
else
742
742
{
743
- fprintf (sql_file , "/*!999999\\- enable the sandbox mode */ \n" );
743
+ fprintf (sql_file , "/*M !999999\\- enable the sandbox mode */ \n" );
744
744
if (!opt_compact )
745
745
{
746
746
print_comment (sql_file , 0 , "-- MariaDB dump %s-%s, for %s (%s)\n--\n" ,
@@ -6136,8 +6136,11 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
6136
6136
} /* dump_selected_tables */
6137
6137
6138
6138
6139
+ const char fmt_gtid_pos []= "%sSET GLOBAL gtid_slave_pos='%s';\n" ;
6140
+
6139
6141
static int do_show_master_status (MYSQL * mysql_con , int consistent_binlog_pos ,
6140
- int have_mariadb_gtid , int use_gtid )
6142
+ int have_mariadb_gtid , int use_gtid ,
6143
+ char * set_gtid_pos )
6141
6144
{
6142
6145
MYSQL_ROW row ;
6143
6146
MYSQL_RES * UNINIT_VAR (master );
@@ -6198,15 +6201,21 @@ static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos,
6198
6201
/* gtid */
6199
6202
if (have_mariadb_gtid )
6200
6203
{
6201
- print_comment (md_result_file , 0 ,
6202
- "\n-- Preferably use GTID to start replication from GTID "
6203
- "position:\n\n" );
6204
6204
if (use_gtid )
6205
+ {
6205
6206
fprintf (md_result_file ,
6206
6207
"%sCHANGE MASTER TO MASTER_USE_GTID=slave_pos;\n" ,
6207
6208
comment_prefix );
6208
- fprintf (md_result_file ,
6209
- "%sSET GLOBAL gtid_slave_pos='%s';\n" ,
6209
+ /*
6210
+ When --gtid is specified defer print of SET gtid_slave_pos until
6211
+ after its placeholder table is guaranteed to have been dumped.
6212
+ */
6213
+ print_comment (md_result_file , 0 ,
6214
+ "\n-- A corresponding to the above master-data "
6215
+ "CHANGE-MASTER settings to the slave gtid state is printed "
6216
+ "later in the file.\n" );
6217
+ }
6218
+ sprintf (set_gtid_pos , fmt_gtid_pos ,
6210
6219
(!use_gtid ? "-- " : comment_prefix ), gtid_pos );
6211
6220
}
6212
6221
@@ -6222,6 +6231,11 @@ static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos,
6222
6231
fprintf (md_result_file ,
6223
6232
"%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n" ,
6224
6233
(use_gtid ? "-- " : comment_prefix ), file , offset );
6234
+ if (have_mariadb_gtid && !use_gtid )
6235
+ print_comment (md_result_file , 0 ,
6236
+ "\n-- A corresponding to the above master-data CHANGE-MASTER "
6237
+ "settings to the slave gtid state is printed as comments "
6238
+ "later in the file.\n" );
6225
6239
check_io (md_result_file );
6226
6240
6227
6241
if (!consistent_binlog_pos )
@@ -6291,8 +6305,8 @@ static int add_slave_statements(void)
6291
6305
return (0 );
6292
6306
}
6293
6307
6294
- static int do_show_slave_status (MYSQL * mysql_con , int use_gtid ,
6295
- int have_mariadb_gtid )
6308
+ static int do_show_slave_status (MYSQL * mysql_con , int have_mariadb_gtid ,
6309
+ int use_gtid , char * set_gtid_pos )
6296
6310
{
6297
6311
MYSQL_RES * UNINIT_VAR (slave );
6298
6312
MYSQL_ROW row ;
@@ -6332,10 +6346,12 @@ static int do_show_slave_status(MYSQL *mysql_con, int use_gtid,
6332
6346
mysql_free_result (slave );
6333
6347
return 1 ;
6334
6348
}
6349
+ /* defer print similarly to do_show_master_status */
6335
6350
print_comment (md_result_file , 0 ,
6336
- "-- GTID position to start replication:\n" );
6337
- fprintf (md_result_file , "%sSET GLOBAL gtid_slave_pos='%s';\n" ,
6338
- gtid_comment_prefix , gtid_pos );
6351
+ "\n-- A corresponding to the below dump-slave "
6352
+ "CHANGE-MASTER settings to the slave gtid state is printed "
6353
+ "later in the file.\n" );
6354
+ sprintf (set_gtid_pos , fmt_gtid_pos , gtid_comment_prefix , gtid_pos );
6339
6355
}
6340
6356
if (use_gtid )
6341
6357
print_comment (md_result_file , 0 ,
@@ -7056,6 +7072,34 @@ static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size)
7056
7072
die (EX_MYSQLERR , DYNAMIC_STR_ERROR_MSG );
7057
7073
}
7058
7074
7075
+ /**
7076
+ Print earlier prepared SET @@global.gtid_slave_pos.
7077
+
7078
+ @param set_gtid_pos[in] formatted sql set statement
7079
+ **/
7080
+ static void do_print_set_gtid_slave_pos (const char * set_gtid_pos ,
7081
+ my_bool is_master_data )
7082
+ {
7083
+ DBUG_ASSERT (opt_master_data || opt_slave_data );
7084
+ if (is_master_data )
7085
+ {
7086
+ print_comment (md_result_file , 0 ,
7087
+ "\n-- The deferred gtid setting for slave corresponding to "
7088
+ "the master-data CHANGE-MASTER follows\n" );
7089
+ print_comment (md_result_file , 0 ,
7090
+ "\n-- Preferably use GTID to start replication from GTID "
7091
+ "position:\n\n" );
7092
+ }
7093
+ else
7094
+ {
7095
+ print_comment (md_result_file , 0 ,
7096
+ "\n-- The deferred gtid setting for slave corresponding to "
7097
+ "the dump-slave CHANGE-MASTER follows\n" );
7098
+ print_comment (md_result_file , 0 ,
7099
+ "-- GTID position to start replication:\n" );
7100
+ }
7101
+ fprintf (md_result_file , "%s" , set_gtid_pos );
7102
+ }
7059
7103
7060
7104
int main (int argc , char * * argv )
7061
7105
{
@@ -7064,6 +7108,12 @@ int main(int argc, char **argv)
7064
7108
int exit_code ;
7065
7109
int consistent_binlog_pos = 0 ;
7066
7110
int have_mariadb_gtid = 0 ;
7111
+ /*
7112
+ to hold SET @@global.gtid_slave_pos which is deferred to print
7113
+ until the function epilogue.
7114
+ */
7115
+ char master_set_gtid_pos [3 + sizeof (fmt_gtid_pos ) + MAX_GTID_LENGTH ]= {0 };
7116
+ char slave_set_gtid_pos [3 + sizeof (fmt_gtid_pos ) + MAX_GTID_LENGTH ]= {0 };
7067
7117
MY_INIT (argv [0 ]);
7068
7118
7069
7119
sf_leaking_memory = 1 ; /* don't report memory leaks on early exits */
@@ -7102,11 +7152,11 @@ int main(int argc, char **argv)
7102
7152
write_header (md_result_file , * argv );
7103
7153
7104
7154
/* Set MAX_STATEMENT_TIME to 0 unless set in client */
7105
- my_snprintf (query , sizeof (query ), "/*!100100 SET @@MAX_STATEMENT_TIME=%f */" , opt_max_statement_time );
7155
+ my_snprintf (query , sizeof (query ), "/*M !100100 SET @@MAX_STATEMENT_TIME=%f */" , opt_max_statement_time );
7106
7156
mysql_query (mysql , query );
7107
7157
7108
7158
/* Set server side timeout between client commands to server compiled-in default */
7109
- mysql_query (mysql , "/*!100100 SET WAIT_TIMEOUT=DEFAULT */" );
7159
+ mysql_query (mysql , "/*M !100100 SET WAIT_TIMEOUT=DEFAULT */" );
7110
7160
7111
7161
/* Check if the server support multi source */
7112
7162
if (mysql_get_server_version (mysql ) >= 100000 )
@@ -7167,10 +7217,12 @@ int main(int argc, char **argv)
7167
7217
goto err ;
7168
7218
7169
7219
if (opt_master_data && do_show_master_status (mysql , consistent_binlog_pos ,
7170
- have_mariadb_gtid , opt_use_gtid ))
7220
+ have_mariadb_gtid ,
7221
+ opt_use_gtid , master_set_gtid_pos ))
7171
7222
goto err ;
7172
- if (opt_slave_data && do_show_slave_status (mysql , opt_use_gtid ,
7173
- have_mariadb_gtid ))
7223
+ if (opt_slave_data && do_show_slave_status (mysql ,
7224
+ have_mariadb_gtid ,
7225
+ opt_use_gtid , slave_set_gtid_pos ))
7174
7226
goto err ;
7175
7227
if (opt_single_transaction && do_unlock_tables (mysql )) /* unlock but no commit! */
7176
7228
goto err ;
@@ -7238,6 +7290,11 @@ int main(int argc, char **argv)
7238
7290
if (opt_system & OPT_SYSTEM_TIMEZONES )
7239
7291
dump_all_timezones ();
7240
7292
7293
+ if (opt_master_data && master_set_gtid_pos [0 ])
7294
+ do_print_set_gtid_slave_pos (master_set_gtid_pos , TRUE);
7295
+ if (opt_slave_data && slave_set_gtid_pos [0 ])
7296
+ do_print_set_gtid_slave_pos (slave_set_gtid_pos , FALSE);
7297
+
7241
7298
/* add 'START SLAVE' to end of dump */
7242
7299
if (opt_slave_apply && add_slave_statements ())
7243
7300
goto err ;
0 commit comments