diff --git a/mysql-test/r/view_multi.result b/mysql-test/r/view_multi.result deleted file mode 100644 index 95a8d572be4..00000000000 --- a/mysql-test/r/view_multi.result +++ /dev/null @@ -1,48 +0,0 @@ -reset master; -create table t1 (i int); -create table t2 (i int); -create view v1 as select * from t1; -select get_lock("lock_bg25144", 1); -get_lock("lock_bg25144", 1) -1 -insert into v1 values (get_lock("lock_bg25144", 100));; -drop view v1;; -select release_lock("lock_bg25144"); -release_lock("lock_bg25144") -1 -select release_lock("lock_bg25144"); -release_lock("lock_bg25144") -1 -select * from t1; -i -1 -create view v1 as select * from t1; -select get_lock("lock_bg25144", 1); -get_lock("lock_bg25144", 1) -1 -insert into v1 values (get_lock("lock_bg25144", 100));; -alter view v1 as select * from t2;; -select release_lock("lock_bg25144"); -release_lock("lock_bg25144") -1 -select release_lock("lock_bg25144"); -release_lock("lock_bg25144") -1 -select * from t1; -i -1 -1 -select * from t2; -i -show binlog events in 'master-bin.000001' from 107; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query 1 # use `test`; create table t1 (i int) -master-bin.000001 # Query 1 # use `test`; create table t2 (i int) -master-bin.000001 # Query 1 # use `test`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select * from t1 -master-bin.000001 # Query 1 # use `test`; insert into v1 values (get_lock("lock_bg25144", 100)) -master-bin.000001 # Query 1 # use `test`; drop view v1 -master-bin.000001 # Query 1 # use `test`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select * from t1 -master-bin.000001 # Query 1 # use `test`; insert into v1 values (get_lock("lock_bg25144", 100)) -master-bin.000001 # Query 1 # use `test`; ALTER ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select * from t2 -drop table t1, t2; -drop view v1; diff --git a/mysql-test/suite/rpl/r/rpl_view_multi.result b/mysql-test/suite/rpl/r/rpl_view_multi.result new file mode 100644 index 00000000000..b3f10584a24 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_view_multi.result @@ -0,0 +1,90 @@ +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; +# +# Bug #25144 "replication / binlog with view breaks". +# Statements that used views didn't ensure that view were not modified +# during their execution. Indeed this led to incorrect binary log with +# statement based logging and as result to broken replication. +# +drop tables if exists t1, t2; +drop view if exists v1; +# Syncing slave with master and switching to connection 'slave' +# Switching to connection 'master' +create table t1 (i int); +create table t2 (i int); +create view v1 as select * from t1; +# First we try to concurrently execute statement that uses view +# and statement that drops it. We use "user" locks as means to +# suspend execution of first statement once it opens our view. +select get_lock("lock_bg25144", 1); +get_lock("lock_bg25144", 1) +1 +# Switching to connection 'master1' +insert into v1 values (get_lock("lock_bg25144", 100)); +# Switching to connection 'master2' +drop view v1; +# Switching to connection 'master' +select release_lock("lock_bg25144"); +release_lock("lock_bg25144") +1 +# Switching to connection 'master1' +select release_lock("lock_bg25144"); +release_lock("lock_bg25144") +1 +# Switching to connection 'master2' +# Switching to connection 'master' +# Check that insertion through view did happen. +select * from t1; +i +1 +# Syncing slave with master and switching to connection 'slave' +# Check that slave was able to replicate this sequence +# which means that we got correct binlog order. +select * from t1; +i +1 +# Switching to connection 'master' +# Now we will repeat the test by trying concurrently execute +# statement that uses a view and statement that alters it. +create view v1 as select * from t1; +select get_lock("lock_bg25144", 1); +get_lock("lock_bg25144", 1) +1 +# Switching to connection 'master1' +insert into v1 values (get_lock("lock_bg25144", 100)); +# Switching to connection 'master2' +alter view v1 as select * from t2; +# Switching to connection 'master' +select release_lock("lock_bg25144"); +release_lock("lock_bg25144") +1 +# Switching to connection 'master1' +select release_lock("lock_bg25144"); +release_lock("lock_bg25144") +1 +# Switching to connection 'master2' +# Switching to connection 'master' +# Second insertion should go to t1 as well. +select * from t1; +i +1 +1 +select * from t2; +i +# Syncing slave with master and switching to connection 'slave' +# Now let us check that statements were logged in proper order +# So we have same result on slave. +select * from t1; +i +1 +1 +select * from t2; +i +# Switching to connection 'master' +drop table t1, t2; +drop view v1; +# Syncing slave with master and switching to connection 'slave' diff --git a/mysql-test/suite/rpl/t/rpl_view_multi.test b/mysql-test/suite/rpl/t/rpl_view_multi.test new file mode 100644 index 00000000000..777ccb2a945 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_view_multi.test @@ -0,0 +1,134 @@ +# +# This file contains test cases for bugs which involve views, several +# concurren connections and manifest themselves as wrong binary log +# sequence which results in broken replication. In principle we are +# mostly interested in SBR here but this test will also work with RBR. +# +--source include/master-slave.inc + +--echo # +--echo # Bug #25144 "replication / binlog with view breaks". +--echo # Statements that used views didn't ensure that view were not modified +--echo # during their execution. Indeed this led to incorrect binary log with +--echo # statement based logging and as result to broken replication. +--echo # + +--disable_warnings +drop tables if exists t1, t2; +drop view if exists v1; +--enable_warnings +--echo # Syncing slave with master and switching to connection 'slave' +--sync_slave_with_master + +connect (master2,127.0.0.1,root,,test,$MASTER_MYPORT,); + +--echo # Switching to connection 'master' +connection master; +create table t1 (i int); +create table t2 (i int); +create view v1 as select * from t1; + +--echo # First we try to concurrently execute statement that uses view +--echo # and statement that drops it. We use "user" locks as means to +--echo # suspend execution of first statement once it opens our view. +select get_lock("lock_bg25144", 1); + +--echo # Switching to connection 'master1' +connection master1; +--send insert into v1 values (get_lock("lock_bg25144", 100)) + +--echo # Switching to connection 'master2' +connection master2; +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "User lock" and info like "insert into v1 %lock_bg25144%"; +--source include/wait_condition.inc +--send drop view v1 + +--echo # Switching to connection 'master' +connection master; +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Waiting for table" and info = "drop view v1"; +--source include/wait_condition.inc + +select release_lock("lock_bg25144"); + +--echo # Switching to connection 'master1' +connection master1; +--reap +select release_lock("lock_bg25144"); + +--echo # Switching to connection 'master2' +connection master2; +--reap + +--echo # Switching to connection 'master' +connection master; +--echo # Check that insertion through view did happen. +select * from t1; +--echo # Syncing slave with master and switching to connection 'slave' +--sync_slave_with_master +--echo # Check that slave was able to replicate this sequence +--echo # which means that we got correct binlog order. +select * from t1; + +--echo # Switching to connection 'master' +connection master; +--echo # Now we will repeat the test by trying concurrently execute +--echo # statement that uses a view and statement that alters it. +create view v1 as select * from t1; + +select get_lock("lock_bg25144", 1); + +--echo # Switching to connection 'master1' +connection master1; +--send insert into v1 values (get_lock("lock_bg25144", 100)) + +--echo # Switching to connection 'master2' +connection master2; +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "User lock" and info like "insert into v1 %lock_bg25144%"; +--source include/wait_condition.inc +--send alter view v1 as select * from t2 + +--echo # Switching to connection 'master' +connection master; +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Waiting for table" and + info = "alter view v1 as select * from t2"; +--source include/wait_condition.inc + +select release_lock("lock_bg25144"); + +--echo # Switching to connection 'master1' +connection master1; +--reap +select release_lock("lock_bg25144"); + +--echo # Switching to connection 'master2' +connection master2; +--reap + +--echo # Switching to connection 'master' +connection master; + +--echo # Second insertion should go to t1 as well. +select * from t1; +select * from t2; + +--echo # Syncing slave with master and switching to connection 'slave' +--sync_slave_with_master +--echo # Now let us check that statements were logged in proper order +--echo # So we have same result on slave. +select * from t1; +select * from t2; + +--echo # Switching to connection 'master' +connection master; +drop table t1, t2; +drop view v1; +--echo # Syncing slave with master and switching to connection 'slave' +--sync_slave_with_master diff --git a/mysql-test/t/view_multi.test b/mysql-test/t/view_multi.test deleted file mode 100644 index a61e7738095..00000000000 --- a/mysql-test/t/view_multi.test +++ /dev/null @@ -1,110 +0,0 @@ -# -# QQ: Should we find a better place for this test? -# May be binlog or rpl suites ? -# ---source include/have_log_bin.inc ---source include/have_binlog_format_mixed_or_statement.inc - -# -# Bug #25144 "replication / binlog with view breaks". -# Statements that used views didn't ensure that view were not modified -# during their execution. Indeed this led to incorrect binary log with -# statement based logging. -# ---disable_parsing -drop table if not exists t1, t2; -drop view if exists v1; ---enable_parsing - -# We are going to use binary log later to check that statements are -# logged in proper order, so it is good idea to reset it here. -reset master; - -connect (addconn1,localhost,root,,); -connect (addconn2,localhost,root,,); -connection default; - -create table t1 (i int); -create table t2 (i int); -create view v1 as select * from t1; - -# First we try to concurrently execute statement that uses view -# and statement that drops it. We use "user" locks as means to -# suspend execution of first statement once it opens our view. -select get_lock("lock_bg25144", 1); - -connection addconn1; ---send insert into v1 values (get_lock("lock_bg25144", 100)); - -connection addconn2; -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "User lock" and info like "insert into v1 %lock_bg25144%"; ---source include/wait_condition.inc ---send drop view v1; - -connection default; -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "Waiting for table" and info = "drop view v1"; ---source include/wait_condition.inc - -select release_lock("lock_bg25144"); - -connection addconn1; ---reap -select release_lock("lock_bg25144"); - -connection addconn2; ---reap - -connection default; -# Check that insertion through view did happen. -select * from t1; -# At the end of test we will check that statements were -# logged in proper order. - -# Now we will repeat the test by trying concurrently execute -# statement that uses a view and statement that alters it. -create view v1 as select * from t1; - -select get_lock("lock_bg25144", 1); - -connection addconn1; ---send insert into v1 values (get_lock("lock_bg25144", 100)); - -connection addconn2; -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "User lock" and info like "insert into v1 %lock_bg25144%"; ---source include/wait_condition.inc ---send alter view v1 as select * from t2; - -connection default; -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "Waiting for table" and - info = "alter view v1 as select * from t2"; ---source include/wait_condition.inc - -select release_lock("lock_bg25144"); - -connection addconn1; ---reap -select release_lock("lock_bg25144"); - -connection addconn2; ---reap - -connection default; - -# Second insertion should go to t1 as well. -select * from t1; -select * from t2; - -# Now let us check that statements were logged in proper order ---replace_column 2 # 5 # -show binlog events in 'master-bin.000001' from 107; - -drop table t1, t2; -drop view v1;