111
110
static bool get_unsigned64(Session *session, set_var *var);
112
111
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
113
112
const std::string &name, int64_t val);
114
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
115
113
static unsigned char *get_error_count(Session *session);
116
114
static unsigned char *get_warning_count(Session *session);
117
115
static unsigned char *get_tmpdir(Session *session);
1303
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
1305
static KEY_CACHE zero_key_cache;
1307
KEY_CACHE *get_key_cache(const LEX_STRING *cache_name)
1309
safe_mutex_assert_owner(&LOCK_global_system_variables);
1310
if (!cache_name || ! cache_name->length)
1311
cache_name= &default_key_cache_base;
1312
return ((KEY_CACHE*) find_named(&key_caches,
1313
cache_name->str, cache_name->length, 0));
1317
1301
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
1318
const LEX_STRING *base)
1320
KEY_CACHE *key_cache= get_key_cache(base);
1322
key_cache= &zero_key_cache;
1323
return (unsigned char*) key_cache + offset ;
1304
return (unsigned char*) dflt_key_cache + offset ;
1310
static int resize_key_cache_with_lock(KEY_CACHE *key_cache)
1312
assert(key_cache->key_cache_inited);
1314
pthread_mutex_lock(&LOCK_global_system_variables);
1315
long tmp_buff_size= (long) key_cache->param_buff_size;
1316
long tmp_block_size= (long) key_cache->param_block_size;
1317
uint32_t division_limit= key_cache->param_division_limit;
1318
uint32_t age_threshold= key_cache->param_age_threshold;
1319
pthread_mutex_unlock(&LOCK_global_system_variables);
1321
return(!resize_key_cache(key_cache, tmp_block_size,
1323
division_limit, age_threshold));
1327
1328
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1329
1330
uint64_t tmp= var->save_result.uint64_t_value;
1330
LEX_STRING *base_name= &var->base;
1331
1331
KEY_CACHE *key_cache;
1334
/* If no basename, assume it's for the key cache named 'default' */
1335
if (!base_name->length)
1336
base_name= &default_key_cache_base;
1338
1334
pthread_mutex_lock(&LOCK_global_system_variables);
1339
key_cache= get_key_cache(base_name);
1343
/* Key cache didn't exists */
1344
if (!tmp) // Tried to delete cache
1345
goto end; // Ok, nothing to do
1346
if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
1335
key_cache= dflt_key_cache;
1354
1338
Abort if some other thread is changing the key cache
1358
1342
if (key_cache->in_init)
1361
if (!tmp) // Zero size means delete
1345
if (tmp == 0) // Zero size means delete
1363
if (key_cache == dflt_key_cache)
1365
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1366
ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1367
ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1368
goto end; // Ignore default key cache
1371
if (key_cache->key_cache_inited) // If initied
1374
Move tables using this key cache to the default key cache
1375
and clear the old key cache.
1378
key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
1379
base_name->length, &list);
1380
key_cache->in_init= 1;
1381
pthread_mutex_unlock(&LOCK_global_system_variables);
1382
error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
1383
pthread_mutex_lock(&LOCK_global_system_variables);
1384
key_cache->in_init= 0;
1387
We don't delete the key cache as some running threads my still be
1388
in the key cache code with a pointer to the deleted (empty) key cache
1347
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1348
ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1349
ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1350
goto end; // Ignore default key cache
1393
1353
key_cache->param_buff_size=
1397
1357
key_cache->in_init= 1;
1398
1358
pthread_mutex_unlock(&LOCK_global_system_variables);
1400
if (!key_cache->key_cache_inited)
1401
error= (bool) (ha_init_key_cache("", key_cache));
1403
error= (bool)(ha_resize_key_cache(key_cache));
1360
error= (bool)(resize_key_cache_with_lock(key_cache));
1405
1362
pthread_mutex_lock(&LOCK_global_system_variables);
1406
1363
key_cache->in_init= 0;
1420
1377
bool sys_var_key_cache_uint32_t::update(Session *session, set_var *var)
1422
1379
uint64_t tmp= (uint64_t) var->value->val_int();
1423
LEX_STRING *base_name= &var->base;
1426
if (!base_name->length)
1427
base_name= &default_key_cache_base;
1429
1382
pthread_mutex_lock(&LOCK_global_system_variables);
1430
KEY_CACHE *key_cache= get_key_cache(base_name);
1432
if (!key_cache && !(key_cache= create_key_cache(base_name->str,
1433
base_name->length)))
1440
1385
Abort if some other thread is changing the key cache
1441
1386
TODO: This should be changed so that we wait until the previous
1442
1387
assignment is done and then do the new assign
1444
if (key_cache->in_init)
1389
if (dflt_key_cache->in_init)
1447
*((uint32_t*) (((char*) key_cache) + offset))=
1392
*((uint32_t*) (((char*) dflt_key_cache) + offset))=
1448
1393
(uint32_t) fix_unsigned(session, tmp, option_limits);
1451
1396
Don't create a new key cache if it didn't exist
1452
1397
(key_caches are created only when the user sets block_size)
1454
key_cache->in_init= 1;
1399
dflt_key_cache->in_init= 1;
1456
1401
pthread_mutex_unlock(&LOCK_global_system_variables);
1458
error= (bool) (ha_resize_key_cache(key_cache));
1403
error= (bool) (resize_key_cache_with_lock(dflt_key_cache));
1460
1405
pthread_mutex_lock(&LOCK_global_system_variables);
1461
key_cache->in_init= 0;
1406
dflt_key_cache->in_init= 0;
1464
1409
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
****************************************************************************/