mirror of
https://github.com/MariaDB/server.git
synced 2025-10-12 12:25:37 +03:00
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.
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user