From 805be70a78ac1a62d4d05ab9f0efe5139f5a8222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 20 Jun 2019 13:19:31 +0300 Subject: [PATCH 1/2] Add more information to rwsplit info messages The statement ID for all binary protocol statements and the error given to handleError are now logged. --- server/core/queryclassifier.cc | 14 +++++++++++--- .../routing/readwritesplit/rwsplitsession.cc | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/core/queryclassifier.cc b/server/core/queryclassifier.cc index 8c5dd14fa..7ebe25395 100644 --- a/server/core/queryclassifier.cc +++ b/server/core/queryclassifier.cc @@ -638,11 +638,19 @@ void QueryClassifier::log_transaction_status(GWBUF* querybuf, uint32_t qtype) uint8_t* packet = GWBUF_DATA(querybuf); unsigned char command = packet[4]; int len = 0; - char* sql; + std::string sqldata; + char* sql = (char*)""; char* qtypestr = qc_typemask_to_string(qtype); - if (!modutil_extract_SQL(querybuf, &sql, &len)) + + if (qc_mysql_is_ps_command(command)) { - sql = (char*)""; + sqldata = "ID: " + std::to_string(mysql_extract_ps_id(querybuf)); + sql = (char*)sqldata.c_str(); + len = sqldata.length(); + } + else + { + modutil_extract_SQL(querybuf, &sql, &len); } if (len > QC_TRACE_MSG_LEN) diff --git a/server/modules/routing/readwritesplit/rwsplitsession.cc b/server/modules/routing/readwritesplit/rwsplitsession.cc index 44b9ea0ff..b9259df2d 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.cc +++ b/server/modules/routing/readwritesplit/rwsplitsession.cc @@ -956,7 +956,7 @@ void RWSplitSession::handleError(GWBUF* errmsgbuf, if (m_current_master && m_current_master->in_use() && m_current_master == backend) { - MXS_INFO("Master '%s' failed", backend->name()); + MXS_INFO("Master '%s' failed: %s", backend->name(), extract_error(errmsgbuf).c_str()); /** The connection to the master has failed */ if (!backend->is_waiting_result()) @@ -1028,7 +1028,7 @@ void RWSplitSession::handleError(GWBUF* errmsgbuf, } else { - MXS_INFO("Slave '%s' failed", backend->name()); + MXS_INFO("Slave '%s' failed: %s", backend->name(), extract_error(errmsgbuf).c_str()); if (m_target_node && m_target_node == backend && session_trx_is_read_only(problem_dcb->session)) { From be429c2c578e783c43ca43d4065e611b7ae7b09f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 20 Jun 2019 13:47:54 +0300 Subject: [PATCH 2/2] MXS-2490: Always restore original statement ID By always restoring the ID, we are guaranteed to only store the query in the form that it was originally sent in. This should be changed so that the ID that the client sends can be used as-is in the backends. --- .../routing/readwritesplit/rwsplit_route_stmt.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index c8a2a9d01..da86d25fe 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -1237,6 +1237,12 @@ bool RWSplitSession::handle_got_target(GWBUF* querybuf, SRWBackend& target, bool target->write(send_buf, response) : target->continue_write(send_buf); + if (orig_id) + { + // Put the original ID back in case we try to route the query again + replace_binary_ps_id(querybuf, orig_id); + } + if (success) { if (store) @@ -1280,12 +1286,6 @@ bool RWSplitSession::handle_got_target(GWBUF* querybuf, SRWBackend& target, bool } else { - if (orig_id) - { - // Put the original ID back in case we try to route the query again - replace_binary_ps_id(querybuf, orig_id); - } - MXS_ERROR("Routing query failed."); }