MXS-1810: Store transaction contents

The queries that make up the transaction are now stored in the router
session while the transaction is in progress. For the time being, the
queries are only used to log extra information about the transaction
contents.
This commit is contained in:
Markus Mäkelä 2018-04-19 09:47:25 +03:00
parent 53a5685dc2
commit 94038933d8
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
3 changed files with 31 additions and 4 deletions

View File

@ -244,6 +244,11 @@ bool RWSplitSession::route_single_stmt(GWBUF *querybuf)
m_exec_map[stmt_id] = target;
MXS_INFO("COM_STMT_EXECUTE on %s: %s", target->name(), target->uri());
}
if (succp && session_trx_is_active(m_client->session))
{
m_trx_log.push_back(gwbuf_clone(querybuf));
}
}
}
else if (can_retry_query())

View File

@ -15,6 +15,8 @@
#include <cmath>
#include <maxscale/modutil.hh>
using namespace maxscale;
RWSplitSession::RWSplitSession(RWSplit* instance, MXS_SESSION* session,
@ -401,8 +403,7 @@ void RWSplitSession::clientReply(GWBUF *writebuf, DCB *backend_dcb)
if (session_trx_is_ending(m_client->session))
{
m_trx_checksum.finalize(writebuf);
MXS_INFO("Transaction checksum: %s", m_trx_checksum.hex().c_str());
close_transaction();
}
else if (session_trx_is_active(m_client->session))
{
@ -558,9 +559,8 @@ void RWSplitSession::handleError(GWBUF *errmsgbuf, DCB *problem_dcb,
if (session_trx_is_active(session))
{
// We have an open transaction, we can't continue
m_trx_checksum.finalize();
MXS_INFO("Checksum of failed transaction: %s", m_trx_checksum.hex().c_str());
can_continue = false;
close_transaction();
}
*succp = can_continue;
@ -760,3 +760,17 @@ bool RWSplitSession::supports_hint(HINT_TYPE hint_type) const
return rv;
}
void RWSplitSession::close_transaction()
{
m_trx_checksum.finalize();
MXS_INFO("Checksum of current transaction: %s", m_trx_checksum.hex().c_str());
int i = 1;
while (!m_trx_log.empty())
{
const int max_len = 1024;
MXS_INFO("%d: %s", i++, mxs::extract_sql(m_trx_log.front().get(), max_len).c_str());
m_trx_log.pop_front();
}
}

View File

@ -16,6 +16,7 @@
#include "rwbackend.hh"
#include <string>
#include <deque>
#include <maxscale/buffer.hh>
#include <maxscale/modutil.h>
@ -39,6 +40,9 @@ typedef std::list< std::pair<mxs::SRWBackend, uint8_t> > SlaveResponseList;
/** Map of COM_STMT_EXECUTE targets by internal ID */
typedef std::tr1::unordered_map<uint32_t, mxs::SRWBackend> ExecMap;
// A log of executed queries, for transaction replay
typedef std::deque<mxs::Buffer> TrxLog;
/**
* The client session of a RWSplit instance
*/
@ -138,6 +142,7 @@ public:
uint64_t m_retry_duration; /**< Total time spent retrying queries */
mxs::Buffer m_current_query; /**< Current query being executed */
mxs::SHA1Checksum m_trx_checksum; /**< Transaction checksum */
TrxLog m_trx_log; /**< Log of executed queries in the current transaction */
private:
RWSplitSession(RWSplit* instance, MXS_SESSION* session,
@ -181,6 +186,9 @@ private:
void handle_error_reply_client(DCB *backend_dcb, GWBUF *errmsg);
bool handle_error_new_connection(DCB *backend_dcb, GWBUF *errmsg);
// Currently only for diagnostic purposes
void close_transaction();
private:
// QueryClassifier::Handler
bool lock_to_master();