Commit c6200353 authored by unknown's avatar unknown

client/mysqltest.c

    fixed bug that created empty result files in no-record mode
mysql-test/t/rpl000007.test
    testing non-replication of load data infile when the table is excluded from replication
mysql-test/t/rpl000016.test
    test purge master logs
sql/slave.cc
    fix memory leaks found by  purge master logs test
sql/sql_repl.cc
    fixed race condition and delete before close bug in reset_slave()

Overall comments - coverage testing is a very good thing!


client/mysqltest.c:
  fixed bug that created empty result files in no-record mode
mysql-test/t/rpl000007.test:
  testing non-replication of load data infile when the table is excluded from replication
mysql-test/t/rpl000016.test:
  test purge master logs
sql/slave.cc:
  fix memory leaks found by  purge master logs test
sql/sql_repl.cc:
  fixed race condition and delete before close bug in reset_slave()
parent e2900df8
......@@ -1306,9 +1306,9 @@ int main(int argc, char** argv)
close_cons();
if(result_file)
if(result_file && ds_res.len)
{
if(!record && ds_res.len)
if(!record)
error |= check_result(&ds_res, result_file);
else
str_to_file(result_file, ds_res.str, ds_res.len);
......
......@@ -9,8 +9,9 @@ insert into foo values(4);
connection master;
use test;
drop table if exists foo;
create table foo (n int);
insert into foo values(5);
create table foo (s char(20));
load data infile '../../std_data/words.dat' into table foo;
insert into foo values('five');
drop table if exists bar;
create table bar (m int);
insert into bar values(15);
......
......@@ -17,3 +17,17 @@ insert into foo values('Could not break slave'),('Tried hard');
connection slave;
sleep 0.3;
select * from foo;
connection master;
flush logs;
drop table if exists bar;
create table bar(m int);
insert into bar values (34),(67),(123);
flush logs;
sleep 0.3;
show master logs;
purge master logs to 'master-bin.003';
show master logs;
insert into bar values (65);
connection slave;
sleep 0.3;
select * from bar;
......@@ -259,7 +259,7 @@ int db_ok(const char* db, I_List<i_string> &do_list,
}
}
static void init_strvar_from_file(char* var, int max_size, IO_CACHE* f,
static int init_strvar_from_file(char* var, int max_size, IO_CACHE* f,
char* default_val)
{
......@@ -272,12 +272,18 @@ static void init_strvar_from_file(char* var, int max_size, IO_CACHE* f,
while( ((c=my_b_get(f)) != '\n' && c != my_b_EOF));
// if we truncated a line or stopped on last char, remove all chars
// up to and including newline
return 0;
}
else if(default_val)
{
strmake(var, default_val, max_size);
return 0;
}
return 1;
}
static void init_intvar_from_file(int* var, IO_CACHE* f,
static int init_intvar_from_file(int* var, IO_CACHE* f,
int default_val)
{
char buf[32];
......@@ -285,9 +291,14 @@ static void init_intvar_from_file(int* var, IO_CACHE* f,
if(my_b_gets(f, buf, sizeof(buf)))
{
*var = atoi(buf);
return 0;
}
else if(default_val)
{
*var = default_val;
return 0;
}
return 1;
}
......@@ -462,6 +473,8 @@ int init_master_info(MASTER_INFO* mi)
|| init_io_cache(&mi->file, fd, IO_SIZE*2, READ_CACHE, 0L,0,
MYF(MY_WME)))
{
if(fd >= 0)
my_close(fd, MYF(0));
pthread_mutex_unlock(&mi->lock);
return 1;
}
......@@ -487,6 +500,8 @@ int init_master_info(MASTER_INFO* mi)
|| init_io_cache(&mi->file, fd, IO_SIZE*2, READ_CACHE, 0L,
0, MYF(MY_WME)))
{
if(fd >= 0)
my_close(fd, MYF(0));
pthread_mutex_unlock(&mi->lock);
return 1;
}
......@@ -494,6 +509,8 @@ int init_master_info(MASTER_INFO* mi)
if(!my_b_gets(&mi->file, mi->log_file_name, sizeof(mi->log_file_name)))
{
sql_print_error("Error reading log file name from master info file ");
end_io_cache(&mi->file);
my_close(fd, MYF(0));
pthread_mutex_unlock(&mi->lock);
return 1;
}
......@@ -503,23 +520,30 @@ int init_master_info(MASTER_INFO* mi)
if(!my_b_gets(&mi->file, buf, sizeof(buf)))
{
sql_print_error("Error reading log file position from master info file");
end_io_cache(&mi->file);
my_close(fd, MYF(0));
pthread_mutex_unlock(&mi->lock);
return 1;
}
mi->pos = atoi(buf);
mi->fd = fd;
init_strvar_from_file(mi->host, sizeof(mi->host), &mi->file,
master_host);
if(init_strvar_from_file(mi->host, sizeof(mi->host), &mi->file,
master_host) ||
init_strvar_from_file(mi->user, sizeof(mi->user), &mi->file,
master_user);
master_user) ||
init_strvar_from_file(mi->password, sizeof(mi->password), &mi->file,
master_password);
init_intvar_from_file((int*)&mi->port, &mi->file, master_port);
master_password) ||
init_intvar_from_file((int*)&mi->port, &mi->file, master_port) ||
init_intvar_from_file((int*)&mi->connect_retry, &mi->file,
master_connect_retry);
master_connect_retry))
{
sql_print_error("Error reading master configuration");
end_io_cache(&mi->file);
my_close(fd, MYF(0));
pthread_mutex_unlock(&mi->lock);
return 1;
}
}
mi->inited = 1;
......@@ -858,6 +882,18 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
thd->query_id = query_id++;
VOID(pthread_mutex_unlock(&LOCK_thread_count));
TABLE_LIST tables;
bzero((char*) &tables,sizeof(tables));
tables.db = thd->db;
tables.name = tables.real_name = (char*)lev->table_name;
tables.lock_type = TL_WRITE;
// the table will be opened in mysql_load
if(table_rules_on && !tables_ok(thd, &tables))
{
skip_load_data_infile(net);
}
else
{
enum enum_duplicates handle_dup = DUP_IGNORE;
if(lev->sql_ex.opt_flags && REPLACE_FLAG)
handle_dup = DUP_REPLACE;
......@@ -895,12 +931,6 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
ex.skip_lines = lev->skip_lines;
TABLE_LIST tables;
bzero((char*) &tables,sizeof(tables));
tables.db = thd->db;
tables.name = tables.real_name = (char*)lev->table_name;
tables.lock_type = TL_WRITE;
// the table will be opened in mysql_load
List<Item> fields;
lev->set_fields(fields);
......@@ -918,6 +948,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
'%s' produced %d warning(s)", glob_mi.pos, RPL_LOG_NAME, thd->cuted_fields );
net->pkt_nr = thd->net.pkt_nr;
}
}
else // we will just ask the master to send us /dev/null if we do not want to
// load the data :-)
{
......
......@@ -577,16 +577,22 @@ void reset_slave()
{
MY_STAT stat_area;
char fname[FN_REFLEN];
bool slave_was_running = slave_running;
bool slave_was_running ;
if(slave_running)
pthread_mutex_lock(&LOCK_slave);
if((slave_was_running = slave_running))
{
pthread_mutex_unlock(&LOCK_slave);
stop_slave(0,0);
}
else
pthread_mutex_unlock(&LOCK_slave);
end_master_info(&glob_mi);
fn_format(fname, master_info_file, mysql_data_home, "", 4+16+32);
if(my_stat(fname, &stat_area, MYF(0)))
if(my_delete(fname, MYF(MY_WME)))
return;
end_master_info(&glob_mi);
if(slave_was_running)
start_slave(0,0);
}
......
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