diff options
author | He Zhenxing <zhenxing.he@sun.com> | 2009-03-27 13:19:50 +0800 |
---|---|---|
committer | He Zhenxing <zhenxing.he@sun.com> | 2009-03-27 13:19:50 +0800 |
commit | 51a91166387760546d563ebf72bfa037fcff24a8 (patch) | |
tree | c64191bf0f499c4e0d6b020460f019c04f7dc2e8 /mysql-test | |
parent | f606cfeae3f934b4e6864693994ed80b7f2631ef (diff) | |
download | mariadb-git-51a91166387760546d563ebf72bfa037fcff24a8.tar.gz |
BUG#37145 Killing a statement doing DDL may log binlog event with error code 1053
When the thread executing a DDL was killed after finished its
execution but before writing the binlog event, the error code in
the binlog event could be set wrongly to ER_SERVER_SHUTDOWN or
ER_QUERY_INTERRUPTED.
This patch fixed the problem by ignoring the kill status when
constructing the event for DDL statements.
This patch also included the following changes in order to
provide the test case.
1) modified mysqltest to support variable for connection command
2) modified mysql-test-run.pl, add new variable MYSQL_SLAVE to
run mysql client against the slave mysqld.
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/include/diff_master_slave.inc | 21 | ||||
-rw-r--r-- | mysql-test/include/kill_query.inc | 68 | ||||
-rw-r--r-- | mysql-test/include/kill_query_and_diff_master_slave.inc | 43 | ||||
-rwxr-xr-x | mysql-test/mysql-test-run.pl | 14 | ||||
-rw-r--r-- | mysql-test/r/rpl_killed_ddl.result | 146 | ||||
-rw-r--r-- | mysql-test/t/rpl_killed_ddl-master.opt | 1 | ||||
-rw-r--r-- | mysql-test/t/rpl_killed_ddl.test | 271 |
7 files changed, 563 insertions, 1 deletions
diff --git a/mysql-test/include/diff_master_slave.inc b/mysql-test/include/diff_master_slave.inc new file mode 100644 index 00000000000..b6d79190671 --- /dev/null +++ b/mysql-test/include/diff_master_slave.inc @@ -0,0 +1,21 @@ +# ==== Purpose ==== +# +# Diff the output of a statement on master and slave +# +# ==== Usage ===== +# +# let $diff_statement= SELECT * FROM t1 WHERE a < 100; +# source include/diff_master_slave.inc; + +--echo source include/diff_master_slave.inc; +disable_query_log; +disable_result_log; + +exec $MYSQL test -e "$diff_statement" > $MYSQLTEST_VARDIR/tmp/diff_master.out; +sync_slave_with_master; +exec $MYSQL_SLAVE test -e "$diff_statement" > $MYSQLTEST_VARDIR/tmp/diff_slave.out; + +diff_files $MYSQLTEST_VARDIR/tmp/diff_master.out $MYSQLTEST_VARDIR/tmp/diff_slave.out; + +enable_result_log; +enable_query_log; diff --git a/mysql-test/include/kill_query.inc b/mysql-test/include/kill_query.inc new file mode 100644 index 00000000000..341c3b93535 --- /dev/null +++ b/mysql-test/include/kill_query.inc @@ -0,0 +1,68 @@ +# ==== Purpose ==== +# +# Kill a query in the master connection, and then try to reap the +# result of the killed query. +# +# ==== Usage ==== +# +# The following variables should be set before sourcing this file. +# +# $debug_lock: name of the debug user lock, if set, will release/lock +# the specified debug lock accordingly, and before +# sourcing this, connection 'master' should get the user +# lock and run a query in another thread, which will +# block before creating statement event. +# +# $connection_name: name of the connection that is waiting for the +# lock, this can not be 'master' +# +# $connection_id: id of the connection that is waiting for the lock +# +# Example: +# let $debug_lock=; +# connection master1; +# let $connection_name= master1; +# let $connection_id= `SELECT CONNECTION_ID()`; +# send CREATE TABLE t1; +# source kill_query.inc; +# +# let $debug_lock= "debug_lock.before_query_log_event"; +# connection master; +# eval SELECT GET_LOCK($debug_lock, 10); +# connection master1; +# let $connection_name= master1; +# let $connection_id= `SELECT CONNECTION_ID()`; +# send CREATE TABLE t1; +# source kill_query.inc; + + +--echo source include/kill_query.inc; +disable_query_log; +disable_result_log; +connection master; + +# kill the query that is waiting +eval kill query $connection_id; + +if (`SELECT '$debug_lock' != ''`) +{ + # release the lock to allow binlog continue + eval SELECT RELEASE_LOCK($debug_lock); +} + +# reap the result of the waiting query +connection $connection_name; +error 0, 1317, 1307, 1306, 1334, 1305; +reap; + +connection master; + +if (`SELECT '$debug_lock' != ''`) +{ + # get lock again to make the next query wait + eval SELECT GET_LOCK($debug_lock, 10); +} + +connection $connection_name; +enable_query_log; +enable_result_log; diff --git a/mysql-test/include/kill_query_and_diff_master_slave.inc b/mysql-test/include/kill_query_and_diff_master_slave.inc new file mode 100644 index 00000000000..611d6929c99 --- /dev/null +++ b/mysql-test/include/kill_query_and_diff_master_slave.inc @@ -0,0 +1,43 @@ +# ==== Purpose ==== +# +# Kill a query, sync master with slave, and diff the output of a +# statement on master and slave to check if statement is correctly +# replicated. +# +# ==== Usage ==== +# +# connection <CONNECTION>; +# let $connection_name=<CONNECTION> +# let $connection_id=`SELECT CONNECTION_ID()`; +# let $diff_statement=<SQL COMMAND>; +# send <SQL COMMAND>; +# source include/kill_query_and_diff_master_slave.inc; +# +# Note: <CONNECTION> must not be 'master'. +# +# See also kill_query.inc and diff_master_slave.inc for more +# information + +source include/kill_query.inc; + +# Release the debug lock if used, so that the statements in +# diff_master_slave.inc will not be blocked. +connection master; +disable_query_log; +disable_result_log; +if (`SELECT '$debug_lock' != ''`) +{ + eval SELECT RELEASE_LOCK($debug_lock); +} +enable_result_log; +enable_query_log; + +source include/diff_master_slave.inc; + +# Acquire the debug lock again if used +connection master; +disable_query_log; disable_result_log; if (`SELECT '$debug_lock' != +''`) { eval SELECT GET_LOCK($debug_lock, 10); } enable_result_log; +enable_query_log; + +connection $connection_name; diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 0948c973e9b..ffa9b4cb1d3 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -2063,7 +2063,7 @@ sub environment_setup () { $ENV{'MYSQL_BINLOG'}= $cmdline_mysqlbinlog; # ---------------------------------------------------- - # Setup env so childs can execute mysql + # Setup env so childs can execute mysql against master # ---------------------------------------------------- my $cmdline_mysql= mtr_native_path($exe_mysql) . @@ -2075,6 +2075,18 @@ sub environment_setup () { $ENV{'MYSQL'}= $cmdline_mysql; # ---------------------------------------------------- + # Setup env so childs can execute mysql against slave + # ---------------------------------------------------- + my $cmdline_mysql_slave= + mtr_native_path($exe_mysql) . + " --no-defaults --host=localhost --user=root --password= " . + "--port=$slave->[0]->{'port'} " . + "--socket=$slave->[0]->{'path_sock'} ". + "--character-sets-dir=$path_charsetsdir"; + + $ENV{'MYSQL_SLAVE'}= $cmdline_mysql_slave; + + # ---------------------------------------------------- # Setup env so childs can execute bug25714 # ---------------------------------------------------- $ENV{'MYSQL_BUG25714'}= $exe_bug25714; diff --git a/mysql-test/r/rpl_killed_ddl.result b/mysql-test/r/rpl_killed_ddl.result new file mode 100644 index 00000000000..aa419a8556e --- /dev/null +++ b/mysql-test/r/rpl_killed_ddl.result @@ -0,0 +1,146 @@ +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 DATABASE IF EXISTS d1; +DROP DATABASE IF EXISTS d2; +DROP DATABASE IF EXISTS d3; +DROP DATABASE IF EXISTS d4; +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t3; +DROP TABLE IF EXISTS t4; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; +DROP PROCEDURE IF EXISTS p4; +DROP TRIGGER IF EXISTS tr1; +DROP TRIGGER IF EXISTS tr2; +DROP TRIGGER IF EXISTS tr3; +DROP TRIGGER IF EXISTS tr4; +CREATE DATABASE d1; +CREATE FUNCTION f1 () RETURNS INT DETERMINISTIC +RETURN 1; +CREATE PROCEDURE p1 (OUT rows INT) +BEGIN +SELECT COUNT(*) INTO rows FROM t1; +END; +// +CREATE TABLE t1 (a int); +CREATE TABLE t3 (a int); +CREATE TRIGGER tr1 BEFORE INSERT ON t1 +FOR EACH ROW BEGIN +DELETE FROM t4 WHERE a=NEW.a; +END; +// +CREATE INDEX i1 ON t1 (a); +CREATE VIEW v1 AS SELECT a FROM t1 WHERE a < 100; +[on master] +[on master1] +CREATE DATABASE d2; +source include/kill_query.inc; +source include/diff_master_slave.inc; +ALTER DATABASE d1 +DEFAULT CHARACTER SET = 'utf8'; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP DATABASE d1; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP DATABASE d2; +source include/kill_query.inc; +source include/diff_master_slave.inc; +CREATE FUNCTION f2 () RETURNS INT DETERMINISTIC +RETURN 1; +source include/kill_query.inc; +source include/diff_master_slave.inc; +ALTER FUNCTION f1 SQL SECURITY INVOKER; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP FUNCTION IF EXISTS f1; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP FUNCTION IF EXISTS f2; +source include/kill_query.inc; +source include/diff_master_slave.inc; +CREATE PROCEDURE p2 (OUT rows INT) +BEGIN +SELECT COUNT(*) INTO rows FROM t2; +END; +// +source include/kill_query.inc; +source include/diff_master_slave.inc; +ALTER PROCEDURE p1 SQL SECURITY INVOKER COMMENT 'return rows of table t1'; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP PROCEDURE IF EXISTS p1; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP PROCEDURE IF EXISTS p2; +source include/kill_query.inc; +source include/diff_master_slave.inc; +CREATE TABLE t2 (b int); +source include/kill_query.inc; +source include/diff_master_slave.inc; +ALTER TABLE t1 ADD (d int); +source include/kill_query.inc; +source include/diff_master_slave.inc; +RENAME TABLE t3 TO t4; +source include/kill_query.inc; +source include/diff_master_slave.inc; +CREATE INDEX i2 on t1 (a); +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP INDEX i1 on t1; +source include/kill_query.inc; +source include/diff_master_slave.inc; +CREATE TRIGGER tr2 BEFORE INSERT ON t4 +FOR EACH ROW BEGIN +DELETE FROM t1 WHERE a=NEW.a; +END; +// +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP TRIGGER tr1; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP TRIGGER IF EXISTS tr2; +source include/kill_query.inc; +source include/diff_master_slave.inc; +CREATE VIEW v2 AS SELECT a FROM t1 WHERE a > 100; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP VIEW v1; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP VIEW IF EXISTS v2; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP TABLE t1; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP TABLE IF EXISTS t2; +source include/kill_query.inc; +source include/diff_master_slave.inc; +DROP DATABASE IF EXISTS d1; +DROP DATABASE IF EXISTS d2; +DROP DATABASE IF EXISTS d3; +DROP DATABASE IF EXISTS d4; +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t3; +DROP TABLE IF EXISTS t4; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; +DROP PROCEDURE IF EXISTS p4; diff --git a/mysql-test/t/rpl_killed_ddl-master.opt b/mysql-test/t/rpl_killed_ddl-master.opt new file mode 100644 index 00000000000..aaf2d8a4251 --- /dev/null +++ b/mysql-test/t/rpl_killed_ddl-master.opt @@ -0,0 +1 @@ +--debug=d,debug_lock_before_query_log_event diff --git a/mysql-test/t/rpl_killed_ddl.test b/mysql-test/t/rpl_killed_ddl.test new file mode 100644 index 00000000000..f4f2f6ac320 --- /dev/null +++ b/mysql-test/t/rpl_killed_ddl.test @@ -0,0 +1,271 @@ +# ==== Purpose ==== +# +# This test check if DDL statements are correctly binlogged when the +# thread is killed +# +# ==== Method ==== +# +# Start a DDL query and kill it, check if the error code of the binlog +# event is correct. +# +# DDL statements tested: +# CREATE/ALTER/RENAME/DROP DATABASE +# CREATE/ALTER/DROP FUNCTION +# CREATE/ALTER/DROP PROCEDURE +# CREATE/ALTER/RENAME/DROP TABLE +# CREATE/DROP TRIGGER +# CREATE/ALTER/DROP VIEW +# +# ==== Bugs ===== +# + +source include/have_debug.inc; +source include/master-slave.inc; + +# Use the DBUG_SYNC_POINT to make sure the thread running the DDL is +# waiting before creating the query log event + +let $debug_lock= "debug_lock.before_query_log_event"; + +######## INITIALIZATION ######## + +disable_warnings; +DROP DATABASE IF EXISTS d1; +DROP DATABASE IF EXISTS d2; +DROP DATABASE IF EXISTS d3; +DROP DATABASE IF EXISTS d4; +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t3; +DROP TABLE IF EXISTS t4; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; +DROP PROCEDURE IF EXISTS p4; +DROP TRIGGER IF EXISTS tr1; +DROP TRIGGER IF EXISTS tr2; +DROP TRIGGER IF EXISTS tr3; +DROP TRIGGER IF EXISTS tr4; +enable_warnings; + +CREATE DATABASE d1; + +CREATE FUNCTION f1 () RETURNS INT DETERMINISTIC + RETURN 1; + +DELIMITER //; +CREATE PROCEDURE p1 (OUT rows INT) + BEGIN + SELECT COUNT(*) INTO rows FROM t1; + END; + // +DELIMITER ;// + +CREATE TABLE t1 (a int); +CREATE TABLE t3 (a int); + +DELIMITER //; +CREATE TRIGGER tr1 BEFORE INSERT ON t1 + FOR EACH ROW BEGIN + DELETE FROM t4 WHERE a=NEW.a; + END; + // +DELIMITER ;// + +CREATE INDEX i1 ON t1 (a); + +CREATE VIEW v1 AS SELECT a FROM t1 WHERE a < 100; + +sync_slave_with_master; + +connection master1; +let $connection_name= master1; +let $connection_id= `SELECT CONNECTION_ID()`; + +connection master; +echo [on master]; + +# This will block the execution of a statement at the DBUG_SYNC_POINT +# with given lock name +if (`SELECT '$debug_lock' != ''`) +{ + disable_query_log; + disable_result_log; + eval SELECT IS_FREE_LOCK($debug_lock); + eval SELECT GET_LOCK($debug_lock, 10); + eval SELECT IS_FREE_LOCK($debug_lock); + enable_query_log; + enable_result_log; +} + +######## START TEST ######## + +connection master1; +echo [on master1]; + +disable_warnings; + +######## DATABASE ######## + +let $diff_statement= SHOW DATABASES LIKE 'd%'; + +send CREATE DATABASE d2; +source include/kill_query_and_diff_master_slave.inc; + +send ALTER DATABASE d1 + DEFAULT CHARACTER SET = 'utf8'; +source include/kill_query_and_diff_master_slave.inc; + +send DROP DATABASE d1; +source include/kill_query_and_diff_master_slave.inc; + +send DROP DATABASE d2; +source include/kill_query_and_diff_master_slave.inc; + +######## FUNCTION ######## + +let $diff_statement= SHOW FUNCTION STATUS LIKE 'f%'; + +send CREATE FUNCTION f2 () RETURNS INT DETERMINISTIC + RETURN 1; +source include/kill_query_and_diff_master_slave.inc; + +send ALTER FUNCTION f1 SQL SECURITY INVOKER; +source include/kill_query_and_diff_master_slave.inc; + +# function f1 probably does not exist because the ALTER query was +# killed +send DROP FUNCTION IF EXISTS f1; +source include/kill_query_and_diff_master_slave.inc; + +# function f2 probably does not exist because the CREATE query was +# killed +send DROP FUNCTION IF EXISTS f2; +source include/kill_query_and_diff_master_slave.inc; + +######## PROCEDURE ######## + +let $diff_statement= SHOW PROCEDURE STATUS LIKE 'p%'; + +DELIMITER //; +send CREATE PROCEDURE p2 (OUT rows INT) + BEGIN + SELECT COUNT(*) INTO rows FROM t2; + END; + // +DELIMITER ;// +source include/kill_query_and_diff_master_slave.inc; + +send ALTER PROCEDURE p1 SQL SECURITY INVOKER COMMENT 'return rows of table t1'; +source include/kill_query_and_diff_master_slave.inc; + +send DROP PROCEDURE IF EXISTS p1; +source include/kill_query_and_diff_master_slave.inc; + +send DROP PROCEDURE IF EXISTS p2; +source include/kill_query_and_diff_master_slave.inc; + +######## TABLE ######## + +let $diff_statement= SHOW TABLES LIKE 't%'; + +send CREATE TABLE t2 (b int); +source include/kill_query_and_diff_master_slave.inc; + +send ALTER TABLE t1 ADD (d int); +source include/kill_query_and_diff_master_slave.inc; + +send RENAME TABLE t3 TO t4; +source include/kill_query_and_diff_master_slave.inc; + +######## INDEX ######## + +let $diff_statement= SHOW INDEX FROM t1; + +send CREATE INDEX i2 on t1 (a); +source include/kill_query_and_diff_master_slave.inc; + +send DROP INDEX i1 on t1; +source include/kill_query_and_diff_master_slave.inc; + +######## TRIGGER ######## + +let $diff_statement= SHOW TRIGGERS LIKE 'v%'; + +DELIMITER //; +send CREATE TRIGGER tr2 BEFORE INSERT ON t4 + FOR EACH ROW BEGIN + DELETE FROM t1 WHERE a=NEW.a; + END; + // +DELIMITER ;// +source include/kill_query_and_diff_master_slave.inc; + +send DROP TRIGGER tr1; +source include/kill_query_and_diff_master_slave.inc; + +send DROP TRIGGER IF EXISTS tr2; +source include/kill_query_and_diff_master_slave.inc; + +######## VIEW ######## + +let $diff_statement= SHOW TABLES LIKE 'v%'; + +send CREATE VIEW v2 AS SELECT a FROM t1 WHERE a > 100; +source include/kill_query_and_diff_master_slave.inc; + +send DROP VIEW v1; +source include/kill_query_and_diff_master_slave.inc; + +send DROP VIEW IF EXISTS v2; +source include/kill_query_and_diff_master_slave.inc; + +######## DROP TABLE ######## + +# Because of BUG#43529, we cannot use the DBUG_SYNC_POINT for DROP +# TABLE statements on 5.0 +connection master; +disable_query_log; +disable_result_log; +eval SELECT RELEASE_LOCK($debug_lock); +enable_result_log; +enable_query_log; +let $debug_lock=; + +connection master1; + +let $diff_statement= SHOW TABLES LIKE 't%'; + +send DROP TABLE t1; +source include/kill_query_and_diff_master_slave.inc; + +send DROP TABLE IF EXISTS t2; +source include/kill_query_and_diff_master_slave.inc; + +######## CLEAN UP ######## + +# The DROP statements above are killed during the process, so they +# does not make sure the objects are dropped. + +disable_warnings; +DROP DATABASE IF EXISTS d1; +DROP DATABASE IF EXISTS d2; +DROP DATABASE IF EXISTS d3; +DROP DATABASE IF EXISTS d4; +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t3; +DROP TABLE IF EXISTS t4; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; +DROP PROCEDURE IF EXISTS p4; +enable_warnings; |