| 1 |
############################################# |
| 2 |
#Purpose: Generic replication from Innodb to NDB |
| 3 |
# using binlog_format defined by caller |
| 4 |
# and ensuring that the ndb_apply_status |
| 5 |
# table is updated. |
| 6 |
############################################# |
| 7 |
# |
| 8 |
# The ndb_apply_status table contains information about the binlog on |
| 9 |
# source, the log_name is the file name, start_pos and end_pos relates |
| 10 |
# to positions of the current "group" where end_pos = start_pos + length(group). |
| 11 |
# |
| 12 |
# A group in the binlog is normally a query/transaction with BEGIN/COMMIT as |
| 13 |
# well as any preceding events containing state. |
| 14 |
# |
| 15 |
# For example queries like this: |
| 16 |
# mysql> BEGIN |
| 17 |
# mysql> UPDATE tpcb.account SET b=1 WHERE pk=4 |
| 18 |
# mysql> UPDATE tpcb.branch SET b=2 WHERE pk=3 |
| 19 |
# mysql> COMMIT |
| 20 |
# |
| 21 |
# would create this group: |
| 22 |
# binlog.001 419917 Anonymous_Gtid 1 419996 SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| 23 |
# binlog.001 419996 Query 1 420080 BEGIN |
| 24 |
# binlog.001 420080 Table_map 1 420145 table_id: 271 (tpcb.account) |
| 25 |
# binlog.001 420145 Update_rows 1 420241 table_id: 271 flags: STMT_END_F |
| 26 |
# binlog.001 420241 Table_map 1 420304 table_id: 272 (tpcb.branch) |
| 27 |
# binlog.001 420304 Update_rows 1 420392 table_id: 272 flags: STMT_END_F |
| 28 |
# binlog.001 420753 Xid 1 420784 COMMIT /* xid=5090 */ |
| 29 |
# |
| 30 |
# Then log_name = binlog.001, start_pos = 419917 and end_pos = 420784 should |
| 31 |
# end up in ndb_apply_status on replica when this group has been replicated. |
| 32 |
# |
| 33 |
# ############################################### |
| 34 |
# Notes: |
| 35 |
# |
| 36 |
# Check contents of ndb_aply_status on replica by: |
| 37 |
# |
| 38 |
# 1) Save binlog file and position before query (on source), this should then |
| 39 |
# show up as "log_name" and "start_pos" in ndb_apply_status (on replica) |
| 40 |
# when change has been replicated. |
| 41 |
# |
| 42 |
# 2) Save binlog position after query (on source), this should then show |
| 43 |
# up as "end_pos" in ndb_apply_status (on replica) when change has |
| 44 |
# been applied replicated. |
| 45 |
# |
| 46 |
# select_ndb_apply_status.inc |
| 47 |
# Selects out the log name and start pos |
| 48 |
# from the ndb_apply_status table on replica and compare with the expected |
| 49 |
# values from 1) and 2) saved when executing the query/transaction. |
| 50 |
# Print relevant debugging information if the positions does not align, |
| 51 |
# then fail the test. |
| 52 |
# |
| 53 |
# include/tpcb.inc |
| 54 |
# Creates DATABASE tpcb, the tables and |
| 55 |
# stored procedures for loading the DB |
| 56 |
# and for running transactions against DB. |
| 57 |
############################################## |
| 58 |
|
| 59 |
--source include/rpl_connection_master.inc |
| 60 |
|
| 61 |
create table t1 (a int key, b int) engine innodb; |
| 62 |
create table t2 (a int key, b int) engine innodb; |
| 63 |
|
| 64 |
let $master_server_id = `select @@server_id`; |
| 65 |
#echo master_server_id: $master_server_id; |
| 66 |
|
| 67 |
--echo |
| 68 |
|
| 69 |
--source include/sync_slave_sql_with_master.inc |
| 70 |
alter table t1 engine ndb; |
| 71 |
alter table t2 engine ndb; |
| 72 |
|
| 73 |
--echo |
| 74 |
--echo *** Test 1 *** |
| 75 |
--echo |
| 76 |
|
| 77 |
# check binlog position without begin |
| 78 |
--source include/rpl_connection_master.inc |
| 79 |
|
| 80 |
let $source_file= query_get_value(SHOW MASTER STATUS, File, 1); |
| 81 |
let $source_start_pos= query_get_value(SHOW MASTER STATUS, Position, 1); |
| 82 |
|
| 83 |
insert into t1 values (1,2); |
| 84 |
|
| 85 |
let $source_end_pos= query_get_value(SHOW MASTER STATUS, Position, 1); |
| 86 |
|
| 87 |
# Show the binlog events recorded for above change |
| 88 |
let $binlog_file = $source_file; |
| 89 |
let $binlog_start = $source_start_pos; |
| 90 |
--source include/show_binlog_events.inc |
| 91 |
|
| 92 |
--source include/sync_slave_sql_with_master.inc |
| 93 |
--source suite/ndb_rpl/t/select_ndb_apply_status.inc |
| 94 |
|
| 95 |
--echo |
| 96 |
--echo *** Test 1B *** |
| 97 |
--echo |
| 98 |
--source include/rpl_connection_master.inc |
| 99 |
|
| 100 |
let $source_file= query_get_value(SHOW MASTER STATUS, File, 1); |
| 101 |
let $source_start_pos= query_get_value(SHOW MASTER STATUS, Position, 1); |
| 102 |
|
| 103 |
# check binlog position with begin |
| 104 |
begin; |
| 105 |
insert into t1 values (2,3); |
| 106 |
insert into t2 values (3,4); |
| 107 |
commit; |
| 108 |
|
| 109 |
let $source_end_pos= query_get_value(SHOW MASTER STATUS, Position, 1); |
| 110 |
|
| 111 |
# Show the binlog events recorded for above change |
| 112 |
let $binlog_file = $source_file; |
| 113 |
let $binlog_start = $source_start_pos; |
| 114 |
--source include/show_binlog_events.inc |
| 115 |
|
| 116 |
--source include/sync_slave_sql_with_master.inc |
| 117 |
--source suite/ndb_rpl/t/select_ndb_apply_status.inc |
| 118 |
|
| 119 |
# Cleanup after test 1 and test 2 |
| 120 |
--source include/rpl_connection_master.inc |
| 121 |
DROP TABLE test.t1, test.t2; |
| 122 |
--source include/sync_slave_sql_with_master.inc |
| 123 |
SHOW TABLES; |
| 124 |
|
| 125 |
--echo |
| 126 |
--echo *** Test 2 *** |
| 127 |
--echo |
| 128 |
|
| 129 |
# Run in some transactions using stored procedures |
| 130 |
# and ensure that the ndb_apply_status table is |
| 131 |
# updated to show the transactions |
| 132 |
--source include/rpl_connection_master.inc |
| 133 |
|
| 134 |
# Create database/tables and stored procdures |
| 135 |
--source include/tpcb.inc |
| 136 |
|
| 137 |
# Switch tables on slave to use NDB |
| 138 |
--source include/sync_slave_sql_with_master.inc |
| 139 |
USE tpcb; |
| 140 |
ALTER TABLE account ENGINE NDB; |
| 141 |
ALTER TABLE branch ENGINE NDB; |
| 142 |
ALTER TABLE teller ENGINE NDB; |
| 143 |
ALTER TABLE history ENGINE NDB; |
| 144 |
|
| 145 |
# Load DB tpcb and run some transactions |
| 146 |
--source include/rpl_connection_master.inc |
| 147 |
|
| 148 |
--disable_query_log |
| 149 |
CALL tpcb.load(); |
| 150 |
SET AUTOCOMMIT=0; |
| 151 |
let $run= 5; |
| 152 |
while ($run) |
| 153 |
{ |
| 154 |
START TRANSACTION; |
| 155 |
--eval CALL tpcb.trans($rpl_format); |
| 156 |
let $run_bad= $mysql_errno; |
| 157 |
if (!$run_bad) |
| 158 |
{ |
| 159 |
let $source_file= query_get_value(SHOW MASTER STATUS, File, 1); |
| 160 |
let $source_start_pos= query_get_value(SHOW MASTER STATUS, Position, 1); |
| 161 |
|
| 162 |
COMMIT; |
| 163 |
echo COMMIT; |
| 164 |
} |
| 165 |
if ($run_bad) |
| 166 |
{ |
| 167 |
ROLLBACK; |
| 168 |
echo ROLLBACK; |
| 169 |
} |
| 170 |
dec $run; |
| 171 |
} |
| 172 |
|
| 173 |
SET AUTOCOMMIT=1; |
| 174 |
--enable_query_log |
| 175 |
|
| 176 |
let $source_end_pos= query_get_value(SHOW MASTER STATUS, Position, 1); |
| 177 |
|
| 178 |
# Show the binlog events recorded for last part of above change |
| 179 |
let $binlog_file = $source_file; |
| 180 |
let $binlog_start = $source_start_pos; |
| 181 |
let $binlog_limit = $off_set, 1; # Show only the last COMMIT event in group |
| 182 |
--source include/show_binlog_events.inc |
| 183 |
|
| 184 |
--source include/sync_slave_sql_with_master.inc |
| 185 |
--source suite/ndb_rpl/t/select_ndb_apply_status.inc |
| 186 |
|
| 187 |
--echo |
| 188 |
--echo ** Test 3 ** |
| 189 |
--echo |
| 190 |
|
| 191 |
# Flush the logs on the master moving all |
| 192 |
# Transaction to a new binlog and ensure |
| 193 |
# that the ndb_apply_status table is updated |
| 194 |
# to show the use of the new binlog. |
| 195 |
--source include/rpl_connection_master.inc |
| 196 |
|
| 197 |
# Flush logs on master which should force it |
| 198 |
# to switch to binlog #2 |
| 199 |
|
| 200 |
FLUSH LOGS; |
| 201 |
|
| 202 |
# Run in some transaction to increase end pos in |
| 203 |
# binlog |
| 204 |
|
| 205 |
--disable_query_log |
| 206 |
SET AUTOCOMMIT=0; |
| 207 |
let $run= 5; |
| 208 |
while ($run) |
| 209 |
{ |
| 210 |
START TRANSACTION; |
| 211 |
--eval CALL tpcb.trans($rpl_format); |
| 212 |
let $run_bad= $mysql_errno; |
| 213 |
if (!$run_bad) |
| 214 |
{ |
| 215 |
let $source_file= query_get_value(SHOW MASTER STATUS, File, 1); |
| 216 |
let $source_start_pos= query_get_value(SHOW MASTER STATUS, Position, 1); |
| 217 |
|
| 218 |
COMMIT; |
| 219 |
echo COMMIT; |
| 220 |
} |
| 221 |
if ($run_bad) |
| 222 |
{ |
| 223 |
ROLLBACK; |
| 224 |
echo ROLLBACK; |
| 225 |
} |
| 226 |
dec $run; |
| 227 |
} |
| 228 |
SET AUTOCOMMIT=1; |
| 229 |
--enable_query_log |
| 230 |
|
| 231 |
let $source_end_pos= query_get_value(SHOW MASTER STATUS, Position, 1); |
| 232 |
|
| 233 |
# Show the binlog events recorded for last part of above change |
| 234 |
let $binlog_file = $source_file; |
| 235 |
let $binlog_start = $source_start_pos; |
| 236 |
let $binlog_limit = $off_set, 1; # Show only the last COMMIT event in group |
| 237 |
--source include/show_binlog_events.inc |
| 238 |
|
| 239 |
--source include/sync_slave_sql_with_master.inc |
| 240 |
--source suite/ndb_rpl/t/select_ndb_apply_status.inc |
| 241 |
|
| 242 |
--echo |
| 243 |
--echo ** Test 4 ** |
| 244 |
--echo |
| 245 |
|
| 246 |
# Now we reset both the master and the slave |
| 247 |
# Run some more transaction and ensure |
| 248 |
# that the ndb_apply_status is updated |
| 249 |
# correctly |
| 250 |
|
| 251 |
--source include/rpl_connection_master.inc |
| 252 |
|
| 253 |
# Reset both slave and master |
| 254 |
# This should reset binlog to #1 |
| 255 |
--source include/rpl_reset.inc |
| 256 |
|
| 257 |
--echo |
| 258 |
|
| 259 |
# Run in some transactions and check |
| 260 |
--source include/rpl_connection_master.inc |
| 261 |
--disable_query_log |
| 262 |
SET AUTOCOMMIT=0; |
| 263 |
let $run= 5; |
| 264 |
while ($run) |
| 265 |
{ |
| 266 |
START TRANSACTION; |
| 267 |
--eval CALL tpcb.trans($rpl_format); |
| 268 |
let $run_bad= $mysql_errno; |
| 269 |
if (!$run_bad) |
| 270 |
{ |
| 271 |
let $source_file= query_get_value(SHOW MASTER STATUS, File, 1); |
| 272 |
let $source_start_pos= query_get_value(SHOW MASTER STATUS, Position, 1); |
| 273 |
|
| 274 |
COMMIT; |
| 275 |
echo COMMIT; |
| 276 |
} |
| 277 |
if ($run_bad) |
| 278 |
{ |
| 279 |
ROLLBACK; |
| 280 |
echo ROLLBACK; |
| 281 |
} |
| 282 |
dec $run; |
| 283 |
} |
| 284 |
SET AUTOCOMMIT=1; |
| 285 |
--enable_query_log |
| 286 |
|
| 287 |
let $source_end_pos= query_get_value(SHOW MASTER STATUS, Position, 1); |
| 288 |
|
| 289 |
# Show the binlog events recorded for last part of above change |
| 290 |
let $binlog_file = $source_file; |
| 291 |
let $binlog_start = $source_start_pos; |
| 292 |
let $binlog_limit = $off_set, 1; # Show only the last COMMIT event in group |
| 293 |
--source include/show_binlog_events.inc |
| 294 |
|
| 295 |
--source include/sync_slave_sql_with_master.inc |
| 296 |
--source suite/ndb_rpl/t/select_ndb_apply_status.inc |
| 297 |
|
| 298 |
# Since we are doing replication, it is a good |
| 299 |
# idea to check to make sure all data was |
| 300 |
# Replicated correctly |
| 301 |
|
| 302 |
--let $diff_tables= tpcb.account, master:tpcb.account |
| 303 |
--source include/diff_tables.inc |
| 304 |
|
| 305 |
--let $diff_tables= tpcb.teller, master:tpcb.teller |
| 306 |
--source include/diff_tables.inc |
| 307 |
|
| 308 |
--let $diff_tables= tpcb.branch, master:tpcb.branch |
| 309 |
--source include/diff_tables.inc |
| 310 |
|
| 311 |
--let $diff_tables= tpcb.history, master:tpcb.history |
| 312 |
--source include/diff_tables.inc |
| 313 |
|
| 314 |
--source include/rpl_connection_master.inc |
| 315 |
DROP DATABASE tpcb; |
| 316 |
|
| 317 |
--source include/sync_slave_sql_with_master.inc |