diff --git a/include/maxscale/queryclassifier.hh b/include/maxscale/queryclassifier.hh index 4bbfb7418..3262c71d0 100644 --- a/include/maxscale/queryclassifier.hh +++ b/include/maxscale/queryclassifier.hh @@ -63,14 +63,10 @@ public: LOAD_DATA_END /**< Current query contains an empty packet that ends the load */ }; - QueryClassifier(MXS_SESSION* pSession, + QueryClassifier(Handler* pHandler, + MXS_SESSION* pSession, mxs_target_t use_sql_variables_in); - void set_handler(Handler* pHandler) // TODO: Eventually to be set in constructor - { - m_pHandler = pHandler; - } - Handler* handler() const { return m_pHandler; diff --git a/server/core/queryclassifier.cc b/server/core/queryclassifier.cc index be543260e..fdc694898 100644 --- a/server/core/queryclassifier.cc +++ b/server/core/queryclassifier.cc @@ -197,9 +197,10 @@ private: // QueryClassifier // -QueryClassifier::QueryClassifier(MXS_SESSION* pSession, +QueryClassifier::QueryClassifier(Handler* pHandler, + MXS_SESSION* pSession, mxs_target_t use_sql_variables_in) - : m_pHandler(NULL) + : m_pHandler(pHandler) , m_pSession(pSession) , m_use_sql_variables_in(use_sql_variables_in) , m_load_data_state(LOAD_DATA_INACTIVE) diff --git a/server/modules/routing/readwritesplit/routeinfo.cc b/server/modules/routing/readwritesplit/routeinfo.cc index 607978333..b396088fc 100644 --- a/server/modules/routing/readwritesplit/routeinfo.cc +++ b/server/modules/routing/readwritesplit/routeinfo.cc @@ -630,7 +630,6 @@ RouteInfo::RouteInfo(RWSplitSession* rses, GWBUF* buffer) , command(0xff) , type(QUERY_TYPE_UNKNOWN) , stmt_id(0) - , m_rses(rses) { ss_dassert(rses); ss_dassert(rses->m_client); @@ -652,28 +651,5 @@ RouteInfo::RouteInfo(RWSplitSession* rses, GWBUF* buffer) current_target = QueryClassifier::CURRENT_TARGET_SLAVE; } - m_rses->qc().set_handler(this); target = get_target_type(rses->qc(), current_target, buffer, &command, &type, &stmt_id); - m_rses->qc().set_handler(NULL); - - m_rses = NULL; -} - - -bool RouteInfo::lock_to_master() -{ - bool rv = false; - - if (m_rses->m_current_master && m_rses->m_current_master->in_use()) - { - m_rses->m_target_node = m_rses->m_current_master; - rv = true; - } - - return rv; -} - -bool RouteInfo::is_locked_to_master() const -{ - return m_rses->m_target_node && m_rses->m_target_node == m_rses->m_current_master; } diff --git a/server/modules/routing/readwritesplit/routeinfo.hh b/server/modules/routing/readwritesplit/routeinfo.hh index a9f2084d6..9421a5d39 100644 --- a/server/modules/routing/readwritesplit/routeinfo.hh +++ b/server/modules/routing/readwritesplit/routeinfo.hh @@ -13,11 +13,10 @@ */ #include "readwritesplit.hh" -#include class RWSplitSession; -struct RouteInfo : private maxscale::QueryClassifier::Handler +struct RouteInfo { RouteInfo(RWSplitSession* rses, GWBUF* buffer); @@ -25,11 +24,4 @@ struct RouteInfo : private maxscale::QueryClassifier::Handler uint8_t command; /**< The command byte, 0xff for unknown commands */ uint32_t type; /**< The query type, QUERY_TYPE_UNKNOWN for unknown types*/ uint32_t stmt_id; /**< Prepared statement ID, 0 for unknown */ - -private: - bool lock_to_master(); - bool is_locked_to_master() const; - -private: - RWSplitSession* m_rses; }; diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index 5894f0ac8..44ce5cd9e 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -144,7 +144,7 @@ bool RWSplitSession::route_single_stmt(GWBUF *querybuf, const RouteInfo& info) uint8_t command = info.command; uint32_t qtype = info.type; route_target_t route_target = info.target; - bool not_locked_to_master = !locked_to_master(); + bool not_locked_to_master = !is_locked_to_master(); if (not_locked_to_master && mxs_mysql_is_ps_command(command)) { @@ -771,7 +771,7 @@ bool RWSplitSession::should_replace_master(SRWBackend& target) // We are not inside a transaction (also checks for autocommit=1) !session_trx_is_active(m_client->session) && // We are not locked to the old master - !locked_to_master(); + !is_locked_to_master(); } void RWSplitSession::replace_master(SRWBackend& target) diff --git a/server/modules/routing/readwritesplit/rwsplitsession.cc b/server/modules/routing/readwritesplit/rwsplitsession.cc index 2d15f4a85..a68200f60 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.cc +++ b/server/modules/routing/readwritesplit/rwsplitsession.cc @@ -36,7 +36,7 @@ RWSplitSession::RWSplitSession(RWSplit* instance, MXS_SESSION* session, m_gtid_pos(""), m_wait_gtid_state(EXPECTING_NOTHING), m_next_seq(0), - m_qc(session, instance->config().use_sql_variables_in) + m_qc(this, session, instance->config().use_sql_variables_in) { if (m_config.rw_max_slave_conn_percent) { @@ -737,3 +737,21 @@ void RWSplitSession::handle_error_reply_client(DCB *backend_dcb, GWBUF *errmsg) m_client->func.write(m_client, gwbuf_clone(errmsg)); } } + +bool RWSplitSession::lock_to_master() +{ + bool rv = false; + + if (m_current_master && m_current_master->in_use()) + { + m_target_node = m_current_master; + rv = true; + } + + return rv; +} + +bool RWSplitSession::is_locked_to_master() const +{ + return m_target_node && m_target_node == m_current_master; +} diff --git a/server/modules/routing/readwritesplit/rwsplitsession.hh b/server/modules/routing/readwritesplit/rwsplitsession.hh index 43889c059..09355c5bf 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.hh +++ b/server/modules/routing/readwritesplit/rwsplitsession.hh @@ -43,12 +43,16 @@ typedef std::tr1::unordered_map ExecMap; /** * The client session of a RWSplit instance */ -class RWSplitSession: public mxs::RouterSession +class RWSplitSession: public mxs::RouterSession, + private mxs::QueryClassifier::Handler { RWSplitSession(const RWSplitSession&) = delete; RWSplitSession& operator=(const RWSplitSession&) = delete; public: + virtual ~RWSplitSession() + { + } /** * Create a new router session @@ -173,6 +177,11 @@ private: { return m_qc.large_query() || (m_current_master && m_target_node == m_current_master); } + +private: + // QueryClassifier::Handler + bool lock_to_master(); + bool is_locked_to_master() const; }; /**