Commit 3c5ebd9d authored by Monty's avatar Monty Committed by Andrei Elkin

Changed from using LOCK_log to LOCK_binlog_end_pos for binary log

Part of MDEV-13073 AliSQL Optimize performance of semisync

The idea it to use a dedicated lock detecting if there is new data in
the master's binary log instead of the overused LOCK_log.

Changes:
- Use dedicated COND variables for the relay and binary log signaling.
  This was needed as we where the old 'update_cond' variable was used
  with different mutex's, which could cause deadlocks.
   - Relay log uses now COND_relay_log_updated and LOCK_log
   - Binary log uses now COND_bin_log_updated and LOCK_binlog_end_pos
- Renamed signal_cnt to relay_signal_cnt (as we now have two signals)
- Added some missing error handling in MYSQL_BIN_LOG::new_file_impl()
- Reformatted some comments with old style
- Renamed m_key_LOCK_binlog_end_pos to key_LOCK_binlog_end_pos
- Changed 'signal_update()' to update_binlog_end_pos() which works for
  both relay and binary log
parent 4234a170
...@@ -62,7 +62,9 @@ where event_name like "%MYSQL_BIN_LOG%" ...@@ -62,7 +62,9 @@ where event_name like "%MYSQL_BIN_LOG%"
and event_name not like "%MYSQL_BIN_LOG::COND_xid_list" and event_name not like "%MYSQL_BIN_LOG::COND_xid_list"
order by event_name; order by event_name;
EVENT_NAME COUNT_STAR EVENT_NAME COUNT_STAR
wait/synch/cond/sql/MYSQL_BIN_LOG::COND_bin_log_updated MANY
wait/synch/cond/sql/MYSQL_BIN_LOG::COND_queue_busy NONE wait/synch/cond/sql/MYSQL_BIN_LOG::COND_queue_busy NONE
wait/synch/cond/sql/MYSQL_BIN_LOG::COND_relay_log_updated NONE
wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_binlog_background_thread MANY wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_binlog_background_thread MANY
wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_binlog_end_pos MANY wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_binlog_end_pos MANY
wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index MANY wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index MANY
...@@ -81,7 +83,9 @@ where event_name like "%MYSQL_RELAY_LOG%" ...@@ -81,7 +83,9 @@ where event_name like "%MYSQL_RELAY_LOG%"
and event_name not like "%MYSQL_RELAY_LOG::update_cond" and event_name not like "%MYSQL_RELAY_LOG::update_cond"
order by event_name; order by event_name;
EVENT_NAME COUNT_STAR SUM_TIMER_WAIT MIN_TIMER_WAIT AVG_TIMER_WAIT MAX_TIMER_WAIT EVENT_NAME COUNT_STAR SUM_TIMER_WAIT MIN_TIMER_WAIT AVG_TIMER_WAIT MAX_TIMER_WAIT
wait/synch/cond/sql/MYSQL_RELAY_LOG::COND_bin_log_updated 0 0 0 0 0
wait/synch/cond/sql/MYSQL_RELAY_LOG::COND_queue_busy 0 0 0 0 0 wait/synch/cond/sql/MYSQL_RELAY_LOG::COND_queue_busy 0 0 0 0 0
wait/synch/cond/sql/MYSQL_RELAY_LOG::COND_relay_log_updated 0 0 0 0 0
wait/synch/mutex/sql/MYSQL_RELAY_LOG::LOCK_index 0 0 0 0 0 wait/synch/mutex/sql/MYSQL_RELAY_LOG::LOCK_index 0 0 0 0 0
connection slave; connection slave;
"============ Performance schema on slave ============" "============ Performance schema on slave ============"
...@@ -142,7 +146,9 @@ where event_name like "%MYSQL_BIN_LOG%" ...@@ -142,7 +146,9 @@ where event_name like "%MYSQL_BIN_LOG%"
and event_name not like "%MYSQL_BIN_LOG::COND_xid_list" and event_name not like "%MYSQL_BIN_LOG::COND_xid_list"
order by event_name; order by event_name;
EVENT_NAME COUNT_STAR EVENT_NAME COUNT_STAR
wait/synch/cond/sql/MYSQL_BIN_LOG::COND_bin_log_updated NONE
wait/synch/cond/sql/MYSQL_BIN_LOG::COND_queue_busy NONE wait/synch/cond/sql/MYSQL_BIN_LOG::COND_queue_busy NONE
wait/synch/cond/sql/MYSQL_BIN_LOG::COND_relay_log_updated NONE
wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_binlog_background_thread MANY wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_binlog_background_thread MANY
wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_binlog_end_pos MANY wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_binlog_end_pos MANY
wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index MANY wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index MANY
...@@ -184,6 +190,8 @@ where event_name like "%MYSQL_RELAY_LOG%" ...@@ -184,6 +190,8 @@ where event_name like "%MYSQL_RELAY_LOG%"
and event_name not like "%MYSQL_RELAY_LOG::update_cond" and event_name not like "%MYSQL_RELAY_LOG::update_cond"
order by event_name; order by event_name;
EVENT_NAME COUNT_STAR EVENT_NAME COUNT_STAR
wait/synch/cond/sql/MYSQL_RELAY_LOG::COND_bin_log_updated NONE
wait/synch/cond/sql/MYSQL_RELAY_LOG::COND_queue_busy NONE wait/synch/cond/sql/MYSQL_RELAY_LOG::COND_queue_busy NONE
wait/synch/cond/sql/MYSQL_RELAY_LOG::COND_relay_log_updated MANY
wait/synch/mutex/sql/MYSQL_RELAY_LOG::LOCK_index MANY wait/synch/mutex/sql/MYSQL_RELAY_LOG::LOCK_index MANY
include/stop_slave.inc include/stop_slave.inc
...@@ -3146,7 +3146,7 @@ MYSQL_BIN_LOG::MYSQL_BIN_LOG(uint *sync_period) ...@@ -3146,7 +3146,7 @@ MYSQL_BIN_LOG::MYSQL_BIN_LOG(uint *sync_period)
group_commit_trigger_lock_wait(0), group_commit_trigger_lock_wait(0),
sync_period_ptr(sync_period), sync_counter(0), sync_period_ptr(sync_period), sync_counter(0),
state_file_deleted(false), binlog_state_recover_done(false), state_file_deleted(false), binlog_state_recover_done(false),
is_relay_log(0), signal_cnt(0), is_relay_log(0), relay_signal_cnt(0),
checksum_alg_reset(BINLOG_CHECKSUM_ALG_UNDEF), checksum_alg_reset(BINLOG_CHECKSUM_ALG_UNDEF),
relay_log_checksum_alg(BINLOG_CHECKSUM_ALG_UNDEF), relay_log_checksum_alg(BINLOG_CHECKSUM_ALG_UNDEF),
description_event_for_exec(0), description_event_for_queue(0), description_event_for_exec(0), description_event_for_queue(0),
...@@ -3216,7 +3216,8 @@ void MYSQL_BIN_LOG::cleanup() ...@@ -3216,7 +3216,8 @@ void MYSQL_BIN_LOG::cleanup()
mysql_mutex_destroy(&LOCK_xid_list); mysql_mutex_destroy(&LOCK_xid_list);
mysql_mutex_destroy(&LOCK_binlog_background_thread); mysql_mutex_destroy(&LOCK_binlog_background_thread);
mysql_mutex_destroy(&LOCK_binlog_end_pos); mysql_mutex_destroy(&LOCK_binlog_end_pos);
mysql_cond_destroy(&update_cond); mysql_cond_destroy(&COND_relay_log_updated);
mysql_cond_destroy(&COND_bin_log_updated);
mysql_cond_destroy(&COND_queue_busy); mysql_cond_destroy(&COND_queue_busy);
mysql_cond_destroy(&COND_xid_list); mysql_cond_destroy(&COND_xid_list);
mysql_cond_destroy(&COND_binlog_background_thread); mysql_cond_destroy(&COND_binlog_background_thread);
...@@ -3251,7 +3252,8 @@ void MYSQL_BIN_LOG::init_pthread_objects() ...@@ -3251,7 +3252,8 @@ void MYSQL_BIN_LOG::init_pthread_objects()
mysql_mutex_setflags(&LOCK_index, MYF_NO_DEADLOCK_DETECTION); mysql_mutex_setflags(&LOCK_index, MYF_NO_DEADLOCK_DETECTION);
mysql_mutex_init(key_BINLOG_LOCK_xid_list, mysql_mutex_init(key_BINLOG_LOCK_xid_list,
&LOCK_xid_list, MY_MUTEX_INIT_FAST); &LOCK_xid_list, MY_MUTEX_INIT_FAST);
mysql_cond_init(m_key_update_cond, &update_cond, 0); mysql_cond_init(m_key_relay_log_update, &COND_relay_log_updated, 0);
mysql_cond_init(m_key_bin_log_update, &COND_bin_log_updated, 0);
mysql_cond_init(m_key_COND_queue_busy, &COND_queue_busy, 0); mysql_cond_init(m_key_COND_queue_busy, &COND_queue_busy, 0);
mysql_cond_init(key_BINLOG_COND_xid_list, &COND_xid_list, 0); mysql_cond_init(key_BINLOG_COND_xid_list, &COND_xid_list, 0);
...@@ -3262,7 +3264,7 @@ void MYSQL_BIN_LOG::init_pthread_objects() ...@@ -3262,7 +3264,7 @@ void MYSQL_BIN_LOG::init_pthread_objects()
mysql_cond_init(key_BINLOG_COND_binlog_background_thread_end, mysql_cond_init(key_BINLOG_COND_binlog_background_thread_end,
&COND_binlog_background_thread_end, 0); &COND_binlog_background_thread_end, 0);
mysql_mutex_init(m_key_LOCK_binlog_end_pos, &LOCK_binlog_end_pos, mysql_mutex_init(key_LOCK_binlog_end_pos, &LOCK_binlog_end_pos,
MY_MUTEX_INIT_SLOW); MY_MUTEX_INIT_SLOW);
} }
...@@ -3737,6 +3739,11 @@ bool MYSQL_BIN_LOG::open(const char *log_name, ...@@ -3737,6 +3739,11 @@ bool MYSQL_BIN_LOG::open(const char *log_name,
close_purge_index_file(); close_purge_index_file();
#endif #endif
/* Notify the io thread that binlog is rotated to a new file */
if (is_relay_log)
signal_relay_log_update();
else
update_binlog_end_pos();
DBUG_RETURN(0); DBUG_RETURN(0);
err: err:
...@@ -5058,7 +5065,12 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock) ...@@ -5058,7 +5065,12 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock)
new file name in the current binary log file. new file name in the current binary log file.
*/ */
if ((error= generate_new_name(new_name, name, 0))) if ((error= generate_new_name(new_name, name, 0)))
{
#ifdef ENABLE_AND_FIX_HANG
close_on_error= TRUE;
#endif
goto end; goto end;
}
new_name_ptr=new_name; new_name_ptr=new_name;
if (log_type == LOG_BIN) if (log_type == LOG_BIN)
...@@ -5089,13 +5101,20 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock) ...@@ -5089,13 +5101,20 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock)
} }
bytes_written += r.data_written; bytes_written += r.data_written;
} }
}
/* /*
Update needs to be signalled even if there is no rotate event Update needs to be signalled even if there is no rotate event
log rotation should give the waiting thread a signal to log rotation should give the waiting thread a signal to
discover EOF and move on to the next log. discover EOF and move on to the next log.
*/ */
signal_update(); if ((error= flush_io_cache(&log_file)))
{
close_on_error= TRUE;
goto end;
} }
update_binlog_end_pos();
old_name=name; old_name=name;
name=0; // Don't free name name=0; // Don't free name
close_flag= LOG_CLOSE_TO_BE_OPENED | LOG_CLOSE_INDEX; close_flag= LOG_CLOSE_TO_BE_OPENED | LOG_CLOSE_INDEX;
...@@ -5182,7 +5201,6 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock) ...@@ -5182,7 +5201,6 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock)
"server and restart it.", "server and restart it.",
new_name_ptr, errno); new_name_ptr, errno);
} }
mysql_mutex_unlock(&LOCK_index); mysql_mutex_unlock(&LOCK_index);
if (need_lock) if (need_lock)
mysql_mutex_unlock(&LOCK_log); mysql_mutex_unlock(&LOCK_log);
...@@ -5229,7 +5247,7 @@ bool MYSQL_BIN_LOG::append_no_lock(Log_event* ev) ...@@ -5229,7 +5247,7 @@ bool MYSQL_BIN_LOG::append_no_lock(Log_event* ev)
if (my_b_append_tell(&log_file) > max_size) if (my_b_append_tell(&log_file) > max_size)
error= new_file_without_locking(); error= new_file_without_locking();
err: err:
signal_update(); // Safe as we don't call close update_binlog_end_pos();
DBUG_RETURN(error); DBUG_RETURN(error);
} }
...@@ -5290,7 +5308,7 @@ bool MYSQL_BIN_LOG::write_event_buffer(uchar* buf, uint len) ...@@ -5290,7 +5308,7 @@ bool MYSQL_BIN_LOG::write_event_buffer(uchar* buf, uint len)
err: err:
my_safe_afree(ebuf, len); my_safe_afree(ebuf, len);
if (!error) if (!error)
signal_update(); update_binlog_end_pos();
DBUG_RETURN(error); DBUG_RETURN(error);
} }
...@@ -6291,6 +6309,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate) ...@@ -6291,6 +6309,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate)
{ {
my_off_t offset= my_b_tell(file); my_off_t offset= my_b_tell(file);
bool check_purge= false; bool check_purge= false;
DBUG_ASSERT(!is_relay_log);
if (!error) if (!error)
{ {
...@@ -6316,15 +6335,14 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate) ...@@ -6316,15 +6335,14 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate)
} }
else else
{ {
/* update binlog_end_pos so it can be read by dump thread /*
* update binlog_end_pos so it can be read by dump thread
* note: must be _after_ the RUN_HOOK(after_flush) or else
* semi-sync-plugin might not have put the transaction into note: must be _after_ the RUN_HOOK(after_flush) or else
* it's list before dump-thread tries to send it semi-sync might not have put the transaction into
it's list before dump-thread tries to send it
*/ */
update_binlog_end_pos(offset); update_binlog_end_pos(offset);
signal_update();
if ((error= rotate(false, &check_purge))) if ((error= rotate(false, &check_purge)))
check_purge= false; check_purge= false;
} }
...@@ -6928,7 +6946,7 @@ bool MYSQL_BIN_LOG::write_incident(THD *thd) ...@@ -6928,7 +6946,7 @@ bool MYSQL_BIN_LOG::write_incident(THD *thd)
if (!(error= write_incident_already_locked(thd)) && if (!(error= write_incident_already_locked(thd)) &&
!(error= flush_and_sync(0))) !(error= flush_and_sync(0)))
{ {
signal_update(); update_binlog_end_pos();
if ((error= rotate(false, &check_purge))) if ((error= rotate(false, &check_purge)))
check_purge= false; check_purge= false;
} }
...@@ -6969,7 +6987,7 @@ MYSQL_BIN_LOG::write_binlog_checkpoint_event_already_locked(const char *name_arg ...@@ -6969,7 +6987,7 @@ MYSQL_BIN_LOG::write_binlog_checkpoint_event_already_locked(const char *name_arg
*/ */
if (!write_event(&ev) && !flush_and_sync(0)) if (!write_event(&ev) && !flush_and_sync(0))
{ {
signal_update(); update_binlog_end_pos();
} }
else else
{ {
...@@ -7637,7 +7655,6 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader) ...@@ -7637,7 +7655,6 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader)
else else
{ {
bool any_error= false; bool any_error= false;
bool all_error= true;
mysql_mutex_assert_not_owner(&LOCK_prepare_ordered); mysql_mutex_assert_not_owner(&LOCK_prepare_ordered);
mysql_mutex_assert_owner(&LOCK_log); mysql_mutex_assert_owner(&LOCK_log);
...@@ -7659,23 +7676,19 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader) ...@@ -7659,23 +7676,19 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader)
current->error_cache= NULL; current->error_cache= NULL;
any_error= true; any_error= true;
} }
else
all_error= false;
first= false; first= false;
} }
/* update binlog_end_pos so it can be read by dump thread /*
* update binlog_end_pos so it can be read by dump thread
* note: must be _after_ the RUN_HOOK(after_flush) or else Note: must be _after_ the RUN_HOOK(after_flush) or else
* semi-sync-plugin might not have put the transaction into semi-sync might not have put the transaction into
* it's list before dump-thread tries to send it it's list before dump-thread tries to send it
*/ */
update_binlog_end_pos(commit_offset); update_binlog_end_pos(commit_offset);
if (any_error) if (any_error)
sql_print_error("Failed to run 'after_flush' hooks"); sql_print_error("Failed to run 'after_flush' hooks");
if (!all_error)
signal_update();
} }
/* /*
...@@ -8055,10 +8068,10 @@ void MYSQL_BIN_LOG::wait_for_update_relay_log(THD* thd) ...@@ -8055,10 +8068,10 @@ void MYSQL_BIN_LOG::wait_for_update_relay_log(THD* thd)
DBUG_ENTER("wait_for_update_relay_log"); DBUG_ENTER("wait_for_update_relay_log");
mysql_mutex_assert_owner(&LOCK_log); mysql_mutex_assert_owner(&LOCK_log);
thd->ENTER_COND(&update_cond, &LOCK_log, thd->ENTER_COND(&COND_relay_log_updated, &LOCK_log,
&stage_slave_has_read_all_relay_log, &stage_slave_has_read_all_relay_log,
&old_stage); &old_stage);
mysql_cond_wait(&update_cond, &LOCK_log); mysql_cond_wait(&COND_relay_log_updated, &LOCK_log);
thd->EXIT_COND(&old_stage); thd->EXIT_COND(&old_stage);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -8086,11 +8099,11 @@ int MYSQL_BIN_LOG::wait_for_update_bin_log(THD* thd, ...@@ -8086,11 +8099,11 @@ int MYSQL_BIN_LOG::wait_for_update_bin_log(THD* thd,
DBUG_ENTER("wait_for_update_bin_log"); DBUG_ENTER("wait_for_update_bin_log");
thd_wait_begin(thd, THD_WAIT_BINLOG); thd_wait_begin(thd, THD_WAIT_BINLOG);
mysql_mutex_assert_owner(&LOCK_log); mysql_mutex_assert_owner(&LOCK_binlog_end_pos);
if (!timeout) if (!timeout)
mysql_cond_wait(&update_cond, &LOCK_log); mysql_cond_wait(&COND_bin_log_updated, &LOCK_binlog_end_pos);
else else
ret= mysql_cond_timedwait(&update_cond, &LOCK_log, ret= mysql_cond_timedwait(&COND_bin_log_updated, &LOCK_binlog_end_pos,
const_cast<struct timespec *>(timeout)); const_cast<struct timespec *>(timeout));
thd_wait_end(thd); thd_wait_end(thd);
DBUG_RETURN(ret); DBUG_RETURN(ret);
...@@ -8105,9 +8118,9 @@ int MYSQL_BIN_LOG::wait_for_update_binlog_end_pos(THD* thd, ...@@ -8105,9 +8118,9 @@ int MYSQL_BIN_LOG::wait_for_update_binlog_end_pos(THD* thd,
thd_wait_begin(thd, THD_WAIT_BINLOG); thd_wait_begin(thd, THD_WAIT_BINLOG);
mysql_mutex_assert_owner(get_binlog_end_pos_lock()); mysql_mutex_assert_owner(get_binlog_end_pos_lock());
if (!timeout) if (!timeout)
mysql_cond_wait(&update_cond, get_binlog_end_pos_lock()); mysql_cond_wait(&COND_bin_log_updated, get_binlog_end_pos_lock());
else else
ret= mysql_cond_timedwait(&update_cond, get_binlog_end_pos_lock(), ret= mysql_cond_timedwait(&COND_bin_log_updated, get_binlog_end_pos_lock(),
timeout); timeout);
thd_wait_end(thd); thd_wait_end(thd);
DBUG_RETURN(ret); DBUG_RETURN(ret);
...@@ -8152,7 +8165,8 @@ void MYSQL_BIN_LOG::close(uint exiting) ...@@ -8152,7 +8165,8 @@ void MYSQL_BIN_LOG::close(uint exiting)
relay_log_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF); relay_log_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF);
write_event(&s); write_event(&s);
bytes_written+= s.data_written; bytes_written+= s.data_written;
signal_update(); flush_io_cache(&log_file);
update_binlog_end_pos();
/* /*
When we shut down server, write out the binlog state to a separate When we shut down server, write out the binlog state to a separate
...@@ -8371,14 +8385,6 @@ bool flush_error_log() ...@@ -8371,14 +8385,6 @@ bool flush_error_log()
return result; return result;
} }
void MYSQL_BIN_LOG::signal_update()
{
DBUG_ENTER("MYSQL_BIN_LOG::signal_update");
signal_cnt++;
mysql_cond_broadcast(&update_cond);
DBUG_VOID_RETURN;
}
#ifdef _WIN32 #ifdef _WIN32
static void print_buffer_to_nt_eventlog(enum loglevel level, char *buff, static void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
size_t length, size_t buffLen) size_t length, size_t buffLen)
......
...@@ -423,8 +423,10 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG ...@@ -423,8 +423,10 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
/** The instrumentation key to use for @ LOCK_index. */ /** The instrumentation key to use for @ LOCK_index. */
PSI_mutex_key m_key_LOCK_index; PSI_mutex_key m_key_LOCK_index;
/** The instrumentation key to use for @ update_cond. */ /** The instrumentation key to use for @ COND_relay_log_updated */
PSI_cond_key m_key_update_cond; PSI_cond_key m_key_relay_log_update;
/** The instrumentation key to use for @ COND_bin_log_updated */
PSI_cond_key m_key_bin_log_update;
/** The instrumentation key to use for opening the log file. */ /** The instrumentation key to use for opening the log file. */
PSI_file_key m_key_file_log; PSI_file_key m_key_file_log;
/** The instrumentation key to use for opening the log index file. */ /** The instrumentation key to use for opening the log index file. */
...@@ -486,7 +488,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG ...@@ -486,7 +488,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
mysql_mutex_t LOCK_binlog_end_pos; mysql_mutex_t LOCK_binlog_end_pos;
mysql_mutex_t LOCK_xid_list; mysql_mutex_t LOCK_xid_list;
mysql_cond_t COND_xid_list; mysql_cond_t COND_xid_list;
mysql_cond_t update_cond; mysql_cond_t COND_relay_log_updated, COND_bin_log_updated;
ulonglong bytes_written; ulonglong bytes_written;
IO_CACHE index_file; IO_CACHE index_file;
char index_file_name[FN_REFLEN]; char index_file_name[FN_REFLEN];
...@@ -596,7 +598,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG ...@@ -596,7 +598,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
/* This is relay log */ /* This is relay log */
bool is_relay_log; bool is_relay_log;
ulong signal_cnt; // update of the counter is checked by heartbeat ulong relay_signal_cnt; // update of the counter is checked by heartbeat
enum enum_binlog_checksum_alg checksum_alg_reset; // to contain a new value when binlog is rotated enum enum_binlog_checksum_alg checksum_alg_reset; // to contain a new value when binlog is rotated
/* /*
Holds the last seen in Relay-Log FD's checksum alg value. Holds the last seen in Relay-Log FD's checksum alg value.
...@@ -659,13 +661,15 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG ...@@ -659,13 +661,15 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
void set_psi_keys(PSI_mutex_key key_LOCK_index, void set_psi_keys(PSI_mutex_key key_LOCK_index,
PSI_cond_key key_update_cond, PSI_cond_key key_relay_log_update,
PSI_cond_key key_bin_log_update,
PSI_file_key key_file_log, PSI_file_key key_file_log,
PSI_file_key key_file_log_index, PSI_file_key key_file_log_index,
PSI_file_key key_COND_queue_busy) PSI_file_key key_COND_queue_busy)
{ {
m_key_LOCK_index= key_LOCK_index; m_key_LOCK_index= key_LOCK_index;
m_key_update_cond= key_update_cond; m_key_relay_log_update= key_relay_log_update;
m_key_bin_log_update= key_bin_log_update;
m_key_file_log= key_file_log; m_key_file_log= key_file_log;
m_key_file_log_index= key_file_log_index; m_key_file_log_index= key_file_log_index;
m_key_COND_queue_busy= key_COND_queue_busy; m_key_COND_queue_busy= key_COND_queue_busy;
...@@ -705,7 +709,53 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG ...@@ -705,7 +709,53 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
void set_max_size(ulong max_size_arg); void set_max_size(ulong max_size_arg);
void signal_update();
/* Handle signaling that relay has been updated */
void signal_relay_log_update()
{
mysql_mutex_assert_owner(&LOCK_log);
DBUG_ASSERT(is_relay_log);
DBUG_ENTER("MYSQL_BIN_LOG::signal_relay_log_update");
relay_signal_cnt++;
mysql_cond_broadcast(&COND_relay_log_updated);
DBUG_VOID_RETURN;
}
void signal_bin_log_update()
{
mysql_mutex_assert_owner(&LOCK_binlog_end_pos);
DBUG_ASSERT(!is_relay_log);
DBUG_ENTER("MYSQL_BIN_LOG::signal_bin_log_update");
mysql_cond_broadcast(&COND_bin_log_updated);
DBUG_VOID_RETURN;
}
void update_binlog_end_pos()
{
if (is_relay_log)
signal_relay_log_update();
else
{
lock_binlog_end_pos();
binlog_end_pos= my_b_safe_tell(&log_file);
signal_bin_log_update();
unlock_binlog_end_pos();
}
}
void update_binlog_end_pos(my_off_t pos)
{
mysql_mutex_assert_owner(&LOCK_log);
mysql_mutex_assert_not_owner(&LOCK_binlog_end_pos);
lock_binlog_end_pos();
/*
Note: it would make more sense to assert(pos > binlog_end_pos)
but there are two places triggered by mtr that has pos == binlog_end_pos
i didn't investigate but accepted as it should do no harm
*/
DBUG_ASSERT(pos >= binlog_end_pos);
binlog_end_pos= pos;
signal_bin_log_update();
unlock_binlog_end_pos();
}
void wait_for_sufficient_commits(); void wait_for_sufficient_commits();
void binlog_trigger_immediate_group_commit(); void binlog_trigger_immediate_group_commit();
void wait_for_update_relay_log(THD* thd); void wait_for_update_relay_log(THD* thd);
...@@ -806,7 +856,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG ...@@ -806,7 +856,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
inline char* get_log_fname() { return log_file_name; } inline char* get_log_fname() { return log_file_name; }
inline char* get_name() { return name; } inline char* get_name() { return name; }
inline mysql_mutex_t* get_log_lock() { return &LOCK_log; } inline mysql_mutex_t* get_log_lock() { return &LOCK_log; }
inline mysql_cond_t* get_log_cond() { return &update_cond; } inline mysql_cond_t* get_bin_log_cond() { return &COND_bin_log_updated; }
inline IO_CACHE* get_log_file() { return &log_file; } inline IO_CACHE* get_log_file() { return &log_file; }
inline void lock_index() { mysql_mutex_lock(&LOCK_index);} inline void lock_index() { mysql_mutex_lock(&LOCK_index);}
...@@ -830,23 +880,6 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG ...@@ -830,23 +880,6 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
bool check_strict_gtid_sequence(uint32 domain_id, uint32 server_id, bool check_strict_gtid_sequence(uint32 domain_id, uint32 server_id,
uint64 seq_no); uint64 seq_no);
void update_binlog_end_pos(my_off_t pos)
{
mysql_mutex_assert_owner(&LOCK_log);
mysql_mutex_assert_not_owner(&LOCK_binlog_end_pos);
lock_binlog_end_pos();
/**
* note: it would make more sense to assert(pos > binlog_end_pos)
* but there are two places triggered by mtr that has pos == binlog_end_pos
* i didn't investigate but accepted as it should do no harm
*/
DBUG_ASSERT(pos >= binlog_end_pos);
binlog_end_pos= pos;
signal_update();
unlock_binlog_end_pos();
}
/** /**
* used when opening new file, and binlog_end_pos moves backwards * used when opening new file, and binlog_end_pos moves backwards
*/ */
...@@ -857,7 +890,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG ...@@ -857,7 +890,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
lock_binlog_end_pos(); lock_binlog_end_pos();
binlog_end_pos= pos; binlog_end_pos= pos;
strcpy(binlog_end_pos_file, file_name); strcpy(binlog_end_pos_file, file_name);
signal_update(); signal_bin_log_update();
unlock_binlog_end_pos(); unlock_binlog_end_pos();
} }
......
...@@ -912,7 +912,7 @@ PSI_mutex_key key_LOCK_des_key_file; ...@@ -912,7 +912,7 @@ PSI_mutex_key key_LOCK_des_key_file;
PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list, PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list,
key_BINLOG_LOCK_binlog_background_thread, key_BINLOG_LOCK_binlog_background_thread,
m_key_LOCK_binlog_end_pos, key_LOCK_binlog_end_pos,
key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi, key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi,
key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create, key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create,
key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log, key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log,
...@@ -966,7 +966,7 @@ static PSI_mutex_info all_server_mutexes[]= ...@@ -966,7 +966,7 @@ static PSI_mutex_info all_server_mutexes[]=
{ &key_BINLOG_LOCK_index, "MYSQL_BIN_LOG::LOCK_index", 0}, { &key_BINLOG_LOCK_index, "MYSQL_BIN_LOG::LOCK_index", 0},
{ &key_BINLOG_LOCK_xid_list, "MYSQL_BIN_LOG::LOCK_xid_list", 0}, { &key_BINLOG_LOCK_xid_list, "MYSQL_BIN_LOG::LOCK_xid_list", 0},
{ &key_BINLOG_LOCK_binlog_background_thread, "MYSQL_BIN_LOG::LOCK_binlog_background_thread", 0}, { &key_BINLOG_LOCK_binlog_background_thread, "MYSQL_BIN_LOG::LOCK_binlog_background_thread", 0},
{ &m_key_LOCK_binlog_end_pos, "MYSQL_BIN_LOG::LOCK_binlog_end_pos", 0 }, { &key_LOCK_binlog_end_pos, "MYSQL_BIN_LOG::LOCK_binlog_end_pos", 0 },
{ &key_RELAYLOG_LOCK_index, "MYSQL_RELAY_LOG::LOCK_index", 0}, { &key_RELAYLOG_LOCK_index, "MYSQL_RELAY_LOG::LOCK_index", 0},
{ &key_delayed_insert_mutex, "Delayed_insert::mutex", 0}, { &key_delayed_insert_mutex, "Delayed_insert::mutex", 0},
{ &key_hash_filo_lock, "hash_filo::lock", 0}, { &key_hash_filo_lock, "hash_filo::lock", 0},
...@@ -1049,7 +1049,8 @@ static PSI_rwlock_info all_server_rwlocks[]= ...@@ -1049,7 +1049,8 @@ static PSI_rwlock_info all_server_rwlocks[]=
PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool; PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool;
#endif /* HAVE_MMAP */ #endif /* HAVE_MMAP */
PSI_cond_key key_BINLOG_COND_xid_list, key_BINLOG_update_cond, PSI_cond_key key_BINLOG_COND_xid_list,
key_BINLOG_COND_bin_log_updated, key_BINLOG_COND_relay_log_updated,
key_BINLOG_COND_binlog_background_thread, key_BINLOG_COND_binlog_background_thread,
key_BINLOG_COND_binlog_background_thread_end, key_BINLOG_COND_binlog_background_thread_end,
key_COND_cache_status_changed, key_COND_manager, key_COND_cache_status_changed, key_COND_manager,
...@@ -1065,7 +1066,8 @@ PSI_cond_key key_BINLOG_COND_xid_list, key_BINLOG_update_cond, ...@@ -1065,7 +1066,8 @@ PSI_cond_key key_BINLOG_COND_xid_list, key_BINLOG_update_cond,
key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache, key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache,
key_COND_start_thread, key_COND_binlog_send, key_COND_start_thread, key_COND_binlog_send,
key_BINLOG_COND_queue_busy; key_BINLOG_COND_queue_busy;
PSI_cond_key key_RELAYLOG_update_cond, key_COND_wakeup_ready, PSI_cond_key key_RELAYLOG_COND_relay_log_updated,
key_RELAYLOG_COND_bin_log_updated, key_COND_wakeup_ready,
key_COND_wait_commit; key_COND_wait_commit;
PSI_cond_key key_RELAYLOG_COND_queue_busy; PSI_cond_key key_RELAYLOG_COND_queue_busy;
PSI_cond_key key_TC_LOG_MMAP_COND_queue_busy; PSI_cond_key key_TC_LOG_MMAP_COND_queue_busy;
...@@ -1086,12 +1088,13 @@ static PSI_cond_info all_server_conds[]= ...@@ -1086,12 +1088,13 @@ static PSI_cond_info all_server_conds[]=
{ &key_COND_pool, "TC_LOG_MMAP::COND_pool", 0}, { &key_COND_pool, "TC_LOG_MMAP::COND_pool", 0},
{ &key_TC_LOG_MMAP_COND_queue_busy, "TC_LOG_MMAP::COND_queue_busy", 0}, { &key_TC_LOG_MMAP_COND_queue_busy, "TC_LOG_MMAP::COND_queue_busy", 0},
#endif /* HAVE_MMAP */ #endif /* HAVE_MMAP */
{ &key_BINLOG_COND_bin_log_updated, "MYSQL_BIN_LOG::COND_bin_log_updated", 0}, { &key_BINLOG_COND_relay_log_updated, "MYSQL_BIN_LOG::COND_relay_log_updated", 0},
{ &key_BINLOG_COND_xid_list, "MYSQL_BIN_LOG::COND_xid_list", 0}, { &key_BINLOG_COND_xid_list, "MYSQL_BIN_LOG::COND_xid_list", 0},
{ &key_BINLOG_update_cond, "MYSQL_BIN_LOG::update_cond", 0},
{ &key_BINLOG_COND_binlog_background_thread, "MYSQL_BIN_LOG::COND_binlog_background_thread", 0}, { &key_BINLOG_COND_binlog_background_thread, "MYSQL_BIN_LOG::COND_binlog_background_thread", 0},
{ &key_BINLOG_COND_binlog_background_thread_end, "MYSQL_BIN_LOG::COND_binlog_background_thread_end", 0}, { &key_BINLOG_COND_binlog_background_thread_end, "MYSQL_BIN_LOG::COND_binlog_background_thread_end", 0},
{ &key_BINLOG_COND_queue_busy, "MYSQL_BIN_LOG::COND_queue_busy", 0}, { &key_BINLOG_COND_queue_busy, "MYSQL_BIN_LOG::COND_queue_busy", 0},
{ &key_RELAYLOG_update_cond, "MYSQL_RELAY_LOG::update_cond", 0}, { &key_RELAYLOG_COND_relay_log_updated, "MYSQL_RELAY_LOG::COND_relay_log_updated", 0},
{ &key_RELAYLOG_COND_bin_log_updated, "MYSQL_RELAY_LOG::COND_bin_log_updated", 0},
{ &key_RELAYLOG_COND_queue_busy, "MYSQL_RELAY_LOG::COND_queue_busy", 0}, { &key_RELAYLOG_COND_queue_busy, "MYSQL_RELAY_LOG::COND_queue_busy", 0},
{ &key_COND_wakeup_ready, "THD::COND_wakeup_ready", 0}, { &key_COND_wakeup_ready, "THD::COND_wakeup_ready", 0},
{ &key_COND_wait_commit, "wait_for_commit::COND_wait_commit", 0}, { &key_COND_wait_commit, "wait_for_commit::COND_wait_commit", 0},
...@@ -4208,7 +4211,8 @@ static int init_common_variables() ...@@ -4208,7 +4211,8 @@ static int init_common_variables()
constructor (called before main()). constructor (called before main()).
*/ */
mysql_bin_log.set_psi_keys(key_BINLOG_LOCK_index, mysql_bin_log.set_psi_keys(key_BINLOG_LOCK_index,
key_BINLOG_update_cond, key_BINLOG_COND_relay_log_updated,
key_BINLOG_COND_bin_log_updated,
key_file_binlog, key_file_binlog,
key_file_binlog_index, key_file_binlog_index,
key_BINLOG_COND_queue_busy); key_BINLOG_COND_queue_busy);
......
...@@ -283,7 +283,7 @@ extern PSI_mutex_key key_LOCK_des_key_file; ...@@ -283,7 +283,7 @@ extern PSI_mutex_key key_LOCK_des_key_file;
extern PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list, extern PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list,
key_BINLOG_LOCK_binlog_background_thread, key_BINLOG_LOCK_binlog_background_thread,
m_key_LOCK_binlog_end_pos, key_LOCK_binlog_end_pos,
key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi, key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi,
key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create, key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create,
key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log, key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log,
...@@ -334,7 +334,8 @@ extern PSI_cond_key key_BINLOG_COND_xid_list, key_BINLOG_update_cond, ...@@ -334,7 +334,8 @@ extern PSI_cond_key key_BINLOG_COND_xid_list, key_BINLOG_update_cond,
key_TABLE_SHARE_cond, key_user_level_lock_cond, key_TABLE_SHARE_cond, key_user_level_lock_cond,
key_COND_start_thread, key_COND_start_thread,
key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache; key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache;
extern PSI_cond_key key_RELAYLOG_update_cond, key_COND_wakeup_ready, extern PSI_cond_key key_RELAYLOG_COND_relay_log_updated,
key_RELAYLOG_COND_bin_log_updated, key_COND_wakeup_ready,
key_COND_wait_commit; key_COND_wait_commit;
extern PSI_cond_key key_RELAYLOG_COND_queue_busy; extern PSI_cond_key key_RELAYLOG_COND_queue_busy;
extern PSI_cond_key key_TC_LOG_MMAP_COND_queue_busy; extern PSI_cond_key key_TC_LOG_MMAP_COND_queue_busy;
......
...@@ -255,8 +255,8 @@ signal_error_to_sql_driver_thread(THD *thd, rpl_group_info *rgi, int err) ...@@ -255,8 +255,8 @@ signal_error_to_sql_driver_thread(THD *thd, rpl_group_info *rgi, int err)
rgi->rli->abort_slave= true; rgi->rli->abort_slave= true;
rgi->rli->stop_for_until= false; rgi->rli->stop_for_until= false;
mysql_mutex_lock(rgi->rli->relay_log.get_log_lock()); mysql_mutex_lock(rgi->rli->relay_log.get_log_lock());
rgi->rli->relay_log.signal_relay_log_update();
mysql_mutex_unlock(rgi->rli->relay_log.get_log_lock()); mysql_mutex_unlock(rgi->rli->relay_log.get_log_lock());
rgi->rli->relay_log.signal_update();
} }
......
...@@ -68,7 +68,8 @@ Relay_log_info::Relay_log_info(bool is_slave_recovery) ...@@ -68,7 +68,8 @@ Relay_log_info::Relay_log_info(bool is_slave_recovery)
relay_log_state.init(); relay_log_state.init();
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
relay_log.set_psi_keys(key_RELAYLOG_LOCK_index, relay_log.set_psi_keys(key_RELAYLOG_LOCK_index,
key_RELAYLOG_update_cond, key_RELAYLOG_COND_relay_log_updated,
key_RELAYLOG_COND_bin_log_updated,
key_file_relaylog, key_file_relaylog,
key_file_relaylog_index, key_file_relaylog_index,
key_RELAYLOG_COND_queue_busy); key_RELAYLOG_COND_queue_busy);
......
...@@ -5939,7 +5939,7 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) ...@@ -5939,7 +5939,7 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
mysql_mutex_unlock(log_lock); mysql_mutex_unlock(log_lock);
goto err; goto err;
} }
rli->relay_log.signal_update(); rli->relay_log.signal_relay_log_update();
mysql_mutex_unlock(log_lock); mysql_mutex_unlock(log_lock);
mi->gtid_reconnect_event_skip_count= 0; mi->gtid_reconnect_event_skip_count= 0;
...@@ -6484,7 +6484,8 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) ...@@ -6484,7 +6484,8 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
if (got_gtid_event) if (got_gtid_event)
rli->ign_gtids.update(&event_gtid); rli->ign_gtids.update(&event_gtid);
} }
rli->relay_log.signal_update(); // the slave SQL thread needs to re-check // the slave SQL thread needs to re-check
rli->relay_log.signal_relay_log_update();
DBUG_PRINT("info", ("master_log_pos: %lu, event originating from %u server, ignored", DBUG_PRINT("info", ("master_log_pos: %lu, event originating from %u server, ignored",
(ulong) mi->master_log_pos, uint4korr(buf + SERVER_ID_OFFSET))); (ulong) mi->master_log_pos, uint4korr(buf + SERVER_ID_OFFSET)));
} }
......
...@@ -2437,7 +2437,7 @@ static int wait_new_events(binlog_send_info *info, /* in */ ...@@ -2437,7 +2437,7 @@ static int wait_new_events(binlog_send_info *info, /* in */
PSI_stage_info old_stage; PSI_stage_info old_stage;
mysql_bin_log.lock_binlog_end_pos(); mysql_bin_log.lock_binlog_end_pos();
info->thd->ENTER_COND(mysql_bin_log.get_log_cond(), info->thd->ENTER_COND(mysql_bin_log.get_bin_log_cond(),
mysql_bin_log.get_binlog_end_pos_lock(), mysql_bin_log.get_binlog_end_pos_lock(),
&stage_master_has_sent_all_binlog_to_slave, &stage_master_has_sent_all_binlog_to_slave,
&old_stage); &old_stage);
......
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