Skip to content

Commit 0131e18

Browse files
MDEV-34124: Test sequences recovery after crash in Galera cluster
1 parent 4849c28 commit 0131e18

File tree

4 files changed

+269
-0
lines changed

4 files changed

+269
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
connection node_2;
2+
connection node_1;
3+
connection node_1;
4+
CREATE SEQUENCE s INCREMENT=0 CACHE=5 ENGINE=InnoDB;
5+
CREATE TABLE t1 (f1 INT PRIMARY KEY DEFAULT NEXTVAL(s), f2 INT) ENGINE=InnoDB;
6+
connection node_1;
7+
BEGIN;
8+
INSERT INTO t1(f2) values (1);
9+
INSERT INTO t1(f2) values (1);
10+
INSERT INTO t1(f2) values (1);
11+
INSERT INTO t1(f2) values (1);
12+
INSERT INTO t1(f2) values (1);
13+
connection node_2;
14+
BEGIN;
15+
INSERT INTO t1(f2) values (2);
16+
INSERT INTO t1(f2) values (2);
17+
INSERT INTO t1(f2) values (2);
18+
Killing server ...
19+
SELECT NEXTVAL(s);
20+
NEXTVAL(s)
21+
12
22+
connection node_1;
23+
INSERT INTO t1(f2) values (1);
24+
INSERT INTO t1(f2) values (1);
25+
INSERT INTO t1(f2) values (1);
26+
INSERT INTO t1(f2) values (1);
27+
INSERT INTO t1(f2) values (1);
28+
COMMIT;
29+
SELECT LASTVAL(s);
30+
LASTVAL(s)
31+
29
32+
SELECT * FROM t1;
33+
f1 f2
34+
1 1
35+
3 1
36+
5 1
37+
7 1
38+
9 1
39+
21 1
40+
23 1
41+
25 1
42+
27 1
43+
29 1
44+
connection node_2;
45+
SELECT LASTVAL(s);
46+
LASTVAL(s)
47+
12
48+
SELECT NEXTVAL(s);
49+
NEXTVAL(s)
50+
32
51+
SELECT * FROM t1;
52+
f1 f2
53+
1 1
54+
3 1
55+
5 1
56+
7 1
57+
9 1
58+
21 1
59+
23 1
60+
25 1
61+
27 1
62+
29 1
63+
connection node_1;
64+
DROP TABLE t1;
65+
DROP SEQUENCE s;
66+
connection node_1;
67+
CREATE SEQUENCE s INCREMENT=0 CACHE=5 ENGINE=InnoDB;
68+
CREATE TABLE t1 (f1 INT PRIMARY KEY DEFAULT NEXTVAL(s), f2 INT) ENGINE=InnoDB;
69+
connection node_1;
70+
BEGIN;
71+
INSERT INTO t1(f2) values (1);
72+
INSERT INTO t1(f2) values (1);
73+
INSERT INTO t1(f2) values (1);
74+
INSERT INTO t1(f2) values (1);
75+
INSERT INTO t1(f2) values (1);
76+
connection node_2;
77+
BEGIN;
78+
INSERT INTO t1(f2) values (2);
79+
INSERT INTO t1(f2) values (2);
80+
INSERT INTO t1(f2) values (2);
81+
INSERT INTO t1(f2) values (2);
82+
INSERT INTO t1(f2) values (2);
83+
INSERT INTO t1(f2) values (2);
84+
Killing server ...
85+
connection node_1;
86+
INSERT INTO t1(f2) values (1);
87+
INSERT INTO t1(f2) values (1);
88+
INSERT INTO t1(f2) values (1);
89+
INSERT INTO t1(f2) values (1);
90+
INSERT INTO t1(f2) values (1);
91+
COMMIT;
92+
SELECT LASTVAL(s);
93+
LASTVAL(s)
94+
19
95+
SELECT * FROM t1;
96+
f1 f2
97+
1 1
98+
3 1
99+
5 1
100+
7 1
101+
9 1
102+
11 1
103+
13 1
104+
15 1
105+
17 1
106+
19 1
107+
connection node_2;
108+
SELECT NEXTVAL(s);
109+
NEXTVAL(s)
110+
22
111+
SELECT * FROM t1;
112+
f1 f2
113+
1 1
114+
3 1
115+
5 1
116+
7 1
117+
9 1
118+
11 1
119+
13 1
120+
15 1
121+
17 1
122+
19 1
123+
connection node_1;
124+
SELECT LASTVAL(s);
125+
LASTVAL(s)
126+
19
127+
SELECT NEXTVAL(s);
128+
NEXTVAL(s)
129+
33
130+
connection node_1;
131+
DROP TABLE t1;
132+
DROP SEQUENCE s;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
!include ../galera_2nodes.cnf
2+
3+
[mysqld.1]
4+
auto-increment-increment=2
5+
auto-increment-offset=1
6+
7+
[mysqld.2]
8+
auto-increment-increment=2
9+
auto-increment-offset=2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[binlogon]
2+
log-bin
3+
log-slave-updates
4+
5+
[binlogoff]
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#
2+
# Test sequences crash recovery.
3+
#
4+
5+
--source include/galera_cluster.inc
6+
--source include/have_sequence.inc
7+
--source include/big_test.inc
8+
9+
--disable_ps2_protocol
10+
11+
#
12+
# Case 1: Crash a node during a transaction, bring the
13+
# sequence in sync by receiving higher current value
14+
#
15+
--connection node_1
16+
CREATE SEQUENCE s INCREMENT=0 CACHE=5 ENGINE=InnoDB;
17+
CREATE TABLE t1 (f1 INT PRIMARY KEY DEFAULT NEXTVAL(s), f2 INT) ENGINE=InnoDB;
18+
19+
--connection node_1
20+
BEGIN;
21+
INSERT INTO t1(f2) values (1);
22+
INSERT INTO t1(f2) values (1);
23+
INSERT INTO t1(f2) values (1);
24+
INSERT INTO t1(f2) values (1);
25+
INSERT INTO t1(f2) values (1);
26+
27+
--connection node_2
28+
BEGIN;
29+
INSERT INTO t1(f2) values (2);
30+
INSERT INTO t1(f2) values (2);
31+
INSERT INTO t1(f2) values (2);
32+
33+
# Crash and restart the node, losing the transaciton
34+
--source include/kill_galera.inc
35+
--let $start_mysqld_params =
36+
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
37+
--source include/start_mysqld.inc
38+
39+
# Check and update the last written sequence value
40+
SELECT NEXTVAL(s);
41+
42+
--connection node_1
43+
# Update the sequence value further
44+
INSERT INTO t1(f2) values (1);
45+
INSERT INTO t1(f2) values (1);
46+
INSERT INTO t1(f2) values (1);
47+
INSERT INTO t1(f2) values (1);
48+
INSERT INTO t1(f2) values (1);
49+
50+
COMMIT;
51+
SELECT LASTVAL(s);
52+
SELECT * FROM t1;
53+
54+
--connection node_2
55+
# The next value should be in sync now, but the last
56+
# value is still the same
57+
SELECT LASTVAL(s);
58+
SELECT NEXTVAL(s);
59+
SELECT * FROM t1;
60+
61+
--connection node_1
62+
DROP TABLE t1;
63+
DROP SEQUENCE s;
64+
65+
#
66+
# Case 2: Crash a node during a transaction, bring the
67+
# sequence in sync by sending higher current value
68+
#
69+
--connection node_1
70+
CREATE SEQUENCE s INCREMENT=0 CACHE=5 ENGINE=InnoDB;
71+
CREATE TABLE t1 (f1 INT PRIMARY KEY DEFAULT NEXTVAL(s), f2 INT) ENGINE=InnoDB;
72+
73+
--connection node_1
74+
BEGIN;
75+
INSERT INTO t1(f2) values (1);
76+
INSERT INTO t1(f2) values (1);
77+
INSERT INTO t1(f2) values (1);
78+
INSERT INTO t1(f2) values (1);
79+
INSERT INTO t1(f2) values (1);
80+
81+
--connection node_2
82+
# Exhaust the cached values once, but no replication happens even
83+
# though the sequnce table is updated
84+
BEGIN;
85+
INSERT INTO t1(f2) values (2);
86+
INSERT INTO t1(f2) values (2);
87+
INSERT INTO t1(f2) values (2);
88+
INSERT INTO t1(f2) values (2);
89+
INSERT INTO t1(f2) values (2);
90+
INSERT INTO t1(f2) values (2);
91+
92+
# Crash and restart the node, losing the transaciton
93+
--source include/kill_galera.inc
94+
--let $start_mysqld_params =
95+
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
96+
--source include/start_mysqld.inc
97+
98+
--connection node_1
99+
INSERT INTO t1(f2) values (1);
100+
INSERT INTO t1(f2) values (1);
101+
INSERT INTO t1(f2) values (1);
102+
INSERT INTO t1(f2) values (1);
103+
INSERT INTO t1(f2) values (1);
104+
105+
COMMIT;
106+
SELECT LASTVAL(s);
107+
SELECT * FROM t1;
108+
109+
--connection node_2
110+
# Check and update the last written sequence value, it's still
111+
# higher than the one from the other node
112+
SELECT NEXTVAL(s);
113+
SELECT * FROM t1;
114+
115+
--connection node_1
116+
# The next value should be in sync now, but the last
117+
# value is still the same
118+
SELECT LASTVAL(s);
119+
SELECT NEXTVAL(s);
120+
121+
--connection node_1
122+
DROP TABLE t1;
123+
DROP SEQUENCE s;

0 commit comments

Comments
 (0)