diff options
author | unknown <kroki/tomash@moonlight.intranet> | 2006-10-30 17:47:02 +0300 |
---|---|---|
committer | unknown <kroki/tomash@moonlight.intranet> | 2006-10-30 17:47:02 +0300 |
commit | 885dc1cb9b7ddbf28ad72c754165a2b87ea79da7 (patch) | |
tree | 65abd4935a132a37425b56d90eea683b5a026f45 /sql | |
parent | 5d46e2993389f3cffe2a37374ba61334f86f7e5e (diff) | |
download | mariadb-git-885dc1cb9b7ddbf28ad72c754165a2b87ea79da7.tar.gz |
BUG#21915: Changing limits of table_cache when setting max_connections
If the user has specified --max-connections=N or --table-open-cache=M
options to the server, a warning could be given that some values were
recalculated, and table-open-cache could be assigned greater value.
Note that both warning and increase of table-open-cache were totally
harmless.
This patch fixes recalculation code to ensure that table-open-cache will
be never increased automatically and that a warning will be given only if
some values had to be decreased due to operating system limits.
No test case is provided because we neither can't predict nor control
operating system limits for maximal number of open files.
sql/mysql_priv.h:
Add constants for table_cache minimum and default values.
sql/mysqld.cc:
Fix max_connections and table_cache_size re-computation.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/mysql_priv.h | 2 | ||||
-rw-r--r-- | sql/mysqld.cc | 42 |
2 files changed, 35 insertions, 9 deletions
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 4a5658c5ccf..c2d378c0be9 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -95,6 +95,8 @@ MY_LOCALE *my_locale_by_name(const char *name); #define MAX_ACCEPT_RETRY 10 // Test accept this many times #define MAX_FIELDS_BEFORE_HASH 32 #define USER_VARS_HASH_SIZE 16 +#define TABLE_OPEN_CACHE_MIN 64 +#define TABLE_OPEN_CACHE_DEFAULT 64 #define STACK_MIN_SIZE 8192 // Abort if less stack during eval. #define STACK_BUFF_ALLOC 64 // For stack overrun checks #ifndef MYSQLD_NET_RETRY_COUNT diff --git a/sql/mysqld.cc b/sql/mysqld.cc index bf83772a8d8..f7b1a2687ea 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2526,19 +2526,43 @@ static int init_common_variables(const char *conf_file_name, int argc, /* connections and databases needs lots of files */ { - uint files, wanted_files; + uint files, wanted_files, max_open_files; - wanted_files= 10+(uint) max(max_connections*5, - max_connections+table_cache_size*2); - set_if_bigger(wanted_files, open_files_limit); - files= my_set_max_open_files(wanted_files); + /* MyISAM requires two file handles per table. */ + wanted_files= 10+max_connections+table_cache_size*2; + /* + We are trying to allocate no less than max_connections*5 file + handles (i.e. we are trying to set the limit so that they will + be available). In addition, we allocate no less than how much + was already allocated. However below we report a warning and + recompute values only if we got less file handles than were + explicitly requested. No warning and re-computation occur if we + can't get max_connections*5 but still got no less than was + requested (value of wanted_files). + */ + max_open_files= max(max(wanted_files, max_connections*5), + open_files_limit); + files= my_set_max_open_files(max_open_files); if (files < wanted_files) { if (!open_files_limit) { - max_connections= (ulong) min((files-10),max_connections); - table_cache_size= (ulong) max((files-10-max_connections)/2,64); + /* + If we have requested too much file handles than we bring + max_connections in supported bounds. + */ + max_connections= (ulong) min(files-10-TABLE_OPEN_CACHE_MIN*2, + max_connections); + /* + Decrease table_cache_size according to max_connections, but + not below TABLE_OPEN_CACHE_MIN. Outer min() ensures that we + never increase table_cache_size automatically (that could + happen if max_connections is decreased above). + */ + table_cache_size= (ulong) min(max((files-10-max_connections)/2, + TABLE_OPEN_CACHE_MIN), + table_cache_size); DBUG_PRINT("warning", ("Changed limits: max_open_files: %u max_connections: %ld table_cache: %ld", files, max_connections, table_cache_size)); @@ -5511,8 +5535,8 @@ The minimum value for this variable is 4096.", 0, 0, 0, 0}, {"table_cache", OPT_TABLE_CACHE, "The number of open tables for all threads.", (gptr*) &table_cache_size, - (gptr*) &table_cache_size, 0, GET_ULONG, REQUIRED_ARG, 64, 1, 512*1024L, - 0, 1, 0}, + (gptr*) &table_cache_size, 0, GET_ULONG, REQUIRED_ARG, + TABLE_OPEN_CACHE_DEFAULT, 1, 512*1024L, 0, 1, 0}, {"thread_cache_size", OPT_THREAD_CACHE_SIZE, "How many threads we should keep in a cache for reuse.", (gptr*) &thread_cache_size, (gptr*) &thread_cache_size, 0, GET_ULONG, |