From c18e0dab8a24db9d8f84fef328c27a28939a6ef5 Mon Sep 17 00:00:00 2001 From: Nirbhay Choubey Date: Fri, 14 Aug 2015 00:01:18 -0400 Subject: [PATCH] MDEV-8617: Multiple galera tests failures with --ps-protocol In galera cluster, when myisam replication is enabled (wsrep_replicate_myisam=ON), DML statements are replicated in open_tables(). However, in case of prepared statements, for an INSERT, open_tables() gets invoked twice. Once for COM_STMT_PREPARE (to validate and prepare INSERT) and later for COM_STMT_EXECUTE. As a result, the command gets replicated twice. Same happens for REPLACE, UPDATE and DELETE commands. Fixed by adding a check to not replicate during 'prepare' phase. Also changed the order of conditions to make it more efficient. Lastly, in order to support wsrep_dirty_reads, made changes to allow COM_STMT_XXX commands to continue past initial check even when wsrep is not ready. --- sql/sql_base.cc | 30 ++++++++++++++++-------------- sql/sql_class.h | 2 ++ sql/sql_parse.cc | 5 +++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/sql/sql_base.cc b/sql/sql_base.cc index acf553b1041..f0596dd1fc6 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -5226,20 +5226,22 @@ restart: } } #ifdef WITH_WSREP - if ((thd->lex->sql_command== SQLCOM_INSERT || - thd->lex->sql_command== SQLCOM_INSERT_SELECT || - thd->lex->sql_command== SQLCOM_REPLACE || - thd->lex->sql_command== SQLCOM_REPLACE_SELECT || - thd->lex->sql_command== SQLCOM_UPDATE || - thd->lex->sql_command== SQLCOM_UPDATE_MULTI || - thd->lex->sql_command== SQLCOM_LOAD || - thd->lex->sql_command== SQLCOM_DELETE) && - wsrep_replicate_myisam && - (*start) && - (*start)->table && (*start)->table->file->ht->db_type == DB_TYPE_MYISAM) - { - WSREP_TO_ISOLATION_BEGIN(NULL, NULL, (*start)); - } + if (wsrep_replicate_myisam && + (*start) && + (*start)->table && + (*start)->table->file->ht->db_type == DB_TYPE_MYISAM && + thd->get_command() != COM_STMT_PREPARE && + ((thd->lex->sql_command == SQLCOM_INSERT || + thd->lex->sql_command == SQLCOM_INSERT_SELECT || + thd->lex->sql_command == SQLCOM_REPLACE || + thd->lex->sql_command == SQLCOM_REPLACE_SELECT || + thd->lex->sql_command == SQLCOM_UPDATE || + thd->lex->sql_command == SQLCOM_UPDATE_MULTI || + thd->lex->sql_command == SQLCOM_LOAD || + thd->lex->sql_command == SQLCOM_DELETE))) + { + WSREP_TO_ISOLATION_BEGIN(NULL, NULL, (*start)); + } error: #endif diff --git a/sql/sql_class.h b/sql/sql_class.h index 418c8043673..6deabb04f3d 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3076,6 +3076,8 @@ private: public: /** Overloaded to guard query/query_length fields */ virtual void set_statement(Statement *stmt); + inline enum enum_server_command get_command() const + { return command; } /** Assign a new value to thd->query and thd->query_id and mysys_var. diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 44f173e627a..3629f3dd198 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -862,6 +862,11 @@ bool do_command(THD *thd) command != COM_SLEEP && command != COM_STATISTICS && command != COM_TIME && + command != COM_STMT_PREPARE && + command != COM_STMT_SEND_LONG_DATA && + command != COM_STMT_EXECUTE && + command != COM_STMT_RESET && + command != COM_STMT_CLOSE && command != COM_END ) { my_message(ER_UNKNOWN_COM_ERROR,