From c8673bc0b394dc16b776fc29999c40e1676abbbb Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 9 Apr 2018 13:46:22 +0300 Subject: [PATCH] MXS-1625 Move determine_query_type() to QueryClassifier --- include/maxscale/queryclassifier.hh | 2 + server/core/queryclassifier.cc | 52 +++++++++++++++ .../routing/readwritesplit/routeinfo.cc | 64 +------------------ 3 files changed, 55 insertions(+), 63 deletions(-) diff --git a/include/maxscale/queryclassifier.hh b/include/maxscale/queryclassifier.hh index 4a3f9d853..26c6eea58 100644 --- a/include/maxscale/queryclassifier.hh +++ b/include/maxscale/queryclassifier.hh @@ -201,6 +201,8 @@ public: void log_transaction_status(GWBUF *querybuf, uint32_t qtype); + static uint32_t determine_query_type(GWBUF *querybuf, int command); + private: class PSManager; typedef std::shared_ptr SPSManager; diff --git a/server/core/queryclassifier.cc b/server/core/queryclassifier.cc index d639fdf55..6a1710516 100644 --- a/server/core/queryclassifier.cc +++ b/server/core/queryclassifier.cc @@ -518,6 +518,58 @@ void QueryClassifier::log_transaction_status(GWBUF *querybuf, uint32_t qtype) } } +uint32_t QueryClassifier::determine_query_type(GWBUF *querybuf, int command) +{ + uint32_t type = QUERY_TYPE_UNKNOWN; + + switch (command) + { + 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 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 MXS_COM_QUERY: + type = qc_get_type_mask(querybuf); + break; + + case MXS_COM_STMT_PREPARE: + type = qc_get_type_mask(querybuf); + type |= QUERY_TYPE_PREPARE_STMT; + break; + + case MXS_COM_STMT_EXECUTE: + /** Parsing is not needed for this type of packet */ + type = QUERY_TYPE_EXEC_STMT; + break; + + 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; + } + + return type; +} } diff --git a/server/modules/routing/readwritesplit/routeinfo.cc b/server/modules/routing/readwritesplit/routeinfo.cc index ac9688c7c..19edd6075 100644 --- a/server/modules/routing/readwritesplit/routeinfo.cc +++ b/server/modules/routing/readwritesplit/routeinfo.cc @@ -23,68 +23,6 @@ using mxs::QueryClassifier; namespace { -/** - * @brief Determine the type of a query - * - * @param querybuf GWBUF containing the query - * @param packet_type Integer denoting DB specific enum - * @param non_empty_packet Boolean to be set by this function - * - * @return uint32_t the query type; also the non_empty_packet bool is set - */ -uint32_t determine_query_type(GWBUF *querybuf, int command) -{ - uint32_t type = QUERY_TYPE_UNKNOWN; - - switch (command) - { - 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 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 MXS_COM_QUERY: - type = qc_get_type_mask(querybuf); - break; - - case MXS_COM_STMT_PREPARE: - type = qc_get_type_mask(querybuf); - type |= QUERY_TYPE_PREPARE_STMT; - break; - - case MXS_COM_STMT_EXECUTE: - /** Parsing is not needed for this type of packet */ - type = QUERY_TYPE_EXEC_STMT; - break; - - 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; - } - - return type; -} - /** * If query is of type QUERY_TYPE_CREATE_TMP_TABLE then find out * the database and table name, create a hashvalue and @@ -414,7 +352,7 @@ route_target_t get_target_type(QueryClassifier& qc, } else { - *type = determine_query_type(buffer, *command); + *type = QueryClassifier::determine_query_type(buffer, *command); current_target = handle_multi_temp_and_load(qc, current_target,