Commit 078388f3 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

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.
parent 92003f01
......@@ -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
......
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