2012-08-09 17:22:00 +02:00
|
|
|
/* Copyright (c) 2005, 2012, Oracle and/or its affiliates.
|
|
|
|
Copyright (c) 2009, 2012, Monty Program Ab
|
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;
|
2010-09-30 15:20:15 +02:00
|
|
|
virtual int log_and_order(THD *thd, my_xid xid, bool all,
|
|
|
|
bool need_prepare_ordered,
|
|
|
|
bool need_commit_ordered) = 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;
|
2012-09-13 14:31:29 +02:00
|
|
|
virtual void commit_checkpoint_notify(void *cookie)= 0;
|
2010-09-30 15:20:15 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/*
|
|
|
|
These methods are meant to be invoked from log_and_order() implementations
|
|
|
|
to run any prepare_ordered() respectively commit_ordered() methods in
|
|
|
|
participating handlers.
|
|
|
|
|
|
|
|
They must be called using suitable thread syncronisation to ensure that
|
|
|
|
they are each called in the correct commit order among all
|
|
|
|
transactions. However, it is only necessary to call them if the
|
|
|
|
corresponding flag passed to log_and_order is set (it is safe, but not
|
|
|
|
required, to call them when the flag is false).
|
|
|
|
|
|
|
|
The caller must be holding LOCK_prepare_ordered respectively
|
|
|
|
LOCK_commit_ordered when calling these methods.
|
|
|
|
*/
|
|
|
|
void run_prepare_ordered(THD *thd, bool all);
|
|
|
|
void run_commit_ordered(THD *thd, bool all);
|
2005-12-22 06:39:02 +01:00
|
|
|
};
|
|
|
|
|
2010-09-30 15:20:15 +02:00
|
|
|
/*
|
|
|
|
Locks used to ensure serialised execution of TC_LOG::run_prepare_ordered()
|
|
|
|
and TC_LOG::run_commit_ordered(), or any other code that calls handler
|
|
|
|
prepare_ordered() or commit_ordered() methods.
|
|
|
|
*/
|
2011-10-19 21:45:18 +02:00
|
|
|
extern mysql_mutex_t LOCK_prepare_ordered;
|
|
|
|
extern mysql_mutex_t LOCK_commit_ordered;
|
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
extern PSI_mutex_key key_LOCK_prepare_ordered, key_LOCK_commit_ordered;
|
|
|
|
#endif
|
2010-09-30 15:20:15 +02:00
|
|
|
|
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() { }
|
2010-10-28 12:40:42 +02:00
|
|
|
/*
|
|
|
|
TC_LOG_DUMMY is only used when there are <= 1 XA-capable engines, and we
|
|
|
|
only use internal XA during commit when >= 2 XA-capable engines
|
|
|
|
participate.
|
|
|
|
*/
|
|
|
|
int log_and_order(THD *thd, my_xid xid, bool all,
|
|
|
|
bool need_prepare_ordered, bool need_commit_ordered)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(0 /* Internal error - TC_LOG_DUMMY::log_and_order() called */);
|
|
|
|
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; }
|
2012-09-13 14:31:29 +02:00
|
|
|
void commit_checkpoint_notify(void *cookie) { DBUG_ASSERT(0); };
|
2005-12-22 06:39:02 +01:00
|
|
|
};
|
|
|
|
|
2012-09-13 14:31:29 +02:00
|
|
|
#define TC_LOG_PAGE_SIZE 8192
|
|
|
|
#define TC_LOG_MIN_SIZE (3*TC_LOG_PAGE_SIZE)
|
|
|
|
|
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;
|
|
|
|
|
2012-09-13 14:31:29 +02:00
|
|
|
struct pending_cookies {
|
|
|
|
uint count;
|
|
|
|
uint pending_count;
|
2012-11-20 14:20:26 +01:00
|
|
|
ulong cookies[TC_LOG_PAGE_SIZE/sizeof(my_xid)];
|
2012-09-13 14:31:29 +02:00
|
|
|
};
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
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;
|
|
|
|
|
2010-10-28 12:40:42 +02:00
|
|
|
/* List of THDs for which to invoke commit_ordered(), in order. */
|
|
|
|
struct commit_entry
|
|
|
|
{
|
|
|
|
struct commit_entry *next;
|
|
|
|
THD *thd;
|
|
|
|
};
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
char logname[FN_REFLEN];
|
|
|
|
File fd;
|
|
|
|
my_off_t file_length;
|
|
|
|
uint npages, inited;
|
|
|
|
uchar *data;
|
2012-11-20 13:28:53 +01:00
|
|
|
struct st_page *pages, *syncing, *active, *pool, **pool_last_ptr;
|
2005-12-22 06:39:02 +01:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
2012-09-13 14:31:29 +02:00
|
|
|
mysql_mutex_t LOCK_active, LOCK_pool, LOCK_sync, LOCK_pending_checkpoint;
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_cond_t COND_pool, COND_active;
|
2010-10-28 12:40:42 +02:00
|
|
|
/*
|
|
|
|
Queue of threads that need to call commit_ordered().
|
|
|
|
Access to this queue must be protected by LOCK_prepare_ordered.
|
|
|
|
*/
|
|
|
|
commit_entry *commit_ordered_queue;
|
|
|
|
/*
|
|
|
|
This flag and condition is used to reserve the queue while threads in it
|
|
|
|
each run the commit_ordered() methods one after the other. Only once the
|
|
|
|
last commit_ordered() in the queue is done can we start on a new queue
|
|
|
|
run.
|
|
|
|
|
|
|
|
Since we start this process in the first thread in the queue and finish in
|
|
|
|
the last (and possibly different) thread, we need a condition variable for
|
|
|
|
this (we cannot unlock a mutex in a different thread than the one who
|
|
|
|
locked it).
|
|
|
|
|
|
|
|
The condition is used together with the LOCK_prepare_ordered mutex.
|
|
|
|
*/
|
2011-10-19 21:45:18 +02:00
|
|
|
mysql_cond_t COND_queue_busy;
|
2010-10-28 12:40:42 +02:00
|
|
|
my_bool commit_ordered_queue_busy;
|
2012-09-13 14:31:29 +02:00
|
|
|
pending_cookies* pending_checkpoint;
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
public:
|
2012-09-13 14:31:29 +02:00
|
|
|
TC_LOG_MMAP(): inited(0), pending_checkpoint(0) {}
|
2005-12-22 06:39:02 +01:00
|
|
|
int open(const char *opt_name);
|
|
|
|
void close();
|
2010-10-28 12:40:42 +02:00
|
|
|
int log_and_order(THD *thd, my_xid xid, bool all,
|
|
|
|
bool need_prepare_ordered, bool need_commit_ordered);
|
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);
|
2012-09-13 14:31:29 +02:00
|
|
|
void commit_checkpoint_notify(void *cookie);
|
2005-12-22 06:39:02 +01:00
|
|
|
int recover();
|
|
|
|
|
|
|
|
private:
|
2010-10-28 12:40:42 +02:00
|
|
|
int log_one_transaction(my_xid xid);
|
2005-12-22 06:39:02 +01:00
|
|
|
void get_active_from_pool();
|
|
|
|
int sync();
|
|
|
|
int overflow();
|
2012-09-13 14:31:29 +02:00
|
|
|
int delete_entry(ulong cookie);
|
2005-12-22 06:39:02 +01:00
|
|
|
};
|
|
|
|
#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
|
2012-06-21 21:17:34 +02:00
|
|
|
#define LOG_CLOSE_DELAYED_CLOSE 8
|
2005-12-22 06:39:02 +01:00
|
|
|
|
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
|
|
|
|
|
2012-04-20 23:25:59 +02:00
|
|
|
/*
|
|
|
|
Note that we destroy the lock mutex in the desctructor here.
|
|
|
|
This means that object instances cannot be destroyed/go out of scope,
|
|
|
|
until we have reset thd->current_linfo to NULL;
|
|
|
|
*/
|
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);
|
2011-05-19 19:19:44 +02:00
|
|
|
bool write(THD *thd, time_t current_time,
|
2006-05-05 08:45:58 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2012-06-22 11:46:28 +02:00
|
|
|
/*
|
|
|
|
We assign each binlog file an internal ID, used to identify them for unlog().
|
2012-09-13 14:31:29 +02:00
|
|
|
The IDs start from 0 and increment for each new binlog created.
|
|
|
|
|
|
|
|
In unlog() we need to know the ID of the binlog file that the corresponding
|
|
|
|
transaction was written into. We also need a special value for a corner
|
|
|
|
case where there is no corresponding binlog id (since nothing was logged).
|
|
|
|
And we need an error flag to mark that unlog() must return failure.
|
|
|
|
|
|
|
|
We use the following macros to pack all of this information into the single
|
|
|
|
ulong available with log_and_order() / unlog().
|
|
|
|
|
|
|
|
Note that we cannot use the value 0 for cookie, as that is reserved as error
|
|
|
|
return value from log_and_order().
|
|
|
|
*/
|
|
|
|
#define BINLOG_COOKIE_ERROR_RETURN 0
|
|
|
|
#define BINLOG_COOKIE_DUMMY_ID 1
|
|
|
|
#define BINLOG_COOKIE_BASE 2
|
|
|
|
#define BINLOG_COOKIE_DUMMY(error_flag) \
|
|
|
|
( (BINLOG_COOKIE_DUMMY_ID<<1) | ((error_flag)&1) )
|
|
|
|
#define BINLOG_COOKIE_MAKE(id, error_flag) \
|
|
|
|
( (((id)+BINLOG_COOKIE_BASE)<<1) | ((error_flag)&1) )
|
|
|
|
#define BINLOG_COOKIE_GET_ERROR_FLAG(c) ((c) & 1)
|
|
|
|
#define BINLOG_COOKIE_GET_ID(c) ( ((ulong)(c)>>1) - BINLOG_COOKIE_BASE )
|
|
|
|
#define BINLOG_COOKIE_IS_DUMMY(c) \
|
|
|
|
( ((ulong)(c)>>1) == BINLOG_COOKIE_DUMMY_ID )
|
|
|
|
|
2011-10-19 21:45:18 +02:00
|
|
|
class binlog_cache_mngr;
|
2013-01-25 15:21:49 +01:00
|
|
|
class rpl_gtid;
|
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;
|
2011-10-19 21:45:18 +02:00
|
|
|
|
|
|
|
PSI_file_key m_key_COND_queue_busy;
|
2011-03-01 17:39:28 +01:00
|
|
|
#endif
|
2011-10-19 21:45:18 +02:00
|
|
|
|
2010-10-29 13:58:47 +02:00
|
|
|
struct group_commit_entry
|
|
|
|
{
|
|
|
|
struct group_commit_entry *next;
|
|
|
|
THD *thd;
|
2011-10-19 21:45:18 +02:00
|
|
|
binlog_cache_mngr *cache_mngr;
|
|
|
|
bool using_stmt_cache;
|
|
|
|
bool using_trx_cache;
|
2010-10-29 13:58:47 +02:00
|
|
|
/*
|
2012-10-23 11:19:42 +02:00
|
|
|
Extra events (COMMIT/ROLLBACK/XID, and possibly INCIDENT) to be
|
2010-10-29 13:58:47 +02:00
|
|
|
written during group commit. The incident_event is only valid if
|
|
|
|
trx_data->has_incident() is true.
|
|
|
|
*/
|
|
|
|
Log_event *end_event;
|
|
|
|
Log_event *incident_event;
|
|
|
|
/* Set during group commit to record any per-thread error. */
|
|
|
|
int error;
|
|
|
|
int commit_errno;
|
2011-10-19 21:45:18 +02:00
|
|
|
IO_CACHE *error_cache;
|
2010-10-29 13:58:47 +02:00
|
|
|
/* This is the `all' parameter for ha_commit_ordered(). */
|
|
|
|
bool all;
|
2012-09-13 14:31:29 +02:00
|
|
|
/*
|
|
|
|
True if we need to increment xid_count in trx_group_commit_leader() and
|
|
|
|
decrement in unlog() (this is needed if there is a participating engine
|
|
|
|
that does not implement the commit_checkpoint_request() handlerton
|
|
|
|
method).
|
|
|
|
*/
|
|
|
|
bool need_unlog;
|
|
|
|
/*
|
|
|
|
Fields used to pass the necessary information to the last thread in a
|
|
|
|
group commit, only used when opt_optimize_thread_scheduling is not set.
|
|
|
|
*/
|
|
|
|
bool check_purge;
|
|
|
|
ulong binlog_id;
|
2010-10-29 13:58:47 +02:00
|
|
|
};
|
|
|
|
|
2012-06-22 11:46:28 +02:00
|
|
|
/*
|
|
|
|
When this is set, a RESET MASTER is in progress.
|
|
|
|
|
|
|
|
Then we should not write any binlog checkpoints into the binlog (that
|
|
|
|
could result in deadlock on LOCK_log, and we will delete all binlog files
|
|
|
|
anyway). Instead we should signal COND_xid_list whenever a new binlog
|
|
|
|
checkpoint arrives - when all have arrived, RESET MASTER will complete.
|
|
|
|
*/
|
|
|
|
bool reset_master_pending;
|
|
|
|
|
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;
|
2012-06-22 11:46:28 +02:00
|
|
|
mysql_mutex_t LOCK_xid_list;
|
|
|
|
mysql_cond_t COND_xid_list;
|
2010-01-07 06:42:07 +01:00
|
|
|
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.
|
|
|
|
max_size is set in init(), and dynamically changed (when one does SET
|
2012-10-01 01:30:44 +02:00
|
|
|
GLOBAL MAX_BINLOG_SIZE|MAX_RELAY_LOG_SIZE) from sys_vars.cc
|
2005-12-22 06:39:02 +01:00
|
|
|
*/
|
|
|
|
ulong max_size;
|
|
|
|
// current file sequence number for load data infile binary logging
|
|
|
|
uint file_id;
|
|
|
|
uint open_count; // For replication
|
|
|
|
int readers_count;
|
2010-09-30 15:20:15 +02:00
|
|
|
/* Queue of transactions queued up to participate in group commit. */
|
2010-10-29 13:58:47 +02:00
|
|
|
group_commit_entry *group_commit_queue;
|
2011-03-23 15:29:20 +01:00
|
|
|
/*
|
|
|
|
Condition variable to mark that the group commit queue is busy.
|
|
|
|
Used when each thread does it's own commit_ordered() (when
|
|
|
|
binlog_optimize_thread_scheduling=1).
|
|
|
|
Used with the LOCK_commit_ordered mutex.
|
|
|
|
*/
|
|
|
|
my_bool group_commit_queue_busy;
|
2011-10-19 21:45:18 +02:00
|
|
|
mysql_cond_t COND_queue_busy;
|
2010-10-29 13:58:47 +02:00
|
|
|
/* Total number of committed transactions. */
|
|
|
|
ulonglong num_commits;
|
|
|
|
/* Number of group commits done. */
|
|
|
|
ulonglong num_group_commits;
|
2005-12-22 06:39:02 +01:00
|
|
|
|
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;
|
2013-03-27 16:06:45 +01:00
|
|
|
/* Protect against reading the binlog state file twice. */
|
|
|
|
bool state_read;
|
2009-09-29 16:27:12 +02:00
|
|
|
|
|
|
|
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);
|
2012-09-13 14:31:29 +02:00
|
|
|
void do_checkpoint_request(ulong binlog_id);
|
|
|
|
void purge();
|
2011-10-19 21:45:18 +02:00
|
|
|
int write_transaction_or_stmt(group_commit_entry *entry);
|
2010-10-29 13:58:47 +02:00
|
|
|
bool write_transaction_to_binlog_events(group_commit_entry *entry);
|
|
|
|
void trx_group_commit_leader(group_commit_entry *leader);
|
2006-02-16 08:30:53 +01:00
|
|
|
|
|
|
|
public:
|
2012-12-14 15:38:07 +01:00
|
|
|
/*
|
|
|
|
A list of struct xid_count_per_binlog is used to keep track of how many
|
|
|
|
XIDs are in prepared, but not committed, state in each binlog. And how
|
|
|
|
many commit_checkpoint_request()'s are pending.
|
|
|
|
|
|
|
|
When count drops to zero in a binlog after rotation, it means that there
|
|
|
|
are no more XIDs in prepared state, so that binlog is no longer needed
|
|
|
|
for XA crash recovery, and we can log a new binlog checkpoint event.
|
|
|
|
|
|
|
|
The list is protected against simultaneous access from multiple
|
|
|
|
threads by LOCK_xid_list.
|
|
|
|
*/
|
|
|
|
struct xid_count_per_binlog : public ilink {
|
|
|
|
char *binlog_name;
|
|
|
|
uint binlog_name_len;
|
|
|
|
ulong binlog_id;
|
|
|
|
/* Total prepared XIDs and pending checkpoint requests in this binlog. */
|
|
|
|
long xid_count;
|
|
|
|
/* For linking in requests to the binlog background thread. */
|
|
|
|
xid_count_per_binlog *next_in_queue;
|
|
|
|
xid_count_per_binlog(); /* Give link error if constructor used. */
|
|
|
|
};
|
|
|
|
I_List<xid_count_per_binlog> binlog_xid_count_list;
|
|
|
|
mysql_mutex_t LOCK_binlog_background_thread;
|
|
|
|
mysql_cond_t COND_binlog_background_thread;
|
|
|
|
mysql_cond_t COND_binlog_background_thread_end;
|
|
|
|
|
2012-08-06 15:33:11 +02:00
|
|
|
using MYSQL_LOG::generate_name;
|
|
|
|
using 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
|
2011-05-03 14:01:11 +02:00
|
|
|
uint8 checksum_alg_reset; // to contain a new value when binlog is rotated
|
|
|
|
/*
|
|
|
|
Holds the last seen in Relay-Log FD's checksum alg value.
|
|
|
|
The initial value comes from the slave's local FD that heads
|
|
|
|
the very first Relay-Log file. In the following the value may change
|
|
|
|
with each received master's FD_m.
|
|
|
|
Besides to be used in verification events that IO thread receives
|
|
|
|
(except the 1st fake Rotate, see @c Master_info:: checksum_alg_before_fd),
|
|
|
|
the value specifies if/how to compute checksum for slave's local events
|
|
|
|
and the first fake Rotate (R_f^1) coming from the master.
|
|
|
|
R_f^1 needs logging checksum-compatibly with the RL's heading FD_s.
|
|
|
|
|
|
|
|
Legends for the checksum related comments:
|
|
|
|
|
|
|
|
FD - Format-Description event,
|
|
|
|
R - Rotate event
|
|
|
|
R_f - the fake Rotate event
|
|
|
|
E - an arbirary event
|
|
|
|
|
|
|
|
The underscore indexes for any event
|
|
|
|
`_s' indicates the event is generated by Slave
|
|
|
|
`_m' - by Master
|
|
|
|
|
|
|
|
Two special underscore indexes of FD:
|
|
|
|
FD_q - Format Description event for queuing (relay-logging)
|
|
|
|
FD_e - Format Description event for executing (relay-logging)
|
|
|
|
|
|
|
|
Upper indexes:
|
|
|
|
E^n - n:th event is a sequence
|
|
|
|
|
|
|
|
RL - Relay Log
|
|
|
|
(A) - checksum algorithm descriptor value
|
|
|
|
FD.(A) - the value of (A) in FD
|
|
|
|
*/
|
|
|
|
uint8 relay_log_checksum_alg;
|
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;
|
2010-11-07 22:37:43 +01:00
|
|
|
/*
|
|
|
|
Binlog position of last commit (or non-transactional write) to the binlog.
|
|
|
|
Access to this is protected by LOCK_commit_ordered.
|
|
|
|
*/
|
|
|
|
char last_commit_pos_file[FN_REFLEN];
|
|
|
|
my_off_t last_commit_pos_offset;
|
2012-09-13 14:31:29 +02:00
|
|
|
ulong current_binlog_id;
|
2005-12-22 06:39:02 +01:00
|
|
|
|
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,
|
2011-10-25 12:53:40 +02:00
|
|
|
PSI_file_key key_file_log_index,
|
|
|
|
PSI_file_key key_COND_queue_busy)
|
2011-03-01 17:39:28 +01:00
|
|
|
{
|
|
|
|
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;
|
2011-10-25 12:53:40 +02:00
|
|
|
m_key_COND_queue_busy= key_COND_queue_busy;
|
2011-03-01 17:39:28 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
int open(const char *opt_name);
|
|
|
|
void close();
|
2010-10-29 13:58:47 +02:00
|
|
|
int log_and_order(THD *thd, my_xid xid, bool all,
|
|
|
|
bool need_prepare_ordered, bool need_commit_ordered);
|
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);
|
2012-09-13 14:31:29 +02:00
|
|
|
void commit_checkpoint_notify(void *cookie);
|
2012-06-22 11:46:28 +02:00
|
|
|
int recover(LOG_INFO *linfo, const char *last_log_name, IO_CACHE *first_log,
|
|
|
|
Format_description_log_event *fdle);
|
2005-12-22 06:39:02 +01:00
|
|
|
#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);
|
2012-09-13 14:31:29 +02:00
|
|
|
void init(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,
|
2012-09-13 14:31:29 +02:00
|
|
|
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
|
|
|
|
2011-01-10 14:53:09 +01:00
|
|
|
bool write(Log_event* event_info,
|
|
|
|
my_bool *with_annotate= 0); // binary log write
|
2011-10-19 21:45:18 +02:00
|
|
|
bool write_transaction_to_binlog(THD *thd, binlog_cache_mngr *cache_mngr,
|
|
|
|
Log_event *end_ev, bool all,
|
|
|
|
bool using_stmt_cache, bool using_trx_cache);
|
2005-12-22 06:39:02 +01:00
|
|
|
|
2011-04-01 15:07:10 +02:00
|
|
|
bool write_incident_already_locked(THD *thd);
|
2010-10-01 10:49:57 +02:00
|
|
|
bool write_incident(THD *thd);
|
2012-06-22 11:46:28 +02:00
|
|
|
void write_binlog_checkpoint_event_already_locked(const char *name, uint len);
|
2010-12-25 15:42:33 +01:00
|
|
|
int write_cache(THD *thd, IO_CACHE *cache);
|
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);
|
|
|
|
|
2012-12-14 15:38:07 +01:00
|
|
|
void mark_xids_active(ulong cookie, uint xid_count);
|
|
|
|
void mark_xid_done(ulong cookie, bool write_checkpoint);
|
2005-12-22 06:39:02 +01:00
|
|
|
void make_log_name(char* buf, const char* log_ident);
|
|
|
|
bool is_active(const char* log_file_name);
|
2012-06-22 11:46:28 +02:00
|
|
|
bool can_purge_log(const char *log_file_name);
|
2005-12-22 06:39:02 +01:00
|
|
|
int update_log_index(LOG_INFO* linfo, bool need_update_threads);
|
2011-10-27 16:14:41 +02:00
|
|
|
int rotate(bool force_rotate, bool* check_purge);
|
2012-09-13 14:31:29 +02:00
|
|
|
void checkpoint_and_purge(ulong binlog_id);
|
2011-10-27 16:14:41 +02:00
|
|
|
int rotate_and_purge(bool force_rotate);
|
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);
|
2012-09-28 20:22:24 +02:00
|
|
|
bool reset_logs(THD* thd, bool create_new_log);
|
2005-12-22 06:39:02 +01:00
|
|
|
void close(uint exiting);
|
2012-06-21 21:17:34 +02:00
|
|
|
void clear_inuse_flag_when_closing(File file);
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
// 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; }
|
2010-11-07 22:37:43 +01:00
|
|
|
void set_status_variables(THD *thd);
|
2012-10-23 11:19:42 +02:00
|
|
|
bool write_gtid_event(THD *thd, bool standalone, bool is_transactional);
|
2012-11-07 14:18:10 +01:00
|
|
|
int read_state_from_file();
|
|
|
|
int write_state_to_file();
|
2013-01-25 15:21:49 +01:00
|
|
|
int get_most_recent_gtid_list(rpl_gtid **list, uint32 *size);
|
2013-03-18 15:09:36 +01:00
|
|
|
bool find_in_binlog_state(uint32 domain_id, uint32 server_id,
|
|
|
|
rpl_gtid *out_gtid);
|
|
|
|
bool lookup_domain_in_binlog_state(uint32 domain_id, rpl_gtid *out_gtid);
|
|
|
|
void bump_seq_no_counter_if_needed(uint64 seq_no);
|
2005-12-22 06:39:02 +01:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
|
2011-05-19 19:19:44 +02:00
|
|
|
virtual bool log_slow(THD *thd, my_hrtime_t current_time,
|
|
|
|
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;
|
2011-05-19 19:19:44 +02:00
|
|
|
virtual bool log_general(THD *thd, my_hrtime_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();
|
|
|
|
|
2011-05-19 19:19:44 +02:00
|
|
|
virtual bool log_slow(THD *thd, my_hrtime_t current_time,
|
|
|
|
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);
|
2011-05-19 19:19:44 +02:00
|
|
|
virtual bool log_general(THD *thd, my_hrtime_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();
|
|
|
|
|
2011-05-19 19:19:44 +02:00
|
|
|
virtual bool log_slow(THD *thd, my_hrtime_t current_time,
|
|
|
|
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);
|
2011-05-19 19:19:44 +02:00
|
|
|
virtual bool log_general(THD *thd, my_hrtime_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 */
|
2011-11-02 12:55:46 +01:00
|
|
|
int set_handlers(ulonglong error_log_printer,
|
|
|
|
ulonglong slow_log_printer,
|
|
|
|
ulonglong general_log_printer);
|
|
|
|
void init_error_log(ulonglong error_log_printer);
|
|
|
|
void init_slow_log(ulonglong slow_log_printer);
|
|
|
|
void init_general_log(ulonglong 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);
|
2012-08-27 18:13:17 +02:00
|
|
|
void sql_print_error(const char *format, ...);
|
2010-03-31 16:05:33 +02:00
|
|
|
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);
|
|
|
|
|
2011-10-19 21:45:18 +02:00
|
|
|
void make_default_log_name(char **out, const char* log_ext, bool once);
|
2010-03-31 16:05:33 +02:00
|
|
|
|
|
|
|
extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log;
|
|
|
|
extern LOGGER logger;
|
|
|
|
|
BUG#11745230: 12133: MASTER.INDEX FILE KEEPS MYSQLD FROM STARTING IF
BIN LOG HAS BEEN MOVED
When moving the binary/relay log files from one location to
another and restarting the server with a different log-bin or
relay-log paths, would cause the startup process to abort. The
root cause was that the server would not be able to find the log
files because it would consider old paths for entries in the
index file instead of the new location. What's even worse, the
relative paths would not be considered relative to the path
provided in log-bin and relay-log, but to mysql_data_dir.
We fix the cases where the server contains relative paths. When
the server is reading from the index file, it checks whether the
entry contains relative paths. If it does, we replace it with the
absolute path set in log-bin/relay-log option. Absolute paths
remain unchanged and the index must be manually edited to
consider the new log-bin and/or relay-log path (this should be
documented). This is a fix for a GA version, that does not break
behavior (that much).
For development versions, we should go with Zhenxing's approach
that removes paths altogether from index files.
mysql-test/include/begin_include_file.inc:
Added parameter to keep the begin_include_file.inc silent. Useful when
including scripts that contain platform dependent parameters, for example:
--let $rpl_server_parameters=--log-bin=$tmpdir/slave-bin --relay-log=$tmpdir/slave-relay-bin
--let $keep_include_silent=1
source include/rpl_start_server.inc;
--let $keep_include_silent=0
We want the paths ($tmpdir/slave-bin and $tmpdir/slave-relay-bin) not to be in the
result file.
mysql-test/suite/rpl/t/rpl_binlog_index.test:
Test case.
sql/log.cc:
When finding the corresponding log entry in the index file, we first
normalize the paths before doing the comparison. This will make relative
paths to be turned into absolute paths (based on the opt_bin_logname or
opt_relay_logname) and then compared against also, expanded paths entered,
through CHANGE MASTER for instance.
sql/log.h:
Added normalize_binlog_name, which turns relative paths, into absolute paths
given the parameter: is_relay_log ? opt_relay_logname : opt_bin_logname .
sql/mysqld.cc:
Exposing opt_bin_logname.
sql/mysqld.h:
Exposing opt_bin_logname.
2011-11-24 18:15:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Turns a relative log binary log path into a full path, based on the
|
|
|
|
opt_bin_logname or opt_relay_logname.
|
|
|
|
|
|
|
|
@param from The log name we want to make into an absolute path.
|
|
|
|
@param to The buffer where to put the results of the
|
|
|
|
normalization.
|
|
|
|
@param is_relay_log Switch that makes is used inside to choose which
|
|
|
|
option (opt_bin_logname or opt_relay_logname) to
|
|
|
|
use when calculating the base path.
|
|
|
|
|
|
|
|
@returns true if a problem occurs, false otherwise.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline bool normalize_binlog_name(char *to, const char *from, bool is_relay_log)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("normalize_binlog_name");
|
|
|
|
bool error= false;
|
|
|
|
char buff[FN_REFLEN];
|
|
|
|
char *ptr= (char*) from;
|
|
|
|
char *opt_name= is_relay_log ? opt_relay_logname : opt_bin_logname;
|
|
|
|
|
|
|
|
DBUG_ASSERT(from);
|
|
|
|
|
|
|
|
/* opt_name is not null and not empty and from is a relative path */
|
|
|
|
if (opt_name && opt_name[0] && from && !test_if_hard_path(from))
|
|
|
|
{
|
|
|
|
// take the path from opt_name
|
|
|
|
// take the filename from from
|
|
|
|
char log_dirpart[FN_REFLEN], log_dirname[FN_REFLEN];
|
|
|
|
size_t log_dirpart_len, log_dirname_len;
|
|
|
|
dirname_part(log_dirpart, opt_name, &log_dirpart_len);
|
|
|
|
dirname_part(log_dirname, from, &log_dirname_len);
|
|
|
|
|
|
|
|
/* log may be empty => relay-log or log-bin did not
|
|
|
|
hold paths, just filename pattern */
|
|
|
|
if (log_dirpart_len > 0)
|
|
|
|
{
|
|
|
|
/* create the new path name */
|
|
|
|
if(fn_format(buff, from+log_dirname_len, log_dirpart, "",
|
|
|
|
MYF(MY_UNPACK_FILENAME | MY_SAFE_PATH)) == NULL)
|
|
|
|
{
|
|
|
|
error= true;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr= buff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_ASSERT(ptr);
|
|
|
|
|
|
|
|
if (ptr)
|
|
|
|
strmake(to, ptr, strlen(ptr));
|
|
|
|
|
|
|
|
end:
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
#endif /* LOG_H */
|