MXS-1625 Move determine_query_type() to QueryClassifier
This commit is contained in:
@ -201,6 +201,8 @@ public:
|
|||||||
|
|
||||||
void log_transaction_status(GWBUF *querybuf, uint32_t qtype);
|
void log_transaction_status(GWBUF *querybuf, uint32_t qtype);
|
||||||
|
|
||||||
|
static uint32_t determine_query_type(GWBUF *querybuf, int command);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class PSManager;
|
class PSManager;
|
||||||
typedef std::shared_ptr<PSManager> SPSManager;
|
typedef std::shared_ptr<PSManager> SPSManager;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,68 +23,6 @@ using mxs::QueryClassifier;
|
|||||||
namespace
|
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
|
* If query is of type QUERY_TYPE_CREATE_TMP_TABLE then find out
|
||||||
* the database and table name, create a hashvalue and
|
* the database and table name, create a hashvalue and
|
||||||
@ -414,7 +352,7 @@ route_target_t get_target_type(QueryClassifier& qc,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*type = determine_query_type(buffer, *command);
|
*type = QueryClassifier::determine_query_type(buffer, *command);
|
||||||
|
|
||||||
current_target = handle_multi_temp_and_load(qc,
|
current_target = handle_multi_temp_and_load(qc,
|
||||||
current_target,
|
current_target,
|
||||||
|
Reference in New Issue
Block a user