110
109
static bool get_unsigned64(Session *session, set_var *var);
111
110
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
112
111
const std::string &name, int64_t val);
113
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
114
112
static unsigned char *get_error_count(Session *session);
115
113
static unsigned char *get_warning_count(Session *session);
116
114
static unsigned char *get_tmpdir(Session *session);
1302
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
1304
static KEY_CACHE zero_key_cache;
1306
KEY_CACHE *get_key_cache(const LEX_STRING *cache_name)
1308
safe_mutex_assert_owner(&LOCK_global_system_variables);
1309
if (!cache_name || ! cache_name->length)
1310
cache_name= &default_key_cache_base;
1311
return ((KEY_CACHE*) find_named(&key_caches,
1312
cache_name->str, cache_name->length, 0));
1316
1300
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
1317
const LEX_STRING *base)
1319
KEY_CACHE *key_cache= get_key_cache(base);
1321
key_cache= &zero_key_cache;
1322
return (unsigned char*) key_cache + offset ;
1303
return (unsigned char*) dflt_key_cache + offset ;
1309
static int resize_key_cache_with_lock(KEY_CACHE *key_cache)
1311
assert(key_cache->key_cache_inited);
1313
pthread_mutex_lock(&LOCK_global_system_variables);
1314
long tmp_buff_size= (long) key_cache->param_buff_size;
1315
long tmp_block_size= (long) key_cache->param_block_size;
1316
uint32_t division_limit= key_cache->param_division_limit;
1317
uint32_t age_threshold= key_cache->param_age_threshold;
1318
pthread_mutex_unlock(&LOCK_global_system_variables);
1320
return(!resize_key_cache(key_cache, tmp_block_size,
1322
division_limit, age_threshold));
1326
1327
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1328
1329
uint64_t tmp= var->save_result.uint64_t_value;
1329
LEX_STRING *base_name= &var->base;
1330
1330
KEY_CACHE *key_cache;
1333
/* If no basename, assume it's for the key cache named 'default' */
1334
if (!base_name->length)
1335
base_name= &default_key_cache_base;
1337
1333
pthread_mutex_lock(&LOCK_global_system_variables);
1338
key_cache= get_key_cache(base_name);
1342
/* Key cache didn't exists */
1343
if (!tmp) // Tried to delete cache
1344
goto end; // Ok, nothing to do
1345
if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
1334
key_cache= dflt_key_cache;
1353
1337
Abort if some other thread is changing the key cache
1357
1341
if (key_cache->in_init)
1360
if (!tmp) // Zero size means delete
1344
if (tmp == 0) // Zero size means delete
1362
if (key_cache == dflt_key_cache)
1364
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1365
ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1366
ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1367
goto end; // Ignore default key cache
1370
if (key_cache->key_cache_inited) // If initied
1373
Move tables using this key cache to the default key cache
1374
and clear the old key cache.
1377
key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
1378
base_name->length, &list);
1379
key_cache->in_init= 1;
1380
pthread_mutex_unlock(&LOCK_global_system_variables);
1381
error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
1382
pthread_mutex_lock(&LOCK_global_system_variables);
1383
key_cache->in_init= 0;
1386
We don't delete the key cache as some running threads my still be
1387
in the key cache code with a pointer to the deleted (empty) key cache
1346
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1347
ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1348
ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1349
goto end; // Ignore default key cache
1392
1352
key_cache->param_buff_size=
1396
1356
key_cache->in_init= 1;
1397
1357
pthread_mutex_unlock(&LOCK_global_system_variables);
1399
if (!key_cache->key_cache_inited)
1400
error= (bool) (ha_init_key_cache("", key_cache));
1402
error= (bool)(ha_resize_key_cache(key_cache));
1359
error= (bool)(resize_key_cache_with_lock(key_cache));
1404
1361
pthread_mutex_lock(&LOCK_global_system_variables);
1405
1362
key_cache->in_init= 0;
1419
1376
bool sys_var_key_cache_uint32_t::update(Session *session, set_var *var)
1421
1378
uint64_t tmp= (uint64_t) var->value->val_int();
1422
LEX_STRING *base_name= &var->base;
1425
if (!base_name->length)
1426
base_name= &default_key_cache_base;
1428
1381
pthread_mutex_lock(&LOCK_global_system_variables);
1429
KEY_CACHE *key_cache= get_key_cache(base_name);
1431
if (!key_cache && !(key_cache= create_key_cache(base_name->str,
1432
base_name->length)))
1439
1384
Abort if some other thread is changing the key cache
1440
1385
TODO: This should be changed so that we wait until the previous
1441
1386
assignment is done and then do the new assign
1443
if (key_cache->in_init)
1388
if (dflt_key_cache->in_init)
1446
*((uint32_t*) (((char*) key_cache) + offset))=
1391
*((uint32_t*) (((char*) dflt_key_cache) + offset))=
1447
1392
(uint32_t) fix_unsigned(session, tmp, option_limits);
1450
1395
Don't create a new key cache if it didn't exist
1451
1396
(key_caches are created only when the user sets block_size)
1453
key_cache->in_init= 1;
1398
dflt_key_cache->in_init= 1;
1455
1400
pthread_mutex_unlock(&LOCK_global_system_variables);
1457
error= (bool) (ha_resize_key_cache(key_cache));
1402
error= (bool) (resize_key_cache_with_lock(dflt_key_cache));
1459
1404
pthread_mutex_lock(&LOCK_global_system_variables);
1460
key_cache->in_init= 0;
1405
dflt_key_cache->in_init= 0;
1463
1408
pthread_mutex_unlock(&LOCK_global_system_variables);
1932
NAMED_LIST::NAMED_LIST(I_List<NAMED_LIST> *links, const char *name_arg,
1933
uint32_t name_length_arg, unsigned char* data_arg)
1936
name.assign(name_arg, name_length_arg);
1937
links->push_back(this);
1941
bool NAMED_LIST::cmp(const char *name_cmp, uint32_t length)
1943
return length == name.length() && !name.compare(name_cmp);
1948
1878
Initialize the system variables
2322
2252
/****************************************************************************
2324
****************************************************************************/
2326
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
2329
I_List_iterator<NAMED_LIST> it(*list);
2330
NAMED_LIST *element;
2331
while ((element= it++))
2333
if (element->cmp(name, length))
2337
return element->data;
2344
void delete_elements(I_List<NAMED_LIST> *list,
2345
void (*free_element)(const char *name, unsigned char*))
2347
NAMED_LIST *element;
2348
while ((element= list->get()))
2350
(*free_element)(element->name.c_str(), element->data);
2357
/* Key cache functions */
2359
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
2361
KEY_CACHE *key_cache;
2363
if ((key_cache= (KEY_CACHE*) malloc(sizeof(KEY_CACHE))))
2365
memset(key_cache, 0, sizeof(KEY_CACHE));
2366
if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
2368
free((char*) key_cache);
2374
Set default values for a key cache
2375
The values in dflt_key_cache_var is set by my_getopt() at startup
2377
We don't set 'buff_size' as this is used to enable the key cache
2379
key_cache->param_block_size= dflt_key_cache_var.param_block_size;
2380
key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
2381
key_cache->param_age_threshold= dflt_key_cache_var.param_age_threshold;
2388
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
2390
LEX_STRING key_cache_name;
2391
KEY_CACHE *key_cache;
2393
key_cache_name.str= (char *) name;
2394
key_cache_name.length= length;
2395
pthread_mutex_lock(&LOCK_global_system_variables);
2396
if (!(key_cache= get_key_cache(&key_cache_name)))
2397
key_cache= create_key_cache(name, length);
2398
pthread_mutex_unlock(&LOCK_global_system_variables);
2403
void free_key_cache(const char *, KEY_CACHE *key_cache)
2405
ha_end_key_cache(key_cache);
2406
free((char*) key_cache);
2410
bool process_key_caches(process_key_cache_t func)
2412
I_List_iterator<NAMED_LIST> it(key_caches);
2413
NAMED_LIST *element;
2415
while ((element= it++))
2417
KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
2418
func(element->name.c_str(), key_cache);
2423
/****************************************************************************
2425
2254
****************************************************************************/