Skip to content

Commit 0e105bc

Browse files
philip-galeraSachinSetiya
authored andcommitted
Galera MTR Tests: Test for GCF-942 - safe_to_bootstrap flag in grastate.dat
1 parent 1529868 commit 0e105bc

File tree

4 files changed

+345
-0
lines changed

4 files changed

+345
-0
lines changed

mysql-test/include/assert_grep.inc

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# ==== Purpose ====
2+
#
3+
# Grep a file for a pattern, produce a single string out of the
4+
# matching lines, and assert that the string matches a given regular
5+
# expression.
6+
#
7+
# ==== Usage ====
8+
#
9+
# --let $assert_text= TEXT
10+
# --let $assert_file= FILE
11+
# --let $assert_select= REGEX
12+
# [--let $assert_match= REGEX | --let $assert_count= NUMBER]
13+
# [--let $assert_only_after= REGEX]
14+
# --source include/assert_grep.inc
15+
#
16+
# Parameters:
17+
#
18+
# $assert_text
19+
# Text that describes what is being checked. This text is written to
20+
# the query log so it should not contain non-deterministic elements.
21+
#
22+
# $assert_file
23+
# File to search.
24+
#
25+
# $assert_select
26+
# All lines matching this text will be checked.
27+
#
28+
# $assert_match
29+
# The script will find all lines that match $assert_select,
30+
# concatenate them to a long string, and assert that it matches
31+
# $assert_match.
32+
#
33+
# $assert_count
34+
# Instead of asserting that the selected lines match
35+
# $assert_match, assert that there were exactly $assert_count
36+
# matching lines.
37+
#
38+
# $assert_only_after
39+
# Reset all the lines matched and the counter when finding this pattern.
40+
# It is useful for searching things in the mysqld.err log file just
41+
# after the last server restart for example (discarding the log content
42+
# of previous server executions).
43+
44+
45+
if (!$assert_text)
46+
{
47+
--die !!!ERROR IN TEST: you must set $assert_text
48+
}
49+
if (!$assert_file)
50+
{
51+
--die !!!ERROR IN TEST: you must set $assert_file
52+
}
53+
if (!$assert_select)
54+
{
55+
--die !!!ERROR IN TEST: you must set $assert_select
56+
}
57+
if ($assert_match == '')
58+
{
59+
if ($assert_count == '')
60+
{
61+
--die !!!ERROR IN TEST: you must set either $assert_match or $assert_count
62+
}
63+
}
64+
if ($assert_match != '')
65+
{
66+
if ($assert_count != '')
67+
{
68+
--echo assert_text='$assert_text' assert_count='$assert_count'
69+
--die !!!ERROR IN TEST: you must set only one of $assert_match or $assert_count
70+
}
71+
}
72+
73+
74+
--let $include_filename= assert_grep.inc [$assert_text]
75+
--source include/begin_include_file.inc
76+
77+
78+
--let _AG_ASSERT_TEXT= $assert_text
79+
--let _AG_ASSERT_FILE= $assert_file
80+
--let _AG_ASSERT_SELECT= $assert_select
81+
--let _AG_ASSERT_MATCH= $assert_match
82+
--let _AG_ASSERT_COUNT= $assert_count
83+
--let _AG_OUT= `SELECT CONCAT('$MYSQLTEST_VARDIR/tmp/_ag_', UUID())`
84+
--let _AG_ASSERT_ONLY_AFTER= $assert_only_after
85+
86+
87+
--perl
88+
use strict;
89+
use warnings;
90+
my $file= $ENV{'_AG_ASSERT_FILE'};
91+
my $assert_select= $ENV{'_AG_ASSERT_SELECT'};
92+
my $assert_match= $ENV{'_AG_ASSERT_MATCH'};
93+
my $assert_count= $ENV{'_AG_ASSERT_COUNT'};
94+
my $assert_only_after= $ENV{'_AG_ASSERT_ONLY_AFTER'};
95+
my $out= $ENV{'_AG_OUT'};
96+
97+
my $result= '';
98+
my $count= 0;
99+
open(FILE, "$file") or die("Error $? opening $file: $!\n");
100+
while (<FILE>) {
101+
my $line = $_;
102+
if ($assert_only_after && $line =~ /$assert_only_after/) {
103+
$result = "";
104+
$count = 0;
105+
}
106+
if ($line =~ /$assert_select/) {
107+
if ($assert_count ne '') {
108+
$count++;
109+
}
110+
else {
111+
$result .= $line;
112+
}
113+
}
114+
}
115+
close(FILE) or die("Error $? closing $file: $!");
116+
open OUT, "> $out" or die("Error $? opening $out: $!");
117+
if ($assert_count ne '' && ($count != $assert_count)) {
118+
print OUT ($count) or die("Error $? writing $out: $!");
119+
}
120+
elsif ($assert_count eq '' && $result !~ /$assert_match/) {
121+
print OUT ($result) or die("Error $? writing $out: $!");
122+
}
123+
else {
124+
print OUT ("assert_grep.inc ok");
125+
}
126+
close OUT or die("Error $? closing $out: $!");
127+
EOF
128+
129+
130+
--let $_ag_outcome= `SELECT LOAD_FILE('$_AG_OUT')`
131+
if ($_ag_outcome != 'assert_grep.inc ok')
132+
{
133+
--source include/show_rpl_debug_info.inc
134+
--echo include/assert_grep.inc failed!
135+
--echo assert_text: '$assert_text'
136+
--echo assert_file: '$assert_file'
137+
--echo assert_select: '$assert_select'
138+
--echo assert_match: '$assert_match'
139+
--echo assert_count: '$assert_count'
140+
--echo assert_only_after: '$assert_only_after'
141+
if ($assert_match != '')
142+
{
143+
--echo matching lines: '$_ag_outcome'
144+
}
145+
if ($assert_count != '')
146+
{
147+
--echo number of matching lines: $_ag_outcome
148+
}
149+
--die assert_grep.inc failed.
150+
}
151+
152+
153+
--let $include_filename= include/assert_grep.inc [$assert_text]
154+
--source include/end_include_file.inc

mysql-test/suite/galera_3nodes/disabled.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ galera_slave_options_do :MDEV-8798
55
galera_slave_options_ignore : MDEV-8798
66
galera_pc_bootstrap : TODO: Investigate: Timeout in wait_condition.inc
77
galera_pc_weight : Test times out
8+
galera_safe_to_bootstrap : I Really dont know :(
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB;
2+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0']
3+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0']
4+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0']
5+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0']
6+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0']
7+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0']
8+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0']
9+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0']
10+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 1']
11+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0']
12+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0']
13+
include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0']
14+
SET SESSION wsrep_on = OFF;
15+
Killing server ...
16+
safe_to_bootstrap: 1
17+
safe_to_bootstrap: 0
18+
safe_to_bootstrap: 0
19+
CALL mtr.add_suppression("Failed to prepare for incremental state transfer");
20+
CALL mtr.add_suppression("Failed to prepare for incremental state transfer");
21+
SHOW CREATE TABLE t1;
22+
Table Create Table
23+
t1 CREATE TABLE `t1` (
24+
`f1` int(11) DEFAULT NULL
25+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
26+
DROP TABLE t1;
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#
2+
# Test the safe_to_bootstrap in grastate.dat
3+
#
4+
5+
--source include/galera_cluster.inc
6+
--source include/have_innodb.inc
7+
CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB;
8+
9+
#
10+
# At start, all grastate.dat files have safe_to_boostrap: 0
11+
#
12+
13+
--let $assert_text= grastate.dat does not have 'safe_to_bootstrap: 0'
14+
--let $assert_select= safe_to_bootstrap: 0
15+
--let $assert_count= 1
16+
17+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.1/data/grastate.dat
18+
--source include/assert_grep.inc
19+
20+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat
21+
--source include/assert_grep.inc
22+
23+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.3/data/grastate.dat
24+
--source include/assert_grep.inc
25+
26+
#
27+
# Shut down one node
28+
#
29+
30+
--connection node_2
31+
--source include/shutdown_mysqld.inc
32+
33+
--connection node_1
34+
--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
35+
--source include/wait_condition.inc
36+
37+
# Still, all grastate.dat files should have safe_to_boostrap: 0
38+
39+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.1/data/grastate.dat
40+
--source include/assert_grep.inc
41+
42+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat
43+
--source include/assert_grep.inc
44+
45+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.3/data/grastate.dat
46+
--source include/assert_grep.inc
47+
48+
#
49+
# Shut down one more node
50+
#
51+
52+
--connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3
53+
--connection node_3
54+
--source include/shutdown_mysqld.inc
55+
56+
--connection node_1
57+
--let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
58+
--source include/wait_condition.inc
59+
60+
# Now, nodes 2,3 should have safe_to_boostrap: 0
61+
62+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat
63+
--source include/assert_grep.inc
64+
65+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.3/data/grastate.dat
66+
--source include/assert_grep.inc
67+
68+
# But node #1 should have safe_to_boostrap: 1
69+
70+
--let $assert_text= grastate.dat does not have 'safe_to_bootstrap: 1'
71+
--let $assert_select= safe_to_bootstrap: 1
72+
73+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.1/data/grastate.dat
74+
--source include/assert_grep.inc
75+
76+
# Restart one node
77+
78+
--connection node_2
79+
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
80+
--source include/start_mysqld.inc
81+
82+
--connection node_1
83+
--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
84+
--source include/wait_condition.inc
85+
86+
# All nodes should be back to 'safe_to_bootstrap: 0'
87+
88+
--let $assert_text= grastate.dat does not have 'safe_to_bootstrap: 0'
89+
--let $assert_select= safe_to_bootstrap: 0
90+
91+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.1/data/grastate.dat
92+
--source include/assert_grep.inc
93+
94+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat
95+
--source include/assert_grep.inc
96+
97+
--let $assert_file= $MYSQLTEST_VARDIR/mysqld.3/data/grastate.dat
98+
--source include/assert_grep.inc
99+
100+
#
101+
# Kill the cluster
102+
#
103+
104+
--connection node_2
105+
--source include/shutdown_mysqld.inc
106+
107+
--connection node_1
108+
SET SESSION wsrep_on = OFF;
109+
--let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
110+
--source include/wait_condition.inc
111+
112+
--source include/kill_galera.inc
113+
114+
#
115+
# Only node #1 should have safe_to_bootstrap: 1
116+
# include/assert_grep.inc requires a running server, so we revert to simple grep
117+
#
118+
119+
--error 0
120+
--exec grep 'safe_to_bootstrap: 1' $MYSQLTEST_VARDIR/mysqld.1/data/grastate.dat
121+
122+
--error 0
123+
--exec grep 'safe_to_bootstrap: 0' $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat
124+
125+
--error 0
126+
--exec grep 'safe_to_bootstrap: 0' $MYSQLTEST_VARDIR/mysqld.3/data/grastate.dat
127+
128+
#
129+
# Attempt to bootstrap nodes #2, #3, should fail
130+
#
131+
132+
--error 1
133+
--exec $MYSQLD --defaults-group-suffix=.2 --defaults-file=$MYSQLTEST_VARDIR/my.cnf --wsrep-new-cluster | grep 'This node is not safe to bootstrap the cluster'
134+
--error 1
135+
--exec $MYSQLD --defaults-group-suffix=.3 --defaults-file=$MYSQLTEST_VARDIR/my.cnf --wsrep-new-cluster | grep 'This node is not safe to bootstrap the cluster'
136+
137+
#
138+
# Attempt to bootstrap starting from node #1, should succeed
139+
#
140+
141+
--connection node_1
142+
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
143+
--source include/start_mysqld.inc
144+
--source include/wait_until_connected_again.inc
145+
146+
--connection node_2
147+
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
148+
--source include/start_mysqld.inc
149+
150+
--connection node_3
151+
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.3.expect
152+
--source include/start_mysqld.inc
153+
154+
--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
155+
--source include/wait_condition.inc
156+
157+
--connection node_2
158+
CALL mtr.add_suppression("Failed to prepare for incremental state transfer");
159+
160+
--connection node_3
161+
CALL mtr.add_suppression("Failed to prepare for incremental state transfer");
162+
SHOW CREATE TABLE t1;
163+
164+
DROP TABLE t1;

0 commit comments

Comments
 (0)