Commit abceaa75 authored by Monty's avatar Monty

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
parent 13770edb
...@@ -1484,7 +1484,7 @@ int ha_commit_trans(THD *thd, bool all) ...@@ -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(mysql_bin_log.get_log_lock());
mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync); mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync);
mysql_mutex_assert_not_owner(&LOCK_commit_ordered); 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; goto end;
/* Come here if error and we need to rollback. */ /* 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) ...@@ -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_owner(&LOCK_log);
mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync); mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync);
mysql_mutex_assert_not_owner(&LOCK_commit_ordered); mysql_mutex_assert_not_owner(&LOCK_commit_ordered);
bool first= true;
bool last= true;
if ((error= RUN_HOOK(binlog_storage, after_flush, if ((error= RUN_HOOK(binlog_storage, after_flush,
(thd, log_file_name, file->pos_in_file, (thd, log_file_name, file->pos_in_file,
synced, first, last)))) synced, true, true))))
{ {
sql_print_error("Failed to run 'after_flush' hooks"); sql_print_error("Failed to run 'after_flush' hooks");
error= 1; error= 1;
...@@ -6408,11 +6406,9 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate) ...@@ -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_not_owner(&LOCK_log);
mysql_mutex_assert_owner(&LOCK_after_binlog_sync); mysql_mutex_assert_owner(&LOCK_after_binlog_sync);
mysql_mutex_assert_not_owner(&LOCK_commit_ordered); mysql_mutex_assert_not_owner(&LOCK_commit_ordered);
bool first= true;
bool last= true;
if (RUN_HOOK(binlog_storage, after_sync, if (RUN_HOOK(binlog_storage, after_sync,
(thd, log_file_name, file->pos_in_file, (thd, log_file_name, file->pos_in_file,
first, last))) true, true)))
{ {
error=1; error=1;
/* error is already printed inside hook */ /* error is already printed inside hook */
...@@ -7838,7 +7834,8 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader) ...@@ -7838,7 +7834,8 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader)
mysql_mutex_assert_owner(&LOCK_log); mysql_mutex_assert_owner(&LOCK_log);
mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync); mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync);
mysql_mutex_assert_not_owner(&LOCK_commit_ordered); 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) for (current= queue; current != NULL; current= current->next)
{ {
last= current->next == NULL; last= current->next == NULL;
...@@ -7924,7 +7921,8 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader) ...@@ -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_owner(&LOCK_after_binlog_sync);
mysql_mutex_assert_not_owner(&LOCK_commit_ordered); 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) for (current= queue; current != NULL; current= current->next)
{ {
last= current->next == NULL; last= current->next == NULL;
......
...@@ -390,7 +390,7 @@ static longlong start_memory_used; ...@@ -390,7 +390,7 @@ static longlong start_memory_used;
/* Global variables */ /* Global variables */
bool opt_bin_log, opt_bin_log_used=0, opt_ignore_builtin_innodb= 0; 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; uint opt_bin_log_compress_min_len;
my_bool opt_log, debug_assert_if_crashed_table= 0, opt_help= 0; my_bool opt_log, debug_assert_if_crashed_table= 0, opt_help= 0;
my_bool debug_assert_on_not_freed_memory= 0; my_bool debug_assert_on_not_freed_memory= 0;
...@@ -8950,6 +8950,7 @@ static int mysql_init_variables(void) ...@@ -8950,6 +8950,7 @@ static int mysql_init_variables(void)
transactions_multi_engine= 0; transactions_multi_engine= 0;
rpl_transactions_multi_engine= 0; rpl_transactions_multi_engine= 0;
transactions_gtid_foreign_engine= 0; transactions_gtid_foreign_engine= 0;
run_hooks_enabled= 0;
log_bin_basename= NULL; log_bin_basename= NULL;
log_bin_index= NULL; log_bin_index= NULL;
......
...@@ -109,6 +109,7 @@ extern CHARSET_INFO *character_set_filesystem; ...@@ -109,6 +109,7 @@ extern CHARSET_INFO *character_set_filesystem;
extern MY_BITMAP temp_pool; extern MY_BITMAP temp_pool;
extern bool opt_large_files; extern bool opt_large_files;
extern bool opt_update_log, opt_bin_log, opt_error_log, opt_bin_log_compress; 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 uint opt_bin_log_compress_min_len;
extern my_bool opt_log, opt_bootstrap; extern my_bool opt_log, opt_bootstrap;
extern my_bool opt_backup_history_log; extern my_bool opt_backup_history_log;
......
...@@ -206,11 +206,13 @@ extern Binlog_relay_IO_delegate *binlog_relay_io_delegate; ...@@ -206,11 +206,13 @@ extern Binlog_relay_IO_delegate *binlog_relay_io_delegate;
#endif /* HAVE_REPLICATION */ #endif /* HAVE_REPLICATION */
/* /*
if there is no observers in the delegate, we can return 0 if semisync replication is not enabled, we can return immediately.
immediately.
*/ */
#define RUN_HOOK(group, hook, args) \ #ifdef HAVE_REPLICATION
(group ##_delegate->is_empty() ? \ #define RUN_HOOK(group, hook, args) \
0 : group ##_delegate->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 */ #endif /* RPL_HANDLER_H */
...@@ -44,6 +44,7 @@ class ReplSemiSyncSlave ...@@ -44,6 +44,7 @@ class ReplSemiSyncSlave
return slave_enabled_; return slave_enabled_;
} }
void setSlaveEnabled(bool enabled) { void setSlaveEnabled(bool enabled) {
run_hooks_enabled|= enabled;
slave_enabled_ = enabled; slave_enabled_ = enabled;
} }
......
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