diff --git a/server/modules/routing/readwritesplit/rwsplitsession.cc b/server/modules/routing/readwritesplit/rwsplitsession.cc index e6d73f981..c3ed80c8e 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.cc +++ b/server/modules/routing/readwritesplit/rwsplitsession.cc @@ -775,8 +775,23 @@ bool RWSplitSession::start_trx_replay() { bool rval = false; - if (!m_is_replay_active && m_config.transaction_replay && m_can_replay_trx) + if (m_config.transaction_replay && m_can_replay_trx) { + if (!m_is_replay_active) + { + // This is the first time we're retrying this transaction, store it and the interrupted query + m_orig_trx = m_trx; + m_orig_stmt.copy_from(m_current_query); + } + else + { + // Not the first time, copy the original + m_replayed_trx.close(); + m_trx.close(); + m_trx = m_orig_trx; + m_current_query.copy_from(m_orig_stmt); + } + if (m_trx.have_stmts() || m_current_query.get()) { // Stash any interrupted queries while we replay the transaction diff --git a/server/modules/routing/readwritesplit/rwsplitsession.hh b/server/modules/routing/readwritesplit/rwsplitsession.hh index d4b5229d8..00418122a 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.hh +++ b/server/modules/routing/readwritesplit/rwsplitsession.hh @@ -163,8 +163,10 @@ public: * transaction */ bool m_can_replay_trx; /**< Whether the transaction can be replayed */ Trx m_replayed_trx; /**< The transaction we are replaying */ - mxs::Buffer m_interrupted_query; /**< Query that was interrupted mid-transaction. - * */ + mxs::Buffer m_interrupted_query; /**< Query that was interrupted mid-transaction. */ + Trx m_orig_trx; /**< The backup of the transaction we're replaying */ + mxs::Buffer m_orig_stmt; /**< The backup of the statement that was interrupted */ + otrx_state m_otrx_state = OTRX_INACTIVE; /**< Optimistic trx state*/ private: