From 12bd34c8d36dd2076ea14e4a7ef8c285a95b6330 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 11 Apr 2018 15:56:36 +0300 Subject: [PATCH] MXS-1625 Remove the PS manager from RWS Not used as it now is in QueryClassifier --- server/core/queryclassifier.cc | 6 - .../routing/readwritesplit/CMakeLists.txt | 1 - .../routing/readwritesplit/rwsplit_ps.cc | 159 ------------------ .../routing/readwritesplit/rwsplit_ps.hh | 91 ---------- .../readwritesplit/rwsplit_route_stmt.cc | 11 ++ .../routing/readwritesplit/rwsplitsession.hh | 1 - 6 files changed, 11 insertions(+), 258 deletions(-) delete mode 100644 server/modules/routing/readwritesplit/rwsplit_ps.cc delete mode 100644 server/modules/routing/readwritesplit/rwsplit_ps.hh diff --git a/server/core/queryclassifier.cc b/server/core/queryclassifier.cc index fa5a0dc1e..1da0ef07f 100644 --- a/server/core/queryclassifier.cc +++ b/server/core/queryclassifier.cc @@ -134,12 +134,6 @@ std::string get_text_ps_id(GWBUF* buffer) return rval; } -void replace_binary_ps_id(GWBUF* buffer, uint32_t id) -{ - uint8_t* ptr = GWBUF_DATA(buffer) + MYSQL_PS_ID_OFFSET; - gw_mysql_set_byte4(ptr, id); -} - bool foreach_table(QueryClassifier& qc, MXS_SESSION* pSession, GWBUF* querybuf, diff --git a/server/modules/routing/readwritesplit/CMakeLists.txt b/server/modules/routing/readwritesplit/CMakeLists.txt index 7e0d79a0c..7e898984f 100644 --- a/server/modules/routing/readwritesplit/CMakeLists.txt +++ b/server/modules/routing/readwritesplit/CMakeLists.txt @@ -5,7 +5,6 @@ rwsplit_mysql.cc rwsplit_route_stmt.cc rwsplit_select_backends.cc rwsplit_session_cmd.cc -rwsplit_ps.cc rwbackend.cc) target_link_libraries(readwritesplit maxscale-common mysqlcommon) set_target_properties(readwritesplit PROPERTIES VERSION "1.0.2") diff --git a/server/modules/routing/readwritesplit/rwsplit_ps.cc b/server/modules/routing/readwritesplit/rwsplit_ps.cc deleted file mode 100644 index 16c8614d9..000000000 --- a/server/modules/routing/readwritesplit/rwsplit_ps.cc +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2016 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl11. - * - * Change Date: 2020-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ - -#include "readwritesplit.hh" -#include "rwsplit_ps.hh" - -#include -#include -#include - -uint32_t get_prepare_type(GWBUF* buffer) -{ - uint32_t type; - - 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); - size_t payload_len = packet_len - MYSQL_HEADER_LEN; - GWBUF* stmt = gwbuf_alloc(packet_len); - uint8_t* ptr = GWBUF_DATA(stmt); - - // Payload length - *ptr++ = payload_len; - *ptr++ = (payload_len >> 8); - *ptr++ = (payload_len >> 16); - // Sequence id - *ptr++ = 0x00; - // Command - *ptr++ = MXS_COM_QUERY; - - gwbuf_copy_data(buffer, MYSQL_HEADER_LEN + 1, payload_len - 1, ptr); - type = qc_get_type_mask(stmt); - - gwbuf_free(stmt); - } - else - { - GWBUF* stmt = qc_get_preparable_stmt(buffer); - ss_dassert(stmt); - - type = qc_get_type_mask(stmt); - } - - ss_dassert((type & (QUERY_TYPE_PREPARE_STMT | QUERY_TYPE_PREPARE_NAMED_STMT)) == 0); - - return type; -} - -std::string get_text_ps_id(GWBUF* buffer) -{ - std::string rval; - char* name = qc_get_prepare_name(buffer); - - if (name) - { - rval = name; - MXS_FREE(name); - } - - return rval; -} - -void replace_binary_ps_id(GWBUF* buffer, uint32_t id) -{ - uint8_t* ptr = GWBUF_DATA(buffer) + MYSQL_PS_ID_OFFSET; - gw_mysql_set_byte4(ptr, id); -} - -PSManager::PSManager() -{ -} - -PSManager::~PSManager() -{ -} - -void PSManager::erase(uint32_t id) -{ - if (m_binary_ps.erase(id) == 0) - { - MXS_WARNING("Closing unknown prepared statement with ID %u", id); - } -} - -void PSManager::erase(std::string id) -{ - if (m_text_ps.erase(id) == 0) - { - MXS_WARNING("Closing unknown prepared statement with ID '%s'", id.c_str()); - } -} - -uint32_t PSManager::get_type(std::string id) const -{ - uint32_t rval = QUERY_TYPE_UNKNOWN; - TextPSMap::const_iterator it = m_text_ps.find(id); - - if (it != m_text_ps.end()) - { - rval = it->second; - } - else - { - MXS_WARNING("Using unknown prepared statement with ID '%s'", id.c_str()); - } - - return rval; -} - - -uint32_t PSManager::get_type(uint32_t id) const -{ - uint32_t rval = QUERY_TYPE_UNKNOWN; - BinaryPSMap::const_iterator it = m_binary_ps.find(id); - - if (it != m_binary_ps.end()) - { - rval = it->second; - } - else - { - MXS_WARNING("Using unknown prepared statement with ID %u", id); - } - - return rval; -} - -void PSManager::store(GWBUF* buffer, uint32_t id) -{ - 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 MXS_COM_QUERY: - m_text_ps[get_text_ps_id(buffer)] = get_prepare_type(buffer); - break; - - case MXS_COM_STMT_PREPARE: - m_binary_ps[id] = get_prepare_type(buffer); - break; - - default: - ss_dassert(!true); - break; - } -} diff --git a/server/modules/routing/readwritesplit/rwsplit_ps.hh b/server/modules/routing/readwritesplit/rwsplit_ps.hh deleted file mode 100644 index fce893cf6..000000000 --- a/server/modules/routing/readwritesplit/rwsplit_ps.hh +++ /dev/null @@ -1,91 +0,0 @@ -#pragma once -/* - * Copyright (c) 2016 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl11. - * - * Change Date: 2020-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ - -#include "readwritesplit.hh" - -#include -#include - -/** Prepared statement ID to type maps for text protocols */ -typedef std::tr1::unordered_map BinaryPSMap; -typedef std::tr1::unordered_map TextPSMap; - -/** Class for tracking prepared statement types by PS statement ID */ -class PSManager -{ - PSManager(const PSManager&); - PSManager& operator =(const PSManager&); - -public: - PSManager(); - ~PSManager(); - - /** - * @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 store(GWBUF* buffer, uint32_t id); - - /** - * @brief Get the type of a stored prepared statement - * - * @param id The unique identifier for the prepared statement or the plaintext - * name of the prepared statement - * - * @return The type of the prepared statement - */ - uint32_t get_type(uint32_t id) const; - uint32_t get_type(std::string id) const; - - /** - * @brief Remove a prepared statement - * - * @param id Statement identifier to remove - */ - void erase(std::string id); - void erase(uint32_t id); - -private: - BinaryPSMap m_binary_ps; - TextPSMap m_text_ps; -}; - -/** - * @brief Get the type of a prepared statement - * - * @param buffer Buffer containing either a text or a binary prepared statement - * - * @return The type of the prepared statement - */ -uint32_t get_prepare_type(GWBUF* buffer); - -/** - * @brief Extract text identifier of a PREPARE or EXECUTE statement - * - * @param buffer Buffer containing a PREPARE or EXECUTE command - * - * @return The string identifier of the statement - */ -std::string get_text_ps_id(GWBUF* buffer); - -/** - * @brief Replace the ID of a binary protocol statement - * - * @param buffer Buffer containing a binary protocol statement with an ID - * @param id ID to insert into the buffer - */ -void replace_binary_ps_id(GWBUF* buffer, uint32_t id); diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index d57eed3ba..a5aaa91cf 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -118,6 +118,17 @@ void RWSplitSession::retry_query(GWBUF* querybuf) ++m_retry_duration; } +namespace +{ + +void replace_binary_ps_id(GWBUF* buffer, uint32_t id) +{ + uint8_t* ptr = GWBUF_DATA(buffer) + MYSQL_PS_ID_OFFSET; + gw_mysql_set_byte4(ptr, id); +} + +} + /** * Routing function. Find out query type, backend type, and target DCB(s). * Then route query to found target(s). diff --git a/server/modules/routing/readwritesplit/rwsplitsession.hh b/server/modules/routing/readwritesplit/rwsplitsession.hh index 9ebc0e1aa..3264ad0db 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.hh +++ b/server/modules/routing/readwritesplit/rwsplitsession.hh @@ -13,7 +13,6 @@ */ #include "readwritesplit.hh" -#include "rwsplit_ps.hh" #include "rwbackend.hh" #include