Skip to content

Commit 647d5b2

Browse files
committed
MDEV-20079 When setting back the system time while mysqld is running, NOW() and UNIX_TIMESTAMP() results get stuck
typo. system_time.start wasn't updated when system_time.sec and system_time.sec_part were.
1 parent 08b01ac commit 647d5b2

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set @old_dbug=@@debug_dbug;
2+
select timestampdiff(minute,now(),sysdate()) as 'must be 0', (unix_timestamp(sysdate()) - unix_timestamp()) div 60 as 'must be 0';
3+
must be 0 must be 0
4+
0 0
5+
set @@debug_dbug='+d,system_time_plus_one_hour';
6+
select timestampdiff(minute,now(),sysdate()) as 'must be 0', (unix_timestamp(sysdate()) - unix_timestamp()) div 60 as 'must be 0';
7+
must be 0 must be 0
8+
0 0
9+
set @@debug_dbug='+d,system_time_minus_one_hour:-d,system_time_plus_one_hour';
10+
select timestampdiff(minute,now(),sysdate()) as 'must be 0', (unix_timestamp(sysdate()) - unix_timestamp()) div 60 as 'must be 0';
11+
must be 0 must be 0
12+
0 0
13+
set @@debug_dbug=@old_dbug;
14+
select timestampdiff(minute,now(),sysdate()) as 'must be 0', (unix_timestamp(sysdate()) - unix_timestamp()) div 60 as 'must be 0';
15+
must be 0 must be 0
16+
0 0
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
source include/have_debug.inc;
2+
#
3+
# MDEV-20079 When setting back the system time while mysqld is running, NOW() and UNIX_TIMESTAMP() results get stuck
4+
#
5+
set @old_dbug=@@debug_dbug;
6+
7+
# because NOW() is taken at the beginning of the query and sysdate() is the actual
8+
# time when sysdate() was evaluated, they don't necessarily have to be equal.
9+
# but hopefully they're less than within a minute from each other.
10+
select timestampdiff(minute,now(),sysdate()) as 'must be 0', (unix_timestamp(sysdate()) - unix_timestamp()) div 60 as 'must be 0';
11+
set @@debug_dbug='+d,system_time_plus_one_hour';
12+
select timestampdiff(minute,now(),sysdate()) as 'must be 0', (unix_timestamp(sysdate()) - unix_timestamp()) div 60 as 'must be 0';
13+
set @@debug_dbug='+d,system_time_minus_one_hour:-d,system_time_plus_one_hour';
14+
select timestampdiff(minute,now(),sysdate()) as 'must be 0', (unix_timestamp(sysdate()) - unix_timestamp()) div 60 as 'must be 0';
15+
set @@debug_dbug=@old_dbug;
16+
select timestampdiff(minute,now(),sysdate()) as 'must be 0', (unix_timestamp(sysdate()) - unix_timestamp()) div 60 as 'must be 0';

mysys/my_getsystime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ my_hrtime_t my_hrtime()
9999
while (gettimeofday(&t, NULL) != 0) {}
100100
hrtime.val= t.tv_sec*1000000ULL + t.tv_usec;
101101
#endif
102+
DBUG_EXECUTE_IF("system_time_plus_one_hour", hrtime.val += 3600*1000000ULL;);
103+
DBUG_EXECUTE_IF("system_time_minus_one_hour", hrtime.val -= 3600*1000000ULL;);
102104
return hrtime;
103105
}
104106

sql/sql_class.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,6 +3443,7 @@ class THD :public Statement,
34433443
{
34443444
system_time.sec= sec;
34453445
system_time.sec_part= sec_part;
3446+
system_time.start= hrtime;
34463447
}
34473448
else
34483449
{

0 commit comments

Comments
 (0)