• svoj@mysql.com/june.mysql.com's avatar
    BUG#13861 - START SLAVE UNTIL may stop 1 evnt too late if · fe3b1c8e
    svoj@mysql.com/june.mysql.com authored
                log-slave-updates and circul repl
    
    Slave SQL thread may execute one extra event when there are events
    skipped by slave I/O thread (e.g. originated by the same server).
    Whereas it was requested not to do so by the UNTIL condition.
    
    This happens because we compare with the end position of previously
    executed event. This is fine when there are no skipped by slave I/O
    thread events, as end position of previous event equals to start
    position of to be executed event. Otherwise this position equals to
    start position of skipped event.
    
    This is fixed by:
    - reading the event to be executed before checking if the until condition
      is satisfied.
    - comparing the start position of the event to be executed. Since we do
      not have the start position available, we compute it by subtracting
      event length from end position (which is available).
    - if there are no events on the event queue at the slave sql starting
      time, that meet until condition, we stop immediately, as in this
      case we do not want to wait for next event.
    fe3b1c8e
rpl_dual_pos_advance.test 2.56 KB
# This test checks that in a dual-head setup
# A->B->A, where A has --log-slave-updates (why would it?
# assume that there is a C as slave of A),
# then the Exec_master_log_pos of SHOW SLAVE STATUS does
# not stay too low on B(BUG#13023 due to events ignored because
# of their server id).
# It also will test BUG#13861.

source include/master-slave.inc;
source include/have_innodb.inc;


# set up "dual head"

connection slave;
reset master;

connection master;
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval change master to master_host="127.0.0.1",master_port=$SLAVE_MYPORT,master_user="root";

start slave;

# now we test it

connection slave;

create table t1 (n int);

save_master_pos;
connection master;
sync_with_master;

#
# BUG#13861 - START SLAVE UNTIL may stop 1 evnt too late if
#             log-slave-updates and circul repl
#
stop slave;

create table t2 (n int); # create one ignored event

save_master_pos;
connection slave;
sync_with_master;

connection slave;

show tables;

save_master_pos;

create table t3 (n int) engine=innodb;
set @a=1;
insert into t3 values(@a);
begin;
insert into t3 values(2);
insert into t3 values(3);
commit;
insert into t3 values(4);


connection master;

# bug is that START SLAVE UNTIL may stop too late, we test that by
# asking it to stop before creation of t3.

start slave until master_log_file="slave-bin.000001",master_log_pos=195;

# wait until it's started (the position below is the start of "CREATE
# TABLE t2") (otherwise wait_for_slave_to_stop may return at once)

select master_pos_wait("slave-bin.000001",137);

wait_for_slave_to_stop;

# then BUG#13861 causes t3 to show up below (because stopped too
# late).

show tables;

# ensure that we do not break set @a=1; insert into t3 values(@a);
start slave until master_log_file="slave-bin.000001",master_log_pos=438;
wait_for_slave_to_stop;
select * from t3;

# ensure that we do not break transaction
start slave until master_log_file="slave-bin.000001",master_log_pos=663;
wait_for_slave_to_stop;
select * from t3;

start slave;

# BUG#13023 is that Exec_master_log_pos may stay too low "forever":

connection master;

create table t4 (n int); # create 3 ignored events
create table t5 (n int);
create table t6 (n int);

save_master_pos;
connection slave;
sync_with_master;

connection slave;

save_master_pos;

connection master;

# then BUG#13023 caused hang below ("master" looks behind, while it's
# not in terms of updates done).

sync_with_master;

show tables;

# cleanup

stop slave;
reset slave;
drop table t1,t2,t3,t4,t5,t6;

save_master_pos;
connection slave;
sync_with_master;

# End of 4.1 tests