Skip to content

Commit a405218

Browse files
committed
MDEV-37890 - sys_vars.thread_cache_size_func fails sporadically
Removed redundant FLUSH STATUS, doesn't serve any purpose in this test. Shrinking thread_cache_size is done without appropriate mutex protection and it doesn't flush thread cache. It means we may have more threads in the cache than thread_cache_size allows. First FLUSH THREADS (line 36) was added just in case thread_cache_size_func-master.opt file is removed and raising thread_cache_size from 0 to 3 becomes shrinking from the default value to 3. Second FLUSH THREADS (line 81) was added to fix timeout in wait condition (line 100). It serves as a barrier that guarantees fourth preceding disconnect won't pick one of subsequent connects and in turn leave 2 threads in the cache. Threads_cached cannot be queried for exact value because there can (or cannot) be disconnecting threads from previous tests or mtr utility connection. There is also a gap between server_threads.erase() (aka removal from I_S.PROCESSLIST) and thread_cache.park() (aka Threads_cached++). All in all it makes Threads_cached value unpredictable after thread_cache_size is set to 3. Instead of querying for exact value, just make sure Threads_cached doesn't exceed thread_cache_size.
1 parent 8be6d25 commit a405218

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

mysql-test/suite/sys_vars/r/thread_cache_size_func.result

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
SET @global_thread_cache_size = @@GLOBAL.thread_cache_size;
2-
FLUSH STATUS;
32
'# Test1#'
43
SET @@GLOBAL.thread_cache_size=3;
5-
SHOW STATUS LIKE 'Threads_cached';
6-
Variable_name Value
7-
Threads_cached 0
8-
0 Expected
4+
FLUSH THREADS;
5+
select variable_value<=@@global.thread_cache_size from information_schema.global_status where variable_name="Threads_cached";
6+
variable_value<=@@global.thread_cache_size
7+
1
98
CONNECT conn1,localhost,root,,;
109
CONNECT conn2,localhost,root,,;
1110
CONNECT conn3,localhost,root,,;
1211
CONNECT conn4,localhost,root,,;
1312
connection default;
14-
SHOW STATUS LIKE 'Threads_cached';
15-
Variable_name Value
16-
Threads_cached 0
17-
0 Expected
13+
select variable_value<=@@global.thread_cache_size from information_schema.global_status where variable_name="Threads_cached";
14+
variable_value<=@@global.thread_cache_size
15+
1
1816
disconnect conn1;
1917
disconnect conn2;
2018
disconnect conn3;
2119
disconnect conn4;
2220
SET @@GLOBAL.thread_cache_size= 1;
21+
FLUSH THREADS;
2322
CONNECT conn1,localhost,root,,;
2423
CONNECT conn2,localhost,root,,;
2524
connection default;

mysql-test/suite/sys_vars/t/thread_cache_size_func.test

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@
3131
--source include/one_thread_per_connection.inc
3232
SET @global_thread_cache_size = @@GLOBAL.thread_cache_size;
3333

34-
FLUSH STATUS;
35-
3634
-- ECHO '# Test1#'
3735
SET @@GLOBAL.thread_cache_size=3;
38-
SHOW STATUS LIKE 'Threads_cached';
39-
--echo 0 Expected
36+
FLUSH THREADS;
37+
select variable_value<=@@global.thread_cache_size from information_schema.global_status where variable_name="Threads_cached";
4038

4139
##################################
4240
# Make 4 connections #
@@ -53,8 +51,7 @@ CONNECTION default;
5351
let $wait_condition= SELECT COUNT(*)= 5 FROM INFORMATION_SCHEMA.PROCESSLIST;
5452
--source include/wait_condition.inc
5553

56-
SHOW STATUS LIKE 'Threads_cached';
57-
--echo 0 Expected
54+
select variable_value<=@@global.thread_cache_size from information_schema.global_status where variable_name="Threads_cached";
5855

5956
####################################
6057
#Disconnecting all the connections #
@@ -81,6 +78,7 @@ let $wait_condition= SELECT variable_value = 3 FROM INFORMATION_SCHEMA.global_st
8178
# Decreasing cache size to 1
8279
#
8380
SET @@GLOBAL.thread_cache_size= 1;
81+
FLUSH THREADS;
8482

8583
CONNECT (conn1,localhost,root,,);
8684
CONNECT (conn2,localhost,root,,);

0 commit comments

Comments
 (0)