Commit 8a6a95a1 authored by Alexey Botchkov's avatar Alexey Botchkov

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 prepared 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 prepared statement run in the main thread doesn't produce expected 'dbug' errors,
    so the test fails.
    To fix that I made prepared statement to be run in that special thread along with the plain queries.
    That makes the environment consistent.
parent 365960a0
......@@ -830,6 +830,8 @@ static void handle_no_active_connection(struct st_command* command,
#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
......@@ -865,11 +867,19 @@ pthread_handler_t connection_thread(void *arg)
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);
}
......@@ -939,6 +949,30 @@ static int do_read_query_result(struct st_connection *cn)
}
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)
......@@ -972,6 +1006,8 @@ static void init_connection_thd(struct st_connection *cn)
#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*/
......@@ -8051,11 +8087,12 @@ void handle_no_error(struct st_command *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;
......@@ -8065,11 +8102,11 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command,
/*
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 */
......@@ -8082,7 +8119,7 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command,
/*
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);
......@@ -8117,7 +8154,7 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command,
/*
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);
......@@ -8252,7 +8289,7 @@ end:
if (mysql->reconnect)
{
mysql_stmt_close(stmt);
cur_con->stmt= NULL;
cn->stmt= NULL;
}
DBUG_VOID_RETURN;
......@@ -8498,7 +8535,7 @@ void run_query(struct st_connection *cn, struct st_command *command, int flags)
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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment