1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
#
# The purpose of this test is to demonstrate:
# 1) The behaviour of the before_commit hook placed in binlog.cc and all
# possible return values.
# 2) All the possible ramifications of the execution of the Transaction Context
# Service and its behaviour in the server.
#
# One will then test:
# 1) before_commit failure
# 2) Transaction Context Service reports that parameters are invalid
# 3) Transaction Context Service reports that the transaction must abort
# 4) Transaction Context Service reports OK without generating a GTID
# 5) Transaction Context Service reports OK generating a GTID internally
#
--source include/have_debug.inc
--source include/not_group_replication_plugin.inc
--source include/not_have_privilege_checks_user.inc
--source include/install_replication_observers_example.inc
--let $rpl_gtid_utils=1
--source include/master-slave.inc
--echo #
--echo # Set up test
--echo #
--let $master_uuid= `SELECT @@GLOBAL.SERVER_UUID`
CREATE TABLE t1 (c1 INT PRIMARY KEY) Engine=InnoDB;
--echo #
--echo # Case 1. This will cause the before_commit hook to fail. As a
--echo # consequence, the whole transaction shall fail.
--echo #
SET @debug_saved= @@GLOBAL.DEBUG;
SET @@GLOBAL.DEBUG= '+d,force_error_on_before_commit_listener';
SET SESSION sql_log_bin= 0;
call mtr.add_suppression("Run function 'before_commit' in plugin");
SET SESSION sql_log_bin= 1;
BEGIN;
INSERT t1 VALUES(1);
--error ER_RUN_HOOK_ERROR
COMMIT;
--error ER_RUN_HOOK_ERROR
INSERT t1 VALUES(2);
--let $assert_text= GTID_EXECUTED must remain the same
--let $assert_cond= GTID_IS_EQUAL(@@GLOBAL.GTID_EXECUTED, "$master_uuid:1")
--source include/assert.inc
--let $assert_text= Table must remain empty
--let $assert_cond= "[SELECT COUNT(*) FROM t1]" = "0"
--source include/assert.inc
--source include/sync_slave_sql_with_master.inc
--let $assert_text= GTID_EXECUTED must remain the same
--let $assert_cond= GTID_IS_EQUAL(@@GLOBAL.GTID_EXECUTED, "$master_uuid:1")
--source include/assert.inc
--let $assert_text= Table must remain empty
--let $assert_cond= "[SELECT COUNT(*) FROM t1]" = "0"
--source include/assert.inc
--connection master
SET @@GLOBAL.DEBUG='';
--echo #
--echo # Case 2. This will force the Transaction Context to report an invalid
--echo # transaction certification outcome,
--echo #
SET @@GLOBAL.DEBUG= '+d,force_invalid_certification_outcome';
SET SESSION sql_log_bin= 0;
call mtr.add_suppression("Plugin replication_observers_example reported: 'Unable to update transaction context service on server, thread_id:.*");
SET SESSION sql_log_bin= 1;
BEGIN;
INSERT t1 VALUES(1);
--error ER_RUN_HOOK_ERROR
COMMIT;
--error ER_RUN_HOOK_ERROR
INSERT t1 VALUES(2);
--let $assert_text= GTID_EXECUTED must remain the same
--let $assert_cond= GTID_IS_EQUAL(@@GLOBAL.GTID_EXECUTED, "$master_uuid:1")
--source include/assert.inc
--let $assert_text= Table must remain empty
--let $assert_cond= "[SELECT COUNT(*) FROM t1]" = "0"
--source include/assert.inc
--source include/sync_slave_sql_with_master.inc
--let $assert_text= GTID_EXECUTED must remain the same
--let $assert_cond= GTID_IS_EQUAL(@@GLOBAL.GTID_EXECUTED, "$master_uuid:1")
--source include/assert.inc
--let $assert_text= Table must remain empty
--let $assert_cond= "[SELECT COUNT(*) FROM t1]" = "0"
--source include/assert.inc
--connection master
SET @@GLOBAL.DEBUG='';
--echo #
--echo # Case 3. This will force the Transaction Context to report an negative
--echo # transaction certification outcome,
--echo #
SET @@GLOBAL.DEBUG= '+d,force_negative_certification_outcome';
BEGIN;
INSERT t1 VALUES(1);
--error ER_TRANSACTION_ROLLBACK_DURING_COMMIT
COMMIT;
--error ER_TRANSACTION_ROLLBACK_DURING_COMMIT
INSERT t1 VALUES(2);
--let $assert_text= GTID_EXECUTED must remain the same
--let $assert_cond= GTID_IS_EQUAL(@@GLOBAL.GTID_EXECUTED, "$master_uuid:1")
--source include/assert.inc
--let $assert_text= Table must remain empty
--let $assert_cond= "[SELECT COUNT(*) FROM t1]" = "0"
--source include/assert.inc
--source include/sync_slave_sql_with_master.inc
--let $assert_text= GTID_EXECUTED must remain the same
--let $assert_cond= GTID_IS_EQUAL(@@GLOBAL.GTID_EXECUTED, "$master_uuid:1")
--source include/assert.inc
--let $assert_text= Table must remain empty
--let $assert_cond= "[SELECT COUNT(*) FROM t1]" = "0"
--source include/assert.inc
--connection master
SET @@GLOBAL.DEBUG='';
--echo #
--echo # Case 4. This will force the Transaction Context to report a valid
--echo # outcome without generating a GTID.
--echo #
SET @@GLOBAL.DEBUG= '+d,force_positive_certification_outcome_without_gtid';
BEGIN;
INSERT t1 VALUES(1);
COMMIT;
INSERT t1 VALUES(2);
--query_vertical SELECT * FROM t1;
--let $assert_text= At this point we should have 2 successful operations
--let $assert_cond= "[SELECT @@GLOBAL.GTID_EXECUTED]" = "$master_uuid:1-3"
--source include/assert.inc
--source include/sync_slave_sql_with_master.inc
--let $assert_text= At this point we should have 2 successful operations
--let $assert_cond= "[SELECT @@GLOBAL.GTID_EXECUTED]" = "$master_uuid:1-3"
--source include/assert.inc
--connection master
SET @@GLOBAL.DEBUG='';
--echo #
--echo # Case 5. This will force the Transaction Context to report a valid
--echo # outcome generating a GTID
--echo #
SET @@GLOBAL.DEBUG= '+d,force_positive_certification_outcome_with_gtid';
BEGIN;
INSERT t1 VALUES(3);
COMMIT;
INSERT t1 VALUES(4);
--query_vertical SELECT * FROM t1;
--let $assert_text= GTID_EXECUTED must contain all GTIDs with the server id and with the fake id
--let $assert_cond= GTID_IS_EQUAL(@@GLOBAL.GTID_EXECUTED, "$master_uuid:1-3,$uuida:1-2")
--source include/assert.inc
--source include/sync_slave_sql_with_master.inc
--let $assert_text= GTID_EXECUTED must contain all GTIDs with the server id and with the fake id
--let $assert_cond= GTID_IS_EQUAL(@@GLOBAL.GTID_EXECUTED, "$master_uuid:1-3,$uuida:1-2")
--source include/assert.inc
--echo #
--echo # Clean up
--echo #
--connection master
SET @@GLOBAL.DEBUG= @debug_saved;
DROP TABLE t1;
--source include/rpl_end.inc
--source include/uninstall_replication_observers_example.inc
--echo End of test
|