MXS-1625 Move RouteInfo to QueryClassifier

This commit is contained in:
Johan Wikman
2018-04-10 15:09:52 +03:00
parent 91b1ce39b8
commit 9be98df41c
7 changed files with 148 additions and 73 deletions

View File

@ -1,6 +1,5 @@
add_library(readwritesplit SHARED
readwritesplit.cc
routeinfo.cc
rwsplitsession.cc
rwsplit_mysql.cc
rwsplit_route_stmt.cc

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2016 MariaDB Corporation Ab
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
*
* Change Date: 2020-01-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#include "routeinfo.hh"
#include <maxscale/queryclassifier.hh>
#include "rwsplitsession.hh"
using namespace maxscale;
RouteInfo::RouteInfo(RWSplitSession* rses, GWBUF* buffer)
: target(RWSplitSession::TARGET_UNDEFINED)
, command(0xff)
, type(QUERY_TYPE_UNKNOWN)
, stmt_id(0)
{
ss_dassert(rses);
ss_dassert(rses->m_client);
ss_dassert(rses->m_client->data);
ss_dassert(buffer);
QueryClassifier::current_target_t current_target;
if (rses->m_target_node == NULL)
{
current_target = QueryClassifier::CURRENT_TARGET_UNDEFINED;
}
else if (rses->m_target_node == rses->m_current_master)
{
current_target = QueryClassifier::CURRENT_TARGET_MASTER;
}
else
{
current_target = QueryClassifier::CURRENT_TARGET_SLAVE;
}
target = static_cast<route_target_t>(rses->qc().get_target_type(current_target,
buffer,
&command,
&type,
&stmt_id));
}

View File

@ -13,15 +13,6 @@
*/
#include "readwritesplit.hh"
#include <maxscale/queryclassifier.hh>
class RWSplitSession;
struct RouteInfo
{
RouteInfo(RWSplitSession* rses, GWBUF* buffer);
route_target_t target; /**< Route target type, TARGET_UNDEFINED for unknown */
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 */
};
typedef maxscale::QueryClassifier::RouteInfo RouteInfo;

View File

@ -150,10 +150,10 @@ void RWSplitSession::retry_query(GWBUF* querybuf)
bool RWSplitSession::route_single_stmt(GWBUF *querybuf, const RouteInfo& info)
{
bool succp = false;
uint32_t stmt_id = info.stmt_id;
uint8_t command = info.command;
uint32_t qtype = info.type;
route_target_t route_target = info.target;
uint32_t stmt_id = info.stmt_id();
uint8_t command = info.command();
uint32_t qtype = info.type_mask();
route_target_t route_target = info.target();
bool not_locked_to_master = !is_locked_to_master();
if (not_locked_to_master && mxs_mysql_is_ps_command(command))

View File

@ -122,7 +122,23 @@ int32_t RWSplitSession::routeQuery(GWBUF* querybuf)
m_qc.large_query()))
{
/** Gather the information required to make routing decisions */
RouteInfo info(this, querybuf);
QueryClassifier::current_target_t current_target;
if (m_target_node == NULL)
{
current_target = QueryClassifier::CURRENT_TARGET_UNDEFINED;
}
else if (m_target_node == m_current_master)
{
current_target = QueryClassifier::CURRENT_TARGET_MASTER;
}
else
{
current_target = QueryClassifier::CURRENT_TARGET_SLAVE;
}
RouteInfo info = m_qc.update_route_info(current_target, querybuf);
/** No active or pending queries */
if (route_single_stmt(querybuf, info))