[Commits] 50f3eb2: # This is a combination of 2 commits.

Oleksandr Byelkin sanja at mariadb.com
Mon Oct 17 17:59:32 EEST 2016


revision-id: 50f3eb2614f85bb6ba437f22ce0e268e646b1420 (mariadb-10.2.2-49-g50f3eb2)
parent(s): 8303aded294ce905bbc513e7ee42623d5f1fdb50
committer: Oleksandr Byelkin
timestamp: 2016-10-17 16:59:32 +0200
message:

# This is a combination of 2 commits.
# The first commit's message is:

MDEV-10340: support COM_RESET_CONNECTION

draft to check with client

# The 2nd commit message will be skipped:

#	CC

---
 include/mysql.h.pp  |  2 ++
 include/mysql_com.h |  2 ++
 sql/sql_class.cc    | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 sql/sql_class.h     |  1 +
 sql/sql_parse.cc    | 13 +++++++++--
 5 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/include/mysql.h.pp b/include/mysql.h.pp
index 857f5b9..799489c 100644
--- a/include/mysql.h.pp
+++ b/include/mysql.h.pp
@@ -9,6 +9,8 @@ enum enum_server_command
   COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE,
   COM_STMT_PREPARE, COM_STMT_EXECUTE, COM_STMT_SEND_LONG_DATA, COM_STMT_CLOSE,
   COM_STMT_RESET, COM_SET_OPTION, COM_STMT_FETCH, COM_DAEMON,
+  COM_UNIMPLEMENTED,
+  COM_RESET_CONNECTION,
   COM_MDB_GAP_BEG,
   COM_MDB_GAP_END=250,
   COM_SLAVE_WORKER,
diff --git a/include/mysql_com.h b/include/mysql_com.h
index 461800f..e1b129a 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -111,6 +111,8 @@ enum enum_server_command
   COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE,
   COM_STMT_PREPARE, COM_STMT_EXECUTE, COM_STMT_SEND_LONG_DATA, COM_STMT_CLOSE,
   COM_STMT_RESET, COM_SET_OPTION, COM_STMT_FETCH, COM_DAEMON,
+  COM_UNIMPLEMENTED,
+  COM_RESET_CONNECTION,
   /* don't forget to update const char *command_name[] in sql_parse.cc */
   COM_MDB_GAP_BEG,
   COM_MDB_GAP_END=250,
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 1af3b9a..97e2606 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -1575,6 +1575,71 @@ void THD::change_user(void)
 }
 
 
+/*
+  Do what's needed when one invokes change user
+
+  SYNOPSIS
+    cleanup_connection()
+
+  IMPLEMENTATION
+    Reset all resources that are connection specific
+*/
+
+void THD::cleanup_connection(void)
+{
+  mysql_mutex_lock(&LOCK_status);
+  add_to_status(&global_status_var, &status_var);
+  {
+    int64 save_mem= status_var.local_memory_used;
+    bzero(&status_var, sizeof(status_var));
+    status_var.local_memory_used= save_mem;
+  }
+  mysql_mutex_unlock(&LOCK_status);
+
+  cleanup();
+#if defined(ENABLED_DEBUG_SYNC)
+  /* End the Debug Sync Facility. See debug_sync.cc. */
+  debug_sync_end_thread(this);
+#endif /* defined(ENABLED_DEBUG_SYNC) */
+  killed= NOT_KILLED;
+  cleanup_done= 0;
+  init();
+  stmt_map.reset();
+  my_hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
+               (my_hash_get_key) get_var_key,
+               (my_hash_free_key) free_user_var, 0);
+  sp_cache_clear(&sp_proc_cache);
+  sp_cache_clear(&sp_func_cache);
+
+  clear_error();
+  // clear the warnings
+  get_stmt_da()->mark_sql_conditions_for_removal();
+
+#ifndef DBUG_OFF
+    /* DEBUG code only (begin) */
+    bool check_cleanup= TRUE;
+    DBUG_EXECUTE_IF("debug_test_cleanup_connection", check_cleanup= TRUE;);
+    if(check_cleanup)
+    {
+      /* isolation level should be default */
+      DBUG_ASSERT(variables.tx_isolation == ISO_REPEATABLE_READ);
+      /* check autocommit is ON by default */
+      DBUG_ASSERT(server_status == SERVER_STATUS_AUTOCOMMIT);
+      /* check prepared stmts are cleaned up */
+      DBUG_ASSERT(prepared_stmt_count == 0);
+      /* check diagnostic area is cleaned up */
+      DBUG_ASSERT(get_stmt_da()->status() == Diagnostics_area::DA_EMPTY);
+      /* check if temp tables are deleted */
+      DBUG_ASSERT(temporary_tables == NULL);
+      /* check if tables are unlocked */
+      DBUG_ASSERT(locked_tables_list.locked_tables() == NULL);
+    }
+    /* DEBUG code only (end) */
+#endif
+
+}
+
+
 /* Do operations that may take a long time */
 
 void THD::cleanup(void)
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 994a161..14628ff 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -3032,6 +3032,7 @@ class THD :public Statement,
   void update_stats(void);
   void change_user(void);
   void cleanup(void);
+  void cleanup_connection();
   void cleanup_after_query();
   void free_connection();
   void reset_for_reuse();
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index ddb5e27..478a0c3 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -171,8 +171,8 @@ const LEX_STRING command_name[257]={
   { C_STRING_WITH_LEN("Set option") },      //27
   { C_STRING_WITH_LEN("Fetch") },           //28
   { C_STRING_WITH_LEN("Daemon") },          //29
-  { 0, 0 }, //30
-  { 0, 0 }, //31
+  { C_STRING_WITH_LEN("Unimpl get tid") },  //30
+  { C_STRING_WITH_LEN("Reset connection") },//31
   { 0, 0 }, //32
   { 0, 0 }, //33
   { 0, 0 }, //34
@@ -524,6 +524,7 @@ void init_update_queries(void)
   server_command_flags[COM_STMT_EXECUTE]= CF_SKIP_WSREP_CHECK;
   server_command_flags[COM_STMT_SEND_LONG_DATA]= CF_SKIP_WSREP_CHECK;
   server_command_flags[COM_MULTI]= CF_SKIP_WSREP_CHECK | CF_NO_COM_MULTI;
+  server_command_flags[CF_NO_COM_MULTI]= CF_NO_COM_MULTI;
 
   /* Initialize the sql command flags array. */
   memset(sql_command_flags, 0, sizeof(sql_command_flags));
@@ -1677,6 +1678,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
     break;
   }
 #endif
+  case COM_RESET_CONNECTION:
+  {
+    thd->status_var.com_other++;
+    thd->cleanup_connection();
+    my_ok(thd, 0, 0, 0);
+    break;
+  }
   case COM_CHANGE_USER:
   {
     int auth_rc;
@@ -2313,6 +2321,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
   case COM_TIME:				// Impossible from client
   case COM_DELAYED_INSERT:
   case COM_END:
+  case COM_UNIMPLEMENTED:
   default:
     my_message(ER_UNKNOWN_COM_ERROR, ER_THD(thd, ER_UNKNOWN_COM_ERROR),
                MYF(0));


More information about the commits mailing list