[Commits] 2722af4: Fix of global value

Oleksandr Byelkin sanja at mariadb.com
Wed May 25 16:00:49 EEST 2016


revision-id: 2722af43559d7d6b31dd7686dc92c80a8c23168e (mariadb-10.2.0-45-g2722af4)
parent(s): 5bf448e1c0d1a8dcabd223595b0111617627d212
committer: Oleksandr Byelkin
timestamp: 2016-05-25 15:00:49 +0200
message:

Fix of global value

---
 .../r/session_track_system_variables_basic.result  | 30 +++++++++++++++++++-
 .../t/session_track_system_variables_basic.test    | 19 +++++++++++++
 sql/session_tracker.cc                             | 33 ++++++++++++++++------
 sql/session_tracker.h                              |  1 +
 sql/sys_vars.ic                                    | 27 ++++++++++++++++--
 5 files changed, 98 insertions(+), 12 deletions(-)

diff --git a/mysql-test/suite/sys_vars/r/session_track_system_variables_basic.result b/mysql-test/suite/sys_vars/r/session_track_system_variables_basic.result
index 9250962..e451a22 100644
--- a/mysql-test/suite/sys_vars/r/session_track_system_variables_basic.result
+++ b/mysql-test/suite/sys_vars/r/session_track_system_variables_basic.result
@@ -124,11 +124,39 @@ SET @@global.session_track_system_variables= "sql_mode,sql_mode";
 SET @@session.session_track_system_variables= "sql_mode,sql_mode";
 SELECT @@global.session_track_system_variables;
 @@global.session_track_system_variables
-sql_mode,sql_mode
+sql_mode
 SELECT @@session.session_track_system_variables;
 @@session.session_track_system_variables
 sql_mode
 
+# testing ordering
+SET @@global.session_track_system_variables= "time_zone,sql_mode";
+SET @@session.session_track_system_variables= "time_zone,sql_mode";
+SELECT @@global.session_track_system_variables;
+@@global.session_track_system_variables
+sql_mode,time_zone
+SELECT @@session.session_track_system_variables;
+@@session.session_track_system_variables
+sql_mode,time_zone
+
+# special values
+SET @@global.session_track_system_variables= "*";
+SET @@session.session_track_system_variables= "*";
+SELECT @@global.session_track_system_variables;
+@@global.session_track_system_variables
+*
+SELECT @@session.session_track_system_variables;
+@@session.session_track_system_variables
+*
+SET @@global.session_track_system_variables= "";
+SET @@session.session_track_system_variables= "";
+SELECT @@global.session_track_system_variables;
+@@global.session_track_system_variables
+
+SELECT @@session.session_track_system_variables;
+@@session.session_track_system_variables
+
+
 # Restoring the original values.
 SET @@global.session_track_system_variables = @global_saved_tmp;
 # End of tests.
diff --git a/mysql-test/suite/sys_vars/t/session_track_system_variables_basic.test b/mysql-test/suite/sys_vars/t/session_track_system_variables_basic.test
index 0be2bf2..bbb32bb 100644
--- a/mysql-test/suite/sys_vars/t/session_track_system_variables_basic.test
+++ b/mysql-test/suite/sys_vars/t/session_track_system_variables_basic.test
@@ -108,6 +108,25 @@ SELECT @@global.session_track_system_variables;
 SELECT @@session.session_track_system_variables;
 --echo
 
+--echo # testing ordering
+SET @@global.session_track_system_variables= "time_zone,sql_mode";
+SET @@session.session_track_system_variables= "time_zone,sql_mode";
+SELECT @@global.session_track_system_variables;
+SELECT @@session.session_track_system_variables;
+--echo
+
+--echo # special values
+SET @@global.session_track_system_variables= "*";
+SET @@session.session_track_system_variables= "*";
+SELECT @@global.session_track_system_variables;
+SELECT @@session.session_track_system_variables;
+SET @@global.session_track_system_variables= "";
+SET @@session.session_track_system_variables= "";
+SELECT @@global.session_track_system_variables;
+SELECT @@session.session_track_system_variables;
+--echo
+
+
 --echo # Restoring the original values.
 SET @@global.session_track_system_variables = @global_saved_tmp;
 
diff --git a/sql/session_tracker.cc b/sql/session_tracker.cc
index db54939..7d3b90e 100644
--- a/sql/session_tracker.cc
+++ b/sql/session_tracker.cc
@@ -184,12 +184,22 @@ class Session_sysvars_tracker : public State_tracker
     for session_track_system_variables during the server
     startup.
   */
-  static bool server_init_check(const CHARSET_INFO *char_set,
+  static bool server_init_check(THD *thd, const CHARSET_INFO *char_set,
                                 LEX_STRING var_list)
   {
     vars_list dummy;
     bool result;
-    result= dummy.parse_var_list(NULL, var_list, false, char_set, true);
+    result= dummy.parse_var_list(thd, var_list, false, char_set, false);
+    return result;
+  }
+  static bool server_init_process(THD *thd, const 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;
   }
 
@@ -280,6 +290,7 @@ static const unsigned int EXTRA_ALLOC= 1024;
 void Session_sysvars_tracker::vars_list::reset()
 {
   buffer_length= 0;
+  track_all= 0;
   if (m_registered_sysvars.records)
     my_hash_reset(&m_registered_sysvars);
 }
@@ -782,12 +793,18 @@ static Session_sysvars_tracker* sysvar_tracker(THD *thd)
 
 bool sysvartrack_validate_value(THD *thd, const char *str, size_t len)
 {
-  if (sysvar_tracker(thd)->is_enabled())
-  {
-    LEX_STRING tmp= {(char *)str, len};
+  LEX_STRING tmp= {(char *)str, len};
+  if (thd && sysvar_tracker(thd)->is_enabled())
     return sysvar_tracker(thd)->check_str(thd, tmp);
-  }
-  return FALSE;
+  return Session_sysvars_tracker::server_init_check(thd, system_charset_info,
+                                                    tmp);
+}
+bool sysvartrack_reprint_value(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)
 {
@@ -1023,7 +1040,7 @@ bool Session_tracker::server_boot_verify(const CHARSET_INFO *char_set)
   set_var tmp(NULL, SHOW_OPT_GLOBAL, svar, &null_lex_str, NULL);
   svar->session_save_default(NULL, &tmp);
   server_tracker= new (std::nothrow) Session_sysvars_tracker();
-  result= server_tracker->server_init_check(char_set,
+  result= server_tracker->server_init_check(NULL, char_set,
                                             tmp.save_result.string_value);
   delete server_tracker;
   return result;
diff --git a/sql/session_tracker.h b/sql/session_tracker.h
index 3ec987b..f6a3f89 100644
--- a/sql/session_tracker.h
+++ b/sql/session_tracker.h
@@ -105,6 +105,7 @@ class State_tracker
 };
 
 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);
 size_t sysvartrack_value_len(THD *thd);
 bool sysvartrack_value_construct(THD *thd, char *val, size_t len);
diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic
index 11683da..45ab6b2 100644
--- a/sql/sys_vars.ic
+++ b/sql/sys_vars.ic
@@ -501,23 +501,32 @@ class Sys_var_charptr_base: public sys_var
   bool do_check(THD *thd, set_var *var)
   { return do_string_check(thd, var, charset(thd)); }
   bool session_update(THD *thd, set_var *var)= 0;
-  bool global_update(THD *thd, set_var *var)
+  char *global_update_prepare(THD *thd, set_var *var)
   {
     char *new_val, *ptr= var->save_result.string_value.str;
     size_t len=var->save_result.string_value.length;
     if (ptr)
     {
       new_val= (char*)my_memdup(ptr, len+1, MYF(MY_WME));
-      if (!new_val) return true;
+      if (!new_val) return 0;
       new_val[len]=0;
     }
     else
       new_val= 0;
+    return new_val;
+  }
+  void global_update_finish(char *new_val)
+  {
     if (flags & ALLOCATED)
       my_free(global_var(char*));
     flags|= ALLOCATED;
     global_var(char*)= new_val;
-    return false;
+  }
+  bool global_update(THD *thd, set_var *var)
+  {
+    char *new_val= global_update_prepare(thd, var);
+    global_update_finish(new_val);
+    return (new_val == 0 && var->save_result.string_value.str != 0);
   }
   void session_save_default(THD *thd, set_var *var)= 0;
   void global_save_default(THD *thd, set_var *var)
@@ -578,6 +587,18 @@ class Sys_var_sesvartrack: public Sys_var_charptr_base
        return TRUE;
      return FALSE;
   }
+  bool global_update(THD *thd, set_var *var)
+  {
+    char *new_val= global_update_prepare(thd, var);
+    if (new_val)
+    {
+      if (sysvartrack_reprint_value(thd, new_val,
+                                    var->save_result.string_value.length))
+        new_val= 0;
+    }
+    global_update_finish(new_val);
+    return (new_val == 0 && var->save_result.string_value.str != 0);
+  }
   bool session_update(THD *thd, set_var *var)
   {
     return sysvartrack_update(thd);


More information about the commits mailing list