1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

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.
This commit is contained in:
Sergei Golubchik
2018-02-25 12:55:12 +01:00
parent 30981dcf56
commit ac2d4d49a0
6 changed files with 37 additions and 33 deletions

View File

@ -900,7 +900,7 @@ void partition_info::vers_set_hist_part(THD *thd)
if (vers_info->interval.is_set()) 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; return;
partition_element *next= NULL; partition_element *next= NULL;
@ -911,7 +911,7 @@ void partition_info::vers_set_hist_part(THD *thd)
while ((next= it++) != vers_info->now_part) while ((next= it++) != vers_info->now_part)
{ {
vers_info->hist_part= next; vers_info->hist_part= next;
if (next->range_value > thd->system_time) if (next->range_value > thd->systime())
return; return;
} }
goto warn; goto warn;

View File

@ -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 // Must be reset to handle error with THD's created for init of mysqld
lex->current_select= 0; lex->current_select= 0;
start_utime= utime_after_query= 0; start_utime= utime_after_query= 0;
system_time= 0; system_time.start.val= system_time.sec= system_time.sec_part= 0;
system_time_sec_part= 0;
utime_after_lock= 0L; utime_after_lock= 0L;
progress.arena= 0; progress.arena= 0;
progress.report_to_client= 0; progress.report_to_client= 0;

View File

@ -2418,8 +2418,6 @@ public:
// track down slow pthread_create // track down slow pthread_create
ulonglong prior_thr_create_utime, thr_create_utime; ulonglong prior_thr_create_utime, thr_create_utime;
ulonglong utime_after_query; ulonglong utime_after_query;
my_time_t system_time;
ulong system_time_sec_part;
// Process indicator // Process indicator
struct { struct {
@ -3430,30 +3428,37 @@ public:
{ query_start_sec_part_used=1; return start_time_sec_part; } { query_start_sec_part_used=1; return start_time_sec_part; }
MYSQL_TIME query_start_TIME(); MYSQL_TIME query_start_TIME();
private: struct {
bool system_time_ge(my_time_t secs, ulong usecs) my_hrtime_t start;
{ my_time_t sec;
return (system_time == secs && system_time_sec_part >= usecs) || ulong sec_part;
system_time > secs; } system_time;
}
ulong systime_sec_part() { return system_time.sec_part; }
my_time_t systime() { return system_time.sec; }
private:
void set_system_time() void set_system_time()
{ {
my_hrtime_t hrtime= my_hrtime(); my_hrtime_t hrtime= my_hrtime();
my_time_t secs= hrtime_to_my_time(hrtime); my_time_t sec= hrtime_to_my_time(hrtime);
ulong usecs= hrtime_sec_part(hrtime); ulong sec_part= hrtime_sec_part(hrtime);
if (system_time_ge(secs, usecs)) 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.sec= sec;
{ system_time.sec_part= sec_part;
++system_time;
system_time_sec_part= 0;
}
} }
else else
{ {
system_time= secs; if (system_time.sec_part < TIME_MAX_SECOND_PART)
system_time_sec_part= usecs; system_time.sec_part++;
else
{
system_time.sec++;
system_time.sec_part= 0;
}
} }
} }
@ -3468,8 +3473,8 @@ public:
} }
else else
{ {
start_time= system_time; start_time= system_time.sec;
start_time_sec_part= system_time_sec_part; start_time_sec_part= system_time.sec_part;
} }
PSI_CALL_set_thread_start_time(start_time); PSI_CALL_set_thread_start_time(start_time);
} }

View File

@ -1574,7 +1574,7 @@ static bool check_vers_constants(THD *thd, partition_info *part_info)
my_tz_OFFSET0->TIME_to_gmt_sec(&ltime, &error); my_tz_OFFSET0->TIME_to_gmt_sec(&ltime, &error);
if (error) if (error)
goto err; 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; vers_info->hist_part= el;
} }
return 0; return 0;
@ -5314,7 +5314,7 @@ that are reorganised.
if (*fast_alter_table && tab_part_info->vers_info->interval.is_set()) if (*fast_alter_table && tab_part_info->vers_info->interval.is_set())
{ {
partition_element *hist_part= tab_part_info->vers_info->hist_part; 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; hist_part->part_state= PART_CHANGED;
} }
} }

View File

@ -5872,7 +5872,7 @@ opt_versioning_rotation:
opt_versioning_interval_start: opt_versioning_interval_start:
/* empty */ /* empty */
{ {
$$= thd->system_time; $$= thd->systime();
} }
| remember_tok_start STARTS_SYM ulong_num | remember_tok_start STARTS_SYM ulong_num
{ {

View File

@ -7764,8 +7764,8 @@ void TABLE::vers_update_fields()
{ {
if (!vers_write) if (!vers_write)
return; return;
if (vers_start_field()->store_timestamp(in_use->system_time, if (vers_start_field()->store_timestamp(in_use->systime(),
in_use->system_time_sec_part)) in_use->systime_sec_part()))
DBUG_ASSERT(0); DBUG_ASSERT(0);
} }
else else
@ -7780,8 +7780,8 @@ void TABLE::vers_update_fields()
void TABLE::vers_update_end() void TABLE::vers_update_end()
{ {
if (vers_end_field()->store_timestamp(in_use->system_time, if (vers_end_field()->store_timestamp(in_use->systime(),
in_use->system_time_sec_part)) in_use->systime_sec_part()))
DBUG_ASSERT(0); DBUG_ASSERT(0);
} }
@ -8622,9 +8622,9 @@ bool TR_table::update(ulonglong start_id, ulonglong end_id)
if (!table && open()) if (!table && open())
return true; 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(); 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_TRX_ID, start_id);
store(FLD_COMMIT_ID, end_id); store(FLD_COMMIT_ID, end_id);
store(FLD_BEGIN_TS, start_time); store(FLD_BEGIN_TS, start_time);