Below is the list of changes that have just been committed into a local
5.0 repository of tomash. When tomash 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
1.2134 06/04/06 00:25:25 kroki@stripped +5 -0
Bug#15933: max_used_connections is wrong after FLUSH STATUS if connections are cached
After FLUSH STATUS max_used_connections was reset to 0, and haven't
been updated while cached threads were reused, until the moment a new
thread was created.
The first suggested fix from original bug report was implemented:
a) On flushing the status, set max_used_connections to
threads_connected, not to 0.
b) Check if it is necessary to increment max_used_connections when
taking a thread from the cache as well as when creating new threads
mysql-test/t/max_used_connections.test
1.1 06/04/06 00:25:19 kroki@stripped +55 -0
Add test case for bug#15933.
mysql-test/r/max_used_connections.result
1.1 06/04/06 00:25:19 kroki@stripped +20 -0
Add test result for bug#15933.
sql/sql_parse.cc
1.537 06/04/06 00:25:19 kroki@stripped +0 -22
refresh_status() moved to sql/mysqld.cc.
mysql-test/t/max_used_connections.test
1.0 06/04/06 00:25:19 kroki@stripped +0 -0
BitKeeper file
/home/tomash/src/mysql_ab/mysql-5.0-bug15933/mysql-test/t/max_used_connections.test
mysql-test/r/max_used_connections.result
1.0 06/04/06 00:25:19 kroki@stripped +0 -0
BitKeeper file
/home/tomash/src/mysql_ab/mysql-5.0-bug15933/mysql-test/r/max_used_connections.result
sql/mysqld.cc
1.541 06/04/06 00:25:18 kroki@stripped +58 -16
Remove start_cached_thread() (code moved directly into create_new_thread()).
Add comment for create_new_thread ().
In create_new_thread() update max_used_connections both when creating new
thread and when reusing the cached one.
Move refresh_status() from sql/sql_parse.cc here, on refresh set
max_used_connections to the current number of connections. Lock
LOCK_thread_count mutex.
sql/mysql_priv.h
1.381 06/04/06 00:25:18 kroki@stripped +1 -0
Add declaration of refresh_status(), which is now external.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: kroki
# Host: moonlight.intranet
# Root: /home/tomash/src/mysql_ab/mysql-5.0-bug15933
--- 1.380/sql/mysql_priv.h 2006-03-30 17:14:51 +04:00
+++ 1.381/sql/mysql_priv.h 2006-04-06 00:25:18 +04:00
@@ -1097,6 +1097,7 @@
/* mysqld.cc */
extern void MYSQLerror(const char*);
+void refresh_status(THD *thd);
/* item_func.cc */
extern bool check_reserved_words(LEX_STRING *name);
--- 1.540/sql/mysqld.cc 2006-03-16 11:15:20 +03:00
+++ 1.541/sql/mysqld.cc 2006-04-06 00:25:18 +04:00
@@ -1639,17 +1639,6 @@
}
-/* Start a cached thread. LOCK_thread_count is locked on entry */
-
-static void start_cached_thread(THD *thd)
-{
- thread_cache.append(thd);
- wake_thread++;
- thread_count++;
- pthread_cond_signal(&COND_thread_cache);
-}
-
-
void flush_thread_cache()
{
(void) pthread_mutex_lock(&LOCK_thread_count);
@@ -3780,6 +3769,25 @@
#ifndef EMBEDDED_LIBRARY
+/*
+ Create new thread to handle incoming connection.
+
+ SYNOPSIS
+ create_new_thread()
+ thd in/out Thread handle of future thread.
+
+ DESCRIPTION
+ This function will create new thread to handle the incoming
+ connection. If there are idle cached threads one will be used.
+ 'thd' will be pushed into 'threads'.
+
+ In single-threaded mode (#define ONE_THREAD) connection will be
+ handled inside this function.
+
+ RETURN VALUE
+ none
+*/
+
static void create_new_thread(THD *thd)
{
DBUG_ENTER("create_new_thread");
@@ -3803,11 +3811,12 @@
thd->real_id=pthread_self(); // Keep purify happy
/* Start a new thread to handle connection */
+ thread_count++;
+
#ifdef ONE_THREAD
if (test_flags & TEST_NO_THREADS) // For debugging under Linux
{
thread_cache_size=0; // Safety
- thread_count++;
threads.append(thd);
thd->real_id=pthread_self();
(void) pthread_mutex_unlock(&LOCK_thread_count);
@@ -3816,18 +3825,20 @@
else
#endif
{
+ if (thread_count-delayed_insert_threads > max_used_connections)
+ max_used_connections=thread_count-delayed_insert_threads;
+
if (cached_thread_count > wake_thread)
{
- start_cached_thread(thd);
+ thread_cache.append(thd);
+ wake_thread++;
+ pthread_cond_signal(&COND_thread_cache);
}
else
{
int error;
- thread_count++;
thread_created++;
threads.append(thd);
- if (thread_count-delayed_insert_threads > max_used_connections)
- max_used_connections=thread_count-delayed_insert_threads;
DBUG_PRINT("info",(("creating thread %d"), thd->thread_id));
thd->connect_time = time(NULL);
if ((error=pthread_create(&thd->real_id,&connection_attrib,
@@ -7390,6 +7401,37 @@
}
sql_perror("Can't start server: can't create PID file");
exit(1);
+}
+
+
+/* Clear most status variables */
+void refresh_status(THD *thd)
+{
+ pthread_mutex_lock(&LOCK_status);
+
+ /* We must update the global status before cleaning up the thread */
+ add_to_status(&global_status_var, &thd->status_var);
+ bzero((char*) &thd->status_var, sizeof(thd->status_var));
+
+ /*
+ We need to lock LOCK_thread_count here because thread_count is
+ indirectly assigned in the loop
+ */
+ pthread_mutex_lock(&LOCK_thread_count);
+
+ for (struct show_var_st *ptr=status_vars; ptr->name; ptr++)
+ {
+ if (ptr->type == SHOW_LONG)
+ *(ulong*) ptr->value= 0;
+ }
+
+ /* Set max_used_connections to the number of currently open connections */
+ max_used_connections= thread_count-delayed_insert_threads;
+ pthread_mutex_unlock(&LOCK_thread_count);
+
+ /* Reset the counters of all key caches (default and named). */
+ process_key_caches(reset_key_cache_counters);
+ pthread_mutex_unlock(&LOCK_status);
}
--- 1.536/sql/sql_parse.cc 2006-03-15 20:15:42 +03:00
+++ 1.537/sql/sql_parse.cc 2006-04-06 00:25:19 +04:00
@@ -74,7 +74,6 @@
static bool check_db_used(THD *thd,TABLE_LIST *tables);
static bool check_multi_update_lock(THD *thd);
static void remove_escape(char *name);
-static void refresh_status(THD *thd);
static bool append_file_to_dir(THD *thd, const char **filename_ptr,
const char *table_name);
@@ -6706,27 +6705,6 @@
send_ok(thd);
else
my_error(error, MYF(0), id);
-}
-
-
-/* Clear most status variables */
-
-static void refresh_status(THD *thd)
-{
- pthread_mutex_lock(&LOCK_status);
-
- /* We must update the global status before cleaning up the thread */
- add_to_status(&global_status_var, &thd->status_var);
- bzero((char*) &thd->status_var, sizeof(thd->status_var));
-
- for (struct show_var_st *ptr=status_vars; ptr->name; ptr++)
- {
- if (ptr->type == SHOW_LONG)
- *(ulong*) ptr->value= 0;
- }
- /* Reset the counters of all key caches (default and named). */
- process_key_caches(reset_key_cache_counters);
- pthread_mutex_unlock(&LOCK_status);
}
--- New file ---
+++ mysql-test/r/max_used_connections.result 06/04/06 00:25:19
FLUSH STATUS;
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 1
SET @save_thread_cache_size=@@thread_cache_size;
SET GLOBAL thread_cache_size=3;
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 3
FLUSH STATUS;
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 2
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 3
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 4
SET GLOBAL thread_cache_size=@save_thread_cache_size;
--- New file ---
+++ mysql-test/t/max_used_connections.test 06/04/06 00:25:19
#
# Test for Bug #15933 max_used_connections is wrong after FLUSH STATUS
# if connections are cached
#
#
# The first suggested fix from the bug report was chosen
# (see http://bugs.mysql.com/bug.php?id=15933):
#
# a) On flushing the status, set max_used_connections to
# threads_connected, not to 0.
#
# b) Check if it is necessary to increment max_used_connections when
# taking a thread from the cache as well as when creating new threads
#
# Reset max_used_connections from previous tests.
FLUSH STATUS;
SHOW STATUS LIKE 'max_used_connections';
# Save original setting.
SET @save_thread_cache_size=@@thread_cache_size;
SET GLOBAL thread_cache_size=3;
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
connection con1;
disconnect con2;
# Check that max_used_connections still reflects maximum value.
SHOW STATUS LIKE 'max_used_connections';
# Check that after flush max_used_connections equals to current number
# of connections.
FLUSH STATUS;
SHOW STATUS LIKE 'max_used_connections';
# Check that max_used_connections is updated both when cached thread
# is reused...
connect (con2,localhost,root,,);
SHOW STATUS LIKE 'max_used_connections';
# ...and when new thread is created.
connect (con3,localhost,root,,);
SHOW STATUS LIKE 'max_used_connections';
# Restore original setting.
connection default;
SET GLOBAL thread_cache_size=@save_thread_cache_size;
disconnect con3;
disconnect con2;
disconnect con1;
# End of 5.0 tests
| Thread |
|---|
| • bk commit into 5.0 tree (kroki:1.2134) BUG#15933 | kroki | 5 Apr |