diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2019-03-15 11:52:26 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2019-05-03 14:14:27 +0400 |
commit | 2be28a91b15010c5e6146e78e78fbe10a9b86153 (patch) | |
tree | 7011f81fb604bdba5c6da4a7859f50fb306cbad4 /sql | |
parent | 19d5ddccfde04c6b336bb4974407ecde4fb6fbc6 (diff) | |
download | mariadb-git-2be28a91b15010c5e6146e78e78fbe10a9b86153.tar.gz |
Cleanup session tracker API
- Session_sysvars_tracker::server_init_check() -> sysvartrack_validate_value()
- Session_sysvars_tracker::check_var_list() -> sysvartrack_validate_value()
- Session_sysvars_tracker::server_init_process() -> sysvartrack_global_update()
- sysvartrack_reprint_value() -> sysvartrack_global_update()
- sysvartrack_value_len() -> sysvartrack_session_value_ptr()
- sysvartrack_value_construct() -> sysvartrack_session_value_ptr()
- sysvartrack_update() -> Session_sysvars_tracker::update()
- Session_tracker::server_boot_verify() -> session_tracker_init()
- sysvar_tracker() -> /dev/null
Part of MDEV-14984 - regression in connect performance
Diffstat (limited to 'sql')
-rw-r--r-- | sql/mysqld.cc | 10 | ||||
-rw-r--r-- | sql/session_tracker.cc | 136 | ||||
-rw-r--r-- | sql/session_tracker.h | 9 | ||||
-rw-r--r-- | sql/sys_vars.ic | 18 |
4 files changed, 56 insertions, 117 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f0ffa7eae8c..73dd7ce36af 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5420,14 +5420,8 @@ static int init_server_components() #endif #ifndef EMBEDDED_LIBRARY - { - if (Session_tracker::server_boot_verify(system_charset_info)) - { - sql_print_error("The variable session_track_system_variables has " - "invalid values."); - unireg_abort(1); - } - } + if (session_tracker_init()) + return 1; #endif //EMBEDDED_LIBRARY /* we do want to exit if there are any other unknown options */ diff --git a/sql/session_tracker.cc b/sql/session_tracker.cc index 14fc43e09e7..7908c083446 100644 --- a/sql/session_tracker.cc +++ b/sql/session_tracker.cc @@ -190,28 +190,6 @@ public: return orig_list->construct_var_list(buf, buf_len); } - /** - Method used to check the validity of string provided - for session_track_system_variables during the server - startup. - */ - static bool server_init_check(THD *thd, CHARSET_INFO *char_set, - LEX_STRING var_list) - { - return check_var_list(thd, var_list, false, char_set, false); - } - - static bool server_init_process(THD *thd, CHARSET_INFO *char_set, - LEX_STRING var_list) - { - vars_list dummy; - bool result; - result= dummy.parse_var_list(thd, var_list, false, char_set, false); - if (!result) - dummy.construct_var_list(var_list.str, var_list.length + 1); - return result; - } - bool enable(THD *thd); bool update(THD *thd, set_var *var); bool store(THD *thd, String *buf); @@ -220,8 +198,7 @@ public: static uchar *sysvars_get_key(const char *entry, size_t *length, my_bool not_used __attribute__((unused))); - static bool check_var_list(THD *thd, LEX_STRING var_list, bool throw_error, - CHARSET_INFO *char_set, bool take_mutex); + friend bool sysvartrack_global_update(THD *thd, char *str, size_t len); }; @@ -442,12 +419,9 @@ error: } -bool Session_sysvars_tracker::check_var_list(THD *thd, - LEX_STRING var_list, - bool throw_error, - CHARSET_INFO *char_set, - bool take_mutex) +bool sysvartrack_validate_value(THD *thd, const char *str, size_t len) { + LEX_STRING var_list= { (char *) str, len }; const char separator= ','; char *token, *lasts= NULL; size_t rest= var_list.length; @@ -466,7 +440,7 @@ bool Session_sysvars_tracker::check_var_list(THD *thd, token value. Hence the mutex is handled here to avoid a performance overhead. */ - if (!thd || take_mutex) + if (!thd) mysql_mutex_lock(&LOCK_plugin); for (;;) { @@ -484,24 +458,14 @@ bool Session_sysvars_tracker::check_var_list(THD *thd, var.length= rest; /* Remove leading/trailing whitespace. */ - trim_whitespace(char_set, &var); + trim_whitespace(system_charset_info, &var); if(!strcmp(var.str, "*") && - !find_sys_var_ex(thd, var.str, var.length, throw_error, true)) + !find_sys_var_ex(thd, var.str, var.length, false, true)) { - if (throw_error && take_mutex && thd) - { - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_WRONG_VALUE_FOR_VAR, - "%.*s is not a valid system variable and will" - "be ignored.", (int)var.length, token); - } - else - { - if (!thd || take_mutex) - mysql_mutex_unlock(&LOCK_plugin); - return true; - } + if (!thd) + mysql_mutex_unlock(&LOCK_plugin); + return true; } if (lasts) @@ -509,7 +473,7 @@ bool Session_sysvars_tracker::check_var_list(THD *thd, else break; } - if (!thd || take_mutex) + if (!thd) mysql_mutex_unlock(&LOCK_plugin); return false; @@ -804,38 +768,50 @@ void Session_sysvars_tracker::vars_list::reset() at(i)->m_changed= false; } -static Session_sysvars_tracker* sysvar_tracker(THD *thd) -{ - return (Session_sysvars_tracker*) - thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER); -} -bool sysvartrack_validate_value(THD *thd, const char *str, size_t len) -{ - LEX_STRING tmp= {(char *)str, len}; - return Session_sysvars_tracker::server_init_check(thd, system_charset_info, - tmp); -} -bool sysvartrack_reprint_value(THD *thd, char *str, size_t len) +bool sysvartrack_global_update(THD *thd, char *str, size_t len) { - LEX_STRING tmp= {str, len}; - return Session_sysvars_tracker::server_init_process(thd, - system_charset_info, - tmp); -} -bool sysvartrack_update(THD *thd, set_var *var) -{ - return sysvar_tracker(thd)->update(thd, var); + LEX_STRING tmp= { str, len }; + Session_sysvars_tracker::vars_list dummy; + if (!dummy.parse_var_list(thd, tmp, false, system_charset_info, false)) + { + dummy.construct_var_list(str, len + 1); + return false; + } + return true; } -size_t sysvartrack_value_len(THD *thd) + + +uchar *sysvartrack_session_value_ptr(THD *thd, const LEX_CSTRING *base) { - return sysvar_tracker(thd)->get_buffer_length(); + Session_sysvars_tracker *tracker= static_cast<Session_sysvars_tracker*> + (thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER)); + size_t len= tracker->get_buffer_length(); + char *res= (char*) thd->alloc(len + sizeof(char*)); + if (res) + { + char *buf= res + sizeof(char*); + *((char**) res)= buf; + tracker->construct_var_list(buf, len); + } + return (uchar*) res; } -bool sysvartrack_value_construct(THD *thd, char *val, size_t len) + + +int session_tracker_init() { - return sysvar_tracker(thd)->construct_var_list(val, len); + if (sysvartrack_validate_value(0, + global_system_variables.session_track_system_variables, + safe_strlen(global_system_variables.session_track_system_variables))) + { + sql_print_error("The variable session_track_system_variables has " + "invalid values."); + return 1; + } + return 0; } + /////////////////////////////////////////////////////////////////////////////// /** @@ -1478,26 +1454,6 @@ void Session_tracker::enable(THD *thd) /** - Method called during the server startup to verify the contents - of @@session_track_system_variables. - - @retval false Success - @retval true Failure -*/ - -bool Session_tracker::server_boot_verify(CHARSET_INFO *char_set) -{ - bool result; - LEX_STRING tmp; - tmp.str= global_system_variables.session_track_system_variables; - tmp.length= safe_strlen(tmp.str); - result= - Session_sysvars_tracker::server_init_check(NULL, char_set, tmp); - return result; -} - - -/** @brief Store all change information in the specified buffer. @param thd [IN] The thd handle. diff --git a/sql/session_tracker.h b/sql/session_tracker.h index 1d0f55c252a..8edc3ce2a39 100644 --- a/sql/session_tracker.h +++ b/sql/session_tracker.h @@ -103,10 +103,8 @@ public: }; bool sysvartrack_validate_value(THD *thd, const char *str, size_t len); -bool sysvartrack_reprint_value(THD *thd, char *str, size_t len); -bool sysvartrack_update(THD *thd, set_var *var); -size_t sysvartrack_value_len(THD *thd); -bool sysvartrack_value_construct(THD *thd, char *val, size_t len); +bool sysvartrack_global_update(THD *thd, char *str, size_t len); +uchar *sysvartrack_session_value_ptr(THD *thd, const LEX_CSTRING *base); /** @@ -152,7 +150,6 @@ public: } void enable(THD *thd); - static bool server_boot_verify(CHARSET_INFO *char_set); /** Returns the pointer to the tracker object for the specified tracker. */ inline State_tracker *get_tracker(enum_session_tracker tracker) const @@ -296,6 +293,8 @@ private: ->X; } } while(0) #define SESSION_TRACKER_CHANGED(A,B,C) \ thd->session_tracker.mark_as_changed(A,B,C) + +int session_tracker_init(); #else #define TRANSACT_TRACKER(X) do{}while(0) diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic index 373df354268..7c375f16cdd 100644 --- a/sql/sys_vars.ic +++ b/sql/sys_vars.ic @@ -615,7 +615,7 @@ public: char *new_val= global_update_prepare(thd, var); if (new_val) { - if (sysvartrack_reprint_value(thd, new_val, + if (sysvartrack_global_update(thd, new_val, var->save_result.string_value.length)) new_val= 0; } @@ -624,7 +624,8 @@ public: } bool session_update(THD *thd, set_var *var) { - return sysvartrack_update(thd, var); + return thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER)-> + update(thd, var); } void session_save_default(THD *thd, set_var *var) { @@ -644,18 +645,7 @@ public: } } uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) - { - DBUG_ASSERT(thd != NULL); - size_t len= sysvartrack_value_len(thd); - char *res= (char *)thd->alloc(len + sizeof(char *)); - if (res) - { - char *buf= res + sizeof(char *); - *((char**) res)= buf; - sysvartrack_value_construct(thd, buf, len); - } - return (uchar *)res; - } + { return sysvartrack_session_value_ptr(thd, base); } }; #endif //EMBEDDED_LIBRARY |