Skip to content

Commit

Permalink
Fixing calculation seconds behind master when IO thread is caught up
Browse files Browse the repository at this point in the history
Summary:
When IO has finished downloading all binlogs but SQL thread is still
executing events a HB event from the master used to update the last master
timestamp on the slave which lead to SBM being reset. This change updates last
master timestamp from a HB event only when the SQL thread has caught up to the
IO thread.

Reference Patch: 257d463

Reviewed By: Pushapgl

Differential Revision: D27885260

fbshipit-source-id: 3642d8fca88
  • Loading branch information
Herman Lee authored and facebook-github-bot committed Apr 22, 2021
1 parent f1404cd commit 12768cb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions sql/rpl_slave.cc
Expand Up @@ -8316,8 +8316,19 @@ QUEUE_EVENT_RESULT queue_event(Master_info *mi, const char *buf,
is always monotonically increasing
*/
mysql_mutex_lock(&rli->data_lock);
rli->set_last_master_timestamp(hb.common_header->when.tv_sec,
hb.common_header->when.tv_sec * 1000);
auto io_thread_file = mi->get_master_log_name();
auto io_thread_pos = mi->get_master_log_pos();
auto sql_thread_file = mi->rli->get_group_master_log_name();
auto sql_thread_pos = mi->rli->get_group_master_log_pos();

// find out if the SQL thread has caught up with the IO thread by
// comparing their coordinates
bool caughtup = (sql_thread_pos == io_thread_pos) &&
(!strcmp(sql_thread_file, io_thread_file));
// case: update last master ts only if we've caughtup
if (caughtup)
rli->set_last_master_timestamp(hb.common_header->when.tv_sec,
hb.common_header->when.tv_sec * 1000);
mysql_mutex_unlock(&rli->data_lock);

/*
Expand Down

0 comments on commit 12768cb

Please sign in to comment.