diff options
Diffstat (limited to 'sql/set_var.cc')
-rw-r--r-- | sql/set_var.cc | 176 |
1 files changed, 174 insertions, 2 deletions
diff --git a/sql/set_var.cc b/sql/set_var.cc index 2d40cb67bab..04c80576887 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -153,6 +153,9 @@ static void fix_thd_mem_root(THD *thd, enum_var_type type); static void fix_trans_mem_root(THD *thd, enum_var_type type); static void fix_server_id(THD *thd, enum_var_type type); static KEY_CACHE *create_key_cache(const char *name, uint length); +#ifdef WITH_MARIA_STORAGE_ENGINE +static PAGECACHE *create_pagecache(const char *name, uint length); +#endif /* WITH_MARIA_STORAGE_ENGINE */ void fix_sql_mode_var(THD *thd, enum_var_type type); static byte *get_error_count(THD *thd); static byte *get_warning_count(THD *thd); @@ -255,6 +258,14 @@ sys_var_key_cache_long sys_key_cache_division_limit("key_cache_division_limit", sys_var_key_cache_long sys_key_cache_age_threshold("key_cache_age_threshold", offsetof(KEY_CACHE, param_age_threshold)); +#ifdef WITH_MARIA_STORAGE_ENGINE +sys_var_pagecache_long sys_pagecache_division_limit("pagecache_division_limit", + offsetof(PAGECACHE, + param_division_limit)); +sys_var_pagecache_long sys_pagecache_age_threshold("pagecache_age_threshold", + offsetof(KEY_CACHE, + param_age_threshold)); +#endif /* WITH_MARIA_STORAGE_ENGINE */ sys_var_bool_ptr sys_local_infile("local_infile", &opt_local_infile); sys_var_trust_routine_creators @@ -859,6 +870,12 @@ SHOW_VAR init_vars[]= { SHOW_SYS}, {sys_key_cache_division_limit.name, (char*) &sys_key_cache_division_limit, SHOW_SYS}, +#ifdef WITH_MARIA_STORAGE_ENGINE + {sys_pagecache_age_threshold.name, (char*) &sys_pagecache_age_threshold, + SHOW_SYS}, + {sys_pagecache_division_limit.name, (char*) &sys_pagecache_division_limit, + SHOW_SYS}, +#endif /* WITH_MARIA_STORAGE_ENGINE */ {"language", language, SHOW_CHAR}, {"large_files_support", (char*) &opt_large_files, SHOW_BOOL}, {"large_page_size", (char*) &opt_large_page_size, SHOW_INT}, @@ -2397,10 +2414,13 @@ void sys_var_collation_server::set_default(THD *thd, enum_var_type type) LEX_STRING default_key_cache_base= {(char *) "default", 7 }; -LEX_STRING maria_key_cache_base= {(char *) "maria", 5 }; - static KEY_CACHE zero_key_cache; +#ifdef WITH_MARIA_STORAGE_ENGINE +LEX_STRING maria_pagecache_base= {(char *) "default", 7 }; +static PAGECACHE zero_pagecache; +#endif /* WITH_MARIA_STORAGE_ENGINE */ + KEY_CACHE *get_key_cache(LEX_STRING *cache_name) { safe_mutex_assert_owner(&LOCK_global_system_variables); @@ -2411,6 +2431,18 @@ KEY_CACHE *get_key_cache(LEX_STRING *cache_name) } +#ifdef WITH_MARIA_STORAGE_ENGINE +PAGECACHE *get_pagecache(LEX_STRING *cache_name) +{ + safe_mutex_assert_owner(&LOCK_global_system_variables); + if (!cache_name || ! cache_name->length) + cache_name= &default_key_cache_base; + return ((PAGECACHE*) find_named(&pagecaches, + cache_name->str, cache_name->length, 0)); +} +#endif /* WITH_MARIA_STORAGE_ENGINE */ + + byte *sys_var_key_cache_param::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base) { @@ -2421,6 +2453,18 @@ byte *sys_var_key_cache_param::value_ptr(THD *thd, enum_var_type type, } +#ifdef WITH_MARIA_STORAGE_ENGINE +byte *sys_var_pagecache_param::value_ptr(THD *thd, enum_var_type type, + LEX_STRING *base) +{ + PAGECACHE *pagecache= get_pagecache(base); + if (!pagecache) + pagecache= &zero_pagecache; + return (byte*) pagecache + offset ; +} +#endif /* WITH_MARIA_STORAGE_ENGINE */ + + bool sys_var_key_buffer_size::update(THD *thd, set_var *var) { ulonglong tmp= var->save_result.ulonglong_value; @@ -2557,6 +2601,60 @@ end: } +#ifdef WITH_MARIA_STORAGE_ENGINE +bool sys_var_pagecache_long::update(THD *thd, set_var *var) +{ + ulong tmp= (ulong) var->value->val_int(); + LEX_STRING *base_name= &var->base; + bool error= 0; + + if (!base_name->length) + base_name= &maria_pagecache_base; + + pthread_mutex_lock(&LOCK_global_system_variables); + PAGECACHE *pagecache= get_pagecache(base_name); + + if (!pagecache && !(pagecache= create_pagecache(base_name->str, + base_name->length))) + { + error= 1; + goto end; + } + + /* + Abort if some other thread is changing the key cache + TODO: This should be changed so that we wait until the previous + assignment is done and then do the new assign + */ + if (pagecache->in_init) + goto end; + + *((ulong*) (((char*) pagecache) + offset))= + (ulong) getopt_ull_limit_value(tmp, option_limits); + + /* + Don't create a new key cache if it didn't exist + (pagecaches are created only when the user sets block_size) + */ + pagecache->in_init= 1; + + pthread_mutex_unlock(&LOCK_global_system_variables); + + /* + TODO: uncomment whan it will be implemented + error= (bool) (ha_resize_pagecache(pagecache)); + */ + + pthread_mutex_lock(&LOCK_global_system_variables); + pagecache->in_init= 0; + +end: + pthread_mutex_unlock(&LOCK_global_system_variables); + return error; +} +#endif /* WITH_MARIA_STORAGE_ENGINE */ + + bool sys_var_log_state::update(THD *thd, set_var *var) { bool res= 0; @@ -3895,12 +3993,86 @@ bool process_key_caches(int (* func) (const char *name, KEY_CACHE *)) } +#ifdef WITH_MARIA_STORAGE_ENGINE + +static PAGECACHE *create_pagecache(const char *name, uint length) +{ + PAGECACHE *pagecache; + DBUG_ENTER("create_pagecache"); + DBUG_PRINT("enter",("name: %.*s", length, name)); + + if ((pagecache= (PAGECACHE*) my_malloc(sizeof(PAGECACHE), + MYF(MY_ZEROFILL | MY_WME)))) + { + if (!new NAMED_LIST(&pagecaches, name, length, (gptr) pagecache)) + { + my_free((char*) pagecache, MYF(0)); + pagecache= 0; + } + else + { + /* + Set default values for a key cache + The values in dflt_pagecache_var is set by my_getopt() at startup + We don't set 'buff_size' as this is used to enable the key cache + */ + pagecache->param_buff_size= (dflt_pagecache_var.param_buff_size ? + dflt_pagecache_var.param_buff_size: + KEY_CACHE_SIZE); + pagecache->param_block_size= dflt_pagecache_var.param_block_size; + pagecache->param_division_limit= dflt_pagecache_var.param_division_limit; + pagecache->param_age_threshold= dflt_pagecache_var.param_age_threshold; + } + } + DBUG_RETURN(pagecache); +} + + +PAGECACHE *get_or_create_pagecache(const char *name, uint length) +{ + LEX_STRING pagecache_name; + PAGECACHE *pagecache; + + pagecache_name.str= (char *) name; + pagecache_name.length= length; + pthread_mutex_lock(&LOCK_global_system_variables); + if (!(pagecache= get_pagecache(&pagecache_name))) + pagecache= create_pagecache(name, length); + pthread_mutex_unlock(&LOCK_global_system_variables); + return pagecache; +} + + +void free_pagecache(const char *name, PAGECACHE *pagecache) +{ + ha_end_pagecache(pagecache); + my_free((char*) pagecache, MYF(0)); +} + + +bool process_pagecaches(int (* func) (const char *name, PAGECACHE *)) +{ + I_List_iterator<NAMED_LIST> it(pagecaches); + NAMED_LIST *element; + + while ((element= it++)) + { + PAGECACHE *pagecache= (PAGECACHE *) element->data; + func(element->name, pagecache); + } + return 0; +} + +#endif /* WITH_MARIA_STORAGE_ENGINE */ + + void sys_var_trust_routine_creators::warn_deprecated(THD *thd) { WARN_DEPRECATED(thd, "5.2", "log_bin_trust_routine_creators", "'log_bin_trust_function_creators'"); } + void sys_var_trust_routine_creators::set_default(THD *thd, enum_var_type type) { warn_deprecated(thd); |