diff options
author | Vladislav Vaintroub <wlad@montyprogram.com> | 2013-09-03 22:45:12 +0200 |
---|---|---|
committer | Vladislav Vaintroub <wlad@montyprogram.com> | 2013-09-03 22:45:12 +0200 |
commit | 078388f39ca8d6f0b5188cc060a7f0e1c2808d87 (patch) | |
tree | 5a3816ae71d902f4cf89d7f04167da8f7903a75a /plugin | |
parent | 92003f0166b226207837ec78e1258d469a379cff (diff) | |
download | mariadb-git-078388f39ca8d6f0b5188cc060a7f0e1c2808d87.tar.gz |
MDEV-4926: Remove division-using-subtraction implementation from semi-sync plugin
If rpl_semi_sync_master_timeout is large, calculation of absolute waiting time in semi-sync plugin is inefficient. This error is specific to systems with 64 bit long values (all 64 bit Unixes)
In rpl_semi_sync_master_timeout has maximal value (= MAX_ULONGLONG), calculating abstime may require ~ 18 billion subtract operations.
The fix is to use division instead of subtraction-in-a-loop. Also fixed an integer overflow bug.
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/semisync/semisync_master.cc | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/plugin/semisync/semisync_master.cc b/plugin/semisync/semisync_master.cc index d1b982468d2..23e35c59281 100644 --- a/plugin/semisync/semisync_master.cc +++ b/plugin/semisync/semisync_master.cc @@ -676,15 +676,11 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name, } /* Calcuate the waiting period. */ - unsigned long long diff_nsecs = - start_ts.tv_nsec + (unsigned long long)wait_timeout_ * TIME_MILLION; - abstime.tv_sec = start_ts.tv_sec; - while (diff_nsecs >= TIME_BILLION) - { - abstime.tv_sec++; - diff_nsecs -= TIME_BILLION; - } - abstime.tv_nsec = (long)diff_nsecs; + long diff_secs = (long) (wait_timeout_ / TIME_THOUSAND); + long diff_nsecs = (long) ((wait_timeout_ % TIME_THOUSAND) * TIME_MILLION); + long nsecs = start_ts.tv_nsec + diff_nsecs; + abstime.tv_sec = start_ts.tv_sec + diff_secs + nsecs/TIME_BILLION; + abstime.tv_nsec = nsecs % TIME_BILLION; /* In semi-synchronous replication, we wait until the binlog-dump * thread has received the reply on the relevant binlog segment from the |