| 1 |
# |
| 2 |
# Test engine native conflict resolution for ndb |
| 3 |
# NDB$EPOCH() function |
| 4 |
# |
| 5 |
# |
| 6 |
--source include/have_ndb.inc |
| 7 |
--source include/have_binlog_format_mixed_or_row.inc |
| 8 |
--source suite/ndb_rpl/ndb_master-slave.inc |
| 9 |
|
| 10 |
--echo Setup circular replication |
| 11 |
--echo The circle is setup between Primary and Secondary |
| 12 |
|
| 13 |
--disable_query_log |
| 14 |
--disable_result_log |
| 15 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 16 |
# Gather port + serverid |
| 17 |
|
| 18 |
select @primary_server_id:=(variable_value+0) |
| 19 |
from performance_schema.global_variables |
| 20 |
where variable_name like 'server_id'; |
| 21 |
let $PRIMARY_SERVER_ID= query_get_value('select @primary_server_id as v',v,1); |
| 22 |
select @primary_server_port:=(variable_value+0) |
| 23 |
from performance_schema.global_variables |
| 24 |
where variable_name like 'port'; |
| 25 |
let $PRIMARY_SERVER_PORT= query_get_value('select @primary_server_port as v', v,1); |
| 26 |
|
| 27 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 28 |
# Gather port + serverid |
| 29 |
select @secondary_server_id:=(variable_value+0) |
| 30 |
from performance_schema.global_variables |
| 31 |
where variable_name like 'server_id'; |
| 32 |
let $SECONDARY_SERVER_ID= query_get_value('select @secondary_server_id as v',v,1); |
| 33 |
select @secondary_server_port:=(variable_value+0) |
| 34 |
from performance_schema.global_variables |
| 35 |
where variable_name like 'port'; |
| 36 |
let $SECONDARY_SERVER_PORT= query_get_value('select @secondary_server_port as v', v,1); |
| 37 |
|
| 38 |
# Now set it up |
| 39 |
# Stop Slave @ Secondary |
| 40 |
STOP REPLICA; |
| 41 |
# Clear Secondary Binlog |
| 42 |
RESET MASTER; |
| 43 |
|
| 44 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 45 |
# Stop Slave @ Primary |
| 46 |
STOP REPLICA; |
| 47 |
# Clear Primary Binlog |
| 48 |
RESET MASTER; |
| 49 |
|
| 50 |
--eval CHANGE REPLICATION SOURCE TO SOURCE_HOST="127.0.0.1",SOURCE_PORT=$SECONDARY_SERVER_PORT,SOURCE_USER="root" |
| 51 |
|
| 52 |
# Start Primary replicating from Secondary |
| 53 |
START REPLICA; |
| 54 |
|
| 55 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 56 |
--eval CHANGE REPLICATION SOURCE TO SOURCE_HOST="127.0.0.1",SOURCE_PORT=$PRIMARY_SERVER_PORT,SOURCE_USER="root" |
| 57 |
|
| 58 |
# Start Secondary replicating from Primary |
| 59 |
START REPLICA; |
| 60 |
|
| 61 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 62 |
|
| 63 |
--enable_query_log |
| 64 |
--enable_result_log |
| 65 |
|
| 66 |
--echo Setup ndb_replication and t1$EX exceptions table |
| 67 |
|
| 68 |
--disable_warnings |
| 69 |
--disable_query_log |
| 70 |
drop table if exists mysql.ndb_replication; |
| 71 |
CREATE TABLE mysql.ndb_replication |
| 72 |
(db VARBINARY(63), |
| 73 |
table_name VARBINARY(63), |
| 74 |
server_id INT UNSIGNED, |
| 75 |
binlog_type INT UNSIGNED, |
| 76 |
conflict_fn VARBINARY(128), |
| 77 |
PRIMARY KEY USING HASH (db,table_name,server_id)) |
| 78 |
ENGINE=NDB PARTITION BY KEY(db,table_name); |
| 79 |
--enable_warnings |
| 80 |
--enable_query_log |
| 81 |
|
| 82 |
if (!$CONFLICT_ALG) |
| 83 |
{ |
| 84 |
let $CONFLICT_ALG=NDB\$EPOCH; |
| 85 |
} |
| 86 |
if (!$SECONDARY_CONFLICT_ALG) |
| 87 |
{ |
| 88 |
let $SECONDARY_CONFLICT_ALG=NULL; |
| 89 |
} |
| 90 |
|
| 91 |
--echo Populate ndb_replication table as necessary |
| 92 |
--echo -- 0 extra gci bits |
| 93 |
--disable_query_log |
| 94 |
eval replace into mysql.ndb_replication values |
| 95 |
("test", "t1", $SECONDARY_SERVER_ID, 7, $SECONDARY_CONFLICT_ALG), |
| 96 |
("test", "t1", $PRIMARY_SERVER_ID, 7, "$CONFLICT_ALG(0)"); |
| 97 |
--enable_query_log |
| 98 |
|
| 99 |
--source suite/ndb_rpl/t/ndb_rpl_conflict_epoch_1.inc |
| 100 |
|
| 101 |
--echo Populate ndb_replication table as necessary |
| 102 |
--echo -- 1 extra gci bits |
| 103 |
--disable_query_log |
| 104 |
eval replace into mysql.ndb_replication values |
| 105 |
("test", "t1", $SECONDARY_SERVER_ID, 7, $SECONDARY_CONFLICT_ALG), |
| 106 |
("test", "t1", $PRIMARY_SERVER_ID, 7, "$CONFLICT_ALG(1)"); |
| 107 |
--enable_query_log |
| 108 |
|
| 109 |
--source suite/ndb_rpl/t/ndb_rpl_conflict_epoch_1.inc |
| 110 |
|
| 111 |
--echo Populate ndb_replication table as necessary |
| 112 |
--echo -- 31 extra gci bits |
| 113 |
--disable_query_log |
| 114 |
eval replace into mysql.ndb_replication values |
| 115 |
("test", "t1", $SECONDARY_SERVER_ID, 7, $SECONDARY_CONFLICT_ALG), |
| 116 |
("test", "t1", $PRIMARY_SERVER_ID, 7, "$CONFLICT_ALG(31)"); |
| 117 |
--enable_query_log |
| 118 |
|
| 119 |
--source suite/ndb_rpl/t/ndb_rpl_conflict_epoch_1.inc |
| 120 |
|
| 121 |
--echo Populate ndb_replication table as necessary |
| 122 |
--echo -- Default extra Gci bits |
| 123 |
--disable_query_log |
| 124 |
eval replace into mysql.ndb_replication values |
| 125 |
("test", "t1", $SECONDARY_SERVER_ID, 7, $SECONDARY_CONFLICT_ALG), |
| 126 |
("test", "t1", $PRIMARY_SERVER_ID, 7, "$CONFLICT_ALG()"); |
| 127 |
--enable_query_log |
| 128 |
|
| 129 |
--source suite/ndb_rpl/t/ndb_rpl_conflict_epoch_1.inc |
| 130 |
|
| 131 |
--source suite/ndb_rpl/t/ndb_conflict_info_init.inc |
| 132 |
|
| 133 |
--echo Now test batched conflict detection/handling |
| 134 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 135 |
|
| 136 |
create table test.t1 ( |
| 137 |
a int primary key, |
| 138 |
b int, |
| 139 |
c varchar(2000)) engine=ndb; |
| 140 |
|
| 141 |
--source suite/ndb_rpl/t/ndb_sync_primary_to_secondary.inc |
| 142 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 143 |
|
| 144 |
--echo -- Stop replication from Primary -> Secondary |
| 145 |
stop slave; |
| 146 |
|
| 147 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 148 |
--echo -- Insert a row on Primary |
| 149 |
insert into test.t1 values (1,1,repeat('B', 2000)); |
| 150 |
|
| 151 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 152 |
--echo -- Generate a large batch of inserts with early + late conflicts |
| 153 |
delimiter %; |
| 154 |
|
| 155 |
create procedure test.doit (`rows` int) |
| 156 |
begin |
| 157 |
set @x = 0; |
| 158 |
START TRANSACTION; |
| 159 |
repeat |
| 160 |
insert into test.t1 values (@x, @x, repeat('B', 2000)); |
| 161 |
set @x = @x + 1; |
| 162 |
until @x = `rows` |
| 163 |
end repeat; |
| 164 |
COMMIT; |
| 165 |
START TRANSACTION; |
| 166 |
update test.t1 set b=999, c=repeat('E',2000) where a=1; |
| 167 |
COMMIT; |
| 168 |
START TRANSACTION; |
| 169 |
delete from test.t1 where a=1; |
| 170 |
COMMIT; |
| 171 |
START TRANSACTION; |
| 172 |
insert into test.t1 values (1,1,'A'); |
| 173 |
COMMIT; |
| 174 |
end% |
| 175 |
|
| 176 |
delimiter ;% |
| 177 |
|
| 178 |
call test.doit(100); |
| 179 |
|
| 180 |
drop procedure test.doit; |
| 181 |
|
| 182 |
--source suite/ndb_rpl/t/ndb_sync_secondary_to_primary.inc |
| 183 |
|
| 184 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 185 |
|
| 186 |
--echo -- Look at Primary status, expect 4 conflicts |
| 187 |
--source suite/ndb_rpl/t/ndb_conflict_info.inc |
| 188 |
|
| 189 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 190 |
start slave; |
| 191 |
|
| 192 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 193 |
--echo -- Look at Seconday row |
| 194 |
select a,b,sha1(c) from test.t1 where a=1; |
| 195 |
|
| 196 |
--source suite/ndb_rpl/t/ndb_sync_primary_to_secondary.inc |
| 197 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 198 |
--echo -- Check it's the same on the Secondary |
| 199 |
select a,b,sha1(c) from test.t1 where a=1; |
| 200 |
|
| 201 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 202 |
--echo Test batching of DELETE vs DELETE with following INSERT |
| 203 |
delete from test.t1; |
| 204 |
insert into test.t1 values (1, 1, "Ma Brows"); |
| 205 |
--source suite/ndb_rpl/t/ndb_sync_primary_to_secondary.inc |
| 206 |
--source suite/ndb_rpl/t/ndb_sync_secondary_to_primary.inc |
| 207 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 208 |
--echo -- Stop Slave in both directions |
| 209 |
stop slave; |
| 210 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 211 |
stop slave; |
| 212 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 213 |
--echo -- Delete row on Primary Cluster |
| 214 |
delete from test.t1 where a=1; |
| 215 |
|
| 216 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 217 |
--echo -- Delete row on Secondary Cluster, followed by Insert in later 'batch' |
| 218 |
delimiter %; |
| 219 |
|
| 220 |
create procedure test.doit (`rows` int) |
| 221 |
begin |
| 222 |
set @x = 2; |
| 223 |
START TRANSACTION; |
| 224 |
delete from test.t1 where a=1; |
| 225 |
repeat |
| 226 |
insert into test.t1 values (@x, @x, repeat('B', 2000)); |
| 227 |
set @x = @x + 1; |
| 228 |
until @x = (`rows` + 2) |
| 229 |
end repeat; |
| 230 |
COMMIT; |
| 231 |
START TRANSACTION; |
| 232 |
insert into test.t1 values (1, 1, 'Malleny arms'); |
| 233 |
COMMIT; |
| 234 |
end% |
| 235 |
|
| 236 |
delimiter ;% |
| 237 |
|
| 238 |
call test.doit(200); |
| 239 |
|
| 240 |
--echo -- Restart slave on Primary Cluster |
| 241 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 242 |
# TODO : Reenable with new slave counts |
| 243 |
#--source suite/ndb_rpl/include/ndb_init_replica_counts.inc |
| 244 |
start replica; |
| 245 |
|
| 246 |
--source suite/ndb_rpl/t/ndb_sync_secondary_to_primary.inc |
| 247 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 248 |
|
| 249 |
# TODO : Reenable with new slave counts |
| 250 |
#--disable_result_log |
| 251 |
# Don't include results as they vary depending on epoch boundaries |
| 252 |
#--source suite/ndb_rpl/include/ndb_slave_counts.inc |
| 253 |
#--enable_result_log |
| 254 |
#--echo -- Verify that batching occurred when replicating the above |
| 255 |
#select (@ndb_slave_execute_count - @ndb_slave_commit_count) > 1; |
| 256 |
--echo -- Show data on Primary Cluster (should have row inserted on Secondary) |
| 257 |
select * from test.t1 where a=1; |
| 258 |
|
| 259 |
--echo -- Show data on Secondary Cluster (should have row inserted on Secondary) |
| 260 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 261 |
select * from test.t1 where a=1; |
| 262 |
|
| 263 |
--echo --Restart slave on Secondary Cluster |
| 264 |
start slave; |
| 265 |
--source suite/ndb_rpl/t/ndb_sync_primary_to_secondary.inc |
| 266 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 267 |
|
| 268 |
--echo -- Show data on Clusters after slaves restarted+synced |
| 269 |
--echo For NDB\$EPOCH, the data will be missing |
| 270 |
--echo as expected with delete vs delete conflict |
| 271 |
--echo followed closely by Insert |
| 272 |
--echo For NDB\$EPOCH2, the data will be present on both |
| 273 |
--echo clusters. |
| 274 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 275 |
--echo PRIMARY |
| 276 |
select * from test.t1 where a=1; |
| 277 |
|
| 278 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 279 |
--echo SECONDARY |
| 280 |
select * from test.t1 where a=1; |
| 281 |
|
| 282 |
--echo -- Force wait for master to be in-sync with slave |
| 283 |
--echo To avoid race between DML and table drop |
| 284 |
flush logs; |
| 285 |
--source suite/ndb_rpl/t/ndb_sync_secondary_to_primary.inc |
| 286 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 287 |
|
| 288 |
drop procedure test.doit; |
| 289 |
drop table test.t1; |
| 290 |
|
| 291 |
delete from mysql.ndb_replication; |
| 292 |
eval insert into mysql.ndb_replication values |
| 293 |
("test", "t3", 0, 7, "$CONFLICT_ALG(32)"), |
| 294 |
("test", "t4", 0, 7, "$CONFLICT_ALG(-1)"); |
| 295 |
|
| 296 |
--disable_query_log |
| 297 |
# Only need suppress here, as table creation fails due to this. |
| 298 |
call mtr.add_suppression("Replica: .* Too many extra Gci bits at .*"); |
| 299 |
call mtr.add_suppression(".*engine for 't3' doesn't have this option"); |
| 300 |
call mtr.add_suppression(".*engine for 't4' doesn't have this option"); |
| 301 |
call mtr.add_suppression(".*coordinator and worker threads are stopped.*"); |
| 302 |
--enable_query_log |
| 303 |
|
| 304 |
--error ER_CONFLICT_FN_PARSE_ERROR |
| 305 |
create table test.t3 (a int primary key) engine=ndb; |
| 306 |
show warnings; |
| 307 |
|
| 308 |
--error ER_CONFLICT_FN_PARSE_ERROR |
| 309 |
create table test.t4 (a int primary key) engine=ndb; |
| 310 |
show warnings; |
| 311 |
|
| 312 |
--echo -- Force sync before dropping table to avoid race |
| 313 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 314 |
flush logs; |
| 315 |
--source suite/ndb_rpl/t/ndb_sync_primary_to_secondary.inc |
| 316 |
--source suite/ndb_rpl/t/ndb_connect_to_secondary.inc |
| 317 |
flush logs; |
| 318 |
--source suite/ndb_rpl/t/ndb_sync_secondary_to_primary.inc |
| 319 |
--source suite/ndb_rpl/t/ndb_connect_to_primary.inc |
| 320 |
|
| 321 |
drop table mysql.ndb_replication; |
| 322 |
|
| 323 |
--source suite/ndb_rpl/t/ndb_sync_primary_to_secondary.inc |
| 324 |
|
| 325 |
--echo -- Attempt to get system back in pre-test state |
| 326 |
# Note use of fixed connection names here. |
| 327 |
--connection master |
| 328 |
stop replica; |
| 329 |
reset replica; |
| 330 |
|
| 331 |
--source include/rpl_end.inc |