#At file:///home/kgeorge/mysql/work/B38217-5.1-bugteam/ based on revid:kristofer.pettersson@stripped
2829 Georgi Kodinov 2009-03-06
Bug #22047: Time in SHOW PROCESSLIST for SQL thread in replication seems to
become negative
THD::start_time has a dual meaning : it's either the time since the process
entered a given state or is the transaction time returned by e.g. NOW().
This causes problems, as sometimes THD::start_time may be set to a value
that is correct and needed when used as a base for NOW(), but these times
may be arbitrary (SET @@timestamp) or non-local (coming from the master
through the replication feed).
If one such non-local time is set there's no way to return a correct value
for e.g. SHOW PROCESSLIST or SELECT ... FROM INFORMATION_SCHEMA.PROCESSLIST.
Fixed by introducing a local equivalent of start_time (local_start_time)
and using the new member exclusively for timing and reporting execution
intervals.
Note that no reliable test suite can be constructed, since it would require
knowing the local time and can't be achieved by the means of the current test
suite.
@ sql/sql_class.cc
Bug #22047: introduced the local time for measuring time intervals
@ sql/sql_class.h
Bug #22047: introduced the local time for measuring time intervals
@ sql/sql_insert.cc
Bug #22047: set local time for the delayed insert thread
@ sql/sql_show.cc
Bug #22047: use local time in I_S.PROCESSLIST
modified:
sql/sql_class.cc
sql/sql_class.h
sql/sql_insert.cc
sql/sql_show.cc
=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc 2009-03-06 10:19:02 +0000
+++ b/sql/sql_class.cc 2009-03-06 15:30:25 +0000
@@ -590,6 +590,7 @@ THD::THD()
// Must be reset to handle error with THD's created for init of mysqld
lex->current_select= 0;
start_time=(time_t) 0;
+ local_start_time=(time_t) 0;
start_utime= 0L;
utime_after_lock= 0L;
current_linfo = 0;
=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h 2009-03-05 19:01:46 +0000
+++ b/sql/sql_class.h 2009-03-06 15:30:25 +0000
@@ -1342,6 +1342,11 @@ public:
/* remote (peer) port */
uint16 peer_port;
time_t start_time, user_time;
+ /*
+ Same as the start_time, but guaranteed to have only times from the local box.
+ Used for reporting local time intervals.
+ */
+ time_t local_start_time;
ulonglong connect_utime, thr_create_utime; // track down slow pthread_create
ulonglong start_utime, utime_after_lock;
@@ -1922,16 +1927,22 @@ public:
if (user_time)
{
start_time= user_time;
- start_utime= utime_after_lock= my_micro_time();
+ start_utime= utime_after_lock= my_micro_time_and_time(&local_start_time);
}
else
+ {
start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
+ local_start_time= start_time;
+ }
+ }
+ inline void set_current_time()
+ {
+ local_start_time= start_time= my_time(MY_WME);
}
- inline void set_current_time() { start_time= my_time(MY_WME); }
inline void set_time(time_t t)
{
start_time= user_time= t;
- start_utime= utime_after_lock= my_micro_time();
+ start_utime= utime_after_lock= my_micro_time_and_time(&local_start_time);
}
void set_time_after_lock() { utime_after_lock= my_micro_time(); }
ulonglong current_utime() { return my_micro_time(); }
=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc 2009-02-19 21:09:35 +0000
+++ b/sql/sql_insert.cc 2009-03-06 15:30:25 +0000
@@ -2564,7 +2564,7 @@ bool Delayed_insert::handle_inserts(void
pthread_mutex_unlock(&mutex);
memcpy(table->record[0],row->record,table->s->reclength);
- thd.start_time=row->start_time;
+ thd.set_time (row->start_time);
thd.query_start_used=row->query_start_used;
/*
To get the exact auto_inc interval to store in the binlog we must not
=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc 2009-03-05 11:15:47 +0000
+++ b/sql/sql_show.cc 2009-03-06 15:30:25 +0000
@@ -1765,7 +1765,7 @@ void mysqld_list_processes(THD *thd,cons
if (mysys_var)
pthread_mutex_unlock(&mysys_var->mutex);
- thd_info->start_time= tmp->start_time;
+ thd_info->start_time= tmp->local_start_time;
thd_info->query=0;
if (tmp->query)
{
@@ -1872,8 +1872,8 @@ int fill_schema_processlist(THD* thd, TA
table->field[4]->store(command_name[tmp->command].str,
command_name[tmp->command].length, cs);
/* MYSQL_TIME */
- table->field[5]->store((uint32)(tmp->start_time ?
- now - tmp->start_time : 0), TRUE);
+ table->field[5]->store((uint32)(tmp->local_start_time ?
+ now - tmp->local_start_time : 0), TRUE);
/* STATE */
#ifndef EMBEDDED_LIBRARY
val= (char*) (tmp->locked ? "Locked" :
Attachment: [text/bzr-bundle] bzr/joro@sun.com-20090306153025-3aao638c8ch6qh9l.bundle