mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-22925 ALTER TABLE s3_table ENGINE=Aria can cause failure on slave
When converting a table (test.s3_table) from S3 to another engine, the following will be logged to the binary log: DROP TABLE IF EXISTS test.t1; CREATE OR REPLACE TABLE test.t1 (...) ENGINE=new_engine INSERT rows to test.t1 in binary-row-log-format The bug is that the above statements are logged one by one to the binary log. This means that a fast slave, configured to use the same S3 storage as the master, would be able to execute the DROP and CREATE from the binary log before the master has finished the ALTER TABLE. In this case the slave would ignore the DROP (as it's on a S3 table) but it will stop on CREATE of the local tale, as the table is still exists in S3. The REPLACE part will be ignored by the slave as it can't touch the S3 table. The fix is to ensure that all the above statements is written to binary log AFTER the table has been deleted from S3.
This commit is contained in:
@ -77,7 +77,6 @@
|
||||
#include "sql_audit.h"
|
||||
#include "sql_derived.h" // mysql_handle_derived
|
||||
#include "sql_prepare.h"
|
||||
#include "rpl_filter.h" // binlog_filter
|
||||
#include <my_bit.h>
|
||||
|
||||
#include "debug_sync.h"
|
||||
@ -4796,8 +4795,12 @@ static int binlog_show_create_table(THD *thd, TABLE *table,
|
||||
to a not shared table.
|
||||
*/
|
||||
|
||||
bool binlog_create_table(THD *thd, TABLE *table)
|
||||
bool binlog_create_table(THD *thd, TABLE *table, bool replace)
|
||||
{
|
||||
Table_specification_st create_info;
|
||||
bool result;
|
||||
ulonglong save_option_bits;
|
||||
|
||||
/* Don't log temporary tables in row format */
|
||||
if (thd->variables.binlog_format == BINLOG_FORMAT_ROW &&
|
||||
table->s->tmp_table)
|
||||
@ -4811,7 +4814,19 @@ bool binlog_create_table(THD *thd, TABLE *table)
|
||||
*/
|
||||
thd->set_current_stmt_binlog_format_row();
|
||||
table->file->prepare_for_row_logging();
|
||||
return binlog_show_create_table(thd, table, 0) != 0;
|
||||
|
||||
create_info.lex_start();
|
||||
save_option_bits= thd->variables.option_bits;
|
||||
if (replace)
|
||||
create_info.set(DDL_options_st::OPT_OR_REPLACE);
|
||||
/* Ensure we write ENGINE=xxx and CHARSET=... to binary log */
|
||||
create_info.used_fields|= (HA_CREATE_USED_ENGINE |
|
||||
HA_CREATE_USED_DEFAULT_CHARSET);
|
||||
/* Ensure we write all engine options to binary log */
|
||||
create_info.used_fields|= HA_CREATE_PRINT_ALL_OPTIONS;
|
||||
result= binlog_show_create_table(thd, table, &create_info) != 0;
|
||||
thd->variables.option_bits= save_option_bits;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user