MXS-1625 Move log_transaction_status() to QueryClassifier

This commit is contained in:
Johan Wikman
2018-04-09 13:40:43 +03:00
parent 5689613801
commit 18ca7018b1
3 changed files with 51 additions and 57 deletions

View File

@ -199,6 +199,8 @@ public:
return m_pSession;
}
void log_transaction_status(GWBUF *querybuf, uint32_t qtype);
private:
class PSManager;
typedef std::shared_ptr<PSManager> SPSManager;

View File

@ -14,12 +14,16 @@
#include <maxscale/queryclassifier.hh>
#include <tr1/unordered_map>
#include <maxscale/alloc.h>
#include <maxscale/modutil.h>
#include <maxscale/query_classifier.h>
#include <maxscale/protocol/mysql.h>
namespace
{
const int QC_TRACE_MSG_LEN = 1000;
bool are_multi_statements_allowed(MXS_SESSION* pSession)
{
MySQLProtocol* pPcol = static_cast<MySQLProtocol*>(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*)"<non-SQL>";
}
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());
}
}
}

View File

@ -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*)"<non-SQL>";
}
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