summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2017-10-26 19:14:37 +0300
committerMonty <monty@mariadb.org>2017-12-18 13:43:37 +0200
commitabceaa75428f9b2d64ce64629d010af9aa6eae1f (patch)
tree99dfd31c24934fb8622e71e996fcb2c173d4e037 /sql
parent13770edbcb181f06315dab659b592edf6355efc6 (diff)
downloadmariadb-git-abceaa75428f9b2d64ce64629d010af9aa6eae1f.tar.gz
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
Diffstat (limited to 'sql')
-rw-r--r--sql/handler.cc2
-rw-r--r--sql/log.cc14
-rw-r--r--sql/mysqld.cc3
-rw-r--r--sql/mysqld.h1
-rw-r--r--sql/rpl_handler.h12
-rw-r--r--sql/semisync_slave.h1
6 files changed, 18 insertions, 15 deletions
diff --git a/sql/handler.cc b/sql/handler.cc
index 4e059e0e56c..47eb58e17f3 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -1484,7 +1484,7 @@ done:
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. */
diff --git a/sql/log.cc b/sql/log.cc
index 4f69e341ad7..9d4a622d400 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -6374,11 +6374,9 @@ err:
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 @@ err:
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;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 5f675a76ecf..71e0aeee473 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -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;
diff --git a/sql/mysqld.h b/sql/mysqld.h
index f72132820fe..1da95fd13f5 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -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;
diff --git a/sql/rpl_handler.h b/sql/rpl_handler.h
index afcfd9d55b1..62bd7d2606c 100644
--- a/sql/rpl_handler.h
+++ b/sql/rpl_handler.h
@@ -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 */
diff --git a/sql/semisync_slave.h b/sql/semisync_slave.h
index 9cca8bbbdb4..6bc10b0d479 100644
--- a/sql/semisync_slave.h
+++ b/sql/semisync_slave.h
@@ -44,6 +44,7 @@ public:
return slave_enabled_;
}
void setSlaveEnabled(bool enabled) {
+ run_hooks_enabled|= enabled;
slave_enabled_ = enabled;
}