Skip to content

Commit 3701c5a

Browse files
committed
BUG#17576516 HOST_CACHE_SIZE VALUE IS IGNORED
Before this fix, starting the server with host_cache_size = N in the my.cnf file had no effect. The internal host cache size was always 128. The root cause is in hostname_cache_init(), which is using 'HOST_CACHE_SIZE' (a #define to 128) instead of 'host_cache_size' (the C global variable that corresponds to the SQL system value named host_cache_size). Overall, the initialization of the host cache is not satisfactory, and needs to be cleaned up. In particular, the fact that there are distinct: - data path (mysqld.cc setting the host_cache_size global variable, to be used by hostname.cc) - control path (mysqld.cc calling hostname_cache_init with no parameters) can only be a source of confusion. This fix: - moves the global variable host_cache_size to mysqld, where it belongs, because this is a server global variable - changes the variable type from ulong to uint, given that the size really is an unsigned int, per hash_filo::m_size - changes hostname_cache_init() to take explicitely a size, for consistency with hostname_cache_resize(), and for a cleaner interface.
1 parent 05d01ee commit 3701c5a

5 files changed

Lines changed: 11 additions & 11 deletions

File tree

sql/hostname.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ void Host_errors::aggregate(const Host_errors *errors)
124124
}
125125

126126
static hash_filo *hostname_cache;
127-
ulong host_cache_size;
128127

129128
void hostname_cache_refresh()
130129
{
@@ -141,12 +140,12 @@ void hostname_cache_resize(uint size)
141140
hostname_cache->resize(size);
142141
}
143142

144-
bool hostname_cache_init()
143+
bool hostname_cache_init(uint size)
145144
{
146145
Host_entry tmp;
147146
uint key_offset= (uint) ((char*) (&tmp.ip_key) - (char*) &tmp);
148147

149-
if (!(hostname_cache= new hash_filo(HOST_CACHE_SIZE,
148+
if (!(hostname_cache= new hash_filo(size,
150149
key_offset, HOST_ENTRY_KEY_SIZE,
151150
NULL, (my_hash_free_key) free,
152151
&my_charset_bin)))

sql/hostname.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2006, 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
@@ -161,9 +161,6 @@ class Host_entry : public hash_filo_element
161161
}
162162
};
163163

164-
/** The size of the host_cache. */
165-
extern ulong host_cache_size;
166-
167164
#define RC_OK 0
168165
#define RC_BLOCKED_HOST 1
169166
int ip_to_hostname(struct sockaddr_storage *ip_storage,
@@ -172,7 +169,7 @@ int ip_to_hostname(struct sockaddr_storage *ip_storage,
172169

173170
void inc_host_errors(const char *ip_string, Host_errors *errors);
174171
void reset_host_connect_errors(const char *ip_string);
175-
bool hostname_cache_init();
172+
bool hostname_cache_init(uint size);
176173
void hostname_cache_free();
177174
void hostname_cache_refresh(void);
178175
uint hostname_cache_size();

sql/mysqld.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ bool opt_using_transactions;
399399
bool volatile abort_loop;
400400
bool volatile shutdown_in_progress;
401401
ulong log_warnings;
402+
uint host_cache_size;
403+
402404
#if defined(_WIN32) && !defined(EMBEDDED_LIBRARY)
403405
ulong slow_start_timeout;
404406
#endif
@@ -4590,7 +4592,7 @@ static int init_server_components()
45904592
all things are initialized so that unireg_abort() doesn't fail
45914593
*/
45924594
mdl_init();
4593-
if (table_def_init() | hostname_cache_init())
4595+
if (table_def_init() | hostname_cache_init(host_cache_size))
45944596
unireg_abort(1);
45954597

45964598
query_cache_set_min_res_unit(query_cache_min_res_unit);

sql/mysqld.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ extern ulong connection_errors_internal;
284284
extern ulong connection_errors_max_connection;
285285
extern ulong connection_errors_peer_addr;
286286
extern ulong log_warnings;
287+
/** The size of the host_cache. */
288+
extern uint host_cache_size;
287289
void init_sql_statement_names();
288290

289291
/*

sql/sys_vars.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4175,11 +4175,11 @@ static Sys_var_tz Sys_time_zone(
41754175

41764176
static bool fix_host_cache_size(sys_var *, THD *, enum_var_type)
41774177
{
4178-
hostname_cache_resize((uint) host_cache_size);
4178+
hostname_cache_resize(host_cache_size);
41794179
return false;
41804180
}
41814181

4182-
static Sys_var_ulong Sys_host_cache_size(
4182+
static Sys_var_uint Sys_host_cache_size(
41834183
"host_cache_size",
41844184
"How many host names should be cached to avoid resolving.",
41854185
GLOBAL_VAR(host_cache_size),

0 commit comments

Comments
 (0)