1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-25477 Auto-create breaks replication when triggering event was not replicated

If UPDATE/DELETE does not change data it is skipped from
replication. We now force replication of such events when they trigger
partition auto-creation.

For ROLLBACK it is as simple as set OPTION_KEEP_LOG
flag. trans_cannot_safely_rollback() does the rest.

For UPDATE/DELETE .. LIMIT 0 we make additional binlog_query() calls
at the early points of return.

As a safety measure we also convert row format into statement if it is
needed. The condition is decided by
binlog_need_stmt_format(). Basically if there are some row events in
cache we don't need that: table open of row event will trigger
auto-creation anyway.

Multi-update/delete works via mysql_select(). There is no early points
of return, so binlogging is always checked by
send_eof()/abort_resultset(). But we must comply with the above
measure of converting into statement.
This commit is contained in:
Aleksey Midenkov
2022-05-06 10:45:18 +03:00
parent 92bfc0e8c4
commit 706a8232da
9 changed files with 438 additions and 44 deletions

View File

@ -450,6 +450,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
*/
has_triggers= table->triggers && table->triggers->has_delete_triggers();
transactional_table= table->file->has_transactions_and_rollback();
if (!returning && !using_limit && const_cond_result &&
(!thd->is_current_stmt_binlog_format_row() && !has_triggers)
@ -508,6 +509,9 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
if (thd->lex->describe || thd->lex->analyze_stmt)
goto produce_explain_and_leave;
if (thd->binlog_for_noop_dml(transactional_table))
DBUG_RETURN(1);
my_ok(thd, 0);
DBUG_RETURN(0);
}
@ -538,6 +542,10 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
*/
if (unlikely(thd->is_error()))
DBUG_RETURN(TRUE);
if (thd->binlog_for_noop_dml(transactional_table))
DBUG_RETURN(1);
my_ok(thd, 0);
DBUG_RETURN(0); // Nothing to delete
}
@ -916,14 +924,14 @@ cleanup:
deltempfile=NULL;
delete select;
select= NULL;
transactional_table= table->file->has_transactions_and_rollback();
if (!transactional_table && deleted > 0)
thd->transaction->stmt.modified_non_trans_table=
thd->transaction->all.modified_non_trans_table= TRUE;
/* See similar binlogging code in sql_update.cc, for comments */
if (likely((error < 0) || thd->transaction->stmt.modified_non_trans_table))
if (likely((error < 0) || thd->transaction->stmt.modified_non_trans_table
|| thd->log_current_statement()))
{
if (WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open())
{
@ -933,8 +941,8 @@ cleanup:
else
errcode= query_error_code(thd, killed_status == NOT_KILLED);
ScopedStatementReplication scoped_stmt_rpl(
table->versioned(VERS_TRX_ID) ? thd : NULL);
StatementBinlog stmt_binlog(thd, table->versioned(VERS_TRX_ID) ||
thd->binlog_need_stmt_format(transactional_table));
/*
[binlog]: If 'handler::delete_all_rows()' was called and the
storage engine does not inject the rows itself, we replicate
@ -1438,13 +1446,15 @@ void multi_delete::abort_result_set()
DBUG_VOID_RETURN;
}
if (thd->transaction->stmt.modified_non_trans_table)
if (thd->transaction->stmt.modified_non_trans_table ||
thd->log_current_statement())
{
/*
there is only side effects; to binlog with the error
*/
if (WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open())
{
StatementBinlog stmt_binlog(thd, thd->binlog_need_stmt_format(transactional_tables));
int errcode= query_error_code(thd, thd->killed == NOT_KILLED);
/* possible error of writing binary log is ignored deliberately */
(void) thd->binlog_query(THD::ROW_QUERY_TYPE,
@ -1618,7 +1628,8 @@ bool multi_delete::send_eof()
query_cache_invalidate3(thd, delete_tables, 1);
}
if (likely((local_error == 0) ||
thd->transaction->stmt.modified_non_trans_table))
thd->transaction->stmt.modified_non_trans_table) ||
thd->log_current_statement())
{
if(WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open())
{
@ -1628,6 +1639,7 @@ bool multi_delete::send_eof()
else
errcode= query_error_code(thd, killed_status == NOT_KILLED);
thd->thread_specific_used= TRUE;
StatementBinlog stmt_binlog(thd, thd->binlog_need_stmt_format(transactional_tables));
if (unlikely(thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query(), thd->query_length(),
transactional_tables, FALSE, FALSE,