Skip to content

Commit 483078b

Browse files
philip-galeraNirbhay Choubey
authored andcommitted
Fixes codership/QA#87 . An MTR test for SERIALIZABLE
1 parent 4102d52 commit 483078b

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CREATE TABLE t1 (id INT PRIMARY KEY, f2 INTEGER) ENGINE=InnoDB;
2+
SET AUTOCOMMIT=OFF;
3+
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
4+
START TRANSACTION;
5+
SELECT * FROM t1;
6+
id f2
7+
INSERT INTO t1 VALUES (1,1);
8+
SELECT * FROM t1;
9+
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
10+
ROLLBACK;
11+
DELETE FROM t1;
12+
INSERT INTO t1 VALUES (1,1);
13+
START TRANSACTION;
14+
SELECT * FROM t1;
15+
id f2
16+
1 1
17+
UPDATE t1 SET f2 = 2;
18+
UPDATE t1 SET f2 = 3;
19+
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
20+
ROLLBACK;
21+
DELETE FROM t1;
22+
START TRANSACTION;
23+
INSERT INTO t1 VALUES (1,1);
24+
INSERT INTO t1 VALUES (1,2);
25+
COMMIT;
26+
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
27+
DROP TABLE t1;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#
2+
# Test that the SERIALIZABLE isolation level behaves as expected.
3+
# A local serializable transaction is aborted by an incoming remote update
4+
#
5+
# wsrep_sync_wait does not work well with serializable, see mysql-wsrep#130
6+
# hence the need to use --sleep .
7+
#
8+
9+
--source include/galera_cluster.inc
10+
--source include/have_innodb.inc
11+
12+
--connection node_1
13+
14+
CREATE TABLE t1 (id INT PRIMARY KEY, f2 INTEGER) ENGINE=InnoDB;
15+
16+
#
17+
# Read (local transaction) / Write (remote transaction) conflict
18+
#
19+
20+
SET AUTOCOMMIT=OFF;
21+
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
22+
START TRANSACTION;
23+
24+
SELECT * FROM t1;
25+
26+
--connection node_2
27+
INSERT INTO t1 VALUES (1,1);
28+
29+
--sleep 2
30+
--connection node_1
31+
--error ER_LOCK_DEADLOCK
32+
SELECT * FROM t1;
33+
34+
ROLLBACK;
35+
DELETE FROM t1;
36+
37+
#
38+
# Write (local transaction) / Write (remote transaction) conflict
39+
#
40+
41+
--connection node_1
42+
INSERT INTO t1 VALUES (1,1);
43+
START TRANSACTION;
44+
SELECT * FROM t1;
45+
46+
--connection node_2
47+
UPDATE t1 SET f2 = 2;
48+
49+
--sleep 2
50+
--connection node_1
51+
--error ER_LOCK_DEADLOCK
52+
UPDATE t1 SET f2 = 3;
53+
54+
ROLLBACK;
55+
DELETE FROM t1;
56+
57+
#
58+
# Write (local transaction) / Write (remote transaction) conflict
59+
# Local transaction writes before remote one.
60+
# Nothing special happens here - ordinary deadlock on COMMIT
61+
#
62+
63+
--connection node_1
64+
START TRANSACTION;
65+
66+
--connection node_1
67+
INSERT INTO t1 VALUES (1,1);
68+
69+
--connection node_2
70+
INSERT INTO t1 VALUES (1,2);
71+
72+
--connection node_1
73+
--error ER_LOCK_DEADLOCK
74+
COMMIT;
75+
76+
DROP TABLE t1;

0 commit comments

Comments
 (0)