~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/extra/rpl_tests/rpl_loaddata.test

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Requires statement logging
 
2
-- source include/have_binlog_format_mixed_or_statement.inc
 
3
 
 
4
# See if replication of a "LOAD DATA in an autoincrement column"
 
5
# Honours autoincrement values
 
6
# i.e. if the master and slave have the same sequence
 
7
#
 
8
# check replication of load data for temporary tables with additional
 
9
# parameters
 
10
#
 
11
# check if duplicate entries trigger an error (they should unless IGNORE or
 
12
# REPLACE was used on the master) (bug 571).
 
13
#
 
14
# check if START SLAVE, RESET SLAVE, CHANGE MASTER reset Last_slave_error and
 
15
# Last_slave_errno in SHOW SLAVE STATUS (1st and 3rd commands did not: bug 986)
 
16
 
 
17
-- source include/master-slave.inc
 
18
source include/have_innodb.inc;
 
19
 
 
20
connection slave;
 
21
reset master;
 
22
connection master;
 
23
 
 
24
# MTR is not case-sensitive.
 
25
let $lower_stmt_head= load data;
 
26
let $UPPER_STMT_HEAD= LOAD DATA;
 
27
if (`SELECT '$lock_option' <> ''`)
 
28
{
 
29
  #if $lock_option is null, an extra blank is added into the statement,
 
30
  #this will change the result of rpl_loaddata test case. so $lock_option
 
31
  #is set only when it is not null.
 
32
  let $lower_stmt_head= load data $lock_option;
 
33
  let $UPPER_STMT_HEAD= LOAD DATA $lock_option;
 
34
}
 
35
 
 
36
select last_insert_id();
 
37
create table t1(a int not null auto_increment, b int, primary key(a) );
 
38
eval $lower_stmt_head infile '../../std_data/rpl_loaddata.dat' into table t1;
 
39
# verify that LAST_INSERT_ID() is set by LOAD DATA INFILE
 
40
select last_insert_id();
 
41
 
 
42
create temporary table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60));
 
43
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;
 
44
 
 
45
create table t3 (day date,id int(9),category enum('a','b','c'),name varchar(60));
 
46
insert into t3 select * from t2;
 
47
 
 
48
save_master_pos;
 
49
connection slave;
 
50
sync_with_master;
 
51
 
 
52
select * from t1;
 
53
select * from t3;
 
54
 
 
55
connection master;
 
56
 
 
57
drop table t1;
 
58
drop table t2;
 
59
drop table t3;
 
60
create table t1(a int, b int, unique(b));
 
61
 
 
62
save_master_pos;
 
63
connection slave;
 
64
sync_with_master;
 
65
 
 
66
# See if slave stops when there's a duplicate entry for key error in LOAD DATA
 
67
 
 
68
insert into t1 values(1,10);
 
69
 
 
70
connection master;
 
71
eval $lower_stmt_head infile '../../std_data/rpl_loaddata.dat' into table t1;
 
72
 
 
73
save_master_pos;
 
74
connection slave;
 
75
# The SQL slave thread should be stopped now.
 
76
--source include/wait_for_slave_sql_to_stop.inc
 
77
 
 
78
# Skip the bad event and see if error is cleared in SHOW SLAVE STATUS by START
 
79
# SLAVE, even though we are not executing any event (as sql_slave_skip_counter
 
80
# takes us directly to the end of the relay log).
 
81
 
 
82
set global sql_slave_skip_counter=1;
 
83
start slave;
 
84
sync_with_master;
 
85
let $last_error= query_get_value(SHOW SLAVE STATUS, Last_SQL_Errno, 1);
 
86
echo Last_SQL_Errno=$last_error;
 
87
let $last_error= query_get_value(SHOW SLAVE STATUS, Last_SQL_Error, 1);
 
88
echo Last_SQL_Error;
 
89
echo $last_error;
 
90
 
 
91
# Trigger error again to test CHANGE MASTER
 
92
 
 
93
connection master;
 
94
set sql_log_bin=0;
 
95
delete from t1;
 
96
set sql_log_bin=1;
 
97
eval $lower_stmt_head infile '../../std_data/rpl_loaddata.dat' into table t1;
 
98
save_master_pos;
 
99
connection slave;
 
100
# The SQL slave thread should be stopped now. 
 
101
# Exec_Master_Log_Pos should point to the start of Execute event
 
102
# for last load data.
 
103
--source include/wait_for_slave_sql_to_stop.inc
 
104
 
 
105
# CHANGE MASTER and see if error is cleared in SHOW SLAVE STATUS.
 
106
stop slave;
 
107
change master to master_user='test';
 
108
change master to master_user='root';
 
109
let $last_error= query_get_value(SHOW SLAVE STATUS, Last_SQL_Errno, 1);
 
110
echo Last_SQL_Errno=$last_error;
 
111
let $last_error= query_get_value(SHOW SLAVE STATUS, Last_SQL_Error, 1);
 
112
echo Last_SQL_Error;
 
113
echo $last_error;
 
114
 
 
115
# Trigger error again to test RESET SLAVE
 
116
 
 
117
set global sql_slave_skip_counter=1;
 
118
start slave;
 
119
sync_with_master;
 
120
connection master;
 
121
set sql_log_bin=0;
 
122
delete from t1;
 
123
set sql_log_bin=1;
 
124
eval $lower_stmt_head infile '../../std_data/rpl_loaddata.dat' into table t1;
 
125
save_master_pos;
 
126
connection slave;
 
127
# The SQL slave thread should be stopped now.
 
128
--source include/wait_for_slave_sql_to_stop.inc
 
129
 
 
130
# RESET SLAVE and see if error is cleared in SHOW SLAVE STATUS.
 
131
stop slave;
 
132
reset slave;
 
133
let $last_error= query_get_value(SHOW SLAVE STATUS, Last_SQL_Errno, 1);
 
134
echo Last_SQL_Errno=$last_error;
 
135
let $last_error= query_get_value(SHOW SLAVE STATUS, Last_SQL_Error, 1);
 
136
echo Last_SQL_Error;
 
137
echo $last_error;
 
138
 
 
139
# Finally, see if logging is done ok on master for a failing LOAD DATA INFILE
 
140
 
 
141
connection master;
 
142
reset master;
 
143
eval create table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60),
 
144
unique(day)) engine=$engine_type; # no transactions
 
145
--error ER_DUP_ENTRY
 
146
eval $lower_stmt_head infile '../../std_data/rpl_loaddata2.dat' into table t2 fields
 
147
terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by
 
148
'\n##\n' starting by '>' ignore 1 lines;
 
149
select * from t2;
 
150
save_master_pos;
 
151
connection slave;
 
152
start slave;
 
153
sync_with_master;
 
154
select * from t2;
 
155
 
 
156
# verify that if no error on slave, this is an error
 
157
 
 
158
alter table t2 drop key day;
 
159
connection master;
 
160
delete from t2;
 
161
--error ER_DUP_ENTRY
 
162
eval $lower_stmt_head infile '../../std_data/rpl_loaddata2.dat' into table t2 fields
 
163
terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by
 
164
'\n##\n' starting by '>' ignore 1 lines;
 
165
connection slave;
 
166
--source include/wait_for_slave_sql_to_stop.inc
 
167
drop table t1, t2;
 
168
connection master;
 
169
drop table t1, t2;
 
170
 
 
171
# BUG#17233 LOAD DATA INFILE: failure causes mysqld dbug_assert, binlog not flushed
 
172
CREATE TABLE t1 (word CHAR(20) NOT NULL PRIMARY KEY) ENGINE=INNODB;
 
173
 
 
174
--error ER_DUP_ENTRY
 
175
eval $UPPER_STMT_HEAD INFILE "../../std_data/words.dat" INTO TABLE t1;
 
176
 
 
177
DROP TABLE IF EXISTS t1;
 
178
 
 
179
# BUG#48297: Schema name is ignored when LOAD DATA is written into binlog,
 
180
# replication aborts
 
181
-- source include/master-slave-reset.inc
 
182
 
 
183
-- let $db1= b48297_db1
 
184
-- let $db2= b42897_db2
 
185
 
 
186
-- connection master
 
187
 
 
188
-- disable_warnings
 
189
-- eval drop database if exists $db1
 
190
-- eval drop database if exists $db2
 
191
-- enable_warnings
 
192
 
 
193
-- eval create database $db1
 
194
-- eval create database $db2
 
195
 
 
196
-- eval use $db1
 
197
-- eval CREATE TABLE t1 (c1 VARCHAR(256)) engine=$engine_type;
 
198
 
 
199
-- eval use $db2
 
200
 
 
201
-- echo ### assertion: works with cross-referenced database
 
202
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
203
-- eval $UPPER_STMT_HEAD LOCAL INFILE '$MYSQLTEST_VARDIR/std_data/loaddata5.dat' INTO TABLE $db1.t1
 
204
 
 
205
-- eval use $db1
 
206
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
207
-- echo ### assertion: works with fully qualified name on current database
 
208
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
209
-- eval $UPPER_STMT_HEAD LOCAL INFILE '$MYSQLTEST_VARDIR/std_data/loaddata5.dat' INTO TABLE $db1.t1
 
210
 
 
211
-- echo ### assertion: works without fully qualified name on current database
 
212
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
213
-- eval $UPPER_STMT_HEAD LOCAL INFILE '$MYSQLTEST_VARDIR/std_data/loaddata5.dat' INTO TABLE t1
 
214
 
 
215
-- echo ### create connection without default database
 
216
-- echo ### connect (conn2,localhost,root,,*NO-ONE*);
 
217
connect (conn2,localhost,root,,*NO-ONE*);
 
218
-- connection conn2
 
219
-- echo ### assertion: works without stating the default database
 
220
-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
221
-- eval $UPPER_STMT_HEAD LOCAL INFILE '$MYSQLTEST_VARDIR/std_data/loaddata5.dat' INTO TABLE $db1.t1
 
222
 
 
223
# We cannot disconnect right away because when inserting
 
224
# concurrently in a MyISAM table, the server is sending an OK 
 
225
# to the client before updating the table state (where the 
 
226
# number of records is kept). See: BUG#37521 and BUG#29334.
 
227
# So we need to wait, otherwise we would be having sporadic 
 
228
# failures as reported here: BUG#50451.
 
229
 
 
230
# 12 = 3 rows per each LOAD DATA executed x 4
 
231
-- let $count= 12
 
232
-- let $table= $db1.t1
 
233
--source include/wait_until_rows_count.inc
 
234
 
 
235
-- echo ### disconnect and switch back to master connection
 
236
-- disconnect conn2
 
237
-- connection master
 
238
 
 
239
-- sync_slave_with_master
 
240
-- eval use $db1
 
241
 
 
242
let $diff_table_1=master:$db1.t1;
 
243
let $diff_table_2=slave:$db1.t1;
 
244
source include/diff_tables.inc;
 
245
 
 
246
-- connection master
 
247
 
 
248
-- eval DROP DATABASE $db1
 
249
-- eval DROP DATABASE $db2
 
250
 
 
251
-- sync_slave_with_master
 
252
 
 
253
# BUG#49479: LOAD DATA INFILE is binlogged without escaping field names
 
254
-- source include/master-slave-reset.inc
 
255
-- connection master
 
256
use test;
 
257
CREATE TABLE t1 (`key` TEXT, `text` TEXT);
 
258
 
 
259
LOAD DATA INFILE '../../std_data/loaddata2.dat' REPLACE INTO TABLE `t1` FIELDS TERMINATED BY ',';
 
260
SELECT * FROM t1;
 
261
 
 
262
-- sync_slave_with_master
 
263
-- connection master
 
264
DROP TABLE t1;
 
265
-- sync_slave_with_master
 
266
 
 
267
# End of 4.1 tests