From a7e5f73abb9da35a1c199b89df84596cffe59901 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Jul 2007 17:50:58 +0200 Subject: Bug#27198: Error returns from time() are ignored gettimeofday() can fail and presumably, so can time(). Keep an eye on it. Since we have no data on this at all so far, we just retry on failure (and log the event), assuming that this is just an intermittant failure. This might of course hang the threat until we succeed. Once we know more about these failures, an appropriate more clever scheme may be picked (only try so many times per thread, etc., if that fails, return last "good" time() we got or some such). Using sql_print_information() to log as this probably only occurs in high load scenarios where the debug- trace likely is disabled (or might interfere with testing the effect). No test-case as this is a non-deterministic issue. sql/mysql_priv.h: Bug#27198: Error returns from time() are ignored move declarations for log.cc to before inclusion of sql_class.h as we now use sql_print_information() in there. sql/sql_class.h: Bug#27198: Error returns from time() are ignored gettimeofday() can fail and presumably, so can time(). Keep an eye on it. --- sql/sql_class.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 17d371d3dc0..25828ac2b7e 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -569,17 +569,33 @@ public: proc_info = old_msg; pthread_mutex_unlock(&mysys_var->mutex); } + + static inline void safe_time(time_t *t) + { + /** + Wrapper around time() which retries on error (-1) + + @details + This is needed because, despite the documentation, time() may fail + in some circumstances. Here we retry time() until it succeeds, and + log the failure so that performance problems related to this can be + identified. + */ + while(unlikely(time(t) == ((time_t) -1))) + sql_print_information("time() failed with %d", errno); + } + inline time_t query_start() { query_start_used=1; return start_time; } - inline void set_time() { if (user_time) start_time=time_after_lock=user_time; else time_after_lock=time(&start_time); } - inline void end_time() { time(&start_time); } + inline void set_time() { if (user_time) start_time=time_after_lock=user_time; else { safe_time(&start_time); time_after_lock= start_time; }} + inline void end_time() { safe_time(&start_time); } inline void set_time(time_t t) { time_after_lock=start_time=user_time=t; } - inline void lock_time() { time(&time_after_lock); } + inline void lock_time() { safe_time(&time_after_lock); } inline void insert_id(ulonglong id) { last_insert_id=id; insert_id_used=1; } inline ulonglong insert_id(void) { if (!last_insert_id_used) - { + { last_insert_id_used=1; current_insert_id=last_insert_id; } @@ -588,7 +604,7 @@ public: inline ulonglong found_rows(void) { return limit_found_rows; - } + } inline bool active_transaction() { #ifdef USING_TRANSACTIONS -- cgit v1.2.1