From 45e0e8bb595ce608a57aed93a33b2db6bba54267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 12 Sep 2017 03:40:42 +0300 Subject: [PATCH] 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. --- examples/roundrobinrouter.cpp | 10 +- include/maxscale/protocol/mysql.h | 59 ++++++-- .../qc_mysqlembedded/qc_mysqlembedded.cc | 5 - query_classifier/qc_sqlite/qc_sqlite.cc | 6 +- query_classifier/test/compare.cc | 4 - query_classifier/test/version_sensitivity.cc | 3 - server/core/backend.cc | 8 +- server/core/modutil.cc | 128 +++++++++--------- .../filter/cache/cachefiltersession.cc | 12 +- .../modules/filter/dbfwfilter/dbfwfilter.cc | 14 +- .../filter/insertstream/insertstream.c | 2 +- .../filter/masking/maskingfiltersession.cc | 8 +- server/modules/filter/maxrows/maxrows.c | 4 +- .../MySQL/MySQLBackend/mysql_backend.c | 18 +-- .../MySQL/MySQLClient/mysql_client.cc | 18 +-- .../MySQL/MySQLClient/setsqlmodeparser.hh | 2 +- server/modules/protocol/MySQL/mysql_common.c | 40 +++--- .../modules/routing/binlogrouter/blr_master.c | 6 +- server/modules/routing/maxinfo/maxinfo.c | 8 +- server/modules/routing/maxinfo/maxinfo.h | 7 - .../routing/readconnroute/readconnroute.c | 8 +- .../routing/readwritesplit/readwritesplit.cc | 10 +- .../readwritesplit/rwsplit_internal.hh | 10 +- .../routing/readwritesplit/rwsplit_mysql.cc | 48 +++---- .../routing/readwritesplit/rwsplit_ps.cc | 10 +- .../readwritesplit/rwsplit_route_stmt.cc | 18 +-- .../readwritesplit/rwsplit_session_cmd.cc | 4 +- .../readwritesplit/rwsplit_tmp_table_multi.cc | 2 +- .../schemarouter/schemaroutersession.cc | 56 ++++---- 29 files changed, 272 insertions(+), 256 deletions(-) diff --git a/examples/roundrobinrouter.cpp b/examples/roundrobinrouter.cpp index 5b7640fcf..e22717071 100644 --- a/examples/roundrobinrouter.cpp +++ b/examples/roundrobinrouter.cpp @@ -485,7 +485,7 @@ void RRRouterSession::close() void RRRouter::decide_target(RRRouterSession* rses, GWBUF* querybuf, DCB*& target, bool& route_to_all) { /* Extract the command type from the SQL-buffer */ - mysql_server_cmd_t cmd_type = MYSQL_GET_COMMAND(GWBUF_DATA(querybuf)); + mxs_mysql_cmd_t cmd_type = MYSQL_GET_COMMAND(GWBUF_DATA(querybuf)); /* The "query_types" is only really valid for query-commands but let's use * it here for all command types. */ @@ -493,7 +493,7 @@ void RRRouter::decide_target(RRRouterSession* rses, GWBUF* querybuf, DCB*& targe switch (cmd_type) { - case MYSQL_COM_QUERY: + case MXS_COM_QUERY: { /* Use the inbuilt query_classifier to get information about * the query. The default qc works with mySQL-queries. @@ -509,15 +509,15 @@ void RRRouter::decide_target(RRRouterSession* rses, GWBUF* querybuf, DCB*& targe #endif } break; - case MYSQL_COM_INIT_DB: + case MXS_COM_INIT_DB: query_types = q_route_to_all; RR_DEBUG("MYSQL_COM_INIT_DB"); break; - case MYSQL_COM_QUIT: + case MXS_COM_QUIT: query_types = q_route_to_all; RR_DEBUG("MYSQL_COM_QUIT"); break; - case MYSQL_COM_FIELD_LIST: + case MXS_COM_FIELD_LIST: query_types = q_route_to_rr; RR_DEBUG("MYSQL_COM_FIELD_LIST"); break; diff --git a/include/maxscale/protocol/mysql.h b/include/maxscale/protocol/mysql.h index 5e0aa2455..0f255ff83 100644 --- a/include/maxscale/protocol/mysql.h +++ b/include/maxscale/protocol/mysql.h @@ -261,9 +261,42 @@ typedef enum #define MXS_MARIA_CAP_COM_MULTI (1 << 1) #define MXS_MARIA_CAP_STMT_BULK_OPERATIONS (1 << 2) -typedef enum enum_server_command mysql_server_cmd_t; +typedef enum +{ + MXS_COM_SLEEP = 0, + MXS_COM_QUIT, + MXS_COM_INIT_DB, + MXS_COM_QUERY, + MXS_COM_FIELD_LIST, + MXS_COM_CREATE_DB, + MXS_COM_DROP_DB, + MXS_COM_REFRESH, + MXS_COM_SHUTDOWN, + MXS_COM_STATISTICS, + MXS_COM_PROCESS_INFO, + MXS_COM_CONNECT, + MXS_COM_PROCESS_KILL, + MXS_COM_DEBUG, + MXS_COM_PING, + MXS_COM_TIME = 15, + MXS_COM_DELAYED_INSERT, + MXS_COM_CHANGE_USER, + MXS_COM_BINLOG_DUMP, + MXS_COM_TABLE_DUMP, + MXS_COM_CONNECT_OUT = 20, + MXS_COM_REGISTER_SLAVE, + MXS_COM_STMT_PREPARE = 22, + MXS_COM_STMT_EXECUTE = 23, + MXS_COM_STMT_SEND_LONG_DATA = 24, + MXS_COM_STMT_CLOSE = 25, + MXS_COM_STMT_RESET = 26, + MXS_COM_SET_OPTION = 27, + MXS_COM_STMT_FETCH = 28, + MXS_COM_DAEMON, + MXS_COM_END +} mxs_mysql_cmd_t; -static const mysql_server_cmd_t MYSQL_COM_UNDEFINED = (mysql_server_cmd_t) - 1; +static const mxs_mysql_cmd_t MXS_COM_UNDEFINED = (mxs_mysql_cmd_t) - 1; /** * List of server commands, and number of response packets are stored here. @@ -272,7 +305,7 @@ static const mysql_server_cmd_t MYSQL_COM_UNDEFINED = (mysql_server_cmd_t) - 1; */ typedef struct server_command_st { - mysql_server_cmd_t scom_cmd; + mxs_mysql_cmd_t scom_cmd; int scom_nresponse_packets; /*< packets in response */ size_t scom_nbytes_to_read; /*< bytes left to read in current packet */ struct server_command_st* scom_next; @@ -291,7 +324,7 @@ typedef struct #endif int fd; /*< The socket descriptor */ struct dcb* owner_dcb; /*< The DCB of the socket we are running on */ - mysql_server_cmd_t current_command; /*< Current command being executed */ + mxs_mysql_cmd_t current_command; /*< Current command being executed */ server_command_t protocol_command; /*< session command list */ server_command_t* protocol_cmd_history; /*< session command history */ mxs_auth_state_t protocol_auth_state; /*< Authentication status */ @@ -325,9 +358,9 @@ typedef struct #define MYSQL_REPLY_LOCAL_INFILE 0xfb #define MYSQL_REPLY_AUTHSWITCHREQUEST 0xfe /**< Only sent during authentication */ -static inline mysql_server_cmd_t MYSQL_GET_COMMAND(const uint8_t* header) +static inline mxs_mysql_cmd_t MYSQL_GET_COMMAND(const uint8_t* header) { - return (mysql_server_cmd_t)header[4]; + return (mxs_mysql_cmd_t)header[4]; } static inline uint8_t MYSQL_GET_PACKET_NO(const uint8_t* header) @@ -352,18 +385,18 @@ static inline bool MYSQL_IS_ERROR_PACKET(const uint8_t* header) static inline bool MYSQL_IS_COM_QUIT(const uint8_t* header) { - return MYSQL_GET_COMMAND(header) == MYSQL_COM_QUIT && + return MYSQL_GET_COMMAND(header) == MXS_COM_QUIT && MYSQL_GET_PAYLOAD_LEN(header) == 1; } static inline bool MYSQL_IS_COM_INIT_DB(const uint8_t* header) { - return MYSQL_GET_COMMAND(header) == MYSQL_COM_INIT_DB; + return MYSQL_GET_COMMAND(header) == MXS_COM_INIT_DB; } static inline bool MYSQL_IS_CHANGE_USER(const uint8_t* header) { - return MYSQL_GET_COMMAND(header) == MYSQL_COM_CHANGE_USER; + return MYSQL_GET_COMMAND(header) == MXS_COM_CHANGE_USER; } /* The following can be compared using memcmp to detect a null password */ @@ -405,11 +438,11 @@ int mysql_send_auth_error ( GWBUF* gw_MySQL_get_next_packet(GWBUF** p_readbuf); GWBUF* gw_MySQL_get_packets(GWBUF** p_readbuf, int* npackets); -void protocol_add_srv_command(MySQLProtocol* p, mysql_server_cmd_t cmd); +void protocol_add_srv_command(MySQLProtocol* p, mxs_mysql_cmd_t cmd); void protocol_remove_srv_command(MySQLProtocol* p); bool protocol_waits_response(MySQLProtocol* p); -mysql_server_cmd_t protocol_get_srv_command(MySQLProtocol* p, bool removep); -int get_stmt_nresponse_packets(GWBUF* buf, mysql_server_cmd_t cmd); +mxs_mysql_cmd_t protocol_get_srv_command(MySQLProtocol* p, bool removep); +int get_stmt_nresponse_packets(GWBUF* buf, mxs_mysql_cmd_t cmd); bool protocol_get_response_status (MySQLProtocol* p, int* npackets, size_t* nbytes); void protocol_set_response_status (MySQLProtocol* p, int npackets, size_t nbytes); void protocol_archive_srv_command(MySQLProtocol* p); @@ -500,7 +533,7 @@ bool mxs_mysql_is_prep_stmt_ok(GWBUF *buffer); bool mxs_mysql_more_results_after_ok(GWBUF *buffer); /** Get current command for a session */ -mysql_server_cmd_t mxs_mysql_current_command(MXS_SESSION* session); +mxs_mysql_cmd_t mxs_mysql_current_command(MXS_SESSION* session); /** * @brief Calculate how many packets a session command will receive * diff --git a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc index 565e7d641..e398a343d 100644 --- a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc +++ b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc @@ -64,11 +64,6 @@ #include #include #include -// assumes it is being compiled agains Connector-C, -// so we need to make certain Connector-C constants visible. -#define MYSQL_COM_QUIT COM_QUIT -#define MYSQL_COM_INIT_DB COM_INIT_DB -#define MYSQL_COM_CHANGE_USER COM_CHANGE_USER #include #include #include diff --git a/query_classifier/qc_sqlite/qc_sqlite.cc b/query_classifier/qc_sqlite/qc_sqlite.cc index 3ca60fe2f..661aac4ab 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.cc +++ b/query_classifier/qc_sqlite/qc_sqlite.cc @@ -2670,7 +2670,7 @@ public: // Sequence id *ptr++ = 0x00; // Command - *ptr++ = MYSQL_COM_QUERY; + *ptr++ = MXS_COM_QUERY; memcpy(ptr, zStmt, preparable_stmt_len); } @@ -3430,7 +3430,7 @@ static bool parse_query(GWBUF* query, uint32_t collect) { uint8_t command = MYSQL_GET_COMMAND(data); - if ((command == MYSQL_COM_QUERY) || (command == MYSQL_COM_STMT_PREPARE)) + if ((command == MXS_COM_QUERY) || (command == MXS_COM_STMT_PREPARE)) { bool suppress_logging = false; @@ -3481,7 +3481,7 @@ static bool parse_query(GWBUF* query, uint32_t collect) this_thread.pInfo->m_pQuery = NULL; this_thread.pInfo->m_nQuery = 0; - if (command == MYSQL_COM_STMT_PREPARE) + if (command == MXS_COM_STMT_PREPARE) { pInfo->m_type_mask |= QUERY_TYPE_PREPARE_STMT; } diff --git a/query_classifier/test/compare.cc b/query_classifier/test/compare.cc index 86f6193ce..bb19165ca 100644 --- a/query_classifier/test/compare.cc +++ b/query_classifier/test/compare.cc @@ -21,10 +21,6 @@ #include #include #include -#define MYSQL_COM_QUERY COM_QUERY -#define MYSQL_COM_QUIT COM_QUIT -#define MYSQL_COM_INIT_DB COM_INIT_DB -#define MYSQL_COM_CHANGE_USER COM_CHANGE_USER #include #include #include diff --git a/query_classifier/test/version_sensitivity.cc b/query_classifier/test/version_sensitivity.cc index 867ff5cd2..9831b166b 100644 --- a/query_classifier/test/version_sensitivity.cc +++ b/query_classifier/test/version_sensitivity.cc @@ -12,9 +12,6 @@ */ #include -#define MYSQL_COM_QUIT COM_QUIT -#define MYSQL_COM_INIT_DB COM_INIT_DB -#define MYSQL_COM_CHANGE_USER COM_CHANGE_USER #include #include #include diff --git a/server/core/backend.cc b/server/core/backend.cc index 3ab16f860..3b658c967 100644 --- a/server/core/backend.cc +++ b/server/core/backend.cc @@ -91,20 +91,20 @@ bool Backend::execute_session_command() switch (sescmd.get_command()) { - case MYSQL_COM_QUIT: - case MYSQL_COM_STMT_CLOSE: + case MXS_COM_QUIT: + case MXS_COM_STMT_CLOSE: /** These commands do not generate responses */ rval = write(buffer, NO_RESPONSE); complete_session_command(); break; - case MYSQL_COM_CHANGE_USER: + case MXS_COM_CHANGE_USER: /** This makes it possible to handle replies correctly */ gwbuf_set_type(buffer, GWBUF_TYPE_SESCMD); rval = auth(buffer); break; - case MYSQL_COM_QUERY: + case MXS_COM_QUERY: default: /** * Mark session command buffer, it triggers writing diff --git a/server/core/modutil.cc b/server/core/modutil.cc index 820652b7b..fb40a646e 100644 --- a/server/core/modutil.cc +++ b/server/core/modutil.cc @@ -318,16 +318,16 @@ char * modutil_get_query(GWBUF *buf) { uint8_t* packet; - mysql_server_cmd_t packet_type; + mxs_mysql_cmd_t packet_type; size_t len; char* query_str = NULL; packet = GWBUF_DATA(buf); - packet_type = (mysql_server_cmd_t)packet[4]; + packet_type = (mxs_mysql_cmd_t)packet[4]; switch (packet_type) { - case MYSQL_COM_QUIT: + case MXS_COM_QUIT: len = strlen("[Quit msg]") + 1; if ((query_str = (char *)MXS_MALLOC(len + 1)) == NULL) { @@ -337,7 +337,7 @@ modutil_get_query(GWBUF *buf) memset(&query_str[len], 0, 1); break; - case MYSQL_COM_QUERY: + case MXS_COM_QUERY: len = MYSQL_GET_PAYLOAD_LEN(packet) - 1; /*< distract 1 for packet type byte */ if (len < 1 || len > ~(size_t)0 - 1 || (query_str = (char *)MXS_MALLOC(len + 1)) == NULL) { @@ -1334,66 +1334,66 @@ const char* STRPACKETTYPE(int p) { switch (p) { - case MYSQL_COM_SLEEP: - return "MYSQL_COM_SLEEP"; - case MYSQL_COM_QUIT: - return "MYSQL_COM_QUIT"; - case MYSQL_COM_INIT_DB: - return "MYSQL_COM_INIT_DB"; - case MYSQL_COM_QUERY: - return "MYSQL_COM_QUERY"; - case MYSQL_COM_FIELD_LIST: - return "MYSQL_COM_FIELD_LIST"; - case MYSQL_COM_CREATE_DB: - return "MYSQL_COM_CREATE_DB"; - case MYSQL_COM_DROP_DB: - return "MYSQL_COM_DROP_DB"; - case MYSQL_COM_REFRESH: - return "MYSQL_COM_REFRESH"; - case MYSQL_COM_SHUTDOWN: - return "MYSQL_COM_SHUTDOWN"; - case MYSQL_COM_STATISTICS: - return "MYSQL_COM_STATISTICS"; - case MYSQL_COM_PROCESS_INFO: - return "MYSQL_COM_PROCESS_INFO"; - case MYSQL_COM_CONNECT: - return "MYSQL_COM_CONNECT"; - case MYSQL_COM_PROCESS_KILL: - return "MYSQL_COM_PROCESS_KILL"; - case MYSQL_COM_DEBUG: - return "MYSQL_COM_DEBUG"; - case MYSQL_COM_PING: - return "MYSQL_COM_PING"; - case MYSQL_COM_TIME: - return "MYSQL_COM_TIME"; - case MYSQL_COM_DELAYED_INSERT: - return "MYSQL_COM_DELAYED_INSERT"; - case MYSQL_COM_CHANGE_USER: - return "MYSQL_COM_CHANGE_USER"; - case MYSQL_COM_BINLOG_DUMP: - return "MYSQL_COM_BINLOG_DUMP"; - case MYSQL_COM_TABLE_DUMP: - return "MYSQL_COM_TABLE_DUMP"; - case MYSQL_COM_CONNECT_OUT: - return "MYSQL_COM_CONNECT_OUT"; - case MYSQL_COM_REGISTER_SLAVE: - return "MYSQL_COM_REGISTER_SLAVE"; - case MYSQL_COM_STMT_PREPARE: - return "MYSQL_COM_STMT_PREPARE"; - case MYSQL_COM_STMT_EXECUTE: - return "MYSQL_COM_STMT_EXECUTE"; - case MYSQL_COM_STMT_SEND_LONG_DATA: - return "MYSQL_COM_STMT_SEND_LONG_DATA"; - case MYSQL_COM_STMT_CLOSE: - return "MYSQL_COM_STMT_CLOSE"; - case MYSQL_COM_STMT_RESET: - return "MYSQL_COM_STMT_RESET"; - case MYSQL_COM_SET_OPTION: - return "MYSQL_COM_SET_OPTION"; - case MYSQL_COM_STMT_FETCH: - return "MYSQL_COM_STMT_FETCH"; - case MYSQL_COM_DAEMON: - return "MYSQL_COM_DAEMON"; + case MXS_COM_SLEEP: + return "COM_SLEEP"; + case MXS_COM_QUIT: + return "COM_QUIT"; + case MXS_COM_INIT_DB: + return "COM_INIT_DB"; + case MXS_COM_QUERY: + return "COM_QUERY"; + case MXS_COM_FIELD_LIST: + return "COM_FIELD_LIST"; + case MXS_COM_CREATE_DB: + return "COM_CREATE_DB"; + case MXS_COM_DROP_DB: + return "COM_DROP_DB"; + case MXS_COM_REFRESH: + return "COM_REFRESH"; + case MXS_COM_SHUTDOWN: + return "COM_SHUTDOWN"; + case MXS_COM_STATISTICS: + return "COM_STATISTICS"; + case MXS_COM_PROCESS_INFO: + return "COM_PROCESS_INFO"; + case MXS_COM_CONNECT: + return "COM_CONNECT"; + case MXS_COM_PROCESS_KILL: + return "COM_PROCESS_KILL"; + case MXS_COM_DEBUG: + return "COM_DEBUG"; + case MXS_COM_PING: + return "COM_PING"; + case MXS_COM_TIME: + return "COM_TIME"; + case MXS_COM_DELAYED_INSERT: + return "COM_DELAYED_INSERT"; + case MXS_COM_CHANGE_USER: + return "COM_CHANGE_USER"; + case MXS_COM_BINLOG_DUMP: + return "COM_BINLOG_DUMP"; + case MXS_COM_TABLE_DUMP: + return "COM_TABLE_DUMP"; + case MXS_COM_CONNECT_OUT: + return "COM_CONNECT_OUT"; + case MXS_COM_REGISTER_SLAVE: + return "COM_REGISTER_SLAVE"; + case MXS_COM_STMT_PREPARE: + return "COM_STMT_PREPARE"; + case MXS_COM_STMT_EXECUTE: + return "COM_STMT_EXECUTE"; + case MXS_COM_STMT_SEND_LONG_DATA: + return "COM_STMT_SEND_LONG_DATA"; + case MXS_COM_STMT_CLOSE: + return "COM_STMT_CLOSE"; + case MXS_COM_STMT_RESET: + return "COM_STMT_RESET"; + case MXS_COM_SET_OPTION: + return "COM_SET_OPTION"; + case MXS_COM_STMT_FETCH: + return "COM_STMT_FETCH"; + case MXS_COM_DAEMON: + return "COM_DAEMON"; } snprintf(unknow_type, sizeof(unknow_type), format_str, p); diff --git a/server/modules/filter/cache/cachefiltersession.cc b/server/modules/filter/cache/cachefiltersession.cc index 46aeb24a4..f47d04138 100644 --- a/server/modules/filter/cache/cachefiltersession.cc +++ b/server/modules/filter/cache/cachefiltersession.cc @@ -248,7 +248,7 @@ int CacheFilterSession::routeQuery(GWBUF* pPacket) switch ((int)MYSQL_GET_COMMAND(pData)) { - case MYSQL_COM_INIT_DB: + case MXS_COM_INIT_DB: { ss_dassert(!m_zUseDb); size_t len = MYSQL_GET_PAYLOAD_LEN(pData) - 1; // Remove the command byte. @@ -272,21 +272,21 @@ int CacheFilterSession::routeQuery(GWBUF* pPacket) } break; - case MYSQL_COM_STMT_PREPARE: + case MXS_COM_STMT_PREPARE: if (log_decisions()) { - MXS_NOTICE("MYSQL_COM_STMT_PREPARE, ignoring."); + MXS_NOTICE("COM_STMT_PREPARE, ignoring."); } break; - case MYSQL_COM_STMT_EXECUTE: + case MXS_COM_STMT_EXECUTE: if (log_decisions()) { - MXS_NOTICE("MYSQL_COM_STMT_EXECUTE, ignoring."); + MXS_NOTICE("COM_STMT_EXECUTE, ignoring."); } break; - case MYSQL_COM_QUERY: + case MXS_COM_QUERY: if (should_consult_cache(pPacket)) { if (m_pCache->should_store(m_zDefaultDb, pPacket)) diff --git a/server/modules/filter/dbfwfilter/dbfwfilter.cc b/server/modules/filter/dbfwfilter/dbfwfilter.cc index ab959ff36..9db364770 100644 --- a/server/modules/filter/dbfwfilter/dbfwfilter.cc +++ b/server/modules/filter/dbfwfilter/dbfwfilter.cc @@ -1273,13 +1273,13 @@ static bool command_is_mandatory(const GWBUF *buffer) { switch (MYSQL_GET_COMMAND((uint8_t*)GWBUF_DATA(buffer))) { - case MYSQL_COM_QUIT: - case MYSQL_COM_PING: - case MYSQL_COM_CHANGE_USER: - case MYSQL_COM_SET_OPTION: - case MYSQL_COM_FIELD_LIST: - case MYSQL_COM_PROCESS_KILL: - case MYSQL_COM_PROCESS_INFO: + case MXS_COM_QUIT: + case MXS_COM_PING: + case MXS_COM_CHANGE_USER: + case MXS_COM_SET_OPTION: + case MXS_COM_FIELD_LIST: + case MXS_COM_PROCESS_KILL: + case MXS_COM_PROCESS_INFO: return true; default: diff --git a/server/modules/filter/insertstream/insertstream.c b/server/modules/filter/insertstream/insertstream.c index bec4b4327..86b6a35ec 100644 --- a/server/modules/filter/insertstream/insertstream.c +++ b/server/modules/filter/insertstream/insertstream.c @@ -606,7 +606,7 @@ static bool extract_insert_target(GWBUF *buffer, char* target, int len) { bool rval = false; - if (MYSQL_GET_COMMAND(GWBUF_DATA(buffer)) == MYSQL_COM_QUERY && + if (MYSQL_GET_COMMAND(GWBUF_DATA(buffer)) == MXS_COM_QUERY && qc_get_operation(buffer) == QUERY_OP_INSERT && only_implicit_values(buffer)) { diff --git a/server/modules/filter/masking/maskingfiltersession.cc b/server/modules/filter/masking/maskingfiltersession.cc index 7e8426648..653bce617 100644 --- a/server/modules/filter/masking/maskingfiltersession.cc +++ b/server/modules/filter/masking/maskingfiltersession.cc @@ -54,8 +54,8 @@ int MaskingFilterSession::routeQuery(GWBUF* pPacket) // TODO: Breaks if responses are not waited for, before the next request is sent. switch (request.command()) { - case MYSQL_COM_QUERY: - case MYSQL_COM_STMT_EXECUTE: + case MXS_COM_QUERY: + case MXS_COM_STMT_EXECUTE: m_res.reset(request.command(), m_filter.rules()); m_state = EXPECTING_RESPONSE; break; @@ -273,7 +273,7 @@ void MaskingFilterSession::mask_values(ComPacket& response) { switch (m_res.command()) { - case MYSQL_COM_QUERY: + case MXS_COM_QUERY: { ComQueryResponse::TextResultsetRow row(response, m_res.types()); @@ -301,7 +301,7 @@ void MaskingFilterSession::mask_values(ComPacket& response) } break; - case MYSQL_COM_STMT_EXECUTE: + case MXS_COM_STMT_EXECUTE: { ComQueryResponse::BinaryResultsetRow row(response, m_res.types()); diff --git a/server/modules/filter/maxrows/maxrows.c b/server/modules/filter/maxrows/maxrows.c index 54d043429..512e77376 100644 --- a/server/modules/filter/maxrows/maxrows.c +++ b/server/modules/filter/maxrows/maxrows.c @@ -354,8 +354,8 @@ static int routeQuery(MXS_FILTER *instance, switch ((int)MYSQL_GET_COMMAND(data)) { - case MYSQL_COM_QUERY: - case MYSQL_COM_STMT_EXECUTE: + case MXS_COM_QUERY: + case MXS_COM_STMT_EXECUTE: { /* Set input query only with MAXROWS_RETURN_ERR */ if (csdata->instance->config.m_return == MAXROWS_RETURN_ERR && diff --git a/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c index ae220e52a..519e1cadf 100644 --- a/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c +++ b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c @@ -387,7 +387,7 @@ static inline void prepare_for_write(DCB *dcb, GWBUF *buffer) if (GWBUF_IS_TYPE_SESCMD(buffer)) { - mysql_server_cmd_t cmd = mxs_mysql_get_command(buffer); + mxs_mysql_cmd_t cmd = mxs_mysql_get_command(buffer); protocol_add_srv_command(proto, cmd); } if (GWBUF_SHOULD_COLLECT_RESULT(buffer)) @@ -616,13 +616,13 @@ static inline bool session_ok_to_route(DCB *dcb) static inline bool expecting_resultset(MySQLProtocol *proto) { - return proto->current_command == MYSQL_COM_QUERY || - proto->current_command == MYSQL_COM_STMT_FETCH; + return proto->current_command == MXS_COM_QUERY || + proto->current_command == MXS_COM_STMT_FETCH; } static inline bool expecting_ps_response(MySQLProtocol *proto) { - return proto->current_command == MYSQL_COM_STMT_PREPARE; + return proto->current_command == MXS_COM_STMT_PREPARE; } static inline bool complete_ps_response(GWBUF *buffer) @@ -887,7 +887,7 @@ gw_read_and_write(DCB *dcb) * If protocol has session command set, concatenate whole * response into one buffer. */ - if (protocol_get_srv_command((MySQLProtocol *)dcb->protocol, true) != MYSQL_COM_UNDEFINED) + if (protocol_get_srv_command((MySQLProtocol *)dcb->protocol, true) != MXS_COM_UNDEFINED) { if (result_collected) { @@ -1139,14 +1139,14 @@ static int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue) case MXS_AUTH_STATE_COMPLETE: { uint8_t* ptr = GWBUF_DATA(queue); - mysql_server_cmd_t cmd = mxs_mysql_get_command(queue); + mxs_mysql_cmd_t cmd = mxs_mysql_get_command(queue); MXS_DEBUG("write to dcb %p fd %d protocol state %s.", dcb, dcb->fd, STRPROTOCOLSTATE(backend_protocol->protocol_auth_state)); prepare_for_write(dcb, queue); - if (cmd == MYSQL_COM_QUIT && dcb->server->persistpoolmax) + if (cmd == MXS_COM_QUIT && dcb->server->persistpoolmax) { /** We need to keep the pooled connections alive so we just ignore the COM_QUIT packet */ gwbuf_free(queue); @@ -1538,7 +1538,7 @@ static int gw_change_user(DCB *backend, * packet and add it to client's read buffer. */ protocol_add_srv_command((MySQLProtocol*)backend->protocol, - MYSQL_COM_CHANGE_USER); + MXS_COM_CHANGE_USER); modutil_reply_auth_error(backend, message, 0); rv = 1; } @@ -1601,7 +1601,7 @@ static GWBUF* process_response_data(DCB* dcb, */ while (nbytes_to_process != 0) { - mysql_server_cmd_t srvcmd; + mxs_mysql_cmd_t srvcmd; bool succp; srvcmd = protocol_get_srv_command(p, false); diff --git a/server/modules/protocol/MySQL/MySQLClient/mysql_client.cc b/server/modules/protocol/MySQL/MySQLClient/mysql_client.cc index 3dcf12fac..5cfec0092 100644 --- a/server/modules/protocol/MySQL/MySQLClient/mysql_client.cc +++ b/server/modules/protocol/MySQL/MySQLClient/mysql_client.cc @@ -808,7 +808,7 @@ static bool process_client_commands(DCB* dcb, int bytes_available, GWBUF** buffe if (protocol_is_idle(dcb)) { int pktlen; - uint8_t cmd = (uint8_t)MYSQL_COM_QUERY; // Treat empty packets as COM_QUERY + uint8_t cmd = (uint8_t)MXS_COM_QUERY; // Treat empty packets as COM_QUERY /** * Buffer has at least 5 bytes, the packet is in contiguous memory @@ -861,7 +861,7 @@ static bool process_client_commands(DCB* dcb, int bytes_available, GWBUF** buffe if (dcb->protocol_packet_length - MYSQL_HEADER_LEN != GW_MYSQL_MAX_PACKET_LEN) { /** We're processing the first packet of a command */ - proto->current_command = (mysql_server_cmd_t)cmd; + proto->current_command = (mxs_mysql_cmd_t)cmd; } dcb->protocol_packet_length = pktlen + MYSQL_HEADER_LEN; @@ -1041,7 +1041,7 @@ gw_read_finish_processing(DCB *dcb, GWBUF *read_buffer, uint64_t capabilities) /** Reset error handler when routing of the new query begins */ dcb->dcb_errhandle_called = false; - if (proto->current_command == MYSQL_COM_QUIT) + if (proto->current_command == MXS_COM_QUIT) { /** The client is closing the connection. We know that this will be the * last command the client sends so the backend connections are very likely @@ -1089,7 +1089,7 @@ gw_read_finish_processing(DCB *dcb, GWBUF *read_buffer, uint64_t capabilities) MXS_ERROR("Routing the query failed. Session will be closed."); } - if (proto->current_command == MYSQL_COM_QUIT) + if (proto->current_command == MXS_COM_QUIT) { /** Close router session which causes closing of backends */ dcb_close(dcb); @@ -1458,7 +1458,7 @@ static int route_by_statement(MXS_SESSION* session, uint64_t capabilities, GWBUF CHK_GWBUF(packetbuf); MySQLProtocol* proto = (MySQLProtocol*)session->client_dcb->protocol; - proto->current_command = (mysql_server_cmd_t)mxs_mysql_get_command(packetbuf); + proto->current_command = (mxs_mysql_cmd_t)mxs_mysql_get_command(packetbuf); /** * This means that buffer includes exactly one MySQL @@ -1500,7 +1500,7 @@ static int route_by_statement(MXS_SESSION* session, uint64_t capabilities, GWBUF session_set_trx_state(session, SESSION_TRX_INACTIVE); } - if (mxs_mysql_get_command(packetbuf) == MYSQL_COM_QUERY) + if (mxs_mysql_get_command(packetbuf) == MXS_COM_QUERY) { uint32_t type = qc_get_trx_type_mask(packetbuf); @@ -1635,7 +1635,7 @@ static spec_com_res_t process_special_commands(DCB *dcb, GWBUF *read_buffer, int MySQLProtocol *proto = (MySQLProtocol*)dcb->protocol; uint8_t opt; - if (proto->current_command == MYSQL_COM_SET_OPTION && + if (proto->current_command == MXS_COM_SET_OPTION && gwbuf_copy_data(read_buffer, MYSQL_HEADER_LEN + 2, 1, &opt)) { if (opt) @@ -1650,7 +1650,7 @@ static spec_com_res_t process_special_commands(DCB *dcb, GWBUF *read_buffer, int /** * Handle COM_PROCESS_KILL */ - else if (proto->current_command == MYSQL_COM_PROCESS_KILL) + else if (proto->current_command == MXS_COM_PROCESS_KILL) { /* Make sure we have a complete SQL packet before trying to read the * process id. If not, try again next time. */ @@ -1672,7 +1672,7 @@ static spec_com_res_t process_special_commands(DCB *dcb, GWBUF *read_buffer, int } } } - else if (proto->current_command == MYSQL_COM_QUERY) + else if (proto->current_command == MXS_COM_QUERY) { /* Limits on the length of the queries in which "KILL" is searched for. Reducing * LONGEST_KILL will reduce overhead but also limit the range of accepted queries. */ diff --git a/server/modules/protocol/MySQL/MySQLClient/setsqlmodeparser.hh b/server/modules/protocol/MySQL/MySQLClient/setsqlmodeparser.hh index 6ecfe96b7..73f63e711 100644 --- a/server/modules/protocol/MySQL/MySQLClient/setsqlmodeparser.hh +++ b/server/modules/protocol/MySQL/MySQLClient/setsqlmodeparser.hh @@ -115,7 +115,7 @@ public: uint8_t command = pPayload[0]; - if (command == MYSQL_COM_QUERY) + if (command == MXS_COM_QUERY) { const uint8_t* pStmt = &pPayload[1]; diff --git a/server/modules/protocol/MySQL/mysql_common.c b/server/modules/protocol/MySQL/mysql_common.c index 8e19005fc..40eb1b68f 100644 --- a/server/modules/protocol/MySQL/mysql_common.c +++ b/server/modules/protocol/MySQL/mysql_common.c @@ -27,7 +27,7 @@ uint8_t null_client_sha1[MYSQL_SCRAMBLE_LEN] = ""; -static server_command_t* server_command_init(server_command_t* srvcmd, mysql_server_cmd_t cmd); +static server_command_t* server_command_init(server_command_t* srvcmd, mxs_mysql_cmd_t cmd); /** * @brief Allocate a new MySQL_session @@ -74,8 +74,8 @@ MySQLProtocol* mysql_protocol_init(DCB* dcb, int fd) } p->protocol_state = MYSQL_PROTOCOL_ALLOC; p->protocol_auth_state = MXS_AUTH_STATE_INIT; - p->current_command = MYSQL_COM_UNDEFINED; - p->protocol_command.scom_cmd = MYSQL_COM_UNDEFINED; + p->current_command = MXS_COM_UNDEFINED; + p->protocol_command.scom_cmd = MXS_COM_UNDEFINED; p->protocol_command.scom_nresponse_packets = 0; p->protocol_command.scom_nbytes_to_read = 0; p->stored_query = NULL; @@ -584,7 +584,7 @@ GWBUF* gw_MySQL_get_packets(GWBUF** p_srcbuf, static server_command_t* server_command_init(server_command_t* srvcmd, - mysql_server_cmd_t cmd) + mxs_mysql_cmd_t cmd) { server_command_t* c; @@ -667,7 +667,7 @@ void protocol_archive_srv_command(MySQLProtocol* p) /** Remove from command list */ if (s1->scom_next == NULL) { - p->protocol_command.scom_cmd = MYSQL_COM_UNDEFINED; + p->protocol_command.scom_cmd = MXS_COM_UNDEFINED; } else { @@ -685,7 +685,7 @@ retblock: * to MySQLProtocol structure. It is removed when response has arrived. */ void protocol_add_srv_command(MySQLProtocol* p, - mysql_server_cmd_t cmd) + mxs_mysql_cmd_t cmd) { #if defined(EXTRA_SS_DEBUG) server_command_t* c; @@ -696,7 +696,7 @@ void protocol_add_srv_command(MySQLProtocol* p, return; } /** this is the only server command in protocol */ - if (p->protocol_command.scom_cmd == MYSQL_COM_UNDEFINED) + if (p->protocol_command.scom_cmd == MXS_COM_UNDEFINED) { /** write into structure */ server_command_init(&p->protocol_command, cmd); @@ -713,7 +713,7 @@ void protocol_add_srv_command(MySQLProtocol* p, c = &p->protocol_command; - while (c != NULL && c->scom_cmd != MYSQL_COM_UNDEFINED) + while (c != NULL && c->scom_cmd != MXS_COM_UNDEFINED) { MXS_INFO("fd %d : %d %s", p->owner_dcb->fd, @@ -743,7 +743,7 @@ void protocol_remove_srv_command(MySQLProtocol* p) #endif if (s->scom_next == NULL) { - p->protocol_command.scom_cmd = MYSQL_COM_UNDEFINED; + p->protocol_command.scom_cmd = MXS_COM_UNDEFINED; } else { @@ -752,10 +752,10 @@ void protocol_remove_srv_command(MySQLProtocol* p) } } -mysql_server_cmd_t protocol_get_srv_command(MySQLProtocol* p, +mxs_mysql_cmd_t protocol_get_srv_command(MySQLProtocol* p, bool removep) { - mysql_server_cmd_t cmd; + mxs_mysql_cmd_t cmd; cmd = p->protocol_command.scom_cmd; @@ -784,7 +784,7 @@ void mysql_num_response_packets(GWBUF *buf, uint8_t cmd, int *npackets, size_t * { switch (cmd) { - case MYSQL_COM_STMT_PREPARE: + case MXS_COM_STMT_PREPARE: gwbuf_copy_data(buf, 9, 2, readbuf); nparam = gw_mysql_get_byte2(readbuf); gwbuf_copy_data(buf, 11, 2, readbuf); @@ -792,9 +792,9 @@ void mysql_num_response_packets(GWBUF *buf, uint8_t cmd, int *npackets, size_t * *npackets = 1 + nparam + MXS_MIN(1, nparam) + nattr + MXS_MIN(nattr, 1); break; - case MYSQL_COM_QUIT: - case MYSQL_COM_STMT_SEND_LONG_DATA: - case MYSQL_COM_STMT_CLOSE: + case MXS_COM_QUIT: + case MXS_COM_STMT_SEND_LONG_DATA: + case MXS_COM_STMT_CLOSE: *npackets = 0; /*< these don't reply anything */ break; @@ -1611,7 +1611,7 @@ bool mxs_mysql_more_results_after_ok(GWBUF *buffer) return rval; } -mysql_server_cmd_t mxs_mysql_current_command(MXS_SESSION* session) +mxs_mysql_cmd_t mxs_mysql_current_command(MXS_SESSION* session) { MySQLProtocol* proto = (MySQLProtocol*)session->client_dcb->protocol; return proto->current_command; @@ -1681,8 +1681,8 @@ uint32_t mxs_mysql_extract_ps_id(GWBUF* buffer) bool mxs_mysql_command_will_respond(uint8_t cmd) { - return cmd != MYSQL_COM_STMT_SEND_LONG_DATA && - cmd != MYSQL_COM_QUIT && - cmd != MYSQL_COM_STMT_CLOSE && - cmd != MYSQL_COM_STMT_FETCH; + return cmd != MXS_COM_STMT_SEND_LONG_DATA && + cmd != MXS_COM_QUIT && + cmd != MXS_COM_STMT_CLOSE && + cmd != MXS_COM_STMT_FETCH; } diff --git a/server/modules/routing/binlogrouter/blr_master.c b/server/modules/routing/binlogrouter/blr_master.c index fbd12887c..e922ef894 100644 --- a/server/modules/routing/binlogrouter/blr_master.c +++ b/server/modules/routing/binlogrouter/blr_master.c @@ -684,7 +684,7 @@ blr_make_query(DCB *dcb, char *query) // This is hack to get the result set processing in order for binlogrouter MySQLProtocol *proto = (MySQLProtocol*)dcb->protocol; - proto->current_command = MYSQL_COM_QUERY; + proto->current_command = MXS_COM_QUERY; return buf; } @@ -753,7 +753,7 @@ blr_make_registration(ROUTER_INSTANCE *router) // This is hack to get the result set processing in order for binlogrouter MySQLProtocol *proto = (MySQLProtocol*)router->master->protocol; - proto->current_command = MYSQL_COM_REGISTER_SLAVE; + proto->current_command = MXS_COM_REGISTER_SLAVE; return buf; } @@ -805,7 +805,7 @@ blr_make_binlog_dump(ROUTER_INSTANCE *router) // This is hack to get the result set processing in order for binlogrouter MySQLProtocol *proto = (MySQLProtocol*)router->master->protocol; - proto->current_command = MYSQL_COM_BINLOG_DUMP; + proto->current_command = MXS_COM_BINLOG_DUMP; return buf; } diff --git a/server/modules/routing/maxinfo/maxinfo.c b/server/modules/routing/maxinfo/maxinfo.c index 8a26bf01d..0957d61dc 100644 --- a/server/modules/routing/maxinfo/maxinfo.c +++ b/server/modules/routing/maxinfo/maxinfo.c @@ -32,6 +32,7 @@ #include #include #include + #include #include #include @@ -49,6 +50,7 @@ #include #include #include +#include #include "../../../core/maxscale/modules.h" #include "../../../core/maxscale/monitor.h" @@ -345,13 +347,13 @@ execute(MXS_ROUTER *rinstance, MXS_ROUTER_SESSION *router_session, GWBUF *queue) { switch (MYSQL_COMMAND(queue)) { - case COM_PING: + case MXS_COM_PING: rc = maxinfo_ping(instance, session, queue); break; - case COM_STATISTICS: + case MXS_COM_STATISTICS: rc = maxinfo_statistics(instance, session, queue); break; - case COM_QUIT: + case MXS_COM_QUIT: break; default: MXS_ERROR("Unexpected MySQL command 0x%x", diff --git a/server/modules/routing/maxinfo/maxinfo.h b/server/modules/routing/maxinfo/maxinfo.h index 22d68d400..973091af8 100644 --- a/server/modules/routing/maxinfo/maxinfo.h +++ b/server/modules/routing/maxinfo/maxinfo.h @@ -100,13 +100,6 @@ typedef struct maxinfo_tree #define MYSQL_COMMAND(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4)) -/** - * MySQL protocol OpCodes needed for replication - */ -#define COM_QUIT 0x01 -#define COM_QUERY 0x03 -#define COM_STATISTICS 0x09 -#define COM_PING 0x0e /** * Token values for the tokeniser used by the parser for maxinfo diff --git a/server/modules/routing/readconnroute/readconnroute.c b/server/modules/routing/readconnroute/readconnroute.c index ad5906344..5e823376f 100644 --- a/server/modules/routing/readconnroute/readconnroute.c +++ b/server/modules/routing/readconnroute/readconnroute.c @@ -506,7 +506,7 @@ closeSession(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session) } /** Log routing failure due to closed session */ -static void log_closed_session(mysql_server_cmd_t mysql_command, bool is_closed, +static void log_closed_session(mxs_mysql_cmd_t mysql_command, bool is_closed, SERVER_REF *ref) { char msg[MAX_SERVER_ADDRESS_LEN + 200] = ""; // Extra space for message @@ -550,7 +550,7 @@ routeQuery(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session, GWBUF *queu int rc = 0; DCB* backend_dcb; MySQLProtocol *proto = (MySQLProtocol*)router_cli_ses->client_dcb->protocol; - mysql_server_cmd_t mysql_command = proto->current_command; + mxs_mysql_cmd_t mysql_command = proto->current_command; bool rses_is_closed; inst->stats.n_queries++; @@ -589,11 +589,11 @@ routeQuery(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session, GWBUF *queu switch (mysql_command) { - case MYSQL_COM_CHANGE_USER: + case MXS_COM_CHANGE_USER: rc = backend_dcb->func.auth(backend_dcb, NULL, backend_dcb->session, queue); break; - case MYSQL_COM_QUERY: + case MXS_COM_QUERY: if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO)) { trc = modutil_get_SQL(queue); diff --git a/server/modules/routing/readwritesplit/readwritesplit.cc b/server/modules/routing/readwritesplit/readwritesplit.cc index feabeeb08..85e37e63a 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.cc +++ b/server/modules/routing/readwritesplit/readwritesplit.cc @@ -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)) { diff --git a/server/modules/routing/readwritesplit/rwsplit_internal.hh b/server/modules/routing/readwritesplit/rwsplit_internal.hh index f343879c5..20180ff9b 100644 --- a/server/modules/routing/readwritesplit/rwsplit_internal.hh +++ b/server/modules/routing/readwritesplit/rwsplit_internal.hh @@ -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; } /* diff --git a/server/modules/routing/readwritesplit/rwsplit_mysql.cc b/server/modules/routing/readwritesplit/rwsplit_mysql.cc index 6c28eeb5a..3b66b78d6 100644 --- a/server/modules/routing/readwritesplit/rwsplit_mysql.cc +++ b/server/modules/routing/readwritesplit/rwsplit_mysql.cc @@ -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); } /* diff --git a/server/modules/routing/readwritesplit/rwsplit_ps.cc b/server/modules/routing/readwritesplit/rwsplit_ps.cc index 603c81ef4..c21a536ba 100644 --- a/server/modules/routing/readwritesplit/rwsplit_ps.cc +++ b/server/modules/routing/readwritesplit/rwsplit_ps.cc @@ -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; diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index a4ddeaaf5..2ce44c059 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -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) diff --git a/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc b/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc index 76bff79e6..035e65b85 100644 --- a/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc +++ b/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc @@ -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; diff --git a/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.cc b/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.cc index 1dddd5673..364914f78 100644 --- a/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.cc +++ b/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.cc @@ -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 */ diff --git a/server/modules/routing/schemarouter/schemaroutersession.cc b/server/modules/routing/schemarouter/schemaroutersession.cc index 51362a15c..3df8e79d7 100644 --- a/server/modules/routing/schemarouter/schemaroutersession.cc +++ b/server/modules/routing/schemarouter/schemaroutersession.cc @@ -137,46 +137,46 @@ static void inspect_query(GWBUF* pPacket, uint32_t* type, qc_query_op_t* op, uin 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_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_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_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_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 MXS_COM_CREATE_DB: /**< 5 DDL must go to the master */ + case MXS_COM_DROP_DB: /**< 6 DDL must go to the master */ *type = QUERY_TYPE_WRITE; break; - case MYSQL_COM_QUERY: + case MXS_COM_QUERY: *type = qc_get_type_mask(pPacket); *op = qc_get_operation(pPacket); break; - case MYSQL_COM_STMT_PREPARE: + case MXS_COM_STMT_PREPARE: *type = qc_get_type_mask(pPacket); *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; } @@ -221,8 +221,8 @@ SERVER* SchemaRouterSession::resolve_query_target(GWBUF* pPacket, * the current default database or to the first available server. */ target = get_shard_target(pPacket, type); - if ((target == NULL && command != MYSQL_COM_INIT_DB && m_current_db.length() == 0) || - command == MYSQL_COM_FIELD_LIST || + if ((target == NULL && command != MXS_COM_INIT_DB && m_current_db.length() == 0) || + command == MXS_COM_FIELD_LIST || m_current_db.length() == 0) { /** No current database and no databases in query or the database is @@ -352,7 +352,7 @@ int32_t SchemaRouterSession::routeQuery(GWBUF* pPacket) } /** The default database changes must be routed to a specific server */ - if (command == MYSQL_COM_INIT_DB || op == QUERY_OP_CHANGE_DB) + if (command == MXS_COM_INIT_DB || op == QUERY_OP_CHANGE_DB) { if (!change_current_db(m_current_db, m_shard, pPacket)) { @@ -664,7 +664,7 @@ bool extract_database(GWBUF* buf, char* str) plen = gw_mysql_get_byte3(packet) - 1; /** Copy database name from MySQL packet to session */ - if (mxs_mysql_get_command(buf) == MYSQL_COM_QUERY && + if (mxs_mysql_get_command(buf) == MXS_COM_QUERY && qc_get_operation(buf) == QUERY_OP_CHANGE_DB) { const char *delim = "` \n\t;"; @@ -1109,7 +1109,7 @@ void create_error_reply(char* fail_str, DCB* dcb) } /** - * Read new database name from MYSQL_COM_INIT_DB packet or a literal USE ... COM_QUERY + * Read new database name from COM_INIT_DB packet or a literal USE ... COM_QUERY * packet, check that it exists in the hashtable and copy its name to MYSQL_session. * * @param dest Destination where the database name will be written @@ -1419,7 +1419,7 @@ SERVER* SchemaRouterSession::get_shard_target(GWBUF* buffer, uint32_t qtype) SERVER *rval = NULL; bool has_dbs = false; /**If the query targets any database other than the current one*/ - if (mxs_mysql_get_command(buffer) == MYSQL_COM_QUERY) + if (mxs_mysql_get_command(buffer) == MXS_COM_QUERY) { bool uses_current_database = false; int n_tables = 0;