Skip to content

Commit 390f2a0

Browse files
committed
Fix incorrect reading of events from relaylog in parallel replication.
The SQL thread keeps track of the position in the current relay log from which to read the next event. This position is not normally used, but a certain interaction with the IO thread can cause the SQL thread to re-open the relay log and seek to the stored position. In parallel replication, there were a couple of places where the position was not updated. This created a race where a re-open of the relay log could seek to the wrong position and start re-reading and processing events already handled once, causing various kinds of problems. Fix this by moving the position update into a single place in apply_event_and_update_pos(), which should ensure that the position is always updated in the parallel replication case. This problem was found from the testcase of MDEV-10863, but it is logically a separate problem.
1 parent f1fcc1f commit 390f2a0

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

sql/rpl_parallel.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2614,7 +2614,6 @@ rpl_parallel::do_event(rpl_group_info *serial_rgi, Log_event *ev,
26142614
/*
26152615
Queue the event for processing.
26162616
*/
2617-
rli->event_relay_log_pos= rli->future_event_relay_log_pos;
26182617
qev->ir= rli->last_inuse_relaylog;
26192618
++qev->ir->queued_count;
26202619
cur_thread->enqueue(qev);

sql/slave.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3569,6 +3569,13 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli,
35693569
if (rli->mi->using_parallel())
35703570
{
35713571
int res= rli->parallel.do_event(serial_rgi, ev, event_size);
3572+
/*
3573+
In parallel replication, we need to update the relay log position
3574+
immediately so that it will be the correct position from which to
3575+
read the next event.
3576+
*/
3577+
if (res == 0)
3578+
rli->event_relay_log_pos= rli->future_event_relay_log_pos;
35723579
if (res >= 0)
35733580
DBUG_RETURN(res);
35743581
/*

0 commit comments

Comments
 (0)