Skip to content
Permalink
Browse files
Optimize RUN_HOOK() call
RUN_HOOK() is only called if semisync is enabled

As the server can't disable the hooks if something is in progress, I added
a new variable, run_hooks_enabled, that is set the first time semi sync is
used. This means that RUN_HOOK will have no overhead, unless semi sync
master or slave has been enabled once.

Some of the changes was just to get rid of warnings for embedded server
  • Loading branch information
montywi committed Dec 18, 2017
1 parent 13770ed commit abceaa7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
@@ -1484,7 +1484,7 @@ int ha_commit_trans(THD *thd, bool all)
mysql_mutex_assert_not_owner(mysql_bin_log.get_log_lock());
mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync);
mysql_mutex_assert_not_owner(&LOCK_commit_ordered);
RUN_HOOK(transaction, after_commit, (thd, FALSE));
(void) RUN_HOOK(transaction, after_commit, (thd, FALSE));
goto end;

/* Come here if error and we need to rollback. */
@@ -6374,11 +6374,9 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate)
mysql_mutex_assert_owner(&LOCK_log);
mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync);
mysql_mutex_assert_not_owner(&LOCK_commit_ordered);
bool first= true;
bool last= true;
if ((error= RUN_HOOK(binlog_storage, after_flush,
(thd, log_file_name, file->pos_in_file,
synced, first, last))))
synced, true, true))))
{
sql_print_error("Failed to run 'after_flush' hooks");
error= 1;
@@ -6408,11 +6406,9 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate)
mysql_mutex_assert_not_owner(&LOCK_log);
mysql_mutex_assert_owner(&LOCK_after_binlog_sync);
mysql_mutex_assert_not_owner(&LOCK_commit_ordered);
bool first= true;
bool last= true;
if (RUN_HOOK(binlog_storage, after_sync,
(thd, log_file_name, file->pos_in_file,
first, last)))
true, true)))
{
error=1;
/* error is already printed inside hook */
@@ -7838,7 +7834,8 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader)
mysql_mutex_assert_owner(&LOCK_log);
mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync);
mysql_mutex_assert_not_owner(&LOCK_commit_ordered);
bool first= true, last;
bool first __attribute__((unused))= true;
bool last __attribute__((unused));
for (current= queue; current != NULL; current= current->next)
{
last= current->next == NULL;
@@ -7924,7 +7921,8 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader)
mysql_mutex_assert_owner(&LOCK_after_binlog_sync);
mysql_mutex_assert_not_owner(&LOCK_commit_ordered);

bool first= true, last;
bool first __attribute__((unused))= true;
bool last __attribute__((unused));
for (current= queue; current != NULL; current= current->next)
{
last= current->next == NULL;
@@ -390,7 +390,7 @@ static longlong start_memory_used;
/* Global variables */

bool opt_bin_log, opt_bin_log_used=0, opt_ignore_builtin_innodb= 0;
bool opt_bin_log_compress;
bool opt_bin_log_compress, run_hooks_enabled;
uint opt_bin_log_compress_min_len;
my_bool opt_log, debug_assert_if_crashed_table= 0, opt_help= 0;
my_bool debug_assert_on_not_freed_memory= 0;
@@ -8950,6 +8950,7 @@ static int mysql_init_variables(void)
transactions_multi_engine= 0;
rpl_transactions_multi_engine= 0;
transactions_gtid_foreign_engine= 0;
run_hooks_enabled= 0;
log_bin_basename= NULL;
log_bin_index= NULL;

@@ -109,6 +109,7 @@ extern CHARSET_INFO *character_set_filesystem;
extern MY_BITMAP temp_pool;
extern bool opt_large_files;
extern bool opt_update_log, opt_bin_log, opt_error_log, opt_bin_log_compress;
extern bool run_hooks_enabled;
extern uint opt_bin_log_compress_min_len;
extern my_bool opt_log, opt_bootstrap;
extern my_bool opt_backup_history_log;
@@ -206,11 +206,13 @@ extern Binlog_relay_IO_delegate *binlog_relay_io_delegate;
#endif /* HAVE_REPLICATION */

/*
if there is no observers in the delegate, we can return 0
immediately.
if semisync replication is not enabled, we can return immediately.
*/
#define RUN_HOOK(group, hook, args) \
(group ##_delegate->is_empty() ? \
0 : group ##_delegate->hook args)
#ifdef HAVE_REPLICATION
#define RUN_HOOK(group, hook, args) \
(unlikely(run_hooks_enabled) ? group ##_delegate->hook args : 0)
#else
#define RUN_HOOK(group, hook, args) 0
#endif /* HAVE_REPLICATION */

#endif /* RPL_HANDLER_H */
@@ -44,6 +44,7 @@ class ReplSemiSyncSlave
return slave_enabled_;
}
void setSlaveEnabled(bool enabled) {
run_hooks_enabled|= enabled;
slave_enabled_ = enabled;
}

0 comments on commit abceaa7

Please sign in to comment.