Skip to content

Commit 213938c

Browse files
committed
Bug#30535835 IMPROVE PLUGIN USE OF MySQL SERVICES
Implement wrapper to encapsulate ndbcluster plugins use of MySQL services, this unifies and documents how and what the plugin uses. Add support for requesting the MySQL server to shut itself down using the "host_application_signal" interface. Use the new interface when a problem is detected during ndbcluster plugin initialization. This fixes a problem with the testcase for --ndb-cluster-connection-pool- nodeids which starts the MySQL Server several times with invalid parameters, the expected result is that the ndbcluster plugin should write a message to log and then shutdown the MySQL Server. Since the shutdown is done in the middle of MySQL startup this may cause sporadic problems due to missing synchronization, when using the new interface the MySQL Server initialization will be alloowed to finish before shutdown is performed. Also use the new interface to shutdown the MySQL Server when failure to setup events occur, this reduces the ndbcluster plugins usage of internal functions in favour of the stable service interface. Move the service initialization to the module which uses it, this encapsulates related code, reduces dependencies and use of global variables or functions. Change-Id: I6f40b1fdc57707eae704bbe80a99811e5cf19223
1 parent a3f35ce commit 213938c

14 files changed

+373
-247
lines changed

mysql-test/suite/ndb/t/ndb_connection_pool_nodeids.test

-8
Original file line numberDiff line numberDiff line change
@@ -36,47 +36,41 @@ let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.1.expect;
3636
--source include/wait_until_disconnected.inc
3737

3838
--echo # - Empty nodeid last
39-
--error 1
4039
--exec $MYSQLD_CMD_11 --ndb-cluster-connection-pool-nodeids="1,2," $args;
4140
let SEARCH_PATTERN= Found empty nodeid;
4241
let SEARCH_FILE= $error_log;
4342
--source include/search_pattern.inc
4443
--remove_file $SEARCH_FILE
4544

4645
--echo # - Empty nodeid in the middle
47-
--error 1
4846
--exec $MYSQLD_CMD_11 --ndb-cluster-connection-pool-nodeids="1,,3" $args;
4947
let SEARCH_PATTERN= Found empty nodeid;
5048
let SEARCH_FILE= $error_log;
5149
--source include/search_pattern.inc
5250
--remove_file $SEARCH_FILE
5351

5452
--echo # - Specified nodeid is not a number
55-
--error 1
5653
--exec $MYSQLD_CMD_11 --ndb-cluster-connection-pool-nodeids="1,a,3" $args;
5754
let SEARCH_PATTERN= Could not parse;
5855
let SEARCH_FILE= $error_log;
5956
--source include/search_pattern.inc
6057
--remove_file $SEARCH_FILE
6158

6259
--echo # - Check valid nodeid(> 0)
63-
--error 1
6460
--exec $MYSQLD_CMD_11 --ndb-cluster-connection-pool-nodeids="2,0,5" --ndb-nodeid=1 $args;
6561
let SEARCH_PATTERN= Invalid nodeid 0;
6662
let SEARCH_FILE= $error_log;
6763
--source include/search_pattern.inc
6864
--remove_file $SEARCH_FILE
6965

7066
--echo # - Check valid nodeid(<= 255)
71-
--error 1
7267
--exec $MYSQLD_CMD_11 --ndb-cluster-connection-pool-nodeids="2,256,5" --ndb-nodeid=1 $args;
7368
let SEARCH_PATTERN= Invalid nodeid 256;
7469
let SEARCH_FILE= $error_log;
7570
--source include/search_pattern.inc
7671
--remove_file $SEARCH_FILE
7772

7873
--echo # - Specified nodeid is unique
79-
--error 1
8074
--exec $MYSQLD_CMD_11 --ndb-cluster-connection-pool-nodeids="1,1,3" $args;
8175
let SEARCH_PATTERN= Found duplicate nodeid 1;
8276
let SEARCH_FILE= $error_log;
@@ -85,15 +79,13 @@ let SEARCH_FILE= $error_log;
8579

8680
--echo # - Number of nodeids in list must match size of pool
8781
--echo # (config specifies --ndb-cluster-connection-pool=3)
88-
--error 1
8982
--exec $MYSQLD_CMD_11 --ndb-cluster-connection-pool-nodeids="1,3" $args;
9083
let SEARCH_PATTERN= The size of the cluster connection pool must be;
9184
let SEARCH_FILE= $error_log;
9285
--source include/search_pattern.inc
9386
--remove_file $SEARCH_FILE
9487

9588
--echo # - First nodeid must be equal to --ndb-nodeid(if given)
96-
--error 1
9789
--exec $MYSQLD_CMD_11 --ndb-cluster-connection-pool-nodeids="2,3,5" --ndb-nodeid=1 $args;
9890
let SEARCH_PATTERN= The nodeid specified by --ndb-nodeid must be equal;
9991
let SEARCH_FILE= $error_log;

mysql-test/suite/ndb/t/ndb_startup.test

-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.1.expect;
3434

3535
--echo # Start server with provoked error in ndbcluster_init()
3636
--echo # - the mysqld should write an error to the log and shutdown
37-
--error 1
3837
--exec $MYSQLD_CMD_11 --debug="+d,ndbcluster_init_fail1" $args;
3938

4039
--echo # Check the log file for expected error
@@ -45,7 +44,6 @@ let SEARCH_FILE= $error_log;
4544

4645
--echo # Start server with another provoked error in ndbcluster_init()
4746
--echo # - the mysqld should write an error to the log and shutdown
48-
--error 1
4947
--exec $MYSQLD_CMD_11 --debug="+d,ndbcluster_init_fail2" $args;
5048

5149
--echo # Check the log file for expected error
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,50 @@
1-
use test;
1+
# First test, check behaviour with --ndb-log-fail-terminate=1
2+
# during metadata synchronization
3+
# - Create table
4+
# - Setup mysqld2 with DBUG error to force "binlog setup" failure
5+
# - Setup mtr.pl to expect mysqld2 to shutdown
6+
# - Use DUMP 900 to disconnect both mysqld's (node 16 and 49)
7+
# - The mysqld2 will disconnect and then shut itself down when
8+
# hitting the DBUG error during metadata sync
9+
# - Start mysqld2 again and check things work
210
create table t1 (a int primary key) engine=ndb;
311
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
4-
Prepare for Server2 to fail
5-
Wait for 'server2' binlog rotate to indicate disconnect
12+
# Setup mysqld2 DBUG
13+
# NOTE! since the process will restart there is no need to save value
14+
set global debug='+d,ndb_binlog_fail_setup';
15+
# Write file to make mtr.pl expect mysqld2 shutdown, but don't start
16+
# until it's told to
17+
# Disconnect both mysqld's with DUMP 900
18+
# Wait for mysqld2 binlog rotate to indicate disconnect
19+
# Wait for mysqld1 to reconnect and insert data to check it's alive
620
insert into t1 values (11);
7-
Give 'server2' some time to start, and fail, a binlog_setup
8-
Wait for Server2 to fail
9-
Server2 failed as expected
21+
# Wait for mysqld2 to disconnect
22+
# mysqld2 disconnected
23+
# Write file to make mtr.pl start up mysqld2 again
24+
# Wait for mysqld2 to reconnect and insert data to check it's alive
1025
insert into t1 values (10);
11-
drop table test.t1;
12-
Wait for 'server2' to complete setup and get out of read-only mode
13-
Prepare for Server2 to fail
14-
set global debug='-d';
26+
drop table t1;
27+
# Second test, check behaviour with --ndb-log-fail-terminate=1
28+
# during CREATE TABLE
29+
# - Setup mysqld2 with DBUG error to force "binlog setup" failure
30+
# - Setup mtr.pl to expect mysqld2 to shutdown
31+
# - Create table on mysqld1
32+
# - mysqld2 will fail during schema distribution and shut itself down
33+
# - Start mysqld2 again and check things work
34+
# Setup mysqld2 DBUG
35+
# NOTE! since the process will restart there is no need to save value
1536
set global debug='+d,ndb_binlog_fail_setup';
16-
use test;
37+
# Write file to make mtr.pl expect mysqld2 shutdown, but don't start
38+
# until it's told to
39+
# Create table from mysqld1
1740
create table t1 (a int primary key) engine=ndb;
41+
Warnings:
42+
Warning 1296 Node 16: 'Distribution of CREATE TABLE 't1' failed'
1843
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
19-
Wait for Server2 to fail
20-
Server2 failed as expected
44+
# Wait for mysqld2 diconnect
45+
# mysqld2 disconnected
46+
# Write file to make mtr.pl start up mysqld2 again
47+
# Wait for mysqld2 to reconnect and insert data to check it's alive
2148
insert into t1 values (10);
2249
insert into t1 values (11);
2350
drop table t1;
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,125 @@
11
-- source include/have_multi_ndb.inc
22
-- source include/have_binlog_format_mixed_or_row.inc
3-
# We are using some debug-only features in this test
3+
# Test is using some debug-only features
44
--source include/have_debug.inc
55
# Test terminates mysqld which causes valgrind warnings
66
--source include/not_valgrind.inc
77
# Ignore any mysqld failure reporting
88
--source include/not_crashrep.inc
99

10-
connection server1;
11-
# Find NodeId of the mysqld we are connected to:
12-
--let $node_id= `SHOW STATUS LIKE 'Ndb_cluster_node_id'`
13-
--let $node_id= `SELECT SUBSTRING('$node_id', 20)+0`
10+
--connection server1
1411
--disable_query_log
1512
call mtr.add_suppression("cluster disconnect An incident event");
1613
--enable_query_log
1714

18-
connection server2;
19-
# Find NodeId2 of 'server2' we are connected to:
20-
--let $node_id2= `SHOW STATUS LIKE 'Ndb_cluster_node_id'`
21-
--let $node_id2= `SELECT SUBSTRING('$node_id2', 20)+0`
22-
23-
# Ignore server shutdown/startup failure
15+
--connection server2
16+
# Ignore server shutdown/startup errors in log
2417
--disable_query_log
2518
call mtr.add_suppression("Failed to setup binlog");
2619
call mtr.add_suppression("Distribution of CREATE TABLE");
2720
call mtr.add_suppression("Server shutdown in progress");
2821
call mtr.add_suppression("cluster disconnect An incident event");
29-
call mtr.add_suppression("Failed setting up binlogging");
3022
call mtr.add_suppression("mysqld startup an incident event");
31-
call mtr.add_suppression("Failed to release global schema lock");
23+
# Reported when the --ndb-log-fail-terminate logic kicks in
24+
call mtr.add_suppression("Requesting server shutdown");
3225
--enable_query_log
3326

34-
#
35-
# 1 create a table
36-
# 2 Setup error insert on MySQLD2
37-
# 3 Disconnect MySQLD2 using DUMP code, causing Binlog re-init
38-
# 4 Observe MySQLD2 fail, then restart (and succeed)
39-
#
40-
41-
connection server1;
42-
use test;
27+
--echo # First test, check behaviour with --ndb-log-fail-terminate=1
28+
--echo # during metadata synchronization
29+
--echo # - Create table
30+
--echo # - Setup mysqld2 with DBUG error to force "binlog setup" failure
31+
--echo # - Setup mtr.pl to expect mysqld2 to shutdown
32+
--echo # - Use DUMP 900 to disconnect both mysqld's (node 16 and 49)
33+
--echo # - The mysqld2 will disconnect and then shut itself down when
34+
--echo # hitting the DBUG error during metadata sync
35+
--echo # - Start mysqld2 again and check things work
4336

37+
--connection server1
4438
create table t1 (a int primary key) engine=ndb;
4539
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
4640

47-
connection server2;
48-
disable_query_log;
49-
let $debug_saved = `select @@global.debug`;
50-
set global debug='-d'; # Switch DEBUG/TRACING OFF
41+
--connection server2
42+
--echo # Setup mysqld2 DBUG
43+
--echo # NOTE! since the process will restart there is no need to save value
5144
set global debug='+d,ndb_binlog_fail_setup';
52-
enable_query_log;
53-
54-
--echo Prepare for Server2 to fail
55-
connection server2;
56-
# Find NodeId2 of 'server2' we are connected to:
57-
--let $node_id2= `SHOW STATUS LIKE 'Ndb_cluster_node_id'`
58-
--let $node_id2= `SELECT SUBSTRING('$node_id2', 20)+0`
59-
60-
#
61-
# Some magic for MTR to allow failure, taken from include/restart_mysqld.inc
62-
#
63-
--let $_server_id= `SELECT @@server_id`
64-
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.1.expect
65-
66-
--exec echo "wait" > $_expect_file_name
67-
#
68-
# /end magic part 1
69-
#
70-
71-
#
72-
# Cause data nodes to disconnect all API nodes
73-
# Each API will setup binlog again
74-
# MySQLD2 will get stuck and restart
75-
#
76-
77-
--exec $NDB_MGM -e "ALL DUMP 900 $node_id" > $NDB_TOOLS_OUTPUT
78-
--exec $NDB_MGM -e "ALL DUMP 900 $node_id2" > $NDB_TOOLS_OUTPUT
79-
80-
#connection server1;
81-
#--echo Wait for 'server1' binlog rotate to indicate disconnect
82-
#--let $wait_binlog_event= binlog.000002
83-
#--source include/wait_for_binlog_event.inc
84-
85-
connection server2;
86-
--echo Wait for 'server2' binlog rotate to indicate disconnect
45+
46+
--echo # Write file to make mtr.pl expect mysqld2 shutdown, but don't start
47+
--echo # until it's told to
48+
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.1.expect
49+
wait
50+
EOF
51+
52+
--echo # Disconnect both mysqld's with DUMP 900
53+
let $out_file = $MYSQLTEST_VARDIR/tmp/mgm_dump.out;
54+
--exec $NDB_MGM -e "ALL DUMP 900 16" > $out_file 2>&1
55+
--exec $NDB_MGM -e "ALL DUMP 900 49" >> $out_file 2>&1
56+
--remove_file $out_file
57+
58+
--echo # Wait for mysqld2 binlog rotate to indicate disconnect
8759
--let $wait_binlog_event= binlog.000002
8860
--source include/wait_for_binlog_event.inc
8961

90-
connection server1;
62+
--connection server1
63+
--echo # Wait for mysqld1 to reconnect and insert data to check it's alive
9164
--source include/ndb_not_readonly.inc
9265
insert into t1 values (11);
9366

94-
--echo Give 'server2' some time to start, and fail, a binlog_setup
95-
sleep 2;
96-
97-
--echo Wait for Server2 to fail
98-
connection server2;
67+
--connection server2
68+
--echo # Wait for mysqld2 to disconnect
9969
--source include/wait_until_disconnected.inc
70+
--echo # mysqld2 disconnected
10071

101-
--echo Server2 failed as expected
102-
103-
#
104-
# More magic from include/restart_mysqld.inc
105-
#
106-
--exec echo "restart" > $_expect_file_name
72+
--echo # Write file to make mtr.pl start up mysqld2 again
73+
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.1.expect
74+
restart
75+
EOF
10776

77+
--echo # Wait for mysqld2 to reconnect and insert data to check it's alive
10878
--enable_reconnect
10979
--source include/wait_until_connected_again.inc
11080
--disable_reconnect
111-
#
112-
# /end magic part 2
113-
#
11481

115-
connection server1;
11682
insert into t1 values (10);
117-
drop table test.t1;
118-
119-
connection server2;
120-
--echo Wait for 'server2' to complete setup and get out of read-only mode
121-
--source include/ndb_not_readonly.inc
122-
--remove_file $NDB_TOOLS_OUTPUT
123-
124-
#
125-
# 1 Setup error insert on MySQLD2
126-
# 2 create a table on MySQLD1
127-
# 3 Observe MySQLD2 fail, then restart (and succeed)
128-
#
129-
130-
--echo Prepare for Server2 to fail
131-
--connection server2
132-
#
133-
# Some magic for MTR to allow failure, taken from include/restart_mysqld.inc
134-
#
135-
--let $_server_id= `SELECT @@server_id`
136-
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.1.expect
83+
drop table t1;
13784

138-
--exec echo "wait" > $_expect_file_name
139-
#
140-
# /end magic part 1
141-
#
85+
--echo # Second test, check behaviour with --ndb-log-fail-terminate=1
86+
--echo # during CREATE TABLE
87+
--echo # - Setup mysqld2 with DBUG error to force "binlog setup" failure
88+
--echo # - Setup mtr.pl to expect mysqld2 to shutdown
89+
--echo # - Create table on mysqld1
90+
--echo # - mysqld2 will fail during schema distribution and shut itself down
91+
--echo # - Start mysqld2 again and check things work
14292

14393
--connection server2
144-
set global debug='-d'; # Switch DEBUG/TRACING OFF
94+
--echo # Setup mysqld2 DBUG
95+
--echo # NOTE! since the process will restart there is no need to save value
14596
set global debug='+d,ndb_binlog_fail_setup';
14697

98+
--echo # Write file to make mtr.pl expect mysqld2 shutdown, but don't start
99+
--echo # until it's told to
100+
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.1.expect
101+
wait
102+
EOF
103+
147104
--connection server1
148-
use test;
149-
--disable_warnings
105+
--echo # Create table from mysqld1
150106
create table t1 (a int primary key) engine=ndb;
151107
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
152108

153-
--echo Wait for Server2 to fail
154109
--connection server2
110+
--echo # Wait for mysqld2 diconnect
155111
--source include/wait_until_disconnected.inc
112+
--echo # mysqld2 disconnected
156113

157-
--echo Server2 failed as expected
158-
--enable_warnings
159-
160-
#
161-
# More magic from include/restart_mysqld.inc
162-
#
163-
--exec echo "restart" > $_expect_file_name
114+
--echo # Write file to make mtr.pl start up mysqld2 again
115+
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.1.expect
116+
restart
117+
EOF
164118

119+
--echo # Wait for mysqld2 to reconnect and insert data to check it's alive
165120
--enable_reconnect
166121
--source include/wait_until_connected_again.inc
167122
--disable_reconnect
168-
#
169-
# /end magic part 2
170-
#
171123

172124
--source include/ndb_not_readonly.inc
173125
insert into t1 values (10);
@@ -177,8 +129,3 @@ insert into t1 values (10);
177129
insert into t1 values (11);
178130
drop table t1;
179131

180-
--connection server2
181-
disable_query_log;
182-
set global debug='+d'; # Switch DEBUG/TRACING ON
183-
eval set global debug= '$debug_saved';
184-
enable_query_log;

0 commit comments

Comments
 (0)