[Commits] Rev 3993: MDEV-5138 Numerous test failures in "mtr --ps --embedded". in file:///home/hf/wmar/mdev-5138/

holyfoot at askmonty.org holyfoot at askmonty.org
Mon Dec 2 14:04:50 EET 2013


At file:///home/hf/wmar/mdev-5138/

------------------------------------------------------------
revno: 3993
revision-id: holyfoot at askmonty.org-20131202104753-srqqm7hv1rtcurx4
parent: holyfoot at askmonty.org-20131130142537-7j272euoaoy0svg1
committer: Alexey Botchkov <holyfoot at askmonty.org>
branch nick: mdev-5138
timestamp: Mon 2013-12-02 14:47:53 +0400
message:
  MDEV-5138 Numerous test failures in "mtr --ps --embedded".
          mysqltest in the 'embedded-server' mode runs queries in a separate thread,
          but it didn't do so for the statements - they were run in the main thread.
          That leads to inconsistencies.
          When a test sets SESSION 'dbug' variable like
                  SET SESSION debug_dbug="+d,warn_during_ha_commit_trans";
          it is run as a plain query in that separate thread, so the main thread remains unaffected.
          After that the statement run in the main thread doesn't produce expected 'dbug' errors,
          so the test fail.
          To fix that I made statement to be run in that special thread along with the plain queries.
          That makes the environment consistent.
-------------- next part --------------
=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2013-11-10 19:19:21 +0000
+++ b/client/mysqltest.cc	2013-12-02 10:47:53 +0000
@@ -829,6 +829,8 @@ static void handle_no_active_connection(
 #define EMB_SEND_QUERY 1
 #define EMB_READ_QUERY_RESULT 2
 #define EMB_END_CONNECTION 3
+#define EMB_PREPARE_STMT 4
+#define EMB_EXECUTE_STMT 5
 
 /* workaround for MySQL BUG#57491 */
 #undef MY_WME
@@ -864,11 +866,19 @@ pthread_handler_t connection_thread(void
       case EMB_END_CONNECTION:
         goto end_thread;
       case EMB_SEND_QUERY:
-        cn->result= mysql_send_query(cn->mysql, cn->cur_query, cn->cur_query_len);
+        cn->result= mysql_send_query(cn->mysql,
+                                     cn->cur_query, cn->cur_query_len);
         break;
       case EMB_READ_QUERY_RESULT:
         cn->result= mysql_read_query_result(cn->mysql);
         break;
+      case EMB_PREPARE_STMT:
+        cn->result= mysql_stmt_prepare(cn->stmt,
+                                       cn->cur_query, cn->cur_query_len);
+        break;
+      case EMB_EXECUTE_STMT:
+        cn->result= mysql_stmt_execute(cn->stmt);
+        break;
       default:
         DBUG_ASSERT(0);
     }
@@ -938,6 +948,30 @@ static int do_read_query_result(struct s
 }
 
 
+static int do_stmt_prepare(struct st_connection *cn, const char *q, int q_len)
+{
+  /* The cn->stmt is already set. */
+  if (!cn->has_thread)
+    return mysql_stmt_prepare(cn->stmt, q, q_len);
+  cn->cur_query= q;
+  cn->cur_query_len= q_len;
+  signal_connection_thd(cn, EMB_PREPARE_STMT);
+  wait_query_thread_done(cn);
+  return cn->result;
+}
+
+
+static int do_stmt_execute(struct st_connection *cn)
+{
+  /* The cn->stmt is already set. */
+  if (!cn->has_thread)
+    return mysql_stmt_execute(cn->stmt);
+  signal_connection_thd(cn, EMB_EXECUTE_STMT);
+  wait_query_thread_done(cn);
+  return cn->result;
+}
+
+
 static void emb_close_connection(struct st_connection *cn)
 {
   if (!cn->has_thread)
@@ -971,6 +1005,8 @@ static void init_connection_thd(struct s
 #define init_connection_thd(X)    do { } while(0)
 #define do_send_query(cn,q,q_len) mysql_send_query(cn->mysql, q, q_len)
 #define do_read_query_result(cn) mysql_read_query_result(cn->mysql)
+#define do_stmt_prepare(cn, q, q_len) mysql_stmt_prepare(cn->stmt, q, q_len)
+#define do_stmt_execute(cn) mysql_stmt_execute(cn->stmt)
 
 #endif /*EMBEDDED_LIBRARY*/
 
@@ -8046,11 +8082,12 @@ void handle_no_error(struct st_command *
   error - function will not return
 */
 
-void run_query_stmt(MYSQL *mysql, struct st_command *command,
+void run_query_stmt(struct st_connection *cn, struct st_command *command,
                     char *query, int query_len, DYNAMIC_STRING *ds,
                     DYNAMIC_STRING *ds_warnings)
 {
   MYSQL_RES *res= NULL;     /* Note that here 'res' is meta data result set */
+  MYSQL *mysql= cn->mysql;
   MYSQL_STMT *stmt;
   DYNAMIC_STRING ds_prepare_warnings;
   DYNAMIC_STRING ds_execute_warnings;
@@ -8060,11 +8097,11 @@ void run_query_stmt(MYSQL *mysql, struct
   /*
     Init a new stmt if it's not already one created for this connection
   */
-  if(!(stmt= cur_con->stmt))
+  if(!(stmt= cn->stmt))
   {
     if (!(stmt= mysql_stmt_init(mysql)))
       die("unable to init stmt structure");
-    cur_con->stmt= stmt;
+    cn->stmt= stmt;
   }
 
   /* Init dynamic strings for warnings */
@@ -8077,7 +8114,7 @@ void run_query_stmt(MYSQL *mysql, struct
   /*
     Prepare the query
   */
-  if (mysql_stmt_prepare(stmt, query, query_len))
+  if (do_stmt_prepare(cn, query, query_len))
   {
     handle_error(command,  mysql_stmt_errno(stmt),
                  mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds);
@@ -8112,7 +8149,7 @@ void run_query_stmt(MYSQL *mysql, struct
   /*
     Execute the query
   */
-  if (mysql_stmt_execute(stmt))
+  if (do_stmt_execute(cn))
   {
     handle_error(command, mysql_stmt_errno(stmt),
                  mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds);
@@ -8247,7 +8284,7 @@ void run_query_stmt(MYSQL *mysql, struct
   if (mysql->reconnect)
   {
     mysql_stmt_close(stmt);
-    cur_con->stmt= NULL;
+    cn->stmt= NULL;
   }
 
   DBUG_VOID_RETURN;
@@ -8490,7 +8527,7 @@ void run_query(struct st_connection *cn,
   if (ps_protocol_enabled &&
       complete_query &&
       match_re(&ps_re, query))
-    run_query_stmt(mysql, command, query, query_len, ds, &ds_warnings);
+    run_query_stmt(cn, command, query, query_len, ds, &ds_warnings);
   else
     run_query_normal(cn, command, flags, query, query_len,
                      ds, &ds_warnings);



More information about the commits mailing list