From dc338ff3f224563286edb83dfd8892ed509b2155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 4 Apr 2018 15:38:50 +0300 Subject: [PATCH] Move causal read reply processing into sub-function This makes the clientReply a lot easier to comprehend. --- .../routing/readwritesplit/rwsplitsession.cc | 27 +++++++++++++------ .../routing/readwritesplit/rwsplitsession.hh | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/server/modules/routing/readwritesplit/rwsplitsession.cc b/server/modules/routing/readwritesplit/rwsplitsession.cc index 0c4129b11..86db378a9 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.cc +++ b/server/modules/routing/readwritesplit/rwsplitsession.cc @@ -383,11 +383,9 @@ static void log_unexpected_response(DCB* dcb, GWBUF* buffer) } } -void RWSplitSession::clientReply(GWBUF *writebuf, DCB *backend_dcb) +bool RWSplitSession::handle_causal_read_reply(GWBUF *writebuf, SRWBackend& backend) { - DCB *client_dcb = backend_dcb->session->client_dcb; - - SRWBackend& backend = get_backend_from_dcb(backend_dcb); + bool rval = true; if (m_config.enable_causal_read && GWBUF_IS_REPLY_OK(writebuf) && @@ -403,18 +401,31 @@ void RWSplitSession::clientReply(GWBUF *writebuf, DCB *backend_dcb) if (m_wait_gtid_state == EXPECTING_WAIT_GTID_RESULT) { - ss_dassert(m_config.enable_causal_read); if ((writebuf = discard_master_wait_gtid_result(writebuf)) == NULL) { - // Nothing to route, return - return; + rval = false; } } - if (m_wait_gtid_state == EXPECTING_REAL_RESULT) + + if (rval && m_wait_gtid_state == EXPECTING_REAL_RESULT) { correct_packet_sequence(writebuf); } + return rval; +} + +void RWSplitSession::clientReply(GWBUF *writebuf, DCB *backend_dcb) +{ + DCB *client_dcb = backend_dcb->session->client_dcb; + + SRWBackend& backend = get_backend_from_dcb(backend_dcb); + + if (!handle_causal_read_reply(writebuf, backend)) + { + return; // Nothing to route, return + } + if (backend->get_reply_state() == REPLY_STATE_DONE) { /** If we receive an unexpected response from the server, the internal diff --git a/server/modules/routing/readwritesplit/rwsplitsession.hh b/server/modules/routing/readwritesplit/rwsplitsession.hh index edaae5c56..2e30542c9 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.hh +++ b/server/modules/routing/readwritesplit/rwsplitsession.hh @@ -159,6 +159,7 @@ private: void log_master_routing_failure(bool found, mxs::SRWBackend& old_master, mxs::SRWBackend& curr_master); + bool handle_causal_read_reply(GWBUF *writebuf, mxs::SRWBackend& backend); GWBUF* add_prefix_wait_gtid(SERVER *server, GWBUF *origin); void correct_packet_sequence(GWBUF *buffer); GWBUF* discard_master_wait_gtid_result(GWBUF *buffer);