diff options
author | He Zhenxing <zhenxing.he@sun.com> | 2009-11-21 12:28:01 +0800 |
---|---|---|
committer | He Zhenxing <zhenxing.he@sun.com> | 2009-11-21 12:28:01 +0800 |
commit | dd383cadec0fbfba626bba72051f2dc548171015 (patch) | |
tree | 33edb6115f37aa26c592dd1aa99a17b195511f5e /sql/sql_table.cc | |
parent | 27fca0ab1775a8c1dfe699c978b6448a7aa8f47b (diff) | |
download | mariadb-git-dd383cadec0fbfba626bba72051f2dc548171015.tar.gz |
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
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r-- | sql/sql_table.cc | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc index cc46dc1ae7a..2bfcabb957e 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1735,9 +1735,10 @@ end: file */ -void write_bin_log(THD *thd, bool clear_error, - char const *query, ulong query_length) +int write_bin_log(THD *thd, bool clear_error, + char const *query, ulong query_length) { + int error= 0; if (mysql_bin_log.is_open()) { int errcode= 0; @@ -1745,9 +1746,10 @@ void write_bin_log(THD *thd, bool clear_error, thd->clear_error(); else errcode= query_error_code(thd, TRUE); - thd->binlog_query(THD::STMT_QUERY_TYPE, - query, query_length, FALSE, FALSE, errcode); + error= thd->binlog_query(THD::STMT_QUERY_TYPE, + query, query_length, FALSE, FALSE, errcode); } + return error; } @@ -2099,7 +2101,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, tables). In this case, we can write the original query into the binary log. */ - write_bin_log(thd, !error, thd->query(), thd->query_length()); + error |= write_bin_log(thd, !error, thd->query(), thd->query_length()); } else if (thd->current_stmt_binlog_row_based && tmp_table_deleted) @@ -2121,7 +2123,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, */ built_query.chop(); // Chop of the last comma built_query.append(" /* generated by server */"); - write_bin_log(thd, !error, built_query.ptr(), built_query.length()); + error|= write_bin_log(thd, !error, built_query.ptr(), built_query.length()); } /* @@ -2140,7 +2142,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, */ built_tmp_query.chop(); // Chop of the last comma built_tmp_query.append(" /* generated by server */"); - write_bin_log(thd, !error, built_tmp_query.ptr(), built_tmp_query.length()); + error|= write_bin_log(thd, !error, built_tmp_query.ptr(), built_tmp_query.length()); } } @@ -3581,9 +3583,9 @@ void sp_prepare_create_field(THD *thd, Create_field *sql_field) RETURN VALUES NONE */ -static inline void write_create_table_bin_log(THD *thd, - const HA_CREATE_INFO *create_info, - bool internal_tmp_table) +static inline int write_create_table_bin_log(THD *thd, + const HA_CREATE_INFO *create_info, + bool internal_tmp_table) { /* Don't write statement if: @@ -3596,7 +3598,7 @@ static inline void write_create_table_bin_log(THD *thd, (!thd->current_stmt_binlog_row_based || (thd->current_stmt_binlog_row_based && !(create_info->options & HA_LEX_CREATE_TMP_TABLE)))) - write_bin_log(thd, TRUE, thd->query(), thd->query_length()); + return write_bin_log(thd, TRUE, thd->query(), thd->query_length()); } @@ -3865,8 +3867,7 @@ bool mysql_create_table_no_lock(THD *thd, push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), alias); - error= 0; - write_create_table_bin_log(thd, create_info, internal_tmp_table); + error= write_create_table_bin_log(thd, create_info, internal_tmp_table); goto err; } my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alias); @@ -3987,8 +3988,7 @@ bool mysql_create_table_no_lock(THD *thd, thd->thread_specific_used= TRUE; } - write_create_table_bin_log(thd, create_info, internal_tmp_table); - error= FALSE; + error= write_create_table_bin_log(thd, create_info, internal_tmp_table); unlock_and_end: VOID(pthread_mutex_unlock(&LOCK_open)); @@ -4003,7 +4003,7 @@ warn: ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), alias); create_info->table_existed= 1; // Mark that table existed - write_create_table_bin_log(thd, create_info, internal_tmp_table); + error= write_create_table_bin_log(thd, create_info, internal_tmp_table); goto unlock_and_end; } @@ -5470,17 +5470,19 @@ binlog: create_info, FALSE /* show_database */); DBUG_ASSERT(result == 0); // store_create_info() always return 0 - write_bin_log(thd, TRUE, query.ptr(), query.length()); + if (write_bin_log(thd, TRUE, query.ptr(), query.length())) + goto err; } else // Case 1 - write_bin_log(thd, TRUE, thd->query(), thd->query_length()); + if (write_bin_log(thd, TRUE, thd->query(), thd->query_length())) + goto err; } /* Case 3 and 4 does nothing under RBR */ } - else - write_bin_log(thd, TRUE, thd->query(), thd->query_length()); + else if (write_bin_log(thd, TRUE, thd->query(), thd->query_length())) + goto err; res= FALSE; @@ -5568,7 +5570,7 @@ mysql_discard_or_import_tablespace(THD *thd, error=1; if (error) goto err; - write_bin_log(thd, FALSE, thd->query(), thd->query_length()); + error= write_bin_log(thd, FALSE, thd->query(), thd->query_length()); err: ha_autocommit_or_rollback(thd, error); @@ -6620,11 +6622,13 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, thd->clear_error(); Query_log_event qinfo(thd, thd->query(), thd->query_length(), 0, FALSE, 0); - mysql_bin_log.write(&qinfo); + if (error= mysql_bin_log.write(&qinfo)) + goto view_err_unlock; } my_ok(thd); } +view_err_unlock: unlock_table_names(thd, table_list, (TABLE_LIST*) 0); view_err: @@ -6872,8 +6876,9 @@ view_err: if (!error) { - write_bin_log(thd, TRUE, thd->query(), thd->query_length()); - my_ok(thd); + error= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); + if (!error) + my_ok(thd); } else if (error > 0) { @@ -7361,8 +7366,9 @@ view_err: if (rename_temporary_table(thd, new_table, new_db, new_name)) goto err1; /* We don't replicate alter table statement on temporary tables */ - if (!thd->current_stmt_binlog_row_based) - write_bin_log(thd, TRUE, thd->query(), thd->query_length()); + if (!thd->current_stmt_binlog_row_based && + write_bin_log(thd, TRUE, thd->query(), thd->query_length())) + DBUG_RETURN(TRUE); goto end_temporary; } @@ -7525,7 +7531,8 @@ view_err: DBUG_ASSERT(!(mysql_bin_log.is_open() && thd->current_stmt_binlog_row_based && (create_info->options & HA_LEX_CREATE_TMP_TABLE))); - write_bin_log(thd, TRUE, thd->query(), thd->query_length()); + if (write_bin_log(thd, TRUE, thd->query(), thd->query_length())) + DBUG_RETURN(TRUE); if (ha_check_storage_engine_flag(old_db_type, HTON_FLUSH_AFTER_RENAME)) { |