Commit 644f0c1d authored by Davi Arnaut's avatar Davi Arnaut

Bug#42054: SELECT CURDATE() is returning bad value

The problem from a user point of view was that on Solaris the
time related functions (e.g. NOW(), SYSDATE(), etc) would always
return a fixed time.

This bug was happening due to a logic in the time retrieving
wrapper function which would only call the time() function every
half second. This interval between calls would be calculated
using the gethrtime() and the logic relied on the fact that time
returned by it is monotonic.

Unfortunately, due to bugs in the gethrtime() implementation,
there are some cases where the time returned by it can drift
(See Solaris bug id 6600939), potentially causing the interval
calculation logic to fail.

The solution is to retrieve the correct time whenever a drift in
the time returned by gethrtime() is detected. That is, do not
use the cached time whenever the values (previous and current)
returned by gethrtime() are not monotonically increasing.

mysys/my_getsystime.c:
  Do not used the cached time if gethrtime is not monotonic.
parent 7f09ed8d
......@@ -170,7 +170,13 @@ ulonglong my_micro_time_and_time(time_t *time_arg)
pthread_mutex_lock(&THR_LOCK_time);
cur_gethrtime= gethrtime();
if ((cur_gethrtime - prev_gethrtime) > DELTA_FOR_SECONDS)
/*
Due to bugs in the Solaris (x86) implementation of gethrtime(),
the time returned by it might not be monotonic. Don't use the
cached time(2) value if this is a case.
*/
if ((prev_gethrtime > cur_gethrtime) ||
((cur_gethrtime - prev_gethrtime) > DELTA_FOR_SECONDS))
{
cur_time= time(0);
prev_gethrtime= cur_gethrtime;
......
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