Below is the list of changes that have just been committed into a local
6.0 repository of davi. When davi does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2008-03-17 21:55:52-03:00, davi@stripped +5 -0
Bug#17954 Threads_connected > Threads_created
The problem is that insert delayed threads are counted as connected
but not as created, leading to a Threads_connected value greater then
the Threads_created value.
The solution is to increment the Threads_created variable when insert
delayed threads are created and to change the Threads_connected variable
to reflect (as documented in the manual) the number of client connections.
mysql-test/r/status.result@stripped, 2008-03-17 21:55:48-03:00, davi@stripped +12 -0
Add test case result for Bug#17954
mysql-test/t/status.test@stripped, 2008-03-17 21:55:49-03:00, davi@stripped +28 -0
Add test case for Bug#17954
sql/mysql_priv.h@stripped, 2008-03-17 21:55:49-03:00, davi@stripped +1 -1
Export the thread_created variable.
sql/mysqld.cc@stripped, 2008-03-17 21:55:49-03:00, davi@stripped +5 -5
Make Threads_connected actually reflect the number of
connected clients and don't reset variables on flush.
sql/sql_insert.cc@stripped, 2008-03-17 21:55:49-03:00, davi@stripped +2 -3
Increment the thread_count value after the thread has been
created. Also, increment the thread_created value since
the thread has been successfully created.
diff -Nrup a/mysql-test/r/status.result b/mysql-test/r/status.result
--- a/mysql-test/r/status.result 2007-12-18 22:27:12 -02:00
+++ b/mysql-test/r/status.result 2008-03-17 21:55:48 -03:00
@@ -183,3 +183,15 @@ Com_create_function 1
Com_drop_function 1
Com_show_function_code 0
Com_show_function_status 0
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (a int);
+FLUSH STATUS;
+SELECT @dit < @tcr;
+@dit < @tcr
+1
+SET GLOBAL delayed_insert_limit= 10;
+INSERT DELAYED INTO t1 VALUES (0);
+DROP TABLE t1;
+SELECT @dit < @ditp, @tcr < @tcrp, @ditp < @tcrp;
+@dit < @ditp @tcr < @tcrp @ditp < @tcrp
+1 1 1
diff -Nrup a/mysql-test/t/status.test b/mysql-test/t/status.test
--- a/mysql-test/t/status.test 2007-12-21 17:27:42 -02:00
+++ b/mysql-test/t/status.test 2008-03-17 21:55:49 -03:00
@@ -262,3 +262,31 @@ show global status like 'Com%function%';
# End of 5.1 tests
+
+#
+# Bug #17954: Threads_connected > Threads_created
+#
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (a int);
+FLUSH STATUS;
+let $dit= `SHOW STATUS LIKE 'delayed_insert_threads'`;
+let $tcr= `SHOW STATUS LIKE 'threads_created'`;
+--disable_query_log
+eval SET @dit= SUBSTRING_INDEX('$dit', ' ', -1);
+eval SET @tcr= SUBSTRING_INDEX('$tcr', ' ', -1);
+--enable_query_log
+SELECT @dit < @tcr;
+SET GLOBAL delayed_insert_limit= 10;
+INSERT DELAYED INTO t1 VALUES (0);
+let $dit= `SHOW STATUS LIKE 'delayed_insert_threads'`;
+let $tcr= `SHOW STATUS LIKE 'threads_created'`;
+DROP TABLE t1;
+--disable_query_log
+eval SET @ditp= SUBSTRING_INDEX('$dit', ' ', -1);
+eval SET @tcrp= SUBSTRING_INDEX('$tcr', ' ', -1);
+--enable_query_log
+SELECT @dit < @ditp, @tcr < @tcrp, @ditp < @tcrp;
diff -Nrup a/sql/mysql_priv.h b/sql/mysql_priv.h
--- a/sql/mysql_priv.h 2008-03-12 11:49:46 -03:00
+++ b/sql/mysql_priv.h 2008-03-17 21:55:49 -03:00
@@ -1981,7 +1981,7 @@ extern my_bool opt_log_queries_not_using
extern bool opt_disable_networking, opt_skip_show_db;
extern my_bool opt_character_set_client_handshake;
extern bool volatile abort_loop, shutdown_in_progress;
-extern uint volatile thread_count, thread_running, global_read_lock;
+extern uint volatile thread_count, thread_running, thread_created, global_read_lock;
extern uint connection_count;
extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types;
extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap;
diff -Nrup a/sql/mysqld.cc b/sql/mysqld.cc
--- a/sql/mysqld.cc 2008-03-14 10:42:59 -03:00
+++ b/sql/mysqld.cc 2008-03-17 21:55:49 -03:00
@@ -386,7 +386,7 @@ static bool volatile ready_to_exit;
static my_bool opt_debugging= 0, opt_external_locking= 0, opt_console= 0;
static my_bool opt_short_log_format= 0;
static uint kill_cached_threads, wake_thread;
-static ulong killed_threads, thread_created;
+static ulong killed_threads;
static ulong max_used_connections;
static volatile ulong cached_thread_count= 0;
static const char *sql_mode_str= "OFF";
@@ -503,7 +503,7 @@ uint mysqld_port_timeout;
uint delay_key_write_options, protocol_version;
uint lower_case_table_names;
uint tc_heuristic_recover= 0;
-uint volatile thread_count, thread_running;
+uint volatile thread_count, thread_running, thread_created;
ulonglong thd_startup_options;
ulong back_log, connect_timeout, concurrency, server_id;
ulong table_cache_size, table_def_size;
@@ -2504,7 +2504,7 @@ and this may fail.\n\n");
fprintf(stderr, "read_buffer_size=%ld\n", (long) global_system_variables.read_buff_size);
fprintf(stderr, "max_used_connections=%lu\n", max_used_connections);
fprintf(stderr, "max_threads=%u\n", thread_scheduler.max_threads);
- fprintf(stderr, "threads_connected=%u\n", thread_count);
+ fprintf(stderr, "thread_count=%u\n", thread_count);
fprintf(stderr, "It is possible that mysqld could use up to \n\
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = %lu K\n\
bytes of memory\n", ((ulong) dflt_key_cache->key_cache_mem_size +
@@ -7438,9 +7438,9 @@ SHOW_VAR status_vars[]= {
{"Tc_log_page_waits", (char*) &tc_log_page_waits, SHOW_LONG},
#endif
{"Threads_cached", (char*) &cached_thread_count, SHOW_LONG_NOFLUSH},
- {"Threads_connected", (char*) &thread_count, SHOW_INT},
+ {"Threads_connected", (char*) &connection_count, SHOW_LONG_NOFLUSH},
{"Threads_created", (char*) &thread_created, SHOW_LONG_NOFLUSH},
- {"Threads_running", (char*) &thread_running, SHOW_INT},
+ {"Threads_running", (char*) &thread_running, SHOW_LONG_NOFLUSH},
{"Uptime", (char*) &show_starttime, SHOW_FUNC},
#ifdef COMMUNITY_SERVER
{"Uptime_since_flush_status",(char*) &show_flushstatustime, SHOW_FUNC},
diff -Nrup a/sql/sql_insert.cc b/sql/sql_insert.cc
--- a/sql/sql_insert.cc 2008-02-26 13:45:12 -03:00
+++ b/sql/sql_insert.cc 2008-03-17 21:55:49 -03:00
@@ -1874,9 +1874,6 @@ bool delayed_get_table(THD *thd, TABLE_L
thd->fatal_error();
goto end_create;
}
- pthread_mutex_lock(&LOCK_thread_count);
- thread_count++;
- pthread_mutex_unlock(&LOCK_thread_count);
di->thd.set_db(table_list->db, strlen(table_list->db));
di->thd.query= my_strdup(table_list->table_name, MYF(MY_WME));
if (di->thd.db == NULL || di->thd.query == NULL)
@@ -2242,6 +2239,8 @@ pthread_handler_t handle_delayed_insert(
pthread_detach_this_thread();
/* Add thread to THD list so that's it's visible in 'show processlist' */
pthread_mutex_lock(&LOCK_thread_count);
+ thread_created++;
+ thread_count++;
thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
thd->set_current_time();
threads.append(thd);