Commit 84a6de3f authored by He Zhenxing's avatar He Zhenxing

Bug#49557 "semisync" plugin test fails on Windows

The problem was because the gettimeofday function was incorrect
implemented for Windows, and so the semisync master did not wait
for slave reply properly on Windows.

Fixed by removing the gettimeofday function for Windows, and using
set_timespec function to get current time for all platforms.


plugin/semisync/semisync_master.cc:
  removing the gettimeofday function for Windows, using set_timespec
  function to get current time for all platforms.
parent 12c5f656
......@@ -43,19 +43,16 @@ unsigned long long rpl_semi_sync_master_trx_wait_time = 0;
char rpl_semi_sync_master_wait_no_slave = 1;
static int getWaitTime(const struct timeval& start_tv);
static int getWaitTime(const struct timespec& start_ts);
#ifdef __WIN__
static int gettimeofday(struct timeval *tv, void *tz)
static unsigned long long timespec_to_usec(const struct timespec *ts)
{
unsigned int ticks;
ticks= GetTickCount();
tv->tv_usec= ticks*1000;
tv->tv_sec= ticks/1000;
return 0;
}
#ifndef __WIN__
return (unsigned long long) ts->tv_sec * TIME_MILLION + ts->tv_nsec / TIME_THOUSAND;
#else
return ts->tv.i64 / 10;
#endif /* __WIN__ */
}
/*******************************************************************************
*
......@@ -604,12 +601,12 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name,
if (getMasterEnabled() && trx_wait_binlog_name)
{
struct timeval start_tv;
struct timespec start_ts;
struct timespec abstime;
int wait_result, start_time_err;
int wait_result;
const char *old_msg= 0;
start_time_err = gettimeofday(&start_tv, 0);
set_timespec(start_ts, 0);
/* Acquire the mutex. */
lock();
......@@ -677,30 +674,19 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name,
kWho, wait_file_name_, (unsigned long)wait_file_pos_);
}
if (start_time_err == 0)
{
int diff_usecs = start_tv.tv_usec + wait_timeout_ * TIME_THOUSAND;
/* Calcuate the waiting period. */
#ifdef __WIN__
abstime.tv.i64 = (__int64)start_tv.tv_sec * TIME_MILLION * 10;
abstime.tv.i64 += (__int64)diff_usecs * 10;
abstime.tv.i64 = start_ts.tv.i64 + (__int64)wait_timeout_ * TIME_THOUSAND * 10;
abstime.max_timeout_msec= (long)wait_timeout_;
#else
abstime.tv_sec = start_tv.tv_sec;
if (diff_usecs < TIME_MILLION)
{
abstime.tv_nsec = diff_usecs * TIME_THOUSAND;
}
else
{
while (diff_usecs >= TIME_MILLION)
unsigned long diff_nsecs = start_ts.tv_nsec + wait_timeout_ * TIME_MILLION;
abstime.tv_sec = start_ts.tv_sec;
while (diff_nsecs >= TIME_BILLION)
{
abstime.tv_sec++;
diff_usecs -= TIME_MILLION;
}
abstime.tv_nsec = diff_usecs * TIME_THOUSAND;
diff_nsecs -= TIME_BILLION;
}
abstime.tv_nsec = diff_nsecs;
#endif /* __WIN__ */
/* In semi-synchronous replication, we wait until the binlog-dump
......@@ -737,13 +723,12 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name,
{
int wait_time;
wait_time = getWaitTime(start_tv);
wait_time = getWaitTime(start_ts);
if (wait_time < 0)
{
if (trace_level_ & kTraceGeneral)
{
/* This is a time/gettimeofday function call error. */
sql_print_error("Replication semi-sync gettimeofday fail1 at "
sql_print_error("Replication semi-sync getWaitTime fail at "
"wait position (%s, %lu)",
trx_wait_binlog_name, (unsigned long)trx_wait_binlog_pos);
}
......@@ -756,21 +741,6 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name,
}
}
}
else
{
if (trace_level_ & kTraceGeneral)
{
/* This is a gettimeofday function call error. */
sql_print_error("Replication semi-sync gettimeofday fail2 at "
"wait position (%s, %lu)",
trx_wait_binlog_name, (unsigned long)trx_wait_binlog_pos);
}
rpl_semi_sync_master_timefunc_fails++;
/* switch semi-sync off */
switch_off();
}
}
l_end:
/*
......@@ -1078,8 +1048,7 @@ int ReplSemiSyncMaster::readSlaveReply(NET *net, uint32 server_id,
ulong packet_len;
int result = -1;
struct timeval start_tv;
int start_time_err= 0;
struct timespec start_ts;
ulong trc_level = trace_level_;
function_enter(kWho);
......@@ -1093,7 +1062,7 @@ int ReplSemiSyncMaster::readSlaveReply(NET *net, uint32 server_id,
}
if (trc_level & kTraceNetWait)
start_time_err = gettimeofday(&start_tv, 0);
set_timespec(start_ts, 0);
/* We flush to make sure that the current event is sent to the network,
* instead of being buffered in the TCP/IP stack.
......@@ -1118,21 +1087,11 @@ int ReplSemiSyncMaster::readSlaveReply(NET *net, uint32 server_id,
if (trc_level & kTraceNetWait)
{
if (start_time_err != 0)
{
sql_print_error("Semi-sync master wait for reply "
"gettimeofday fail to get start time");
rpl_semi_sync_master_timefunc_fails++;
}
else
{
int wait_time;
wait_time = getWaitTime(start_tv);
int wait_time = getWaitTime(start_ts);
if (wait_time < 0)
{
sql_print_error("Semi-sync master wait for reply "
"gettimeofday fail to get wait time.");
"fail to get wait time.");
rpl_semi_sync_master_timefunc_fails++;
}
else
......@@ -1141,7 +1100,6 @@ int ReplSemiSyncMaster::readSlaveReply(NET *net, uint32 server_id,
rpl_semi_sync_master_net_wait_time += wait_time;
}
}
}
if (packet_len == packet_error || packet_len < REPLY_BINLOG_NAME_OFFSET)
{
......@@ -1228,24 +1186,23 @@ void ReplSemiSyncMaster::setExportStats()
*
* Return:
* >= 0: the waiting time in microsecons(us)
* < 0: error in gettimeofday or time back traverse
* < 0: error in get time or time back traverse
*/
static int getWaitTime(const struct timeval& start_tv)
static int getWaitTime(const struct timespec& start_ts)
{
unsigned long long start_usecs, end_usecs;
struct timeval end_tv;
int end_time_err;
struct timespec end_ts;
/* Starting time in microseconds(us). */
start_usecs = start_tv.tv_sec * TIME_MILLION + start_tv.tv_usec;
start_usecs = timespec_to_usec(&start_ts);
/* Get the wait time interval. */
end_time_err = gettimeofday(&end_tv, 0);
set_timespec(end_ts, 0);
/* Ending time in microseconds(us). */
end_usecs = end_tv.tv_sec * TIME_MILLION + end_tv.tv_usec;
end_usecs = timespec_to_usec(&end_ts);
if (end_time_err != 0 || end_usecs < start_usecs)
if (end_usecs < start_usecs)
return -1;
return (int)(end_usecs - start_usecs);
......
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