Commit ac2d4d49 authored by Sergei Golubchik's avatar Sergei Golubchik

fix THD::system_time to follow, well, system time

Because NOW() is set to system time, unless overriden.
And both should follow big manual system time changes,
while still coping with lowres system clocks.

Ignoring system time changes is both confusing and
breaks with restarts.
parent 30981dcf
......@@ -900,7 +900,7 @@ void partition_info::vers_set_hist_part(THD *thd)
if (vers_info->interval.is_set())
{
if (vers_info->hist_part->range_value > thd->system_time)
if (vers_info->hist_part->range_value > thd->systime())
return;
partition_element *next= NULL;
......@@ -911,7 +911,7 @@ void partition_info::vers_set_hist_part(THD *thd)
while ((next= it++) != vers_info->now_part)
{
vers_info->hist_part= next;
if (next->range_value > thd->system_time)
if (next->range_value > thd->systime())
return;
}
goto warn;
......
......@@ -819,8 +819,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock)
// Must be reset to handle error with THD's created for init of mysqld
lex->current_select= 0;
start_utime= utime_after_query= 0;
system_time= 0;
system_time_sec_part= 0;
system_time.start.val= system_time.sec= system_time.sec_part= 0;
utime_after_lock= 0L;
progress.arena= 0;
progress.report_to_client= 0;
......
......@@ -2418,8 +2418,6 @@ class THD :public Statement,
// track down slow pthread_create
ulonglong prior_thr_create_utime, thr_create_utime;
ulonglong utime_after_query;
my_time_t system_time;
ulong system_time_sec_part;
// Process indicator
struct {
......@@ -3430,30 +3428,37 @@ class THD :public Statement,
{ query_start_sec_part_used=1; return start_time_sec_part; }
MYSQL_TIME query_start_TIME();
private:
bool system_time_ge(my_time_t secs, ulong usecs)
{
return (system_time == secs && system_time_sec_part >= usecs) ||
system_time > secs;
}
struct {
my_hrtime_t start;
my_time_t sec;
ulong sec_part;
} system_time;
ulong systime_sec_part() { return system_time.sec_part; }
my_time_t systime() { return system_time.sec; }
private:
void set_system_time()
{
my_hrtime_t hrtime= my_hrtime();
my_time_t secs= hrtime_to_my_time(hrtime);
ulong usecs= hrtime_sec_part(hrtime);
if (system_time_ge(secs, usecs))
my_time_t sec= hrtime_to_my_time(hrtime);
ulong sec_part= hrtime_sec_part(hrtime);
if (sec > system_time.sec ||
(sec == system_time.sec && sec_part > system_time.sec_part) ||
hrtime.val < system_time.start.val)
{
if (++system_time_sec_part == HRTIME_RESOLUTION)
{
++system_time;
system_time_sec_part= 0;
}
system_time.sec= sec;
system_time.sec_part= sec_part;
}
else
{
system_time= secs;
system_time_sec_part= usecs;
if (system_time.sec_part < TIME_MAX_SECOND_PART)
system_time.sec_part++;
else
{
system_time.sec++;
system_time.sec_part= 0;
}
}
}
......@@ -3468,8 +3473,8 @@ class THD :public Statement,
}
else
{
start_time= system_time;
start_time_sec_part= system_time_sec_part;
start_time= system_time.sec;
start_time_sec_part= system_time.sec_part;
}
PSI_CALL_set_thread_start_time(start_time);
}
......
......@@ -1574,7 +1574,7 @@ static bool check_vers_constants(THD *thd, partition_info *part_info)
my_tz_OFFSET0->TIME_to_gmt_sec(&ltime, &error);
if (error)
goto err;
if (vers_info->hist_part->range_value <= thd->system_time)
if (vers_info->hist_part->range_value <= thd->systime())
vers_info->hist_part= el;
}
return 0;
......@@ -5314,7 +5314,7 @@ that are reorganised.
if (*fast_alter_table && tab_part_info->vers_info->interval.is_set())
{
partition_element *hist_part= tab_part_info->vers_info->hist_part;
if (hist_part->range_value <= thd->system_time)
if (hist_part->range_value <= thd->systime())
hist_part->part_state= PART_CHANGED;
}
}
......
......@@ -5872,7 +5872,7 @@ opt_versioning_rotation:
opt_versioning_interval_start:
/* empty */
{
$$= thd->system_time;
$$= thd->systime();
}
| remember_tok_start STARTS_SYM ulong_num
{
......
......@@ -7764,8 +7764,8 @@ void TABLE::vers_update_fields()
{
if (!vers_write)
return;
if (vers_start_field()->store_timestamp(in_use->system_time,
in_use->system_time_sec_part))
if (vers_start_field()->store_timestamp(in_use->systime(),
in_use->systime_sec_part()))
DBUG_ASSERT(0);
}
else
......@@ -7780,8 +7780,8 @@ void TABLE::vers_update_fields()
void TABLE::vers_update_end()
{
if (vers_end_field()->store_timestamp(in_use->system_time,
in_use->system_time_sec_part))
if (vers_end_field()->store_timestamp(in_use->systime(),
in_use->systime_sec_part()))
DBUG_ASSERT(0);
}
......@@ -8622,9 +8622,9 @@ bool TR_table::update(ulonglong start_id, ulonglong end_id)
if (!table && open())
return true;
timeval start_time= {thd->system_time, long(thd->system_time_sec_part)};
timeval start_time= {thd->systime(), long(thd->systime_sec_part())};
thd->set_start_time();
timeval end_time= {thd->system_time, long(thd->system_time_sec_part)};
timeval end_time= {thd->systime(), long(thd->systime_sec_part())};
store(FLD_TRX_ID, start_id);
store(FLD_COMMIT_ID, end_id);
store(FLD_BEGIN_TS, start_time);
......
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