fixed bug in master_pos_wait(), got rid of sleep hack,

added test/sanity check for master_pos_wait()
parent 1385ffee
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db
127.0.0.1 root 9306 60 master-bin.001 216 Yes
s s
Could not break slave Could not break slave
Tried hard Tried hard
...@@ -7,6 +9,8 @@ master-bin.002 ...@@ -7,6 +9,8 @@ master-bin.002
master-bin.003 master-bin.003
Log_name Log_name
master-bin.003 master-bin.003
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db
127.0.0.1 root 9306 60 master-bin.003 128 Yes
m m
34 34
67 67
......
...@@ -12,7 +12,6 @@ insert into foo values(1),(2); ...@@ -12,7 +12,6 @@ insert into foo values(1),(2);
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
sleep 1;
use test; use test;
select * from foo; select * from foo;
select sum(length(word)) from t1; select sum(length(word)) from t1;
......
...@@ -9,7 +9,6 @@ save_master_pos; ...@@ -9,7 +9,6 @@ save_master_pos;
connection slave; connection slave;
use test; use test;
sync_with_master; sync_with_master;
sleep 1;
@r/rpl000002.result select * from t1; @r/rpl000002.result select * from t1;
connection master; connection master;
drop table t1; drop table t1;
......
...@@ -7,7 +7,6 @@ insert into t1 values (3); ...@@ -7,7 +7,6 @@ insert into t1 values (3);
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
sleep 1;
@r/rpl000003.result select * from t1; @r/rpl000003.result select * from t1;
connection master; connection master;
drop table t1; drop table t1;
......
...@@ -18,7 +18,6 @@ insert into bar values(15); ...@@ -18,7 +18,6 @@ insert into bar values(15);
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
sleep 1;
@r/rpl000007.result select foo.n,bar.m from foo,bar; @r/rpl000007.result select foo.n,bar.m from foo,bar;
connection master; connection master;
drop table if exists bar,foo; drop table if exists bar,foo;
......
...@@ -20,7 +20,6 @@ insert into choo values(55); ...@@ -20,7 +20,6 @@ insert into choo values(55);
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
sleep 1;
@r/rpl000008.result select foo.n,bar.m,choo.k from foo,bar,choo; @r/rpl000008.result select foo.n,bar.m,choo.k from foo,bar,choo;
connection master; connection master;
drop table if exists foo,bar,choo; drop table if exists foo,bar,choo;
......
...@@ -22,7 +22,6 @@ insert into bar.bar values(15); ...@@ -22,7 +22,6 @@ insert into bar.bar values(15);
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
sleep 1;
@r/rpl000009.result select foo.foo.n,bar.bar.m from foo.foo,bar.bar; @r/rpl000009.result select foo.foo.n,bar.bar.m from foo.foo,bar.bar;
connection master; connection master;
drop database if exists bar; drop database if exists bar;
......
...@@ -11,10 +11,10 @@ insert into t1 values(2); ...@@ -11,10 +11,10 @@ insert into t1 values(2);
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
sleep 1;
@r/rpl000010.result select n from t1; @r/rpl000010.result select n from t1;
connection master; connection master;
drop table t1; drop table t1;
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
...@@ -6,7 +6,6 @@ create table t1 (n int); ...@@ -6,7 +6,6 @@ create table t1 (n int);
insert into t1 values(1); insert into t1 values(1);
save_master_pos; save_master_pos;
connection slave; connection slave;
#give slave some breathing room to get started
sync_with_master; sync_with_master;
slave stop; slave stop;
slave start; slave start;
...@@ -16,7 +15,6 @@ save_master_pos; ...@@ -16,7 +15,6 @@ save_master_pos;
connection slave; connection slave;
#let slave catch up #let slave catch up
sync_with_master; sync_with_master;
sleep 1;
@r/rpl000011.result select * from t1; @r/rpl000011.result select * from t1;
connection master; connection master;
drop table t1; drop table t1;
......
...@@ -19,7 +19,6 @@ connection master2; ...@@ -19,7 +19,6 @@ connection master2;
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
sleep 1;
@r/rpl000012.result select * from t2; @r/rpl000012.result select * from t2;
@r/rpl000012.status.result show status like 'Slave_open_temp_tables'; @r/rpl000012.status.result show status like 'Slave_open_temp_tables';
# #
......
...@@ -22,7 +22,6 @@ connection master2; ...@@ -22,7 +22,6 @@ connection master2;
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
sleep 1;
@r/rpl000013.result select * from t2; @r/rpl000013.result select * from t2;
@r/rpl000013.status.result show status like 'Slave_open_temp_tables'; @r/rpl000013.status.result show status like 'Slave_open_temp_tables';
# #
......
...@@ -24,7 +24,6 @@ save_master_pos; ...@@ -24,7 +24,6 @@ save_master_pos;
connection slave; connection slave;
change master to master_log_pos=73; change master to master_log_pos=73;
sync_with_master; sync_with_master;
sleep 1;
select * from foo; select * from foo;
connection master; connection master;
drop table foo; drop table foo;
......
...@@ -4,6 +4,7 @@ source include/have_default_master.inc; ...@@ -4,6 +4,7 @@ source include/have_default_master.inc;
connection master; connection master;
reset master; reset master;
show master status; show master status;
save_master_pos;
connection slave; connection slave;
reset slave; reset slave;
show slave status; show slave status;
...@@ -13,7 +14,7 @@ change master to master_host='127.0.0.1',master_user='root', ...@@ -13,7 +14,7 @@ change master to master_host='127.0.0.1',master_user='root',
master_password='',master_port=9306; master_password='',master_port=9306;
show slave status; show slave status;
slave start; slave start;
sleep 3; sync_with_master;
show slave status; show slave status;
connection master; connection master;
drop table if exists foo; drop table if exists foo;
...@@ -22,7 +23,6 @@ insert into foo values (10),(45),(90); ...@@ -22,7 +23,6 @@ insert into foo values (10),(45),(90);
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
sleep 1;
select * from foo; select * from foo;
connection master; connection master;
drop table foo; drop table foo;
......
...@@ -10,6 +10,9 @@ system chmod 600 var/slave-data/master.info; ...@@ -10,6 +10,9 @@ system chmod 600 var/slave-data/master.info;
!change master to master_host='127.0.0.1',master_port=9306,master_user='root'; !change master to master_host='127.0.0.1',master_port=9306,master_user='root';
reset slave; reset slave;
!change master to master_host='127.0.0.1',master_port=9306,master_user='root'; !change master to master_host='127.0.0.1',master_port=9306,master_user='root';
connection master;
reset master;
connection slave;
slave start; slave start;
connection master; connection master;
drop table if exists t1; drop table if exists t1;
...@@ -18,7 +21,7 @@ insert into t1 values('Could not break slave'),('Tried hard'); ...@@ -18,7 +21,7 @@ insert into t1 values('Could not break slave'),('Tried hard');
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
sleep 1; show slave status;
select * from t1; select * from t1;
connection master; connection master;
flush logs; flush logs;
...@@ -27,14 +30,13 @@ create table t2(m int); ...@@ -27,14 +30,13 @@ create table t2(m int);
insert into t2 values (34),(67),(123); insert into t2 values (34),(67),(123);
flush logs; flush logs;
show master logs; show master logs;
sleep 2; # If a slow machine
purge master logs to 'master-bin.003'; purge master logs to 'master-bin.003';
show master logs; show master logs;
insert into t2 values (65); insert into t2 values (65);
save_master_pos; save_master_pos;
connection slave; connection slave;
sync_with_master; sync_with_master;
sleep 1; show slave status;
select * from t2; select * from t2;
drop table if exists t1,t2; drop table if exists t1,t2;
connection master; connection master;
......
...@@ -616,7 +616,7 @@ int st_master_info::wait_for_pos(THD* thd, String* log_name, ulong log_pos) ...@@ -616,7 +616,7 @@ int st_master_info::wait_for_pos(THD* thd, String* log_name, ulong log_pos)
bool pos_reached; bool pos_reached;
int event_count = 0; int event_count = 0;
pthread_mutex_lock(&lock); pthread_mutex_lock(&lock);
do while(!thd->killed)
{ {
int cmp_result; int cmp_result;
if (*log_file_name) if (*log_file_name)
...@@ -638,15 +638,13 @@ int st_master_info::wait_for_pos(THD* thd, String* log_name, ulong log_pos) ...@@ -638,15 +638,13 @@ int st_master_info::wait_for_pos(THD* thd, String* log_name, ulong log_pos)
pos_reached = ((!cmp_result && pos >= log_pos) || cmp_result > 0); pos_reached = ((!cmp_result && pos >= log_pos) || cmp_result > 0);
if (pos_reached || thd->killed) if (pos_reached || thd->killed)
break; break;
{
const char* msg = thd->enter_cond(&cond, &lock, const char* msg = thd->enter_cond(&cond, &lock,
"Waiting for master update"); "Waiting for master update");
pthread_cond_wait(&cond, &lock); pthread_cond_wait(&cond, &lock);
thd->exit_cond(msg); thd->exit_cond(msg);
event_count++; event_count++;
pos_reached = (pos >= log_pos);
} }
} while (!pos_reached && !thd->killed);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
return thd->killed ? -1 : event_count; return thd->killed ? -1 : event_count;
} }
......
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