Skip to content

Commit 49562aa

Browse files
author
Mattias Jonsson
committed
Bug#16657588: VARIABLE OPEN_FILES_LIMIT DOES NOT
SHOW MAXIMUM NUMBER OF OPEN FILES The read-only system variable open_files_limit did not show maximum number of open files the mysqld process could have, but instead the number that was requested after adjusting the start-up option open_files_limit. Fixed by adding internal variable for propagating the requested number of files, since that was used for adjusting other start-up options. And set the read-only system variable open_files_limit to the real maximum value.
1 parent b446584 commit 49562aa

13 files changed

+62
-59
lines changed

libmysqld/lib_sql.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ int init_embedded_server(int argc, char **argv, char **groups)
566566
return 1;
567567
}
568568

569-
adjust_related_options();
569+
ulong requested_open_files_dummy;
570+
adjust_related_options(&requested_open_files_dummy);
570571

571572
if (init_common_variables())
572573
{

mysql-test/r/partition_open_files_limit.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CREATE TABLE t1 (a INT PRIMARY KEY)
44
ENGINE=MyISAM PARTITION BY KEY () PARTITIONS 1;
55
INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11);
66
# if the bug exists, then crash will happen here
7-
ALTER TABLE t1 ADD PARTITION PARTITIONS 5001;
7+
ALTER TABLE t1 ADD PARTITION PARTITIONS 600;
88
ERROR HY000: Out of resources when opening file '<partition file>' (Errcode: 24 - Too many open files)
99
SELECT * FROM t1;
1010
a

mysql-test/suite/perfschema/include/sizing_auto.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
show variables like "table_definition_cache";
33
show variables like "table_open_cache";
44
show variables like "max_connections";
5-
show variables like "open_files_limit";
5+
# open_files_limit depends on OS configuration (ulimit -n)
6+
#show variables like "open_files_limit";
67
show variables like "%performance_schema%";
78
show status like "%performance_schema%";
89

mysql-test/suite/perfschema/r/sizing_default.result

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ table_open_cache 2000
77
show variables like "max_connections";
88
Variable_name Value
99
max_connections 151
10-
show variables like "open_files_limit";
11-
Variable_name Value
12-
open_files_limit 5000
1310
show variables like "%performance_schema%";
1411
Variable_name Value
1512
performance_schema ON

mysql-test/suite/perfschema/r/sizing_high.result

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ table_open_cache 400
77
show variables like "max_connections";
88
Variable_name Value
99
max_connections 200
10-
show variables like "open_files_limit";
11-
Variable_name Value
12-
open_files_limit 1024
1310
show variables like "%performance_schema%";
1411
Variable_name Value
1512
performance_schema ON

mysql-test/suite/perfschema/r/sizing_low.result

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ table_open_cache 100
77
show variables like "max_connections";
88
Variable_name Value
99
max_connections 50
10-
show variables like "open_files_limit";
11-
Variable_name Value
12-
open_files_limit 1024
1310
show variables like "%performance_schema%";
1411
Variable_name Value
1512
performance_schema ON

mysql-test/suite/perfschema/r/sizing_med.result

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ table_open_cache 401
77
show variables like "max_connections";
88
Variable_name Value
99
max_connections 152
10-
show variables like "open_files_limit";
11-
Variable_name Value
12-
open_files_limit 1024
1310
show variables like "%performance_schema%";
1411
Variable_name Value
1512
performance_schema ON

mysql-test/suite/perfschema/t/sizing_default.cnf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# table_open_cache = 2000
1212
# table_definition_cache = 400 + 2000/2 = 1400
1313
# max_connections = 151
14-
# open_files_limit = 5000
1514

1615
# Automated sizing for everything
1716

mysql-test/suite/perfschema/t/sizing_default.test

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,26 @@
55
--source include/not_valgrind.inc
66
--source ../include/have_aligned_memory.inc
77

8-
# For this test to work,
9-
# open_files_limit should not be scaled down by OS limitations.
10-
let $max_open_files_limit= `SELECT @@open_files_limit != 5000`;
8+
# Skip test if not defaults is used.
9+
let $max_open_files_limit= `SELECT @@open_files_limit < 5000`;
1110
if ($max_open_files_limit)
1211
{
13-
skip Need open_files_limit to be exactly 5000;
12+
skip Need open_files_limit to be at least 5000;
13+
}
14+
let $max_table_open_cache= `SELECT @@table_open_cache != 2000`;
15+
if ($max_table_open_cache)
16+
{
17+
skip Need table_open_cache to be exactly 2000;
18+
}
19+
let $max_table_definition_cache= `SELECT @@table_definition_cache != 1400`;
20+
if ($max_table_definition_cache)
21+
{
22+
skip Need table_definition_cache to be exactly 1400;
23+
}
24+
let $max_connections= `SELECT @@max_connections != 151`;
25+
if ($max_connections)
26+
{
27+
skip Need max_connections to be exactly 151;
1428
}
1529

1630
--source ../include/sizing_auto.inc

mysql-test/t/disabled.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ ds_mrr-big @solaris : Bug#14168107 2012-04-03 Hemant disabled new test adde
1818
partition_locking_4 : Bug#13924750 2012-04-04 lost connection.
1919
mysql_embedded_client_test : Bug#13964673 2012-04-16 amitbha since most of the test cases are failing
2020
mysql_client_test_embedded : Bug#16084066 2013-01-08 Disabled since this test is failing
21-
partition_open_files_limit : Bug#16553132 2013-03-26 TEST FAILURE IN MAIN.PARTITION_OPEN_FILES_LIMIT

mysql-test/t/partition_open_files_limit.test

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,30 @@ DROP TABLE IF EXISTS `t1`;
55
--enable_warnings
66

77
# On some platforms the lowest possible open_files_limit is too high...
8-
let $max_open_files_limit= `SELECT @@open_files_limit > 511`;
8+
let $max_open_files_limit= `SELECT @@open_files_limit > 1024`;
99
if ($max_open_files_limit)
1010
{
11-
skip Need open_files_limit to be lower than 512;
11+
skip Need open_files_limit to be lower than 1025;
1212
}
1313

1414
#
1515
--echo # Bug#46922: crash when adding partitions and open_files_limit is reached
1616
#
1717
# Note:
1818
# The test script ask for open_files_limit=5
19-
# The server silently increase that to 5000 before asking the OS
20-
# The OS may (or may not) reduce open_files_limit, typically to 1024
19+
# The server silently increase that to 5000 before asking the OS.
20+
# The OS may (or may not) reduce/increase open_files_limit, typically to 1024
21+
# (Linux, see 'ulimit -n')
2122
# So, for the ADD PARTITIONS to really reach the 'Too many open files'
22-
# error, the test script attempts 5001 partitions, will likely fail earlier
23-
# The statement may still pass without errors,
24-
# if the OS limit is much higher (unlikely, causing a test failure).
23+
# error, the test script attempts 600 partitions.
2524
#
2625
CREATE TABLE t1 (a INT PRIMARY KEY)
2726
ENGINE=MyISAM PARTITION BY KEY () PARTITIONS 1;
2827
INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11);
2928
--echo # if the bug exists, then crash will happen here
3029
--replace_regex /file '.*'/file '<partition file>'/
3130
--error 23
32-
ALTER TABLE t1 ADD PARTITION PARTITIONS 5001;
31+
ALTER TABLE t1 ADD PARTITION PARTITIONS 600;
3332
--sorted_result
3433
SELECT * FROM t1;
3534
DROP TABLE t1;

sql/mysqld.cc

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5118,27 +5118,29 @@ int mysqld_main(int argc, char **argv)
51185118

51195119
ho_error= handle_early_options();
51205120

5121-
adjust_related_options();
5121+
{
5122+
ulong requested_open_files;
5123+
adjust_related_options(&requested_open_files);
51225124

51235125
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
5124-
if (ho_error == 0)
5125-
{
5126-
if (pfs_param.m_enabled && !opt_help && !opt_bootstrap)
5126+
if (ho_error == 0)
51275127
{
5128-
/* Add sizing hints from the server sizing parameters. */
5129-
pfs_param.m_hints.m_table_definition_cache= table_def_size;
5130-
pfs_param.m_hints.m_table_open_cache= table_cache_size;
5131-
pfs_param.m_hints.m_max_connections= max_connections;
5132-
pfs_param.m_hints.m_open_files_limit= open_files_limit;
5133-
PSI_hook= initialize_performance_schema(&pfs_param);
5134-
if (PSI_hook == NULL)
5128+
if (pfs_param.m_enabled && !opt_help && !opt_bootstrap)
51355129
{
5136-
pfs_param.m_enabled= false;
5137-
buffered_logs.buffer(WARNING_LEVEL,
5138-
"Performance schema disabled (reason: init failed).");
5130+
/* Add sizing hints from the server sizing parameters. */
5131+
pfs_param.m_hints.m_table_definition_cache= table_def_size;
5132+
pfs_param.m_hints.m_table_open_cache= table_cache_size;
5133+
pfs_param.m_hints.m_max_connections= max_connections;
5134+
pfs_param.m_hints.m_open_files_limit= requested_open_files;
5135+
PSI_hook= initialize_performance_schema(&pfs_param);
5136+
if (PSI_hook == NULL)
5137+
{
5138+
pfs_param.m_enabled= false;
5139+
buffered_logs.buffer(WARNING_LEVEL,
5140+
"Performance schema disabled (reason: init failed).");
5141+
}
51395142
}
51405143
}
5141-
}
51425144
#else
51435145
/*
51445146
Other provider of the instrumentation interface should
@@ -5150,6 +5152,7 @@ int mysqld_main(int argc, char **argv)
51505152
these two defines are kept separate.
51515153
*/
51525154
#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
5155+
}
51535156

51545157
#ifdef HAVE_PSI_INTERFACE
51555158
/*
@@ -6720,7 +6723,7 @@ int handle_early_options()
67206723
- @c table_cache_size,
67216724
- the platform max open file limit.
67226725
*/
6723-
void adjust_open_files_limit()
6726+
void adjust_open_files_limit(ulong *requested_open_files)
67246727
{
67256728
ulong limit_1;
67266729
ulong limit_2;
@@ -6743,12 +6746,9 @@ void adjust_open_files_limit()
67436746

67446747
request_open_files= max<ulong>(max<ulong>(limit_1, limit_2), limit_3);
67456748

6749+
/* Notice: my_set_max_open_files() may return more than requested. */
67466750
effective_open_files= my_set_max_open_files(request_open_files);
67476751

6748-
/* Warning: my_set_max_open_files() may return more than requested. */
6749-
if (effective_open_files > request_open_files)
6750-
effective_open_files= request_open_files;
6751-
67526752
if (effective_open_files < request_open_files)
67536753
{
67546754
char msg[1024];
@@ -6771,13 +6771,15 @@ void adjust_open_files_limit()
67716771
}
67726772

67736773
open_files_limit= effective_open_files;
6774+
if (requested_open_files)
6775+
*requested_open_files= min<ulong>(effective_open_files, request_open_files);
67746776
}
67756777

6776-
void adjust_max_connections()
6778+
void adjust_max_connections(ulong requested_open_files)
67776779
{
67786780
ulong limit;
67796781

6780-
limit= open_files_limit - 10 - TABLE_OPEN_CACHE_MIN * 2;
6782+
limit= requested_open_files - 10 - TABLE_OPEN_CACHE_MIN * 2;
67816783

67826784
if (limit < max_connections)
67836785
{
@@ -6792,11 +6794,11 @@ void adjust_max_connections()
67926794
}
67936795
}
67946796

6795-
void adjust_table_cache_size()
6797+
void adjust_table_cache_size(ulong requested_open_files)
67966798
{
67976799
ulong limit;
67986800

6799-
limit= max<ulong>((open_files_limit - 10 - max_connections) / 2,
6801+
limit= max<ulong>((requested_open_files - 10 - max_connections) / 2,
68006802
TABLE_OPEN_CACHE_MIN);
68016803

68026804
if (limit < table_cache_size)
@@ -6828,16 +6830,16 @@ void adjust_table_def_size()
68286830
table_def_size= default_value;
68296831
}
68306832

6831-
void adjust_related_options()
6833+
void adjust_related_options(ulong *requested_open_files)
68326834
{
68336835
/* In bootstrap, disable grant tables (we are about to create them) */
68346836
if (opt_bootstrap)
68356837
opt_noacl= 1;
68366838

68376839
/* The order is critical here, because of dependencies. */
6838-
adjust_open_files_limit();
6839-
adjust_max_connections();
6840-
adjust_table_cache_size();
6840+
adjust_open_files_limit(requested_open_files);
6841+
adjust_max_connections(*requested_open_files);
6842+
adjust_table_cache_size(*requested_open_files);
68416843
adjust_table_def_size();
68426844
}
68436845

sql/mysqld.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -264,7 +264,7 @@ extern const char *load_default_groups[];
264264
extern struct my_option my_long_options[];
265265
extern struct my_option my_long_early_options[];
266266
int handle_early_options();
267-
void adjust_related_options();
267+
void adjust_related_options(ulong *requested_open_files);
268268
extern int mysqld_server_started;
269269
extern "C" MYSQL_PLUGIN_IMPORT int orig_argc;
270270
extern "C" MYSQL_PLUGIN_IMPORT char **orig_argv;

0 commit comments

Comments
 (0)