diff options
author | unknown <lars@mysql.com> | 2004-11-15 17:03:54 +0100 |
---|---|---|
committer | unknown <lars@mysql.com> | 2004-11-15 17:03:54 +0100 |
commit | 58f984add28bba67add38efb0c19d67a154b47ea (patch) | |
tree | 9cabe4ed38a9aa909b2016e45e2488b4066b8558 | |
parent | fe37a1472c22b0a48244b932664925cad68f3e96 (diff) | |
download | mariadb-git-58f984add28bba67add38efb0c19d67a154b47ea.tar.gz |
BUG#6353 V2:
Replication using replicate-rewrite-db did not work for LOAD DATA INFILE.
Now is does. There was one place in the code that used current database
instead of the rewrite database.
mysql-test/r/rpl_rewrite_db.result:
New tests
mysql-test/t/rpl_rewrite_db-slave.opt:
New tests
mysql-test/t/rpl_rewrite_db.test:
New tests
sql/log_event.cc:
Added db to set_fields function so that current db is used.
sql/log_event.h:
Added db to set_fields function so that current db is used.
-rw-r--r-- | mysql-test/r/rpl_rewrite_db.result | 70 | ||||
-rw-r--r-- | mysql-test/t/rpl_rewrite_db-slave.opt | 2 | ||||
-rw-r--r-- | mysql-test/t/rpl_rewrite_db.test | 58 | ||||
-rw-r--r-- | sql/log_event.cc | 26 | ||||
-rw-r--r-- | sql/log_event.h | 2 |
5 files changed, 146 insertions, 12 deletions
diff --git a/mysql-test/r/rpl_rewrite_db.result b/mysql-test/r/rpl_rewrite_db.result index 2804b98dea1..a2c8706e3e1 100644 --- a/mysql-test/r/rpl_rewrite_db.result +++ b/mysql-test/r/rpl_rewrite_db.result @@ -20,3 +20,73 @@ a 9 drop table t1; drop database mysqltest1; +drop database if exists rewrite; +create database rewrite; +use test; +create table t1 (a date, b date, c date not null, d date); +load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ','; +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +Warning 1265 Data truncated for column 'c' at row 1 +Warning 1265 Data truncated for column 'd' at row 1 +Warning 1265 Data truncated for column 'a' at row 2 +Warning 1265 Data truncated for column 'b' at row 2 +Warning 1265 Data truncated for column 'd' at row 2 +load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES; +select * from rewrite.t1; +a b c d +0000-00-00 NULL 0000-00-00 0000-00-00 +0000-00-00 0000-00-00 0000-00-00 0000-00-00 +2003-03-03 2003-03-03 2003-03-03 NULL +2003-03-03 2003-03-03 2003-03-03 NULL +truncate table t1; +load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d); +Warnings: +Warning 1265 Data truncated for column 'c' at row 1 +Warning 1265 Data truncated for column 'd' at row 1 +Warning 1265 Data truncated for column 'b' at row 2 +Warning 1265 Data truncated for column 'd' at row 2 +select * from rewrite.t1; +a b c d +NULL NULL 0000-00-00 0000-00-00 +NULL 0000-00-00 0000-00-00 0000-00-00 +NULL 2003-03-03 2003-03-03 NULL +drop table t1; +create table t1 (a text, b text); +load data infile '../../std_data/loaddata2.dat' into table t1 fields terminated by ',' enclosed by ''''; +Warnings: +Warning 1261 Row 3 doesn't contain data for all columns +select concat('|',a,'|'), concat('|',b,'|') from rewrite.t1; +concat('|',a,'|') concat('|',b,'|') +|Field A| |Field B| +|Field 1| |Field 2' +Field 3,'Field 4| +|Field 5' ,'Field 6| NULL +|Field 6| | 'Field 7'| +drop table t1; +create table t1 (a int, b char(10)); +load data infile '../../std_data/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines; +Warnings: +Warning 1265 Data truncated for column 'a' at row 3 +Warning 1262 Row 3 was truncated; it contained more data than there were input columns +Warning 1265 Data truncated for column 'a' at row 5 +Warning 1262 Row 5 was truncated; it contained more data than there were input columns +select * from rewrite.t1; +a b +1 row 1 +2 row 2 +0 1234567890 +3 row 3 +0 1234567890 +truncate table t1; +load data infile '../../std_data/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines; +Warnings: +Warning 1265 Data truncated for column 'a' at row 4 +Warning 1261 Row 4 doesn't contain data for all columns +select * from rewrite.t1; +a b +1 row 1 +2 row 2 +3 row 3 +0 +drop table t1; diff --git a/mysql-test/t/rpl_rewrite_db-slave.opt b/mysql-test/t/rpl_rewrite_db-slave.opt index b9cd29e9205..a462ad19ba0 100644 --- a/mysql-test/t/rpl_rewrite_db-slave.opt +++ b/mysql-test/t/rpl_rewrite_db-slave.opt @@ -1 +1 @@ -"--replicate-rewrite-db=mysqltest1->test" +"--replicate-rewrite-db=test->rewrite" "--replicate-rewrite-db=mysqltest1->test" diff --git a/mysql-test/t/rpl_rewrite_db.test b/mysql-test/t/rpl_rewrite_db.test index 4cc8ae4b676..b6118854037 100644 --- a/mysql-test/t/rpl_rewrite_db.test +++ b/mysql-test/t/rpl_rewrite_db.test @@ -17,3 +17,61 @@ drop table t1; drop database mysqltest1; sync_slave_with_master; +# +# BUG#6353: +# Option --replicate-rewrite-db should work together with LOAD DATA INFILE +# + +connection slave; +--disable_warnings +drop database if exists rewrite; +--enable_warnings +create database rewrite; + +connection master; +use test; +create table t1 (a date, b date, c date not null, d date); +load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ','; +load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES; +sync_slave_with_master; + +connection slave; +select * from rewrite.t1; + +connection master; +truncate table t1; +load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d); +sync_slave_with_master; + +connection slave; +select * from rewrite.t1; + +connection master; +drop table t1; +create table t1 (a text, b text); +load data infile '../../std_data/loaddata2.dat' into table t1 fields terminated by ',' enclosed by ''''; +sync_slave_with_master; + +connection slave; +select concat('|',a,'|'), concat('|',b,'|') from rewrite.t1; + +connection master; +drop table t1; +create table t1 (a int, b char(10)); +load data infile '../../std_data/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines; +sync_slave_with_master; + +connection slave; +select * from rewrite.t1; + +connection master; +truncate table t1; +load data infile '../../std_data/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines; +sync_slave_with_master; + +connection slave; +# The empty line last comes from the end line field in the file +select * from rewrite.t1; + +connection master; +drop table t1; diff --git a/sql/log_event.cc b/sql/log_event.cc index 091566c5d90..301c8ec222c 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1655,16 +1655,22 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db, /* Load_log_event::set_fields() + + Note that this function can not use the member variable + for the database, since LOAD DATA INFILE on the slave + can be for a different database than the current one. + This is the reason for the affected_db argument to this method. */ #ifndef MYSQL_CLIENT -void Load_log_event::set_fields(List<Item> &field_list) +void Load_log_event::set_fields(const char* affected_db, + List<Item> &field_list) { uint i; const char* field = fields; for (i= 0; i < num_fields; i++) { - field_list.push_back(new Item_field(db, table_name, field)); + field_list.push_back(new Item_field(affected_db, table_name, field)); field+= field_lens[i] + 1; } } @@ -1820,7 +1826,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, ex.skip_lines = skip_lines; List<Item> field_list; - set_fields(field_list); + set_fields(thd->db,field_list); thd->variables.pseudo_thread_id= thread_id; if (net) { @@ -1837,13 +1843,13 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, if (thd->cuted_fields) { /* log_pos is the position of the LOAD event in the master log */ - sql_print_error("\ -Slave: load data infile on table '%s' at log position %s in log \ -'%s' produced %ld warning(s). Default database: '%s'", - (char*) table_name, - llstr(log_pos,llbuff), RPL_LOG_NAME, - (ulong) thd->cuted_fields, - print_slave_db_safe(thd->db)); + sql_print_warning("Slave: load data infile on table '%s' at " + "log position %s in log '%s' produced %ld " + "warning(s). Default database: '%s'", + (char*) table_name, + llstr(log_pos,llbuff), RPL_LOG_NAME, + (ulong) thd->cuted_fields, + print_slave_db_safe(thd->db)); } if (net) net->pkt_nr= thd->net.pkt_nr; diff --git a/sql/log_event.h b/sql/log_event.h index 8070c334d8b..1606659e21e 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -587,7 +587,7 @@ public: const char* table_name_arg, List<Item>& fields_arg, enum enum_duplicates handle_dup, bool using_trans); - void set_fields(List<Item> &fields_arg); + void set_fields(const char* db, List<Item> &fields_arg); const char* get_db() { return db; } #ifdef HAVE_REPLICATION void pack_info(Protocol* protocol); |