MXS-1625 Move QueryClassifier::Handler to RWSplitSession
This commit is contained in:
@ -63,14 +63,10 @@ public:
|
|||||||
LOAD_DATA_END /**< Current query contains an empty packet that ends the load */
|
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);
|
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
|
Handler* handler() const
|
||||||
{
|
{
|
||||||
return m_pHandler;
|
return m_pHandler;
|
||||||
|
@ -197,9 +197,10 @@ private:
|
|||||||
// QueryClassifier
|
// QueryClassifier
|
||||||
//
|
//
|
||||||
|
|
||||||
QueryClassifier::QueryClassifier(MXS_SESSION* pSession,
|
QueryClassifier::QueryClassifier(Handler* pHandler,
|
||||||
|
MXS_SESSION* pSession,
|
||||||
mxs_target_t use_sql_variables_in)
|
mxs_target_t use_sql_variables_in)
|
||||||
: m_pHandler(NULL)
|
: m_pHandler(pHandler)
|
||||||
, m_pSession(pSession)
|
, m_pSession(pSession)
|
||||||
, m_use_sql_variables_in(use_sql_variables_in)
|
, m_use_sql_variables_in(use_sql_variables_in)
|
||||||
, m_load_data_state(LOAD_DATA_INACTIVE)
|
, m_load_data_state(LOAD_DATA_INACTIVE)
|
||||||
|
@ -630,7 +630,6 @@ RouteInfo::RouteInfo(RWSplitSession* rses, GWBUF* buffer)
|
|||||||
, command(0xff)
|
, command(0xff)
|
||||||
, type(QUERY_TYPE_UNKNOWN)
|
, type(QUERY_TYPE_UNKNOWN)
|
||||||
, stmt_id(0)
|
, stmt_id(0)
|
||||||
, m_rses(rses)
|
|
||||||
{
|
{
|
||||||
ss_dassert(rses);
|
ss_dassert(rses);
|
||||||
ss_dassert(rses->m_client);
|
ss_dassert(rses->m_client);
|
||||||
@ -652,28 +651,5 @@ RouteInfo::RouteInfo(RWSplitSession* rses, GWBUF* buffer)
|
|||||||
current_target = QueryClassifier::CURRENT_TARGET_SLAVE;
|
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);
|
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;
|
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "readwritesplit.hh"
|
#include "readwritesplit.hh"
|
||||||
#include <maxscale/queryclassifier.hh>
|
|
||||||
|
|
||||||
class RWSplitSession;
|
class RWSplitSession;
|
||||||
|
|
||||||
struct RouteInfo : private maxscale::QueryClassifier::Handler
|
struct RouteInfo
|
||||||
{
|
{
|
||||||
RouteInfo(RWSplitSession* rses, GWBUF* buffer);
|
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 */
|
uint8_t command; /**< The command byte, 0xff for unknown commands */
|
||||||
uint32_t type; /**< The query type, QUERY_TYPE_UNKNOWN for unknown types*/
|
uint32_t type; /**< The query type, QUERY_TYPE_UNKNOWN for unknown types*/
|
||||||
uint32_t stmt_id; /**< Prepared statement ID, 0 for unknown */
|
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;
|
|
||||||
};
|
};
|
||||||
|
@ -144,7 +144,7 @@ bool RWSplitSession::route_single_stmt(GWBUF *querybuf, const RouteInfo& info)
|
|||||||
uint8_t command = info.command;
|
uint8_t command = info.command;
|
||||||
uint32_t qtype = info.type;
|
uint32_t qtype = info.type;
|
||||||
route_target_t route_target = info.target;
|
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))
|
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)
|
// We are not inside a transaction (also checks for autocommit=1)
|
||||||
!session_trx_is_active(m_client->session) &&
|
!session_trx_is_active(m_client->session) &&
|
||||||
// We are not locked to the old master
|
// We are not locked to the old master
|
||||||
!locked_to_master();
|
!is_locked_to_master();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RWSplitSession::replace_master(SRWBackend& target)
|
void RWSplitSession::replace_master(SRWBackend& target)
|
||||||
|
@ -36,7 +36,7 @@ RWSplitSession::RWSplitSession(RWSplit* instance, MXS_SESSION* session,
|
|||||||
m_gtid_pos(""),
|
m_gtid_pos(""),
|
||||||
m_wait_gtid_state(EXPECTING_NOTHING),
|
m_wait_gtid_state(EXPECTING_NOTHING),
|
||||||
m_next_seq(0),
|
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)
|
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));
|
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;
|
||||||
|
}
|
||||||
|
@ -43,12 +43,16 @@ typedef std::tr1::unordered_map<uint32_t, mxs::SRWBackend> ExecMap;
|
|||||||
/**
|
/**
|
||||||
* The client session of a RWSplit instance
|
* 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(const RWSplitSession&) = delete;
|
||||||
RWSplitSession& operator=(const RWSplitSession&) = delete;
|
RWSplitSession& operator=(const RWSplitSession&) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual ~RWSplitSession()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new router session
|
* Create a new router session
|
||||||
@ -173,6 +177,11 @@ private:
|
|||||||
{
|
{
|
||||||
return m_qc.large_query() || (m_current_master && m_target_node == m_current_master);
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user