summaryrefslogtreecommitdiff
path: root/mysql-test/suite/rpl_ndb/t/rpl_ndb_idempotent.test
blob: 99c9df40094221290663e3fca5b7d5ca91878fe3 (plain)
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
--source include/have_ndb.inc
--source include/have_binlog_format_mixed_or_row.inc
--source include/ndb_master-slave.inc

#
# Currently test only works with ndb since it retrieves "old"
# binlog positions with mysql.ndb_binlog_index and ndb_apply_status;
#

# create a table with one row
CREATE TABLE t1 (c1 CHAR(15), c2 CHAR(15), c3 INT, PRIMARY KEY (c3)) ENGINE = NDB ;
INSERT INTO t1 VALUES ("row1","will go away",1);
SELECT * FROM t1 ORDER BY c3;

# sync slave and retrieve epoch
sync_slave_with_master;
--replace_column 1 <the_epoch>
SELECT @the_epoch:=MAX(epoch) FROM mysql.ndb_apply_status;
let $the_epoch= `select @the_epoch` ;
SELECT * FROM t1 ORDER BY c3;

# get the master binlog pos from the epoch
connection master;
--replace_result $the_epoch <the_epoch>
--replace_column 1 <the_pos>
eval SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1)
   FROM mysql.ndb_binlog_index WHERE epoch = $the_epoch ;
let $the_pos= `SELECT @the_pos` ;
let $the_file= `SELECT @the_file` ;

# insert some more values
INSERT INTO t1 VALUES ("row2","will go away",2),("row3","will change",3),("row4","D",4);
DELETE FROM t1 WHERE c3 = 1;
UPDATE t1 SET c2="should go away" WHERE c3 = 2;
UPDATE t1 SET c2="C" WHERE c3 = 3;
DELETE FROM t1 WHERE c3 = 2;

SELECT * FROM t1 ORDER BY c3;

# check that we have it on the slave
--sync_slave_with_master
SELECT * FROM t1 ORDER BY c3;

source include/check_slave_is_running.inc;

# stop slave and reset position to before the last changes
STOP SLAVE;
--replace_result $the_pos <the_pos>
eval CHANGE MASTER TO
  master_log_file = '$the_file',
  master_log_pos = $the_pos ;

source include/check_slave_no_error.inc;

# start the slave again
# -> same events should have been applied again
# e.g. inserting rows that already there
#      deleting a row which is not there
#      updating a row which is not there
START SLAVE;

--connection master
SELECT * FROM t1 ORDER BY c3;
--sync_slave_with_master
SELECT * FROM t1 ORDER BY c3;

STOP SLAVE;

#
# cleanup
#
--connection master
DROP TABLE t1;
RESET master;
--connection slave
DROP TABLE t1;
RESET slave;

START SLAVE;

#
# Test that we can handle update of a row that does not exist on the slave
# will trigger usage of AO_IgnoreError on slave side so that the INSERT
# still succeeds even if the replication of the UPDATE generates an error.
#
--connection master
CREATE TABLE t1 (c1 CHAR(15) NOT NULL, c2 CHAR(15) NOT NULL, c3 INT NOT NULL, PRIMARY KEY (c3)) ENGINE = NDB ;
INSERT INTO t1 VALUES ("row1","remove on slave",1);

--sync_slave_with_master
--connection slave
DELETE FROM t1;

--connection master
BEGIN;
UPDATE t1 SET c2="does not exist" WHERE c3=1;
INSERT INTO t1 VALUES ("row2","new on slave",2);
COMMIT;

--sync_slave_with_master
--connection slave
SELECT * FROM t1;
source include/check_slave_is_running.inc;

connection master;
DROP TABLE IF EXISTS t1;

# End of 5.1 Test
-- source include/master-slave-end.inc