diff options
author | Sergei Golubchik <serg@mariadb.org> | 2018-05-02 21:53:12 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2018-05-12 10:16:46 +0200 |
commit | a4272bf154acf0e35b4b678812024b43a0c57829 (patch) | |
tree | b586567adc4344660452561cf578260ae4a3c8f5 /sql | |
parent | 4203f572aeebb55ad97c9576d58c0a14ed73862a (diff) | |
download | mariadb-git-a4272bf154acf0e35b4b678812024b43a0c57829.tar.gz |
versioning: use @@timestamp
Don't use hidden system time in versioning,
but keep the system time logic in THD
to workaround low-res system clock and
replication not versioned to versioned.
This reverts MDEV-14788 (System versioning cannot
be based on local timestamps, as it is now).
Versioning is based on local timestamps again,
but timestamps are protected by MDEV-15923
(option to control who can set session @@timestamp).
Diffstat (limited to 'sql')
-rw-r--r-- | sql/partition_info.cc | 4 | ||||
-rw-r--r-- | sql/sql_class.h | 48 | ||||
-rw-r--r-- | sql/sql_partition.cc | 4 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 2 | ||||
-rw-r--r-- | sql/table.cc | 12 |
5 files changed, 29 insertions, 41 deletions
diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 746d00ef8d1..5c1cb106b28 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -859,7 +859,7 @@ void partition_info::vers_set_hist_part(THD *thd) if (vers_info->interval.is_set()) { - if (vers_info->hist_part->range_value > thd->systime()) + if (vers_info->hist_part->range_value > thd->query_start()) return; partition_element *next= NULL; @@ -870,7 +870,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->systime()) + if (next->range_value > thd->query_start()) return; } goto warn; diff --git a/sql/sql_class.h b/sql/sql_class.h index 6241e80052c..22b8e3e18f0 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3437,16 +3437,13 @@ public: { query_start_sec_part_used=1; return start_time_sec_part; } MYSQL_TIME query_start_TIME(); +private: struct { my_hrtime_t start; my_time_t sec; ulong sec_part; } system_time; - ulong systime_sec_part() { query_start_sec_part_used=1; return system_time.sec_part; } - my_time_t systime() { return system_time.sec; } - -private: void set_system_time() { my_hrtime_t hrtime= my_hrtime(); @@ -3471,29 +3468,9 @@ private: } } - void set_system_time_from_user_time(bool with_sec_part) - { - if (with_sec_part) - { - system_time.sec= start_time; - system_time.sec_part= start_time_sec_part; - } - else - { - if (system_time.sec == start_time) - system_time.sec_part++; - else - { - system_time.sec= start_time; - system_time.sec_part= 0; - } - } - } - public: inline void set_start_time() { - set_system_time(); if (user_time.val) { start_time= hrtime_to_my_time(user_time); @@ -3501,6 +3478,7 @@ public: } else { + set_system_time(); start_time= system_time.sec; start_time_sec_part= system_time.sec_part; } @@ -3511,6 +3489,7 @@ public: set_start_time(); start_utime= utime_after_lock= microsecond_interval_timer(); } + /* only used in SET @@timestamp=... */ inline void set_time(my_hrtime_t t) { user_time= t; @@ -3526,13 +3505,22 @@ public: set_time(); // note that BINLOG itself requires SUPER else { - start_time= t; - start_time_sec_part= sec_part > TIME_MAX_SECOND_PART ? 0 : sec_part; + if (sec_part <= TIME_MAX_SECOND_PART) + { + start_time= system_time.sec= t; + start_time_sec_part= system_time.sec_part= sec_part; + } + else if (t != system_time.sec) + { + start_time= system_time.sec= t; + start_time_sec_part= system_time.sec_part= 0; + } + else + { + start_time= t; + start_time_sec_part= ++system_time.sec_part; + } user_time.val= hrtime_from_time(start_time) + start_time_sec_part; - if (slave_thread) - set_system_time_from_user_time(sec_part <= TIME_MAX_SECOND_PART); - else // BINLOG command - set_system_time(); PSI_CALL_set_thread_start_time(start_time); start_utime= utime_after_lock= microsecond_interval_timer(); } diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index c2534a9962e..f7cd6c2a71e 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1571,7 +1571,7 @@ static bool check_vers_constants(THD *thd, partition_info *part_info) my_tz_OFFSET0->TIME_to_gmt_sec(<ime, &error); if (error) goto err; - if (vers_info->hist_part->range_value <= thd->systime()) + if (vers_info->hist_part->range_value <= thd->query_start()) vers_info->hist_part= el; } return 0; @@ -5310,7 +5310,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->systime()) + if (hist_part->range_value <= thd->query_start()) hist_part->part_state= PART_CHANGED; } } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 9608620d88c..9e6d53883ad 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -5907,7 +5907,7 @@ opt_versioning_rotation: opt_versioning_interval_start: /* empty */ { - $$= thd->systime(); + $$= thd->query_start(); } | STARTS_SYM ulong_num { diff --git a/sql/table.cc b/sql/table.cc index 74b4ce3c842..bc61e77c972 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -7752,8 +7752,8 @@ void TABLE::vers_update_fields() { if (!vers_write) return; - if (vers_start_field()->store_timestamp(in_use->systime(), - in_use->systime_sec_part())) + if (vers_start_field()->store_timestamp(in_use->query_start(), + in_use->query_start_sec_part())) DBUG_ASSERT(0); } else @@ -7768,8 +7768,8 @@ void TABLE::vers_update_fields() void TABLE::vers_update_end() { - if (vers_end_field()->store_timestamp(in_use->systime(), - in_use->systime_sec_part())) + if (vers_end_field()->store_timestamp(in_use->query_start(), + in_use->query_start_sec_part())) DBUG_ASSERT(0); } @@ -8611,9 +8611,9 @@ bool TR_table::update(ulonglong start_id, ulonglong end_id) if (!table && open()) return true; - timeval start_time= {thd->systime(), long(thd->systime_sec_part())}; + timeval start_time= {thd->query_start(), long(thd->query_start_sec_part())}; thd->set_start_time(); - timeval end_time= {thd->systime(), long(thd->systime_sec_part())}; + timeval end_time= {thd->query_start(), long(thd->query_start_sec_part())}; store(FLD_TRX_ID, start_id); store(FLD_COMMIT_ID, end_id); store(FLD_BEGIN_TS, start_time); |