Skip to content

Commit ea1abd4

Browse files
author
Sven Sandberg
committed
Merge BUG#27525856 from mysql-8.0 into mysql-trunk
2 parents 825854b + f70557b commit ea1abd4

File tree

6 files changed

+147
-66
lines changed

6 files changed

+147
-66
lines changed

mysql-test/extra/rpl_tests/rpl_perfschema_applier_xa_status.test

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,54 +20,63 @@
2020
--source include/rpl_connection_slave.inc
2121
TRUNCATE TABLE performance_schema.events_transactions_current;
2222

23+
--echo ---- Setup ----
2324
--source include/rpl_connection_master.inc
2425
--let $master_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
2526
CREATE TABLE t ( f INT) ENGINE=INNODB;
27+
28+
--echo ---- XA PREPARE ----
2629
XA START 'xatest';
2730
INSERT INTO t VALUES (10);
2831
XA END 'xatest';
2932
XA PREPARE 'xatest';
30-
--let $master_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
31-
--let $master_file= query_get_value(SHOW MASTER STATUS, File, 1)
3233

33-
--source include/rpl_connection_slave.inc
34-
--echo # Wait until SQL thread reaches desired master binlog position
35-
--let $slave_param= Relay_Master_Log_File
36-
--let $slave_param_value= $master_file
37-
--let $slave_param_comparison= =
38-
--source include/wait_for_slave_param.inc
34+
# Sync on a different connection, since we can't run queries on a
35+
# connection that has an XA transaction in PREPARED state.
36+
--connection default
37+
--source include/sync_slave_sql_with_master.inc
3938

40-
--let $slave_param= Exec_Master_Log_Pos
41-
--let $slave_param_value= $master_pos
42-
--let $slave_param_comparison= >=
43-
--source include/wait_for_slave_param.inc
39+
--echo # Wait for XA_STATE to become PREPARED on slave
40+
# It is not enough to only use sync_slave_sql_with_master.inc, because
41+
# the XA state is updated after the GTID state and the replication
42+
# positions. Hence we also *wait* for the XA state to change.
43+
--let $wait_condition = SELECT COUNT(*) = 1 FROM performance_schema.events_transactions_current WHERE XID_GTRID = 'xatest' AND XA_STATE = 'PREPARED'
44+
--source include/wait_condition_or_abort.inc
4445

46+
--echo # Expecting one prepared transaction
4547
XA RECOVER;
46-
--echo ####################################################################
47-
--echo # Asserting XA_STATE is PREPARED on Slave
48-
--echo ####################################################################
49-
--let $assert_text= Verify that XA_STATE is set PREPARED.
50-
--let $assert_cond=count(*)=1 FROM performance_schema.events_transactions_current WHERE XID_GTRID=\'xatest\' AND XA_STATE=\'PREPARED\'
51-
--source include/assert.inc
5248

49+
if ($gtid_mode == ON)
50+
{
51+
--let $gno_0 = 2
52+
--let $expected_gtid = $master_uuid:$gno_0
53+
--echo Waiting until gtid is MASTER_UUID:$gno_0
54+
--let $wait_condition = SELECT GTID = '$expected_gtid' FROM performance_schema.events_transactions_current where XID_GTRID = 'xatest' AND XA_STATE = 'PREPARED'
55+
--source include/wait_condition_or_abort.inc
56+
}
57+
58+
--echo ---- XA COMMIT ----
5359
--source include/rpl_connection_master.inc
5460
XA COMMIT 'xatest';
5561
--source include/sync_slave_sql_with_master.inc
62+
63+
--echo # Wait for XA_STATE to become COMMITTED on slave
64+
--let $wait_condition = SELECT COUNT(*) = 1 FROM performance_schema.events_transactions_current WHERE XID_GTRID = 'xatest' AND XA_STATE = 'COMMITTED'
65+
--source include/wait_condition_or_abort.inc
66+
67+
--echo # Expecting no prepared transactions
5668
XA RECOVER;
57-
--echo ####################################################################
58-
--echo # Asserting XA_STATE is COMMITTED on Slave
59-
--echo ####################################################################
60-
--let $assert_text= Verify that XA_STATE is set COMMITTED.
61-
--let $assert_cond=count(*)=1 FROM performance_schema.events_transactions_current WHERE XID_GTRID=\'xatest\' AND XA_STATE=\'COMMITTED\'
62-
--source include/assert.inc
6369

6470
if ($gtid_mode == ON)
6571
{
6672
--let $gno_0 = 3
6773
--let $expected_gtid = $master_uuid:$gno_0
68-
--let $assert_text= Expected gtid is MASTER_UUID:$gno_0
69-
--let $assert_cond= "[SELECT GTID FROM performance_schema.events_transactions_current where XID_GTRID=\'xatest\']" = "$expected_gtid"
70-
--source include/assert.inc
74+
--echo Waiting until gtid is MASTER_UUID:$gno_0
75+
# We need the "XA_STATE='COMMITTED'" condition, since there
76+
# can be multiple rows having XID_GTRID='xatest' in case XA PREPARE
77+
# and XA COMMIT were handled by different applier worker threads.
78+
--let $wait_condition = SELECT GTID = '$expected_gtid' FROM performance_schema.events_transactions_current where XID_GTRID = 'xatest' AND XA_STATE = 'COMMITTED'
79+
--source include/wait_condition_or_abort.inc
7180
}
7281

7382
--let $diff_tables=master:t,slave:t

mysql-test/include/dbug_crash.inc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ==== Purpose ====
2+
#
3+
# Crash the server of the current connection.
4+
#
5+
# This should be used only for debugging test cases, when you need the
6+
# core file. To stop a server as part of a test scenario, use one of
7+
# rpl_stop_server.inc, rpl_restart_server.inc, kill_mysqld.inc,
8+
# restart_mysqld.inc, etc.
9+
#
10+
# ==== Implementation ====
11+
#
12+
# This relies on a debug symbol that causes the server to call
13+
# DBUG_ASSERT(0). So it only works on debug-compiled servers.
14+
#
15+
# ==== Usage ====
16+
#
17+
# [in main test: source include/have_dbug.inc]
18+
# --source include/dbug_crash.inc
19+
20+
SET SESSION debug = 'd,crash_now';

mysql-test/include/dbug_crash_all.inc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ==== Purpose ====
2+
#
3+
# Crash all servers that were configured with rpl_init.inc/master-slave.inc.
4+
#
5+
# This should be used only for debugging test cases, when you need the
6+
# core file. To stop a server as part of a test scenario, use one of
7+
# rpl_stop_server.inc, rpl_restart_server.inc, kill_mysqld.inc,
8+
# restart_mysqld.inc, etc.
9+
#
10+
# ==== Implementation ====
11+
#
12+
# This relies on a debug symbol that causes the server to call
13+
# DBUG_ASSERT(0). So it only works on debug-compiled servers.
14+
#
15+
# ==== Usage ====
16+
#
17+
# [in main test: source include/have_dbug.inc]
18+
# [--let $connection_suffix = _1]
19+
# --source include/dbug_crash_all.inc
20+
#
21+
# Parameters:
22+
# $connection_suffix
23+
# By default, uses connections server_1, server_2, etc.
24+
# Set this variable to use server_1$connection_suffix,
25+
# server_2$connection_suffix, etc.
26+
27+
28+
# Tell all servers to crash
29+
--let $_rpl_server = $rpl_server_count
30+
while ($_rpl_server) {
31+
--connection server_$_rpl_server$server_suffix
32+
--echo # Crashing server_$_rpl_server$server_suffix
33+
send SET SESSION debug = 'd,crash_now';
34+
--dec $_rpl_server
35+
}
36+
37+
# Wait until connection drops
38+
--let $_rpl_server = $rpl_server_count
39+
while ($_rpl_server) {
40+
--connection server_$_rpl_server$server_suffix
41+
--error 0,1040,1053,2002,2003,2006,2013,2016,2017
42+
--reap
43+
--dec $_rpl_server
44+
}

mysql-test/include/show_rpl_debug_info.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
# with the current connection. If this variable is set, debug
3333
# info is printed only for the current connection.
3434
#
35+
# $crash_after_show_rpl_debug_info
36+
# Crash all servers at the end (using include/dbug_crash_all.inc)
37+
#
3538
# $extra_debug_info
3639
# This text is printed verbatim to the output. Useful for helper
3740
# scripts to supply extra diagnostic output.
@@ -198,5 +201,10 @@ if ($extra_debug_eval)
198201
--echo extra evaluated debug info: '$eval_result'
199202
}
200203

204+
if ($crash_after_show_rpl_debug_info)
205+
{
206+
--source include/dbug_crash_all.inc
207+
}
208+
201209
--connection $_rpl_old_con
202210
--enable_abort_on_error

mysql-test/suite/rpl_gtid/r/rpl_gtid_perfschema_applier_xa_status.result

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,30 @@ Note #### Storing MySQL user name or password information in the master info rep
55
[connection master]
66
[connection slave]
77
TRUNCATE TABLE performance_schema.events_transactions_current;
8+
---- Setup ----
89
[connection master]
910
CREATE TABLE t ( f INT) ENGINE=INNODB;
11+
---- XA PREPARE ----
1012
XA START 'xatest';
1113
INSERT INTO t VALUES (10);
1214
XA END 'xatest';
1315
XA PREPARE 'xatest';
14-
[connection slave]
15-
# Wait until SQL thread reaches desired master binlog position
16-
include/wait_for_slave_param.inc [Relay_Master_Log_File]
17-
include/wait_for_slave_param.inc [Exec_Master_Log_Pos]
16+
include/sync_slave_sql_with_master.inc
17+
# Wait for XA_STATE to become PREPARED on slave
18+
# Expecting one prepared transaction
1819
XA RECOVER;
1920
formatID gtrid_length bqual_length data
2021
1 6 0 xatest
21-
####################################################################
22-
# Asserting XA_STATE is PREPARED on Slave
23-
####################################################################
24-
include/assert.inc [Verify that XA_STATE is set PREPARED.]
22+
Waiting until gtid is MASTER_UUID:2
23+
---- XA COMMIT ----
2524
[connection master]
2625
XA COMMIT 'xatest';
2726
include/sync_slave_sql_with_master.inc
27+
# Wait for XA_STATE to become COMMITTED on slave
28+
# Expecting no prepared transactions
2829
XA RECOVER;
2930
formatID gtrid_length bqual_length data
30-
####################################################################
31-
# Asserting XA_STATE is COMMITTED on Slave
32-
####################################################################
33-
include/assert.inc [Verify that XA_STATE is set COMMITTED.]
34-
include/assert.inc [Expected gtid is MASTER_UUID:3]
31+
Waiting until gtid is MASTER_UUID:3
3532
include/diff_tables.inc [master:t,slave:t]
3633
[connection master]
3734
DROP TABLE t;
@@ -52,33 +49,30 @@ SET GLOBAL slave_parallel_type='DATABASE';
5249
include/start_slave.inc
5350
[connection slave]
5451
TRUNCATE TABLE performance_schema.events_transactions_current;
52+
---- Setup ----
5553
[connection master]
5654
CREATE TABLE t ( f INT) ENGINE=INNODB;
55+
---- XA PREPARE ----
5756
XA START 'xatest';
5857
INSERT INTO t VALUES (10);
5958
XA END 'xatest';
6059
XA PREPARE 'xatest';
61-
[connection slave]
62-
# Wait until SQL thread reaches desired master binlog position
63-
include/wait_for_slave_param.inc [Relay_Master_Log_File]
64-
include/wait_for_slave_param.inc [Exec_Master_Log_Pos]
60+
include/sync_slave_sql_with_master.inc
61+
# Wait for XA_STATE to become PREPARED on slave
62+
# Expecting one prepared transaction
6563
XA RECOVER;
6664
formatID gtrid_length bqual_length data
6765
1 6 0 xatest
68-
####################################################################
69-
# Asserting XA_STATE is PREPARED on Slave
70-
####################################################################
71-
include/assert.inc [Verify that XA_STATE is set PREPARED.]
66+
Waiting until gtid is MASTER_UUID:2
67+
---- XA COMMIT ----
7268
[connection master]
7369
XA COMMIT 'xatest';
7470
include/sync_slave_sql_with_master.inc
71+
# Wait for XA_STATE to become COMMITTED on slave
72+
# Expecting no prepared transactions
7573
XA RECOVER;
7674
formatID gtrid_length bqual_length data
77-
####################################################################
78-
# Asserting XA_STATE is COMMITTED on Slave
79-
####################################################################
80-
include/assert.inc [Verify that XA_STATE is set COMMITTED.]
81-
include/assert.inc [Expected gtid is MASTER_UUID:3]
75+
Waiting until gtid is MASTER_UUID:3
8276
include/diff_tables.inc [master:t,slave:t]
8377
[connection master]
8478
DROP TABLE t;
@@ -96,33 +90,30 @@ SET GLOBAL slave_parallel_type='LOGICAL_CLOCK';
9690
include/start_slave.inc
9791
[connection slave]
9892
TRUNCATE TABLE performance_schema.events_transactions_current;
93+
---- Setup ----
9994
[connection master]
10095
CREATE TABLE t ( f INT) ENGINE=INNODB;
96+
---- XA PREPARE ----
10197
XA START 'xatest';
10298
INSERT INTO t VALUES (10);
10399
XA END 'xatest';
104100
XA PREPARE 'xatest';
105-
[connection slave]
106-
# Wait until SQL thread reaches desired master binlog position
107-
include/wait_for_slave_param.inc [Relay_Master_Log_File]
108-
include/wait_for_slave_param.inc [Exec_Master_Log_Pos]
101+
include/sync_slave_sql_with_master.inc
102+
# Wait for XA_STATE to become PREPARED on slave
103+
# Expecting one prepared transaction
109104
XA RECOVER;
110105
formatID gtrid_length bqual_length data
111106
1 6 0 xatest
112-
####################################################################
113-
# Asserting XA_STATE is PREPARED on Slave
114-
####################################################################
115-
include/assert.inc [Verify that XA_STATE is set PREPARED.]
107+
Waiting until gtid is MASTER_UUID:2
108+
---- XA COMMIT ----
116109
[connection master]
117110
XA COMMIT 'xatest';
118111
include/sync_slave_sql_with_master.inc
112+
# Wait for XA_STATE to become COMMITTED on slave
113+
# Expecting no prepared transactions
119114
XA RECOVER;
120115
formatID gtrid_length bqual_length data
121-
####################################################################
122-
# Asserting XA_STATE is COMMITTED on Slave
123-
####################################################################
124-
include/assert.inc [Verify that XA_STATE is set COMMITTED.]
125-
include/assert.inc [Expected gtid is MASTER_UUID:3]
116+
Waiting until gtid is MASTER_UUID:3
126117
include/diff_tables.inc [master:t,slave:t]
127118
[connection master]
128119
DROP TABLE t;

sql/sql_parse.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3277,6 +3277,15 @@ int mysql_execute_command(THD *thd, bool first_level) {
32773277
goto error;
32783278
}
32793279

3280+
#ifndef DBUG_OFF
3281+
/*
3282+
Makes server crash when executing SET SESSION debug = 'd,crash_now';
3283+
See mysql-test/include/dbug_crash[_all].inc
3284+
*/
3285+
bool force_server_crash_dbug = false;
3286+
DBUG_EXECUTE_IF("crash_now", DBUG_ASSERT(force_server_crash_dbug););
3287+
#endif
3288+
32803289
break;
32813290
}
32823291
case SQLCOM_SET_PASSWORD: {

0 commit comments

Comments
 (0)