summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/pool_of_threads.result10
-rw-r--r--mysql-test/t/pool_of_threads.cnf3
-rw-r--r--mysql-test/t/pool_of_threads.test6
-rw-r--r--sql/threadpool_unix.cc15
4 files changed, 23 insertions, 11 deletions
diff --git a/mysql-test/r/pool_of_threads.result b/mysql-test/r/pool_of_threads.result
index 74ea7ba12eb..64168b0eb3c 100644
--- a/mysql-test/r/pool_of_threads.result
+++ b/mysql-test/r/pool_of_threads.result
@@ -2084,10 +2084,10 @@ fld6 char(4) latin1_swedish_ci NO #
show full columns from t2 from test like 's%';
Field Type Collation Null Key Default Extra Privileges Comment
show keys from t2;
-Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
-t2 0 PRIMARY 1 auto A 1199 NULL NULL BTREE
-t2 0 fld1 1 fld1 A 1199 NULL NULL BTREE
-t2 1 fld3 1 fld3 A NULL NULL NULL BTREE
+Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
+t2 0 PRIMARY 1 auto A 1199 NULL NULL BTREE
+t2 0 fld1 1 fld1 A 1199 NULL NULL BTREE
+t2 1 fld3 1 fld3 A NULL NULL NULL BTREE
drop table t4, t3, t2, t1;
CREATE TABLE t1 (
cont_nr int(11) NOT NULL auto_increment,
@@ -2153,7 +2153,7 @@ Warning 1052 Column 'kundentyp' in group statement is ambiguous
drop table t1;
SELECT sleep(5);
SELECT sleep(5);
-# -- Success: more than --thread-pool-size normal connections not possible
+# -- Success: more than --thread_pool_max_threads normal connections not possible
sleep(5)
0
sleep(5)
diff --git a/mysql-test/t/pool_of_threads.cnf b/mysql-test/t/pool_of_threads.cnf
index d719cc22ad4..ed4ad501c9d 100644
--- a/mysql-test/t/pool_of_threads.cnf
+++ b/mysql-test/t/pool_of_threads.cnf
@@ -2,7 +2,8 @@
[mysqld.1]
loose-thread-handling= pool-of-threads
-loose-thread_pool_size= 2
+loose-thread_pool_size= 1
+loose-thread_pool_max_threads= 2
extra-port= @ENV.MASTER_EXTRA_PORT
extra-max-connections=1
diff --git a/mysql-test/t/pool_of_threads.test b/mysql-test/t/pool_of_threads.test
index 530038cee91..caedb56dd2b 100644
--- a/mysql-test/t/pool_of_threads.test
+++ b/mysql-test/t/pool_of_threads.test
@@ -13,7 +13,7 @@
# connections on the extra port.
# First set two connections running, and check that extra connection
-# on normal port fails due to--thread-pool-size=2
+# on normal port fails due to--thread-pool-max_threads=2
connection default;
send SELECT sleep(5);
@@ -32,11 +32,11 @@ connect(con3,localhost,root,,);
let $error = $mysql_errno;
if (!$error)
{
- --echo # -- Error: managed to establish more than --thread-pool-size connections
+ --echo # -- Error: managed to establish more than --thread_pool_max_threads connections
}
if ($error)
{
- --echo # -- Success: more than --thread-pool-size normal connections not possible
+ --echo # -- Success: more than --thread_pool_max_threads normal connections not possible
}
connection default;
diff --git a/sql/threadpool_unix.cc b/sql/threadpool_unix.cc
index f0d7d5f33be..a8ceb250e5c 100644
--- a/sql/threadpool_unix.cc
+++ b/sql/threadpool_unix.cc
@@ -624,14 +624,22 @@ static pool_event_t * listener(worker_thread_t *current_thread,
-/* Creates a new worker thread. thread_mutex must be held when calling this function */
+/*
+ Creates a new worker thread.
+ thread_mutex must be held when calling this function
+
+ NOTE: in rare cases, the number of threads can exceed
+ threadpool_max_threads, because we need at least 2 threads
+ per group to prevent deadlocks (one listener + one worker)
+*/
static int create_worker(thread_group_t *thread_group)
{
pthread_t thread_id;
int err;
DBUG_ENTER("create_worker");
- if (tp_stats.num_worker_threads >= (int)threadpool_max_threads)
+ if (tp_stats.num_worker_threads >= (int)threadpool_max_threads
+ && thread_group->thread_count >= 2)
{
DBUG_PRINT("info",
("Cannot create new thread (maximum allowed threads reached)"));
@@ -667,6 +675,9 @@ static int wake_or_create_thread(thread_group_t *thread_group)
if (thread_group->pending_thread_start_count > 0)
DBUG_RETURN(-1);
+ if (thread_group->thread_count > thread_group->connection_count)
+ DBUG_RETURN(-1);
+
if (thread_group->thread_count < 4)
{
DBUG_RETURN(create_worker(thread_group));