1############################################################################### 2# This include file is created to test local transaction's behaviour 3# (conflict/success) against a transaction that is ordered first 4# on a remote server and broadcasted to local server. 5# 6# 1. Set a debug sync before broadcast message to group on local server. 7# 2. Commit a transaction (called local transaction) that will be blocked 8# before broadcast. 9# 3. Wait until local server reaches the debug sync point. 10# 4. Execute a transaction on remote server (called remote transaction), that 11# will reach first certification, since local transaction is blocked before 12# broadcast. 13# 5. Signal the waiting thread on local server to resume. 14# 6. Wait for remote transaction to be executed succesfully on local server. 15# 7. Check the local transaction behaviour (depends on the scenario, it should be 16# rolled back (conflict scenario) or it should succesfully commit(success scenario). 17# 8. Sync everything. 18# 9. Assert that number of certified transactions are the expected ones. 19#10. Assert that GTID is increased as expected. 20#11. Cleanup (restore the connection back to original) 21# 22# ##### Usage ####### 23# 24# --let $local_server_connection1=server_1 25# --let $local_server_connection2=server1 26# --let $remote_server_connection=server2 27# --let $local_transaction= INSERT INTO t2 VALUES (5); INSERT INTO t1 VALUES (5); 28# --let $remote_transaction=UPDATE t1 SET c1=6 WHERE c1=2 29# --let $conflict_test=1 30# --source ../inc/gr_parallel_local_and_remote_transactions.inc 31# 32# ##### Parameters ##### 33# 34# $local_server_connection1 35# Connection name on which the $local_transaction needs to be executed. 36# 37# $local_server_connection2 38# Connection name on which debug sync commands can be executed to block 39# local transaction before broadcasting. 40# 41# $remote_server_connection 42# Connection name on which the $remote_transaction needs to be executed. 43# 44# $local_transaction 45# The transaction statements that needs to be executed on local server. 46# If there are more than one statement, they should be specified in the same 47# line with semicolon(;) as delimiter. 48# Eg: --let $local_transaction= INSERT INTO t2 VALUES (5); INSERT INTO t1 VALUES (5); 49# 50# $remote_transaction 51# The transaction statements that needs to be executed on remote server. 52# If there are more than one statement, they should be specified in the same 53# line with semicolon(;) as delimiter. 54# Eg: --let $remote_transaction= INSERT INTO t2 VALUES (5); INSERT INTO t1 VALUES (5); 55# 56# $conflict_test 57# 0 or 1 depends on the testing scenario. 58# If the test case is conflict scenario(1), local transaction 59# should end up in an error stating that it was aborted, 60# since transactions are conflicting and transaction on 61# remote server was ordered first. 62# If the test case is is positive scenario(0), 63# no error will be seen while executing local transaction and 64# should be committed succesfully. 65# 66# P.S: This .inc will restore the original connection back. 67# 68--echo 69--echo ############################################################ 70--echo # 0. Initial setup and checks. 71 72-- let $old_conn= $CURRENT_CONNECTION 73if (!$local_server_connection1) 74{ 75 --die !!!ERROR IN TEST: you must set $local_server_connection1 on which the local_transaction needs to be executed. 76} 77if (!$local_server_connection2) 78{ 79 --die !!!ERROR IN TEST: you must set $local_server_connection2 on which debug sync needs to be set to block the broadcast. 80} 81if (!$remote_server_connection) 82{ 83 --die !!!ERROR IN TEST: you must set $remote_server_connection on which the remote_transaction needs to be executed. 84} 85if (!$local_transaction) 86{ 87 --die !!!ERROR IN TEST: you must set $local_transaction which will be executed on local_server_connection1. 88} 89if (!$remote_transaction) 90{ 91 --die !!!ERROR IN TEST: you must set $remote_transaction which will be executed on remote_server_connection. 92} 93 94--let $rpl_connection_name= $local_server_connection1 95--source include/rpl_connection.inc 96 97# Include gtid_utils if it is not included already 98if (!$gtid_util_included) 99{ 100 SET SESSION sql_log_bin= 0; 101 --source include/gtid_utils.inc 102 SET SESSION sql_log_bin= 1; 103 --let $gtid_utils_installed= 1; 104} 105# Remember the gtid position 106--source include/gtid_step_reset.inc 107--let $prev_certified_transactions= query_get_value(SELECT Count_Transactions_Checked from performance_schema.replication_group_member_stats, Count_Transactions_Checked, 1) 108--let $prev_negatively_certified= query_get_value(SELECT Count_Conflicts_Detected from performance_schema.replication_group_member_stats, Count_Conflicts_Detected, 1) 109 110--echo 111--echo ############################################################ 112--echo # 1. Set a debug sync before broadcast message to group on 113--echo # connection local_server_connection1. 114--let $rpl_connection_name= $local_server_connection1 115--source include/rpl_connection.inc 116SET @debug_save= @@GLOBAL.DEBUG; 117SET @@GLOBAL.DEBUG='d,group_replication_before_message_broadcast'; 118 119--echo 120--echo ##################################################################### 121--echo # 2. Commit local_transaction that will be blocked before broadcast. 122BEGIN; 123--eval $local_transaction 124--send COMMIT 125 126--echo 127--echo ############################################################ 128--echo # 3. Wait until local transaction reaches the 129--echo # group_replication_before_message_broadcast debug sync point. 130--let $rpl_connection_name= $local_server_connection2 131--source include/rpl_connection.inc 132--let $wait_condition=SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State = 'debug sync point: now' 133--source include/wait_condition.inc 134 135--echo 136--echo ############################################################ 137--echo # 4. Execute a transaction on remote server, that will reach first 138--echo # certification, since transaction on the local server 139--echo # is blocked before broadcast. 140--let $rpl_connection_name= $remote_server_connection 141--source include/rpl_connection.inc 142BEGIN; 143--eval $remote_transaction 144COMMIT; 145 146--echo 147--echo ############################################################ 148--echo # 5. Signal the waiting thread on local server to resume the 149--echo # transaction. 150--let $rpl_connection_name= $local_server_connection2 151--source include/rpl_connection.inc 152SET DEBUG_SYNC='now SIGNAL waiting'; 153SET @@GLOBAL.DEBUG= @debug_save; 154 155 156--echo 157--echo ############################################################ 158--echo # 6. Wait for remote transaction to be executed succesfully 159--echo on local server. 160--let $rpl_connection_name= $remote_server_connection 161--source include/rpl_connection.inc 162--let $sync_slave_connection= $local_server_connection2 163--source include/sync_slave_sql_with_master.inc 164 165--echo ############################################################ 166--echo # 7. If the test case is conflict scenario, local transaction 167--echo # will end up in an error stating that it was aborted, 168--echo # since transactions are conflicting and transaction on 169--echo # remote server was ordered first. If the test case is 170--echo # is positive scenario, no error will be seen here. 171--let $rpl_connection_name= $local_server_connection1 172--source include/rpl_connection.inc 173if ($conflict_test) 174{ 175 --error ER_TRANSACTION_ROLLBACK_DURING_COMMIT 176} 177--reap 178 179--let $rpl_connection_name= $local_server_connection1 180--source include/rpl_connection.inc 181SET @@GLOBAL.DEBUG=@debug_save; 182 183--echo ############################################################ 184--echo # 8. Sync everything 185--source include/rpl_sync.inc 186 187--echo ############################################################ 188--echo # 9. Assert that number of certified transactions are the 189--echo # expected ones. 190--let $expected_certified_transactions= `SELECT $prev_certified_transactions + 2` 191--let $certified_transactions= query_get_value(SELECT Count_Transactions_Checked from performance_schema.replication_group_member_stats, Count_Transactions_Checked, 1) 192--let $assert_text= The value of Count_Transactions_Checked should be $expected_certified_transactions after starting group replication 193--let $assert_cond= "$certified_transactions" = $expected_certified_transactions 194--source include/assert.inc 195 196--let $expected_negatively_certified_transactions= `SELECT $prev_negatively_certified + $conflict_test` 197--let $negatively_certified= query_get_value(SELECT Count_Conflicts_Detected from performance_schema.replication_group_member_stats, Count_Conflicts_Detected, 1) 198--let $assert_text= The value of Count_Conflicts_Detected should be $expected_negatively_certified_transactions after starting group replication 199--let $assert_cond= "$negatively_certified" = $expected_negatively_certified_transactions 200--source include/assert.inc 201 202--echo ############################################################ 203--echo # 10. Assert that GTID is increased as expected 204--let $gtid_step_count= `SELECT 2 - $conflict_test` 205--let $gtid_step_uuid=`SELECT @@global.group_replication_group_name` 206--let $gtid_step_only_count= 1 207--source include/gtid_step_assert.inc 208 209# uninstall gtid_utils if it is installed by this file. 210if ($gtid_utils_installed) 211{ 212 --let $rpl_connection_name= $local_server_connection1 213 --source include/rpl_connection.inc 214 SET SESSION sql_log_bin= 0; 215 --source include/gtid_utils_end.inc 216 SET SESSION sql_log_bin= 1; 217} 218 219--echo ############################################################ 220--echo # 11. Cleanup (restore the connection back to original) 221--let $rpl_connection_name= $old_conn 222--source include/rpl_connection.inc 223