1
/* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software Foundation,
14
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
16
#include "keycaches.h"
18
/****************************************************************************
20
****************************************************************************/
22
NAMED_ILIST key_caches;
24
uchar* find_named(I_List<NAMED_ILINK> *list, const char *name, uint length,
27
I_List_iterator<NAMED_ILINK> it(*list);
29
while ((element= it++))
31
if (element->cmp(name, length))
42
void NAMED_ILIST::delete_elements(void (*free_element)(const char *name, uchar*))
45
DBUG_ENTER("NAMED_ILIST::delete_elements");
46
while ((element= get()))
48
(*free_element)(element->name, element->data);
55
/* Key cache functions */
57
LEX_STRING default_key_cache_base= {C_STRING_WITH_LEN("default")};
59
KEY_CACHE zero_key_cache; ///< @@nonexistent_cache.param->value_ptr() points here
61
KEY_CACHE *get_key_cache(LEX_STRING *cache_name)
63
if (!cache_name || ! cache_name->length)
64
cache_name= &default_key_cache_base;
65
return ((KEY_CACHE*) find_named(&key_caches,
66
cache_name->str, cache_name->length, 0));
69
KEY_CACHE *create_key_cache(const char *name, uint length)
72
DBUG_ENTER("create_key_cache");
73
DBUG_PRINT("enter",("name: %.*s", length, name));
75
if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
76
MYF(MY_ZEROFILL | MY_WME))))
78
if (!new NAMED_ILINK(&key_caches, name, length, (uchar*) key_cache))
86
Set default values for a key cache
87
The values in dflt_key_cache_var is set by my_getopt() at startup
89
We don't set 'buff_size' as this is used to enable the key cache
91
key_cache->param_block_size= dflt_key_cache_var.param_block_size;
92
key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
93
key_cache->param_age_threshold= dflt_key_cache_var.param_age_threshold;
96
DBUG_RETURN(key_cache);
100
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
102
LEX_STRING key_cache_name;
103
KEY_CACHE *key_cache;
105
key_cache_name.str= (char *) name;
106
key_cache_name.length= length;
107
if (!(key_cache= get_key_cache(&key_cache_name)))
108
key_cache= create_key_cache(name, length);
113
void free_key_cache(const char *name, KEY_CACHE *key_cache)
115
end_key_cache(key_cache, 1); // Can never fail
120
bool process_key_caches(process_key_cache_t func)
122
I_List_iterator<NAMED_ILINK> it(key_caches);
123
NAMED_ILINK *element;
125
while ((element= it++))
127
KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
128
func(element->name, key_cache);