From 288ca68677860f18505ef7649fbca168aa69a2af Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Thu, 20 Mar 2014 12:15:57 +0200 Subject: [PATCH] Changed variable type which includes information of query type returned by query classifier. As a consequence, if autocommit is enabled, active transaction(s) are implicitly committed and MaxScale detects that implicit commit. --- query_classifier/query_classifier.cc | 131 +++++++++--------- query_classifier/query_classifier.h | 20 +-- .../routing/readwritesplit/readwritesplit.c | 13 +- 3 files changed, 88 insertions(+), 76 deletions(-) diff --git a/query_classifier/query_classifier.cc b/query_classifier/query_classifier.cc index d39985b56..24cacd53c 100644 --- a/query_classifier/query_classifier.cc +++ b/query_classifier/query_classifier.cc @@ -94,13 +94,13 @@ skygw_query_type_t skygw_query_classifier_get_type( const char* query, unsigned long client_flags) { - MYSQL* mysql; - char* query_str; - const char* user = "skygw"; - const char* db = "skygw"; - THD* thd; + MYSQL* mysql; + char* query_str; + const char* user = "skygw"; + const char* db = "skygw"; + THD* thd; skygw_query_type_t qtype = QUERY_TYPE_UNKNOWN; - bool failp = FALSE; + bool failp = FALSE; ss_info_dassert(query != NULL, ("query_str is NULL")); @@ -343,9 +343,9 @@ return_here: * restrictive, for example, QUERY_TYPE_READ is smaller than QUERY_TYPE_WRITE. * */ -static skygw_query_type_t set_query_type( - skygw_query_type_t* qtype, - skygw_query_type_t new_type) +static u_int8_t set_query_type( + u_int8_t* qtype, + u_int8_t new_type) { *qtype = MAX(*qtype, new_type); return *qtype; @@ -371,8 +371,9 @@ static skygw_query_type_t resolve_query_type( THD* thd) { skygw_query_type_t qtype = QUERY_TYPE_UNKNOWN; - LEX* lex; - Item* item; + u_int8_t type = QUERY_TYPE_UNKNOWN; + LEX* lex; + Item* item; /** * By default, if sql_log_bin, that is, recording data modifications * to binary log, is disabled, gateway treats operations normally. @@ -389,8 +390,8 @@ static skygw_query_type_t resolve_query_type( /** SELECT ..INTO variable|OUTFILE|DUMPFILE */ if (lex->result != NULL) { - qtype = QUERY_TYPE_SESSION_WRITE; - goto return_qtype; + type = QUERY_TYPE_SESSION_WRITE; + goto return_qtype; } /** * 1:ALTER TABLE, TRUNCATE, REPAIR, OPTIMIZE, ANALYZE, CHECK. @@ -402,17 +403,17 @@ static skygw_query_type_t resolve_query_type( * CREATE SPFUNCTION, INSTALL|UNINSTALL PLUGIN */ if (is_log_table_write_query(lex->sql_command) || - is_update_query(lex->sql_command)) + is_update_query(lex->sql_command)) { - if (thd->variables.sql_log_bin == 0 && - force_data_modify_op_replication) - { - qtype = QUERY_TYPE_SESSION_WRITE; - } else { - qtype = QUERY_TYPE_WRITE; - } + if (thd->variables.sql_log_bin == 0 && + force_data_modify_op_replication) + { + type |= QUERY_TYPE_SESSION_WRITE; + } else { + type |= QUERY_TYPE_WRITE; + } - goto return_qtype; + goto return_qtype; } /** @@ -422,56 +423,56 @@ static skygw_query_type_t resolve_query_type( if (sql_command_flags[lex->sql_command] & CF_AUTO_COMMIT_TRANS) { if (lex->option_type == OPT_GLOBAL) { - qtype = QUERY_TYPE_GLOBAL_WRITE; + type |= (QUERY_TYPE_GLOBAL_WRITE|QUERY_TYPE_COMMIT); } else { - qtype = QUERY_TYPE_SESSION_WRITE; + type |= (QUERY_TYPE_SESSION_WRITE|QUERY_TYPE_COMMIT); } goto return_qtype; } /** Try to catch session modifications here */ switch (lex->sql_command) { - case SQLCOM_SET_OPTION: - if (lex->option_type == OPT_GLOBAL) - { - qtype = QUERY_TYPE_GLOBAL_WRITE; - break; - } + case SQLCOM_SET_OPTION: + if (lex->option_type == OPT_GLOBAL) + { + type |= QUERY_TYPE_GLOBAL_WRITE; + break; + } /**func.write(master_dcb, gwbuf_clone(querybuf)); - rc2 = slave_dcb->func.write(slave_dcb, gwbuf_clone(querybuf)); + rc2 = slave_dcb->func.write(slave_dcb, querybuf); if (rc == 1 && rc == rc2) { @@ -869,6 +876,10 @@ return_ret: { gwbuf_free(plainsqlbuf); } + if (querystr != NULL) + { + free(querystr); + } return ret; }