From 8ac786110eaa2ed75fc613330961df084c75ade9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 10 Jan 2019 22:24:35 +0200 Subject: [PATCH] MXS-2255: Fix COMMIT matching The code used a rather questionable method for parsing SQL statements instead of using the query classifier for detecting transaction start and stop events. --- .../binlogfilter/binlogfiltersession.cc | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/server/modules/filter/binlogfilter/binlogfiltersession.cc b/server/modules/filter/binlogfilter/binlogfiltersession.cc index eeadc51ca..508404828 100644 --- a/server/modules/filter/binlogfilter/binlogfiltersession.cc +++ b/server/modules/filter/binlogfilter/binlogfiltersession.cc @@ -51,6 +51,7 @@ #include #include #include +#include #include "binlogfilter.hh" #include "binlogfiltersession.hh" @@ -380,33 +381,30 @@ static bool should_skip(const BinlogConfig& config, const std::string& str) static bool should_skip_query(const BinlogConfig& config, const std::string& sql, const std::string& db = "") { - uint32_t pktlen = sql.size() + 1; // Payload and command byte - GWBUF* buf = gwbuf_alloc(MYSQL_HEADER_LEN + pktlen); - uint8_t* data = GWBUF_DATA(buf); - - data[0] = pktlen; - data[1] = pktlen >> 8; - data[2] = pktlen >> 16; - data[3] = 0; - data[4] = (uint8_t)MXS_COM_QUERY; - strcpy((char*)&data[5], sql.c_str()); - + GWBUF* buf = modutil_create_query(sql.c_str()); bool rval = false; int n = 0; - char** names = qc_get_table_names(buf, &n, true); - for (int i = 0; i < n; i++) + if (qc_get_trx_type_mask(buf) == 0) { - std::string name = strchr(names[i], '.') ? names[i] : db + "." + names[i]; + // Not a transaction management related command - if (should_skip(config, name)) + char** names = qc_get_table_names(buf, &n, true); + + for (int i = 0; i < n; i++) { - rval = true; - break; + std::string name = strchr(names[i], '.') ? names[i] : db + "." + names[i]; + + if (should_skip(config, name)) + { + rval = true; + break; + } } + + qc_free_table_names(names, n); } - qc_free_table_names(names, n); gwbuf_free(buf); return rval; } @@ -796,13 +794,6 @@ bool BinlogFilterSession::checkStatement(const uint8_t* event, const uint32_t ev std::string db((char*)event + static_size + var_block_len, db_name_len); std::string sql((char*)event + static_size + var_block_len + db_name_len + 1, statement_len); - std::string lower_sql; - std::transform(sql.begin(), sql.end(), std::back_inserter(lower_sql), tolower); - - if (lower_sql.find("commit") != std::string::npos) - { - return false; - } m_skip = should_skip_query(m_filter.getConfig(), sql, db); MXS_INFO("[%s] (%s) %s", m_skip ? "SKIP" : " ", db.c_str(), sql.c_str());