Debian Codegraph @

mysql-test/suite/galera/t/galera_sequences_recovery.test

raw
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;