From 20e2c322c2d73c067b69022471d0f86bd8bb899e Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 22 Jun 2012 17:29:35 -0700 Subject: [PATCH 1/2] Bug#65715: Wrong connection ID (thread ID) in the general and slow query logs The problem is that connection IDs (thread IDs) above 2^32 are not properly written to the general query log. The method used to write commands to the log (e.g. MYSQL_QUERY_LOG::write) uses a 32-bits wide integer to store the connection ID value, which is actually a 64-bits wide integer value, thus causing the higher bits of the value to be discarded. The solution is to simply use the correct type for storing thread IDs, which is my_thread_id (unsigned long). --- sql/log.cc | 9 ++++----- sql/log.h | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/sql/log.cc b/sql/log.cc index c094437..52810ca 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -552,7 +552,7 @@ void Log_to_csv_event_handler::cleanup() bool Log_to_csv_event_handler:: log_general(THD *thd, time_t event_time, const char *user_host, - uint user_host_len, int thread_id, + uint user_host_len, my_thread_id thread_id, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len, CHARSET_INFO *client_cs) @@ -958,7 +958,7 @@ bool Log_to_file_event_handler:: bool Log_to_file_event_handler:: log_general(THD *thd, time_t event_time, const char *user_host, - uint user_host_len, int thread_id, + uint user_host_len, my_thread_id thread_id, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len, CHARSET_INFO *client_cs) @@ -2554,7 +2554,7 @@ void MYSQL_QUERY_LOG::reopen_file() */ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host, - uint user_host_len, int thread_id, + uint user_host_len, my_thread_id thread_id, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len) { @@ -2592,8 +2592,7 @@ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host, if (my_b_write(&log_file, (uchar*) "\t\t" ,2) < 0) goto err; - /* command_type, thread_id */ - length= my_snprintf(buff, 32, "%5ld ", (long) thread_id); + length= my_snprintf(buff, 32, "%5lu ", thread_id); if (my_b_write(&log_file, (uchar*) buff, length)) goto err; diff --git a/sql/log.h b/sql/log.h index 6f86d6c..46f80c2 100644 --- a/sql/log.h +++ b/sql/log.h @@ -244,7 +244,7 @@ public: MYSQL_QUERY_LOG() : last_time(0) {} void reopen_file(); bool write(time_t event_time, const char *user_host, - uint user_host_len, int thread_id, + uint user_host_len, my_thread_id thread_id, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len); bool write(THD *thd, time_t current_time, time_t query_start_arg, @@ -530,7 +530,7 @@ public: virtual bool log_error(enum loglevel level, const char *format, va_list args)= 0; virtual bool log_general(THD *thd, time_t event_time, const char *user_host, - uint user_host_len, int thread_id, + uint user_host_len, my_thread_id thread_id, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len, CHARSET_INFO *client_cs)= 0; @@ -559,7 +559,7 @@ public: virtual bool log_error(enum loglevel level, const char *format, va_list args); virtual bool log_general(THD *thd, time_t event_time, const char *user_host, - uint user_host_len, int thread_id, + uint user_host_len, my_thread_id thread_id, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len, CHARSET_INFO *client_cs); @@ -591,7 +591,7 @@ public: virtual bool log_error(enum loglevel level, const char *format, va_list args); virtual bool log_general(THD *thd, time_t event_time, const char *user_host, - uint user_host_len, int thread_id, + uint user_host_len, my_thread_id thread_id, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len, CHARSET_INFO *client_cs); -- 1.7.4.4