mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
BUG#37148 Most callers of mysql_bin_log.write ignore the return result
This is the non-ndb part of the patch. The return value of mysql_bin_log.write was ignored by most callers, which may lead to inconsistent on master and slave if the transaction was committed while the binlog was not correctly written. If my_error() is call in mysql_bin_log.write, this could also lead to assertion issue if my_ok() or my_error() is called after. This fixed the problem by let the caller to check and handle the return value of mysql_bin_log.write. This patch only adresses the simple cases. mysql-test/include/binlog_inject_error.inc: inject binlog write error when doing a query mysql-test/suite/binlog/t/binlog_write_error.test: Simple test case to check if proper error is reported when injecting binlog write errors. sql/events.cc: check return value of mysql_bin_log.write sql/log.cc: check return value of mysql_bin_log.write sql/log_event.cc: check return value of mysql_bin_log.write sql/log_event_old.cc: check return value of mysql_bin_log.write sql/mysql_priv.h: Change write_bin_log to return int instead of void sql/rpl_injector.cc: check return value of writing binlog sql/sp.cc: check return value of writing binlog sql/sp_head.cc: return 1 if writing binlog failed sql/sql_acl.cc: check return value of writing binlog sql/sql_base.cc: check return value of writing binlog sql/sql_class.h: Change binlog_show_create_table to return int sql/sql_db.cc: Change write_to_binlog to return int check return value of writing binlog sql/sql_delete.cc: check return value of writing binlog sql/sql_insert.cc: check return value of writing binlog sql/sql_load.cc: check return value of writing binlog sql/sql_parse.cc: check return value of writing binlog sql/sql_partition.cc: check return value of writing binlog sql/sql_rename.cc: check return value of writing binlog sql/sql_repl.cc: check return value of writing binlog sql/sql_table.cc: Change write_bin_log to return int, and return 1 if there was error writing binlog sql/sql_tablespace.cc: check return value of writing binlog sql/sql_trigger.cc: check return value of writing binlog sql/sql_udf.cc: check return value of writing binlog sql/sql_update.cc: check return value of writing binlog sql/sql_view.cc: check return value of writing binlog
This commit is contained in:
@@ -2734,10 +2734,11 @@ bool Delayed_insert::handle_inserts(void)
|
||||
will be binlogged together as one single Table_map event and one
|
||||
single Rows event.
|
||||
*/
|
||||
thd.binlog_query(THD::ROW_QUERY_TYPE,
|
||||
row->query.str, row->query.length,
|
||||
FALSE, FALSE, errcode);
|
||||
|
||||
if (thd.binlog_query(THD::ROW_QUERY_TYPE,
|
||||
row->query.str, row->query.length,
|
||||
FALSE, FALSE, errcode))
|
||||
goto err;
|
||||
|
||||
thd.time_zone_used = backup_time_zone_used;
|
||||
thd.variables.time_zone = backup_time_zone;
|
||||
}
|
||||
@@ -2811,8 +2812,9 @@ bool Delayed_insert::handle_inserts(void)
|
||||
|
||||
TODO: Move the logging to last in the sequence of rows.
|
||||
*/
|
||||
if (thd.current_stmt_binlog_row_based)
|
||||
thd.binlog_flush_pending_rows_event(TRUE);
|
||||
if (thd.current_stmt_binlog_row_based &&
|
||||
thd.binlog_flush_pending_rows_event(TRUE))
|
||||
goto err;
|
||||
|
||||
if ((error=table->file->extra(HA_EXTRA_NO_CACHE)))
|
||||
{ // This shouldn't happen
|
||||
@@ -3265,16 +3267,21 @@ bool select_insert::send_eof()
|
||||
events are in the transaction cache and will be written when
|
||||
ha_autocommit_or_rollback() is issued below.
|
||||
*/
|
||||
if (mysql_bin_log.is_open())
|
||||
if (mysql_bin_log.is_open() &&
|
||||
(!error || thd->transaction.stmt.modified_non_trans_table))
|
||||
{
|
||||
int errcode= 0;
|
||||
if (!error)
|
||||
thd->clear_error();
|
||||
else
|
||||
errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
|
||||
thd->binlog_query(THD::ROW_QUERY_TYPE,
|
||||
if (thd->binlog_query(THD::ROW_QUERY_TYPE,
|
||||
thd->query(), thd->query_length(),
|
||||
trans_table, FALSE, errcode);
|
||||
trans_table, FALSE, errcode))
|
||||
{
|
||||
table->file->ha_release_auto_increment();
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
}
|
||||
table->file->ha_release_auto_increment();
|
||||
|
||||
@@ -3345,9 +3352,10 @@ void select_insert::abort() {
|
||||
if (mysql_bin_log.is_open())
|
||||
{
|
||||
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
|
||||
thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query(),
|
||||
thd->query_length(),
|
||||
transactional_table, FALSE, errcode);
|
||||
/* error of writing binary log is ignored */
|
||||
(void) thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query(),
|
||||
thd->query_length(),
|
||||
transactional_table, FALSE, errcode);
|
||||
}
|
||||
if (!thd->current_stmt_binlog_row_based && !can_rollback_data())
|
||||
thd->transaction.all.modified_non_trans_table= TRUE;
|
||||
@@ -3602,7 +3610,8 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
|
||||
!table->s->tmp_table &&
|
||||
!ptr->get_create_info()->table_existed)
|
||||
{
|
||||
ptr->binlog_show_create_table(tables, count);
|
||||
if (int error= ptr->binlog_show_create_table(tables, count))
|
||||
return error;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -3709,7 +3718,7 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
select_create::binlog_show_create_table(TABLE **tables, uint count)
|
||||
{
|
||||
/*
|
||||
@@ -3748,12 +3757,13 @@ select_create::binlog_show_create_table(TABLE **tables, uint count)
|
||||
if (mysql_bin_log.is_open())
|
||||
{
|
||||
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
|
||||
thd->binlog_query(THD::STMT_QUERY_TYPE,
|
||||
query.ptr(), query.length(),
|
||||
/* is_trans */ TRUE,
|
||||
/* suppress_use */ FALSE,
|
||||
errcode);
|
||||
result= thd->binlog_query(THD::STMT_QUERY_TYPE,
|
||||
query.ptr(), query.length(),
|
||||
/* is_trans */ TRUE,
|
||||
/* suppress_use */ FALSE,
|
||||
errcode);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void select_create::store_values(List<Item> &values)
|
||||
@@ -3851,7 +3861,8 @@ void select_create::abort()
|
||||
select_insert::abort();
|
||||
thd->transaction.stmt.modified_non_trans_table= FALSE;
|
||||
reenable_binlog(thd);
|
||||
thd->binlog_flush_pending_rows_event(TRUE);
|
||||
/* possible error of writing binary log is ignored deliberately */
|
||||
(void)thd->binlog_flush_pending_rows_event(TRUE);
|
||||
|
||||
if (m_plock)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user