Skip to content

Commit 75dc267

Browse files
committed
Change Seconds_behind_master to be updated only at commit in parallel replication
Before, the Seconds_behind_master was updated already when an event was queued for a worker thread to execute later. This might lead users to interpret a low value as the slave being almost up to date with the master, while in reality there might still be lots and lots of events still queued up waiting to be applied by the slave. See https://lists.launchpad.net/maria-developers/msg08958.html for more detailed discussions.
1 parent e7cb032 commit 75dc267

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

sql/rpl_parallel.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ rpt_handle_event(rpl_parallel_thread::queued_event *qev,
4444
rgi->event_relay_log_pos= qev->event_relay_log_pos;
4545
rgi->future_event_relay_log_pos= qev->future_event_relay_log_pos;
4646
strcpy(rgi->future_event_master_log_name, qev->future_event_master_log_name);
47+
if (!(ev->is_artificial_event() || ev->is_relay_log_event() ||
48+
(ev->when == 0)))
49+
rgi->last_master_timestamp= ev->when + (time_t)ev->exec_time;
4750
mysql_mutex_lock(&rli->data_lock);
4851
/* Mutex will be released in apply_event_and_update_pos(). */
4952
err= apply_event_and_update_pos(ev, thd, rgi, rpt);

sql/rpl_rli.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,18 @@ void Relay_log_info::inc_group_relay_log_pos(ulonglong log_pos,
10011001
else if (group_master_log_pos < log_pos)
10021002
group_master_log_pos= log_pos;
10031003
}
1004+
1005+
/*
1006+
In the parallel case, we only update the Seconds_Behind_Master at the
1007+
end of a transaction. In the non-parallel case, the value is updated as
1008+
soon as an event is read from the relay log; however this would be too
1009+
confusing for the user, seeing the slave reported as up-to-date when
1010+
potentially thousands of events are still queued up for worker threads
1011+
waiting for execution.
1012+
*/
1013+
if (rgi->last_master_timestamp &&
1014+
rgi->last_master_timestamp > last_master_timestamp)
1015+
last_master_timestamp= rgi->last_master_timestamp;
10041016
}
10051017
else
10061018
{
@@ -1630,6 +1642,7 @@ rpl_group_info::reinit(Relay_log_info *rli)
16301642
row_stmt_start_timestamp= 0;
16311643
long_find_row_note_printed= false;
16321644
did_mark_start_commit= false;
1645+
last_master_timestamp = 0;
16331646
gtid_ignore_duplicate_state= GTID_DUPLICATE_NULL;
16341647
commit_orderer.reinit();
16351648
}

sql/rpl_rli.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,13 @@ struct rpl_group_info
668668
/* Needs room for "Gtid D-S-N\x00". */
669669
char gtid_info_buf[5+10+1+10+1+20+1];
670670

671+
/*
672+
The timestamp, from the master, of the commit event.
673+
Used to do delayed update of rli->last_master_timestamp, for getting
674+
reasonable values out of Seconds_Behind_Master in SHOW SLAVE STATUS.
675+
*/
676+
time_t last_master_timestamp;
677+
671678
/*
672679
Information to be able to re-try an event group in case of a deadlock or
673680
other temporary error.

sql/slave.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3500,8 +3500,13 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli,
35003500
If it is an artificial event, or a relay log event (IO thread generated
35013501
event) or ev->when is set to 0, we don't update the
35023502
last_master_timestamp.
3503+
3504+
In parallel replication, we might queue a large number of events, and
3505+
the user might be surprised to see a claim that the slave is up to date
3506+
long before those queued events are actually executed.
35033507
*/
3504-
if (!(ev->is_artificial_event() || ev->is_relay_log_event() || (ev->when == 0)))
3508+
if (opt_slave_parallel_threads == 0 &&
3509+
!(ev->is_artificial_event() || ev->is_relay_log_event() || (ev->when == 0)))
35053510
{
35063511
rli->last_master_timestamp= ev->when + (time_t) ev->exec_time;
35073512
DBUG_ASSERT(rli->last_master_timestamp >= 0);

0 commit comments

Comments
 (0)