From 2e809524d1b77f1ff7527232cceb393ccea624b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 28 Jan 2019 11:52:21 +0200 Subject: [PATCH] MXS-2295: Reset session commands on connection reset When the connection state is reset by executing a COM_CHANGE_USER or COM_RESET_CONNECTION, readwritesplit does not need to store the session command history that was executed before it. With this, pooled connections will effectively behave like normal connections if the pooling mechanism is smart enough to reset the connection. This also prevents unwanted visibility into the session states of other connections. --- include/maxscale/protocol/mysql.h | 5 ++++- .../routing/readwritesplit/rwsplit_session_cmd.cc | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/maxscale/protocol/mysql.h b/include/maxscale/protocol/mysql.h index bd4edf090..9c8ff0783 100644 --- a/include/maxscale/protocol/mysql.h +++ b/include/maxscale/protocol/mysql.h @@ -299,8 +299,11 @@ typedef enum MXS_COM_STMT_RESET = 26, MXS_COM_SET_OPTION = 27, MXS_COM_STMT_FETCH = 28, + MXS_COM_DAEMON = 29, + MXS_COM_UNSUPPORTED = 30, + MXS_COM_RESET_CONNECTION = 31, MXS_COM_STMT_BULK_EXECUTE = 0xfa, - MXS_COM_DAEMON, + MXS_COM_MULTI = 0xfe, MXS_COM_END } mxs_mysql_cmd_t; diff --git a/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc b/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc index fb3aea782..b709ff4a9 100644 --- a/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc +++ b/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc @@ -161,5 +161,18 @@ void RWSplitSession::process_sescmd_response(SRWBackend& backend, GWBUF** ppPack gwbuf_free(*ppPacket); *ppPacket = NULL; } + + if (m_expected_responses == 0 + && (command == MXS_COM_CHANGE_USER || command == MXS_COM_RESET_CONNECTION)) + { + // This is the last session command to finish that resets the session state, reset the history + MXS_INFO("Resetting session command history (length: %lu)", m_sescmd_list.size()); + m_sescmd_list.clear(); + m_sescmd_responses.clear(); + m_slave_responses.clear(); + m_recv_sescmd = 0; + m_sent_sescmd = 0; + m_sescmd_count = 1; + } } }