MXS-1506: Store queries inside RWSplitSession

As the readwritesplit is the only thing that uses the statement storage,
it can be integrated into RWSplitSession. This makes the code a lot
simpler.
This commit is contained in:
Markus Mäkelä
2018-04-04 17:35:07 +03:00
parent 53dec5323d
commit 450b31dd8c
5 changed files with 39 additions and 111 deletions

View File

@ -959,9 +959,9 @@ bool RWSplitSession::handle_got_target(GWBUF* querybuf, SRWBackend& target, bool
if (target->write(send_buf, response))
{
if (store && !session_store_stmt(m_client->session, querybuf, target->server()))
if (store)
{
MXS_ERROR("Failed to store current statement, it won't be retried if it fails.");
set_query(send_buf);
}
atomic_add_uint64(&m_router->stats().n_queries, 1);

View File

@ -37,7 +37,8 @@ RWSplitSession::RWSplitSession(RWSplit* instance, MXS_SESSION* session,
m_wait_gtid_state(EXPECTING_NOTHING),
m_next_seq(0),
m_qc(this, session, instance->config().use_sql_variables_in),
m_retry_duration(0)
m_retry_duration(0),
m_current_query(NULL)
{
if (m_config.rw_max_slave_conn_percent)
{
@ -386,11 +387,7 @@ void RWSplitSession::clientReply(GWBUF *writebuf, DCB *backend_dcb)
return;
}
if (session_have_stmt(backend_dcb->session))
{
/** Statement was successfully executed, free the stored statement */
session_clear_stmt(backend_dcb->session);
}
reset_query();
if (backend->reply_is_complete(writebuf))
{
@ -612,17 +609,12 @@ bool RWSplitSession::handle_error_new_connection(DCB *backend_dcb, GWBUF *errmsg
* Try to reroute the statement to a working server or send an error
* to the client.
*/
GWBUF *stored = NULL;
const SERVER *target = NULL;
GWBUF *stored = release_query();
if (session_take_stmt(backend_dcb->session, &stored, &target) &&
m_config.retry_failed_reads)
if (stored && m_config.retry_failed_reads)
{
ss_dassert(target == backend->server());
MXS_INFO("Re-routing failed read after server '%s' failed", backend->name());
MXS_SESSION* session = m_client->session;
// Try to route the failed read as often as possible
session_delay_routing(session, router_as_downstream(session), stored, 1);
}
else

View File

@ -127,6 +127,7 @@ public:
uint32_t m_next_seq; /**< Next packet's sequence number */
mxs::QueryClassifier m_qc; /**< The query classifier. */
uint64_t m_retry_duration; /**< Total time spent retrying queries */
GWBUF* m_current_query; /**< Current query being executed, NULL for no query */
private:
RWSplitSession(RWSplit* instance, MXS_SESSION* session,
@ -191,6 +192,37 @@ private:
m_retry_duration < m_config.query_retry_timeout &&
!session_trx_is_active(m_client->session);
}
/**
* Set the current query
*
* @param query The current query
*/
inline void set_query(GWBUF* query)
{
ss_dassert(!m_current_query);
m_current_query = gwbuf_clone(query);
}
/**
* Release current query
*
* @return The current query
*/
inline GWBUF* release_query()
{
GWBUF* rval = m_current_query;
m_current_query = NULL;
return rval;
}
/**
* Reset current query
*/
inline void reset_query()
{
gwbuf_free(release_query());
}
};
/**