Introduce internal protocol command enum
The enums exposed by the connector are not intended to be used by the users of the library. The fact that the protocol, and other, modules used it was in violation of how the library is intended to be used. Adding an internal mapping into MaxScale also removes some of the dependencies that the core has on the connector.
This commit is contained in:
@ -509,11 +509,11 @@ static bool route_stored_query(RWSplitSession *rses)
|
||||
*/
|
||||
bool reply_is_complete(SRWBackend backend, GWBUF *buffer)
|
||||
{
|
||||
mysql_server_cmd_t cmd = mxs_mysql_current_command(backend->dcb()->session);
|
||||
mxs_mysql_cmd_t cmd = mxs_mysql_current_command(backend->dcb()->session);
|
||||
|
||||
if (backend->get_reply_state() == REPLY_STATE_START && !mxs_mysql_is_result_set(buffer))
|
||||
{
|
||||
if (cmd == MYSQL_COM_STMT_PREPARE || !mxs_mysql_more_results_after_ok(buffer))
|
||||
if (cmd == MXS_COM_STMT_PREPARE || !mxs_mysql_more_results_after_ok(buffer))
|
||||
{
|
||||
/** Not a result set, we have the complete response */
|
||||
LOG_RS(backend, REPLY_STATE_DONE);
|
||||
@ -534,7 +534,7 @@ bool reply_is_complete(SRWBackend backend, GWBUF *buffer)
|
||||
LOG_RS(backend, REPLY_STATE_RSET_COLDEF);
|
||||
backend->set_reply_state(REPLY_STATE_RSET_COLDEF);
|
||||
}
|
||||
else if (n_eof == 1 && cmd != MYSQL_COM_FIELD_LIST)
|
||||
else if (n_eof == 1 && cmd != MXS_COM_FIELD_LIST)
|
||||
{
|
||||
/** Waiting for the EOF packet after the rows */
|
||||
LOG_RS(backend, REPLY_STATE_RSET_ROWS);
|
||||
@ -544,7 +544,7 @@ bool reply_is_complete(SRWBackend backend, GWBUF *buffer)
|
||||
{
|
||||
/** We either have a complete result set or a response to
|
||||
* a COM_FIELD_LIST command */
|
||||
ss_dassert(n_eof == 2 || (n_eof == 1 && cmd == MYSQL_COM_FIELD_LIST));
|
||||
ss_dassert(n_eof == 2 || (n_eof == 1 && cmd == MXS_COM_FIELD_LIST));
|
||||
LOG_RS(backend, REPLY_STATE_DONE);
|
||||
backend->set_reply_state(REPLY_STATE_DONE);
|
||||
|
||||
@ -894,7 +894,7 @@ static int routeQuery(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session,
|
||||
|
||||
if (rses->query_queue == NULL &&
|
||||
(rses->expected_responses == 0 ||
|
||||
info.command == MYSQL_COM_STMT_FETCH ||
|
||||
info.command == MXS_COM_STMT_FETCH ||
|
||||
rses->load_data_state == LOAD_DATA_ACTIVE ||
|
||||
rses->large_query))
|
||||
{
|
||||
|
||||
@ -33,11 +33,11 @@ do{ \
|
||||
|
||||
static inline bool is_ps_command(uint8_t cmd)
|
||||
{
|
||||
return cmd == MYSQL_COM_STMT_EXECUTE ||
|
||||
cmd == MYSQL_COM_STMT_SEND_LONG_DATA ||
|
||||
cmd == MYSQL_COM_STMT_CLOSE ||
|
||||
cmd == MYSQL_COM_STMT_FETCH ||
|
||||
cmd == MYSQL_COM_STMT_RESET;
|
||||
return cmd == MXS_COM_STMT_EXECUTE ||
|
||||
cmd == MXS_COM_STMT_SEND_LONG_DATA ||
|
||||
cmd == MXS_COM_STMT_CLOSE ||
|
||||
cmd == MXS_COM_STMT_FETCH ||
|
||||
cmd == MXS_COM_STMT_RESET;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -65,46 +65,46 @@ uint32_t determine_query_type(GWBUF *querybuf, int command)
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case MYSQL_COM_QUIT: /*< 1 QUIT will close all sessions */
|
||||
case MYSQL_COM_INIT_DB: /*< 2 DDL must go to the master */
|
||||
case MYSQL_COM_REFRESH: /*< 7 - I guess this is session but not sure */
|
||||
case MYSQL_COM_DEBUG: /*< 0d all servers dump debug info to stdout */
|
||||
case MYSQL_COM_PING: /*< 0e all servers are pinged */
|
||||
case MYSQL_COM_CHANGE_USER: /*< 11 all servers change it accordingly */
|
||||
case MYSQL_COM_SET_OPTION: /*< 1b send options to all servers */
|
||||
case MXS_COM_QUIT: /*< 1 QUIT will close all sessions */
|
||||
case MXS_COM_INIT_DB: /*< 2 DDL must go to the master */
|
||||
case MXS_COM_REFRESH: /*< 7 - I guess this is session but not sure */
|
||||
case MXS_COM_DEBUG: /*< 0d all servers dump debug info to stdout */
|
||||
case MXS_COM_PING: /*< 0e all servers are pinged */
|
||||
case MXS_COM_CHANGE_USER: /*< 11 all servers change it accordingly */
|
||||
case MXS_COM_SET_OPTION: /*< 1b send options to all servers */
|
||||
type = QUERY_TYPE_SESSION_WRITE;
|
||||
break;
|
||||
|
||||
case MYSQL_COM_CREATE_DB: /**< 5 DDL must go to the master */
|
||||
case MYSQL_COM_DROP_DB: /**< 6 DDL must go to the master */
|
||||
case MYSQL_COM_STMT_CLOSE: /*< free prepared statement */
|
||||
case MYSQL_COM_STMT_SEND_LONG_DATA: /*< send data to column */
|
||||
case MYSQL_COM_STMT_RESET: /*< resets the data of a prepared statement */
|
||||
case MXS_COM_CREATE_DB: /**< 5 DDL must go to the master */
|
||||
case MXS_COM_DROP_DB: /**< 6 DDL must go to the master */
|
||||
case MXS_COM_STMT_CLOSE: /*< free prepared statement */
|
||||
case MXS_COM_STMT_SEND_LONG_DATA: /*< send data to column */
|
||||
case MXS_COM_STMT_RESET: /*< resets the data of a prepared statement */
|
||||
type = QUERY_TYPE_WRITE;
|
||||
break;
|
||||
|
||||
case MYSQL_COM_QUERY:
|
||||
case MXS_COM_QUERY:
|
||||
type = qc_get_type_mask(querybuf);
|
||||
break;
|
||||
|
||||
case MYSQL_COM_STMT_PREPARE:
|
||||
case MXS_COM_STMT_PREPARE:
|
||||
type = qc_get_type_mask(querybuf);
|
||||
type |= QUERY_TYPE_PREPARE_STMT;
|
||||
break;
|
||||
|
||||
case MYSQL_COM_STMT_EXECUTE:
|
||||
case MXS_COM_STMT_EXECUTE:
|
||||
/** Parsing is not needed for this type of packet */
|
||||
type = QUERY_TYPE_EXEC_STMT;
|
||||
break;
|
||||
|
||||
case MYSQL_COM_SHUTDOWN: /**< 8 where should shutdown be routed ? */
|
||||
case MYSQL_COM_STATISTICS: /**< 9 ? */
|
||||
case MYSQL_COM_PROCESS_INFO: /**< 0a ? */
|
||||
case MYSQL_COM_CONNECT: /**< 0b ? */
|
||||
case MYSQL_COM_PROCESS_KILL: /**< 0c ? */
|
||||
case MYSQL_COM_TIME: /**< 0f should this be run in gateway ? */
|
||||
case MYSQL_COM_DELAYED_INSERT: /**< 10 ? */
|
||||
case MYSQL_COM_DAEMON: /**< 1d ? */
|
||||
case MXS_COM_SHUTDOWN: /**< 8 where should shutdown be routed ? */
|
||||
case MXS_COM_STATISTICS: /**< 9 ? */
|
||||
case MXS_COM_PROCESS_INFO: /**< 0a ? */
|
||||
case MXS_COM_CONNECT: /**< 0b ? */
|
||||
case MXS_COM_PROCESS_KILL: /**< 0c ? */
|
||||
case MXS_COM_TIME: /**< 0f should this be run in gateway ? */
|
||||
case MXS_COM_DELAYED_INSERT: /**< 10 ? */
|
||||
case MXS_COM_DAEMON: /**< 1d ? */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -129,7 +129,7 @@ uint32_t determine_query_type(GWBUF *querybuf, int command)
|
||||
bool
|
||||
is_packet_a_query(int packet_type)
|
||||
{
|
||||
return (packet_type == MYSQL_COM_QUERY);
|
||||
return (packet_type == MXS_COM_QUERY);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -23,7 +23,7 @@ uint32_t get_prepare_type(GWBUF* buffer)
|
||||
{
|
||||
uint32_t type;
|
||||
|
||||
if (mxs_mysql_get_command(buffer) == MYSQL_COM_STMT_PREPARE)
|
||||
if (mxs_mysql_get_command(buffer) == MXS_COM_STMT_PREPARE)
|
||||
{
|
||||
// TODO: This could be done inside the query classifier
|
||||
size_t packet_len = gwbuf_length(buffer);
|
||||
@ -38,7 +38,7 @@ uint32_t get_prepare_type(GWBUF* buffer)
|
||||
// Sequence id
|
||||
*ptr++ = 0x00;
|
||||
// Command
|
||||
*ptr++ = MYSQL_COM_QUERY;
|
||||
*ptr++ = MXS_COM_QUERY;
|
||||
|
||||
gwbuf_copy_data(buffer, MYSQL_HEADER_LEN + 1, payload_len - 1, ptr);
|
||||
type = qc_get_type_mask(stmt);
|
||||
@ -139,17 +139,17 @@ uint32_t PSManager::get_type(uint32_t id) const
|
||||
|
||||
void PSManager::store(GWBUF* buffer, uint32_t id)
|
||||
{
|
||||
ss_dassert(mxs_mysql_get_command(buffer) == MYSQL_COM_STMT_PREPARE ||
|
||||
ss_dassert(mxs_mysql_get_command(buffer) == MXS_COM_STMT_PREPARE ||
|
||||
qc_query_is_type(qc_get_type_mask(buffer),
|
||||
QUERY_TYPE_PREPARE_NAMED_STMT));
|
||||
|
||||
switch (mxs_mysql_get_command(buffer))
|
||||
{
|
||||
case MYSQL_COM_QUERY:
|
||||
case MXS_COM_QUERY:
|
||||
m_text_ps[get_text_ps_id(buffer)] = get_prepare_type(buffer);
|
||||
break;
|
||||
|
||||
case MYSQL_COM_STMT_PREPARE:
|
||||
case MXS_COM_STMT_PREPARE:
|
||||
m_binary_ps[id] = get_prepare_type(buffer);
|
||||
break;
|
||||
|
||||
|
||||
@ -139,7 +139,7 @@ route_target_t get_target_type(RWSplitSession *rses, GWBUF *buffer,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*command == MYSQL_COM_QUERY &&
|
||||
if (*command == MXS_COM_QUERY &&
|
||||
qc_get_operation(buffer) == QUERY_OP_EXECUTE)
|
||||
{
|
||||
std::string id = get_text_ps_id(buffer);
|
||||
@ -248,7 +248,7 @@ bool route_single_stmt(RWSplit *inst, RWSplitSession *rses, GWBUF *querybuf, con
|
||||
ss_dassert(!store_stmt || TARGET_IS_SLAVE(route_target));
|
||||
succp = handle_got_target(inst, rses, querybuf, target, store_stmt);
|
||||
|
||||
if (succp && command == MYSQL_COM_STMT_EXECUTE && not_locked_to_master)
|
||||
if (succp && command == MXS_COM_STMT_EXECUTE && not_locked_to_master)
|
||||
{
|
||||
/** Track the targets of the COM_STMT_EXECUTE statements. This
|
||||
* information is used to route all COM_STMT_FETCH commands
|
||||
@ -584,8 +584,8 @@ route_target_t get_route_target(RWSplitSession *rses, uint8_t command,
|
||||
*/
|
||||
if (qc_query_is_type(qtype, QUERY_TYPE_PREPARE_STMT) ||
|
||||
qc_query_is_type(qtype, QUERY_TYPE_PREPARE_NAMED_STMT) ||
|
||||
command == MYSQL_COM_STMT_CLOSE ||
|
||||
command == MYSQL_COM_STMT_RESET)
|
||||
command == MXS_COM_STMT_CLOSE ||
|
||||
command == MXS_COM_STMT_RESET)
|
||||
{
|
||||
target = TARGET_ALL;
|
||||
}
|
||||
@ -944,7 +944,7 @@ SRWBackend handle_slave_is_target(RWSplit *inst, RWSplitSession *rses,
|
||||
int rlag_max = rses_get_max_replication_lag(rses);
|
||||
SRWBackend target;
|
||||
|
||||
if (cmd == MYSQL_COM_STMT_FETCH)
|
||||
if (cmd == MXS_COM_STMT_FETCH)
|
||||
{
|
||||
/** The COM_STMT_FETCH must be executed on the same server as the
|
||||
* COM_STMT_EXECUTE was executed on */
|
||||
@ -1082,10 +1082,10 @@ bool handle_master_is_target(RWSplit *inst, RWSplitSession *rses,
|
||||
|
||||
static inline bool query_creates_reply(uint8_t cmd)
|
||||
{
|
||||
return cmd != MYSQL_COM_QUIT &&
|
||||
cmd != MYSQL_COM_STMT_SEND_LONG_DATA &&
|
||||
cmd != MYSQL_COM_STMT_CLOSE &&
|
||||
cmd != MYSQL_COM_STMT_FETCH; // Fetch is done mid-result
|
||||
return cmd != MXS_COM_QUIT &&
|
||||
cmd != MXS_COM_STMT_SEND_LONG_DATA &&
|
||||
cmd != MXS_COM_STMT_CLOSE &&
|
||||
cmd != MXS_COM_STMT_FETCH; // Fetch is done mid-result
|
||||
}
|
||||
|
||||
static inline bool is_large_query(GWBUF* buf)
|
||||
|
||||
@ -40,7 +40,7 @@ void process_sescmd_response(RWSplitSession* rses, SRWBackend& backend,
|
||||
uint64_t id = backend->complete_session_command();
|
||||
MXS_PS_RESPONSE resp = {};
|
||||
|
||||
if (command == MYSQL_COM_STMT_PREPARE)
|
||||
if (command == MXS_COM_STMT_PREPARE)
|
||||
{
|
||||
// This should never fail or the backend protocol is broken
|
||||
ss_debug(bool b = )mxs_mysql_extract_ps_response(*ppPacket, &resp);
|
||||
@ -60,7 +60,7 @@ void process_sescmd_response(RWSplitSession* rses, SRWBackend& backend,
|
||||
* be compared to it */
|
||||
rses->sescmd_responses[id] = cmd;
|
||||
|
||||
if (command == MYSQL_COM_STMT_PREPARE)
|
||||
if (command == MXS_COM_STMT_PREPARE)
|
||||
{
|
||||
/** Map the returned response to the internal ID */
|
||||
rses->ps_handles[resp.id] = id;
|
||||
|
||||
@ -197,7 +197,7 @@ bool check_for_multi_stmt(GWBUF *buf, void *protocol, uint8_t packet_type)
|
||||
bool rval = false;
|
||||
|
||||
if (proto->client_capabilities & GW_MYSQL_CAPABILITIES_MULTI_STATEMENTS &&
|
||||
packet_type == MYSQL_COM_QUERY)
|
||||
packet_type == MXS_COM_QUERY)
|
||||
{
|
||||
char *ptr, *data = (char*)GWBUF_DATA(buf) + 5;
|
||||
/** Payload size without command byte */
|
||||
|
||||
Reference in New Issue
Block a user