Commit db47e4ca authored by unknown's avatar unknown

Added timeout for wait_for_master_pos

Fixed comparision of log-binary name to handle comparison when file name extension wraps from .999 to .1000
Don't replicate CREATE/DROP DATABASE if wild_xxx_table=database.% is used.


mysql-test/r/rpl000009.result:
  Fixed replication test after fixing replication of DROP/CREATE DATABASE
mysql-test/t/rpl000009.test:
  Fixed replication test after fixing replication of DROP/CREATE DATABASE
sql/item_create.cc:
  Added timeout for wait_for_master_pos
sql/item_create.h:
  Added timeout for wait_for_master_pos
sql/item_func.cc:
  Added timeout for wait_for_master_pos
sql/item_func.h:
  Added timeout for wait_for_master_pos
sql/lex.h:
  Added timeout for wait_for_master_pos
sql/slave.h:
  Added timeout for wait_for_master_pos
  Don't replicate CREATE/DROP DATABASE if wild_xxx_table=database.% is used.
sql/sql_parse.cc:
  Don't replicate CREATE/DROP DATABASE if wild_xxx_table=database.% is used.
sql/sql_repl.cc:
  Fixed comparision of log-binary name to handle comparison when file name extension wraps from .999 to .1000
parent f2564f61
......@@ -8,6 +8,7 @@ drop database if exists foo;
create database foo;
drop database if exists bar;
create database bar;
create database foo;
drop table if exists foo.foo;
create table foo.foo (n int);
insert into foo.foo values(4);
......@@ -20,10 +21,11 @@ insert into bar.bar values(15);
select foo.foo.n,bar.bar.m from foo.foo,bar.bar;
n m
4 15
drop database if exists bar;
drop database if exists foo;
drop database if exists bar;
drop database bar;
drop database if exists foo;
drop database bar;
Can't drop database 'bar'. Database doesn't exist
drop database foo;
set sql_log_bin = 0;
create database foo;
create database bar;
......
slave stop;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
slave start;
select master_pos_wait('master-bin.999999',0,10);
master_pos_wait('master-bin.999999',0,10)
-1
......@@ -9,6 +9,7 @@ create database bar;
save_master_pos;
connection slave;
sync_with_master;
create database foo;
drop table if exists foo.foo;
create table foo.foo (n int);
insert into foo.foo values(4);
......@@ -24,13 +25,14 @@ connection slave;
sync_with_master;
select foo.foo.n,bar.bar.m from foo.foo,bar.bar;
connection master;
drop database if exists bar;
drop database bar;
drop database if exists foo;
save_master_pos;
connection slave;
sync_with_master;
drop database if exists bar;
drop database if exists foo;
--error 1008
drop database bar;
drop database foo;
# Now let's test load data from master
......
# See if master_pos_wait(,,timeout)
# Terminates with "timeout expired" (-1)
source include/master-slave.inc;
save_master_pos;
connection slave;
sync_with_master;
# Ask for a master log that has certainly not been reached yet
# timeout= 10 seconds
select master_pos_wait('master-bin.999999',0,10);
......@@ -424,12 +424,6 @@ Item *create_load_file(Item* a)
return new Item_load_file(a);
}
Item *create_wait_for_master_pos(Item* a, Item* b)
{
current_thd->safe_to_cache_query=0;
return new Item_master_pos_wait(a, b);
}
Item *create_func_cast(Item *a, Item_cast cast_type)
{
Item *res;
......
......@@ -92,6 +92,5 @@ Item *create_func_ucase(Item* a);
Item *create_func_version(void);
Item *create_func_weekday(Item* a);
Item *create_load_file(Item* a);
Item *create_wait_for_master_pos(Item* a, Item* b);
Item *create_func_is_free_lock(Item* a);
Item *create_func_quote(Item* a);
......@@ -1549,9 +1549,10 @@ longlong Item_master_pos_wait::val_int()
null_value = 1;
return 0;
}
ulong pos = (ulong)args[1]->val_int();
longlong pos = args[1]->val_int();
longlong timeout = (arg_count==3) ? args[2]->val_int() : 0 ;
LOCK_ACTIVE_MI;
if ((event_count = active_mi->rli.wait_for_pos(thd, log_name, pos)) == -1)
if ((event_count = active_mi->rli.wait_for_pos(thd, log_name, pos, timeout)) == -2)
{
null_value = 1;
event_count=0;
......
......@@ -865,9 +865,10 @@ class Item_master_pos_wait :public Item_int_func
String value;
public:
Item_master_pos_wait(Item *a,Item *b) :Item_int_func(a,b) {}
Item_master_pos_wait(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {}
longlong val_int();
const char *func_name() const { return "master_pos_wait"; }
void fix_length_and_dec() { max_length=1; maybe_null=1;}
void fix_length_and_dec() { max_length=21; maybe_null=1;}
unsigned int size_of() { return sizeof(*this);}
};
......
......@@ -462,9 +462,8 @@ static SYMBOL sql_functions[] = {
{ "LOWER", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_lcase)},
{ "LPAD", SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_lpad)},
{ "LTRIM", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ltrim)},
{ "MASTER_POS_WAIT", SYM(FUNC_ARG2),0,
CREATE_FUNC(create_wait_for_master_pos)},
{ "MAKE_SET", SYM(MAKE_SET_SYM),0,0},
{ "MASTER_POS_WAIT", SYM(MASTER_POS_WAIT),0,0},
{ "MAX", SYM(MAX_SYM),0,0},
{ "MD5", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_md5)},
{ "MID", SYM(SUBSTRING),0,0}, /* unireg function */
......
This diff is collapsed.
......@@ -226,7 +226,8 @@ typedef struct st_relay_log_info
pthread_mutex_unlock(&data_lock);
}
int wait_for_pos(THD* thd, String* log_name, ulonglong log_pos);
int wait_for_pos(THD* thd, String* log_name, longlong log_pos,
longlong timeout);
} RELAY_LOG_INFO;
......@@ -390,6 +391,7 @@ int tables_ok(THD* thd, TABLE_LIST* tables);
*/
int db_ok(const char* db, I_List<i_string> &do_list,
I_List<i_string> &ignore_list );
int db_ok_with_wild_table(const char *db);
int add_table_rule(HASH* h, const char* table_spec);
int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec);
......
......@@ -2253,6 +2253,18 @@ mysql_execute_command(void)
}
if (lower_case_table_names)
casedn_str(lex->name);
/*
If in a slave thread :
CREATE DATABASE DB was certainly not preceded by USE DB.
For that reason, db_ok() in sql/slave.cc did not check the
do_db/ignore_db. And as this query involves no tables, tables_ok()
above was not called. So we have to check rules again here.
*/
if (thd->slave_thread &&
(!db_ok(lex->name, replicate_do_db, replicate_ignore_db) ||
!db_ok_with_wild_table(lex->name)))
break;
if (check_access(thd,CREATE_ACL,lex->name,0,1))
break;
res=mysql_create_db(thd,lex->name,lex->create_info.options,0);
......@@ -2267,6 +2279,17 @@ mysql_execute_command(void)
}
if (lower_case_table_names)
casedn_str(lex->name);
/*
If in a slave thread :
DROP DATABASE DB may not be preceded by USE DB.
For that reason, maybe db_ok() in sql/slave.cc did not check the
do_db/ignore_db. And as this query involves no tables, tables_ok()
above was not called. So we have to check rules again here.
*/
if (thd->slave_thread &&
(!db_ok(lex->name, replicate_do_db, replicate_ignore_db) ||
!db_ok_with_wild_table(lex->name)))
break;
if (check_access(thd,DROP_ACL,lex->name,0,1))
break;
if (thd->locked_tables || thd->active_transaction())
......
......@@ -925,18 +925,17 @@ int cmp_master_pos(const char* log_file_name1, ulonglong log_pos1,
const char* log_file_name2, ulonglong log_pos2)
{
int res;
/*
TODO: Change compare function to work with file name of type
'.999 and .1000'
*/
uint log_file_name1_len= strlen(log_file_name1);
uint log_file_name2_len= strlen(log_file_name2);
if ((res = strcmp(log_file_name1, log_file_name2)))
// We assume that both log names match up to '.'
if (log_file_name1_len == log_file_name2_len)
{
if ((res= strcmp(log_file_name1, log_file_name2)))
return res;
if (log_pos1 > log_pos2)
return 1;
else if (log_pos1 == log_pos2)
return 0;
return -1;
return (log_pos1 < log_pos2) ? -1 : (log_pos1 == log_pos2) ? 0 : 1;
}
return ((log_file_name1_len < log_file_name2_len) ? -1 : 1);
}
......
......@@ -426,6 +426,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token LEFT
%token LOCATE
%token MAKE_SET_SYM
%token MASTER_POS_WAIT
%token MINUTE_SECOND_SYM
%token MINUTE_SYM
%token MODE_SYM
......@@ -1855,6 +1856,16 @@ simple_expr:
{ $$= new Item_func_log($3); }
| LOG_SYM '(' expr ',' expr ')'
{ $$= new Item_func_log($3, $5); }
| MASTER_POS_WAIT '(' expr ',' expr ')'
{
$$= new Item_master_pos_wait($3, $5);
current_thd->safe_to_cache_query=0;
}
| MASTER_POS_WAIT '(' expr ',' expr ',' expr ')'
{
$$= new Item_master_pos_wait($3, $5, $7);
current_thd->safe_to_cache_query=0;
}
| MINUTE_SYM '(' expr ')'
{ $$= new Item_func_minute($3); }
| MONTH_SYM '(' expr ')'
......
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