mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Backport Bug#37148 to 5.1
This commit is contained in:
@ -1748,9 +1748,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;
|
||||
@ -1758,9 +1759,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;
|
||||
}
|
||||
|
||||
|
||||
@ -2106,7 +2108,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)
|
||||
@ -2128,7 +2130,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());
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2147,7 +2149,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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -3556,9 +3558,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:
|
||||
@ -3571,7 +3573,8 @@ 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());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -3837,8 +3840,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);
|
||||
@ -3959,8 +3961,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));
|
||||
|
||||
@ -3975,7 +3976,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;
|
||||
}
|
||||
|
||||
@ -5448,18 +5449,20 @@ 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;
|
||||
|
||||
@ -5547,7 +5550,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);
|
||||
@ -6558,11 +6561,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:
|
||||
@ -6810,8 +6815,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)
|
||||
{
|
||||
@ -7299,8 +7305,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;
|
||||
}
|
||||
|
||||
@ -7463,7 +7470,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))
|
||||
{
|
||||
|
Reference in New Issue
Block a user