From 150590a0bce917f7747765e1589fa37efa09fb53 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 20 Dec 2007 16:07:54 +0100 Subject: [PATCH 01/12] BUG#12691 (Exec_master_log_pos corrupted with SQL_SLAVE_SKIP_COUNTER): Complementary patch since LOAD DATA INFILE was not covered in the previous patch. This patch adds a check so that the slave skip counter is not decreased to zero if seeing a BEGIN_LOAD_QUERY_EVENT, APPEND_BLOCK_EVENT, or CREATE_FILE_EVENT since these cannot end a group. The group is terminated by an EXECUTE_LOAD_QUERY_ EVENT or DELETE_FILE_EVENT. mysql-test/r/rpl_slave_skip.result: Result change. mysql-test/t/rpl_slave_skip.test: Adding tests to test that the first event of a LOAD DATA INFILE can be skipped safely for both transactional and non-transactional tables. Also include a case that will generate a DELETE_FILE event last in the group, and this should be properly skipped as well. sql/slave.cc: Not decrementing slave skip counter to zero when seeing a BEGIN_LOAD_QUERY_EVENT, APPEND_BLOCK_EVENT, or CREATE_FILE_EVENT since these cannot end a group. --- mysql-test/r/rpl_slave_skip.result | 104 +++++++++++++++++- mysql-test/t/rpl_slave_skip.test | 169 ++++++++++++++++++++++++++++- sql/slave.cc | 5 +- 3 files changed, 271 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/rpl_slave_skip.result b/mysql-test/r/rpl_slave_skip.result index a59ac3eb884..0e06e0951b3 100644 --- a/mysql-test/r/rpl_slave_skip.result +++ b/mysql-test/r/rpl_slave_skip.result @@ -5,8 +5,10 @@ reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; **** On Master **** -CREATE TABLE t1 (a INT, b SET('master','slave')) ENGINE=INNODB; -CREATE TABLE t2 (a INT, b SET('master','slave')) ENGINE=MYISAM; +CREATE TABLE t1 (a INT, b SET('master','slave')) ENGINE=InnoDB; +CREATE TABLE t2 (a INT, b SET('master','slave')) ENGINE=MyISAM; +CREATE TABLE t3 (a CHAR(20), b SET('master','slave')) ENGINE=InnoDB; +CREATE TABLE t4 (a CHAR(20), b SET('master','slave')) ENGINE=MyISAM; ==== Skipping normal transactions ==== **** On Slave **** STOP SLAVE; @@ -139,6 +141,102 @@ a b SELECT * FROM t2 ORDER BY a; a b 5 master,slave +==== Skipping first event of a LOAD DATA for a transactional table ==== +**** On Slave **** +STOP SLAVE; +**** On Master **** +SET AUTOCOMMIT=1; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t3(a) SET b = 'master'; +INSERT INTO t3 VALUES ('Go Rin No Sho', 'master,slave'); +SELECT COUNT(*) FROM t3; +COUNT(*) +71 +**** On Slave **** +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +START SLAVE; +-- Should only contain records marked 'master,slave' +SELECT * FROM t3 ORDER BY a; +a b +Go Rin No Sho master,slave +**** On Master **** +DELETE FROM t3; +==== Skipping first event of a LOAD DATA for a non-transactional table ==== +**** On Slave **** +STOP SLAVE; +**** On Master **** +SET AUTOCOMMIT=1; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t4(a) SET b = 'master'; +INSERT INTO t4 VALUES ('Go Rin No Sho', 'master,slave'); +SELECT COUNT(*) FROM t4; +COUNT(*) +71 +**** On Slave **** +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +START SLAVE; +-- Should only contain records marked 'master,slave' +SELECT * FROM t4 ORDER BY a; +a b +Go Rin No Sho master,slave +**** On Master **** +DELETE FROM t4; +==== Try with a big file so that we get an append_block event as well +**** On Slave **** +STOP SLAVE; +**** On Master **** +SET AUTOCOMMIT=1; +SET SQL_LOG_BIN=0; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t4(a) SET b = 'master'; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +SELECT a FROM t4 INTO OUTFILE 'rpl_slave_skip_words.dat'; +SET SQL_LOG_BIN=1; +LOAD DATA INFILE 'rpl_slave_skip_words.dat' INTO TABLE t4(a) SET b = 'master'; +INSERT INTO t4 VALUES ('Go Rin No Sho', 'master,slave'); +SELECT COUNT(*) FROM t4; +COUNT(*) +286721 +**** On Slave **** +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +START SLAVE; +-- Should only contain records marked 'master,slave' +SELECT * FROM t4 ORDER BY a; +a b +Go Rin No Sho master,slave +**** On Master **** +DELETE FROM t4; +**** On Master **** +CREATE TABLE t5 (a int, b int, c SET('master','slave'), PRIMARY KEY (a,b)) ENGINE=MyISAM; +LOAD DATA INFILE '../std_data_ln/loaddata5.dat' INTO TABLE t5 FIELDS TERMINATED BY '' ENCLOSED BY '' (a,b) SET c='master,slave'; +**** On Slave **** +STOP SLAVE; +**** On Master **** +LOAD DATA INFILE '../std_data_ln/loaddata5.dat' INTO TABLE t5 FIELDS TERMINATED BY '' ENCLOSED BY '' (a,b) SET c=''; +ERROR 23000: Duplicate entry '1-2' for key 1 +INSERT INTO t5 VALUES (42, 42, 'master,slave'); +SELECT * FROM t5; +a b c +1 2 master,slave +3 4 master,slave +5 6 master,slave +42 42 master,slave +**** On Slave **** +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +START SLAVE; +SELECT * FROM t5; +a b c +1 2 master,slave +3 4 master,slave +5 6 master,slave +42 42 master,slave ==== Cleanup ==== **** On Master **** -DROP TABLE t1, t2; +DROP TABLE t1, t2, t3, t4, t5; diff --git a/mysql-test/t/rpl_slave_skip.test b/mysql-test/t/rpl_slave_skip.test index 04aafc51129..71e951aceea 100644 --- a/mysql-test/t/rpl_slave_skip.test +++ b/mysql-test/t/rpl_slave_skip.test @@ -13,8 +13,10 @@ source include/master-slave.inc; # it back to get the non-transactional change into the table. --echo **** On Master **** -CREATE TABLE t1 (a INT, b SET('master','slave')) ENGINE=INNODB; -CREATE TABLE t2 (a INT, b SET('master','slave')) ENGINE=MYISAM; +CREATE TABLE t1 (a INT, b SET('master','slave')) ENGINE=InnoDB; +CREATE TABLE t2 (a INT, b SET('master','slave')) ENGINE=MyISAM; +CREATE TABLE t3 (a CHAR(20), b SET('master','slave')) ENGINE=InnoDB; +CREATE TABLE t4 (a CHAR(20), b SET('master','slave')) ENGINE=MyISAM; --echo ==== Skipping normal transactions ==== @@ -195,9 +197,170 @@ sync_with_master; SELECT * FROM t1 ORDER BY a; SELECT * FROM t2 ORDER BY a; +--echo ==== Skipping first event of a LOAD DATA for a transactional table ==== + +--echo **** On Slave **** +connection slave; +STOP SLAVE; +source include/wait_for_slave_to_stop.inc; + +--echo **** On Master **** +connection master; +SET AUTOCOMMIT=1; + +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t3(a) SET b = 'master'; +INSERT INTO t3 VALUES ('Go Rin No Sho', 'master,slave'); + +save_master_pos; + +SELECT COUNT(*) FROM t3; + +# This will skip a begin event and the first INSERT of the +# transaction, and it should keep skipping until it has reached the +# transaction terminator. + +--echo **** On Slave **** +connection slave; +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +START SLAVE; +source include/wait_for_slave_to_start.inc; +sync_with_master; +--echo -- Should only contain records marked 'master,slave' +SELECT * FROM t3 ORDER BY a; + +--echo **** On Master **** +connection master; +DELETE FROM t3; +sync_slave_with_master; + +--echo ==== Skipping first event of a LOAD DATA for a non-transactional table ==== + +--echo **** On Slave **** +connection slave; +STOP SLAVE; +source include/wait_for_slave_to_stop.inc; + +--echo **** On Master **** +connection master; +SET AUTOCOMMIT=1; + +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t4(a) SET b = 'master'; +INSERT INTO t4 VALUES ('Go Rin No Sho', 'master,slave'); + +save_master_pos; + +SELECT COUNT(*) FROM t4; + +# This will skip a begin event and the first INSERT of the +# transaction, and it should keep skipping until it has reached the +# transaction terminator. + +--echo **** On Slave **** +connection slave; +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +START SLAVE; +source include/wait_for_slave_to_start.inc; +sync_with_master; +--echo -- Should only contain records marked 'master,slave' +SELECT * FROM t4 ORDER BY a; + +--echo **** On Master **** +connection master; +DELETE FROM t4; +sync_slave_with_master; + +--echo ==== Try with a big file so that we get an append_block event as well + +--echo **** On Slave **** +connection slave; +STOP SLAVE; +source include/wait_for_slave_to_stop.inc; + +--echo **** On Master **** +connection master; +SET AUTOCOMMIT=1; + +# This contain about 70 words, so we double it a few times to get more than 128 KiB +SET SQL_LOG_BIN=0; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t4(a) SET b = 'master'; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +INSERT INTO t4 SELECT * FROM t4; +SELECT a FROM t4 INTO OUTFILE 'rpl_slave_skip_words.dat'; +SET SQL_LOG_BIN=1; + +# Start the real job +LOAD DATA INFILE 'rpl_slave_skip_words.dat' INTO TABLE t4(a) SET b = 'master'; +INSERT INTO t4 VALUES ('Go Rin No Sho', 'master,slave'); + +#SHOW BINLOG EVENTS; + +save_master_pos; + +SELECT COUNT(*) FROM t4; + +# This will skip a begin event and the first INSERT of the +# transaction, and it should keep skipping until it has reached the +# transaction terminator. + +--echo **** On Slave **** +connection slave; +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +START SLAVE; +source include/wait_for_slave_to_start.inc; +sync_with_master; +--echo -- Should only contain records marked 'master,slave' +SELECT * FROM t4 ORDER BY a; + +--echo **** On Master **** +connection master; +DELETE FROM t4; +sync_slave_with_master; + +# Test to generate a Delete_file log event, and see that it works as well. +--echo **** On Master **** +connection master; +CREATE TABLE t5 (a int, b int, c SET('master','slave'), PRIMARY KEY (a,b)) ENGINE=MyISAM; +LOAD DATA INFILE '../std_data_ln/loaddata5.dat' INTO TABLE t5 FIELDS TERMINATED BY '' ENCLOSED BY '' (a,b) SET c='master,slave'; + +--echo **** On Slave **** +sync_slave_with_master; +STOP SLAVE; +source include/wait_for_slave_to_stop.inc; + +--echo **** On Master **** +connection master; +error ER_DUP_ENTRY; +LOAD DATA INFILE '../std_data_ln/loaddata5.dat' INTO TABLE t5 FIELDS TERMINATED BY '' ENCLOSED BY '' (a,b) SET c=''; +INSERT INTO t5 VALUES (42, 42, 'master,slave'); +save_master_pos; + +#SHOW BINLOG EVENTS; + +SELECT * FROM t5; + +--echo **** On Slave **** +connection slave; +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +START SLAVE; +source include/wait_for_slave_to_start.inc; + +sync_with_master; +SELECT * FROM t5; + +connection slave; + --echo ==== Cleanup ==== --echo **** On Master **** connection master; -DROP TABLE t1, t2; +DROP TABLE t1, t2, t3, t4, t5; sync_slave_with_master; diff --git a/sql/slave.cc b/sql/slave.cc index 1509916fe91..4a65e9aaa85 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -3348,7 +3348,10 @@ static int exec_relay_log_event(THD* thd, RELAY_LOG_INFO* rli) if (rli->slave_skip_counter && !((type_code == INTVAR_EVENT || type_code == RAND_EVENT || - type_code == USER_VAR_EVENT) && + type_code == USER_VAR_EVENT || + type_code == BEGIN_LOAD_QUERY_EVENT || + type_code == APPEND_BLOCK_EVENT || + type_code == CREATE_FILE_EVENT) && rli->slave_skip_counter == 1) && #if MYSQL_VERSION_ID < 50100 /* From 8e2d28e013ac63e9eeb98b3c38ba4fc5ae4b884c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 20 Dec 2007 23:57:06 +0300 Subject: [PATCH 02/12] WL#4077 fix for innodb test that were skipped mysql-test/include/have_innodb.inc: added new value 'ENABLED' for 'support' field --- mysql-test/include/have_innodb.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/include/have_innodb.inc b/mysql-test/include/have_innodb.inc index cbffe6a2574..8944cc46f3e 100644 --- a/mysql-test/include/have_innodb.inc +++ b/mysql-test/include/have_innodb.inc @@ -1,4 +1,4 @@ disable_query_log; --require r/true.require -select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines where engine = 'innodb'; +select (support = 'YES' or support = 'DEFAULT' or support = 'ENABLED') as `TRUE` from information_schema.engines where engine = 'innodb'; enable_query_log; From c9cbd6a48d47e94f480a09d6fd109bd39558bb21 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 20 Dec 2007 22:00:42 +0100 Subject: [PATCH 03/12] Fixed errors in pushbuild by updating test and result files. mysql-test/suite/binlog/r/binlog_row_binlog.result: updated result file. This part of the test was created in parallel with the fix to bug#26395, which modifies the output of mysqlbinlog and hence the output of many tests, including this one. mysql-test/suite/rpl_ndb/r/rpl_ndb_transaction.result: updated result file mysql-test/suite/rpl_ndb/t/rpl_ndb_transaction.test: 1. replaced include/show_slave_status.inc by more specific tests for the SQL error and IO error, as well as Slave_IO_State. 2. drop all tables at the end of test. --- .../suite/binlog/r/binlog_row_binlog.result | 4 ++ .../rpl_ndb/r/rpl_ndb_transaction.result | 52 +++++-------------- .../suite/rpl_ndb/t/rpl_ndb_transaction.test | 26 +++++++--- 3 files changed, 36 insertions(+), 46 deletions(-) diff --git a/mysql-test/suite/binlog/r/binlog_row_binlog.result b/mysql-test/suite/binlog/r/binlog_row_binlog.result index fd91f65bbb5..6c5c149d48e 100644 --- a/mysql-test/suite/binlog/r/binlog_row_binlog.result +++ b/mysql-test/suite/binlog/r/binlog_row_binlog.result @@ -1099,9 +1099,11 @@ master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Query # # use `test`; drop table t1 master-bin.000001 # Query # # use `test`; create table t1 (a int) +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Query # # use `test`; CREATE TABLE IF NOT EXISTS `t2` ( `a` int(11) DEFAULT NULL ) +master-bin.000001 # Query # # use `test`; COMMIT master-bin.000001 # Query # # use `test`; CREATE TABLE IF NOT EXISTS `t3` ( `a` int(11) DEFAULT NULL ) @@ -1124,9 +1126,11 @@ master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Query # # use `test`; drop table t1 master-bin.000001 # Query # # use `test`; create table t1 (a int) +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Query # # use `test`; CREATE TABLE IF NOT EXISTS `t2` ( `a` int(11) DEFAULT NULL ) +master-bin.000001 # Query # # use `test`; COMMIT master-bin.000001 # Query # # use `test`; CREATE TABLE IF NOT EXISTS `t3` ( `a` int(11) DEFAULT NULL ) diff --git a/mysql-test/suite/rpl_ndb/r/rpl_ndb_transaction.result b/mysql-test/suite/rpl_ndb/r/rpl_ndb_transaction.result index b7479552eab..098f191c998 100644 --- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_transaction.result +++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_transaction.result @@ -94,47 +94,21 @@ a 1 --- on slave --- STOP SLAVE; -SHOW SLAVE STATUS; -Slave_IO_State # -Master_Host 127.0.0.1 -Master_User root -Master_Port MASTER_PORT -Connect_Retry 1 -Master_Log_File master-bin.000001 -Read_Master_Log_Pos 1740 -Relay_Log_File # -Relay_Log_Pos # -Relay_Master_Log_File master-bin.000001 -Slave_IO_Running No -Slave_SQL_Running No -Replicate_Do_DB -Replicate_Ignore_DB -Replicate_Do_Table -Replicate_Ignore_Table # -Replicate_Wild_Do_Table -Replicate_Wild_Ignore_Table -Last_Errno 0 -Last_Error -Skip_Counter 0 -Exec_Master_Log_Pos 1579 -Relay_Log_Space # -Until_Condition None -Until_Log_File -Until_Log_Pos 0 -Master_SSL_Allowed No -Master_SSL_CA_File -Master_SSL_CA_Path -Master_SSL_Cert -Master_SSL_Cipher -Master_SSL_Key -Seconds_Behind_Master # -Master_SSL_Verify_Server_Cert No -Last_IO_Errno # -Last_IO_Error # -Last_SQL_Errno 0 -Last_SQL_Error +SELECT "" AS Last_IO_Error; +Last_IO_Error + +SELECT "" AS Last_SQL_Error; +Last_SQL_Error + +SELECT "" AS Last_IO_Error; +Last_IO_Error + SELECT * FROM tinnodb ORDER BY a; a DROP TABLE tmyisam; DROP TABLE tinnodb; DROP TABLE tndb; +--- on master --- +DROP TABLE tmyisam; +DROP TABLE tinnodb; +DROP TABLE tndb; diff --git a/mysql-test/suite/rpl_ndb/t/rpl_ndb_transaction.test b/mysql-test/suite/rpl_ndb/t/rpl_ndb_transaction.test index 16870720e8c..03b43470270 100644 --- a/mysql-test/suite/rpl_ndb/t/rpl_ndb_transaction.test +++ b/mysql-test/suite/rpl_ndb/t/rpl_ndb_transaction.test @@ -82,10 +82,10 @@ SELECT * FROM tmyisam ORDER BY a; # the statement, and slave should roll back later when master is # restarted. -# However, we the master to be alive so that we are sure it replicates -# the statement to the slave. So in the test case, we must therefore -# not crash the master. Instead, we fake the crash by just not writing -# the XID event to the binlog. This is done by the +# However, we want the master to be alive so that we are sure it +# replicates the statement to the slave. So in the test case, we must +# therefore not crash the master. Instead, we fake the crash by just +# not writing the XID event to the binlog. This is done by the # --debug=d,do_not_write_xid flag in the .opt file. # So, unlike if the master had crashed, the master *will* execute the @@ -111,12 +111,24 @@ SELECT * FROM tinnodb ORDER BY a; --connection slave --sleep 3 STOP SLAVE; ---source include/show_slave_status.inc -# the following statement should show that nothing has been replicated +source include/wait_for_slave_to_stop.inc; +let $tmp= query_get_value("SHOW SLAVE STATUS", Slave_IO_State, 1); +eval SELECT "$tmp" AS Slave_IO_State; +let $tmp= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1); +eval SELECT "$tmp" AS Last_SQL_Error; +let $tmp= query_get_value("SHOW SLAVE STATUS", Last_IO_Error, 1); +eval SELECT "$tmp" AS Last_IO_Error; SELECT * FROM tinnodb ORDER BY a; -# clean up +# Clean up. We cannot do it on master and replicate over, because +# master binlog is in a bad state after last test. So we do it both on +# master and on slave. +DROP TABLE tmyisam; +DROP TABLE tinnodb; +DROP TABLE tndb; +--echo --- on master --- +connection master; DROP TABLE tmyisam; DROP TABLE tinnodb; DROP TABLE tndb; From e2937d7f430414607bbf8a56e5617b26e1fabdb3 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Dec 2007 11:02:48 +0800 Subject: [PATCH 04/12] BUG#28908 Replication: set global server_id is not setting the session server_id When set the server-id dynamically, the server_id member of current thread is not updated. Update the server_id member of current thread after updated the global variable value. sql/set_var.cc: Update server_id of current thread mysql-test/r/rpl_server_id.result: Add test for BUG#28908 mysql-test/t/rpl_server_id.test: Add test for BUG#28908 --- mysql-test/r/rpl_server_id.result | 34 +++++++++++++++++++++++++++++++ mysql-test/t/rpl_server_id.test | 29 ++++++++++++++++++++++++++ sql/set_var.cc | 1 + 3 files changed, 64 insertions(+) create mode 100644 mysql-test/r/rpl_server_id.result create mode 100644 mysql-test/t/rpl_server_id.test diff --git a/mysql-test/r/rpl_server_id.result b/mysql-test/r/rpl_server_id.result new file mode 100644 index 00000000000..1e74394c122 --- /dev/null +++ b/mysql-test/r/rpl_server_id.result @@ -0,0 +1,34 @@ +set global server_id=1; +reset master; +drop table if exists t1,t2,t3; +create table t1 (a int); +select @@server_id; +@@server_id +1 +show binlog events from ; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query 1 # use `test`; drop table if exists t1,t2,t3 +master-bin.000001 # Query 1 # use `test`; create table t1 (a int) +set global server_id=2; +create table t2 (b int); +select @@server_id; +@@server_id +2 +show binlog events from ; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query 1 # use `test`; drop table if exists t1,t2,t3 +master-bin.000001 # Query 1 # use `test`; create table t1 (a int) +master-bin.000001 # Query 2 # use `test`; create table t2 (b int) +set global server_id=3; +create table t3 (c int); +select @@server_id; +@@server_id +3 +show binlog events from ; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query 1 # use `test`; drop table if exists t1,t2,t3 +master-bin.000001 # Query 1 # use `test`; create table t1 (a int) +master-bin.000001 # Query 2 # use `test`; create table t2 (b int) +master-bin.000001 # Query 3 # use `test`; create table t3 (c int) +set global server_id=1; +drop table t1,t2,t3; diff --git a/mysql-test/t/rpl_server_id.test b/mysql-test/t/rpl_server_id.test new file mode 100644 index 00000000000..6e98ec6ee6d --- /dev/null +++ b/mysql-test/t/rpl_server_id.test @@ -0,0 +1,29 @@ +# Test for BUG#28908 Replication: set global server_id is not setting the session server_id + +-- source include/have_log_bin.inc + +let $saved_server_id=`select @@server_id`; +set global server_id=1; +reset master; + +-- disable_warnings +drop table if exists t1,t2,t3; +-- enable_warnings + +create table t1 (a int); +select @@server_id; +source include/show_binlog_events2.inc; + +set global server_id=2; +create table t2 (b int); +select @@server_id; +source include/show_binlog_events2.inc; + +set global server_id=3; +create table t3 (c int); +select @@server_id; +source include/show_binlog_events2.inc; + +# cleanup +eval set global server_id=$saved_server_id; +drop table t1,t2,t3; diff --git a/sql/set_var.cc b/sql/set_var.cc index a128529fcc7..fac5a431176 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1441,6 +1441,7 @@ static void fix_trans_mem_root(THD *thd, enum_var_type type) static void fix_server_id(THD *thd, enum_var_type type) { server_id_supplied = 1; + thd->server_id= server_id; } From a82cb42121b9d52171e6cce60e9ef0172385053d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Dec 2007 12:22:09 +0100 Subject: [PATCH 05/12] fixed broken result file --- mysql-test/suite/rpl_ndb/r/rpl_ndb_transaction.result | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/rpl_ndb/r/rpl_ndb_transaction.result b/mysql-test/suite/rpl_ndb/r/rpl_ndb_transaction.result index 098f191c998..94ba40478e0 100644 --- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_transaction.result +++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_transaction.result @@ -94,8 +94,8 @@ a 1 --- on slave --- STOP SLAVE; -SELECT "" AS Last_IO_Error; -Last_IO_Error +SELECT "" AS Slave_IO_State; +Slave_IO_State SELECT "" AS Last_SQL_Error; Last_SQL_Error From b5d95f021f1f984384897890d9335f5bd23c4ba6 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Dec 2007 20:30:23 +0100 Subject: [PATCH 06/12] BUG#26395: if crash during autocommit update to transactional table on master, slave fails Now, every transaction (including autocommit transactions) start with a BEGIN and end with a COMMIT/ROLLBACK in the binlog. Added a test case, and updated lots of test case result files. mysql-test/t/rpl_transaction-master.opt: BitKeeper file /home/sven/bk/b26395-autocommit-xa/5.0-rpl/mysql-test/t/rpl_transaction-master.opt mysql-test/t/rpl_transaction-slave.opt: BitKeeper file /home/sven/bk/b26395-autocommit-xa/5.0-rpl/mysql-test/t/rpl_transaction-slave.opt mysql-test/r/mix_innodb_myisam_binlog.result: Updated result file mysql-test/r/multi_update.result: Updated result file mysql-test/r/rpl_transaction.result: New result file for new test case. mysql-test/r/sp_trans_log.result: Updated result file mysql-test/r/variables-big.result: Updated result file mysql-test/t/rpl_transaction.test: New test case. sql/log.cc: - Always write BEGIN and COMMIT around statements, even in autocommit mode. - Added comments for binlog_commit and binlog_rollback. sql/log_event.cc: Added debug trigger to avoid writing xid events to the binlog. --- mysql-test/r/mix_innodb_myisam_binlog.result | 81 +++++++------- mysql-test/r/multi_update.result | 4 +- mysql-test/r/rpl_transaction.result | 95 +++++++++++++++++ mysql-test/r/sp_trans_log.result | 1 + mysql-test/r/variables-big.result | 14 ++- mysql-test/t/rpl_transaction-master.opt | 1 + mysql-test/t/rpl_transaction-slave.opt | 1 + mysql-test/t/rpl_transaction.test | 106 +++++++++++++++++++ sql/log.cc | 100 ++++++++++++----- sql/log_event.cc | 1 + 10 files changed, 331 insertions(+), 73 deletions(-) create mode 100644 mysql-test/r/rpl_transaction.result create mode 100644 mysql-test/t/rpl_transaction-master.opt create mode 100644 mysql-test/t/rpl_transaction-slave.opt create mode 100644 mysql-test/t/rpl_transaction.test diff --git a/mysql-test/r/mix_innodb_myisam_binlog.result b/mysql-test/r/mix_innodb_myisam_binlog.result index fb69de508dc..bd0c558ea45 100644 --- a/mysql-test/r/mix_innodb_myisam_binlog.result +++ b/mysql-test/r/mix_innodb_myisam_binlog.result @@ -100,9 +100,10 @@ insert into t1 values(9); insert into t2 select * from t1; show binlog events from 98; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 98 Query 1 # use `test`; insert into t1 values(9) -master-bin.000001 185 Xid 1 # COMMIT /* XID */ -master-bin.000001 212 Query 1 # use `test`; insert into t2 select * from t1 +master-bin.000001 98 Query 1 # use `test`; BEGIN +master-bin.000001 166 Query 1 # use `test`; insert into t1 values(9) +master-bin.000001 253 Xid 1 # COMMIT /* XID */ +master-bin.000001 280 Query 1 # use `test`; insert into t2 select * from t1 delete from t1; delete from t2; reset master; @@ -111,19 +112,21 @@ begin; insert into t2 select * from t1; show binlog events from 98; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 98 Query 1 # use `test`; insert into t1 values(10) -master-bin.000001 186 Xid 1 # COMMIT /* XID */ -master-bin.000001 213 Query 1 # use `test`; insert into t2 select * from t1 +master-bin.000001 98 Query 1 # use `test`; BEGIN +master-bin.000001 166 Query 1 # use `test`; insert into t1 values(10) +master-bin.000001 254 Xid 1 # COMMIT /* XID */ +master-bin.000001 281 Query 1 # use `test`; insert into t2 select * from t1 insert into t1 values(11); commit; show binlog events from 98; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 98 Query 1 # use `test`; insert into t1 values(10) -master-bin.000001 186 Xid 1 # COMMIT /* XID */ -master-bin.000001 213 Query 1 # use `test`; insert into t2 select * from t1 -master-bin.000001 307 Query 1 # use `test`; BEGIN -master-bin.000001 375 Query 1 # use `test`; insert into t1 values(11) -master-bin.000001 463 Xid 1 # COMMIT /* XID */ +master-bin.000001 98 Query 1 # use `test`; BEGIN +master-bin.000001 166 Query 1 # use `test`; insert into t1 values(10) +master-bin.000001 254 Xid 1 # COMMIT /* XID */ +master-bin.000001 281 Query 1 # use `test`; insert into t2 select * from t1 +master-bin.000001 375 Query 1 # use `test`; BEGIN +master-bin.000001 443 Query 1 # use `test`; insert into t1 values(11) +master-bin.000001 531 Xid 1 # COMMIT /* XID */ alter table t2 engine=INNODB; delete from t1; delete from t2; @@ -235,25 +238,29 @@ master-bin.000001 98 Query 1 # use `test`; BEGIN master-bin.000001 166 Query 1 # use `test`; insert into t1 values(16) master-bin.000001 254 Query 1 # use `test`; insert into t1 values(18) master-bin.000001 342 Xid 1 # COMMIT /* XID */ -master-bin.000001 369 Query 1 # use `test`; delete from t1 -master-bin.000001 446 Xid 1 # COMMIT /* XID */ -master-bin.000001 473 Query 1 # use `test`; delete from t2 -master-bin.000001 550 Xid 1 # COMMIT /* XID */ -master-bin.000001 577 Query 1 # use `test`; alter table t2 type=MyISAM -master-bin.000001 666 Query 1 # use `test`; insert into t1 values (1) -master-bin.000001 754 Xid 1 # COMMIT /* XID */ -master-bin.000001 781 Query 1 # use `test`; insert into t2 values (20) -master-bin.000001 870 Query 1 # use `test`; drop table t1,t2 -master-bin.000001 949 Query 1 # use `test`; create temporary table ti (a int) engine=innodb -master-bin.000001 1059 Query 1 # use `test`; insert into ti values(1) -master-bin.000001 1146 Xid 1 # COMMIT /* XID */ -master-bin.000001 1173 Query 1 # use `test`; create temporary table t1 (a int) engine=myisam -master-bin.000001 1283 Query 1 # use `test`; insert t1 values (1) -master-bin.000001 1366 Query 1 # use `test`; create table t0 (n int) -master-bin.000001 1452 Query 1 # use `test`; insert t0 select * from t1 -master-bin.000001 1541 Query 1 # use `test`; insert into t0 select GET_LOCK("lock1",null) -master-bin.000001 1648 Query 1 # use `test`; create table t2 (n int) engine=innodb -master-bin.000001 1748 Query 1 # use `test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `test`.`t1`,`test`.`ti` +master-bin.000001 369 Query 1 # use `test`; BEGIN +master-bin.000001 437 Query 1 # use `test`; delete from t1 +master-bin.000001 514 Xid 1 # COMMIT /* XID */ +master-bin.000001 541 Query 1 # use `test`; BEGIN +master-bin.000001 609 Query 1 # use `test`; delete from t2 +master-bin.000001 686 Xid 1 # COMMIT /* XID */ +master-bin.000001 713 Query 1 # use `test`; alter table t2 type=MyISAM +master-bin.000001 802 Query 1 # use `test`; BEGIN +master-bin.000001 870 Query 1 # use `test`; insert into t1 values (1) +master-bin.000001 958 Xid 1 # COMMIT /* XID */ +master-bin.000001 985 Query 1 # use `test`; insert into t2 values (20) +master-bin.000001 1074 Query 1 # use `test`; drop table t1,t2 +master-bin.000001 1153 Query 1 # use `test`; create temporary table ti (a int) engine=innodb +master-bin.000001 1263 Query 1 # use `test`; BEGIN +master-bin.000001 1331 Query 1 # use `test`; insert into ti values(1) +master-bin.000001 1418 Xid 1 # COMMIT /* XID */ +master-bin.000001 1445 Query 1 # use `test`; create temporary table t1 (a int) engine=myisam +master-bin.000001 1555 Query 1 # use `test`; insert t1 values (1) +master-bin.000001 1638 Query 1 # use `test`; create table t0 (n int) +master-bin.000001 1724 Query 1 # use `test`; insert t0 select * from t1 +master-bin.000001 1813 Query 1 # use `test`; insert into t0 select GET_LOCK("lock1",null) +master-bin.000001 1920 Query 1 # use `test`; create table t2 (n int) engine=innodb +master-bin.000001 2020 Query 1 # use `test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `test`.`t1`,`test`.`ti` do release_lock("lock1"); drop table t0,t2; reset master; @@ -402,7 +409,7 @@ insert into t2 values (bug27417(1)); ERROR 23000: Duplicate entry '1' for key 1 show master status /* the offset must denote there is the query */; File Position Binlog_Do_DB Binlog_Ignore_DB -master-bin.000001 267 +master-bin.000001 335 select count(*) from t1 /* must be 1 */; count(*) 1 @@ -414,7 +421,7 @@ insert into t2 select bug27417(1) union select bug27417(2); ERROR 23000: Duplicate entry '2' for key 1 show master status /* the offset must denote there is the query */; File Position Binlog_Do_DB Binlog_Ignore_DB -master-bin.000001 290 +master-bin.000001 358 select count(*) from t1 /* must be 2 */; count(*) 2 @@ -438,7 +445,7 @@ UPDATE t4,t3 SET t4.a=t3.a + bug27417(1) /* top level non-ta table */; ERROR 23000: Duplicate entry '2' for key 1 show master status /* the offset must denote there is the query */; File Position Binlog_Do_DB Binlog_Ignore_DB -master-bin.000001 301 +master-bin.000001 369 select count(*) from t1 /* must be 4 */; count(*) 4 @@ -466,7 +473,7 @@ delete from t2; ERROR 23000: Duplicate entry '1' for key 1 show master status /* the offset must denote there is the query */; File Position Binlog_Do_DB Binlog_Ignore_DB -master-bin.000001 246 +master-bin.000001 314 select count(*) from t1 /* must be 1 */; count(*) 1 @@ -483,7 +490,7 @@ delete t2.* from t2,t5 where t2.a=t5.a + 1; ERROR 23000: Duplicate entry '1' for key 1 show master status /* the offset must denote there is the query */; File Position Binlog_Do_DB Binlog_Ignore_DB -master-bin.000001 274 +master-bin.000001 342 select count(*) from t1 /* must be 1 */; count(*) 1 @@ -501,7 +508,7 @@ count(*) 2 show master status /* the offset must denote there is the query */; File Position Binlog_Do_DB Binlog_Ignore_DB -master-bin.000001 376 +master-bin.000001 444 drop trigger trg_del_t2; drop table t1,t2,t3,t4,t5; drop function bug27417; diff --git a/mysql-test/r/multi_update.result b/mysql-test/r/multi_update.result index d95036090a5..8a0eacd9eeb 100644 --- a/mysql-test/r/multi_update.result +++ b/mysql-test/r/multi_update.result @@ -545,7 +545,7 @@ a b 4 4 show master status /* there must be the UPDATE query event */; File Position Binlog_Do_DB Binlog_Ignore_DB -master-bin.000001 260 +master-bin.000001 328 delete from t1; delete from t2; insert into t1 values (1,2),(3,4),(4,4); @@ -555,7 +555,7 @@ UPDATE t2,t1 SET t2.a=t2.b where t2.a=t1.a; ERROR 23000: Duplicate entry '4' for key 1 show master status /* there must be the UPDATE query event */; File Position Binlog_Do_DB Binlog_Ignore_DB -master-bin.000001 275 +master-bin.000001 343 drop table t1, t2; drop table if exists t1, t2, t3; CREATE TABLE t1 (a int, PRIMARY KEY (a)); diff --git a/mysql-test/r/rpl_transaction.result b/mysql-test/r/rpl_transaction.result new file mode 100644 index 00000000000..9ea0c8f7afd --- /dev/null +++ b/mysql-test/r/rpl_transaction.result @@ -0,0 +1,95 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; +CREATE TABLE tmyisam (a int) ENGINE = MYISAM; +CREATE TABLE tinnodb (a int) ENGINE = INNODB; +SHOW CREATE TABLE tmyisam; +Table Create Table +tmyisam CREATE TABLE `tmyisam` ( + `a` int(11) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SHOW CREATE TABLE tinnodb; +Table Create Table +tinnodb CREATE TABLE `tinnodb` ( + `a` int(11) default NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +==== Test 1: Non-XA Engines ==== +--- on master --- +SET AUTOCOMMIT = 1; +INSERT INTO tmyisam VALUES (1); +BEGIN; +INSERT INTO tmyisam VALUES (2); +INSERT INTO tmyisam VALUES (3); +COMMIT; +BEGIN; +INSERT INTO tmyisam VALUES (5); +INSERT INTO tmyisam VALUES (6); +ROLLBACK; +Warnings: +Warning 1196 Some non-transactional changed tables couldn't be rolled back +SELECT * FROM tmyisam ORDER BY a; +a +1 +2 +3 +5 +6 +--- on slave --- +SELECT * FROM tmyisam ORDER BY a; +a +1 +2 +3 +5 +6 +==== Test 2: Master crash before writing XID event on XA engine ==== +--- on master --- +INSERT INTO tinnodb VALUES (1); +SELECT * FROM tinnodb ORDER BY a; +a +1 +--- on slave --- +STOP SLAVE; +SHOW SLAVE STATUS; +Slave_IO_State +Master_Host 127.0.0.1 +Master_User root +Master_Port # +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos # +Relay_Log_File # +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running No +Slave_SQL_Running No +Replicate_Do_DB +Replicate_Ignore_DB +Replicate_Do_Table +Replicate_Ignore_Table # +Replicate_Wild_Do_Table +Replicate_Wild_Ignore_Table +Last_Errno 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos # +Relay_Log_Space # +Until_Condition None +Until_Log_File +Until_Log_Pos 0 +Master_SSL_Allowed No +Master_SSL_CA_File +Master_SSL_CA_Path +Master_SSL_Cert +Master_SSL_Cipher +Master_SSL_Key +Seconds_Behind_Master # +SELECT * FROM tinnodb ORDER BY a; +a +DROP TABLE tmyisam; +DROP TABLE tinnodb; +DROP TABLE tmyisam; +DROP TABLE tinnodb; diff --git a/mysql-test/r/sp_trans_log.result b/mysql-test/r/sp_trans_log.result index 9b644798079..eb0770cb0a1 100644 --- a/mysql-test/r/sp_trans_log.result +++ b/mysql-test/r/sp_trans_log.result @@ -16,6 +16,7 @@ show binlog events from 98 /* with fixes for #23333 will show there are 2 querie Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Query 1 # # master-bin.000001 # Query 1 # # +master-bin.000001 # Query 1 # # select count(*),@a from t1 /* must be 1,1 */| count(*) @a 1 1 diff --git a/mysql-test/r/variables-big.result b/mysql-test/r/variables-big.result index d7906869276..c441f27d82d 100644 --- a/mysql-test/r/variables-big.result +++ b/mysql-test/r/variables-big.result @@ -1,20 +1,24 @@ set session transaction_prealloc_size=1024*1024*1024*1; show processlist; Id User Host db Command Time State Info -1 root localhost test Query 0 NULL show processlist +6 root localhost test Query 0 NULL show processlist set session transaction_prealloc_size=1024*1024*1024*2; show processlist; Id User Host db Command Time State Info -1 root localhost test Query 2 NULL show processlist +6 root localhost test Query 1 NULL show processlist set session transaction_prealloc_size=1024*1024*1024*3; show processlist; Id User Host db Command Time State Info -1 root localhost test Query 0 NULL show processlist +6 root localhost test Query 0 NULL show processlist set session transaction_prealloc_size=1024*1024*1024*4; +Warnings: +Warning 1292 Truncated incorrect transaction_prealloc_size value: '4294967296' show processlist; Id User Host db Command Time State Info -1 root localhost test Query 0 NULL show processlist +6 root localhost test Query 0 NULL show processlist set session transaction_prealloc_size=1024*1024*1024*5; +Warnings: +Warning 1292 Truncated incorrect transaction_prealloc_size value: '5368709120' show processlist; Id User Host db Command Time State Info -1 root localhost test Query 0 NULL show processlist +6 root localhost test Query 0 NULL show processlist diff --git a/mysql-test/t/rpl_transaction-master.opt b/mysql-test/t/rpl_transaction-master.opt new file mode 100644 index 00000000000..5411960b4aa --- /dev/null +++ b/mysql-test/t/rpl_transaction-master.opt @@ -0,0 +1 @@ +--innodb --debug=d,do_not_write_xid diff --git a/mysql-test/t/rpl_transaction-slave.opt b/mysql-test/t/rpl_transaction-slave.opt new file mode 100644 index 00000000000..627becdbfb5 --- /dev/null +++ b/mysql-test/t/rpl_transaction-slave.opt @@ -0,0 +1 @@ +--innodb diff --git a/mysql-test/t/rpl_transaction.test b/mysql-test/t/rpl_transaction.test new file mode 100644 index 00000000000..b7912ee274f --- /dev/null +++ b/mysql-test/t/rpl_transaction.test @@ -0,0 +1,106 @@ +# Tests that transactions are replicated correctly, with various +# combinations of non-transactional and transactional non-XA tables. +# Also tests that an XA transaction where the master crashes just +# before writing the XID log event is executed correctly. See below +# for implementation details. + +# Note: this test should not exist in 5.1 or higher. It has been +# replaced by rpl_ndb_transaction.test, which tests a superset of what +# this test tests. + +source include/have_innodb.inc; +source include/master-slave.inc; + + +CREATE TABLE tmyisam (a int) ENGINE = MYISAM; +CREATE TABLE tinnodb (a int) ENGINE = INNODB; + +SHOW CREATE TABLE tmyisam; +SHOW CREATE TABLE tinnodb; + + +--echo ==== Test 1: Non-XA Engines ==== +# Test that everything works fine with non-XA engines. We just try +# all ways to do transactions involving ndb and/or myisam, with +# rollback or commit. + +--echo --- on master --- + +SET AUTOCOMMIT = 1; + +INSERT INTO tmyisam VALUES (1); + +BEGIN; +INSERT INTO tmyisam VALUES (2); +INSERT INTO tmyisam VALUES (3); +COMMIT; + +BEGIN; +INSERT INTO tmyisam VALUES (5); +INSERT INTO tmyisam VALUES (6); +--warning 1196 +ROLLBACK; + +SELECT * FROM tmyisam ORDER BY a; + +--echo --- on slave --- +--sync_slave_with_master +SELECT * FROM tmyisam ORDER BY a; + + +--echo ==== Test 2: Master crash before writing XID event on XA engine ==== +# We now want to test the following scenario, to verify that BUG#26395 +# has been fixed: + +# "master and slave have a transactional table that uses XA. Master +# has AUTOCOMMIT on and executes a statement (in this case an +# INSERT). Master crashes just before writing the XID event." + +# In this scenario, master will roll back, so slave should not execute +# the statement, and slave should roll back later when master is +# restarted. + +# However, we the master to be alive so that we are sure it replicates +# the statement to the slave. So in the test case, we must therefore +# not crash the master. Instead, we fake the crash by just not writing +# the XID event to the binlog. This is done by the +# --debug=d,do_not_write_xid flag in the .opt file. + +# So, unlike if the master had crashed, the master *will* execute the +# statement. But the slave should not execute it. Hence, after the +# first test is executed, the expected result on master is a table +# with one row, and on slave a table with no rows. + +# To simulate the slave correctly, we wait until everything up to the +# XID is replicated. We cannot sync_slave_with_master, because that +# would wait for the transaction to end. Instead, we wait for +# "sufficiently long time". Then we stop the slave. + +# Note: since this puts the master binlog in an inconsistent state, +# this should be the last test of the file. + +--echo --- on master --- +--connection master + +INSERT INTO tinnodb VALUES (1); +SELECT * FROM tinnodb ORDER BY a; + +--echo --- on slave --- +--connection slave +--sleep 3 +STOP SLAVE; +source include/wait_for_slave_to_stop.inc; +--replace_column 4 # 7 # 8 # 9 # 16 # 22 # 23 # 33 # +query_vertical SHOW SLAVE STATUS; +# the following statement should show that nothing has been replicated +SELECT * FROM tinnodb ORDER BY a; + + +# clean up +connection master; +DROP TABLE tmyisam; +DROP TABLE tinnodb; + +connection slave; +DROP TABLE tmyisam; +DROP TABLE tinnodb; diff --git a/sql/log.cc b/sql/log.cc index af03cecd462..eca3cf32228 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -122,6 +122,20 @@ static int binlog_prepare(THD *thd, bool all) return 0; } +/** + This function is called once after each statement. + + It has the responsibility to flush the transaction cache to the + binlog file on commits. + + @param thd The client thread that executes the transaction. + @param all true if this is the last statement before a COMMIT + statement; false if either this is a statement in a + transaction but not the last, or if this is a statement + not inside a BEGIN block and autocommit is on. + + @see handlerton::commit +*/ static int binlog_commit(THD *thd, bool all) { IO_CACHE *trans_log= (IO_CACHE*)thd->ha_data[binlog_hton.slot]; @@ -134,7 +148,15 @@ static int binlog_commit(THD *thd, bool all) // we're here because trans_log was flushed in MYSQL_LOG::log_xid() DBUG_RETURN(0); } - if (all) + /* + Write commit event if at least one of the following holds: + - the user sends an explicit COMMIT; or + - the autocommit flag is on, and we are not inside a BEGIN. + However, if the user has not sent an explicit COMMIT, and we are + either inside a BEGIN or run with autocommit off, then this is not + the end of a transaction and we should not write a commit event. + */ + if (all || !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) { Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE); qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE) @@ -144,6 +166,22 @@ static int binlog_commit(THD *thd, bool all) DBUG_RETURN(binlog_end_trans(thd, trans_log, &invisible_commit)); } +/** + This function is called when a transaction involving a transactional + table is rolled back. + + It has the responsibility to flush the transaction cache to the + binlog file. However, if the transaction does not involve + non-transactional tables, nothing needs to be logged. + + @param thd The client thread that executes the transaction. + @param all true if this is the last statement before a COMMIT + statement; false if either this is a statement in a + transaction but not the last, or if this is a statement + not inside a BEGIN block and autocommit is on. + + @see handlerton::rollback +*/ static int binlog_rollback(THD *thd, bool all) { int error=0; @@ -1817,9 +1855,11 @@ uint MYSQL_LOG::next_file_id() IMPLEMENTATION - To support transaction over replication, we wrap the transaction with BEGIN/COMMIT or BEGIN/ROLLBACK in the binary log. - We want to write a BEGIN/ROLLBACK block when a non-transactional table - was updated in a transaction which was rolled back. This is to ensure - that the same updates are run on the slave. + If a transaction that only involves transactional tables is + rolled back, we do not binlog it. However, we write a + BEGIN/ROLLBACK block when a non-transactional table was updated + in a transaction which was rolled back. This is to ensure that + the same updates are run on the slave. */ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event) @@ -1837,32 +1877,34 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event) byte header[LOG_EVENT_HEADER_LEN]; /* - Log "BEGIN" at the beginning of the transaction. - which may contain more than 1 SQL statement. + Log "BEGIN" at the beginning of every transaction. Here, a + transaction is either a BEGIN..COMMIT block or a single + statement in autocommit mode. */ - if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) - { - Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, FALSE); - /* - Imagine this is rollback due to net timeout, after all statements of - the transaction succeeded. Then we want a zero-error code in BEGIN. - In other words, if there was a really serious error code it's already - in the statement's events, there is no need to put it also in this - internally generated event, and as this event is generated late it - would lead to false alarms. - This is safer than thd->clear_error() against kills at shutdown. - */ - qinfo.error_code= 0; - /* - Now this Query_log_event has artificial log_pos 0. It must be adjusted - to reflect the real position in the log. Not doing it would confuse the - slave: it would prevent this one from knowing where he is in the - master's binlog, which would result in wrong positions being shown to - the user, MASTER_POS_WAIT undue waiting etc. - */ - if (qinfo.write(&log_file)) - goto err; - } + Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, FALSE); + /* + Imagine this is rollback due to net timeout, after all + statements of the transaction succeeded. Then we want a + zero-error code in BEGIN. In other words, if there was a + really serious error code it's already in the statement's + events, there is no need to put it also in this internally + generated event, and as this event is generated late it would + lead to false alarms. + + This is safer than thd->clear_error() against kills at shutdown. + */ + qinfo.error_code= 0; + /* + Now this Query_log_event has artificial log_pos 0. It must be + adjusted to reflect the real position in the log. Not doing it + would confuse the slave: it would prevent this one from + knowing where he is in the master's binlog, which would result + in wrong positions being shown to the user, MASTER_POS_WAIT + undue waiting etc. + */ + if (qinfo.write(&log_file)) + goto err; + /* Read from the file used to cache the queries .*/ if (reinit_io_cache(cache, READ_CACHE, 0, 0, 0)) goto err; diff --git a/sql/log_event.cc b/sql/log_event.cc index 965dfb5f5cf..a950094a018 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -3793,6 +3793,7 @@ Xid_log_event(const char* buf, #ifndef MYSQL_CLIENT bool Xid_log_event::write(IO_CACHE* file) { + DBUG_EXECUTE_IF("do_not_write_xid", return 0;); return write_header(file, sizeof(xid)) || my_b_safe_write(file, (byte*) &xid, sizeof(xid)); } From 7bc3e859f3478637c6d06d63dd7b26d87f5a3401 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Dec 2007 21:30:20 +0100 Subject: [PATCH 07/12] Undo previous merge. BitKeeper/deleted/.del-rpl_transaction.result: Delete: mysql-test/r/rpl_transaction.result BitKeeper/deleted/.del-rpl_transaction-master.opt: Delete: mysql-test/t/rpl_transaction-master.opt BitKeeper/deleted/.del-rpl_transaction-slave.opt: Delete: mysql-test/t/rpl_transaction-slave.opt BitKeeper/deleted/.del-rpl_transaction.test: Delete: mysql-test/t/rpl_transaction.test --- mysql-test/r/rpl_transaction.result | 95 --------------------- mysql-test/r/variables-big.result | 12 +-- mysql-test/t/rpl_transaction-master.opt | 1 - mysql-test/t/rpl_transaction-slave.opt | 1 - mysql-test/t/rpl_transaction.test | 106 ------------------------ 5 files changed, 4 insertions(+), 211 deletions(-) delete mode 100644 mysql-test/r/rpl_transaction.result delete mode 100644 mysql-test/t/rpl_transaction-master.opt delete mode 100644 mysql-test/t/rpl_transaction-slave.opt delete mode 100644 mysql-test/t/rpl_transaction.test diff --git a/mysql-test/r/rpl_transaction.result b/mysql-test/r/rpl_transaction.result deleted file mode 100644 index 9ea0c8f7afd..00000000000 --- a/mysql-test/r/rpl_transaction.result +++ /dev/null @@ -1,95 +0,0 @@ -stop slave; -drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; -reset master; -reset slave; -drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; -start slave; -CREATE TABLE tmyisam (a int) ENGINE = MYISAM; -CREATE TABLE tinnodb (a int) ENGINE = INNODB; -SHOW CREATE TABLE tmyisam; -Table Create Table -tmyisam CREATE TABLE `tmyisam` ( - `a` int(11) default NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -SHOW CREATE TABLE tinnodb; -Table Create Table -tinnodb CREATE TABLE `tinnodb` ( - `a` int(11) default NULL -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -==== Test 1: Non-XA Engines ==== ---- on master --- -SET AUTOCOMMIT = 1; -INSERT INTO tmyisam VALUES (1); -BEGIN; -INSERT INTO tmyisam VALUES (2); -INSERT INTO tmyisam VALUES (3); -COMMIT; -BEGIN; -INSERT INTO tmyisam VALUES (5); -INSERT INTO tmyisam VALUES (6); -ROLLBACK; -Warnings: -Warning 1196 Some non-transactional changed tables couldn't be rolled back -SELECT * FROM tmyisam ORDER BY a; -a -1 -2 -3 -5 -6 ---- on slave --- -SELECT * FROM tmyisam ORDER BY a; -a -1 -2 -3 -5 -6 -==== Test 2: Master crash before writing XID event on XA engine ==== ---- on master --- -INSERT INTO tinnodb VALUES (1); -SELECT * FROM tinnodb ORDER BY a; -a -1 ---- on slave --- -STOP SLAVE; -SHOW SLAVE STATUS; -Slave_IO_State -Master_Host 127.0.0.1 -Master_User root -Master_Port # -Connect_Retry 1 -Master_Log_File master-bin.000001 -Read_Master_Log_Pos # -Relay_Log_File # -Relay_Log_Pos # -Relay_Master_Log_File master-bin.000001 -Slave_IO_Running No -Slave_SQL_Running No -Replicate_Do_DB -Replicate_Ignore_DB -Replicate_Do_Table -Replicate_Ignore_Table # -Replicate_Wild_Do_Table -Replicate_Wild_Ignore_Table -Last_Errno 0 -Last_Error -Skip_Counter 0 -Exec_Master_Log_Pos # -Relay_Log_Space # -Until_Condition None -Until_Log_File -Until_Log_Pos 0 -Master_SSL_Allowed No -Master_SSL_CA_File -Master_SSL_CA_Path -Master_SSL_Cert -Master_SSL_Cipher -Master_SSL_Key -Seconds_Behind_Master # -SELECT * FROM tinnodb ORDER BY a; -a -DROP TABLE tmyisam; -DROP TABLE tinnodb; -DROP TABLE tmyisam; -DROP TABLE tinnodb; diff --git a/mysql-test/r/variables-big.result b/mysql-test/r/variables-big.result index e8719c218ea..ae1e20109b9 100644 --- a/mysql-test/r/variables-big.result +++ b/mysql-test/r/variables-big.result @@ -1,7 +1,7 @@ set session transaction_prealloc_size=1024*1024*1024*1; show processlist; Id User Host db Command Time State Info -6 root localhost test Query 0 NULL show processlist +1 root localhost test Query 0 NULL show processlist set session transaction_prealloc_size=1024*1024*1024*2; show processlist; Id User Host db Command Time State Info @@ -9,16 +9,12 @@ Id User Host db Command Time State Info set session transaction_prealloc_size=1024*1024*1024*3; show processlist; Id User Host db Command Time State Info -6 root localhost test Query 0 NULL show processlist +1 root localhost test Query 0 NULL show processlist set session transaction_prealloc_size=1024*1024*1024*4; -Warnings: -Warning 1292 Truncated incorrect transaction_prealloc_size value: '4294967296' show processlist; Id User Host db Command Time State Info -6 root localhost test Query 0 NULL show processlist +1 root localhost test Query 0 NULL show processlist set session transaction_prealloc_size=1024*1024*1024*5; -Warnings: -Warning 1292 Truncated incorrect transaction_prealloc_size value: '5368709120' show processlist; Id User Host db Command Time State Info -6 root localhost test Query 0 NULL show processlist +1 root localhost test Query 0 NULL show processlist diff --git a/mysql-test/t/rpl_transaction-master.opt b/mysql-test/t/rpl_transaction-master.opt deleted file mode 100644 index 5411960b4aa..00000000000 --- a/mysql-test/t/rpl_transaction-master.opt +++ /dev/null @@ -1 +0,0 @@ ---innodb --debug=d,do_not_write_xid diff --git a/mysql-test/t/rpl_transaction-slave.opt b/mysql-test/t/rpl_transaction-slave.opt deleted file mode 100644 index 627becdbfb5..00000000000 --- a/mysql-test/t/rpl_transaction-slave.opt +++ /dev/null @@ -1 +0,0 @@ ---innodb diff --git a/mysql-test/t/rpl_transaction.test b/mysql-test/t/rpl_transaction.test deleted file mode 100644 index b7912ee274f..00000000000 --- a/mysql-test/t/rpl_transaction.test +++ /dev/null @@ -1,106 +0,0 @@ -# Tests that transactions are replicated correctly, with various -# combinations of non-transactional and transactional non-XA tables. -# Also tests that an XA transaction where the master crashes just -# before writing the XID log event is executed correctly. See below -# for implementation details. - -# Note: this test should not exist in 5.1 or higher. It has been -# replaced by rpl_ndb_transaction.test, which tests a superset of what -# this test tests. - -source include/have_innodb.inc; -source include/master-slave.inc; - - -CREATE TABLE tmyisam (a int) ENGINE = MYISAM; -CREATE TABLE tinnodb (a int) ENGINE = INNODB; - -SHOW CREATE TABLE tmyisam; -SHOW CREATE TABLE tinnodb; - - ---echo ==== Test 1: Non-XA Engines ==== -# Test that everything works fine with non-XA engines. We just try -# all ways to do transactions involving ndb and/or myisam, with -# rollback or commit. - ---echo --- on master --- - -SET AUTOCOMMIT = 1; - -INSERT INTO tmyisam VALUES (1); - -BEGIN; -INSERT INTO tmyisam VALUES (2); -INSERT INTO tmyisam VALUES (3); -COMMIT; - -BEGIN; -INSERT INTO tmyisam VALUES (5); -INSERT INTO tmyisam VALUES (6); ---warning 1196 -ROLLBACK; - -SELECT * FROM tmyisam ORDER BY a; - ---echo --- on slave --- ---sync_slave_with_master -SELECT * FROM tmyisam ORDER BY a; - - ---echo ==== Test 2: Master crash before writing XID event on XA engine ==== -# We now want to test the following scenario, to verify that BUG#26395 -# has been fixed: - -# "master and slave have a transactional table that uses XA. Master -# has AUTOCOMMIT on and executes a statement (in this case an -# INSERT). Master crashes just before writing the XID event." - -# In this scenario, master will roll back, so slave should not execute -# the statement, and slave should roll back later when master is -# restarted. - -# However, we the master to be alive so that we are sure it replicates -# the statement to the slave. So in the test case, we must therefore -# not crash the master. Instead, we fake the crash by just not writing -# the XID event to the binlog. This is done by the -# --debug=d,do_not_write_xid flag in the .opt file. - -# So, unlike if the master had crashed, the master *will* execute the -# statement. But the slave should not execute it. Hence, after the -# first test is executed, the expected result on master is a table -# with one row, and on slave a table with no rows. - -# To simulate the slave correctly, we wait until everything up to the -# XID is replicated. We cannot sync_slave_with_master, because that -# would wait for the transaction to end. Instead, we wait for -# "sufficiently long time". Then we stop the slave. - -# Note: since this puts the master binlog in an inconsistent state, -# this should be the last test of the file. - ---echo --- on master --- ---connection master - -INSERT INTO tinnodb VALUES (1); -SELECT * FROM tinnodb ORDER BY a; - ---echo --- on slave --- ---connection slave ---sleep 3 -STOP SLAVE; -source include/wait_for_slave_to_stop.inc; ---replace_column 4 # 7 # 8 # 9 # 16 # 22 # 23 # 33 # -query_vertical SHOW SLAVE STATUS; -# the following statement should show that nothing has been replicated -SELECT * FROM tinnodb ORDER BY a; - - -# clean up -connection master; -DROP TABLE tmyisam; -DROP TABLE tinnodb; - -connection slave; -DROP TABLE tmyisam; -DROP TABLE tinnodb; From bbbdec345cee2e4c8bf51856a09c7a5b6fed84b8 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Dec 2007 15:03:23 +0800 Subject: [PATCH 08/12] Move test rpl_server_id to suite rpl mysql-test/suite/rpl/t/rpl_server_id.test: Rename: mysql-test/t/rpl_server_id.test -> mysql-test/suite/rpl/t/rpl_server_id.test mysql-test/suite/rpl/r/rpl_server_id.result: Rename: mysql-test/r/rpl_server_id.result -> mysql-test/suite/rpl/r/rpl_server_id.result --- mysql-test/{ => suite/rpl}/r/rpl_server_id.result | 0 mysql-test/{ => suite/rpl}/t/rpl_server_id.test | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename mysql-test/{ => suite/rpl}/r/rpl_server_id.result (100%) rename mysql-test/{ => suite/rpl}/t/rpl_server_id.test (100%) diff --git a/mysql-test/r/rpl_server_id.result b/mysql-test/suite/rpl/r/rpl_server_id.result similarity index 100% rename from mysql-test/r/rpl_server_id.result rename to mysql-test/suite/rpl/r/rpl_server_id.result diff --git a/mysql-test/t/rpl_server_id.test b/mysql-test/suite/rpl/t/rpl_server_id.test similarity index 100% rename from mysql-test/t/rpl_server_id.test rename to mysql-test/suite/rpl/t/rpl_server_id.test From 0e862b756a2deb25e0e489694053dce5678ad9a6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Dec 2007 15:04:22 +0800 Subject: [PATCH 09/12] Remove test rpl_drop_view from main suite BitKeeper/deleted/.del-rpl_drop_view.test: Delete: mysql-test/t/rpl_drop_view.test BitKeeper/deleted/.del-rpl_drop_view.result: Delete: mysql-test/r/rpl_drop_view.result --- mysql-test/r/rpl_drop_view.result | 27 --------------------------- mysql-test/t/rpl_drop_view.test | 31 ------------------------------- 2 files changed, 58 deletions(-) delete mode 100644 mysql-test/r/rpl_drop_view.result delete mode 100644 mysql-test/t/rpl_drop_view.test diff --git a/mysql-test/r/rpl_drop_view.result b/mysql-test/r/rpl_drop_view.result deleted file mode 100644 index ef625464881..00000000000 --- a/mysql-test/r/rpl_drop_view.result +++ /dev/null @@ -1,27 +0,0 @@ -stop slave; -drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; -reset master; -reset slave; -drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; -start slave; -drop table if exists t1, t2; -drop view if exists v1, v2, v3, not_exist_view; -create table t1 (a int); -create table t2 (b int); -create table t3 (c int); -create view v1 as select * from t1; -create view v2 as select * from t2; -create view v3 as select * from t3; -drop view not_exist_view; -ERROR 42S02: Unknown table 'not_exist_view' -drop view v1, not_exist_view; -ERROR 42S02: Unknown table 'not_exist_view' -select * from v1; -ERROR 42S02: Table 'test.v1' doesn't exist -drop view v2, v3; -select * from v1; -ERROR 42S02: Table 'test.v1' doesn't exist -select * from v2; -ERROR 42S02: Table 'test.v2' doesn't exist -select * from v3; -ERROR 42S02: Table 'test.v3' doesn't exist diff --git a/mysql-test/t/rpl_drop_view.test b/mysql-test/t/rpl_drop_view.test deleted file mode 100644 index 8d826b8214d..00000000000 --- a/mysql-test/t/rpl_drop_view.test +++ /dev/null @@ -1,31 +0,0 @@ -# test case for bug#30998 -# Drop View breaks replication if view does not exist -# - -source include/master-slave.inc; ---disable_warnings -drop table if exists t1, t2; -drop view if exists v1, v2, v3, not_exist_view; ---enable_warnings -create table t1 (a int); -create table t2 (b int); -create table t3 (c int); -create view v1 as select * from t1; -create view v2 as select * from t2; -create view v3 as select * from t3; ---error 1051 -drop view not_exist_view; ---error 1051 -drop view v1, not_exist_view; ---error 1146 -select * from v1; -drop view v2, v3; -save_master_pos; -connection slave; -sync_with_master; ---error 1146 -select * from v1; ---error 1146 -select * from v2; ---error 1146 -select * from v3; From d658b408af7a208f747cae9818bc3ab626ac37c3 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 Dec 2007 22:10:22 +0300 Subject: [PATCH 10/12] WL#4077, added mask for SHOW DATABASES statement mysql-test/suite/rpl/r/rpl_create_database.result: updated result file mysql-test/suite/rpl/r/rpl_load_from_master.result: updated result file mysql-test/suite/rpl/t/rpl_create_database.test: added the mask 'mysql%' for SHOW DATABASES mysql-test/suite/rpl/t/rpl_load_from_master.test: added the mask 'mysql%' for SHOw DATABASES --- .../suite/rpl/r/rpl_create_database.result | 24 +++++++------------ .../suite/rpl/r/rpl_load_from_master.result | 18 +++++--------- .../suite/rpl/t/rpl_create_database.test | 8 +++---- .../suite/rpl/t/rpl_load_from_master.test | 6 ++--- 4 files changed, 21 insertions(+), 35 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_create_database.result b/mysql-test/suite/rpl/r/rpl_create_database.result index 0cfd44bc58c..9780b65f334 100644 --- a/mysql-test/suite/rpl/r/rpl_create_database.result +++ b/mysql-test/suite/rpl/r/rpl_create_database.result @@ -20,21 +20,17 @@ INSERT INTO t2 VALUES(2); ALTER DATABASE mysqltest_sisyfos CHARACTER SET latin1; USE mysqltest_sisyfos; ALTER DATABASE mysqltest_bob CHARACTER SET latin1; -SHOW DATABASES; -Database -information_schema +SHOW DATABASES LIKE 'mysql%'; +Database (mysql%) mysql mysqltest_bob mysqltest_prometheus mysqltest_sisyfos -test -SHOW DATABASES; -Database -information_schema +SHOW DATABASES LIKE 'mysql%'; +Database (mysql%) mysql mysqltest_prometheus mysqltest_sisyfos -test DROP DATABASE IF EXISTS mysqltest_sisyfos; USE mysqltest_prometheus; CREATE TABLE t1 (a INT); @@ -42,21 +38,17 @@ INSERT INTO t1 VALUES (1); CREATE DATABASE mysqltest_sisyfos; USE mysqltest_sisyfos; CREATE TABLE t2 (a INT); -SHOW DATABASES; -Database -information_schema +SHOW DATABASES LIKE 'mysql%'; +Database (mysql%) mysql mysqltest_bob mysqltest_prometheus mysqltest_sisyfos -test -SHOW DATABASES; -Database -information_schema +SHOW DATABASES LIKE 'mysql%'; +Database (mysql%) mysql mysqltest_prometheus mysqltest_sisyfos -test USE mysqltest_prometheus; SHOW TABLES; Tables_in_mysqltest_prometheus diff --git a/mysql-test/suite/rpl/r/rpl_load_from_master.result b/mysql-test/suite/rpl/r/rpl_load_from_master.result index 08b45ec1db0..e1c2ecb35be 100644 --- a/mysql-test/suite/rpl/r/rpl_load_from_master.result +++ b/mysql-test/suite/rpl/r/rpl_load_from_master.result @@ -30,13 +30,11 @@ drop database mysqltest2; set sql_log_bin = 0; create database mysqltest2; create database mysqltest; -show databases; -Database -information_schema +show databases like 'mysql%'; +Database (mysql%) mysql mysqltest mysqltest2 -test create table mysqltest2.t1(n int, s char(20))ENGINE=MyISAM; create table mysqltest2.t2(n int, s text)ENGINE=MyISAM; insert into mysqltest2.t1 values (1, 'one'), (2, 'two'), (3, 'three'); @@ -47,11 +45,9 @@ insert into mysqltest.t1 values (1, 'one test'), (2, 'two test'), (3, 'three tes insert into mysqltest.t2 values (11, 'eleven test'), (12, 'twelve test'), (13, 'thirteen test'); set sql_log_bin = 1; -show databases; -Database -information_schema +show databases like 'mysql%'; +Database (mysql%) mysql -test create database mysqltest2; create table mysqltest2.t1(n int, s char(20))ENGINE=MyISAM; insert into mysqltest2.t1 values (1, 'original foo.t1'); @@ -66,14 +62,12 @@ insert into mysqltest.t1 values (1, 'original bar.t1'); create table mysqltest.t3(n int, s char(20))ENGINE=MyISAM; insert into mysqltest.t3 values (1, 'original bar.t3'); load data from master; -show databases; -Database -information_schema +show databases like 'mysql%'; +Database (mysql%) mysql mysqltest mysqltest2 mysqltest3 -test use mysqltest2; show tables; Tables_in_mysqltest2 diff --git a/mysql-test/suite/rpl/t/rpl_create_database.test b/mysql-test/suite/rpl/t/rpl_create_database.test index 70cff8daca2..e3e2e637594 100644 --- a/mysql-test/suite/rpl/t/rpl_create_database.test +++ b/mysql-test/suite/rpl/t/rpl_create_database.test @@ -42,9 +42,9 @@ USE mysqltest_sisyfos; # The following should *not* be replicated ALTER DATABASE mysqltest_bob CHARACTER SET latin1; -SHOW DATABASES; +SHOW DATABASES LIKE 'mysql%'; sync_slave_with_master; -SHOW DATABASES; +SHOW DATABASES LIKE 'mysql%'; connection master; DROP DATABASE IF EXISTS mysqltest_sisyfos; @@ -55,9 +55,9 @@ CREATE DATABASE mysqltest_sisyfos; USE mysqltest_sisyfos; CREATE TABLE t2 (a INT); let $VERSION=`select version()`; -SHOW DATABASES; +SHOW DATABASES LIKE 'mysql%'; sync_slave_with_master; -SHOW DATABASES; +SHOW DATABASES LIKE 'mysql%'; USE mysqltest_prometheus; SHOW TABLES; USE mysqltest_sisyfos; diff --git a/mysql-test/suite/rpl/t/rpl_load_from_master.test b/mysql-test/suite/rpl/t/rpl_load_from_master.test index 9bab7d5696e..b04d8a44226 100644 --- a/mysql-test/suite/rpl/t/rpl_load_from_master.test +++ b/mysql-test/suite/rpl/t/rpl_load_from_master.test @@ -54,7 +54,7 @@ connection master; set sql_log_bin = 0; create database mysqltest2; create database mysqltest; -show databases; +show databases like 'mysql%'; create table mysqltest2.t1(n int, s char(20))ENGINE=MyISAM; create table mysqltest2.t2(n int, s text)ENGINE=MyISAM; insert into mysqltest2.t1 values (1, 'one'), (2, 'two'), (3, 'three'); @@ -71,7 +71,7 @@ connection slave; sync_with_master; # This should show that the slave is empty at this point -show databases; +show databases like 'mysql%'; # Create mysqltest2 and mysqltest3 on slave; we expect that LOAD DATA FROM # MASTER will neither touch database mysqltest nor mysqltest3 create database mysqltest2; @@ -95,7 +95,7 @@ insert into mysqltest.t3 values (1, 'original bar.t3'); load data from master; # Now let's check if we have the right tables and the right data in them -show databases; +show databases like 'mysql%'; use mysqltest2; # LOAD DATA FROM MASTER uses only replicate_*_db rules to decide which From f1e1a498a7a0a37b29e855ecc2afac496752f298 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Dec 2007 17:30:17 +0300 Subject: [PATCH 11/12] WL#4077 added support old versions of mysqld binaries mysql-test/include/have_multi_ndb.inc: check that information_schema.engines table exists --- mysql-test/include/have_multi_ndb.inc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mysql-test/include/have_multi_ndb.inc b/mysql-test/include/have_multi_ndb.inc index 3a2100c1d25..fa201793eaf 100644 --- a/mysql-test/include/have_multi_ndb.inc +++ b/mysql-test/include/have_multi_ndb.inc @@ -4,26 +4,34 @@ connect (server2,127.0.0.1,root,,test,$MASTER_MYPORT1,); # Check that server1 has NDB support connection server1; +let $engines_table= query_get_value(SHOW TABLES FROM information_schema LIKE 'engines', Tables_in_information_schema (engines), 1); disable_query_log; --disable_warnings drop table if exists t1, t2; --enable_warnings flush tables; +if (`SELECT 1 FROM dual WHERE '$engines_table' = 'engines'`) +{ --require r/true.require -select (support = 'YES' or support = 'DEFAULT' or support = 'ENABLED') as `TRUE` from information_schema.engines where engine = 'ndbcluster'; +SELECT (support = 'YES' or support = 'DEFAULT' or support = 'ENABLED') as `TRUE` FROM information_schema.engines WHERE engine = 'ndbcluster'; --source include/ndb_not_readonly.inc +} enable_query_log; # Check that server2 has NDB support connection server2; +let $engines_table= query_get_value(SHOW TABLES FROM information_schema LIKE 'engines', Tables_in_information_schema (engines), 1); disable_query_log; --disable_warnings drop table if exists t1, t2; --enable_warnings flush tables; +if (`SELECT 1 FROM dual WHERE '$engines_table' = 'engines'`) +{ --require r/true.require -select (support = 'YES' or support = 'DEFAULT' or support = 'ENABLED') as `TRUE` from information_schema.engines where engine = 'ndbcluster'; +SELECT (support = 'YES' or support = 'DEFAULT' or support = 'ENABLED') as `TRUE` FROM information_schema.engines WHERE engine = 'ndbcluster'; --source include/ndb_not_readonly.inc +} enable_query_log; # Set the default connection to 'server1' From c06d3d70715334daa0925c14ad1d9e71b56cf32d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 11 Jan 2008 12:35:35 +0100 Subject: [PATCH 12/12] Post-merge fixes to make binlog test suite pass. mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test: Fixing test to use different positions depending on binlog format. mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result: Result change. mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result: Result change. mysql-test/suite/binlog/t/binlog_row_mix_innodb_myisam.test: Removing part of test that does not work any more. mysql-test/suite/binlog/t/binlog_stm_mix_innodb_myisam.test: Removing part of test that does not work any more. --- .../mix_innodb_myisam_binlog.test | 18 +- .../r/binlog_row_mix_innodb_myisam.result | 239 +++++++++++++++++- .../r/binlog_stm_mix_innodb_myisam.result | 232 ++++++++++++++++- .../t/binlog_row_mix_innodb_myisam.test | 20 -- .../t/binlog_stm_mix_innodb_myisam.test | 20 -- 5 files changed, 481 insertions(+), 48 deletions(-) diff --git a/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test b/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test index d8788dceaa5..985acdb2fa2 100644 --- a/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test +++ b/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test @@ -315,11 +315,21 @@ disconnect con3; connection con4; select get_lock("a",10); # wait for rollback to finish +flush logs; # we check that the error code of the "ROLLBACK" event is 0 and not # ER_SERVER_SHUTDOWN (i.e. disconnection just rolls back transaction # and does not make slave to stop) ---exec $MYSQL_BINLOG --start-position=547 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output +if (`select @@binlog_format = 'ROW'`) +{ + --exec $MYSQL_BINLOG --start-position=524 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output +} + +if (`select @@binlog_format = 'STATEMENT' || @@binlog_format = 'MIXED'`) +{ + --exec $MYSQL_BINLOG --start-position=555 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output +} + --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR eval select (@a:=load_file("$MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output")) @@ -360,7 +370,7 @@ rollback; select count(*) from tt /* 2 */; show master status; --replace_column 2 # 5 # -show binlog events from 98; +show binlog events from 106; select count(*) from ti /* zero */; insert into ti select * from tt; select * from ti /* that is what slave would miss - a bug */; @@ -385,12 +395,12 @@ rollback; show master status; --replace_column 2 # 5 # -show binlog events from 98; +show binlog events from 106; select count(*) from ti /* zero */; insert into ti select * from tt; select * from tt /* that is what otherwise slave missed - the bug */; -drop table ti; +drop table ti, tt; # diff --git a/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result b/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result index f69d5717a1f..9d24cac3226 100644 --- a/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result +++ b/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result @@ -113,6 +113,7 @@ insert into t1 values(9); insert into t2 select * from t1; show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Xid # # COMMIT /* XID */ @@ -126,6 +127,7 @@ begin; insert into t2 select * from t1; show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Xid # # COMMIT /* XID */ @@ -135,6 +137,7 @@ insert into t1 values(11); commit; show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Xid # # COMMIT /* XID */ @@ -260,10 +263,12 @@ master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Xid # # COMMIT /* XID */ +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Delete_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Xid # # COMMIT /* XID */ master-bin.000001 # Query # # use `test`; alter table t2 engine=MyISAM +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Xid # # COMMIT /* XID */ @@ -366,6 +371,7 @@ master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t2 master-bin.000001 # Query # # use `test`; CREATE TABLE t2 (a int, b int, primary key (a)) engine=innodb master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Query # # use `test`; TRUNCATE table t2 master-bin.000001 # Xid # # COMMIT /* XID */ master-bin.000001 # Table_map # # table_id: # (test.t1) @@ -383,6 +389,7 @@ master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Query # # use `test`; TRUNCATE table t2 master-bin.000001 # Xid # # COMMIT /* XID */ master-bin.000001 # Table_map # # table_id: # (test.t1) @@ -408,9 +415,9 @@ is not null; is not null 1 select -@a like "%#%error_code=0%ROLLBACK/*!*/;%ROLLBACK /* added by mysqlbinlog */;%", +@a like "%#%error_code=0%ROLLBACK\n/*!*/;%ROLLBACK /* added by mysqlbinlog */;%", @a not like "%#%error_code=%error_code=%"; -@a like "%#%error_code=0%ROLLBACK/*!*/;%ROLLBACK /* added by mysqlbinlog */;%" @a not like "%#%error_code=%error_code=%" +@a like "%#%error_code=0%ROLLBACK\n/*!*/;%ROLLBACK /* added by mysqlbinlog */;%" @a not like "%#%error_code=%error_code=%" 1 1 drop table t1, t2; create temporary table tt (a int unique); @@ -432,6 +439,226 @@ count(*) show master status; File Position Binlog_Do_DB Binlog_Ignore_DB master-bin.000001 395 +show binlog events from 106; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query 1 # use `test`; BEGIN +master-bin.000001 # Table_map 1 # table_id: 27 (test.ti) +master-bin.000001 # Write_rows 1 # table_id: 27 flags: STMT_END_F +master-bin.000001 # Table_map 1 # table_id: 27 (test.ti) +master-bin.000001 # Write_rows 1 # table_id: 27 flags: STMT_END_F +master-bin.000001 # Query 1 # use `test`; ROLLBACK +select count(*) from ti /* zero */; +count(*) +0 +insert into ti select * from tt; +select * from ti /* that is what slave would miss - a bug */; +a +1 +2 +delete from ti; +delete from tt where a=1; +reset master; +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 106 +begin; +insert into ti values (1); +insert into ti values (2) /* to make the dup error in the following */; +insert into tt select * from ti /* one affected and error */; +ERROR 23000: Duplicate entry '2' for key 'a' +rollback; +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 106 +show binlog events from 106; +Log_name Pos Event_type Server_id End_log_pos Info +select count(*) from ti /* zero */; +count(*) +0 +insert into ti select * from tt; +select * from tt /* that is what otherwise slave missed - the bug */; +a +1 +2 +drop table ti, tt; +drop function if exists bug27417; +drop table if exists t1,t2; +CREATE TABLE t1 (a int NOT NULL auto_increment primary key) ENGINE=MyISAM; +CREATE TABLE t2 (a int NOT NULL auto_increment, PRIMARY KEY (a)); +create function bug27417(n int) +RETURNS int(11) +begin +insert into t1 values (null); +return n; +end| +reset master; +insert into t2 values (bug27417(1)); +insert into t2 select bug27417(2); +reset master; +insert into t2 values (bug27417(2)); +ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 222 +/* only (!) with fixes for #23333 will show there is the query */; +select count(*) from t1 /* must be 3 */; +count(*) +3 +reset master; +select count(*) from t2; +count(*) +2 +delete from t2 where a=bug27417(3); +select count(*) from t2 /* nothing got deleted */; +count(*) +2 +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 227 +/* the query must be in regardless of #23333 */; +select count(*) from t1 /* must be 5 */; +count(*) +5 +delete t2 from t2 where t2.a=bug27417(100) /* must not affect t2 */; +affected rows: 0 +select count(*) from t1 /* must be 7 */; +count(*) +7 +drop table t1,t2; +CREATE TABLE t1 (a int NOT NULL auto_increment primary key) ENGINE=MyISAM; +CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB; +CREATE TABLE t3 (a int, PRIMARY KEY (a), b int unique) ENGINE=MyISAM; +CREATE TABLE t4 (a int, PRIMARY KEY (a), b int unique) ENGINE=Innodb; +CREATE TABLE t5 (a int, PRIMARY KEY (a)) ENGINE=InnoDB; +insert into t2 values (1); +reset master; +insert into t2 values (bug27417(1)); +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 361 +select count(*) from t1 /* must be 1 */; +count(*) +1 +delete from t1; +delete from t2; +insert into t2 values (2); +reset master; +insert into t2 select bug27417(1) union select bug27417(2); +ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 400 +select count(*) from t1 /* must be 2 */; +count(*) +2 +delete from t1; +insert into t3 values (1,1),(2,3),(3,4); +reset master; +update t3 set b=b+bug27417(1); +ERROR 23000: Duplicate entry '4' for key 'b' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 305 +select count(*) from t1 /* must be 2 */; +count(*) +2 +delete from t3; +delete from t4; +insert into t3 values (1,1); +insert into t4 values (1,1),(2,2); +reset master; +UPDATE t4,t3 SET t4.a=t3.a + bug27417(1) /* top level non-ta table */; +ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 367 +select count(*) from t1 /* must be 4 */; +count(*) +4 +delete from t1; +delete from t3; +delete from t4; +insert into t3 values (1,1),(2,2); +insert into t4 values (1,1),(2,2); +reset master; +UPDATE t3,t4 SET t3.a=t4.a + bug27417(1); +ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +select count(*) from t1 /* must be 1 */; +count(*) +2 +drop table t4; +delete from t1; +delete from t2; +delete from t3; +insert into t2 values (1); +insert into t3 values (1,1); +create trigger trg_del before delete on t2 for each row +insert into t3 values (bug27417(1), 2); +reset master; +delete from t2; +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 403 +select count(*) from t1 /* must be 1 */; +count(*) +1 +drop trigger trg_del; +delete from t1; +delete from t2; +delete from t5; +create trigger trg_del_t2 after delete on t2 for each row +insert into t1 values (1); +insert into t2 values (2),(3); +insert into t5 values (1),(2); +reset master; +delete t2.* from t2,t5 where t2.a=t5.a + 1; +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 429 +select count(*) from t1 /* must be 1 */; +count(*) +1 +delete from t1; +create table t4 (a int default 0, b int primary key) engine=innodb; +insert into t4 values (0, 17); +reset master; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2); +ERROR 23000: Duplicate entry '17' for key 'PRIMARY' +select * from t4; +a b +0 17 +select count(*) from t1 /* must be 2 */; +count(*) +2 +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 430 +drop trigger trg_del_t2; +drop table t1,t2,t3,t4,t5; +drop function bug27417; +end of tests +create temporary table tt (a int unique); +create table ti (a int) engine=innodb; +reset master; +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 106 +begin; +insert into ti values (1); +insert into ti values (2) ; +insert into tt select * from ti; +rollback; +Warnings: +Warning 1196 Some non-transactional changed tables couldn't be rolled back +select count(*) from tt /* 2 */; +count(*) +2 +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 395 show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Query # # use `test`; BEGIN @@ -529,6 +756,7 @@ insert into t2 values (bug27417(1)); ERROR 23000: Duplicate entry '1' for key 'PRIMARY' show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Intvar # # INSERT_ID=1 master-bin.000001 # Query # # use `test`; insert into t2 values (bug27417(1)) master-bin.000001 # Query # # use `test`; ROLLBACK @@ -543,6 +771,7 @@ insert into t2 select bug27417(1) union select bug27417(2); ERROR 23000: Duplicate entry '2' for key 'PRIMARY' show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Intvar # # INSERT_ID=2 master-bin.000001 # Query # # use `test`; insert into t2 select bug27417(1) union select bug27417(2) master-bin.000001 # Query # # use `test`; ROLLBACK @@ -570,6 +799,7 @@ UPDATE t4,t3 SET t4.a=t3.a + bug27417(1) /* top level non-ta table */; ERROR 23000: Duplicate entry '2' for key 'PRIMARY' show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Intvar # # INSERT_ID=6 master-bin.000001 # Query # # use `test`; UPDATE t4,t3 SET t4.a=t3.a + bug27417(1) /* top level non-ta table */ master-bin.000001 # Query # # use `test`; ROLLBACK @@ -600,6 +830,7 @@ delete from t2; ERROR 23000: Duplicate entry '1' for key 'PRIMARY' show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Intvar # # INSERT_ID=9 master-bin.000001 # Query # # use `test`; delete from t2 master-bin.000001 # Query # # use `test`; ROLLBACK @@ -619,6 +850,7 @@ delete t2.* from t2,t5 where t2.a=t5.a + 1; ERROR 23000: Duplicate entry '1' for key 'PRIMARY' show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Query # # use `test`; delete t2.* from t2,t5 where t2.a=t5.a + 1 master-bin.000001 # Query # # use `test`; ROLLBACK select count(*) from t1 /* must be 1 */; @@ -638,9 +870,12 @@ count(*) 2 show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Intvar # # INSERT_ID=10 +master-bin.000001 # User var # # @`b`=_latin1 0x3135 COLLATE latin1_swedish_ci master-bin.000001 # Begin_load_query # # ;file_id=1;block_len=12 master-bin.000001 # Intvar # # INSERT_ID=10 +master-bin.000001 # User var # # @`b`=_latin1 0x3135 COLLATE latin1_swedish_ci master-bin.000001 # Execute_load_query # # use `test`; load data infile '../std_data_ln/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2) ;file_id=1 master-bin.000001 # Query # # use `test`; ROLLBACK drop trigger trg_del_t2; diff --git a/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result b/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result index f9684a9f641..20f2eaac535 100644 --- a/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result +++ b/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result @@ -389,6 +389,232 @@ select @a like "%#%error_code=0%ROLLBACK\n/*!*/;%ROLLBACK /* added by mysqlbinlog */;%" @a not like "%#%error_code=%error_code=%" 1 1 drop table t1, t2; +create temporary table tt (a int unique); +create table ti (a int) engine=innodb; +reset master; +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 106 +begin; +insert into ti values (1); +insert into ti values (2) ; +insert into tt select * from ti; +rollback; +Warnings: +Warning 1196 Some non-transactional changed tables couldn't be rolled back +select count(*) from tt /* 2 */; +count(*) +2 +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 515 +show binlog events from 106; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query 1 # use `test`; BEGIN +master-bin.000001 # Query 1 # use `test`; insert into ti values (1) +master-bin.000001 # Query 1 # use `test`; insert into ti values (2) +master-bin.000001 # Query 1 # use `test`; insert into tt select * from ti +master-bin.000001 # Query 1 # use `test`; ROLLBACK +select count(*) from ti /* zero */; +count(*) +0 +insert into ti select * from tt; +select * from ti /* that is what slave would miss - a bug */; +a +1 +2 +delete from ti; +delete from tt where a=1; +reset master; +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 106 +begin; +insert into ti values (1); +insert into ti values (2) /* to make the dup error in the following */; +insert into tt select * from ti /* one affected and error */; +ERROR 23000: Duplicate entry '2' for key 'a' +rollback; +Warnings: +Warning 1196 Some non-transactional changed tables couldn't be rolled back +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 589 +show binlog events from 106; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query 1 # use `test`; BEGIN +master-bin.000001 # Query 1 # use `test`; insert into ti values (1) +master-bin.000001 # Query 1 # use `test`; insert into ti values (2) /* to make the dup error in the following */ +master-bin.000001 # Query 1 # use `test`; insert into tt select * from ti /* one affected and error */ +master-bin.000001 # Query 1 # use `test`; ROLLBACK +select count(*) from ti /* zero */; +count(*) +0 +insert into ti select * from tt; +select * from tt /* that is what otherwise slave missed - the bug */; +a +1 +2 +drop table ti, tt; +drop function if exists bug27417; +drop table if exists t1,t2; +CREATE TABLE t1 (a int NOT NULL auto_increment primary key) ENGINE=MyISAM; +CREATE TABLE t2 (a int NOT NULL auto_increment, PRIMARY KEY (a)); +create function bug27417(n int) +RETURNS int(11) +begin +insert into t1 values (null); +return n; +end| +reset master; +insert into t2 values (bug27417(1)); +insert into t2 select bug27417(2); +reset master; +insert into t2 values (bug27417(2)); +ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 222 +/* only (!) with fixes for #23333 will show there is the query */; +select count(*) from t1 /* must be 3 */; +count(*) +3 +reset master; +select count(*) from t2; +count(*) +2 +delete from t2 where a=bug27417(3); +select count(*) from t2 /* nothing got deleted */; +count(*) +2 +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 227 +/* the query must be in regardless of #23333 */; +select count(*) from t1 /* must be 5 */; +count(*) +5 +delete t2 from t2 where t2.a=bug27417(100) /* must not affect t2 */; +affected rows: 0 +select count(*) from t1 /* must be 7 */; +count(*) +7 +drop table t1,t2; +CREATE TABLE t1 (a int NOT NULL auto_increment primary key) ENGINE=MyISAM; +CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB; +CREATE TABLE t3 (a int, PRIMARY KEY (a), b int unique) ENGINE=MyISAM; +CREATE TABLE t4 (a int, PRIMARY KEY (a), b int unique) ENGINE=Innodb; +CREATE TABLE t5 (a int, PRIMARY KEY (a)) ENGINE=InnoDB; +insert into t2 values (1); +reset master; +insert into t2 values (bug27417(1)); +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 371 +select count(*) from t1 /* must be 1 */; +count(*) +1 +delete from t1; +delete from t2; +insert into t2 values (2); +reset master; +insert into t2 select bug27417(1) union select bug27417(2); +ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 394 +select count(*) from t1 /* must be 2 */; +count(*) +2 +delete from t1; +insert into t3 values (1,1),(2,3),(3,4); +reset master; +update t3 set b=b+bug27417(1); +ERROR 23000: Duplicate entry '4' for key 'b' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 226 +select count(*) from t1 /* must be 2 */; +count(*) +2 +delete from t3; +delete from t4; +insert into t3 values (1,1); +insert into t4 values (1,1),(2,2); +reset master; +UPDATE t4,t3 SET t4.a=t3.a + bug27417(1) /* top level non-ta table */; +ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 405 +select count(*) from t1 /* must be 4 */; +count(*) +4 +delete from t1; +delete from t3; +delete from t4; +insert into t3 values (1,1),(2,2); +insert into t4 values (1,1),(2,2); +reset master; +UPDATE t3,t4 SET t3.a=t4.a + bug27417(1); +ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +select count(*) from t1 /* must be 1 */; +count(*) +1 +drop table t4; +delete from t1; +delete from t2; +delete from t3; +insert into t2 values (1); +insert into t3 values (1,1); +create trigger trg_del before delete on t2 for each row +insert into t3 values (bug27417(1), 2); +reset master; +delete from t2; +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 350 +select count(*) from t1 /* must be 1 */; +count(*) +1 +drop trigger trg_del; +delete from t1; +delete from t2; +delete from t5; +create trigger trg_del_t2 after delete on t2 for each row +insert into t1 values (1); +insert into t2 values (2),(3); +insert into t5 values (1),(2); +reset master; +delete t2.* from t2,t5 where t2.a=t5.a + 1; +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 350 +select count(*) from t1 /* must be 1 */; +count(*) +1 +delete from t1; +create table t4 (a int default 0, b int primary key) engine=innodb; +insert into t4 values (0, 17); +reset master; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2); +ERROR 23000: Duplicate entry '17' for key 'PRIMARY' +select * from t4; +a b +0 17 +select count(*) from t1 /* must be 2 */; +count(*) +2 +show master status /* the offset must denote there is the query */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 508 +drop trigger trg_del_t2; +drop table t1,t2,t3,t4,t5; +drop function bug27417; +end of tests set @@session.binlog_format=statement; create temporary table tt (a int unique); create table ti (a int) engine=innodb; @@ -628,9 +854,11 @@ show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Intvar # # INSERT_ID=10 -master-bin.000001 # Begin_load_query # # ;file_id=1;block_len=12 +master-bin.000001 # User var # # @`b`=_latin1 0x3135 COLLATE latin1_swedish_ci +master-bin.000001 # Begin_load_query # # ;file_id=2;block_len=12 master-bin.000001 # Intvar # # INSERT_ID=10 -master-bin.000001 # Execute_load_query # # use `test`; load data infile '../std_data_ln/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2) ;file_id=1 +master-bin.000001 # User var # # @`b`=_latin1 0x3135 COLLATE latin1_swedish_ci +master-bin.000001 # Execute_load_query # # use `test`; load data infile '../std_data_ln/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2) ;file_id=2 master-bin.000001 # Query # # use `test`; ROLLBACK drop trigger trg_del_t2; drop table t1,t2,t3,t4,t5; diff --git a/mysql-test/suite/binlog/t/binlog_row_mix_innodb_myisam.test b/mysql-test/suite/binlog/t/binlog_row_mix_innodb_myisam.test index 3148cc50fd0..a7722075d6e 100644 --- a/mysql-test/suite/binlog/t/binlog_row_mix_innodb_myisam.test +++ b/mysql-test/suite/binlog/t/binlog_row_mix_innodb_myisam.test @@ -12,24 +12,4 @@ --enable_ps_protocol -# This piece below cannot be put into -# extra/binlog_tests/mix_innodb_myisam_binlog.test -# because the argument of --start-position differs between statement- -# and row-based (and "eval --exec" doesn't work). -# we check that the error code of the "ROLLBACK" event is 0 and not -# ER_SERVER_SHUTDOWN (i.e. disconnection just rolls back transaction -# and does not make slave to stop) -flush logs; ---exec $MYSQL_BINLOG --start-position=524 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output ---replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR -eval select -(@a:=load_file("$MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output")) -is not null; - ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR -eval select -@a like "%#%error_code=0%ROLLBACK/*!*/;%ROLLBACK /* added by mysqlbinlog */;%", -@a not like "%#%error_code=%error_code=%"; -drop table t1, t2; - -- source extra/binlog_tests/mix_innodb_myisam_side_effects.test diff --git a/mysql-test/suite/binlog/t/binlog_stm_mix_innodb_myisam.test b/mysql-test/suite/binlog/t/binlog_stm_mix_innodb_myisam.test index b13d3175441..f6f69fcfaf2 100644 --- a/mysql-test/suite/binlog/t/binlog_stm_mix_innodb_myisam.test +++ b/mysql-test/suite/binlog/t/binlog_stm_mix_innodb_myisam.test @@ -4,26 +4,6 @@ -- source include/have_binlog_format_mixed_or_statement.inc -- source extra/binlog_tests/mix_innodb_myisam_binlog.test -# This piece below cannot be put into -# extra/binlog_tests/mix_innodb_myisam_binlog.test -# because the argument of --start-position differs between statement- -# and row-based (and "eval --exec" doesn't work). -# we check that the error code of the "ROLLBACK" event is 0 and not -# ER_SERVER_SHUTDOWN (i.e. disconnection just rolls back transaction -# and does not make slave to stop) -flush logs; ---exec $MYSQL_BINLOG --start-position=555 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output ---replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR -eval select -(@a:=load_file("$MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output")) -is not null; ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR -eval select -@a like "%#%error_code=0%ROLLBACK\\n/*!*/;%ROLLBACK /* added by mysqlbinlog */;%", -@a not like "%#%error_code=%error_code=%"; - -drop table t1, t2; - set @@session.binlog_format=statement; -- source extra/binlog_tests/mix_innodb_myisam_side_effects.test set @@session.binlog_format=@@global.binlog_format;