From 24b438c9b69f8e1da96254846dadc2ab9dfed9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 25 Sep 2018 12:49:02 +0300 Subject: [PATCH] MXS-2068: Split reply_is_complete into two functions By splitting the processing and state querying into two separate functions, the result can be inspected multiple times without triggering the result processing. --- include/maxscale/protocol/rwbackend.hh | 12 +++++++++++- server/modules/protocol/MySQL/rwbackend.cc | 16 ++++------------ server/modules/routing/cat/catsession.cc | 4 +++- .../routing/readwritesplit/rwsplitsession.cc | 4 +++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/maxscale/protocol/rwbackend.hh b/include/maxscale/protocol/rwbackend.hh index 1f15a51e4..a72602774 100644 --- a/include/maxscale/protocol/rwbackend.hh +++ b/include/maxscale/protocol/rwbackend.hh @@ -104,7 +104,17 @@ public: return m_local_infile_requested; } - bool reply_is_complete(GWBUF* buffer); + void process_reply(GWBUF* buffer); + + /** + * Check whether the response from the server is complete + * + * @return True if no more results are expected from this server + */ + bool reply_is_complete() const + { + return m_reply_state == REPLY_STATE_DONE; + } // Controlled by the session ResponseStat& response_stat(); diff --git a/server/modules/protocol/MySQL/rwbackend.cc b/server/modules/protocol/MySQL/rwbackend.cc index 70289a380..416716d60 100644 --- a/server/modules/protocol/MySQL/rwbackend.cc +++ b/server/modules/protocol/MySQL/rwbackend.cc @@ -137,14 +137,11 @@ static inline bool have_next_packet(GWBUF* buffer) } /** - * @brief Check if we have received a complete reply from the backend + * @brief Process a possibly partial response from the backend * - * @param backend Backend reference * @param buffer Buffer containing the response - * - * @return True if the complete response has been received */ -bool RWBackend::reply_is_complete(GWBUF* buffer) +void RWBackend::process_reply(GWBUF* buffer) { if (current_command() == MXS_COM_STMT_FETCH) { @@ -191,9 +188,9 @@ bool RWBackend::reply_is_complete(GWBUF* buffer) // TODO: Don't clone the buffer GWBUF* tmp = gwbuf_clone(buffer); tmp = gwbuf_consume(tmp, mxs_mysql_get_packet_len(tmp)); - bool rval = reply_is_complete(tmp); + process_reply(tmp); gwbuf_free(tmp); - return rval; + return; } } } @@ -245,15 +242,10 @@ bool RWBackend::reply_is_complete(GWBUF* buffer) } } - bool rval = false; - if (get_reply_state() == REPLY_STATE_DONE) { ack_write(); - rval = true; } - - return rval; } ResponseStat& RWBackend::response_stat() diff --git a/server/modules/routing/cat/catsession.cc b/server/modules/routing/cat/catsession.cc index 049b62de2..eb6c97185 100644 --- a/server/modules/routing/cat/catsession.cc +++ b/server/modules/routing/cat/catsession.cc @@ -72,7 +72,9 @@ void CatSession::clientReply(GWBUF* pPacket, DCB* pDcb) mxb_assert(backend->dcb() == pDcb); bool send = false; - if (backend->reply_is_complete(pPacket)) + backend->process_reply(pPacket); + + if (backend->reply_is_complete()) { m_completed++; m_current++; diff --git a/server/modules/routing/readwritesplit/rwsplitsession.cc b/server/modules/routing/readwritesplit/rwsplitsession.cc index 25c38e138..2cf2aee72 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.cc +++ b/server/modules/routing/readwritesplit/rwsplitsession.cc @@ -560,7 +560,9 @@ void RWSplitSession::clientReply(GWBUF* writebuf, DCB* backend_dcb) m_current_query.reset(); } - if (backend->reply_is_complete(writebuf)) + backend->process_reply(writebuf); + + if (backend->reply_is_complete()) { /** Got a complete reply, decrement expected response count */ m_expected_responses--;