rpl_loaddata.test 8.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
# See if replication of a "LOAD DATA in an autoincrement column"
# Honours autoincrement values
# i.e. if the master and slave have the same sequence
#
# check replication of load data for temporary tables with additional
# parameters
#
# check if duplicate entries trigger an error (they should unless IGNORE or
# REPLACE was used on the master) (bug 571).
#
# check if START SLAVE, RESET SLAVE, CHANGE MASTER reset Last_slave_error and
# Last_slave_errno in SHOW SLAVE STATUS (1st and 3rd commands did not: bug 986)

14
-- source include/have_binlog_format_statement.inc
15
-- source include/master-slave.inc
16
source include/have_innodb.inc;
17

18 19 20
# MTR is not case-sensitive.
let $lower_stmt_head= load data;
let $UPPER_STMT_HEAD= LOAD DATA;
21
if ($lock_option)
22 23 24 25 26 27 28 29
{
  #if $lock_option is null, an extra blank is added into the statement,
  #this will change the result of rpl_loaddata test case. so $lock_option
  #is set only when it is not null.
  let $lower_stmt_head= load data $lock_option;
  let $UPPER_STMT_HEAD= LOAD DATA $lock_option;
}

30
select last_insert_id();
31
create table t1(a int not null auto_increment, b int, primary key(a) );
32
eval $lower_stmt_head infile '../../std_data/rpl_loaddata.dat' into table t1;
33 34
# verify that LAST_INSERT_ID() is set by LOAD DATA INFILE
select last_insert_id();
35 36

create temporary table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60));
37
eval $lower_stmt_head infile '../../std_data/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines;
38 39 40 41

create table t3 (day date,id int(9),category enum('a','b','c'),name varchar(60));
insert into t3 select * from t2;

42
sync_slave_with_master;
43 44 45 46 47 48 49 50 51 52 53

select * from t1;
select * from t3;

connection master;

drop table t1;
drop table t2;
drop table t3;
create table t1(a int, b int, unique(b));

54
sync_slave_with_master;
55 56 57 58 59 60

# See if slave stops when there's a duplicate entry for key error in LOAD DATA

insert into t1 values(1,10);

connection master;
61
eval $lower_stmt_head infile '../../std_data/rpl_loaddata.dat' into table t1;
62 63 64

save_master_pos;
connection slave;
65
# 1062 = ER_DUP_ENTRY
66 67
call mtr.add_suppression("Slave SQL.*Error .Duplicate entry .10. for key .b.. on query.* Error_code: 1062");
call mtr.add_suppression("Slave SQL.*Query caused different errors on master and slave.*Error on master:.*error code=1062.*Error on slave:.*Error_code: 0");
68 69
--let $slave_sql_errno= 1062
--source include/wait_for_slave_sql_error_and_skip.inc
70 71 72 73 74 75

# Skip the bad event and see if error is cleared in SHOW SLAVE STATUS by START
# SLAVE, even though we are not executing any event (as sql_slave_skip_counter
# takes us directly to the end of the relay log).

sync_with_master;
76
--source include/check_slave_no_error.inc
77 78 79 80 81 82 83

# Trigger error again to test CHANGE MASTER

connection master;
set sql_log_bin=0;
delete from t1;
set sql_log_bin=1;
84
eval $lower_stmt_head infile '../../std_data/rpl_loaddata.dat' into table t1;
85 86 87 88 89
save_master_pos;
connection slave;
# The SQL slave thread should be stopped now. 
# Exec_Master_Log_Pos should point to the start of Execute event
# for last load data.
90 91 92
# 1062 = ER_DUP_ENTRY
--let $slave_sql_errno= 1062
--source include/wait_for_slave_sql_error.inc
93 94

# CHANGE MASTER and see if error is cleared in SHOW SLAVE STATUS.
95
--source include/stop_slave_io.inc
96 97
change master to master_user='test';
change master to master_user='root';
98
--source include/check_slave_no_error.inc
99 100 101 102 103 104 105 106 107 108

# Trigger error again to test RESET SLAVE

set global sql_slave_skip_counter=1;
start slave;
sync_with_master;
connection master;
set sql_log_bin=0;
delete from t1;
set sql_log_bin=1;
109
eval $lower_stmt_head infile '../../std_data/rpl_loaddata.dat' into table t1;
110 111 112
save_master_pos;
connection slave;
# The SQL slave thread should be stopped now.
113 114 115
# 1062 = ER_DUP_ENTRY
--let $slave_sql_errno= 1062
--source include/wait_for_slave_sql_error.inc
116 117 118 119

# RESET SLAVE and see if error is cleared in SHOW SLAVE STATUS.
stop slave;
reset slave;
120
--source include/check_slave_no_error.inc
121 122 123 124 125 126 127

# Finally, see if logging is done ok on master for a failing LOAD DATA INFILE

connection master;
reset master;
eval create table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60),
unique(day)) engine=$engine_type; # no transactions
128
--error ER_DUP_ENTRY
129
eval $lower_stmt_head infile '../../std_data/rpl_loaddata2.dat' into table t2 fields
130 131 132 133 134 135 136 137 138 139 140 141 142 143
terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by
'\n##\n' starting by '>' ignore 1 lines;
select * from t2;
save_master_pos;
connection slave;
start slave;
sync_with_master;
select * from t2;

# verify that if no error on slave, this is an error

alter table t2 drop key day;
connection master;
delete from t2;
144
--error ER_DUP_ENTRY
145
eval $lower_stmt_head infile '../../std_data/rpl_loaddata2.dat' into table t2 fields
146 147 148
terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by
'\n##\n' starting by '>' ignore 1 lines;
connection slave;
149
--source include/wait_for_slave_sql_to_stop.inc
150
drop table t1, t2;
151
--source include/stop_slave_io.inc
152
connection master;
153
drop table t1, t2;
154 155 156 157

# BUG#17233 LOAD DATA INFILE: failure causes mysqld dbug_assert, binlog not flushed
CREATE TABLE t1 (word CHAR(20) NOT NULL PRIMARY KEY) ENGINE=INNODB;

158
--error ER_DUP_ENTRY
159
eval $UPPER_STMT_HEAD INFILE "../../std_data/words.dat" INTO TABLE t1;
160 161 162

DROP TABLE IF EXISTS t1;

163 164
# BUG#48297: Schema name is ignored when LOAD DATA is written into binlog,
# replication aborts
165 166
-- let $rpl_only_running_threads= 1
-- source include/rpl_reset.inc
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

-- let $db1= b48297_db1
-- let $db2= b42897_db2

-- connection master

-- disable_warnings
-- eval drop database if exists $db1
-- eval drop database if exists $db2
-- enable_warnings

-- eval create database $db1
-- eval create database $db2

-- eval use $db1
-- eval CREATE TABLE t1 (c1 VARCHAR(256)) engine=$engine_type;

-- eval use $db2

-- echo ### assertion: works with cross-referenced database
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
188
-- eval $UPPER_STMT_HEAD LOCAL INFILE '$MYSQLTEST_VARDIR/std_data/loaddata5.dat' INTO TABLE $db1.t1
189 190 191 192 193

-- eval use $db1
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
-- echo ### assertion: works with fully qualified name on current database
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
194
-- eval $UPPER_STMT_HEAD LOCAL INFILE '$MYSQLTEST_VARDIR/std_data/loaddata5.dat' INTO TABLE $db1.t1
195 196 197

-- echo ### assertion: works without fully qualified name on current database
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
198
-- eval $UPPER_STMT_HEAD LOCAL INFILE '$MYSQLTEST_VARDIR/std_data/loaddata5.dat' INTO TABLE t1
199 200 201 202 203 204 205

-- echo ### create connection without default database
-- echo ### connect (conn2,localhost,root,,*NO-ONE*);
connect (conn2,localhost,root,,*NO-ONE*);
-- connection conn2
-- echo ### assertion: works without stating the default database
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
206
-- eval $UPPER_STMT_HEAD LOCAL INFILE '$MYSQLTEST_VARDIR/std_data/loaddata5.dat' INTO TABLE $db1.t1
207 208 209 210 211 212 213 214 215 216 217 218 219

# We cannot disconnect right away because when inserting
# concurrently in a MyISAM table, the server is sending an OK 
# to the client before updating the table state (where the 
# number of records is kept). See: BUG#37521 and BUG#29334.
# So we need to wait, otherwise we would be having sporadic 
# failures as reported here: BUG#50451.

# 12 = 3 rows per each LOAD DATA executed x 4
-- let $count= 12
-- let $table= $db1.t1
--source include/wait_until_rows_count.inc

220 221 222 223 224 225 226
-- echo ### disconnect and switch back to master connection
-- disconnect conn2
-- connection master

-- sync_slave_with_master
-- eval use $db1

227
let $diff_tables= master:$db1.t1, slave:$db1.t1;
228 229 230 231 232 233 234 235 236
source include/diff_tables.inc;

-- connection master

-- eval DROP DATABASE $db1
-- eval DROP DATABASE $db2

-- sync_slave_with_master

237
# BUG#49479: LOAD DATA INFILE is binlogged without escaping field names
238
-- source include/rpl_reset.inc
239 240 241 242 243 244 245 246 247 248 249
-- connection master
use test;
CREATE TABLE t1 (`key` TEXT, `text` TEXT);

LOAD DATA INFILE '../../std_data/loaddata2.dat' REPLACE INTO TABLE `t1` FIELDS TERMINATED BY ',';
SELECT * FROM t1;

-- sync_slave_with_master
-- connection master
DROP TABLE t1;

250
# End of 4.1 tests
251
--source include/rpl_end.inc