Commit e31e697f authored by Sachin's avatar Sachin

MDEV-15919 lower_case_table_names does not behave as expected(nor...

 consistently) on Replication Slave

lower_case_table_names  0 -> 1 replication works, it's safe as long as
 mixed case names mapping to the lower case ones is one-to-one
parent 28ad5aba
# BUG#37656
#
# This test aims at checking whether lower_case_table_names=1 option works
# for database names and table names.
#
# This test checks the following (when lower_case_table_names=1 is set on slave):
# (i) creating a database on upper case on master results in lower case
# database name on slave
# (ii) creating tables with upper case names on master results in lower case
# table names on slave
# (iii) loading data infile into capitalized table name on master replicates to
# lower case table name on slave
# (iv) Propagating changes from upper case table names on into correspondent
# lower case table names on slave works.
# setup: create database and tables
-- echo ******** [ MASTER ] ********
-- let $dbname_upper= BUG_37656
-- let $dbname_lower= `SELECT LOWER('$dbname_upper')`
-- eval CREATE DATABASE $dbname_upper
-- eval use $dbname_upper
# assert: database names are in upper case in master and lower
# case in slave
-- eval show databases like '$dbname_upper'
sync_slave_with_master;
-- echo ******** [ SLAVE ] ********
--eval show databases like '$dbname_lower'
-- connection master
-- echo ******** [ MASTER ] ********
CREATE TABLE T1 (a int);
-- eval CREATE TABLE T2 (b int) ENGINE=$engine
CREATE TABLE T3 (txt TEXT);
# assert: that tables exist on master with upper case names
show tables;
# assert: that tables exist on slave but with lower case names
-- sync_slave_with_master
-- echo ******** [ SLAVE ] ********
-- eval use $dbname_lower
show tables;
# action: lets create t1 for asserting below that t1 does not get changes
# from master (slave configured with --replicate-ignore-db=$dbname_lower.t1)
CREATE TABLE t1 (a INT);
# action: fill data into tables
-- connection master
-- echo ******** [ MASTER ] ********
-- eval use $dbname_upper
INSERT INTO T1 VALUES (1);
INSERT INTO T2 VALUES (1);
if (`SELECT @@session.binlog_format != 'ROW'`)
{
-- eval LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE $dbname_upper.T3
}
if (`SELECT @@session.binlog_format = 'ROW'`)
{
use test;
-- eval INSERT INTO $dbname_upper.T1 VALUES (2)
-- eval INSERT INTO $dbname_upper.T2 VALUES (2)
-- eval LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE $dbname_upper.T3
}
# assert: lower case tables on lower case database on slave
# get updates from upper case tables on upper case
# database on master
-- sync_slave_with_master
-- echo ******** [ SLAVE ] ********
# assert: changes for slave's t1 were filterd out
if (`SELECT count(*) != 0 FROM t1`)
{
-- echo UNEXPECTED DATA on $dbname_lower.t1 as table is filtered by replicate-ignore-table rules
}
-- let $diff_tables=master:$dbname_upper.T2, slave:$dbname_lower.t2
-- source include/diff_tables.inc
-- let $diff_tables=master:$dbname_upper.T3, slave:$dbname_lower.t3
-- source include/diff_tables.inc
# clean up
-- connection master
-- echo ******** [ MASTER ] ********
-- eval DROP DATABASE $dbname_upper
-- sync_slave_with_master
#
# BUG#50653: drop procedure implicitely treats db name in a case sensitive way
#
-- connection master
-- let $dbname= B50653
-- let $procname= b50653_proc
-- eval CREATE DATABASE $dbname
-- eval USE $dbname
-- eval CREATE PROCEDURE $procname() BEGIN SELECT 1; END
if (`SELECT count(*) = 1 FROM mysql.proc WHERE name like '$dbname'`)
{
-- die Procedure not created on MASTER
}
-- sync_slave_with_master
if (`SELECT count(*) = 1 FROM mysql.proc WHERE name like '$dbname'`)
{
-- die Procedure not created on SLAVE
}
-- connection master
-- eval DROP PROCEDURE $procname
if (`SELECT count(*) FROM mysql.proc WHERE name like '$dbname'`)
{
-- die Procedure not dropped on MASTER
}
-- sync_slave_with_master
if (`SELECT count(*) FROM mysql.proc WHERE name like '$dbname'`)
{
-- die Procedure not dropped on SLAVE
}
-- let $last_error = query_get_value("SHOW SLAVE STATUS", Last_SQL_Errno, 1)
if ($last_error)
{
-- die UNEXPECTED SLAVE SQL error: $last_error
}
-- connection master
-- eval DROP DATABASE $dbname
-- sync_slave_with_master
-- source include/rpl_end.inc
include/master-slave.inc
[connection master]
create table RPL(a int);
insert into RPL values(1);
select * from rpl;
a
1
insert into RPL values(3);
insert into rpl values(4);
select * from rpl;
a
1
3
4
drop table RPL;
include/rpl_end.inc
include/master-slave.inc
[connection master]
SET SQL_LOG_BIN=0;
CREATE DATABASE B37656;
SET SQL_LOG_BIN=1;
CREATE DATABASE BUG37656;
### action: show that database on slave is created in lowercase
SHOW DATABASES LIKE '%37656';
Database (%37656)
bug37656
USE B37656;
CREATE TABLE T1 (a int);
INSERT INTO T1 VALUES (1);
### assertion: master contains capitalized case table
SHOW TABLES;
Tables_in_B37656
T1
use bug37656;
### assertion: slave contains lowered case table
SHOW TABLES;
Tables_in_bug37656
t1
### assertion: master and slave tables do not differ
include/diff_tables.inc [master:B37656.T1, slave:bug37656.t1]
SET SQL_LOG_BIN=0;
DROP DATABASE B37656;
SET SQL_LOG_BIN=1;
SHOW DATABASES LIKE '%37656';
Database (%37656)
DROP DATABASE BUG37656;
SHOW DATABASES LIKE '%37656';
Database (%37656)
include/rpl_end.inc
include/master-slave.inc
[connection master]
******** [ MASTER ] ********
CREATE DATABASE BUG_37656;
use BUG_37656;
show databases like 'BUG_37656';
Database (BUG_37656)
BUG_37656
******** [ SLAVE ] ********
show databases like 'bug_37656';
Database (bug_37656)
bug_37656
******** [ MASTER ] ********
CREATE TABLE T1 (a int);
CREATE TABLE T2 (b int) ENGINE=InnoDB;
CREATE TABLE T3 (txt TEXT);
show tables;
Tables_in_BUG_37656
T1
T2
T3
******** [ SLAVE ] ********
use bug_37656;
show tables;
Tables_in_bug_37656
t2
t3
CREATE TABLE t1 (a INT);
******** [ MASTER ] ********
use BUG_37656;
INSERT INTO T1 VALUES (1);
INSERT INTO T2 VALUES (1);
use test;
INSERT INTO BUG_37656.T1 VALUES (2);
INSERT INTO BUG_37656.T2 VALUES (2);
LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE BUG_37656.T3;
******** [ SLAVE ] ********
include/diff_tables.inc [master:BUG_37656.T2, slave:bug_37656.t2]
include/diff_tables.inc [master:BUG_37656.T3, slave:bug_37656.t3]
******** [ MASTER ] ********
DROP DATABASE BUG_37656;
CREATE DATABASE B50653;
USE B50653;
CREATE PROCEDURE b50653_proc() BEGIN SELECT 1; END;
DROP PROCEDURE b50653_proc;
DROP DATABASE B50653;
include/rpl_end.inc
include/master-slave.inc
[connection master]
******** [ MASTER ] ********
CREATE DATABASE BUG_37656;
use BUG_37656;
show databases like 'BUG_37656';
Database (BUG_37656)
BUG_37656
******** [ SLAVE ] ********
show databases like 'bug_37656';
Database (bug_37656)
bug_37656
******** [ MASTER ] ********
CREATE TABLE T1 (a int);
CREATE TABLE T2 (b int) ENGINE=InnoDB;
CREATE TABLE T3 (txt TEXT);
show tables;
Tables_in_BUG_37656
T1
T2
T3
******** [ SLAVE ] ********
use bug_37656;
show tables;
Tables_in_bug_37656
t2
t3
CREATE TABLE t1 (a INT);
******** [ MASTER ] ********
use BUG_37656;
INSERT INTO T1 VALUES (1);
INSERT INTO T2 VALUES (1);
LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE BUG_37656.T3;
******** [ SLAVE ] ********
include/diff_tables.inc [master:BUG_37656.T2, slave:bug_37656.t2]
include/diff_tables.inc [master:BUG_37656.T3, slave:bug_37656.t3]
******** [ MASTER ] ********
DROP DATABASE BUG_37656;
CREATE DATABASE B50653;
USE B50653;
CREATE PROCEDURE b50653_proc() BEGIN SELECT 1; END;
DROP PROCEDURE b50653_proc;
DROP DATABASE B50653;
include/rpl_end.inc
--source include/master-slave.inc
--source include/have_innodb.inc
--connection master
create table RPL(a int);
insert into RPL values(1);
--sync_slave_with_master
select * from rpl;
insert into RPL values(3);
insert into rpl values(4);
select * from rpl;
--connection master
drop table RPL;
--source include/rpl_end.inc
--lower-case-table-names=1 "--replicate-rewrite-db=b37656->bug37656"
# BUG#37656
#
# DESCRIPTION
#
#
# This test case is tests whether replication works properly when
# slave is configured with --lower-case-table-names=1 and replication
# rewrite rules are in effect.
#
# It checks four issues:
#
# (i) master contains capitalized table name
#
# (ii) slave contains lowered case table name
#
# (iii) master and slave tables do not differ
#
-- source include/master-slave.inc
-- source include/not_windows.inc
SET SQL_LOG_BIN=0;
CREATE DATABASE B37656;
SET SQL_LOG_BIN=1;
-- connection slave
CREATE DATABASE BUG37656;
-- echo ### action: show that database on slave is created in lowercase
SHOW DATABASES LIKE '%37656';
-- connection master
USE B37656;
CREATE TABLE T1 (a int);
INSERT INTO T1 VALUES (1);
-- echo ### assertion: master contains capitalized case table
SHOW TABLES;
-- sync_slave_with_master
use bug37656;
-- echo ### assertion: slave contains lowered case table
SHOW TABLES;
-- echo ### assertion: master and slave tables do not differ
let $diff_tables= master:B37656.T1, slave:bug37656.t1;
-- source include/diff_tables.inc
-- connection master
SET SQL_LOG_BIN=0;
DROP DATABASE B37656;
SET SQL_LOG_BIN=1;
SHOW DATABASES LIKE '%37656';
-- connection slave
DROP DATABASE BUG37656;
SHOW DATABASES LIKE '%37656';
--source include/rpl_end.inc
--replicate-do-db=bug_37656 --replicate-ignore-table=buG_37656.T1 --replicate-do-table=bUg_37656.T2 --replicate-do-table=bUg_37656.T3 --lower-case-table-names=1
# BUG#37656
#
# For details look into extra/rpl_tests/rpl_lower_case_table_names.test
#
-- source include/master-slave.inc
-- source include/have_innodb.inc
-- source include/not_windows.inc
-- source include/have_binlog_format_row.inc
-- let $engine=InnoDB
-- source extra/rpl_tests/rpl_lower_case_table_names.test
--replicate-do-db=bug_37656 --replicate-ignore-table=bug_37656.t1 --replicate-do-table=bug_37656.t2 --replicate-do-table=bug_37656.t3 --lower-case-table-names=1
# BUG#37656
#
# For details look into extra/rpl_tests/rpl_lower_case_table_names.test
#
-- source include/master-slave.inc
-- source include/have_innodb.inc
-- source include/not_windows.inc
-- source include/have_binlog_format_mixed_or_statement.inc
-- let $engine=InnoDB
-- source extra/rpl_tests/rpl_lower_case_table_names.test
......@@ -245,6 +245,27 @@ static void inline slave_rows_error_report(enum loglevel level, int ha_error,
}
#endif
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
static void set_thd_db(THD *thd,const char *db, uint32 db_len)
{
char lcase_db_buf[NAME_LEN +1];
LEX_STRING new_db;
new_db.length= db_len;
if (lower_case_table_names == 1)
{
strmov(lcase_db_buf, db);
my_casedn_str(system_charset_info, lcase_db_buf);
new_db.str= lcase_db_buf;
}
else
new_db.str= (char*) db;
/* TODO WARNING this makes rewrite_db respect lower_case_table_names values
* for more info look MDEV-17446 */
new_db.str= (char*) rpl_filter->get_rewrite_db(new_db.str,
&new_db.length);
thd->set_db(new_db.str, new_db.length);
}
#endif
/*
Cache that will automatically be written to a dedicated file on
destruction.
......@@ -3619,7 +3640,6 @@ bool test_if_equal_repl_errors(int expected_error, int actual_error)
int Query_log_event::do_apply_event(Relay_log_info const *rli,
const char *query_arg, uint32 q_len_arg)
{
LEX_STRING new_db;
int expected_error,actual_error= 0;
HA_CREATE_INFO db_options;
DBUG_ENTER("Query_log_event::do_apply_event");
......@@ -3646,9 +3666,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
goto end;
}
new_db.length= db_len;
new_db.str= (char *) rpl_filter->get_rewrite_db(db, &new_db.length);
thd->set_db(new_db.str, new_db.length); /* allocates a copy of 'db' */
set_thd_db(thd, db, db_len);
/*
Setting the character set and collation of the current database thd->db.
......@@ -5424,13 +5442,10 @@ void Load_log_event::set_fields(const char* affected_db,
int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli,
bool use_rli_only_for_errors)
{
LEX_STRING new_db;
DBUG_ENTER("Load_log_event::do_apply_event");
new_db.length= db_len;
new_db.str= (char *) rpl_filter->get_rewrite_db(db, &new_db.length);
thd->set_db(new_db.str, new_db.length);
DBUG_ASSERT(thd->query() == 0);
set_thd_db(thd, db, db_len);
thd->reset_query_inner(); // Should not be needed
thd->is_slave_error= 0;
clear_all_errors(thd, const_cast<Relay_log_info*>(rli));
......@@ -5485,6 +5500,8 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli,
thd->warning_info->opt_clear_warning_info(thd->query_id);
TABLE_LIST tables;
if (lower_case_table_names)
my_casedn_str(system_charset_info, (char *)table_name);
tables.init_one_table(thd->strmake(thd->db, thd->db_length),
thd->db_length,
table_name, strlen(table_name),
......@@ -9678,7 +9695,7 @@ check_table_map(Relay_log_info const *rli, RPL_TABLE_LIST *table_list)
int Table_map_log_event::do_apply_event(Relay_log_info const *rli)
{
RPL_TABLE_LIST *table_list;
char *db_mem, *tname_mem;
char *db_mem, *tname_mem, *ptr;
size_t dummy_len;
void *memory;
DBUG_ENTER("Table_map_log_event::do_apply_event(Relay_log_info*)");
......@@ -9694,8 +9711,17 @@ int Table_map_log_event::do_apply_event(Relay_log_info const *rli)
NullS)))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
strmov(db_mem, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
strmov(db_mem, m_dbnam);
strmov(tname_mem, m_tblnam);
if (lower_case_table_names)
{
my_casedn_str(files_charset_info, (char*)tname_mem);
my_casedn_str(files_charset_info, (char*)db_mem);
}
/* rewrite rules changed the database */
if (((ptr= (char*) rpl_filter->get_rewrite_db(db_mem, &dummy_len)) != db_mem))
strmov(db_mem, ptr);
table_list->init_one_table(db_mem, strlen(db_mem),
tname_mem, strlen(tname_mem),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment