rpl_ndb_basic.test 3.95 KB
Newer Older
unknown's avatar
unknown committed
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
--source include/have_ndb.inc
--source include/have_binlog_format_row.inc
--source include/master-slave.inc



#
# Bug #11087
#
# connect to the master and create tabe t1 in gotoslave database
--connection master
CREATE TABLE `t1` ( `nid` int(11) NOT NULL default '0',
 	            `nom` char(4) default NULL,
  		    `prenom` char(4) default NULL,
		    PRIMARY KEY  (`nid`)) 
    ENGINE=ndbcluster DEFAULT CHARSET=latin1;

INSERT INTO t1 VALUES(1,"XYZ1","ABC1");
select * from t1 order by nid;

--sync_slave_with_master
# connect to slave and ensure data it there.
--connection slave
select * from t1 order by nid;

--connection master
delete from t1;
INSERT INTO t1 VALUES(1,"XYZ2","ABC2");
# Make sure all rows are on the master
select * from t1 order by nid;

# make sure all rows are on the slave.
--sync_slave_with_master
--connection slave
# Bug #11087 would have row with nid 2 missing
select * from t1 order by nid;

--connection master
DROP table t1;

#
# Test replication of table with no primary key 
#
--connection master
CREATE TABLE `t1` ( `nid` int(11) NOT NULL default '0',
 	            `nom` char(4) default NULL,
  		    `prenom` char(4) default NULL)
    ENGINE=ndbcluster DEFAULT CHARSET=latin1;

INSERT INTO t1 VALUES(1,"XYZ1","ABC1"),(2,"AAA","BBB"),(3,"CCC","DDD");
select * from t1 order by nid;

--sync_slave_with_master
# connect to slave and ensure data it there.
--connection slave
select * from t1 order by nid;

--connection master
delete from t1 where nid = 2;
INSERT INTO t1 VALUES(4,"EEE","FFF");
# Make sure all rows are on the master
select * from t1 order by nid;

# make sure all rows are on the slave.
--sync_slave_with_master
--connection slave
select * from t1 order by nid;

--connection master
UPDATE t1 set nid=nid+1;
UPDATE t1 set nom="CCP" where nid = 4;
select * from t1 order by nid;

# make sure all rows are on the slave.
--sync_slave_with_master
--connection slave
select * from t1 order by nid;

--connection master
DROP table t1;

##################################################################
#
# Check that retries are made on the slave on some temporary errors
#

#
# 1. Deadlock
#
--connection master
CREATE TABLE `t1` ( `nid` int(11) NOT NULL default '0',
 	            `nom` char(4) default NULL,
  		    `prenom` char(4) default NULL,
		    PRIMARY KEY USING HASH (`nid`)) 
    ENGINE=ndbcluster DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES(1,"XYZ1","ABC1");

# cause a lock on that row on the slave
--sync_slave_with_master
--connection slave
BEGIN;
UPDATE t1 SET `nom`="LOCK" WHERE `nid`=1;

# set number of retries low so we fail the retries
set GLOBAL slave_transaction_retries=1;

# now do a change to this row on the master
# will deadlock on the slave because of lock above
--connection master
UPDATE t1 SET `nom`="DEAD" WHERE `nid`=1;

# wait for deadlock to be detected
# sleep longer than dead lock detection timeout in config
# we do this 2 times, once with few retries to verify that we 
# get a failure with the set sleep, and once with the _same_
# sleep, but with more retries to get it to succeed
--sleep 5

# replication should have stopped, since max retries where not enough
# verify with show slave status
--connection slave
--replace_result $MASTER_MYPORT MASTER_PORT
--replace_column 1 <Slave_IO_State> 7 <Read_Master_Log_Pos> 8 <Relay_Log_File> 9 <Relay_Log_Pos> 16 <Replicate_Ignore_Table> 22 <Exec_Master_Log_Pos> 23 <Relay_Log_Space> 33 <Seconds_Behind_Master>
SHOW SLAVE STATUS;

# now set max retries high enough to succeed, and start slave again
set GLOBAL slave_transaction_retries=10;
START SLAVE;

# wait for deadlock to be detected and retried
# should be the same sleep as above for test to be valid
--sleep 5

# commit transaction to release lock on row and let replication succeed
select * from t1 order by nid;
COMMIT;

# verify that the row succeded to be applied on the slave
--connection master
--sync_slave_with_master
--connection slave
select * from t1 order by nid;

# cleanup
--connection master
DROP TABLE t1;
147
sync_slave_with_master;