MXS-1625 Make as much private as possible in QueryClassifier

Some stuff that is manipulated from RWS must be left public
for the time being.
This commit is contained in:
Johan Wikman
2018-04-10 10:55:36 +03:00
parent 563a33ae56
commit d65af04d19
3 changed files with 73 additions and 64 deletions

View File

@ -72,14 +72,21 @@ public:
MXS_SESSION* pSession,
mxs_target_t use_sql_variables_in);
Handler* handler() const
void master_replaced()
{
return m_pHandler;
// As the master has changed, we can reset the temporary table information
set_have_tmp_tables(false);
clear_tmp_tables();
}
bool multi_statements_allowed() const
bool large_query() const
{
return m_multi_statements_allowed;
return m_large_query;
}
void set_large_query(bool large_query)
{
m_large_query = large_query;
}
load_data_state_t load_data_state() const
@ -92,6 +99,35 @@ public:
m_load_data_state = state;
}
/**
* @brief Store and process a prepared statement
*
* @param buffer Buffer containing either a text or a binary protocol
* prepared statement
* @param id The unique ID for this statement
*/
void ps_store(GWBUF* buffer, uint32_t id);
/**
* @brief Store a mapping from an external id to the corresponding internal id
*
* @param external_id The external id as seen by the client.
* @param internal_id The corresponding internal id.
*/
void ps_id_internal_put(uint32_t external_id, uint32_t internal_id);
uint32_t get_target_type(QueryClassifier::current_target_t current_target,
GWBUF *buffer,
uint8_t* command,
uint32_t* type,
uint32_t* stmt_id);
private:
bool multi_statements_allowed() const
{
return m_multi_statements_allowed;
}
uint64_t load_data_sent() const
{
return m_load_data_sent;
@ -137,25 +173,6 @@ public:
return m_tmp_tables.find(table) != m_tmp_tables.end();
}
bool large_query() const
{
return m_large_query;
}
void set_large_query(bool large_query)
{
m_large_query = large_query;
}
/**
* @brief Store and process a prepared statement
*
* @param buffer Buffer containing either a text or a binary protocol
* prepared statement
* @param id The unique ID for this statement
*/
void ps_store(GWBUF* buffer, uint32_t id);
/**
* @brief Get the type of a stored prepared statement
*
@ -184,14 +201,6 @@ public:
*/
uint32_t ps_id_internal_get(GWBUF* pBuffer);
/**
* @brief Store a mapping from an external id to the corresponding internal id
*
* @param external_id The external id as seen by the client.
* @param internal_id The corresponding internal id.
*/
void ps_id_internal_put(uint32_t external_id, uint32_t internal_id);
uint32_t get_route_target(uint8_t command, uint32_t qtype, HINT* pHints);
MXS_SESSION* session() const
@ -217,18 +226,16 @@ public:
uint8_t packet_type,
uint32_t *qtype);
uint32_t get_target_type(QueryClassifier::current_target_t current_target,
GWBUF *buffer,
uint8_t* command,
uint32_t* type,
uint32_t* stmt_id);
private:
class PSManager;
typedef std::shared_ptr<PSManager> SPSManager;
typedef std::tr1::unordered_map<uint32_t, uint32_t> HandleMap;
static bool find_table(QueryClassifier& qc, const std::string& table);
static bool delete_table(QueryClassifier& qc, const std::string& table);
private:
Handler* m_pHandler;
MXS_SESSION* m_pSession;

View File

@ -140,25 +140,10 @@ void replace_binary_ps_id(GWBUF* buffer, uint32_t id)
gw_mysql_set_byte4(ptr, id);
}
bool find_table(QueryClassifier& qc, const std::string& table)
{
if (qc.is_tmp_table(table))
{
MXS_INFO("Query targets a temporary table: %s", table.c_str());
return false;
}
return true;
}
bool delete_table(QueryClassifier& qc, const std::string& table)
{
qc.remove_tmp_table(table);
return true;
}
bool foreach_table(QueryClassifier& qc, GWBUF* querybuf, bool (*func)(QueryClassifier& qc,
const std::string&))
bool foreach_table(QueryClassifier& qc,
MXS_SESSION* pSession,
GWBUF* querybuf,
bool (*func)(QueryClassifier& qc, const std::string&))
{
bool rval = true;
int n_tables;
@ -166,7 +151,7 @@ bool foreach_table(QueryClassifier& qc, GWBUF* querybuf, bool (*func)(QueryClass
for (int i = 0; i < n_tables; i++)
{
const char* db = qc_mysql_get_current_db(qc.session());
const char* db = qc_mysql_get_current_db(pSession);
std::string table;
if (strchr(tables[i], '.') == NULL)
@ -694,7 +679,7 @@ bool QueryClassifier::is_read_tmp_table(GWBUF *querybuf, uint32_t qtype)
qc_query_is_type(qtype, QUERY_TYPE_SYSVAR_READ) ||
qc_query_is_type(qtype, QUERY_TYPE_GSYSVAR_READ))
{
if (!foreach_table(*this, querybuf, find_table))
if (!foreach_table(*this, m_pSession, querybuf, &QueryClassifier::find_table))
{
rval = true;
}
@ -707,7 +692,7 @@ void QueryClassifier::check_drop_tmp_table(GWBUF *querybuf)
{
if (qc_is_drop_table_query(querybuf))
{
foreach_table(*this, querybuf, delete_table);
foreach_table(*this, m_pSession, querybuf, &QueryClassifier::delete_table);
}
}
@ -864,7 +849,7 @@ uint32_t QueryClassifier::get_target_type(QueryClassifier::current_target_t curr
* effective since we don't have a node to force queries to. In this
* situation, assigning QUERY_TYPE_WRITE for the query will trigger
* the error processing. */
if (!handler()->lock_to_master())
if (!m_pHandler->lock_to_master())
{
*type |= QUERY_TYPE_WRITE;
}
@ -893,7 +878,7 @@ uint32_t QueryClassifier::get_target_type(QueryClassifier::current_target_t curr
* eventually to master
*/
if (handler()->is_locked_to_master())
if (m_pHandler->is_locked_to_master())
{
/** The session is locked to the master */
route_target = TARGET_MASTER;
@ -934,4 +919,23 @@ uint32_t QueryClassifier::get_target_type(QueryClassifier::current_target_t curr
return route_target;
}
// static
bool QueryClassifier::find_table(QueryClassifier& qc, const std::string& table)
{
if (qc.is_tmp_table(table))
{
MXS_INFO("Query targets a temporary table: %s", table.c_str());
return false;
}
return true;
}
// static
bool QueryClassifier::delete_table(QueryClassifier& qc, const std::string& table)
{
qc.remove_tmp_table(table);
return true;
}
}

View File

@ -778,9 +778,7 @@ void RWSplitSession::replace_master(SRWBackend& target)
{
m_current_master = target;
// As the master has changed, we can reset the temporary table information
m_qc.set_have_tmp_tables(false);
m_qc.clear_tmp_tables();
m_qc.master_replaced();
}
/**