Skip to content

Commit abceaa7

Browse files
committed
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
1 parent 13770ed commit abceaa7

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

sql/handler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ int ha_commit_trans(THD *thd, bool all)
14841484
mysql_mutex_assert_not_owner(mysql_bin_log.get_log_lock());
14851485
mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync);
14861486
mysql_mutex_assert_not_owner(&LOCK_commit_ordered);
1487-
RUN_HOOK(transaction, after_commit, (thd, FALSE));
1487+
(void) RUN_HOOK(transaction, after_commit, (thd, FALSE));
14881488
goto end;
14891489

14901490
/* Come here if error and we need to rollback. */

sql/log.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6374,11 +6374,9 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate)
63746374
mysql_mutex_assert_owner(&LOCK_log);
63756375
mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync);
63766376
mysql_mutex_assert_not_owner(&LOCK_commit_ordered);
6377-
bool first= true;
6378-
bool last= true;
63796377
if ((error= RUN_HOOK(binlog_storage, after_flush,
63806378
(thd, log_file_name, file->pos_in_file,
6381-
synced, first, last))))
6379+
synced, true, true))))
63826380
{
63836381
sql_print_error("Failed to run 'after_flush' hooks");
63846382
error= 1;
@@ -6408,11 +6406,9 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate)
64086406
mysql_mutex_assert_not_owner(&LOCK_log);
64096407
mysql_mutex_assert_owner(&LOCK_after_binlog_sync);
64106408
mysql_mutex_assert_not_owner(&LOCK_commit_ordered);
6411-
bool first= true;
6412-
bool last= true;
64136409
if (RUN_HOOK(binlog_storage, after_sync,
64146410
(thd, log_file_name, file->pos_in_file,
6415-
first, last)))
6411+
true, true)))
64166412
{
64176413
error=1;
64186414
/* error is already printed inside hook */
@@ -7838,7 +7834,8 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader)
78387834
mysql_mutex_assert_owner(&LOCK_log);
78397835
mysql_mutex_assert_not_owner(&LOCK_after_binlog_sync);
78407836
mysql_mutex_assert_not_owner(&LOCK_commit_ordered);
7841-
bool first= true, last;
7837+
bool first __attribute__((unused))= true;
7838+
bool last __attribute__((unused));
78427839
for (current= queue; current != NULL; current= current->next)
78437840
{
78447841
last= current->next == NULL;
@@ -7924,7 +7921,8 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader)
79247921
mysql_mutex_assert_owner(&LOCK_after_binlog_sync);
79257922
mysql_mutex_assert_not_owner(&LOCK_commit_ordered);
79267923

7927-
bool first= true, last;
7924+
bool first __attribute__((unused))= true;
7925+
bool last __attribute__((unused));
79287926
for (current= queue; current != NULL; current= current->next)
79297927
{
79307928
last= current->next == NULL;

sql/mysqld.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ static longlong start_memory_used;
390390
/* Global variables */
391391

392392
bool opt_bin_log, opt_bin_log_used=0, opt_ignore_builtin_innodb= 0;
393-
bool opt_bin_log_compress;
393+
bool opt_bin_log_compress, run_hooks_enabled;
394394
uint opt_bin_log_compress_min_len;
395395
my_bool opt_log, debug_assert_if_crashed_table= 0, opt_help= 0;
396396
my_bool debug_assert_on_not_freed_memory= 0;
@@ -8950,6 +8950,7 @@ static int mysql_init_variables(void)
89508950
transactions_multi_engine= 0;
89518951
rpl_transactions_multi_engine= 0;
89528952
transactions_gtid_foreign_engine= 0;
8953+
run_hooks_enabled= 0;
89538954
log_bin_basename= NULL;
89548955
log_bin_index= NULL;
89558956

sql/mysqld.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ extern CHARSET_INFO *character_set_filesystem;
109109
extern MY_BITMAP temp_pool;
110110
extern bool opt_large_files;
111111
extern bool opt_update_log, opt_bin_log, opt_error_log, opt_bin_log_compress;
112+
extern bool run_hooks_enabled;
112113
extern uint opt_bin_log_compress_min_len;
113114
extern my_bool opt_log, opt_bootstrap;
114115
extern my_bool opt_backup_history_log;

sql/rpl_handler.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,13 @@ extern Binlog_relay_IO_delegate *binlog_relay_io_delegate;
206206
#endif /* HAVE_REPLICATION */
207207

208208
/*
209-
if there is no observers in the delegate, we can return 0
210-
immediately.
209+
if semisync replication is not enabled, we can return immediately.
211210
*/
212-
#define RUN_HOOK(group, hook, args) \
213-
(group ##_delegate->is_empty() ? \
214-
0 : group ##_delegate->hook args)
211+
#ifdef HAVE_REPLICATION
212+
#define RUN_HOOK(group, hook, args) \
213+
(unlikely(run_hooks_enabled) ? group ##_delegate->hook args : 0)
214+
#else
215+
#define RUN_HOOK(group, hook, args) 0
216+
#endif /* HAVE_REPLICATION */
215217

216218
#endif /* RPL_HANDLER_H */

sql/semisync_slave.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ReplSemiSyncSlave
4444
return slave_enabled_;
4545
}
4646
void setSlaveEnabled(bool enabled) {
47+
run_hooks_enabled|= enabled;
4748
slave_enabled_ = enabled;
4849
}
4950

0 commit comments

Comments
 (0)