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