From 18ca7018b19a6f9c90921535aa5cb5e56604877c Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 9 Apr 2018 13:40:43 +0300 Subject: [PATCH] MXS-1625 Move log_transaction_status() to QueryClassifier --- include/maxscale/queryclassifier.hh | 2 + server/core/queryclassifier.cc | 48 +++++++++++++++ .../routing/readwritesplit/routeinfo.cc | 58 +------------------ 3 files changed, 51 insertions(+), 57 deletions(-) diff --git a/include/maxscale/queryclassifier.hh b/include/maxscale/queryclassifier.hh index f502cfd15..4a3f9d853 100644 --- a/include/maxscale/queryclassifier.hh +++ b/include/maxscale/queryclassifier.hh @@ -199,6 +199,8 @@ public: return m_pSession; } + void log_transaction_status(GWBUF *querybuf, uint32_t qtype); + private: class PSManager; typedef std::shared_ptr SPSManager; diff --git a/server/core/queryclassifier.cc b/server/core/queryclassifier.cc index e974d2195..d639fdf55 100644 --- a/server/core/queryclassifier.cc +++ b/server/core/queryclassifier.cc @@ -14,12 +14,16 @@ #include #include #include +#include #include #include namespace { +const int QC_TRACE_MSG_LEN = 1000; + + bool are_multi_statements_allowed(MXS_SESSION* pSession) { MySQLProtocol* pPcol = static_cast(pSession->client_dcb->protocol); @@ -471,5 +475,49 @@ void QueryClassifier::ps_id_internal_put(uint32_t external_id, uint32_t internal m_ps_handles[external_id] = internal_id; } +void QueryClassifier::log_transaction_status(GWBUF *querybuf, uint32_t qtype) +{ + if (large_query()) + { + MXS_INFO("> Processing large request with more than 2^24 bytes of data"); + } + else if (load_data_state() == QueryClassifier::LOAD_DATA_INACTIVE) + { + uint8_t *packet = GWBUF_DATA(querybuf); + unsigned char command = packet[4]; + int len = 0; + char* sql; + char *qtypestr = qc_typemask_to_string(qtype); + if (!modutil_extract_SQL(querybuf, &sql, &len)) + { + sql = (char*)""; + } + + if (len > QC_TRACE_MSG_LEN) + { + len = QC_TRACE_MSG_LEN; + } + + MXS_SESSION *ses = session(); + const char *autocommit = session_is_autocommit(ses) ? "[enabled]" : "[disabled]"; + const char *transaction = session_trx_is_active(ses) ? "[open]" : "[not open]"; + uint32_t plen = MYSQL_GET_PACKET_LEN(querybuf); + const char *querytype = qtypestr == NULL ? "N/A" : qtypestr; + const char *hint = querybuf->hint == NULL ? "" : ", Hint:"; + const char *hint_type = querybuf->hint == NULL ? "" : STRHINTTYPE(querybuf->hint->type); + + MXS_INFO("> Autocommit: %s, trx is %s, cmd: (0x%02x) %s, plen: %u, type: %s, stmt: %.*s%s %s", + autocommit, transaction, command, STRPACKETTYPE(command), plen, + querytype, len, sql, hint, hint_type); + + MXS_FREE(qtypestr); + } + else + { + MXS_INFO("> Processing LOAD DATA LOCAL INFILE: %lu bytes sent.", load_data_sent()); + } +} + + } diff --git a/server/modules/routing/readwritesplit/routeinfo.cc b/server/modules/routing/readwritesplit/routeinfo.cc index a2e65d557..ac9688c7c 100644 --- a/server/modules/routing/readwritesplit/routeinfo.cc +++ b/server/modules/routing/readwritesplit/routeinfo.cc @@ -23,62 +23,6 @@ using mxs::QueryClassifier; namespace { -/** - * @brief Log the transaction status - * - * The router session and the query buffer are used to log the transaction - * status, along with the query type (which is a generic description that - * should be usable across all DB types). - * - * @param qc The query classifier. - * @param querybuf Query buffer - * @param qtype Query type - */ -void -log_transaction_status(const QueryClassifier& qc, GWBUF *querybuf, uint32_t qtype) -{ - if (qc.large_query()) - { - MXS_INFO("> Processing large request with more than 2^24 bytes of data"); - } - else if (qc.load_data_state() == QueryClassifier::LOAD_DATA_INACTIVE) - { - uint8_t *packet = GWBUF_DATA(querybuf); - unsigned char command = packet[4]; - int len = 0; - char* sql; - char *qtypestr = qc_typemask_to_string(qtype); - if (!modutil_extract_SQL(querybuf, &sql, &len)) - { - sql = (char*)""; - } - - if (len > RWSPLIT_TRACE_MSG_LEN) - { - len = RWSPLIT_TRACE_MSG_LEN; - } - - MXS_SESSION *ses = qc.session(); - const char *autocommit = session_is_autocommit(ses) ? "[enabled]" : "[disabled]"; - const char *transaction = session_trx_is_active(ses) ? "[open]" : "[not open]"; - uint32_t plen = MYSQL_GET_PACKET_LEN(querybuf); - const char *querytype = qtypestr == NULL ? "N/A" : qtypestr; - const char *hint = querybuf->hint == NULL ? "" : ", Hint:"; - const char *hint_type = querybuf->hint == NULL ? "" : STRHINTTYPE(querybuf->hint->type); - - MXS_INFO("> Autocommit: %s, trx is %s, cmd: (0x%02x) %s, plen: %u, type: %s, stmt: %.*s%s %s", - autocommit, transaction, command, STRPACKETTYPE(command), plen, - querytype, len, sql, hint, hint_type); - - MXS_FREE(qtypestr); - } - else - { - MXS_INFO("> Processing LOAD DATA LOCAL INFILE: %lu bytes sent.", - qc.load_data_sent()); - } -} - /** * @brief Determine the type of a query * @@ -491,7 +435,7 @@ route_target_t get_target_type(QueryClassifier& qc, if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO)) { - log_transaction_status(qc, buffer, *type); + qc.log_transaction_status(buffer, *type); } /** * Find out where to route the query. Result may not be clear; it is