mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Merge the following patch from MySQL 5.6.10, in order to make perfschema.binlog_* tests work.
revno: 4559 committer: Marc Alff <marc.alff@oracle.com> branch nick: mysql-5.6-bug14741537-v4 timestamp: Thu 2012-11-08 22:40:31 +0100 message: Bug#14741537 - MYSQL 5.6, GTID AND PERFORMANCE_SCHEMA Before this fix, statements using performance_schema tables: - were marked as unsafe for replication, - did cause warnings during execution, - were written to the binlog, either in STATEMENT or ROW format. When using replication with the new GTID feature, unsafe warnings are elevated to errors, which prevents to use both the performance_schema and GTID together. The root cause of the problem is not related to raising warnings/errors in some special cases, but deeper: statements involving the performance schema should not even be written to the binary log in the first place, because the content of the performance schema tables is 'local' to a server instance, and may differ greatly between nodes in a replication topology. In particular, the DBA should be able to configure (INSERT, UPDATE, DELETE) or flush (TRUNCATE) performance schema tables on one node, without affecting other nodes. This fix introduces the concept of a 'non-replicated' or 'local' table, and adjusts the replication logic to ignore tables that are not replicated when deciding if or how to log a statement to the binlog. Note that while this issue was detected using the performance_schema, other tables are also affected by the same problem. This fix define as 'local' the following tables, which are then never replicated: - performance_schema.* - mysql.general_log - mysql.slow_log - mysql.slave_relay_log_info - mysql.slave_master_info - mysql.slave_worker_info Existing behavior for information_schema.* is unchanged by this fix, to limit the scope of changes. Coding wise, this fix implements the following changes: 1) Performance schema tables are not using any replication flags, since performance schema tables are not replicated. 2) In open_table_from_share(), tables with no replication capabilities (performance_schema.*), tables with TABLE_CATEGORY_LOG (logs) and tables with TABLE_CATEGORY_RPL_INFO (replication) are marked as non replicated, with TABLE::no_replicate 3) A new THD member, THD::m_binlog_filter_state, indicate if the current statement is written to the binlog (normal cases for most statements), or is to be discarded (because the statements affects non replicated tables). 4) In THD::decide_logging_format(), the replication logic is changed to take into account non replicated tables. Statements that affect only non replicated tables are executed normally (no warning or errors), but not written to the binlog. Statements that affect (i.e., write to) a replicated table while also using (i.e., reading from or writing to) a non replicated table are executed normally in MIXED and ROW binlog format, and cause a new error in STATEMENT binlog format. THD::decide_logging_format() uses THD::m_binlog_filter_state to indicate if a statement is to be ignored, when writing to the binlog. 5) In THD::binlog_query(), statements marked as ignored are not written to the binary log. 6) For row based replication, the existing test for 'table->no_replicate', has been moved from binlog_log_row() to check_table_binlog_row_based().
This commit is contained in:
@@ -1314,6 +1314,7 @@ void THD::init(void)
|
||||
tx_read_only= variables.tx_read_only;
|
||||
update_charset();
|
||||
reset_current_stmt_binlog_format_row();
|
||||
reset_binlog_local_stmt_filter();
|
||||
set_status_var_init();
|
||||
bzero((char *) &org_status_var, sizeof(org_status_var));
|
||||
|
||||
@@ -1972,6 +1973,14 @@ void THD::cleanup_after_query()
|
||||
auto_inc_intervals_in_cur_stmt_for_binlog.empty();
|
||||
rand_used= 0;
|
||||
}
|
||||
/*
|
||||
Forget the binlog stmt filter for the next query.
|
||||
There are some code paths that:
|
||||
- do not call THD::decide_logging_format()
|
||||
- do call THD::binlog_query(),
|
||||
making this reset necessary.
|
||||
*/
|
||||
reset_binlog_local_stmt_filter();
|
||||
if (first_successful_insert_id_in_cur_stmt > 0)
|
||||
{
|
||||
/* set what LAST_INSERT_ID() will return */
|
||||
@@ -4916,6 +4925,8 @@ int THD::decide_logging_format(TABLE_LIST *tables)
|
||||
DBUG_PRINT("info", ("lex->get_stmt_unsafe_flags(): 0x%x",
|
||||
lex->get_stmt_unsafe_flags()));
|
||||
|
||||
reset_binlog_local_stmt_filter();
|
||||
|
||||
/*
|
||||
We should not decide logging format if the binlog is closed or
|
||||
binlogging is off, or if the statement is filtered out from the
|
||||
@@ -4958,6 +4969,28 @@ int THD::decide_logging_format(TABLE_LIST *tables)
|
||||
A pointer to a previous table that was accessed.
|
||||
*/
|
||||
TABLE* prev_access_table= NULL;
|
||||
/**
|
||||
The number of tables used in the current statement,
|
||||
that should be replicated.
|
||||
*/
|
||||
uint replicated_tables_count= 0;
|
||||
/**
|
||||
The number of tables written to in the current statement,
|
||||
that should not be replicated.
|
||||
A table should not be replicated when it is considered
|
||||
'local' to a MySQL instance.
|
||||
Currently, these tables are:
|
||||
- mysql.slow_log
|
||||
- mysql.general_log
|
||||
- mysql.slave_relay_log_info
|
||||
- mysql.slave_master_info
|
||||
- mysql.slave_worker_info
|
||||
- performance_schema.*
|
||||
- TODO: information_schema.*
|
||||
In practice, from this list, only performance_schema.* tables
|
||||
are written to by user queries.
|
||||
*/
|
||||
uint non_replicated_tables_count= 0;
|
||||
|
||||
#ifndef DBUG_OFF
|
||||
{
|
||||
@@ -4980,14 +5013,38 @@ int THD::decide_logging_format(TABLE_LIST *tables)
|
||||
if (table->placeholder())
|
||||
continue;
|
||||
|
||||
if (table->table->s->table_category == TABLE_CATEGORY_PERFORMANCE ||
|
||||
table->table->s->table_category == TABLE_CATEGORY_LOG)
|
||||
lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_TABLE);
|
||||
|
||||
handler::Table_flags const flags= table->table->file->ha_table_flags();
|
||||
|
||||
DBUG_PRINT("info", ("table: %s; ha_table_flags: 0x%llx",
|
||||
table->table_name, flags));
|
||||
|
||||
if (table->table->no_replicate)
|
||||
{
|
||||
/*
|
||||
The statement uses a table that is not replicated.
|
||||
The following properties about the table:
|
||||
- persistent / transient
|
||||
- transactional / non transactional
|
||||
- temporary / permanent
|
||||
- read or write
|
||||
- multiple engines involved because of this table
|
||||
are not relevant, as this table is completely ignored.
|
||||
Because the statement uses a non replicated table,
|
||||
using STATEMENT format in the binlog is impossible.
|
||||
Either this statement will be discarded entirely,
|
||||
or it will be logged (possibly partially) in ROW format.
|
||||
*/
|
||||
lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_TABLE);
|
||||
|
||||
if (table->lock_type >= TL_WRITE_ALLOW_WRITE)
|
||||
{
|
||||
non_replicated_tables_count++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
replicated_tables_count++;
|
||||
|
||||
if (table->lock_type >= TL_WRITE_ALLOW_WRITE)
|
||||
{
|
||||
if (prev_write_table && prev_write_table->file->ht !=
|
||||
@@ -5163,6 +5220,30 @@ int THD::decide_logging_format(TABLE_LIST *tables)
|
||||
}
|
||||
}
|
||||
|
||||
if (non_replicated_tables_count > 0)
|
||||
{
|
||||
if ((replicated_tables_count == 0) || ! is_write)
|
||||
{
|
||||
DBUG_PRINT("info", ("decision: no logging, no replicated table affected"));
|
||||
set_binlog_local_stmt_filter();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! is_current_stmt_binlog_format_row())
|
||||
{
|
||||
my_error((error= ER_BINLOG_STMT_MODE_AND_NO_REPL_TABLES), MYF(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
clear_binlog_local_stmt_filter();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clear_binlog_local_stmt_filter();
|
||||
}
|
||||
|
||||
if (error) {
|
||||
DBUG_PRINT("info", ("decision: no logging since an error was generated"));
|
||||
DBUG_RETURN(-1);
|
||||
@@ -5788,6 +5869,15 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
|
||||
show_query_type(qtype), (int) query_len, query_arg));
|
||||
DBUG_ASSERT(query_arg && mysql_bin_log.is_open());
|
||||
|
||||
if (get_binlog_local_stmt_filter() == BINLOG_FILTER_SET)
|
||||
{
|
||||
/*
|
||||
The current statement is to be ignored, and not written to
|
||||
the binlog. Do not call issue_unsafe_warnings().
|
||||
*/
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
/*
|
||||
If we are not in prelocked mode, mysql_unlock_tables() will be
|
||||
called after this binlog_query(), so we have to flush the pending
|
||||
|
||||
Reference in New Issue
Block a user