MXS-1507: Add initial implementation of transaction replay

Added the initial implementation of transaction replay. Transactions are
only replayed if the master fails when no statement is being executed.

The validity of the replayed transaction is done by verifying that the
checksums of the returned results are equal.

Added a close function into the Trx class to make resetting its state
easier. Also changed the return type of the pop_stmt to GWBUF* as the
places where it is used expect a raw GWBUF pointer.
This commit is contained in:
Markus Mäkelä
2018-04-19 15:36:14 +03:00
parent daecb6980b
commit 01bf5cc8b0
4 changed files with 102 additions and 32 deletions

View File

@ -19,13 +19,12 @@
#include <maxscale/buffer.hh>
#include <maxscale/utils.hh>
// A log of executed queries, for transaction replay
typedef std::deque<mxs::Buffer> TrxLog;
// A transaction
class Trx
{
public:
// A log of executed queries, for transaction replay
typedef std::deque<mxs::Buffer> TrxLog;
/**
* Add a statement to the transaction
@ -57,9 +56,10 @@ public:
*
* @return The oldest statement in this transaction
*/
mxs::Buffer pop_stmt()
GWBUF* pop_stmt()
{
mxs::Buffer rval = m_log.front();
ss_dassert(!m_log.empty());
GWBUF* rval = m_log.front().release();
m_log.pop_front();
return rval;
}
@ -86,6 +86,17 @@ public:
return m_log.empty();
}
/**
* Close the transaction
*
* This clears out the stored statements and resets the checksum state.
*/
void close()
{
m_checksum.reset();
m_log.clear();
}
/**
* Return the current checksum
*