2011-05-21 10:21:08 +02:00
|
|
|
/* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-27 02:23:51 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2011-05-21 10:21:08 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
#ifndef LOG_H
|
|
|
|
#define LOG_H
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "unireg.h" // REQUIRED: for other includes
|
|
|
|
#include "handler.h" /* my_xid */
|
|
|
|
|
2007-08-16 07:37:50 +02:00
|
|
|
class Relay_log_info;
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
class Format_description_log_event;
|
|
|
|
|
Manual merge of patch for Bug#46364 from mysql-next-mr-bugfixing.
Conflicts:
- mysql-test/r/mysqld--help-win.result
- sql/sys_vars.cc
Original revsion (in next-mr-bugfixing):
------------------------------------------------------------
revno: 2971 [merge]
revision-id: alfranio.correia@sun.com-20100121210527-rbuheu5rnsmcakh1
committer: Alfranio Correia <alfranio.correia@sun.com>
branch nick: mysql-next-mr-bugfixing
timestamp: Thu 2010-01-21 21:05:27 +0000
message:
BUG#46364 MyISAM transbuffer problems (NTM problem)
It is well-known that due to concurrency issues, a slave can become
inconsistent when a transaction contains updates to both transaction and
non-transactional tables.
In a nutshell, the current code-base tries to preserve causality among the
statements by writing non-transactional statements to the txn-cache which
is flushed upon commit. However, modifications done to non-transactional
tables on behalf of a transaction become immediately visible to other
connections but may not immediately get into the binary log and therefore
consistency may be broken.
In general, it is impossible to automatically detect causality/dependency
among statements by just analyzing the statements sent to the server. This
happen because dependency may be hidden in the application code and it is
necessary to know a priori all the statements processed in the context of
a transaction such as in a procedure. Moreover, even for the few cases that
we could automatically address in the server, the computation effort
required could make the approach infeasible.
So, in this patch we introduce the option
- "--binlog-direct-non-transactional-updates" that can be used to bypass
the current behavior in order to write directly to binary log statements
that change non-transactional tables.
Besides, it is used to enable the WL#2687 which is disabled by default.
------------------------------------------------------------
revno: 2970.1.1
revision-id: alfranio.correia@sun.com-20100121131034-183r4qdyld7an5a0
parent: alik@sun.com-20100121083914-r9rz2myto3tkdya0
committer: Alfranio Correia <alfranio.correia@sun.com>
branch nick: mysql-next-mr-bugfixing
timestamp: Thu 2010-01-21 13:10:34 +0000
message:
BUG#46364 MyISAM transbuffer problems (NTM problem)
It is well-known that due to concurrency issues, a slave can become
inconsistent when a transaction contains updates to both transaction and
non-transactional tables.
In a nutshell, the current code-base tries to preserve causality among the
statements by writing non-transactional statements to the txn-cache which
is flushed upon commit. However, modifications done to non-transactional
tables on behalf of a transaction become immediately visible to other
connections but may not immediately get into the binary log and therefore
consistency may be broken.
In general, it is impossible to automatically detect causality/dependency
among statements by just analyzing the statements sent to the server. This
happen because dependency may be hidden in the application code and it is
necessary to know a priori all the statements processed in the context of
a transaction such as in a procedure. Moreover, even for the few cases that
we could automatically address in the server, the computation effort
required could make the approach infeasible.
So, in this patch we introduce the option
- "--binlog-direct-non-transactional-updates" that can be used to bypass
the current behavior in order to write directly to binary log statements
that change non-transactional tables.
Besides, it is used to enable the WL#2687 which is disabled by default.
2010-02-02 08:56:42 +01:00
|
|
|
bool trans_has_updated_trans_table(const THD* thd);
|
|
|
|
bool stmt_has_updated_trans_table(const THD *thd);
|
|
|
|
bool use_trans_cache(const THD* thd, bool is_transactional);
|
BUG#51894 Replication failure with SBR on DROP TEMPORARY TABLE inside a
transaction
BUG#52616 Temp table prevents switch binlog format from STATEMENT to ROW
Before the WL#2687 and BUG#46364, every non-transactional change that happened
after a transactional change was written to trx-cache and flushed upon
committing the transaction. WL#2687 and BUG#46364 changed this behavior and
non-transactional changes are now written to the binary log upon committing
the statement.
A binary log event is identified as transactional or non-transactional through
a flag in the Log_event which is set taking into account the underlie storage
engine on what it is stems from. In the current bug, this flag was not being
set properly when the DROP TEMPORARY TABLE was executed.
However, while fixing this bug we figured out that changes to temporary tables
should be always written to the trx-cache if there is an on-going transaction.
Otherwise, binlog events in the reversed order would be produced.
Regarding concurrency, keeping changes to temporary tables in the trx-cache is
also safe as temporary tables are only visible to the owner connection.
In this patch, we classify the following statements as unsafe:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
On the other hand, the following statements are classified as safe:
1 - INSERT INTO t_innodb SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_innodb
The patch also guarantees that transactions that have a DROP TEMPORARY are
always written to the binary log regardless of the mode and the outcome:
commit or rollback. In particular, the DROP TEMPORARY is extended with the
IF EXISTS clause when the current statement logging format is set to row.
Finally, the patch allows to switch from STATEMENT to MIXED/ROW when there
are temporary tables but the contrary is not possible.
mysql-test/extra/rpl_tests/rpl_binlog_max_cache_size.test:
Updated the test case because
CREATE TEMPORARY TABLE t_innodb_temp SELECT * FROM t_myisam is not unsafe.
mysql-test/extra/rpl_tests/rpl_implicit_commit_binlog.test:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/extra/rpl_tests/rpl_innodb.test:
Removed comments from the test case that became false after the patch.
mysql-test/extra/rpl_tests/rpl_loaddata.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
mysql-test/include/ctype_utf8_table.inc:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
mysql-test/r/ctype_cp932_binlog_stm.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/r/binlog_database.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/r/binlog_innodb_row.result:
Updated the result file.
mysql-test/suite/binlog/r/binlog_multi_engine.result:
Updated the unsafe message.
mysql-test/suite/binlog/r/binlog_row_binlog.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/r/binlog_row_drop_tmp_tbl.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/r/binlog_stm_binlog.result:
Updated the result file.
mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/t/binlog_tmp_table.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
mysql-test/suite/ndb/r/ndb_binlog_format.result:
Updated the unsafe message.
mysql-test/suite/rpl/r/rpl_concurrency_error.result:
Updated the unsafe message.
mysql-test/suite/rpl/r/rpl_mixed_binlog_max_cache_size.result:
Updated the result file because
CREATE TEMPORARY TABLE t_innodb_temp SELECT * FROM t_myisam is not unsafe.
mysql-test/suite/rpl/r/rpl_mixed_implicit_commit_binlog.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_mixed_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_mixed_row_innodb.result:
Added some comments to ease the understanding of the result file.
mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_non_direct_row_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_non_direct_stm_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_row_drop.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_row_implicit_commit_binlog.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_row_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_stm_binlog_max_cache_size.result:
Updated the result file because
CREATE TEMPORARY TABLE t_innodb_temp SELECT * FROM t_myisam is not unsafe.
mysql-test/suite/rpl/r/rpl_stm_implicit_commit_binlog.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_stm_innodb.result:
Added some comments to ease the understanding of the result file.
mysql-test/suite/rpl/r/rpl_stm_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_stm_stop_middle_group.result:
Updated the unsafe message.
mysql-test/suite/rpl/r/rpl_temp_temporary.result:
Added a test case.
mysql-test/suite/rpl/t/rpl000013.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
mysql-test/suite/rpl/t/rpl_misc_functions.test:
Suppressed warning messages.
mysql-test/suite/rpl/t/rpl_temp_table.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
mysql-test/suite/rpl/t/rpl_temp_temporary.test:
Added a test case.
mysql-test/suite/rpl/t/rpl_temporary.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
mysql-test/suite/rpl_ndb/r/rpl_ndb_row_implicit_commit_binlog.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl_ndb/r/rpl_truncate_7ndb.result:
Updated the test case to remove references to positions
in the binary log.
mysql-test/suite/rpl_ndb/t/rpl_truncate_7ndb.test:
Updated the test case to remove references to positions
in the binary log.
mysql-test/t/create_select_tmp.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
mysql-test/t/ctype_cp932_binlog_stm.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
mysql-test/t/mysqlbinlog.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
sql/log.cc:
Improved the code by creating several functions to hide decision
on type of engine changed, commit/abort, etc:
. stmt_has_updated_non_trans_table
. trans_has_updated_non_trans_table
. ending_trans
Updated the binlog_rollback function and the use of the
OPTION_KEEP_LOG which indincates when a temporary table was
either created or dropped and as such the command must be
logged if not in MIXED mode and even while rolling back the
transaction.
sql/log.h:
Improved the code by creating several functions to hide decision
on type of engine changed, commit/abort, etc.
sql/log_event.cc:
Removed the setting of the OPTION_KEEP_LOG as it is related to CREATE
TEMPORARY and DROP TEMPORARY and not to the type of engine (i.e.
transactional or non-transactional).
sql/log_event_old.cc:
Removed the setting of the OPTION_KEEP_LOG as it is related to CREATE
TEMPORARY and DROP TEMPORARY and not to the type of engine (i.e.
transactional or non-transactional).
sql/share/errmsg-utf8.txt:
Updated the unsafe message.
sql/sql_class.cc:
Classifies the following statements as unsafe:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
On the other hand, the following statements are classified as safe:
1 - INSERT INTO t_innodb SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_innodb
sql/sql_class.h:
It allows to switch from STATEMENT to MIXED/ROW when there are temporary
tables but the contrary is not possible.
sql/sql_table.cc:
Fixed the case that a DROP/DROP TEMPORARY that affects a temporary table in MIXED
mode is written as a DROP TEMPORARY TABLE IF EXISTS because the table may not exist in the slave and due to the IF EXISTS token an error will never happen
while processing the statement in the slave.
Removed a function that was not being used.
2010-04-20 11:10:43 +02:00
|
|
|
bool ending_trans(THD* thd, const bool all);
|
2010-06-30 17:25:13 +02:00
|
|
|
bool ending_single_stmt_trans(THD* thd, const bool all);
|
BUG#51894 Replication failure with SBR on DROP TEMPORARY TABLE inside a
transaction
BUG#52616 Temp table prevents switch binlog format from STATEMENT to ROW
Before the WL#2687 and BUG#46364, every non-transactional change that happened
after a transactional change was written to trx-cache and flushed upon
committing the transaction. WL#2687 and BUG#46364 changed this behavior and
non-transactional changes are now written to the binary log upon committing
the statement.
A binary log event is identified as transactional or non-transactional through
a flag in the Log_event which is set taking into account the underlie storage
engine on what it is stems from. In the current bug, this flag was not being
set properly when the DROP TEMPORARY TABLE was executed.
However, while fixing this bug we figured out that changes to temporary tables
should be always written to the trx-cache if there is an on-going transaction.
Otherwise, binlog events in the reversed order would be produced.
Regarding concurrency, keeping changes to temporary tables in the trx-cache is
also safe as temporary tables are only visible to the owner connection.
In this patch, we classify the following statements as unsafe:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
On the other hand, the following statements are classified as safe:
1 - INSERT INTO t_innodb SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_innodb
The patch also guarantees that transactions that have a DROP TEMPORARY are
always written to the binary log regardless of the mode and the outcome:
commit or rollback. In particular, the DROP TEMPORARY is extended with the
IF EXISTS clause when the current statement logging format is set to row.
Finally, the patch allows to switch from STATEMENT to MIXED/ROW when there
are temporary tables but the contrary is not possible.
mysql-test/extra/rpl_tests/rpl_binlog_max_cache_size.test:
Updated the test case because
CREATE TEMPORARY TABLE t_innodb_temp SELECT * FROM t_myisam is not unsafe.
mysql-test/extra/rpl_tests/rpl_implicit_commit_binlog.test:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/extra/rpl_tests/rpl_innodb.test:
Removed comments from the test case that became false after the patch.
mysql-test/extra/rpl_tests/rpl_loaddata.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
mysql-test/include/ctype_utf8_table.inc:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
mysql-test/r/ctype_cp932_binlog_stm.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/r/binlog_database.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/r/binlog_innodb_row.result:
Updated the result file.
mysql-test/suite/binlog/r/binlog_multi_engine.result:
Updated the unsafe message.
mysql-test/suite/binlog/r/binlog_row_binlog.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/r/binlog_row_drop_tmp_tbl.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/r/binlog_stm_binlog.result:
Updated the result file.
mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/binlog/t/binlog_tmp_table.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
mysql-test/suite/ndb/r/ndb_binlog_format.result:
Updated the unsafe message.
mysql-test/suite/rpl/r/rpl_concurrency_error.result:
Updated the unsafe message.
mysql-test/suite/rpl/r/rpl_mixed_binlog_max_cache_size.result:
Updated the result file because
CREATE TEMPORARY TABLE t_innodb_temp SELECT * FROM t_myisam is not unsafe.
mysql-test/suite/rpl/r/rpl_mixed_implicit_commit_binlog.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_mixed_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_mixed_row_innodb.result:
Added some comments to ease the understanding of the result file.
mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_non_direct_row_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_non_direct_stm_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_row_drop.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_row_implicit_commit_binlog.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_row_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_stm_binlog_max_cache_size.result:
Updated the result file because
CREATE TEMPORARY TABLE t_innodb_temp SELECT * FROM t_myisam is not unsafe.
mysql-test/suite/rpl/r/rpl_stm_implicit_commit_binlog.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_stm_innodb.result:
Added some comments to ease the understanding of the result file.
mysql-test/suite/rpl/r/rpl_stm_mixing_engines.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl/r/rpl_stm_stop_middle_group.result:
Updated the unsafe message.
mysql-test/suite/rpl/r/rpl_temp_temporary.result:
Added a test case.
mysql-test/suite/rpl/t/rpl000013.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
mysql-test/suite/rpl/t/rpl_misc_functions.test:
Suppressed warning messages.
mysql-test/suite/rpl/t/rpl_temp_table.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
mysql-test/suite/rpl/t/rpl_temp_temporary.test:
Added a test case.
mysql-test/suite/rpl/t/rpl_temporary.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
mysql-test/suite/rpl_ndb/r/rpl_ndb_row_implicit_commit_binlog.result:
Updated the test case due to the new rules: changes to
temporary tables are written to the binary log in the
boundaries of a transaction if there is any.
mysql-test/suite/rpl_ndb/r/rpl_truncate_7ndb.result:
Updated the test case to remove references to positions
in the binary log.
mysql-test/suite/rpl_ndb/t/rpl_truncate_7ndb.test:
Updated the test case to remove references to positions
in the binary log.
mysql-test/t/create_select_tmp.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
mysql-test/t/ctype_cp932_binlog_stm.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
mysql-test/t/mysqlbinlog.test:
Suppressed warning messages due to the following cases:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
3 - CREATE TEMPORARY TABLE t_myisam_temp SELECT * FROM t_myisam
sql/log.cc:
Improved the code by creating several functions to hide decision
on type of engine changed, commit/abort, etc:
. stmt_has_updated_non_trans_table
. trans_has_updated_non_trans_table
. ending_trans
Updated the binlog_rollback function and the use of the
OPTION_KEEP_LOG which indincates when a temporary table was
either created or dropped and as such the command must be
logged if not in MIXED mode and even while rolling back the
transaction.
sql/log.h:
Improved the code by creating several functions to hide decision
on type of engine changed, commit/abort, etc.
sql/log_event.cc:
Removed the setting of the OPTION_KEEP_LOG as it is related to CREATE
TEMPORARY and DROP TEMPORARY and not to the type of engine (i.e.
transactional or non-transactional).
sql/log_event_old.cc:
Removed the setting of the OPTION_KEEP_LOG as it is related to CREATE
TEMPORARY and DROP TEMPORARY and not to the type of engine (i.e.
transactional or non-transactional).
sql/share/errmsg-utf8.txt:
Updated the unsafe message.
sql/sql_class.cc:
Classifies the following statements as unsafe:
1 - INSERT INTO t_myisam SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_myisam
On the other hand, the following statements are classified as safe:
1 - INSERT INTO t_innodb SELECT * FROM t_myisam_temp
2 - INSERT INTO t_myisam_temp SELECT * FROM t_innodb
sql/sql_class.h:
It allows to switch from STATEMENT to MIXED/ROW when there are temporary
tables but the contrary is not possible.
sql/sql_table.cc:
Fixed the case that a DROP/DROP TEMPORARY that affects a temporary table in MIXED
mode is written as a DROP TEMPORARY TABLE IF EXISTS because the table may not exist in the slave and due to the IF EXISTS token an error will never happen
while processing the statement in the slave.
Removed a function that was not being used.
2010-04-20 11:10:43 +02:00
|
|
|
bool trans_has_updated_non_trans_table(const THD* thd);
|
|
|
|
bool stmt_has_updated_non_trans_table(const THD* thd);
|
2009-11-03 20:02:56 +01:00
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
/*
|
|
|
|
Transaction Coordinator log - a base abstract class
|
|
|
|
for two different implementations
|
|
|
|
*/
|
|
|
|
class TC_LOG
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int using_heuristic_recover();
|
|
|
|
TC_LOG() {}
|
|
|
|
virtual ~TC_LOG() {}
|
|
|
|
|
|
|
|
virtual int open(const char *opt_name)=0;
|
|
|
|
virtual void close()=0;
|
2007-01-29 00:47:35 +01:00
|
|
|
virtual int log_xid(THD *thd, my_xid xid)=0;
|
BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error
when generating new name.
If find_uniq_filename returns an error, then this error is not
being propagated upwards, and execution does not report error to
the user (although a entry in the error log is generated).
Additionally, some more errors were ignored in new_file_impl:
- when writing the rotate event
- when reopening the index and binary log file
This patch addresses this by propagating the error up in the
execution stack. Furthermore, when rotation of the binary log
fails, an incident event is written, because there may be a
chance that some changes for a given statement, were not properly
logged. For example, in SBR, LOAD DATA INFILE statement requires
more than one event to be logged, should rotation fail while
logging part of the LOAD DATA events, then the logged data would
become inconsistent with the data in the storage engine.
mysql-test/include/restart_mysqld.inc:
Refactored restart_mysqld so that it is not hardcoded for
mysqld.1, but rather for the current server.
mysql-test/suite/binlog/t/binlog_index.test:
The error on open of index and binary log on new_file_impl
is now caught. Thence the user will get an error message.
We need to accomodate this change in the test case for the
failing FLUSH LOGS.
mysql-test/suite/rpl/t/rpl_binlog_errors-master.opt:
Sets max_binlog_size to 4096.
mysql-test/suite/rpl/t/rpl_binlog_errors.test:
Added some test cases for asserting that the error is found
and reported.
sql/handler.cc:
Catching error now returned by unlog (in ha_commit_trans) and
returning it.
sql/log.cc:
Propagating errors from new_file_impl upwards. The errors that
new_file_impl catches now are:
- error on generate_new_name
- error on writing the rotate event
- error when opening the index or the binary log file.
sql/log.h:
Changing declaration of:
- rotate_and_purge
- new_file
- new_file_without_locking
- new_file_impl
- unlog
They now return int instead of void.
sql/mysql_priv.h:
Change signature of reload_acl_and_cache so that write_to_binlog
is an int instead of bool.
sql/mysqld.cc:
Redeclaring not_used var as int instead of bool.
sql/rpl_injector.cc:
Changes to catch the return from rotate_and_purge.
sql/slave.cc:
Changes to catch the return values for new_file and rotate_relay_log.
sql/slave.h:
Changes to rotate_relay_log declaration (now returns int
instead of void).
sql/sql_load.cc:
In SBR, some logging of LOAD DATA events goes through
IO_CACHE_CALLBACK invocation at mf_iocache.c:_my_b_get. The
IO_CACHE implementation is ignoring the return value for from
these callbacks (pre_read and post_read), so we need to find out
at the end of the execution if the error is set or not in THD.
sql/sql_parse.cc:
Catching the rotate_relay_log and rotate_and_purge return values.
Semantic change in reload_acl_and_cache so that we report errors
in binlog interactions through the write_to_binlog output parameter.
If there was any failure while rotating the binary log, we should
then report the error to the client when handling SQLCOMM_FLUSH.
2010-12-01 00:32:51 +01:00
|
|
|
virtual int unlog(ulong cookie, my_xid xid)=0;
|
2005-12-22 06:39:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class TC_LOG_DUMMY: public TC_LOG // use it to disable the logging
|
|
|
|
{
|
2006-03-29 13:27:36 +02:00
|
|
|
public:
|
|
|
|
TC_LOG_DUMMY() {}
|
2005-12-22 06:39:02 +01:00
|
|
|
int open(const char *opt_name) { return 0; }
|
|
|
|
void close() { }
|
2007-01-29 00:47:35 +01:00
|
|
|
int log_xid(THD *thd, my_xid xid) { return 1; }
|
BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error
when generating new name.
If find_uniq_filename returns an error, then this error is not
being propagated upwards, and execution does not report error to
the user (although a entry in the error log is generated).
Additionally, some more errors were ignored in new_file_impl:
- when writing the rotate event
- when reopening the index and binary log file
This patch addresses this by propagating the error up in the
execution stack. Furthermore, when rotation of the binary log
fails, an incident event is written, because there may be a
chance that some changes for a given statement, were not properly
logged. For example, in SBR, LOAD DATA INFILE statement requires
more than one event to be logged, should rotation fail while
logging part of the LOAD DATA events, then the logged data would
become inconsistent with the data in the storage engine.
mysql-test/include/restart_mysqld.inc:
Refactored restart_mysqld so that it is not hardcoded for
mysqld.1, but rather for the current server.
mysql-test/suite/binlog/t/binlog_index.test:
The error on open of index and binary log on new_file_impl
is now caught. Thence the user will get an error message.
We need to accomodate this change in the test case for the
failing FLUSH LOGS.
mysql-test/suite/rpl/t/rpl_binlog_errors-master.opt:
Sets max_binlog_size to 4096.
mysql-test/suite/rpl/t/rpl_binlog_errors.test:
Added some test cases for asserting that the error is found
and reported.
sql/handler.cc:
Catching error now returned by unlog (in ha_commit_trans) and
returning it.
sql/log.cc:
Propagating errors from new_file_impl upwards. The errors that
new_file_impl catches now are:
- error on generate_new_name
- error on writing the rotate event
- error when opening the index or the binary log file.
sql/log.h:
Changing declaration of:
- rotate_and_purge
- new_file
- new_file_without_locking
- new_file_impl
- unlog
They now return int instead of void.
sql/mysql_priv.h:
Change signature of reload_acl_and_cache so that write_to_binlog
is an int instead of bool.
sql/mysqld.cc:
Redeclaring not_used var as int instead of bool.
sql/rpl_injector.cc:
Changes to catch the return from rotate_and_purge.
sql/slave.cc:
Changes to catch the return values for new_file and rotate_relay_log.
sql/slave.h:
Changes to rotate_relay_log declaration (now returns int
instead of void).
sql/sql_load.cc:
In SBR, some logging of LOAD DATA events goes through
IO_CACHE_CALLBACK invocation at mf_iocache.c:_my_b_get. The
IO_CACHE implementation is ignoring the return value for from
these callbacks (pre_read and post_read), so we need to find out
at the end of the execution if the error is set or not in THD.
sql/sql_parse.cc:
Catching the rotate_relay_log and rotate_and_purge return values.
Semantic change in reload_acl_and_cache so that we report errors
in binlog interactions through the write_to_binlog output parameter.
If there was any failure while rotating the binary log, we should
then report the error to the client when handling SQLCOMM_FLUSH.
2010-12-01 00:32:51 +01:00
|
|
|
int unlog(ulong cookie, my_xid xid) { return 0; }
|
2005-12-22 06:39:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef HAVE_MMAP
|
|
|
|
class TC_LOG_MMAP: public TC_LOG
|
|
|
|
{
|
|
|
|
public: // only to keep Sun Forte on sol9x86 happy
|
|
|
|
typedef enum {
|
2011-01-17 13:25:31 +01:00
|
|
|
PS_POOL, // page is in pool
|
|
|
|
PS_ERROR, // last sync failed
|
|
|
|
PS_DIRTY // new xids added since last sync
|
2005-12-22 06:39:02 +01:00
|
|
|
} PAGE_STATE;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef struct st_page {
|
|
|
|
struct st_page *next; // page a linked in a fifo queue
|
|
|
|
my_xid *start, *end; // usable area of a page
|
|
|
|
my_xid *ptr; // next xid will be written here
|
|
|
|
int size, free; // max and current number of free xid slots on the page
|
|
|
|
int waiters; // number of waiters on condition
|
|
|
|
PAGE_STATE state; // see above
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_t lock; // to access page data or control structure
|
|
|
|
mysql_cond_t cond; // to wait for a sync
|
2005-12-22 06:39:02 +01:00
|
|
|
} PAGE;
|
|
|
|
|
|
|
|
char logname[FN_REFLEN];
|
|
|
|
File fd;
|
|
|
|
my_off_t file_length;
|
|
|
|
uint npages, inited;
|
|
|
|
uchar *data;
|
|
|
|
struct st_page *pages, *syncing, *active, *pool, *pool_last;
|
|
|
|
/*
|
|
|
|
note that, e.g. LOCK_active is only used to protect
|
|
|
|
'active' pointer, to protect the content of the active page
|
|
|
|
one has to use active->lock.
|
|
|
|
Same for LOCK_pool and LOCK_sync
|
|
|
|
*/
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_t LOCK_active, LOCK_pool, LOCK_sync;
|
|
|
|
mysql_cond_t COND_pool, COND_active;
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
TC_LOG_MMAP(): inited(0) {}
|
|
|
|
int open(const char *opt_name);
|
|
|
|
void close();
|
2007-01-29 00:47:35 +01:00
|
|
|
int log_xid(THD *thd, my_xid xid);
|
BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error
when generating new name.
If find_uniq_filename returns an error, then this error is not
being propagated upwards, and execution does not report error to
the user (although a entry in the error log is generated).
Additionally, some more errors were ignored in new_file_impl:
- when writing the rotate event
- when reopening the index and binary log file
This patch addresses this by propagating the error up in the
execution stack. Furthermore, when rotation of the binary log
fails, an incident event is written, because there may be a
chance that some changes for a given statement, were not properly
logged. For example, in SBR, LOAD DATA INFILE statement requires
more than one event to be logged, should rotation fail while
logging part of the LOAD DATA events, then the logged data would
become inconsistent with the data in the storage engine.
mysql-test/include/restart_mysqld.inc:
Refactored restart_mysqld so that it is not hardcoded for
mysqld.1, but rather for the current server.
mysql-test/suite/binlog/t/binlog_index.test:
The error on open of index and binary log on new_file_impl
is now caught. Thence the user will get an error message.
We need to accomodate this change in the test case for the
failing FLUSH LOGS.
mysql-test/suite/rpl/t/rpl_binlog_errors-master.opt:
Sets max_binlog_size to 4096.
mysql-test/suite/rpl/t/rpl_binlog_errors.test:
Added some test cases for asserting that the error is found
and reported.
sql/handler.cc:
Catching error now returned by unlog (in ha_commit_trans) and
returning it.
sql/log.cc:
Propagating errors from new_file_impl upwards. The errors that
new_file_impl catches now are:
- error on generate_new_name
- error on writing the rotate event
- error when opening the index or the binary log file.
sql/log.h:
Changing declaration of:
- rotate_and_purge
- new_file
- new_file_without_locking
- new_file_impl
- unlog
They now return int instead of void.
sql/mysql_priv.h:
Change signature of reload_acl_and_cache so that write_to_binlog
is an int instead of bool.
sql/mysqld.cc:
Redeclaring not_used var as int instead of bool.
sql/rpl_injector.cc:
Changes to catch the return from rotate_and_purge.
sql/slave.cc:
Changes to catch the return values for new_file and rotate_relay_log.
sql/slave.h:
Changes to rotate_relay_log declaration (now returns int
instead of void).
sql/sql_load.cc:
In SBR, some logging of LOAD DATA events goes through
IO_CACHE_CALLBACK invocation at mf_iocache.c:_my_b_get. The
IO_CACHE implementation is ignoring the return value for from
these callbacks (pre_read and post_read), so we need to find out
at the end of the execution if the error is set or not in THD.
sql/sql_parse.cc:
Catching the rotate_relay_log and rotate_and_purge return values.
Semantic change in reload_acl_and_cache so that we report errors
in binlog interactions through the write_to_binlog output parameter.
If there was any failure while rotating the binary log, we should
then report the error to the client when handling SQLCOMM_FLUSH.
2010-12-01 00:32:51 +01:00
|
|
|
int unlog(ulong cookie, my_xid xid);
|
2005-12-22 06:39:02 +01:00
|
|
|
int recover();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void get_active_from_pool();
|
|
|
|
int sync();
|
|
|
|
int overflow();
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
#define TC_LOG_MMAP TC_LOG_DUMMY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern TC_LOG *tc_log;
|
|
|
|
extern TC_LOG_MMAP tc_log_mmap;
|
|
|
|
extern TC_LOG_DUMMY tc_log_dummy;
|
|
|
|
|
|
|
|
/* log info errors */
|
|
|
|
#define LOG_INFO_EOF -1
|
|
|
|
#define LOG_INFO_IO -2
|
|
|
|
#define LOG_INFO_INVALID -3
|
|
|
|
#define LOG_INFO_SEEK -4
|
|
|
|
#define LOG_INFO_MEM -6
|
|
|
|
#define LOG_INFO_FATAL -7
|
|
|
|
#define LOG_INFO_IN_USE -8
|
2006-10-13 06:48:05 +02:00
|
|
|
#define LOG_INFO_EMFILE -9
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
/* bitmap to SQL_LOG::close() */
|
|
|
|
#define LOG_CLOSE_INDEX 1
|
|
|
|
#define LOG_CLOSE_TO_BE_OPENED 2
|
|
|
|
#define LOG_CLOSE_STOP_EVENT 4
|
|
|
|
|
2009-11-22 04:59:48 +01:00
|
|
|
/*
|
|
|
|
Maximum unique log filename extension.
|
|
|
|
Note: setting to 0x7FFFFFFF due to atol windows
|
|
|
|
overflow/truncate.
|
|
|
|
*/
|
|
|
|
#define MAX_LOG_UNIQUE_FN_EXT 0x7FFFFFFF
|
|
|
|
|
|
|
|
/*
|
|
|
|
Number of warnings that will be printed to error log
|
|
|
|
before extension number is exhausted.
|
|
|
|
*/
|
|
|
|
#define LOG_WARN_UNIQUE_FN_EXT_LEFT 1000
|
|
|
|
|
2007-08-16 07:37:50 +02:00
|
|
|
class Relay_log_info;
|
2005-12-22 06:39:02 +01:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
extern PSI_mutex_key key_LOG_INFO_lock;
|
|
|
|
#endif
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
typedef struct st_log_info
|
|
|
|
{
|
|
|
|
char log_file_name[FN_REFLEN];
|
|
|
|
my_off_t index_file_offset, index_file_start_offset;
|
|
|
|
my_off_t pos;
|
|
|
|
bool fatal; // if the purge happens to give us a negative offset
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_t lock;
|
2011-07-10 20:21:18 +02:00
|
|
|
st_log_info() : index_file_offset(0), index_file_start_offset(0),
|
2007-10-04 12:13:04 +02:00
|
|
|
pos(0), fatal(0)
|
2011-07-10 20:21:18 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("LOG_INFO");
|
|
|
|
log_file_name[0] = '\0';
|
|
|
|
mysql_mutex_init(key_LOG_INFO_lock, &lock, MY_MUTEX_INIT_FAST);
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
~st_log_info()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("~LOG_INFO");
|
|
|
|
mysql_mutex_destroy(&lock);
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2005-12-22 06:39:02 +01:00
|
|
|
} LOG_INFO;
|
|
|
|
|
2006-01-19 03:56:06 +01:00
|
|
|
/*
|
|
|
|
Currently we have only 3 kinds of logging functions: old-fashioned
|
|
|
|
logs, stdout and csv logging routines.
|
|
|
|
*/
|
|
|
|
#define MAX_LOG_HANDLERS_NUM 3
|
|
|
|
|
2006-01-27 11:41:15 +01:00
|
|
|
/* log event handler flags */
|
|
|
|
#define LOG_NONE 1
|
|
|
|
#define LOG_FILE 2
|
|
|
|
#define LOG_TABLE 4
|
2006-01-19 03:56:06 +01:00
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
class Log_event;
|
|
|
|
class Rows_log_event;
|
|
|
|
|
2006-06-05 03:34:34 +02:00
|
|
|
enum enum_log_type { LOG_UNKNOWN, LOG_NORMAL, LOG_BIN };
|
|
|
|
enum enum_log_state { LOG_OPENED, LOG_CLOSED, LOG_TO_BE_OPENED };
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
TODO use mmap instead of IO_CACHE for binlog
|
|
|
|
(mmap+fsync is two times faster than write+fsync)
|
|
|
|
*/
|
|
|
|
|
2006-05-05 08:45:58 +02:00
|
|
|
class MYSQL_LOG
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MYSQL_LOG();
|
|
|
|
void init_pthread_objects();
|
|
|
|
void cleanup();
|
2010-11-12 07:23:26 +01:00
|
|
|
bool open(
|
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
PSI_file_key log_file_key,
|
|
|
|
#endif
|
|
|
|
const char *log_name,
|
2006-05-05 08:45:58 +02:00
|
|
|
enum_log_type log_type,
|
|
|
|
const char *new_name,
|
|
|
|
enum cache_type io_cache_type_arg);
|
2009-12-04 15:40:42 +01:00
|
|
|
bool init_and_set_log_file_name(const char *log_name,
|
|
|
|
const char *new_name,
|
|
|
|
enum_log_type log_type_arg,
|
|
|
|
enum cache_type io_cache_type_arg);
|
2006-05-05 08:45:58 +02:00
|
|
|
void init(enum_log_type log_type_arg,
|
|
|
|
enum cache_type io_cache_type_arg);
|
|
|
|
void close(uint exiting);
|
2006-06-05 03:34:34 +02:00
|
|
|
inline bool is_open() { return log_state != LOG_CLOSED; }
|
2006-05-05 08:45:58 +02:00
|
|
|
const char *generate_name(const char *log_name, const char *suffix,
|
|
|
|
bool strip_ext, char *buff);
|
|
|
|
int generate_new_name(char *new_name, const char *log_name);
|
|
|
|
protected:
|
|
|
|
/* LOCK_log is inited by init_pthread_objects() */
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_t LOCK_log;
|
2006-05-05 08:45:58 +02:00
|
|
|
char *name;
|
|
|
|
char log_file_name[FN_REFLEN];
|
2006-09-28 15:00:44 +02:00
|
|
|
char time_buff[20], db[NAME_LEN + 1];
|
2006-05-05 08:45:58 +02:00
|
|
|
bool write_error, inited;
|
|
|
|
IO_CACHE log_file;
|
2006-06-05 03:34:34 +02:00
|
|
|
enum_log_type log_type;
|
|
|
|
volatile enum_log_state log_state;
|
2006-05-05 08:45:58 +02:00
|
|
|
enum cache_type io_cache_type;
|
|
|
|
friend class Log_event;
|
2010-11-12 07:23:26 +01:00
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
/** Instrumentation key to use for file io in @c log_file */
|
|
|
|
PSI_file_key m_log_file_key;
|
|
|
|
#endif
|
2006-05-05 08:45:58 +02:00
|
|
|
};
|
|
|
|
|
2006-06-05 03:34:34 +02:00
|
|
|
class MYSQL_QUERY_LOG: public MYSQL_LOG
|
2006-05-05 08:45:58 +02:00
|
|
|
{
|
|
|
|
public:
|
2006-06-05 03:34:34 +02:00
|
|
|
MYSQL_QUERY_LOG() : last_time(0) {}
|
|
|
|
void reopen_file();
|
2006-05-05 08:45:58 +02:00
|
|
|
bool write(time_t event_time, const char *user_host,
|
|
|
|
uint user_host_len, int thread_id,
|
|
|
|
const char *command_type, uint command_type_len,
|
|
|
|
const char *sql_text, uint sql_text_len);
|
|
|
|
bool write(THD *thd, time_t current_time, time_t query_start_arg,
|
|
|
|
const char *user_host, uint user_host_len,
|
2007-07-30 10:33:50 +02:00
|
|
|
ulonglong query_utime, ulonglong lock_utime, bool is_command,
|
2006-05-05 08:45:58 +02:00
|
|
|
const char *sql_text, uint sql_text_len);
|
|
|
|
bool open_slow_log(const char *log_name)
|
|
|
|
{
|
|
|
|
char buf[FN_REFLEN];
|
2010-11-12 07:23:26 +01:00
|
|
|
return open(
|
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
key_file_slow_log,
|
|
|
|
#endif
|
|
|
|
generate_name(log_name, "-slow.log", 0, buf),
|
|
|
|
LOG_NORMAL, 0, WRITE_CACHE);
|
2006-05-05 08:45:58 +02:00
|
|
|
}
|
2006-06-05 03:34:34 +02:00
|
|
|
bool open_query_log(const char *log_name)
|
|
|
|
{
|
|
|
|
char buf[FN_REFLEN];
|
2010-11-12 07:23:26 +01:00
|
|
|
return open(
|
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
key_file_query_log,
|
|
|
|
#endif
|
|
|
|
generate_name(log_name, ".log", 0, buf),
|
|
|
|
LOG_NORMAL, 0, WRITE_CACHE);
|
2006-06-05 03:34:34 +02:00
|
|
|
}
|
WL#3984 (Revise locking of mysql.general_log and mysql.slow_log)
Bug#25422 (Hang with log tables)
Bug 17876 (Truncating mysql.slow_log in a SP after using cursor locks the
thread)
Bug 23044 (Warnings on flush of a log table)
Bug 29129 (Resetting general_log while the GLOBAL READ LOCK is set causes
a deadlock)
Prior to this fix, the server would hang when performing concurrent
ALTER TABLE or TRUNCATE TABLE statements against the LOG TABLES,
which are mysql.general_log and mysql.slow_log.
The root cause traces to the following code:
in sql_base.cc, open_table()
if (table->in_use != thd)
{
/* wait_for_condition will unlock LOCK_open for us */
wait_for_condition(thd, &LOCK_open, &COND_refresh);
}
The problem with this code is that the current implementation of the
LOGGER creates 'fake' THD objects, like
- Log_to_csv_event_handler::general_log_thd
- Log_to_csv_event_handler::slow_log_thd
which are not associated to a real thread running in the server,
so that waiting for these non-existing threads to release table locks
cause the dead lock.
In general, the design of Log_to_csv_event_handler does not fit into the
general architecture of the server, so that the concept of general_log_thd
and slow_log_thd has to be abandoned:
- this implementation does not work with table locking
- it will not work with commands like SHOW PROCESSLIST
- having the log tables always opened does not integrate well with DDL
operations / FLUSH TABLES / SET GLOBAL READ_ONLY
With this patch, the fundamental design of the LOGGER has been changed to:
- always open and close a log table when writing a log
- remove totally the usage of fake THD objects
- clarify how locking of log tables is implemented in general.
See WL#3984 for details related to the new locking design.
Additional changes (misc bugs exposed and fixed):
1)
mysqldump which would ignore some tables in dump_all_tables_in_db(),
but forget to ignore the same in dump_all_views_in_db().
2)
mysqldump would also issue an empty "LOCK TABLE" command when all the tables
to lock are to be ignored (numrows == 0), instead of not issuing the query.
3)
Internal errors handlers could intercept errors but not warnings
(see sql_error.cc).
4)
Implementing a nested call to open tables, for the performance schema tables,
exposed an existing bug in remove_table_from_cache(), which would perform:
in_use->some_tables_deleted=1;
against another thread, without any consideration about thread locking.
This call inside remove_table_from_cache() was not required anyway,
since calling mysql_lock_abort() takes care of aborting -- cleanly -- threads
that might hold a lock on a table.
This line (in_use->some_tables_deleted=1) has been removed.
sql/handler.cc:
Moved logic for system / log tables in the SQL layer.
sql/handler.h:
Moved logic for system / log tables in the SQL layer.
sql/lock.cc:
Revised locking of log tables
sql/log.cc:
Major cleanup: changed how log tables are locked / written to.
sql/log.h:
Major cleanup: changed how log tables are locked / written to.
sql/mysql_priv.h:
performance schema helpers
sql/slave.cc:
open_ltable() lock flags
sql/sp.cc:
open_ltable() lock flags
sql/sql_acl.cc:
open_ltable() lock flags
sql/sql_class.h:
performance schema helpers
sql/sql_delete.cc:
log tables cleanup in TRUNCATE
sql/sql_error.cc:
Internal handlers can also intercept warnings
sql/sql_insert.cc:
open_ltable() lock flags
sql/sql_parse.cc:
performance schema helpers
sql/sql_plugin.cc:
open_ltable() lock flags
sql/sql_rename.cc:
log tables cleanup in RENAME
sql/sql_servers.cc:
open_ltable() lock flags
sql/sql_show.cc:
Move INFORMATION_SCHEMA_NAME to table.cc
sql/sql_table.cc:
log tables cleanup (admin operations, ALTER TABLE)
sql/sql_udf.cc:
open_ltable() lock flags
sql/table.cc:
Implemented TABLE_CATEGORY.
sql/share/errmsg.txt:
Changed the wording and name of ER_CANT_READ_LOCK_LOG_TABLE
sql/table.h:
Implemented TABLE_CATEGORY.
storage/csv/ha_tina.cc:
Moved logic for system / log tables in the SQL layer.
storage/csv/ha_tina.h:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.cc:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.h:
Moved logic for system / log tables in the SQL layer.
client/mysqldump.c:
Don't lock tables in the ignore list.
Don't issue empty LOCK TABLES queries.
sql/sql_base.cc:
log tables cleanup
performance schema helpers
mysql-test/r/ps.result:
Adjust test results
mysql-test/r/show_check.result:
Adjust test results
mysql-test/r/status.result:
Adjust test results
mysql-test/t/log_state.test:
Added tests for Bug#29129
mysql-test/t/ps.test:
Make the test output deterministic
mysql-test/t/show_check.test:
Make the test output deterministic
mysql-test/r/log_state.result:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
Adjust test results
mysql-test/r/log_tables.result:
cleanup for -ps-protocol
mysql-test/t/log_tables.test:
cleanup for -ps-protocol
sql/set_var.cc:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
log tables cleanup
2007-07-27 08:31:06 +02:00
|
|
|
|
2006-06-05 03:34:34 +02:00
|
|
|
private:
|
|
|
|
time_t last_time;
|
2006-05-05 08:45:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
|
2005-12-22 06:39:02 +01:00
|
|
|
{
|
|
|
|
private:
|
2011-03-01 17:39:28 +01:00
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
/** The instrumentation key to use for @ LOCK_index. */
|
|
|
|
PSI_mutex_key m_key_LOCK_index;
|
|
|
|
/** The instrumentation key to use for @ update_cond. */
|
|
|
|
PSI_cond_key m_key_update_cond;
|
|
|
|
/** The instrumentation key to use for opening the log file. */
|
|
|
|
PSI_file_key m_key_file_log;
|
|
|
|
/** The instrumentation key to use for opening the log index file. */
|
|
|
|
PSI_file_key m_key_file_log_index;
|
|
|
|
#endif
|
2005-12-22 06:39:02 +01:00
|
|
|
/* LOCK_log and LOCK_index are inited by init_pthread_objects() */
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_t LOCK_index;
|
|
|
|
mysql_mutex_t LOCK_prep_xids;
|
|
|
|
mysql_cond_t COND_prep_xids;
|
|
|
|
mysql_cond_t update_cond;
|
2005-12-22 06:39:02 +01:00
|
|
|
ulonglong bytes_written;
|
|
|
|
IO_CACHE index_file;
|
2009-12-04 15:40:42 +01:00
|
|
|
char index_file_name[FN_REFLEN];
|
2008-12-04 15:07:56 +01:00
|
|
|
/*
|
2009-12-04 15:40:42 +01:00
|
|
|
purge_file is a temp file used in purge_logs so that the index file
|
2008-12-04 15:07:56 +01:00
|
|
|
can be updated before deleting files from disk, yielding better crash
|
|
|
|
recovery. It is created on demand the first time purge_logs is called
|
|
|
|
and then reused for subsequent calls. It is cleaned up in cleanup().
|
|
|
|
*/
|
2009-12-04 15:40:42 +01:00
|
|
|
IO_CACHE purge_index_file;
|
|
|
|
char purge_index_file_name[FN_REFLEN];
|
2005-12-22 06:39:02 +01:00
|
|
|
/*
|
|
|
|
The max size before rotation (usable only if log_type == LOG_BIN: binary
|
|
|
|
logs and relay logs).
|
|
|
|
For a binlog, max_size should be max_binlog_size.
|
|
|
|
For a relay log, it should be max_relay_log_size if this is non-zero,
|
|
|
|
max_binlog_size otherwise.
|
|
|
|
max_size is set in init(), and dynamically changed (when one does SET
|
|
|
|
GLOBAL MAX_BINLOG_SIZE|MAX_RELAY_LOG_SIZE) by fix_max_binlog_size and
|
|
|
|
fix_max_relay_log_size).
|
|
|
|
*/
|
|
|
|
ulong max_size;
|
2007-03-20 09:50:10 +01:00
|
|
|
long prepared_xids; /* for tc log - number of xids to remember */
|
2005-12-22 06:39:02 +01:00
|
|
|
// current file sequence number for load data infile binary logging
|
|
|
|
uint file_id;
|
|
|
|
uint open_count; // For replication
|
|
|
|
int readers_count;
|
|
|
|
bool need_start_event;
|
|
|
|
/*
|
|
|
|
no_auto_events means we don't want any of these automatic events :
|
|
|
|
Start/Rotate/Stop. That is, in 4.x when we rotate a relay log, we don't
|
|
|
|
want a Rotate_log event to be written to the relay log. When we start a
|
|
|
|
relay log etc. So in 4.x this is 1 for relay logs, 0 for binlogs.
|
|
|
|
In 5.0 it's 0 for relay logs too!
|
|
|
|
*/
|
|
|
|
bool no_auto_events;
|
|
|
|
|
2009-09-29 16:27:12 +02:00
|
|
|
/* pointer to the sync period variable, for binlog this will be
|
|
|
|
sync_binlog_period, for relay log this will be
|
|
|
|
sync_relay_log_period
|
|
|
|
*/
|
|
|
|
uint *sync_period_ptr;
|
|
|
|
uint sync_counter;
|
|
|
|
|
|
|
|
inline uint get_sync_period()
|
|
|
|
{
|
|
|
|
return *sync_period_ptr;
|
|
|
|
}
|
|
|
|
|
2006-02-16 08:30:53 +01:00
|
|
|
int write_to_file(IO_CACHE *cache);
|
2006-05-05 08:45:58 +02:00
|
|
|
/*
|
|
|
|
This is used to start writing to a new log file. The difference from
|
|
|
|
new_file() is locking. new_file_without_locking() does not acquire
|
|
|
|
LOCK_log.
|
|
|
|
*/
|
BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error
when generating new name.
If find_uniq_filename returns an error, then this error is not
being propagated upwards, and execution does not report error to
the user (although a entry in the error log is generated).
Additionally, some more errors were ignored in new_file_impl:
- when writing the rotate event
- when reopening the index and binary log file
This patch addresses this by propagating the error up in the
execution stack. Furthermore, when rotation of the binary log
fails, an incident event is written, because there may be a
chance that some changes for a given statement, were not properly
logged. For example, in SBR, LOAD DATA INFILE statement requires
more than one event to be logged, should rotation fail while
logging part of the LOAD DATA events, then the logged data would
become inconsistent with the data in the storage engine.
mysql-test/include/restart_mysqld.inc:
Refactored restart_mysqld so that it is not hardcoded for
mysqld.1, but rather for the current server.
mysql-test/suite/binlog/t/binlog_index.test:
The error on open of index and binary log on new_file_impl
is now caught. Thence the user will get an error message.
We need to accomodate this change in the test case for the
failing FLUSH LOGS.
mysql-test/suite/rpl/t/rpl_binlog_errors-master.opt:
Sets max_binlog_size to 4096.
mysql-test/suite/rpl/t/rpl_binlog_errors.test:
Added some test cases for asserting that the error is found
and reported.
sql/handler.cc:
Catching error now returned by unlog (in ha_commit_trans) and
returning it.
sql/log.cc:
Propagating errors from new_file_impl upwards. The errors that
new_file_impl catches now are:
- error on generate_new_name
- error on writing the rotate event
- error when opening the index or the binary log file.
sql/log.h:
Changing declaration of:
- rotate_and_purge
- new_file
- new_file_without_locking
- new_file_impl
- unlog
They now return int instead of void.
sql/mysql_priv.h:
Change signature of reload_acl_and_cache so that write_to_binlog
is an int instead of bool.
sql/mysqld.cc:
Redeclaring not_used var as int instead of bool.
sql/rpl_injector.cc:
Changes to catch the return from rotate_and_purge.
sql/slave.cc:
Changes to catch the return values for new_file and rotate_relay_log.
sql/slave.h:
Changes to rotate_relay_log declaration (now returns int
instead of void).
sql/sql_load.cc:
In SBR, some logging of LOAD DATA events goes through
IO_CACHE_CALLBACK invocation at mf_iocache.c:_my_b_get. The
IO_CACHE implementation is ignoring the return value for from
these callbacks (pre_read and post_read), so we need to find out
at the end of the execution if the error is set or not in THD.
sql/sql_parse.cc:
Catching the rotate_relay_log and rotate_and_purge return values.
Semantic change in reload_acl_and_cache so that we report errors
in binlog interactions through the write_to_binlog output parameter.
If there was any failure while rotating the binary log, we should
then report the error to the client when handling SQLCOMM_FLUSH.
2010-12-01 00:32:51 +01:00
|
|
|
int new_file_without_locking();
|
|
|
|
int new_file_impl(bool need_lock);
|
2006-02-16 08:30:53 +01:00
|
|
|
|
|
|
|
public:
|
2006-05-05 08:45:58 +02:00
|
|
|
MYSQL_LOG::generate_name;
|
2006-06-05 03:34:34 +02:00
|
|
|
MYSQL_LOG::is_open;
|
2008-09-28 09:34:25 +02:00
|
|
|
|
|
|
|
/* This is relay log */
|
|
|
|
bool is_relay_log;
|
2009-09-29 13:16:23 +02:00
|
|
|
ulong signal_cnt; // update of the counter is checked by heartbeat
|
2005-12-22 06:39:02 +01:00
|
|
|
/*
|
|
|
|
These describe the log's format. This is used only for relay logs.
|
|
|
|
_for_exec is used by the SQL thread, _for_queue by the I/O thread. It's
|
|
|
|
necessary to have 2 distinct objects, because the I/O thread may be reading
|
|
|
|
events in a different format from what the SQL thread is reading (consider
|
|
|
|
the case of a master which has been upgraded from 5.0 to 5.1 without doing
|
|
|
|
RESET MASTER, or from 4.x to 5.0).
|
|
|
|
*/
|
|
|
|
Format_description_log_event *description_event_for_exec,
|
|
|
|
*description_event_for_queue;
|
|
|
|
|
2009-09-29 16:27:12 +02:00
|
|
|
MYSQL_BIN_LOG(uint *sync_period);
|
2005-12-22 06:39:02 +01:00
|
|
|
/*
|
2006-05-05 08:45:58 +02:00
|
|
|
note that there's no destructor ~MYSQL_BIN_LOG() !
|
2005-12-22 06:39:02 +01:00
|
|
|
The reason is that we don't want it to be automatically called
|
|
|
|
on exit() - but only during the correct shutdown process
|
|
|
|
*/
|
|
|
|
|
2011-03-01 17:39:28 +01:00
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
void set_psi_keys(PSI_mutex_key key_LOCK_index,
|
|
|
|
PSI_cond_key key_update_cond,
|
|
|
|
PSI_file_key key_file_log,
|
|
|
|
PSI_file_key key_file_log_index)
|
|
|
|
{
|
|
|
|
m_key_LOCK_index= key_LOCK_index;
|
|
|
|
m_key_update_cond= key_update_cond;
|
|
|
|
m_key_file_log= key_file_log;
|
|
|
|
m_key_file_log_index= key_file_log_index;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
int open(const char *opt_name);
|
|
|
|
void close();
|
2007-01-29 00:47:35 +01:00
|
|
|
int log_xid(THD *thd, my_xid xid);
|
BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error
when generating new name.
If find_uniq_filename returns an error, then this error is not
being propagated upwards, and execution does not report error to
the user (although a entry in the error log is generated).
Additionally, some more errors were ignored in new_file_impl:
- when writing the rotate event
- when reopening the index and binary log file
This patch addresses this by propagating the error up in the
execution stack. Furthermore, when rotation of the binary log
fails, an incident event is written, because there may be a
chance that some changes for a given statement, were not properly
logged. For example, in SBR, LOAD DATA INFILE statement requires
more than one event to be logged, should rotation fail while
logging part of the LOAD DATA events, then the logged data would
become inconsistent with the data in the storage engine.
mysql-test/include/restart_mysqld.inc:
Refactored restart_mysqld so that it is not hardcoded for
mysqld.1, but rather for the current server.
mysql-test/suite/binlog/t/binlog_index.test:
The error on open of index and binary log on new_file_impl
is now caught. Thence the user will get an error message.
We need to accomodate this change in the test case for the
failing FLUSH LOGS.
mysql-test/suite/rpl/t/rpl_binlog_errors-master.opt:
Sets max_binlog_size to 4096.
mysql-test/suite/rpl/t/rpl_binlog_errors.test:
Added some test cases for asserting that the error is found
and reported.
sql/handler.cc:
Catching error now returned by unlog (in ha_commit_trans) and
returning it.
sql/log.cc:
Propagating errors from new_file_impl upwards. The errors that
new_file_impl catches now are:
- error on generate_new_name
- error on writing the rotate event
- error when opening the index or the binary log file.
sql/log.h:
Changing declaration of:
- rotate_and_purge
- new_file
- new_file_without_locking
- new_file_impl
- unlog
They now return int instead of void.
sql/mysql_priv.h:
Change signature of reload_acl_and_cache so that write_to_binlog
is an int instead of bool.
sql/mysqld.cc:
Redeclaring not_used var as int instead of bool.
sql/rpl_injector.cc:
Changes to catch the return from rotate_and_purge.
sql/slave.cc:
Changes to catch the return values for new_file and rotate_relay_log.
sql/slave.h:
Changes to rotate_relay_log declaration (now returns int
instead of void).
sql/sql_load.cc:
In SBR, some logging of LOAD DATA events goes through
IO_CACHE_CALLBACK invocation at mf_iocache.c:_my_b_get. The
IO_CACHE implementation is ignoring the return value for from
these callbacks (pre_read and post_read), so we need to find out
at the end of the execution if the error is set or not in THD.
sql/sql_parse.cc:
Catching the rotate_relay_log and rotate_and_purge return values.
Semantic change in reload_acl_and_cache so that we report errors
in binlog interactions through the write_to_binlog output parameter.
If there was any failure while rotating the binary log, we should
then report the error to the client when handling SQLCOMM_FLUSH.
2010-12-01 00:32:51 +01:00
|
|
|
int unlog(ulong cookie, my_xid xid);
|
2005-12-22 06:39:02 +01:00
|
|
|
int recover(IO_CACHE *log, Format_description_log_event *fdle);
|
|
|
|
#if !defined(MYSQL_CLIENT)
|
2006-02-16 08:30:53 +01:00
|
|
|
|
2009-11-03 20:02:56 +01:00
|
|
|
int flush_and_set_pending_rows_event(THD *thd, Rows_log_event* event,
|
|
|
|
bool is_transactional);
|
|
|
|
int remove_pending_rows_event(THD *thd, bool is_transactional);
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
#endif /* !defined(MYSQL_CLIENT) */
|
|
|
|
void reset_bytes_written()
|
|
|
|
{
|
|
|
|
bytes_written = 0;
|
|
|
|
}
|
|
|
|
void harvest_bytes_written(ulonglong* counter)
|
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
char buf1[22],buf2[22];
|
|
|
|
#endif
|
|
|
|
DBUG_ENTER("harvest_bytes_written");
|
|
|
|
(*counter)+=bytes_written;
|
|
|
|
DBUG_PRINT("info",("counter: %s bytes_written: %s", llstr(*counter,buf1),
|
|
|
|
llstr(bytes_written,buf2)));
|
|
|
|
bytes_written=0;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
void set_max_size(ulong max_size_arg);
|
|
|
|
void signal_update();
|
2009-09-29 13:16:23 +02:00
|
|
|
void wait_for_update_relay_log(THD* thd);
|
|
|
|
int wait_for_update_bin_log(THD* thd, const struct timespec * timeout);
|
2005-12-22 06:39:02 +01:00
|
|
|
void set_need_start_event() { need_start_event = 1; }
|
2006-05-05 08:45:58 +02:00
|
|
|
void init(bool no_auto_events_arg, ulong max_size);
|
2005-12-22 06:39:02 +01:00
|
|
|
void init_pthread_objects();
|
|
|
|
void cleanup();
|
|
|
|
bool open(const char *log_name,
|
|
|
|
enum_log_type log_type,
|
|
|
|
const char *new_name,
|
|
|
|
enum cache_type io_cache_type_arg,
|
|
|
|
bool no_auto_events_arg, ulong max_size,
|
2009-12-04 15:40:42 +01:00
|
|
|
bool null_created,
|
|
|
|
bool need_mutex);
|
2005-12-22 06:39:02 +01:00
|
|
|
bool open_index_file(const char *index_file_name_arg,
|
2009-12-04 15:40:42 +01:00
|
|
|
const char *log_name, bool need_mutex);
|
2006-05-05 08:45:58 +02:00
|
|
|
/* Use this to start writing a new log file */
|
BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error
when generating new name.
If find_uniq_filename returns an error, then this error is not
being propagated upwards, and execution does not report error to
the user (although a entry in the error log is generated).
Additionally, some more errors were ignored in new_file_impl:
- when writing the rotate event
- when reopening the index and binary log file
This patch addresses this by propagating the error up in the
execution stack. Furthermore, when rotation of the binary log
fails, an incident event is written, because there may be a
chance that some changes for a given statement, were not properly
logged. For example, in SBR, LOAD DATA INFILE statement requires
more than one event to be logged, should rotation fail while
logging part of the LOAD DATA events, then the logged data would
become inconsistent with the data in the storage engine.
mysql-test/include/restart_mysqld.inc:
Refactored restart_mysqld so that it is not hardcoded for
mysqld.1, but rather for the current server.
mysql-test/suite/binlog/t/binlog_index.test:
The error on open of index and binary log on new_file_impl
is now caught. Thence the user will get an error message.
We need to accomodate this change in the test case for the
failing FLUSH LOGS.
mysql-test/suite/rpl/t/rpl_binlog_errors-master.opt:
Sets max_binlog_size to 4096.
mysql-test/suite/rpl/t/rpl_binlog_errors.test:
Added some test cases for asserting that the error is found
and reported.
sql/handler.cc:
Catching error now returned by unlog (in ha_commit_trans) and
returning it.
sql/log.cc:
Propagating errors from new_file_impl upwards. The errors that
new_file_impl catches now are:
- error on generate_new_name
- error on writing the rotate event
- error when opening the index or the binary log file.
sql/log.h:
Changing declaration of:
- rotate_and_purge
- new_file
- new_file_without_locking
- new_file_impl
- unlog
They now return int instead of void.
sql/mysql_priv.h:
Change signature of reload_acl_and_cache so that write_to_binlog
is an int instead of bool.
sql/mysqld.cc:
Redeclaring not_used var as int instead of bool.
sql/rpl_injector.cc:
Changes to catch the return from rotate_and_purge.
sql/slave.cc:
Changes to catch the return values for new_file and rotate_relay_log.
sql/slave.h:
Changes to rotate_relay_log declaration (now returns int
instead of void).
sql/sql_load.cc:
In SBR, some logging of LOAD DATA events goes through
IO_CACHE_CALLBACK invocation at mf_iocache.c:_my_b_get. The
IO_CACHE implementation is ignoring the return value for from
these callbacks (pre_read and post_read), so we need to find out
at the end of the execution if the error is set or not in THD.
sql/sql_parse.cc:
Catching the rotate_relay_log and rotate_and_purge return values.
Semantic change in reload_acl_and_cache so that we report errors
in binlog interactions through the write_to_binlog output parameter.
If there was any failure while rotating the binary log, we should
then report the error to the client when handling SQLCOMM_FLUSH.
2010-12-01 00:32:51 +01:00
|
|
|
int new_file();
|
2006-01-19 03:56:06 +01:00
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
bool write(Log_event* event_info); // binary log write
|
BUG#43929 binlog corruption when max_binlog_cache_size is exceeded
Large transactions and statements may corrupt the binary log if the size of the
cache, which is set by the max_binlog_cache_size, is not enough to store the
the changes.
In a nutshell, to fix the bug, we save the position of the next character in the
cache before starting processing a statement. If there is a problem, we simply
restore the position thus removing any effect of the statement from the cache.
Unfortunately, to avoid corrupting the binary log, we may end up loosing changes
on non-transactional tables if they do not fit in the cache. In such cases, we
store an Incident_log_event in order to stop the slave and alert users that some
changes were not logged.
Precisely, for every non-transactional changes that do not fit into the cache,
we do the following:
a) the statement is *not* logged
b) an incident event is logged after committing/rolling back the transaction,
if any. Note that if a failure happens before writing the incident event to
the binary log, the slave will not stop and the master will not have reported
any error.
c) its respective statement gives an error
For transactional changes that do not fit into the cache, we do the following:
a) the statement is *not* logged
b) its respective statement gives an error
To work properly, this patch requires two additional things. Firstly, callers to
MYSQL_BIN_LOG::write and THD::binlog_query must handle any error returned and
take the appropriate actions such as undoing the effects of a statement. We
already changed some calls in the sql_insert.cc, sql_update.cc and sql_insert.cc
modules but the remaining calls spread all over the code should be handled in
BUG#37148. Secondly, statements must be either classified as DDL or DML because
DDLs that do not get into the cache must generate an incident event since they
cannot be rolled back.
2009-06-18 15:52:46 +02:00
|
|
|
bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event, bool incident);
|
2010-08-02 21:48:56 +02:00
|
|
|
bool write_incident(THD *thd, bool lock);
|
This is based on the userstatv2 patch from Percona and OurDelta.
The original code comes, as far as I know, from Google (Mark Callaghan's team) with additional work from Percona, Ourdelta and Weldon Whipple.
This code provides the same functionallity, but with a lot of changes to make it faster and better fit the MariaDB infrastucture.
Added new status variables:
- Com_show_client_statistics, Com_show_index_statistics, Com_show_table_statistics, Com_show_user_statistics
- Access_denied_errors, Busy_time (clock time), Binlog_bytes_written, Cpu_time, Empty_queries, Rows_sent, Rows_read
Added new variable / startup option 'userstat' to control if user statistics should be enabled or not
Added my_getcputime(); Returns cpu time used by this thread.
New FLUSH commands:
- FLUSH SLOW QUERY LOG
- FLUSH TABLE_STATISTICS
- FLUSH INDEX_STATISTICS
- FLUSH USER_STATISTICS
- FLUSH CLIENT_STATISTICS
New SHOW commands:
- SHOW CLIENT_STATISTICS
- SHOW USER_STATISTICS
- SHOW TABLE_STATISTICS
- SHOW INDEX_STATISTICS
New Information schemas:
- CLIENT_STATISTICS
- USER_STATISTICS
- INDEX_STATISTICS
- TABLE_STATISTICS
Added support for all new flush commands to mysqladmin
Added handler::ha_... wrappers for all handler read calls to do statistics counting
- Changed all code to use new ha_... calls
- Count number of read rows, changed rows and rows read trough an index
Added counting of number of bytes sent to binary log (status variable Binlog_bytes_written)
Added counting of access denied errors (status variable Access_denied_erors)
Bugs fixed:
- Fixed bug in add_to_status() and add_diff_to_status() where longlong variables where threated as long
- CLOCK_GETTIME was not propely working on Linuxm
client/mysqladmin.cc:
Added support for all new flush commmands and some common combinations:
flush-slow-log
flush-table-statistics
flush-index-statistics
flush-user-statistics
flush-client-statistics
flush-all-status
flush-all-statistics
configure.in:
Added checking if clock_gettime needs the librt.
(Fixes Bug #37639 clock_gettime is never used/enabled in Linux/Unix)
include/my_sys.h:
Added my_getcputime()
include/mysql_com.h:
Added LIST_PROCESS_HOST_LEN & new REFRESH target defines
mysql-test/r/information_schema.result:
New information schema tables added
mysql-test/r/information_schema_all_engines.result:
New information schema tables added
mysql-test/r/information_schema_db.result:
New information schema tables added
mysql-test/r/log_slow.result:
Added testing that flosh slow query logs is accepted
mysql-test/r/status_user.result:
Basic testing of user, client, table and index statistics
mysql-test/t/log_slow.test:
Added testing that flosh slow query logs is accepted
mysql-test/t/status_user-master.opt:
Ensure that we get a fresh restart before running status_user.test
mysql-test/t/status_user.test:
Basic testing of user, client, table and index statistics
mysys/my_getsystime.c:
Added my_getcputime()
Returns cpu time used by this thread.
sql/authors.h:
Updated authors to have core and original MySQL developers first.
sql/event_data_objects.cc:
Updated call to mysql_reset_thd_for_next_command()
sql/event_db_repository.cc:
Changed to use new ha_... calls
sql/filesort.cc:
Changed to use new ha_... calls
sql/ha_partition.cc:
Changed to use new ha_... calls
Fixed comment syntax
sql/handler.cc:
Changed to use new ha_... calls
Reset table statistics
Added code to update global table and index status
Added counting of rows changed
sql/handler.h:
Added table and index statistics variables
Added function reset_statistics()
Added handler::ha_... wrappers for all handler read calls to do statistics counting
Protected all normal read calls to ensure we use the new calls in the server.
Made ha_partition a friend class so that partition code can call the old read functions
sql/item_subselect.cc:
Changed to use new ha_... calls
sql/lex.h:
Added keywords for new information schema tables and flush commands
sql/log.cc:
Added flush_slow_log()
Added counting of number of bytes sent to binary log
Removed not needed test of thd (It's used before, so it's safe to use)
Added THD object to MYSQL_BIN_LOG::write_cache() to simplify statistics counting
sql/log.h:
Added new parameter to write_cache()
Added flush_slow_log() functions.
sql/log_event.cc:
Updated call to mysql_reset_thd_for_next_command()
Changed to use new ha_... calls
sql/log_event_old.cc:
Updated call to mysql_reset_thd_for_next_command()
Changed to use new ha_... calls
sql/mysql_priv.h:
Updated call to mysql_reset_thd_for_next_command()
Added new statistics functions and variables needed by these.
sql/mysqld.cc:
Added new statistics variables and structures to handle these
Added new status variables:
- Com_show_client_statistics, Com_show_index_statistics, Com_show_table_statistics, Com_show_user_statistics
- Access_denied_errors, Busy_time (clock time), Binlog_bytes_written, Cpu_time, Empty_queries, Rows_set, Rows_read
Added new option 'userstat' to control if user statistics should be enabled or not
sql/opt_range.cc:
Changed to use new ha_... calls
sql/opt_range.h:
Changed to use new ha_... calls
sql/opt_sum.cc:
Changed to use new ha_... calls
sql/records.cc:
Changed to use new ha_... calls
sql/set_var.cc:
Added variable 'userstat'
sql/sp.cc:
Changed to use new ha_... calls
sql/sql_acl.cc:
Changed to use new ha_... calls
Added counting of access_denied_errors
sql/sql_base.cc:
Added call to statistics functions
sql/sql_class.cc:
Added usage of org_status_var, to store status variables at start of command
Added functions THD::update_stats(), THD::update_all_stats()
Fixed bug in add_to_status() and add_diff_to_status() where longlong variables where threated as long
sql/sql_class.h:
Added new status variables to status_var
Moved variables that was not ulong in status_var last.
Added variables to THD for storing temporary values during statistics counting
sql/sql_connect.cc:
Variables and functions to calculate user and client statistics
Added counting of access_denied_errors and lost_connections
sql/sql_cursor.cc:
Changed to use new ha_... calls
sql/sql_handler.cc:
Changed to use new ha_... calls
sql/sql_help.cc:
Changed to use new ha_... calls
sql/sql_insert.cc:
Changed to use new ha_... calls
sql/sql_lex.h:
Added SQLCOM_SHOW_USER_STATS, SQLCOM_SHOW_TABLE_STATS, SQLCOM_SHOW_INDEX_STATS, SQLCOM_SHOW_CLIENT_STATS
sql/sql_parse.cc:
Added handling of:
- SHOW CLIENT_STATISTICS
- SHOW USER_STATISTICS
- SHOW TABLE_STATISTICS
- SHOW INDEX_STATISTICS
Added handling of new FLUSH commands:
- FLUSH SLOW QUERY LOGS
- FLUSH TABLE_STATISTICS
- FLUSH INDEX_STATISTICS
- FLUSH USER_STATISTICS
- FLUSH CLIENT_STATISTICS
Added THD parameter to mysql_reset_thd_for_next_command()
Added initialization and calls to user statistics functions
Added increment of statistics variables empty_queries, rows_sent and access_denied_errors.
Added counting of cpu time per query
sql/sql_plugin.cc:
Changed to use new ha_... calls
sql/sql_prepare.cc:
Updated call to mysql_reset_thd_for_next_command()
sql/sql_select.cc:
Changed to use new ha_... calls
Indentation changes
sql/sql_servers.cc:
Changed to use new ha_... calls
sql/sql_show.cc:
Added counting of access denied errors
Added function for new information schema tables:
- CLIENT_STATISTICS
- USER_STATISTICS
- INDEX_STATISTICS
- TABLE_STATISTICS
Changed to use new ha_... calls
sql/sql_table.cc:
Changed to use new ha_... calls
sql/sql_udf.cc:
Changed to use new ha_... calls
sql/sql_update.cc:
Changed to use new ha_... calls
sql/sql_yacc.yy:
Add new show and flush commands
sql/structs.h:
Add name_length to KEY to avoid some strlen
Added cache_name to KEY for fast storage of keyvalue in cache
Added structs USER_STATS, TABLE_STATS, INDEX_STATS
Added function prototypes for statistics functions
sql/table.cc:
Store db+table+index name into keyinfo->cache_name
sql/table.h:
Added new information schema tables
sql/tztime.cc:
Changed to use new ha_... calls
2009-10-19 19:14:48 +02:00
|
|
|
int write_cache(THD *thd, IO_CACHE *cache, bool lock_log,
|
|
|
|
bool flush_and_sync);
|
2010-11-05 18:42:37 +01:00
|
|
|
void set_write_error(THD *thd, bool is_transactional);
|
BUG#43929 binlog corruption when max_binlog_cache_size is exceeded
Large transactions and statements may corrupt the binary log if the size of the
cache, which is set by the max_binlog_cache_size, is not enough to store the
the changes.
In a nutshell, to fix the bug, we save the position of the next character in the
cache before starting processing a statement. If there is a problem, we simply
restore the position thus removing any effect of the statement from the cache.
Unfortunately, to avoid corrupting the binary log, we may end up loosing changes
on non-transactional tables if they do not fit in the cache. In such cases, we
store an Incident_log_event in order to stop the slave and alert users that some
changes were not logged.
Precisely, for every non-transactional changes that do not fit into the cache,
we do the following:
a) the statement is *not* logged
b) an incident event is logged after committing/rolling back the transaction,
if any. Note that if a failure happens before writing the incident event to
the binary log, the slave will not stop and the master will not have reported
any error.
c) its respective statement gives an error
For transactional changes that do not fit into the cache, we do the following:
a) the statement is *not* logged
b) its respective statement gives an error
To work properly, this patch requires two additional things. Firstly, callers to
MYSQL_BIN_LOG::write and THD::binlog_query must handle any error returned and
take the appropriate actions such as undoing the effects of a statement. We
already changed some calls in the sql_insert.cc, sql_update.cc and sql_insert.cc
modules but the remaining calls spread all over the code should be handled in
BUG#37148. Secondly, statements must be either classified as DDL or DML because
DDLs that do not get into the cache must generate an incident event since they
cannot be rolled back.
2009-06-18 15:52:46 +02:00
|
|
|
bool check_write_error(THD *thd);
|
BUG#22864 (Rollback following CREATE... SELECT discards 'CREATE TABLE'
from log):
When row-based logging is used, the CREATE-SELECT is written as two
parts: as a CREATE TABLE statement and as the rows for the table. For
both transactional and non-transactional tables, the CREATE TABLE
statement was written to the transaction cache, as were the rows, and
on statement end, the entire transaction cache was written to the binary
log if the table was non-transactional. For transactional tables, the
events were kept in the transaction cache until end of transaction (or
statement that were not part of a transaction).
For the case when AUTOCOMMIT=0 and we are creating a transactional table
using a create select, we would then keep the CREATE TABLE statement and
the rows for the CREATE-SELECT, while executing the following statements.
On a rollback, the transaction cache would then be cleared, which would
also remove the CREATE TABLE statement. Hence no table would be created
on the slave, while there is an empty table on the master.
This relates to BUG#22865 where the table being created exists on the
master, but not on the slave during insertion of rows into the newly
created table. This occurs since the CREATE TABLE statement were still
in the transaction cache until the statement finished executing, and
possibly longer if the table was transactional.
This patch changes the behaviour of the CREATE-SELECT statement by
adding an implicit commit at the end of the statement when creating
non-temporary tables. Hence, non-temporary tables will be written to the
binary log on completion, and in the even of AUTOCOMMIT=0, a new
transaction will be started. Temporary tables do not commit an ongoing
transaction: neither as a pre- not a post-commit.
The events for both transactional and non-transactional tables are
saved in the transaction cache, and written to the binary log at end
of the statement.
mysql-test/r/rpl_row_create_table.result:
Result change
mysql-test/t/rpl_row_create_table.test:
Requring InnoDB for slave as well.
Adding test CREATE-SELECT that is rolled back explicitly.
Changing binlog positions.
sql/log.cc:
Adding helper class to handle lock/unlock of mutexes using RAII.
Factoring out code into write_cache() function to transaction cache
to binary log.
Adding function THD::binlog_flush_transaction_cache() to flush the
transaction cache to the binary log file.
Factoring out code into binlog_set_stmt_begin() to set the beginning
of statement savepoint.
Clearing before statement point when transaction cache is truncated
so that these points are out of range.
sql/log.h:
Adding method MYSQL_BIN_LOG::write_cache()
sql/log_event.h:
Replicating OPTION_NOT_AUTOCOMMIT flag (see changeset comment)
sql/mysql_priv.h:
Although left-shifting signed integer values is well-defined,
it has potential for strange errors. Using unsigned long long
instead of signed long long since this is the type of the options
flags.
sql/slave.cc:
Adding printout of transaction-critical thread flags.
sql/sql_class.h:
Adding function THD::binlog_flush_transaction_cache()
Adding function THD::binlog_set_stmt_begin()
sql/sql_insert.cc:
Adding code to cache events for a CREATE-SELECT statement.
Disabling binlog for SBR (but not RBR) when sending error for select part
of CREATE-SELECT statement.
Adding implicit commit at end of statement for non-temporary tables.
mysql-test/t/rpl_row_create_table-slave.opt:
New BitKeeper file ``mysql-test/t/rpl_row_create_table-slave.opt''
2006-12-21 09:29:02 +01:00
|
|
|
|
2007-02-26 20:06:10 +01:00
|
|
|
void start_union_events(THD *thd, query_id_t query_id_param);
|
2005-12-22 06:39:02 +01:00
|
|
|
void stop_union_events(THD *thd);
|
|
|
|
bool is_query_in_union(THD *thd, query_id_t query_id_param);
|
|
|
|
|
|
|
|
/*
|
|
|
|
v stands for vector
|
|
|
|
invoked as appendv(buf1,len1,buf2,len2,...,bufn,lenn,0)
|
|
|
|
*/
|
|
|
|
bool appendv(const char* buf,uint len,...);
|
|
|
|
bool append(Log_event* ev);
|
|
|
|
|
|
|
|
void make_log_name(char* buf, const char* log_ident);
|
|
|
|
bool is_active(const char* log_file_name);
|
|
|
|
int update_log_index(LOG_INFO* linfo, bool need_update_threads);
|
BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error
when generating new name.
If find_uniq_filename returns an error, then this error is not
being propagated upwards, and execution does not report error to
the user (although a entry in the error log is generated).
Additionally, some more errors were ignored in new_file_impl:
- when writing the rotate event
- when reopening the index and binary log file
This patch addresses this by propagating the error up in the
execution stack. Furthermore, when rotation of the binary log
fails, an incident event is written, because there may be a
chance that some changes for a given statement, were not properly
logged. For example, in SBR, LOAD DATA INFILE statement requires
more than one event to be logged, should rotation fail while
logging part of the LOAD DATA events, then the logged data would
become inconsistent with the data in the storage engine.
mysql-test/include/restart_mysqld.inc:
Refactored restart_mysqld so that it is not hardcoded for
mysqld.1, but rather for the current server.
mysql-test/suite/binlog/t/binlog_index.test:
The error on open of index and binary log on new_file_impl
is now caught. Thence the user will get an error message.
We need to accomodate this change in the test case for the
failing FLUSH LOGS.
mysql-test/suite/rpl/t/rpl_binlog_errors-master.opt:
Sets max_binlog_size to 4096.
mysql-test/suite/rpl/t/rpl_binlog_errors.test:
Added some test cases for asserting that the error is found
and reported.
sql/handler.cc:
Catching error now returned by unlog (in ha_commit_trans) and
returning it.
sql/log.cc:
Propagating errors from new_file_impl upwards. The errors that
new_file_impl catches now are:
- error on generate_new_name
- error on writing the rotate event
- error when opening the index or the binary log file.
sql/log.h:
Changing declaration of:
- rotate_and_purge
- new_file
- new_file_without_locking
- new_file_impl
- unlog
They now return int instead of void.
sql/mysql_priv.h:
Change signature of reload_acl_and_cache so that write_to_binlog
is an int instead of bool.
sql/mysqld.cc:
Redeclaring not_used var as int instead of bool.
sql/rpl_injector.cc:
Changes to catch the return from rotate_and_purge.
sql/slave.cc:
Changes to catch the return values for new_file and rotate_relay_log.
sql/slave.h:
Changes to rotate_relay_log declaration (now returns int
instead of void).
sql/sql_load.cc:
In SBR, some logging of LOAD DATA events goes through
IO_CACHE_CALLBACK invocation at mf_iocache.c:_my_b_get. The
IO_CACHE implementation is ignoring the return value for from
these callbacks (pre_read and post_read), so we need to find out
at the end of the execution if the error is set or not in THD.
sql/sql_parse.cc:
Catching the rotate_relay_log and rotate_and_purge return values.
Semantic change in reload_acl_and_cache so that we report errors
in binlog interactions through the write_to_binlog output parameter.
If there was any failure while rotating the binary log, we should
then report the error to the client when handling SQLCOMM_FLUSH.
2010-12-01 00:32:51 +01:00
|
|
|
int rotate_and_purge(uint flags);
|
2009-09-29 16:27:12 +02:00
|
|
|
/**
|
|
|
|
Flush binlog cache and synchronize to disk.
|
|
|
|
|
|
|
|
This function flushes events in binlog cache to binary log file,
|
|
|
|
it will do synchronizing according to the setting of system
|
|
|
|
variable 'sync_binlog'. If file is synchronized, @c synced will
|
|
|
|
be set to 1, otherwise 0.
|
|
|
|
|
|
|
|
@param[out] synced if not NULL, set to 1 if file is synchronized, otherwise 0
|
|
|
|
|
|
|
|
@retval 0 Success
|
|
|
|
@retval other Failure
|
|
|
|
*/
|
|
|
|
bool flush_and_sync(bool *synced);
|
2005-12-22 06:39:02 +01:00
|
|
|
int purge_logs(const char *to_log, bool included,
|
|
|
|
bool need_mutex, bool need_update_threads,
|
|
|
|
ulonglong *decrease_log_space);
|
|
|
|
int purge_logs_before_date(time_t purge_time);
|
2007-08-16 07:37:50 +02:00
|
|
|
int purge_first_log(Relay_log_info* rli, bool included);
|
2009-12-04 15:40:42 +01:00
|
|
|
int set_purge_index_file_name(const char *base_file_name);
|
|
|
|
int open_purge_index_file(bool destroy);
|
|
|
|
bool is_inited_purge_index_file();
|
|
|
|
int close_purge_index_file();
|
|
|
|
int clean_purge_index_file();
|
|
|
|
int sync_purge_index_file();
|
|
|
|
int register_purge_index_entry(const char* entry);
|
|
|
|
int register_create_index_entry(const char* entry);
|
|
|
|
int purge_index_entry(THD *thd, ulonglong *decrease_log_space,
|
|
|
|
bool need_mutex);
|
2005-12-22 06:39:02 +01:00
|
|
|
bool reset_logs(THD* thd);
|
|
|
|
void close(uint exiting);
|
|
|
|
|
|
|
|
// iterating through the log index file
|
|
|
|
int find_log_pos(LOG_INFO* linfo, const char* log_name,
|
|
|
|
bool need_mutex);
|
|
|
|
int find_next_log(LOG_INFO* linfo, bool need_mutex);
|
|
|
|
int get_current_log(LOG_INFO* linfo);
|
2006-09-04 14:19:39 +02:00
|
|
|
int raw_get_current_log(LOG_INFO* linfo);
|
2005-12-22 06:39:02 +01:00
|
|
|
uint next_file_id();
|
|
|
|
inline char* get_index_fname() { return index_file_name;}
|
|
|
|
inline char* get_log_fname() { return log_file_name; }
|
|
|
|
inline char* get_name() { return name; }
|
2010-01-07 06:42:07 +01:00
|
|
|
inline mysql_mutex_t* get_log_lock() { return &LOCK_log; }
|
2010-09-06 19:18:44 +02:00
|
|
|
inline mysql_cond_t* get_log_cond() { return &update_cond; }
|
2005-12-22 06:39:02 +01:00
|
|
|
inline IO_CACHE* get_log_file() { return &log_file; }
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
inline void lock_index() { mysql_mutex_lock(&LOCK_index);}
|
|
|
|
inline void unlock_index() { mysql_mutex_unlock(&LOCK_index);}
|
2005-12-22 06:39:02 +01:00
|
|
|
inline IO_CACHE *get_index_file() { return &index_file;}
|
|
|
|
inline uint32 get_open_count() { return open_count; }
|
|
|
|
};
|
|
|
|
|
2006-01-19 03:56:06 +01:00
|
|
|
class Log_event_handler
|
|
|
|
{
|
|
|
|
public:
|
2006-03-29 13:27:36 +02:00
|
|
|
Log_event_handler() {}
|
2006-01-19 03:56:06 +01:00
|
|
|
virtual bool init()= 0;
|
|
|
|
virtual void cleanup()= 0;
|
|
|
|
|
|
|
|
virtual bool log_slow(THD *thd, time_t current_time,
|
|
|
|
time_t query_start_arg, const char *user_host,
|
2007-07-30 10:33:50 +02:00
|
|
|
uint user_host_len, ulonglong query_utime,
|
|
|
|
ulonglong lock_utime, bool is_command,
|
2006-01-19 03:56:06 +01:00
|
|
|
const char *sql_text, uint sql_text_len)= 0;
|
|
|
|
virtual bool log_error(enum loglevel level, const char *format,
|
|
|
|
va_list args)= 0;
|
WL#3984 (Revise locking of mysql.general_log and mysql.slow_log)
Bug#25422 (Hang with log tables)
Bug 17876 (Truncating mysql.slow_log in a SP after using cursor locks the
thread)
Bug 23044 (Warnings on flush of a log table)
Bug 29129 (Resetting general_log while the GLOBAL READ LOCK is set causes
a deadlock)
Prior to this fix, the server would hang when performing concurrent
ALTER TABLE or TRUNCATE TABLE statements against the LOG TABLES,
which are mysql.general_log and mysql.slow_log.
The root cause traces to the following code:
in sql_base.cc, open_table()
if (table->in_use != thd)
{
/* wait_for_condition will unlock LOCK_open for us */
wait_for_condition(thd, &LOCK_open, &COND_refresh);
}
The problem with this code is that the current implementation of the
LOGGER creates 'fake' THD objects, like
- Log_to_csv_event_handler::general_log_thd
- Log_to_csv_event_handler::slow_log_thd
which are not associated to a real thread running in the server,
so that waiting for these non-existing threads to release table locks
cause the dead lock.
In general, the design of Log_to_csv_event_handler does not fit into the
general architecture of the server, so that the concept of general_log_thd
and slow_log_thd has to be abandoned:
- this implementation does not work with table locking
- it will not work with commands like SHOW PROCESSLIST
- having the log tables always opened does not integrate well with DDL
operations / FLUSH TABLES / SET GLOBAL READ_ONLY
With this patch, the fundamental design of the LOGGER has been changed to:
- always open and close a log table when writing a log
- remove totally the usage of fake THD objects
- clarify how locking of log tables is implemented in general.
See WL#3984 for details related to the new locking design.
Additional changes (misc bugs exposed and fixed):
1)
mysqldump which would ignore some tables in dump_all_tables_in_db(),
but forget to ignore the same in dump_all_views_in_db().
2)
mysqldump would also issue an empty "LOCK TABLE" command when all the tables
to lock are to be ignored (numrows == 0), instead of not issuing the query.
3)
Internal errors handlers could intercept errors but not warnings
(see sql_error.cc).
4)
Implementing a nested call to open tables, for the performance schema tables,
exposed an existing bug in remove_table_from_cache(), which would perform:
in_use->some_tables_deleted=1;
against another thread, without any consideration about thread locking.
This call inside remove_table_from_cache() was not required anyway,
since calling mysql_lock_abort() takes care of aborting -- cleanly -- threads
that might hold a lock on a table.
This line (in_use->some_tables_deleted=1) has been removed.
sql/handler.cc:
Moved logic for system / log tables in the SQL layer.
sql/handler.h:
Moved logic for system / log tables in the SQL layer.
sql/lock.cc:
Revised locking of log tables
sql/log.cc:
Major cleanup: changed how log tables are locked / written to.
sql/log.h:
Major cleanup: changed how log tables are locked / written to.
sql/mysql_priv.h:
performance schema helpers
sql/slave.cc:
open_ltable() lock flags
sql/sp.cc:
open_ltable() lock flags
sql/sql_acl.cc:
open_ltable() lock flags
sql/sql_class.h:
performance schema helpers
sql/sql_delete.cc:
log tables cleanup in TRUNCATE
sql/sql_error.cc:
Internal handlers can also intercept warnings
sql/sql_insert.cc:
open_ltable() lock flags
sql/sql_parse.cc:
performance schema helpers
sql/sql_plugin.cc:
open_ltable() lock flags
sql/sql_rename.cc:
log tables cleanup in RENAME
sql/sql_servers.cc:
open_ltable() lock flags
sql/sql_show.cc:
Move INFORMATION_SCHEMA_NAME to table.cc
sql/sql_table.cc:
log tables cleanup (admin operations, ALTER TABLE)
sql/sql_udf.cc:
open_ltable() lock flags
sql/table.cc:
Implemented TABLE_CATEGORY.
sql/share/errmsg.txt:
Changed the wording and name of ER_CANT_READ_LOCK_LOG_TABLE
sql/table.h:
Implemented TABLE_CATEGORY.
storage/csv/ha_tina.cc:
Moved logic for system / log tables in the SQL layer.
storage/csv/ha_tina.h:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.cc:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.h:
Moved logic for system / log tables in the SQL layer.
client/mysqldump.c:
Don't lock tables in the ignore list.
Don't issue empty LOCK TABLES queries.
sql/sql_base.cc:
log tables cleanup
performance schema helpers
mysql-test/r/ps.result:
Adjust test results
mysql-test/r/show_check.result:
Adjust test results
mysql-test/r/status.result:
Adjust test results
mysql-test/t/log_state.test:
Added tests for Bug#29129
mysql-test/t/ps.test:
Make the test output deterministic
mysql-test/t/show_check.test:
Make the test output deterministic
mysql-test/r/log_state.result:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
Adjust test results
mysql-test/r/log_tables.result:
cleanup for -ps-protocol
mysql-test/t/log_tables.test:
cleanup for -ps-protocol
sql/set_var.cc:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
log tables cleanup
2007-07-27 08:31:06 +02:00
|
|
|
virtual bool log_general(THD *thd, time_t event_time, const char *user_host,
|
2006-01-19 03:56:06 +01:00
|
|
|
uint user_host_len, int thread_id,
|
|
|
|
const char *command_type, uint command_type_len,
|
2006-02-03 11:05:14 +01:00
|
|
|
const char *sql_text, uint sql_text_len,
|
|
|
|
CHARSET_INFO *client_cs)= 0;
|
2006-01-19 03:56:06 +01:00
|
|
|
virtual ~Log_event_handler() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-05-27 23:28:24 +02:00
|
|
|
int check_if_log_table(size_t db_len, const char *db, size_t table_name_len,
|
|
|
|
const char *table_name, bool check_if_opened);
|
Fix for Bug #17544 "Cannot do atomic log rotate",
Bug #21785 "Server crashes after rename of the log table" and
Bug #21966 "Strange warnings on create like/repair of the log
tables"
According to the patch, from now on, one should use RENAME to
perform a log table rotation (this should also be reflected in
the manual).
Here is a sample:
use mysql;
CREATE TABLE IF NOT EXISTS general_log2 LIKE general_log;
RENAME TABLE general_log TO general_log_backup, general_log2 TO general_log;
The rules for Rename of the log tables are following:
IF 1. Log tables are enabled
AND 2. Rename operates on the log table and nothing is being
renamed to the log table.
DO 3. Throw an error message.
ELSE 4. Perform rename.
The very RENAME query will go the the old (backup) table. This is
consistent with the behavoiur we have with binlog ROTATE LOGS
statement.
Other problems, which are solved by the patch are:
1) Now REPAIR of the log table is exclusive operation (as it should be), this
also eliminates lock-related warnings. and
2) CREATE LIKE TABLE now usese usual read lock on the source table rather
then name lock, which is too restrictive. This way we get rid of another
log table-related warning, which occured because of the above fact
(as a side-effect, name lock resulted in a warning).
mysql-test/r/log_tables.result:
update result file
mysql-test/t/log_tables.test:
Add tests for the bugs
sql/handler.cc:
update comment
sql/handler.h:
update function to reflect changes in log tables
locking logic.
sql/lock.cc:
Now we allow locking of the log tables for "privileged" threads
Privileged thread must explicitly close and lock log tables. This
is required for admin operations such as REPAIR.
sql/log.cc:
Changes to the file:
1) Add checks for table schema. It's more important now,
as we allow rename of the log tables. Since we should
check for schema when writing to a log table.
E.g. if one created a table with one-only comlumn and
renamed it to general_log, the server should cope with
it.
2) refactor LOGGER::flush(), so that we can now use the same
machinery as we use in FLUSH LOGS in other statements:
whenever we have to perform a serious operation on the log
tables, we have to
(a) lock logger, which blocks other concurrent statements (such
as selects) (b) close logs. Then perform an
exclusive operation, c) reenable logs and d) unlock logger.
3) Add a function to check if a given table is a log table.
4) Add support for "privileged" thread
5) merge is_[general/slow]_log_table_enabled() into one function.
6) Add new function: reopen _log_tables, which reopens the tables,
which were enabled (after temporary close, required for admin
operation)
sql/log.h:
1) add a new call close_n_lock_tables(). Now we use it instead of
LOGGER::flush() in FLUSH LOGS implementation.
2) add a prototype for the function to check if a given
table is a log table;
3) add privileged table flag to table logger
4) merge is_[general/slow]_log_table_enabled()
into one function.
sql/mysql_priv.h:
move log table defines to log.h
sql/sql_delete.cc:
use new function check_if_log_table() instead of direct strcmp
sql/sql_rename.cc:
Traverse the list of tables in mysql_rename_tables
to make sure that log tables are processed correctly
(that is, according to the rules specified in the
main CS comment)
sql/sql_table.cc:
1) mysql_admin_table() should disable logs if it performs
exclusive admin operation on a log table. This way we
also eliminate warning on REPAIR of the log table.
2) mysql_create_like_table should read-lock the source table
instead getting name lock on it. Name lock is too restrictive
in this case.
sql/share/errmsg.txt:
Add a new error message for rename of the log tables
sql/table.cc:
use new function instead of direct strcmp.
change my_strcasecmp() -> strcmp(), when
comparing system db and table names
storage/csv/ha_tina.cc:
update function to reflect changes in log tables
locking logic.
storage/myisam/ha_myisam.cc:
update function to reflect changes in log tables
locking logic.
2006-10-13 15:26:46 +02:00
|
|
|
|
2006-01-19 03:56:06 +01:00
|
|
|
class Log_to_csv_event_handler: public Log_event_handler
|
|
|
|
{
|
|
|
|
friend class LOGGER;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Log_to_csv_event_handler();
|
|
|
|
~Log_to_csv_event_handler();
|
|
|
|
virtual bool init();
|
|
|
|
virtual void cleanup();
|
|
|
|
|
|
|
|
virtual bool log_slow(THD *thd, time_t current_time,
|
|
|
|
time_t query_start_arg, const char *user_host,
|
2007-07-30 10:33:50 +02:00
|
|
|
uint user_host_len, ulonglong query_utime,
|
|
|
|
ulonglong lock_utime, bool is_command,
|
2006-01-19 03:56:06 +01:00
|
|
|
const char *sql_text, uint sql_text_len);
|
|
|
|
virtual bool log_error(enum loglevel level, const char *format,
|
|
|
|
va_list args);
|
WL#3984 (Revise locking of mysql.general_log and mysql.slow_log)
Bug#25422 (Hang with log tables)
Bug 17876 (Truncating mysql.slow_log in a SP after using cursor locks the
thread)
Bug 23044 (Warnings on flush of a log table)
Bug 29129 (Resetting general_log while the GLOBAL READ LOCK is set causes
a deadlock)
Prior to this fix, the server would hang when performing concurrent
ALTER TABLE or TRUNCATE TABLE statements against the LOG TABLES,
which are mysql.general_log and mysql.slow_log.
The root cause traces to the following code:
in sql_base.cc, open_table()
if (table->in_use != thd)
{
/* wait_for_condition will unlock LOCK_open for us */
wait_for_condition(thd, &LOCK_open, &COND_refresh);
}
The problem with this code is that the current implementation of the
LOGGER creates 'fake' THD objects, like
- Log_to_csv_event_handler::general_log_thd
- Log_to_csv_event_handler::slow_log_thd
which are not associated to a real thread running in the server,
so that waiting for these non-existing threads to release table locks
cause the dead lock.
In general, the design of Log_to_csv_event_handler does not fit into the
general architecture of the server, so that the concept of general_log_thd
and slow_log_thd has to be abandoned:
- this implementation does not work with table locking
- it will not work with commands like SHOW PROCESSLIST
- having the log tables always opened does not integrate well with DDL
operations / FLUSH TABLES / SET GLOBAL READ_ONLY
With this patch, the fundamental design of the LOGGER has been changed to:
- always open and close a log table when writing a log
- remove totally the usage of fake THD objects
- clarify how locking of log tables is implemented in general.
See WL#3984 for details related to the new locking design.
Additional changes (misc bugs exposed and fixed):
1)
mysqldump which would ignore some tables in dump_all_tables_in_db(),
but forget to ignore the same in dump_all_views_in_db().
2)
mysqldump would also issue an empty "LOCK TABLE" command when all the tables
to lock are to be ignored (numrows == 0), instead of not issuing the query.
3)
Internal errors handlers could intercept errors but not warnings
(see sql_error.cc).
4)
Implementing a nested call to open tables, for the performance schema tables,
exposed an existing bug in remove_table_from_cache(), which would perform:
in_use->some_tables_deleted=1;
against another thread, without any consideration about thread locking.
This call inside remove_table_from_cache() was not required anyway,
since calling mysql_lock_abort() takes care of aborting -- cleanly -- threads
that might hold a lock on a table.
This line (in_use->some_tables_deleted=1) has been removed.
sql/handler.cc:
Moved logic for system / log tables in the SQL layer.
sql/handler.h:
Moved logic for system / log tables in the SQL layer.
sql/lock.cc:
Revised locking of log tables
sql/log.cc:
Major cleanup: changed how log tables are locked / written to.
sql/log.h:
Major cleanup: changed how log tables are locked / written to.
sql/mysql_priv.h:
performance schema helpers
sql/slave.cc:
open_ltable() lock flags
sql/sp.cc:
open_ltable() lock flags
sql/sql_acl.cc:
open_ltable() lock flags
sql/sql_class.h:
performance schema helpers
sql/sql_delete.cc:
log tables cleanup in TRUNCATE
sql/sql_error.cc:
Internal handlers can also intercept warnings
sql/sql_insert.cc:
open_ltable() lock flags
sql/sql_parse.cc:
performance schema helpers
sql/sql_plugin.cc:
open_ltable() lock flags
sql/sql_rename.cc:
log tables cleanup in RENAME
sql/sql_servers.cc:
open_ltable() lock flags
sql/sql_show.cc:
Move INFORMATION_SCHEMA_NAME to table.cc
sql/sql_table.cc:
log tables cleanup (admin operations, ALTER TABLE)
sql/sql_udf.cc:
open_ltable() lock flags
sql/table.cc:
Implemented TABLE_CATEGORY.
sql/share/errmsg.txt:
Changed the wording and name of ER_CANT_READ_LOCK_LOG_TABLE
sql/table.h:
Implemented TABLE_CATEGORY.
storage/csv/ha_tina.cc:
Moved logic for system / log tables in the SQL layer.
storage/csv/ha_tina.h:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.cc:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.h:
Moved logic for system / log tables in the SQL layer.
client/mysqldump.c:
Don't lock tables in the ignore list.
Don't issue empty LOCK TABLES queries.
sql/sql_base.cc:
log tables cleanup
performance schema helpers
mysql-test/r/ps.result:
Adjust test results
mysql-test/r/show_check.result:
Adjust test results
mysql-test/r/status.result:
Adjust test results
mysql-test/t/log_state.test:
Added tests for Bug#29129
mysql-test/t/ps.test:
Make the test output deterministic
mysql-test/t/show_check.test:
Make the test output deterministic
mysql-test/r/log_state.result:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
Adjust test results
mysql-test/r/log_tables.result:
cleanup for -ps-protocol
mysql-test/t/log_tables.test:
cleanup for -ps-protocol
sql/set_var.cc:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
log tables cleanup
2007-07-27 08:31:06 +02:00
|
|
|
virtual bool log_general(THD *thd, time_t event_time, const char *user_host,
|
2006-01-19 03:56:06 +01:00
|
|
|
uint user_host_len, int thread_id,
|
|
|
|
const char *command_type, uint command_type_len,
|
2006-02-03 11:05:14 +01:00
|
|
|
const char *sql_text, uint sql_text_len,
|
WL#3984 (Revise locking of mysql.general_log and mysql.slow_log)
Bug#25422 (Hang with log tables)
Bug 17876 (Truncating mysql.slow_log in a SP after using cursor locks the
thread)
Bug 23044 (Warnings on flush of a log table)
Bug 29129 (Resetting general_log while the GLOBAL READ LOCK is set causes
a deadlock)
Prior to this fix, the server would hang when performing concurrent
ALTER TABLE or TRUNCATE TABLE statements against the LOG TABLES,
which are mysql.general_log and mysql.slow_log.
The root cause traces to the following code:
in sql_base.cc, open_table()
if (table->in_use != thd)
{
/* wait_for_condition will unlock LOCK_open for us */
wait_for_condition(thd, &LOCK_open, &COND_refresh);
}
The problem with this code is that the current implementation of the
LOGGER creates 'fake' THD objects, like
- Log_to_csv_event_handler::general_log_thd
- Log_to_csv_event_handler::slow_log_thd
which are not associated to a real thread running in the server,
so that waiting for these non-existing threads to release table locks
cause the dead lock.
In general, the design of Log_to_csv_event_handler does not fit into the
general architecture of the server, so that the concept of general_log_thd
and slow_log_thd has to be abandoned:
- this implementation does not work with table locking
- it will not work with commands like SHOW PROCESSLIST
- having the log tables always opened does not integrate well with DDL
operations / FLUSH TABLES / SET GLOBAL READ_ONLY
With this patch, the fundamental design of the LOGGER has been changed to:
- always open and close a log table when writing a log
- remove totally the usage of fake THD objects
- clarify how locking of log tables is implemented in general.
See WL#3984 for details related to the new locking design.
Additional changes (misc bugs exposed and fixed):
1)
mysqldump which would ignore some tables in dump_all_tables_in_db(),
but forget to ignore the same in dump_all_views_in_db().
2)
mysqldump would also issue an empty "LOCK TABLE" command when all the tables
to lock are to be ignored (numrows == 0), instead of not issuing the query.
3)
Internal errors handlers could intercept errors but not warnings
(see sql_error.cc).
4)
Implementing a nested call to open tables, for the performance schema tables,
exposed an existing bug in remove_table_from_cache(), which would perform:
in_use->some_tables_deleted=1;
against another thread, without any consideration about thread locking.
This call inside remove_table_from_cache() was not required anyway,
since calling mysql_lock_abort() takes care of aborting -- cleanly -- threads
that might hold a lock on a table.
This line (in_use->some_tables_deleted=1) has been removed.
sql/handler.cc:
Moved logic for system / log tables in the SQL layer.
sql/handler.h:
Moved logic for system / log tables in the SQL layer.
sql/lock.cc:
Revised locking of log tables
sql/log.cc:
Major cleanup: changed how log tables are locked / written to.
sql/log.h:
Major cleanup: changed how log tables are locked / written to.
sql/mysql_priv.h:
performance schema helpers
sql/slave.cc:
open_ltable() lock flags
sql/sp.cc:
open_ltable() lock flags
sql/sql_acl.cc:
open_ltable() lock flags
sql/sql_class.h:
performance schema helpers
sql/sql_delete.cc:
log tables cleanup in TRUNCATE
sql/sql_error.cc:
Internal handlers can also intercept warnings
sql/sql_insert.cc:
open_ltable() lock flags
sql/sql_parse.cc:
performance schema helpers
sql/sql_plugin.cc:
open_ltable() lock flags
sql/sql_rename.cc:
log tables cleanup in RENAME
sql/sql_servers.cc:
open_ltable() lock flags
sql/sql_show.cc:
Move INFORMATION_SCHEMA_NAME to table.cc
sql/sql_table.cc:
log tables cleanup (admin operations, ALTER TABLE)
sql/sql_udf.cc:
open_ltable() lock flags
sql/table.cc:
Implemented TABLE_CATEGORY.
sql/share/errmsg.txt:
Changed the wording and name of ER_CANT_READ_LOCK_LOG_TABLE
sql/table.h:
Implemented TABLE_CATEGORY.
storage/csv/ha_tina.cc:
Moved logic for system / log tables in the SQL layer.
storage/csv/ha_tina.h:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.cc:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.h:
Moved logic for system / log tables in the SQL layer.
client/mysqldump.c:
Don't lock tables in the ignore list.
Don't issue empty LOCK TABLES queries.
sql/sql_base.cc:
log tables cleanup
performance schema helpers
mysql-test/r/ps.result:
Adjust test results
mysql-test/r/show_check.result:
Adjust test results
mysql-test/r/status.result:
Adjust test results
mysql-test/t/log_state.test:
Added tests for Bug#29129
mysql-test/t/ps.test:
Make the test output deterministic
mysql-test/t/show_check.test:
Make the test output deterministic
mysql-test/r/log_state.result:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
Adjust test results
mysql-test/r/log_tables.result:
cleanup for -ps-protocol
mysql-test/t/log_tables.test:
cleanup for -ps-protocol
sql/set_var.cc:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
log tables cleanup
2007-07-27 08:31:06 +02:00
|
|
|
CHARSET_INFO *client_cs);
|
|
|
|
|
|
|
|
int activate_log(THD *thd, uint log_type);
|
2006-01-19 03:56:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
Fix for Bug #17544 "Cannot do atomic log rotate",
Bug #21785 "Server crashes after rename of the log table" and
Bug #21966 "Strange warnings on create like/repair of the log
tables"
According to the patch, from now on, one should use RENAME to
perform a log table rotation (this should also be reflected in
the manual).
Here is a sample:
use mysql;
CREATE TABLE IF NOT EXISTS general_log2 LIKE general_log;
RENAME TABLE general_log TO general_log_backup, general_log2 TO general_log;
The rules for Rename of the log tables are following:
IF 1. Log tables are enabled
AND 2. Rename operates on the log table and nothing is being
renamed to the log table.
DO 3. Throw an error message.
ELSE 4. Perform rename.
The very RENAME query will go the the old (backup) table. This is
consistent with the behavoiur we have with binlog ROTATE LOGS
statement.
Other problems, which are solved by the patch are:
1) Now REPAIR of the log table is exclusive operation (as it should be), this
also eliminates lock-related warnings. and
2) CREATE LIKE TABLE now usese usual read lock on the source table rather
then name lock, which is too restrictive. This way we get rid of another
log table-related warning, which occured because of the above fact
(as a side-effect, name lock resulted in a warning).
mysql-test/r/log_tables.result:
update result file
mysql-test/t/log_tables.test:
Add tests for the bugs
sql/handler.cc:
update comment
sql/handler.h:
update function to reflect changes in log tables
locking logic.
sql/lock.cc:
Now we allow locking of the log tables for "privileged" threads
Privileged thread must explicitly close and lock log tables. This
is required for admin operations such as REPAIR.
sql/log.cc:
Changes to the file:
1) Add checks for table schema. It's more important now,
as we allow rename of the log tables. Since we should
check for schema when writing to a log table.
E.g. if one created a table with one-only comlumn and
renamed it to general_log, the server should cope with
it.
2) refactor LOGGER::flush(), so that we can now use the same
machinery as we use in FLUSH LOGS in other statements:
whenever we have to perform a serious operation on the log
tables, we have to
(a) lock logger, which blocks other concurrent statements (such
as selects) (b) close logs. Then perform an
exclusive operation, c) reenable logs and d) unlock logger.
3) Add a function to check if a given table is a log table.
4) Add support for "privileged" thread
5) merge is_[general/slow]_log_table_enabled() into one function.
6) Add new function: reopen _log_tables, which reopens the tables,
which were enabled (after temporary close, required for admin
operation)
sql/log.h:
1) add a new call close_n_lock_tables(). Now we use it instead of
LOGGER::flush() in FLUSH LOGS implementation.
2) add a prototype for the function to check if a given
table is a log table;
3) add privileged table flag to table logger
4) merge is_[general/slow]_log_table_enabled()
into one function.
sql/mysql_priv.h:
move log table defines to log.h
sql/sql_delete.cc:
use new function check_if_log_table() instead of direct strcmp
sql/sql_rename.cc:
Traverse the list of tables in mysql_rename_tables
to make sure that log tables are processed correctly
(that is, according to the rules specified in the
main CS comment)
sql/sql_table.cc:
1) mysql_admin_table() should disable logs if it performs
exclusive admin operation on a log table. This way we
also eliminate warning on REPAIR of the log table.
2) mysql_create_like_table should read-lock the source table
instead getting name lock on it. Name lock is too restrictive
in this case.
sql/share/errmsg.txt:
Add a new error message for rename of the log tables
sql/table.cc:
use new function instead of direct strcmp.
change my_strcasecmp() -> strcmp(), when
comparing system db and table names
storage/csv/ha_tina.cc:
update function to reflect changes in log tables
locking logic.
storage/myisam/ha_myisam.cc:
update function to reflect changes in log tables
locking logic.
2006-10-13 15:26:46 +02:00
|
|
|
/* type of the log table */
|
|
|
|
#define QUERY_LOG_SLOW 1
|
|
|
|
#define QUERY_LOG_GENERAL 2
|
|
|
|
|
2006-01-19 03:56:06 +01:00
|
|
|
class Log_to_file_event_handler: public Log_event_handler
|
|
|
|
{
|
2006-06-05 03:34:34 +02:00
|
|
|
MYSQL_QUERY_LOG mysql_log;
|
|
|
|
MYSQL_QUERY_LOG mysql_slow_log;
|
2006-01-19 03:56:06 +01:00
|
|
|
bool is_initialized;
|
|
|
|
public:
|
|
|
|
Log_to_file_event_handler(): is_initialized(FALSE)
|
|
|
|
{}
|
|
|
|
virtual bool init();
|
|
|
|
virtual void cleanup();
|
|
|
|
|
|
|
|
virtual bool log_slow(THD *thd, time_t current_time,
|
|
|
|
time_t query_start_arg, const char *user_host,
|
2007-07-30 10:33:50 +02:00
|
|
|
uint user_host_len, ulonglong query_utime,
|
|
|
|
ulonglong lock_utime, bool is_command,
|
2006-01-19 03:56:06 +01:00
|
|
|
const char *sql_text, uint sql_text_len);
|
|
|
|
virtual bool log_error(enum loglevel level, const char *format,
|
|
|
|
va_list args);
|
WL#3984 (Revise locking of mysql.general_log and mysql.slow_log)
Bug#25422 (Hang with log tables)
Bug 17876 (Truncating mysql.slow_log in a SP after using cursor locks the
thread)
Bug 23044 (Warnings on flush of a log table)
Bug 29129 (Resetting general_log while the GLOBAL READ LOCK is set causes
a deadlock)
Prior to this fix, the server would hang when performing concurrent
ALTER TABLE or TRUNCATE TABLE statements against the LOG TABLES,
which are mysql.general_log and mysql.slow_log.
The root cause traces to the following code:
in sql_base.cc, open_table()
if (table->in_use != thd)
{
/* wait_for_condition will unlock LOCK_open for us */
wait_for_condition(thd, &LOCK_open, &COND_refresh);
}
The problem with this code is that the current implementation of the
LOGGER creates 'fake' THD objects, like
- Log_to_csv_event_handler::general_log_thd
- Log_to_csv_event_handler::slow_log_thd
which are not associated to a real thread running in the server,
so that waiting for these non-existing threads to release table locks
cause the dead lock.
In general, the design of Log_to_csv_event_handler does not fit into the
general architecture of the server, so that the concept of general_log_thd
and slow_log_thd has to be abandoned:
- this implementation does not work with table locking
- it will not work with commands like SHOW PROCESSLIST
- having the log tables always opened does not integrate well with DDL
operations / FLUSH TABLES / SET GLOBAL READ_ONLY
With this patch, the fundamental design of the LOGGER has been changed to:
- always open and close a log table when writing a log
- remove totally the usage of fake THD objects
- clarify how locking of log tables is implemented in general.
See WL#3984 for details related to the new locking design.
Additional changes (misc bugs exposed and fixed):
1)
mysqldump which would ignore some tables in dump_all_tables_in_db(),
but forget to ignore the same in dump_all_views_in_db().
2)
mysqldump would also issue an empty "LOCK TABLE" command when all the tables
to lock are to be ignored (numrows == 0), instead of not issuing the query.
3)
Internal errors handlers could intercept errors but not warnings
(see sql_error.cc).
4)
Implementing a nested call to open tables, for the performance schema tables,
exposed an existing bug in remove_table_from_cache(), which would perform:
in_use->some_tables_deleted=1;
against another thread, without any consideration about thread locking.
This call inside remove_table_from_cache() was not required anyway,
since calling mysql_lock_abort() takes care of aborting -- cleanly -- threads
that might hold a lock on a table.
This line (in_use->some_tables_deleted=1) has been removed.
sql/handler.cc:
Moved logic for system / log tables in the SQL layer.
sql/handler.h:
Moved logic for system / log tables in the SQL layer.
sql/lock.cc:
Revised locking of log tables
sql/log.cc:
Major cleanup: changed how log tables are locked / written to.
sql/log.h:
Major cleanup: changed how log tables are locked / written to.
sql/mysql_priv.h:
performance schema helpers
sql/slave.cc:
open_ltable() lock flags
sql/sp.cc:
open_ltable() lock flags
sql/sql_acl.cc:
open_ltable() lock flags
sql/sql_class.h:
performance schema helpers
sql/sql_delete.cc:
log tables cleanup in TRUNCATE
sql/sql_error.cc:
Internal handlers can also intercept warnings
sql/sql_insert.cc:
open_ltable() lock flags
sql/sql_parse.cc:
performance schema helpers
sql/sql_plugin.cc:
open_ltable() lock flags
sql/sql_rename.cc:
log tables cleanup in RENAME
sql/sql_servers.cc:
open_ltable() lock flags
sql/sql_show.cc:
Move INFORMATION_SCHEMA_NAME to table.cc
sql/sql_table.cc:
log tables cleanup (admin operations, ALTER TABLE)
sql/sql_udf.cc:
open_ltable() lock flags
sql/table.cc:
Implemented TABLE_CATEGORY.
sql/share/errmsg.txt:
Changed the wording and name of ER_CANT_READ_LOCK_LOG_TABLE
sql/table.h:
Implemented TABLE_CATEGORY.
storage/csv/ha_tina.cc:
Moved logic for system / log tables in the SQL layer.
storage/csv/ha_tina.h:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.cc:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.h:
Moved logic for system / log tables in the SQL layer.
client/mysqldump.c:
Don't lock tables in the ignore list.
Don't issue empty LOCK TABLES queries.
sql/sql_base.cc:
log tables cleanup
performance schema helpers
mysql-test/r/ps.result:
Adjust test results
mysql-test/r/show_check.result:
Adjust test results
mysql-test/r/status.result:
Adjust test results
mysql-test/t/log_state.test:
Added tests for Bug#29129
mysql-test/t/ps.test:
Make the test output deterministic
mysql-test/t/show_check.test:
Make the test output deterministic
mysql-test/r/log_state.result:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
Adjust test results
mysql-test/r/log_tables.result:
cleanup for -ps-protocol
mysql-test/t/log_tables.test:
cleanup for -ps-protocol
sql/set_var.cc:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
log tables cleanup
2007-07-27 08:31:06 +02:00
|
|
|
virtual bool log_general(THD *thd, time_t event_time, const char *user_host,
|
2006-01-19 03:56:06 +01:00
|
|
|
uint user_host_len, int thread_id,
|
|
|
|
const char *command_type, uint command_type_len,
|
2006-02-03 11:05:14 +01:00
|
|
|
const char *sql_text, uint sql_text_len,
|
|
|
|
CHARSET_INFO *client_cs);
|
2006-01-19 03:56:06 +01:00
|
|
|
void flush();
|
|
|
|
void init_pthread_objects();
|
2006-06-21 11:53:40 +02:00
|
|
|
MYSQL_QUERY_LOG *get_mysql_slow_log() { return &mysql_slow_log; }
|
|
|
|
MYSQL_QUERY_LOG *get_mysql_log() { return &mysql_log; }
|
2006-01-19 03:56:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Class which manages slow, general and error log event handlers */
|
|
|
|
class LOGGER
|
|
|
|
{
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_rwlock_t LOCK_logger;
|
2006-01-19 03:56:06 +01:00
|
|
|
/* flag to check whether logger mutex is initialized */
|
|
|
|
uint inited;
|
|
|
|
|
|
|
|
/* available log handlers */
|
|
|
|
Log_to_csv_event_handler *table_log_handler;
|
|
|
|
Log_to_file_event_handler *file_log_handler;
|
|
|
|
|
|
|
|
/* NULL-terminated arrays of log handlers */
|
|
|
|
Log_event_handler *error_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
|
|
|
|
Log_event_handler *slow_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
|
|
|
|
Log_event_handler *general_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool is_log_tables_initialized;
|
|
|
|
|
|
|
|
LOGGER() : inited(0), table_log_handler(NULL),
|
|
|
|
file_log_handler(NULL), is_log_tables_initialized(FALSE)
|
|
|
|
{}
|
2010-01-07 06:42:07 +01:00
|
|
|
void lock_shared() { mysql_rwlock_rdlock(&LOCK_logger); }
|
|
|
|
void lock_exclusive() { mysql_rwlock_wrlock(&LOCK_logger); }
|
|
|
|
void unlock() { mysql_rwlock_unlock(&LOCK_logger); }
|
WL#3984 (Revise locking of mysql.general_log and mysql.slow_log)
Bug#25422 (Hang with log tables)
Bug 17876 (Truncating mysql.slow_log in a SP after using cursor locks the
thread)
Bug 23044 (Warnings on flush of a log table)
Bug 29129 (Resetting general_log while the GLOBAL READ LOCK is set causes
a deadlock)
Prior to this fix, the server would hang when performing concurrent
ALTER TABLE or TRUNCATE TABLE statements against the LOG TABLES,
which are mysql.general_log and mysql.slow_log.
The root cause traces to the following code:
in sql_base.cc, open_table()
if (table->in_use != thd)
{
/* wait_for_condition will unlock LOCK_open for us */
wait_for_condition(thd, &LOCK_open, &COND_refresh);
}
The problem with this code is that the current implementation of the
LOGGER creates 'fake' THD objects, like
- Log_to_csv_event_handler::general_log_thd
- Log_to_csv_event_handler::slow_log_thd
which are not associated to a real thread running in the server,
so that waiting for these non-existing threads to release table locks
cause the dead lock.
In general, the design of Log_to_csv_event_handler does not fit into the
general architecture of the server, so that the concept of general_log_thd
and slow_log_thd has to be abandoned:
- this implementation does not work with table locking
- it will not work with commands like SHOW PROCESSLIST
- having the log tables always opened does not integrate well with DDL
operations / FLUSH TABLES / SET GLOBAL READ_ONLY
With this patch, the fundamental design of the LOGGER has been changed to:
- always open and close a log table when writing a log
- remove totally the usage of fake THD objects
- clarify how locking of log tables is implemented in general.
See WL#3984 for details related to the new locking design.
Additional changes (misc bugs exposed and fixed):
1)
mysqldump which would ignore some tables in dump_all_tables_in_db(),
but forget to ignore the same in dump_all_views_in_db().
2)
mysqldump would also issue an empty "LOCK TABLE" command when all the tables
to lock are to be ignored (numrows == 0), instead of not issuing the query.
3)
Internal errors handlers could intercept errors but not warnings
(see sql_error.cc).
4)
Implementing a nested call to open tables, for the performance schema tables,
exposed an existing bug in remove_table_from_cache(), which would perform:
in_use->some_tables_deleted=1;
against another thread, without any consideration about thread locking.
This call inside remove_table_from_cache() was not required anyway,
since calling mysql_lock_abort() takes care of aborting -- cleanly -- threads
that might hold a lock on a table.
This line (in_use->some_tables_deleted=1) has been removed.
sql/handler.cc:
Moved logic for system / log tables in the SQL layer.
sql/handler.h:
Moved logic for system / log tables in the SQL layer.
sql/lock.cc:
Revised locking of log tables
sql/log.cc:
Major cleanup: changed how log tables are locked / written to.
sql/log.h:
Major cleanup: changed how log tables are locked / written to.
sql/mysql_priv.h:
performance schema helpers
sql/slave.cc:
open_ltable() lock flags
sql/sp.cc:
open_ltable() lock flags
sql/sql_acl.cc:
open_ltable() lock flags
sql/sql_class.h:
performance schema helpers
sql/sql_delete.cc:
log tables cleanup in TRUNCATE
sql/sql_error.cc:
Internal handlers can also intercept warnings
sql/sql_insert.cc:
open_ltable() lock flags
sql/sql_parse.cc:
performance schema helpers
sql/sql_plugin.cc:
open_ltable() lock flags
sql/sql_rename.cc:
log tables cleanup in RENAME
sql/sql_servers.cc:
open_ltable() lock flags
sql/sql_show.cc:
Move INFORMATION_SCHEMA_NAME to table.cc
sql/sql_table.cc:
log tables cleanup (admin operations, ALTER TABLE)
sql/sql_udf.cc:
open_ltable() lock flags
sql/table.cc:
Implemented TABLE_CATEGORY.
sql/share/errmsg.txt:
Changed the wording and name of ER_CANT_READ_LOCK_LOG_TABLE
sql/table.h:
Implemented TABLE_CATEGORY.
storage/csv/ha_tina.cc:
Moved logic for system / log tables in the SQL layer.
storage/csv/ha_tina.h:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.cc:
Moved logic for system / log tables in the SQL layer.
storage/myisam/ha_myisam.h:
Moved logic for system / log tables in the SQL layer.
client/mysqldump.c:
Don't lock tables in the ignore list.
Don't issue empty LOCK TABLES queries.
sql/sql_base.cc:
log tables cleanup
performance schema helpers
mysql-test/r/ps.result:
Adjust test results
mysql-test/r/show_check.result:
Adjust test results
mysql-test/r/status.result:
Adjust test results
mysql-test/t/log_state.test:
Added tests for Bug#29129
mysql-test/t/ps.test:
Make the test output deterministic
mysql-test/t/show_check.test:
Make the test output deterministic
mysql-test/r/log_state.result:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
Adjust test results
mysql-test/r/log_tables.result:
cleanup for -ps-protocol
mysql-test/t/log_tables.test:
cleanup for -ps-protocol
sql/set_var.cc:
Changed the default location of the log output to LOG_FILE,
for backward compatibility with MySQL 5.0
---
log tables cleanup
2007-07-27 08:31:06 +02:00
|
|
|
bool is_log_table_enabled(uint log_table_type);
|
2007-10-18 20:45:07 +02:00
|
|
|
bool log_command(THD *thd, enum enum_server_command command);
|
|
|
|
|
2006-01-19 03:56:06 +01:00
|
|
|
/*
|
|
|
|
We want to initialize all log mutexes as soon as possible,
|
|
|
|
but we cannot do it in constructor, as safe_mutex relies on
|
|
|
|
initialization, performed by MY_INIT(). This why this is done in
|
|
|
|
this function.
|
|
|
|
*/
|
|
|
|
void init_base();
|
|
|
|
void init_log_tables();
|
|
|
|
bool flush_logs(THD *thd);
|
2009-12-03 09:59:58 +01:00
|
|
|
bool flush_slow_log();
|
|
|
|
bool flush_general_log();
|
2006-01-27 14:10:40 +01:00
|
|
|
/* Perform basic logger cleanup. this will leave e.g. error log open. */
|
|
|
|
void cleanup_base();
|
|
|
|
/* Free memory. Nothing could be logged after this function is called */
|
|
|
|
void cleanup_end();
|
2006-01-19 03:56:06 +01:00
|
|
|
bool error_log_print(enum loglevel level, const char *format,
|
|
|
|
va_list args);
|
|
|
|
bool slow_log_print(THD *thd, const char *query, uint query_length,
|
2007-07-30 10:33:50 +02:00
|
|
|
ulonglong current_utime);
|
2006-01-19 03:56:06 +01:00
|
|
|
bool general_log_print(THD *thd,enum enum_server_command command,
|
|
|
|
const char *format, va_list args);
|
2007-10-18 20:45:07 +02:00
|
|
|
bool general_log_write(THD *thd, enum enum_server_command command,
|
|
|
|
const char *query, uint query_length);
|
2006-01-19 03:56:06 +01:00
|
|
|
|
|
|
|
/* we use this function to setup all enabled log event handlers */
|
2006-01-27 11:41:15 +01:00
|
|
|
int set_handlers(uint error_log_printer,
|
|
|
|
uint slow_log_printer,
|
|
|
|
uint general_log_printer);
|
|
|
|
void init_error_log(uint error_log_printer);
|
|
|
|
void init_slow_log(uint slow_log_printer);
|
|
|
|
void init_general_log(uint general_log_printer);
|
2006-06-19 15:30:55 +02:00
|
|
|
void deactivate_log_handler(THD* thd, uint log_type);
|
|
|
|
bool activate_log_handler(THD* thd, uint log_type);
|
2009-12-22 10:35:56 +01:00
|
|
|
MYSQL_QUERY_LOG *get_slow_log_file_handler() const
|
2006-06-19 15:30:55 +02:00
|
|
|
{
|
|
|
|
if (file_log_handler)
|
|
|
|
return file_log_handler->get_mysql_slow_log();
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
MYSQL_QUERY_LOG *get_log_file_handler() const
|
2006-06-19 15:30:55 +02:00
|
|
|
{
|
|
|
|
if (file_log_handler)
|
|
|
|
return file_log_handler->get_mysql_log();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
};
|
WL#2977 and WL#2712 global and session-level variable to set the binlog format (row/statement),
and new binlog format called "mixed" (which is statement-based except if only row-based is correct,
in this cset it means if UDF or UUID is used; more cases could be added in later 5.1 release):
SET GLOBAL|SESSION BINLOG_FORMAT=row|statement|mixed|default;
the global default is statement unless cluster is enabled (then it's row) as in 5.1-alpha.
It's not possible to use SET on this variable if a session is currently in row-based mode and has open temporary tables (because CREATE
TEMPORARY TABLE was not binlogged so temp table is not known on slave), or if NDB is enabled (because
NDB does not support such change on-the-fly, though it will later), of if in a stored function (see below).
The added tests test the possibility or impossibility to SET, their effects, and the mixed mode,
including in prepared statements and in stored procedures and functions.
Caveats:
a) The mixed mode will not work for stored functions: in mixed mode, a stored function will
always be binlogged as one call and in a statement-based way (e.g. INSERT VALUES(myfunc()) or SELECT myfunc()).
b) for the same reason, changing the thread's binlog format inside a stored function is
refused with an error message.
c) the same problems apply to triggers; implementing b) for triggers will be done later (will ask
Dmitri).
Additionally, as the binlog format is now changeable by each user for his session, I remove the implication
which was done at startup, where row-based automatically set log-bin-trust-routine-creators to 1
(not possible anymore as a user can now switch to stmt-based and do nasty things again), and automatically
set --innodb-locks-unsafe-for-binlog to 1 (was anyway theoretically incorrect as it disabled
phantom protection).
Plus fixes for compiler warnings.
mysql-test/r/rpl_row_4_bytes.result:
update
mysql-test/t/rpl_row_4_bytes.test:
don't influence next tests
sql/ha_archive.cc:
please pay attention to this structure when you change it...
sql/ha_berkeley.cc:
please pay attention to this structure when you change it...
sql/ha_blackhole.cc:
please pay attention to this structure when you change it...
sql/ha_federated.cc:
please pay attention to this structure when you change it...
sql/ha_heap.cc:
please pay attention to this structure when you change it...
sql/ha_innodb.cc:
please pay attention to this structure when you change it...
sql/ha_myisam.cc:
please pay attention to this structure when you change it...
sql/ha_myisammrg.cc:
please pay attention to this structure when you change it...
sql/ha_ndbcluster_binlog.cc:
no more global 'binlog_row_based'
sql/ha_partition.cc:
please pay attention to this structure when you change it...
sql/handler.cc:
please pay attention to this structure when you change it...
sql/handler.h:
it's good to initialize statically (to get no compiler warning) even if to a null value.
sql/item_func.cc:
UDFs require row-based if this is the "mixed" binlog format.
sql/item_strfunc.cc:
UUID() requires row-based binlogging if this is the "mixed" binlog format
sql/log.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/log.h:
the enum enum_binlog_format moves to log.h from mysqld.cc as we need it in several places.
sql/log_event.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/log_event.h:
this global variable not used anymore
sql/mysql_priv.h:
these global variables not used anymore
sql/mysqld.cc:
simplification in the handling of --binlog-format (but with no user-visible change), thanks to
the new global system variable.
RBR does not anymore turn on --log-bin-trust-function-creators and --innodb-locks-unsafe-for-binlog
as these are global options and RBR is now settable per session.
sql/partition_info.cc:
compiler warnings
sql/set_var.cc:
new class of thread's variable, to handle the binlog_format (like sys_var_thd_enum except
that is_readonly() is overriden for more checks before update).
compiler warnings (ok'd by Serg)
sql/set_var.h:
new class for the thread's binlog_format (see set_var.cc)
sql/share/errmsg.txt:
some messages for when one can't toggle from one binlog format to another
sql/sp_head.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_base.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_class.cc:
When a THD is initialized, we set its current_stmt_binlog_row_based
sql/sql_class.h:
new THD::variables.binlog_format (the value of the session variable set by SET
or inherited from the global value), and THD::current_stmt_binlog_row_based which tells if the
current statement does row-based or statement-based binlogging. Both members are needed
as the 2nd one cannot be derived only from the first one (the statement's type plays a role too),
and the 1st one is needed to reset the 2nd one.
sql/sql_delete.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_insert.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_load.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based.
sql/sql_parse.cc:
when we are done with a statement, we reset the current_stmt_binlog_row_based to the value
derived from THD::variables.binlog_format.
sql/sql_partition.cc:
compiler warning
sql/sql_show.cc:
compiler warning
sql/sql_table.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
tests/mysql_client_test.c:
compiler warning
mysql-test/r/ndb_binlog_basic2.result:
new result
mysql-test/r/rpl_switch_stm_row_mixed.result:
new result
mysql-test/t/ndb_binlog_basic2.test:
new test to verify that if cluster is enabled, can't change binlog format on the fly.
mysql-test/t/rpl_switch_stm_row_mixed.test:
test to see if one can switch between SBR, RBR, and "mixed" mode, and when one cannot,
and test to see if the switching, and the mixed mode, work properly (using UUID() to test,
as using UDFs is not possible in the testsuite for portability reasons).
2006-02-25 22:21:03 +01:00
|
|
|
|
|
|
|
enum enum_binlog_format {
|
2009-12-22 10:35:56 +01:00
|
|
|
BINLOG_FORMAT_MIXED= 0, ///< statement if safe, otherwise row - autodetected
|
|
|
|
BINLOG_FORMAT_STMT= 1, ///< statement-based
|
|
|
|
BINLOG_FORMAT_ROW= 2, ///< row-based
|
|
|
|
BINLOG_FORMAT_UNSPEC=3 ///< thd_binlog_format() returns it when binlog is closed
|
WL#2977 and WL#2712 global and session-level variable to set the binlog format (row/statement),
and new binlog format called "mixed" (which is statement-based except if only row-based is correct,
in this cset it means if UDF or UUID is used; more cases could be added in later 5.1 release):
SET GLOBAL|SESSION BINLOG_FORMAT=row|statement|mixed|default;
the global default is statement unless cluster is enabled (then it's row) as in 5.1-alpha.
It's not possible to use SET on this variable if a session is currently in row-based mode and has open temporary tables (because CREATE
TEMPORARY TABLE was not binlogged so temp table is not known on slave), or if NDB is enabled (because
NDB does not support such change on-the-fly, though it will later), of if in a stored function (see below).
The added tests test the possibility or impossibility to SET, their effects, and the mixed mode,
including in prepared statements and in stored procedures and functions.
Caveats:
a) The mixed mode will not work for stored functions: in mixed mode, a stored function will
always be binlogged as one call and in a statement-based way (e.g. INSERT VALUES(myfunc()) or SELECT myfunc()).
b) for the same reason, changing the thread's binlog format inside a stored function is
refused with an error message.
c) the same problems apply to triggers; implementing b) for triggers will be done later (will ask
Dmitri).
Additionally, as the binlog format is now changeable by each user for his session, I remove the implication
which was done at startup, where row-based automatically set log-bin-trust-routine-creators to 1
(not possible anymore as a user can now switch to stmt-based and do nasty things again), and automatically
set --innodb-locks-unsafe-for-binlog to 1 (was anyway theoretically incorrect as it disabled
phantom protection).
Plus fixes for compiler warnings.
mysql-test/r/rpl_row_4_bytes.result:
update
mysql-test/t/rpl_row_4_bytes.test:
don't influence next tests
sql/ha_archive.cc:
please pay attention to this structure when you change it...
sql/ha_berkeley.cc:
please pay attention to this structure when you change it...
sql/ha_blackhole.cc:
please pay attention to this structure when you change it...
sql/ha_federated.cc:
please pay attention to this structure when you change it...
sql/ha_heap.cc:
please pay attention to this structure when you change it...
sql/ha_innodb.cc:
please pay attention to this structure when you change it...
sql/ha_myisam.cc:
please pay attention to this structure when you change it...
sql/ha_myisammrg.cc:
please pay attention to this structure when you change it...
sql/ha_ndbcluster_binlog.cc:
no more global 'binlog_row_based'
sql/ha_partition.cc:
please pay attention to this structure when you change it...
sql/handler.cc:
please pay attention to this structure when you change it...
sql/handler.h:
it's good to initialize statically (to get no compiler warning) even if to a null value.
sql/item_func.cc:
UDFs require row-based if this is the "mixed" binlog format.
sql/item_strfunc.cc:
UUID() requires row-based binlogging if this is the "mixed" binlog format
sql/log.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/log.h:
the enum enum_binlog_format moves to log.h from mysqld.cc as we need it in several places.
sql/log_event.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/log_event.h:
this global variable not used anymore
sql/mysql_priv.h:
these global variables not used anymore
sql/mysqld.cc:
simplification in the handling of --binlog-format (but with no user-visible change), thanks to
the new global system variable.
RBR does not anymore turn on --log-bin-trust-function-creators and --innodb-locks-unsafe-for-binlog
as these are global options and RBR is now settable per session.
sql/partition_info.cc:
compiler warnings
sql/set_var.cc:
new class of thread's variable, to handle the binlog_format (like sys_var_thd_enum except
that is_readonly() is overriden for more checks before update).
compiler warnings (ok'd by Serg)
sql/set_var.h:
new class for the thread's binlog_format (see set_var.cc)
sql/share/errmsg.txt:
some messages for when one can't toggle from one binlog format to another
sql/sp_head.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_base.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_class.cc:
When a THD is initialized, we set its current_stmt_binlog_row_based
sql/sql_class.h:
new THD::variables.binlog_format (the value of the session variable set by SET
or inherited from the global value), and THD::current_stmt_binlog_row_based which tells if the
current statement does row-based or statement-based binlogging. Both members are needed
as the 2nd one cannot be derived only from the first one (the statement's type plays a role too),
and the 1st one is needed to reset the 2nd one.
sql/sql_delete.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_insert.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_load.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based.
sql/sql_parse.cc:
when we are done with a statement, we reset the current_stmt_binlog_row_based to the value
derived from THD::variables.binlog_format.
sql/sql_partition.cc:
compiler warning
sql/sql_show.cc:
compiler warning
sql/sql_table.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
tests/mysql_client_test.c:
compiler warning
mysql-test/r/ndb_binlog_basic2.result:
new result
mysql-test/r/rpl_switch_stm_row_mixed.result:
new result
mysql-test/t/ndb_binlog_basic2.test:
new test to verify that if cluster is enabled, can't change binlog format on the fly.
mysql-test/t/rpl_switch_stm_row_mixed.test:
test to see if one can switch between SBR, RBR, and "mixed" mode, and when one cannot,
and test to see if the switching, and the mixed mode, work properly (using UUID() to test,
as using UDFs is not possible in the testsuite for portability reasons).
2006-02-25 22:21:03 +01:00
|
|
|
};
|
|
|
|
|
2009-05-30 15:32:28 +02:00
|
|
|
int query_error_code(THD *thd, bool not_killed);
|
2009-11-20 14:30:35 +01:00
|
|
|
uint purge_log_get_error_code(int res);
|
2009-05-30 15:32:28 +02:00
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
int vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
|
|
|
|
void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
|
|
|
|
void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
|
|
|
|
void sql_print_information(const char *format, ...)
|
|
|
|
ATTRIBUTE_FORMAT(printf, 1, 2);
|
|
|
|
typedef void (*sql_print_message_func)(const char *format, ...)
|
2011-05-21 10:21:08 +02:00
|
|
|
ATTRIBUTE_FORMAT_FPTR(printf, 1, 2);
|
2010-03-31 16:05:33 +02:00
|
|
|
extern sql_print_message_func sql_print_message_handlers[];
|
|
|
|
|
|
|
|
int error_log_print(enum loglevel level, const char *format,
|
|
|
|
va_list args);
|
|
|
|
|
|
|
|
bool slow_log_print(THD *thd, const char *query, uint query_length,
|
|
|
|
ulonglong current_utime);
|
|
|
|
|
|
|
|
bool general_log_print(THD *thd, enum enum_server_command command,
|
|
|
|
const char *format,...);
|
|
|
|
|
|
|
|
bool general_log_write(THD *thd, enum enum_server_command command,
|
|
|
|
const char *query, uint query_length);
|
|
|
|
|
|
|
|
void sql_perror(const char *message);
|
|
|
|
bool flush_error_log();
|
|
|
|
|
|
|
|
File open_binlog(IO_CACHE *log, const char *log_file_name,
|
|
|
|
const char **errmsg);
|
|
|
|
|
|
|
|
char *make_log_name(char *buff, const char *name, const char* log_ext);
|
|
|
|
|
|
|
|
extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log;
|
|
|
|
extern LOGGER logger;
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
#endif /* LOG_H */
|