Skip to content

Commit a241d41

Browse files
committed
MDEV-18027: Running out of file descriptors and eventual crash
For automatic number of opened files limit take into account number of table instances for table cache
1 parent a9d1324 commit a241d41

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

mysql-test/r/mysqld--help.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ sysdate-is-now FALSE
15191519
table-cache 421
15201520
table-definition-cache 400
15211521
table-open-cache 421
1522-
table-open-cache-instances 8
1522+
table-open-cache-instances 1
15231523
tc-heuristic-recover OFF
15241524
thread-cache-size 151
15251525
thread-pool-idle-timeout 60
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
select @@global.host_cache_size;
22
@@global.host_cache_size
3-
632
3+
653

sql/mysqld.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4432,7 +4432,7 @@ static int init_common_variables()
44324432
min_connections= 10;
44334433
/* MyISAM requires two file handles per table. */
44344434
wanted_files= (extra_files + max_connections + extra_max_connections +
4435-
tc_size * 2);
4435+
tc_size * 2 * tc_instances);
44364436
#if defined(HAVE_POOL_OF_THREADS) && !defined(__WIN__)
44374437
// add epoll or kevent fd for each threadpool group, in case pool of threads is used
44384438
wanted_files+= (thread_handling > SCHEDULER_NO_THREADS) ? 0 : threadpool_size;
@@ -4461,14 +4461,22 @@ static int init_common_variables()
44614461
if (files < wanted_files && global_system_variables.log_warnings)
44624462
sql_print_warning("Could not increase number of max_open_files to more than %u (request: %u)", files, wanted_files);
44634463

4464+
/* If we required too much tc_instances than we reduce */
4465+
SYSVAR_AUTOSIZE_IF_CHANGED(tc_instances,
4466+
(uint32) MY_MIN(MY_MAX((files - extra_files -
4467+
max_connections)/
4468+
2/tc_size,
4469+
1),
4470+
tc_instances),
4471+
uint32);
44644472
/*
44654473
If we have requested too much file handles than we bring
44664474
max_connections in supported bounds. Still leave at least
44674475
'min_connections' connections
44684476
*/
44694477
SYSVAR_AUTOSIZE_IF_CHANGED(max_connections,
44704478
(ulong) MY_MAX(MY_MIN(files- extra_files-
4471-
min_tc_size*2,
4479+
min_tc_size*2*tc_instances,
44724480
max_connections),
44734481
min_connections),
44744482
ulong);
@@ -4481,7 +4489,7 @@ static int init_common_variables()
44814489
*/
44824490
SYSVAR_AUTOSIZE_IF_CHANGED(tc_size,
44834491
(ulong) MY_MIN(MY_MAX((files - extra_files -
4484-
max_connections) / 2,
4492+
max_connections) / 2 / tc_instances,
44854493
min_tc_size),
44864494
tc_size), ulong);
44874495
DBUG_PRINT("warning",

0 commit comments

Comments
 (0)