Skip to content
Permalink
Browse files
Galera MTR Tests: Tests for MW-328 Fix unnecessary/silent BF aborts
  • Loading branch information
philip-galera authored and SachinSetiya committed Mar 14, 2017
1 parent dd2f023 commit 69b5bd7
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 0 deletions.
@@ -0,0 +1,21 @@
CREATE TABLE t1 (f1 INTEGER AUTO_INCREMENT PRIMARY KEY, f2 CHAR(20) DEFAULT 'abc') ENGINE=InnoDB;
INSERT INTO t1 (f1) VALUES (1);
CREATE TABLE t2 (f1 CHAR(20)) ENGINE=InnoDB;
CREATE PROCEDURE proc_update ()
BEGIN
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END;
SET SESSION wsrep_sync_wait = 0;
WHILE 1 DO
UPDATE t1 SET f2 = LEFT(MD5(RAND()), 4);
END WHILE;
END|
CALL proc_update();;
SET SESSION wsrep_retry_autocommit = 0;
have_successes
1
have_deadlocks
1
Got one of the listed errors
DROP PROCEDURE proc_update;
DROP TABLE t1, t2;
CALL mtr.add_suppression("conflict state 3 after post commit");
@@ -0,0 +1,17 @@
CREATE TABLE t1 (f1 INTEGER AUTO_INCREMENT PRIMARY KEY, f2 CHAR(20) DEFAULT 'abc') ENGINE=InnoDB;
INSERT INTO t1 (f1) VALUES (1);
CREATE TABLE t2 (f1 CHAR(20)) ENGINE=InnoDB;
CREATE PROCEDURE proc_update ()
BEGIN
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END;
SET SESSION wsrep_sync_wait = 0;
WHILE 1 DO
UPDATE t1 SET f2 = LEFT(MD5(RAND()), 4);
END WHILE;
END|
CALL proc_update();;
SET SESSION wsrep_retry_autocommit = 0;
Got one of the listed errors
DROP PROCEDURE proc_update;
DROP TABLE t1, t2;
CALL mtr.add_suppression("conflict state 3 after post commit");
@@ -0,0 +1,17 @@
CREATE TABLE t1 (f1 INTEGER AUTO_INCREMENT PRIMARY KEY, f2 CHAR(20) DEFAULT 'abc') ENGINE=InnoDB;
INSERT INTO t1 (f1) VALUES (1);
CREATE TABLE t2 (f1 CHAR(20)) ENGINE=InnoDB;
CREATE PROCEDURE proc_update ()
BEGIN
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END;
SET SESSION wsrep_sync_wait = 0;
WHILE 1 DO
UPDATE t1 SET f2 = LEFT(MD5(RAND()), 4);
END WHILE;
END|
CALL proc_update();;
SET SESSION wsrep_retry_autocommit = 10000;
Got one of the listed errors
DROP PROCEDURE proc_update;
DROP TABLE t1, t2;
CALL mtr.add_suppression("conflict state 3 after post commit");
@@ -0,0 +1,15 @@
CREATE TABLE t1 (i INT) ENGINE = InnoDB;
INSERT INTO t1 (i) VALUES(1);
CREATE TABLE t2 (i INT) ENGINE = InnoDB;
SET AUTOCOMMIT=OFF;
START TRANSACTION;
SELECT * FROM t1 WHERE i = 1 LOCK IN SHARE MODE;
i
1
SET AUTOCOMMIT=OFF;
START TRANSACTION;
INSERT IGNORE INTO t2 SELECT * FROM t1 WHERE i = 1 FOR UPDATE;;
DELETE FROM t1 WHERE i = 1;
COMMIT;
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
DROP TABLE t1, t2;
@@ -0,0 +1,15 @@
create table t1 (i int primary key, j int) engine=innodb;
create table t2 (i int primary key, j int) engine=innodb;
insert into t1 values (1,0);
insert into t2 values (2,0);
set autocommit=off;
start transaction;
update t1 set j=1 where i=1;
set autocommit=off;
start transaction;
begin;
update t2 set j=1 where i=2;
insert into t1 select * from t2;;
insert into t2 select * from t1;
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
DROP TABLE t1, t2;
@@ -0,0 +1,18 @@
#
# Cleanup for MW-328 tests
#

--connection node_1
--disable_query_log
--eval KILL CONNECTION $sp_connection_id
--enable_query_log

--connection node_1X
--error 2013,1317
--reap

--connection node_1
DROP PROCEDURE proc_update;
DROP TABLE t1, t2;

CALL mtr.add_suppression("conflict state 3 after post commit");
@@ -0,0 +1,29 @@
#
# Initialization for MW-328 tests
#

CREATE TABLE t1 (f1 INTEGER AUTO_INCREMENT PRIMARY KEY, f2 CHAR(20) DEFAULT 'abc') ENGINE=InnoDB;
INSERT INTO t1 (f1) VALUES (1);

CREATE TABLE t2 (f1 CHAR(20)) ENGINE=InnoDB;

#
# Have some random updates going on against t1
#

DELIMITER |;
CREATE PROCEDURE proc_update ()
BEGIN
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END;
SET SESSION wsrep_sync_wait = 0;
WHILE 1 DO
UPDATE t1 SET f2 = LEFT(MD5(RAND()), 4);
END WHILE;
END|

DELIMITER ;|

--connect node_1X, 127.0.0.1, root, , test, $NODE_MYPORT_1
--connection node_1X
--let $sp_connection_id = `SELECT CONNECTION_ID()`
--send CALL proc_update();
@@ -0,0 +1,55 @@
#
# MW-328 Fix unnecessary/silent BF aborts
#

#
# Attempt to insert into t2 and check if insert actually inserted rows if
# a success was reported.
#

--source include/galera_cluster.inc
--source suite/galera/t/MW-328-header.inc

--connection node_2
--let $count = 100
--let $successes = 0
--let $deadlocks = 0

SET SESSION wsrep_retry_autocommit = 0;

--disable_query_log

while ($count)
{
TRUNCATE TABLE t2;

--error 0,1213
INSERT IGNORE INTO t2 SELECT f2 FROM t1;
if ($mysql_errno != 1213) {
--inc $successes
if (`SELECT COUNT(*) = 0 FROM t2`) {
--die No rows arrived in table t2
}
}

if ($mysql_errno == 1213) {
--inc $deadlocks

}

--dec $count
}

--enable_query_log

#
# Check that the test produced both deadlocks and successes
#

--disable_query_log
--eval SELECT $successes > 0 AS have_successes
--eval SELECT $deadlocks > 0 AS have_deadlocks
--enable_query_log


--source suite/galera/t/MW-328-footer.inc
@@ -0,0 +1,35 @@
#
# MW-328 Fix unnecessary/silent BF aborts
#

#
# Make sure an unrelated SELECT following a BF-aborted query never
# gets the deadlock error
#

--source include/galera_cluster.inc
--source suite/galera/t/MW-328-header.inc

--connection node_2
--let $count = 100

SET SESSION wsrep_retry_autocommit = 0;

--disable_query_log

while ($count)
{
--error 0,1213
INSERT IGNORE INTO t2 SELECT f2 FROM t1;

--disable_result_log
--error 0
SELECT 1 FROM DUAL;
--enable_result_log

--dec $count
}

--enable_query_log

--source suite/galera/t/MW-328-footer.inc
@@ -0,0 +1,35 @@
#
# MW-328 Fix unnecessary/silent BF aborts
#

#
# Make sure that a high value of wsrep_retry_autocommit
# masks all deadlock errors
#

--source include/galera_cluster.inc
--source suite/galera/t/MW-328-header.inc

--connection node_2
--let $count = 100

SET SESSION wsrep_retry_autocommit = 10000;

--disable_query_log

while ($count)
{
--error 0
INSERT IGNORE INTO t2 SELECT f2 FROM t1;

--disable_result_log
--error 0
SELECT 1 FROM DUAL;
--enable_result_log

--dec $count
}

--enable_query_log

--source suite/galera/t/MW-328-footer.inc
@@ -0,0 +1,39 @@
#
# MW-328 Fix unnecessary/silent BF aborts
#

#
# Test that non-Galera deadlock error still behaves as expected
#

--source include/galera_cluster.inc

CREATE TABLE t1 (i INT) ENGINE = InnoDB;
INSERT INTO t1 (i) VALUES(1);

CREATE TABLE t2 (i INT) ENGINE = InnoDB;

# Create a deadlock situation

--connection node_1
SET AUTOCOMMIT=OFF;
START TRANSACTION;
SELECT * FROM t1 WHERE i = 1 LOCK IN SHARE MODE;

--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1
--connection node_1a
SET AUTOCOMMIT=OFF;
START TRANSACTION;
--send INSERT IGNORE INTO t2 SELECT * FROM t1 WHERE i = 1 FOR UPDATE;

--connection node_1
--sleep 2
DELETE FROM t1 WHERE i = 1;
COMMIT;

# We expect that ER_LOCK_DEADLOCK will be delivered even though it was a INSERT INGORE statement
--connection node_1a
--error ER_LOCK_DEADLOCK
--reap

DROP TABLE t1, t2;
@@ -0,0 +1,40 @@
#
# MW-328 Fix unnecessary/silent BF aborts
#

#
# Test that non-Galera deadlock error still behaves as expected (case #2)
#

--source include/galera_cluster.inc

create table t1 (i int primary key, j int) engine=innodb;
create table t2 (i int primary key, j int) engine=innodb;

insert into t1 values (1,0);
insert into t2 values (2,0);

set autocommit=off;
start transaction;
update t1 set j=1 where i=1;

--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1
--connection node_1a
set autocommit=off;
start transaction;
begin;
update t2 set j=1 where i=2;

--connection node_1
# Hang expected here
--send insert into t1 select * from t2;

--sleep 2
--connection node_1a
--error ER_LOCK_DEADLOCK
insert into t2 select * from t1;

--connection node_1
--reap

DROP TABLE t1, t2;

0 comments on commit 69b5bd7

Please sign in to comment.