From 2a36bbc72541a558b4aceb451b62be4a774cdbaf Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Fri, 17 Mar 2023 00:17:57 -0700 Subject: [PATCH 1/7] create DUMMY_PROXY to handle mysql library calls, refactor MYSQL_PROXY to only forward proxy call --- driver/CMakeLists.txt | 4 +- driver/connection_handler.h | 1 - driver/driver.h | 4 +- driver/dummy_proxy.cc | 406 ++++++++++++++++++++++++++++++ driver/dummy_proxy.h | 174 +++++++++++++ driver/efm_proxy.cc | 206 +-------------- driver/efm_proxy.h | 79 +----- driver/failover.h | 5 +- driver/failover_reader_handler.cc | 2 +- driver/failover_writer_handler.cc | 2 +- driver/handle.cc | 5 +- driver/mysql_proxy.cc | 198 +++++++-------- driver/mysql_proxy.h | 10 +- driver/topology_service.h | 3 + unit_testing/efm_proxy_test.cc | 2 + unit_testing/mock_objects.h | 2 + unit_testing/test_utils.h | 2 + 17 files changed, 690 insertions(+), 415 deletions(-) create mode 100644 driver/dummy_proxy.cc create mode 100644 driver/dummy_proxy.h diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt index c2a473451..1fa0648ae 100644 --- a/driver/CMakeLists.txt +++ b/driver/CMakeLists.txt @@ -60,7 +60,7 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT}) base_metrics_holder.cc catalog.cc catalog_no_i_s.cc cluster_topology_info.cc cluster_aware_hit_metrics_holder.cc cluster_aware_metrics_container.cc cluster_aware_metrics.cc cluster_aware_time_metrics_holder.cc - connect.cc connection_handler.cc cursor.cc desc.cc dll.cc driver.cc efm_proxy.cc + connect.cc connection_handler.cc cursor.cc desc.cc dll.cc driver.cc dummy_proxy.cc efm_proxy.cc error.cc execute.cc failover_handler.cc failover_reader_handler.cc failover_writer_handler.cc handle.cc host_info.cc info.cc monitor.cc monitor_connection_context.cc monitor_service.cc monitor_thread_container.cc @@ -84,7 +84,7 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT}) SET(DRIVER_SRCS ${DRIVER_SRCS} driver${CONNECTOR_DRIVER_TYPE_SHORT}.def driver${CONNECTOR_DRIVER_TYPE_SHORT}.rc base_metrics_holder.h catalog.h cluster_aware_hit_metrics_holder.h cluster_aware_metrics_container.h cluster_aware_metrics.h cluster_aware_time_metrics_holder.h cluster_topology_info.h connection_handler.h - driver.h efm_proxy.h error.h failover.h host_info.h monitor.h monitor_connection_context.h monitor_service.h + driver.h dummy_proxy.h efm_proxy.h error.h failover.h host_info.h monitor.h monitor_connection_context.h monitor_service.h monitor_thread_container.h mylog.h mysql_proxy.h myutil.h parse.h query_parsing.h topology_service.h ../MYODBC_MYSQL.h ../MYODBC_CONF.h ../MYODBC_ODBC.h) ENDIF(WIN32) diff --git a/driver/connection_handler.h b/driver/connection_handler.h index 1cab2745a..43e7d577a 100644 --- a/driver/connection_handler.h +++ b/driver/connection_handler.h @@ -31,7 +31,6 @@ #define __CONNECTION_HANDLER_H__ #include "host_info.h" - #include #ifdef __linux__ diff --git a/driver/driver.h b/driver/driver.h index a9cd79015..38eda0833 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -41,11 +41,11 @@ #include "../MYODBC_MYSQL.h" #include "../MYODBC_CONF.h" #include "../MYODBC_ODBC.h" +#include "util/installer.h" + #include "connection_handler.h" -#include "efm_proxy.h" #include "failover.h" #include "mysql_proxy.h" -#include "util/installer.h" /* Disable _attribute__ on non-gcc compilers. */ #if !defined(__attribute__) && !defined(__GNUC__) diff --git a/driver/dummy_proxy.cc b/driver/dummy_proxy.cc new file mode 100644 index 000000000..8cc797ef9 --- /dev/null +++ b/driver/dummy_proxy.cc @@ -0,0 +1,406 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License, version 2.0 +// (GPLv2), as published by the Free Software Foundation, with the +// following additional permissions: +// +// This program is distributed with certain software that is licensed +// under separate terms, as designated in a particular file or component +// or in the license documentation. Without limiting your rights under +// the GPLv2, the authors of this program hereby grant you an additional +// permission to link the program and your derivative works with the +// separately licensed software that they have included with the program. +// +// Without limiting the foregoing grant of rights under the GPLv2 and +// additional permission as to separately licensed software, this +// program is also subject to the Universal FOSS Exception, version 1.0, +// a copy of which can be found along with its FAQ at +// http://oss.oracle.com/licenses/universal-foss-exception. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License, version 2.0, for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// http://www.gnu.org/licenses/gpl-2.0.html. + +#include "dummy_proxy.h" + +//#include "driver.h" + +#include + +namespace { + const auto SOCKET_CLOSE_DELAY = std::chrono::milliseconds(100); +} + +DUMMY_PROXY::DUMMY_PROXY(DBC* dbc, DataSource* ds) : MYSQL_PROXY(dbc, ds) { + this->host = get_host_info_from_ds(ds); +} + +DUMMY_PROXY::~DUMMY_PROXY() { + if (this->mysql) { + close(); + } +} + +uint64_t DUMMY_PROXY::num_rows(MYSQL_RES* res) { + return mysql_num_rows(res); +} + +unsigned int DUMMY_PROXY::num_fields(MYSQL_RES* res) { + return mysql_num_fields(res); +} + +MYSQL_FIELD* DUMMY_PROXY::fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) { + return mysql_fetch_field_direct(res, fieldnr); +} + +MYSQL_ROW_OFFSET DUMMY_PROXY::row_tell(MYSQL_RES* res) { + return mysql_row_tell(res); +} + +unsigned int DUMMY_PROXY::field_count() { + return mysql_field_count(mysql); +} + +uint64_t DUMMY_PROXY::affected_rows() { + return mysql_affected_rows(mysql); +} + +unsigned int DUMMY_PROXY::error_code() { + return mysql_errno(mysql); +} + +const char* DUMMY_PROXY::error() { + return mysql_error(mysql); +} + +const char* DUMMY_PROXY::sqlstate() { + return mysql_sqlstate(mysql); +} + +unsigned long DUMMY_PROXY::thread_id() { + return mysql_thread_id(mysql); +} + +int DUMMY_PROXY::set_character_set(const char* csname) { + return mysql_set_character_set(mysql, csname); +} + +void DUMMY_PROXY::init() { + this->mysql = mysql_init(nullptr); +} + +bool DUMMY_PROXY::ssl_set(const char* key, const char* cert, const char* ca, const char* capath, const char* cipher) { + return mysql_ssl_set(mysql, key, cert, ca, capath, cipher); +} + +bool DUMMY_PROXY::change_user(const char* user, const char* passwd, const char* db) { + return mysql_change_user(mysql, user, passwd, db); +} + +bool DUMMY_PROXY::real_connect( + const char* host, const char* user, const char* passwd, + const char* db, unsigned int port, const char* unix_socket, + unsigned long clientflag) { + + const MYSQL* new_mysql = mysql_real_connect(mysql, host, user, passwd, db, port, unix_socket, clientflag); + return new_mysql != nullptr; +} + +int DUMMY_PROXY::select_db(const char* db) { + return mysql_select_db(mysql, db); +} + +int DUMMY_PROXY::query(const char* q) { + return mysql_query(mysql, q); +} + +int DUMMY_PROXY::real_query(const char* q, unsigned long length) { + return mysql_real_query(mysql, q, length); +} + +MYSQL_RES* DUMMY_PROXY::store_result() { + return mysql_store_result(mysql); +} + +MYSQL_RES* DUMMY_PROXY::use_result() { + return mysql_use_result(mysql); +} + +struct CHARSET_INFO* DUMMY_PROXY::get_character_set() const { + return this->mysql->charset; +} + +void DUMMY_PROXY::get_character_set_info(MY_CHARSET_INFO* charset) { + mysql_get_character_set_info(mysql, charset); +} + +bool DUMMY_PROXY::autocommit(bool auto_mode) { + return mysql_autocommit(mysql, auto_mode); +} + +int DUMMY_PROXY::next_result() { + return mysql_next_result(mysql); +} + +int DUMMY_PROXY::stmt_next_result(MYSQL_STMT* stmt) { + return mysql_stmt_next_result(stmt); +} + +void DUMMY_PROXY::close() { + mysql_close(mysql); + mysql = nullptr; +} + +bool DUMMY_PROXY::real_connect_dns_srv( + const char* dns_srv_name, const char* user, + const char* passwd, const char* db, unsigned long client_flag) { + + const MYSQL* new_mysql = mysql_real_connect_dns_srv(mysql, dns_srv_name, user, passwd, db, client_flag); + return new_mysql != nullptr; +} + +int DUMMY_PROXY::ping() { + return mysql_ping(mysql); +} + +int DUMMY_PROXY::get_option(mysql_option option, const void* arg) { + return mysql_get_option(mysql, option, arg); +} + +int DUMMY_PROXY::options4(mysql_option option, const void* arg1, const void* arg2) { + return mysql_options4(mysql, option, arg1, arg2); +} + +int DUMMY_PROXY::options(mysql_option option, const void* arg) { + return mysql_options(mysql, option, arg); +} + +void DUMMY_PROXY::free_result(MYSQL_RES* result) { + mysql_free_result(result); +} + +void DUMMY_PROXY::data_seek(MYSQL_RES* result, uint64_t offset) { + mysql_data_seek(result, offset); +} + +MYSQL_ROW_OFFSET DUMMY_PROXY::row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) { + return mysql_row_seek(result, offset); +} + +MYSQL_FIELD_OFFSET DUMMY_PROXY::field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) { + return mysql_field_seek(result, offset); +} + +MYSQL_ROW DUMMY_PROXY::fetch_row(MYSQL_RES* result) { + return mysql_fetch_row(result); +} + +unsigned long* DUMMY_PROXY::fetch_lengths(MYSQL_RES* result) { + return mysql_fetch_lengths(result); +} + +MYSQL_FIELD* DUMMY_PROXY::fetch_field(MYSQL_RES* result) { + return mysql_fetch_field(result); +} + +MYSQL_RES* DUMMY_PROXY::list_fields(const char* table, const char* wild) { + return mysql_list_fields(mysql, table, wild); +} + +unsigned long DUMMY_PROXY::real_escape_string(char* to, const char* from, unsigned long length) { + return mysql_real_escape_string(mysql, to, from, length); +} + +bool DUMMY_PROXY::bind_param(unsigned n_params, MYSQL_BIND* binds, const char** names) { + return mysql_bind_param(mysql, n_params, binds, names); +} + +MYSQL_STMT* DUMMY_PROXY::stmt_init() { + return mysql_stmt_init(mysql); +} + +int DUMMY_PROXY::stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length) { + return mysql_stmt_prepare(stmt, query, length); +} + +int DUMMY_PROXY::stmt_execute(MYSQL_STMT* stmt) { + return mysql_stmt_execute(stmt); +} + +int DUMMY_PROXY::stmt_fetch(MYSQL_STMT* stmt) { + return mysql_stmt_fetch(stmt); +} + +int DUMMY_PROXY::stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, unsigned int column, unsigned long offset) { + return mysql_stmt_fetch_column(stmt, bind_arg, column, offset); +} + +int DUMMY_PROXY::stmt_store_result(MYSQL_STMT* stmt) { + return mysql_stmt_store_result(stmt); +} + +unsigned long DUMMY_PROXY::stmt_param_count(MYSQL_STMT* stmt) { + return mysql_stmt_param_count(stmt); +} + +bool DUMMY_PROXY::stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { + return mysql_stmt_bind_param(stmt, bnd); +} + +bool DUMMY_PROXY::stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { + return mysql_stmt_bind_result(stmt, bnd); +} + +bool DUMMY_PROXY::stmt_close(MYSQL_STMT* stmt) { + return mysql_stmt_close(stmt); +} + +bool DUMMY_PROXY::stmt_reset(MYSQL_STMT* stmt) { + return mysql_stmt_reset(stmt); +} + +bool DUMMY_PROXY::stmt_free_result(MYSQL_STMT* stmt) { + return mysql_stmt_free_result(stmt); +} + +bool DUMMY_PROXY::stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, const char* data, + unsigned long length) { + + return mysql_stmt_send_long_data(stmt, param_number, data, length); +} + +MYSQL_RES* DUMMY_PROXY::stmt_result_metadata(MYSQL_STMT* stmt) { + return mysql_stmt_result_metadata(stmt); +} + +unsigned int DUMMY_PROXY::stmt_errno(MYSQL_STMT* stmt) { + return mysql_stmt_errno(stmt); +} + +const char* DUMMY_PROXY::stmt_error(MYSQL_STMT* stmt) { + return mysql_stmt_error(stmt); +} + +MYSQL_ROW_OFFSET DUMMY_PROXY::stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) { + return mysql_stmt_row_seek(stmt, offset); +} + +MYSQL_ROW_OFFSET DUMMY_PROXY::stmt_row_tell(MYSQL_STMT* stmt) { + return mysql_stmt_row_tell(stmt); +} + +void DUMMY_PROXY::stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) { + mysql_stmt_data_seek(stmt, offset); +} + +uint64_t DUMMY_PROXY::stmt_num_rows(MYSQL_STMT* stmt) { + return mysql_stmt_num_rows(stmt); +} + +uint64_t DUMMY_PROXY::stmt_affected_rows(MYSQL_STMT* stmt) { + return mysql_stmt_affected_rows(stmt); +} + +unsigned int DUMMY_PROXY::stmt_field_count(MYSQL_STMT* stmt) { + return mysql_stmt_field_count(stmt); +} + +st_mysql_client_plugin* DUMMY_PROXY::client_find_plugin(const char* name, int type) { + return mysql_client_find_plugin(mysql, name, type); +} + +bool DUMMY_PROXY::is_connected() { + return this->mysql != nullptr && this->mysql->net.vio; +} + +void DUMMY_PROXY::set_last_error_code(unsigned int error_code) { + this->mysql->net.last_errno = error_code; +} + +char* DUMMY_PROXY::get_last_error() const { + return this->mysql->net.last_error; +} + +unsigned int DUMMY_PROXY::get_last_error_code() const { + return this->mysql->net.last_errno; +} + +char* DUMMY_PROXY::get_sqlstate() const { + return this->mysql->net.sqlstate; +} + +char* DUMMY_PROXY::get_server_version() const { + return this->mysql->server_version; +} + +uint64_t DUMMY_PROXY::get_affected_rows() const { + return this->mysql->affected_rows; +} + +void DUMMY_PROXY::set_affected_rows(uint64_t num_rows) { + this->mysql->affected_rows = num_rows; +} + +char* DUMMY_PROXY::get_host_info() const { + return this->mysql->host_info; +} + +std::string DUMMY_PROXY::get_host() { + return (this->mysql && this->mysql->host) ? this->mysql->host : this->host->get_host(); +} + +unsigned int DUMMY_PROXY::get_port() { + return (this->mysql) ? this->mysql->port : this->host->get_port(); +} + +unsigned long DUMMY_PROXY::get_max_packet() const { + return this->mysql->net.max_packet; +} + +unsigned long DUMMY_PROXY::get_server_capabilities() const { + return this->mysql->server_capabilities; +} + +unsigned int DUMMY_PROXY::get_server_status() const { + return this->mysql->server_status; +} + +void DUMMY_PROXY::delete_ds() { + if (ds) { + ds_delete(ds); + ds = nullptr; + } +} + +MYSQL* DUMMY_PROXY::move_mysql_connection() { + MYSQL* ret = this->mysql; + this->mysql = nullptr; + return ret; +} + +void DUMMY_PROXY::set_connection(MYSQL_PROXY* mysql_proxy) { + close(); + this->mysql = mysql_proxy->move_mysql_connection(); + // delete the ds initialized in CONNECTION_HANDLER::clone_dbc() + mysql_proxy->delete_ds(); + delete mysql_proxy; +} + +void DUMMY_PROXY::close_socket() { + MYLOG_DBC_TRACE(dbc, "Closing socket"); + int ret = 0; + if (mysql->net.fd != INVALID_SOCKET && (ret = shutdown(mysql->net.fd, SHUT_RDWR))) { + MYLOG_DBC_TRACE(dbc, "shutdown() with return code: %d, error message: %s,", ret, strerror(socket_errno)); + } + // Yield to main thread to handle socket shutdown + std::this_thread::sleep_for(SOCKET_CLOSE_DELAY); + if (mysql->net.fd != INVALID_SOCKET && (ret = ::closesocket(mysql->net.fd))) { + MYLOG_DBC_TRACE(dbc, "closesocket() with return code: %d, error message: %s,", ret, strerror(socket_errno)); + } +} diff --git a/driver/dummy_proxy.h b/driver/dummy_proxy.h new file mode 100644 index 000000000..23de9e839 --- /dev/null +++ b/driver/dummy_proxy.h @@ -0,0 +1,174 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License, version 2.0 +// (GPLv2), as published by the Free Software Foundation, with the +// following additional permissions: +// +// This program is distributed with certain software that is licensed +// under separate terms, as designated in a particular file or component +// or in the license documentation. Without limiting your rights under +// the GPLv2, the authors of this program hereby grant you an additional +// permission to link the program and your derivative works with the +// separately licensed software that they have included with the program. +// +// Without limiting the foregoing grant of rights under the GPLv2 and +// additional permission as to separately licensed software, this +// program is also subject to the Universal FOSS Exception, version 1.0, +// a copy of which can be found along with its FAQ at +// http://oss.oracle.com/licenses/universal-foss-exception. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License, version 2.0, for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// http://www.gnu.org/licenses/gpl-2.0.html. + +#ifndef __DUMMY_PROXY__ +#define __DUMMY_PROXY__ + +#include "driver.h" +#include "host_info.h" +#include "mysql_proxy.h" + +class DUMMY_PROXY : public MYSQL_PROXY { +public: + DUMMY_PROXY(DBC* dbc, DataSource* ds); + ~DUMMY_PROXY() override; + + uint64_t num_rows(MYSQL_RES* res) override; + unsigned int num_fields(MYSQL_RES* res) override; + MYSQL_FIELD* fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) override; + MYSQL_ROW_OFFSET row_tell(MYSQL_RES* res) override; + + unsigned int field_count() override; + uint64_t affected_rows() override; + unsigned int error_code() override; + const char* error() override; + const char* sqlstate() override; + unsigned long thread_id() override; + int set_character_set(const char* csname) override; + + void init() override; + bool ssl_set(const char* key, const char* cert, const char* ca, + const char* capath, const char* cipher) override; + bool change_user(const char* user, const char* passwd, + const char* db) override; + bool real_connect(const char* host, const char* user, + const char* passwd, const char* db, unsigned int port, + const char* unix_socket, unsigned long clientflag) override; + int select_db(const char* db) override; + int query(const char* q) override; + int real_query(const char* q, unsigned long length) override; + MYSQL_RES* store_result() override; + MYSQL_RES* use_result() override; + struct CHARSET_INFO* get_character_set() const; + void get_character_set_info(MY_CHARSET_INFO* charset) override; + + int ping() override; + int options(enum mysql_option option, const void* arg) override; + int options4(enum mysql_option option, const void* arg1, + const void* arg2) override; + int get_option(enum mysql_option option, const void* arg) override; + void free_result(MYSQL_RES* result) override; + void data_seek(MYSQL_RES* result, uint64_t offset) override; + MYSQL_ROW_OFFSET row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) override; + MYSQL_FIELD_OFFSET field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) override; + MYSQL_ROW fetch_row(MYSQL_RES* result) override; + + unsigned long* fetch_lengths(MYSQL_RES* result) override; + MYSQL_FIELD* fetch_field(MYSQL_RES* result) override; + MYSQL_RES* list_fields(const char* table, const char* wild) override; + unsigned long real_escape_string(char* to, const char* from, + unsigned long length) override; + + bool bind_param(unsigned n_params, MYSQL_BIND* binds, + const char** names) override; + + MYSQL_STMT* stmt_init() override; + int stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length) override; + int stmt_execute(MYSQL_STMT* stmt) override; + int stmt_fetch(MYSQL_STMT* stmt) override; + int stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, + unsigned int column, unsigned long offset) override; + int stmt_store_result(MYSQL_STMT* stmt) override; + unsigned long stmt_param_count(MYSQL_STMT* stmt) override; + bool stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; + bool stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; + bool stmt_close(MYSQL_STMT* stmt) override; + bool stmt_reset(MYSQL_STMT* stmt) override; + bool stmt_free_result(MYSQL_STMT* stmt) override; + bool stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, + const char* data, unsigned long length) override; + MYSQL_RES* stmt_result_metadata(MYSQL_STMT* stmt) override; + unsigned int stmt_errno(MYSQL_STMT* stmt) override; + const char* stmt_error(MYSQL_STMT* stmt) override; + MYSQL_ROW_OFFSET stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) override; + MYSQL_ROW_OFFSET stmt_row_tell(MYSQL_STMT* stmt) override; + void stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) override; + uint64_t stmt_num_rows(MYSQL_STMT* stmt) override; + uint64_t stmt_affected_rows(MYSQL_STMT* stmt) override; + unsigned int stmt_field_count(MYSQL_STMT* stmt) override; + + bool autocommit(bool auto_mode) override; + int next_result() override; + int stmt_next_result(MYSQL_STMT* stmt) override; + void close() override; + + bool real_connect_dns_srv(const char* dns_srv_name, + const char* user, const char* passwd, + const char* db, unsigned long client_flag) override; + struct st_mysql_client_plugin* client_find_plugin( + const char* name, int type) override; + + bool is_connected() override; + + void set_last_error_code(unsigned int error_code) override; + + char* get_last_error() const; + + unsigned int get_last_error_code() const; + + char* get_sqlstate() const; + + char* get_server_version() const; + + uint64_t get_affected_rows() const; + + void set_affected_rows(uint64_t num_rows) override; + + char* get_host_info() const; + + std::string get_host() override; + + unsigned int get_port() override; + + unsigned long get_max_packet() const; + + unsigned long get_server_capabilities() const; + + unsigned int get_server_status() const; + + void delete_ds() override; + + MYSQL* move_mysql_connection() override; + + void set_connection(MYSQL_PROXY* mysql_proxy) override; + + void close_socket() override; + +protected: + DBC* dbc = nullptr; + DataSource* ds = nullptr; + DUMMY_PROXY* next_proxy = nullptr; + +private: + MYSQL* mysql = nullptr; + std::shared_ptr host = nullptr; +}; + + +#endif /* __DUMMY_PROXY__ */ diff --git a/driver/efm_proxy.cc b/driver/efm_proxy.cc index 4329c1ea8..083be6f70 100644 --- a/driver/efm_proxy.cc +++ b/driver/efm_proxy.cc @@ -27,7 +27,7 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. -#include "driver.h" +#include "efm_proxy.h" namespace { const char* RETRIEVE_HOST_PORT_SQL = "SELECT CONCAT(@@hostname, ':', @@port)"; @@ -118,54 +118,6 @@ void EFM_PROXY::set_connection(MYSQL_PROXY* mysql_proxy) { generate_node_keys(); } -void EFM_PROXY::close_socket() { - next_proxy->close_socket(); -} - -void EFM_PROXY::delete_ds() { - next_proxy->delete_ds(); -} - -uint64_t EFM_PROXY::num_rows(MYSQL_RES* res) { - return next_proxy->num_rows(res); -} - -unsigned EFM_PROXY::num_fields(MYSQL_RES* res) { - return next_proxy->num_fields(res); -} - -MYSQL_FIELD* EFM_PROXY::fetch_field_direct(MYSQL_RES* res, unsigned fieldnr) { - return next_proxy->fetch_field_direct(res, fieldnr); -} - -MYSQL_ROW_OFFSET EFM_PROXY::row_tell(MYSQL_RES* res) { - return next_proxy->row_tell(res); -} - -unsigned EFM_PROXY::field_count() { - return next_proxy->field_count(); -} - -uint64_t EFM_PROXY::affected_rows() { - return next_proxy->affected_rows(); -} - -unsigned EFM_PROXY::error_code() { - return next_proxy->error_code(); -} - -const char* EFM_PROXY::error() { - return next_proxy->error(); -} - -const char* EFM_PROXY::sqlstate() { - return next_proxy->sqlstate(); -} - -unsigned long EFM_PROXY::thread_id() { - return next_proxy->thread_id(); -} - int EFM_PROXY::set_character_set(const char* csname) { const auto context = start_monitoring(); const int ret = next_proxy->set_character_set(csname); @@ -173,14 +125,6 @@ int EFM_PROXY::set_character_set(const char* csname) { return ret; } -void EFM_PROXY::init() { - next_proxy->init(); -} - -bool EFM_PROXY::ssl_set(const char* key, const char* cert, const char* ca, const char* capath, const char* cipher) { - return next_proxy->ssl_set(key, cert, ca, capath, cipher); -} - bool EFM_PROXY::change_user(const char* user, const char* passwd, const char* db) { const auto context = start_monitoring(); const bool ret = next_proxy->change_user(user, passwd, db); @@ -235,18 +179,6 @@ MYSQL_RES* EFM_PROXY::use_result() { return ret; } -CHARSET_INFO* EFM_PROXY::get_character_set() const { - return next_proxy->get_character_set(); -} - -void EFM_PROXY::get_character_set_info(MY_CHARSET_INFO* charset) { - next_proxy->get_character_set_info(charset); -} - -bool EFM_PROXY::autocommit(bool auto_mode) { - return next_proxy->autocommit(auto_mode); -} - int EFM_PROXY::next_result() { const auto context = start_monitoring(); const int ret = next_proxy->next_result(); @@ -261,10 +193,6 @@ int EFM_PROXY::stmt_next_result(MYSQL_STMT* stmt) { return ret; } -void EFM_PROXY::close() { - next_proxy->close(); -} - bool EFM_PROXY::real_connect_dns_srv( const char* dns_srv_name, const char* user, const char* passwd, const char* db, unsigned long client_flag) { @@ -276,40 +204,12 @@ bool EFM_PROXY::real_connect_dns_srv( return ret; } -int EFM_PROXY::ping() { - return next_proxy->ping(); -} - -int EFM_PROXY::options4(mysql_option option, const void* arg1, const void* arg2) { - return next_proxy->options4(option, arg1, arg2); -} - -int EFM_PROXY::get_option(mysql_option option, const void* arg) { - return next_proxy->get_option(option, arg); -} - -int EFM_PROXY::options(mysql_option option, const void* arg) { - return next_proxy->options(option, arg); -} - void EFM_PROXY::free_result(MYSQL_RES* result) { const auto context = start_monitoring(); next_proxy->free_result(result); stop_monitoring(context); } -void EFM_PROXY::data_seek(MYSQL_RES* result, uint64_t offset) { - next_proxy->data_seek(result, offset); -} - -MYSQL_ROW_OFFSET EFM_PROXY::row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) { - return next_proxy->row_seek(result, offset); -} - -MYSQL_FIELD_OFFSET EFM_PROXY::field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) { - return next_proxy->field_seek(result, offset); -} - MYSQL_ROW EFM_PROXY::fetch_row(MYSQL_RES* result) { const auto context = start_monitoring(); const MYSQL_ROW ret = next_proxy->fetch_row(result); @@ -317,14 +217,6 @@ MYSQL_ROW EFM_PROXY::fetch_row(MYSQL_RES* result) { return ret; } -unsigned long* EFM_PROXY::fetch_lengths(MYSQL_RES* result) { - return next_proxy->fetch_lengths(result); -} - -MYSQL_FIELD* EFM_PROXY::fetch_field(MYSQL_RES* result) { - return next_proxy->fetch_field(result); -} - MYSQL_RES* EFM_PROXY::list_fields(const char* table, const char* wild) { const auto context = start_monitoring(); MYSQL_RES* ret = next_proxy->list_fields(table, wild); @@ -388,10 +280,6 @@ int EFM_PROXY::stmt_store_result(MYSQL_STMT* stmt) { return ret; } -unsigned long EFM_PROXY::stmt_param_count(MYSQL_STMT* stmt) { - return next_proxy->stmt_param_count(stmt); -} - bool EFM_PROXY::stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { const auto context = start_monitoring(); const bool ret = next_proxy->stmt_bind_param(stmt, bnd); @@ -441,95 +329,3 @@ MYSQL_RES* EFM_PROXY::stmt_result_metadata(MYSQL_STMT* stmt) { stop_monitoring(context); return ret; } - -unsigned EFM_PROXY::stmt_errno(MYSQL_STMT* stmt) { - return next_proxy->stmt_errno(stmt); -} - -const char* EFM_PROXY::stmt_error(MYSQL_STMT* stmt) { - return next_proxy->stmt_error(stmt); -} - -MYSQL_ROW_OFFSET EFM_PROXY::stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) { - return next_proxy->stmt_row_seek(stmt, offset); -} - -MYSQL_ROW_OFFSET EFM_PROXY::stmt_row_tell(MYSQL_STMT* stmt) { - return next_proxy->stmt_row_tell(stmt); -} - -void EFM_PROXY::stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) { - next_proxy->stmt_data_seek(stmt, offset); -} - -uint64_t EFM_PROXY::stmt_num_rows(MYSQL_STMT* stmt) { - return next_proxy->stmt_num_rows(stmt); -} - -uint64_t EFM_PROXY::stmt_affected_rows(MYSQL_STMT* stmt) { - return next_proxy->stmt_affected_rows(stmt); -} - -unsigned EFM_PROXY::stmt_field_count(MYSQL_STMT* stmt) { - return next_proxy->stmt_field_count(stmt); -} - -st_mysql_client_plugin* EFM_PROXY::client_find_plugin(const char* name, int type) { - return next_proxy->client_find_plugin(name, type); -} - -bool EFM_PROXY::is_connected() { - return next_proxy->is_connected(); -} - -void EFM_PROXY::set_last_error_code(unsigned error_code) { - next_proxy->set_last_error_code(error_code); -} - -char* EFM_PROXY::get_last_error() const { - return next_proxy->get_last_error(); -} - -unsigned EFM_PROXY::get_last_error_code() const { - return next_proxy->get_last_error_code(); -} - -char* EFM_PROXY::get_sqlstate() const { - return next_proxy->get_sqlstate(); -} - -char* EFM_PROXY::get_server_version() const { - return next_proxy->get_server_version(); -} - -uint64_t EFM_PROXY::get_affected_rows() const { - return next_proxy->get_affected_rows(); -} - -void EFM_PROXY::set_affected_rows(uint64_t num_rows) { - next_proxy->set_affected_rows(num_rows); -} - -char* EFM_PROXY::get_host_info() const { - return next_proxy->get_host_info(); -} - -std::string EFM_PROXY::get_host() { - return next_proxy->get_host(); -} - -unsigned EFM_PROXY::get_port() { - return next_proxy->get_port(); -} - -unsigned long EFM_PROXY::get_max_packet() const { - return next_proxy->get_max_packet(); -} - -unsigned long EFM_PROXY::get_server_capabilities() const { - return next_proxy->get_server_capabilities(); -} - -unsigned EFM_PROXY::get_server_status() const { - return next_proxy->get_server_status(); -} diff --git a/driver/efm_proxy.h b/driver/efm_proxy.h index a2168d78f..6da6f145a 100644 --- a/driver/efm_proxy.h +++ b/driver/efm_proxy.h @@ -30,8 +30,7 @@ #ifndef __EFM_PROXY__ #define __EFM_PROXY__ -#include - +#include "driver.h" #include "monitor_service.h" #include "mysql_proxy.h" @@ -41,23 +40,7 @@ class EFM_PROXY : public MYSQL_PROXY { EFM_PROXY(DBC* dbc, DataSource* ds, MYSQL_PROXY* next_proxy); EFM_PROXY(DBC* dbc, DataSource* ds, MYSQL_PROXY* next_proxy, std::shared_ptr monitor_service); - void delete_ds() override; - uint64_t num_rows(MYSQL_RES* res) override; - unsigned int num_fields(MYSQL_RES* res) override; - MYSQL_FIELD* fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) override; - MYSQL_ROW_OFFSET row_tell(MYSQL_RES* res) override; - - unsigned int field_count() override; - uint64_t affected_rows() override; - unsigned int error_code() override; - const char* error() override; - const char* sqlstate() override; - unsigned long thread_id() override; int set_character_set(const char* csname) override; - - void init() override; - bool ssl_set(const char* key, const char* cert, const char* ca, - const char* capath, const char* cipher) override; bool change_user(const char* user, const char* passwd, const char* db) override; bool real_connect(const char* host, const char* user, @@ -68,22 +51,8 @@ class EFM_PROXY : public MYSQL_PROXY { int real_query(const char* q, unsigned long length) override; MYSQL_RES* store_result() override; MYSQL_RES* use_result() override; - struct CHARSET_INFO* get_character_set() const override; - void get_character_set_info(MY_CHARSET_INFO* charset) override; - - int ping() override; - int options(enum mysql_option option, const void* arg) override; - int options4(enum mysql_option option, const void* arg1, - const void* arg2) override; - int get_option(enum mysql_option option, const void* arg) override; void free_result(MYSQL_RES* result) override; - void data_seek(MYSQL_RES* result, uint64_t offset) override; - MYSQL_ROW_OFFSET row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) override; - MYSQL_FIELD_OFFSET field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) override; MYSQL_ROW fetch_row(MYSQL_RES* result) override; - - unsigned long* fetch_lengths(MYSQL_RES* result) override; - MYSQL_FIELD* fetch_field(MYSQL_RES* result) override; MYSQL_RES* list_fields(const char* table, const char* wild) override; unsigned long real_escape_string(char* to, const char* from, unsigned long length) override; @@ -98,7 +67,6 @@ class EFM_PROXY : public MYSQL_PROXY { int stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, unsigned int column, unsigned long offset) override; int stmt_store_result(MYSQL_STMT* stmt) override; - unsigned long stmt_param_count(MYSQL_STMT* stmt) override; bool stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; bool stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; bool stmt_close(MYSQL_STMT* stmt) override; @@ -107,58 +75,13 @@ class EFM_PROXY : public MYSQL_PROXY { bool stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, const char* data, unsigned long length) override; MYSQL_RES* stmt_result_metadata(MYSQL_STMT* stmt) override; - unsigned int stmt_errno(MYSQL_STMT* stmt) override; - const char* stmt_error(MYSQL_STMT* stmt) override; - MYSQL_ROW_OFFSET stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) override; - MYSQL_ROW_OFFSET stmt_row_tell(MYSQL_STMT* stmt) override; - void stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) override; - uint64_t stmt_num_rows(MYSQL_STMT* stmt) override; - uint64_t stmt_affected_rows(MYSQL_STMT* stmt) override; - unsigned int stmt_field_count(MYSQL_STMT* stmt) override; - - bool autocommit(bool auto_mode) override; int next_result() override; int stmt_next_result(MYSQL_STMT* stmt) override; - void close() override; - bool real_connect_dns_srv(const char* dns_srv_name, const char* user, const char* passwd, const char* db, unsigned long client_flag) override; - struct st_mysql_client_plugin* client_find_plugin( - const char* name, int type) override; - - bool is_connected() override; - - void set_last_error_code(unsigned int error_code) override; - - char* get_last_error() const override; - - unsigned int get_last_error_code() const override; - - char* get_sqlstate() const override; - - char* get_server_version() const override; - - uint64_t get_affected_rows() const override; - - void set_affected_rows(uint64_t num_rows) override; - - char* get_host_info() const override; - - std::string get_host() override; - - unsigned int get_port() override; - - unsigned long get_max_packet() const override; - - unsigned long get_server_capabilities() const override; - - unsigned int get_server_status() const override; void set_connection(MYSQL_PROXY* mysql_proxy) override; - - void close_socket() override; - void set_next_proxy(MYSQL_PROXY* next_proxy) override; private: diff --git a/driver/failover.h b/driver/failover.h index cae82c4f1..8d3d50fa2 100644 --- a/driver/failover.h +++ b/driver/failover.h @@ -33,13 +33,10 @@ #include "connection_handler.h" #include "topology_service.h" #include "mylog.h" +#include "mysql_proxy.h" #include -struct DBC; -struct DataSource; -typedef short SQLRETURN; - struct READER_FAILOVER_RESULT { bool connected = false; std::shared_ptr new_host; diff --git a/driver/failover_reader_handler.cc b/driver/failover_reader_handler.cc index 99eafbf5c..cf9ebbf36 100644 --- a/driver/failover_reader_handler.cc +++ b/driver/failover_reader_handler.cc @@ -27,7 +27,7 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. -#include "failover.h" +#include "driver.h" #include #include diff --git a/driver/failover_writer_handler.cc b/driver/failover_writer_handler.cc index 33f718ba6..0baa81e24 100644 --- a/driver/failover_writer_handler.cc +++ b/driver/failover_writer_handler.cc @@ -27,7 +27,7 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. -#include "failover.h" +#include "driver.h" #include #include diff --git a/driver/handle.cc b/driver/handle.cc index 78f291b37..913cf7e9c 100644 --- a/driver/handle.cc +++ b/driver/handle.cc @@ -48,6 +48,9 @@ ****************************************************************************/ #include "driver.h" +#include "dummy_proxy.h" +#include "efm_proxy.h" + #include thread_local long thread_count = 0; @@ -114,7 +117,7 @@ void DBC::close() // construct a proxy chain, example: iam->efm->mysql void DBC::init_proxy_chain(DataSource* dsrc) { - MYSQL_PROXY *head = new MYSQL_PROXY(this, dsrc); + MYSQL_PROXY *head = new DUMMY_PROXY(this, dsrc); if (dsrc->enable_failure_detection) { MYSQL_PROXY* efm_proxy = new EFM_PROXY(this, dsrc); diff --git a/driver/mysql_proxy.cc b/driver/mysql_proxy.cc index d3c936af8..8f23dd1b6 100644 --- a/driver/mysql_proxy.cc +++ b/driver/mysql_proxy.cc @@ -29,12 +29,6 @@ #include "driver.h" -#include - -namespace { - const auto SOCKET_CLOSE_DELAY = std::chrono::milliseconds(100); -} - MYSQL_PROXY::MYSQL_PROXY(DBC* dbc, DataSource* ds) : dbc{dbc}, ds{ds} { if (!this->dbc) { throw std::runtime_error("DBC cannot be null."); @@ -43,81 +37,72 @@ MYSQL_PROXY::MYSQL_PROXY(DBC* dbc, DataSource* ds) : dbc{dbc}, ds{ds} { if (!this->ds) { throw std::runtime_error("DataSource cannot be null."); } - - this->host = get_host_info_from_ds(ds); } MYSQL_PROXY::~MYSQL_PROXY() { - if (this->mysql) { - close(); - } - if (this->next_proxy) { delete next_proxy; } } void MYSQL_PROXY::delete_ds() { - if (ds) { - ds_delete(ds); - ds = nullptr; - } + next_proxy->delete_ds(); } uint64_t MYSQL_PROXY::num_rows(MYSQL_RES* res) { - return mysql_num_rows(res); + return next_proxy->num_rows(res); } unsigned int MYSQL_PROXY::num_fields(MYSQL_RES* res) { - return mysql_num_fields(res); + return next_proxy->num_fields(res); } MYSQL_FIELD* MYSQL_PROXY::fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) { - return mysql_fetch_field_direct(res, fieldnr); + return next_proxy->fetch_field_direct(res, fieldnr); } MYSQL_ROW_OFFSET MYSQL_PROXY::row_tell(MYSQL_RES* res) { - return mysql_row_tell(res); + return next_proxy->row_tell(res); } unsigned int MYSQL_PROXY::field_count() { - return mysql_field_count(mysql); + return next_proxy->field_count(); } uint64_t MYSQL_PROXY::affected_rows() { - return mysql_affected_rows(mysql); + return next_proxy->affected_rows(); } unsigned int MYSQL_PROXY::error_code() { - return mysql_errno(mysql); + return next_proxy->error_code(); } const char* MYSQL_PROXY::error() { - return mysql_error(mysql); + return next_proxy->error(); } const char* MYSQL_PROXY::sqlstate() { - return mysql_sqlstate(mysql); + return next_proxy->sqlstate(); } unsigned long MYSQL_PROXY::thread_id() { - return mysql_thread_id(mysql); + return next_proxy->thread_id(); } int MYSQL_PROXY::set_character_set(const char* csname) { - return mysql_set_character_set(mysql, csname); + return next_proxy->set_character_set(csname); } void MYSQL_PROXY::init() { - this->mysql = mysql_init(nullptr); + next_proxy->init(); } bool MYSQL_PROXY::ssl_set(const char* key, const char* cert, const char* ca, const char* capath, const char* cipher) { - return mysql_ssl_set(mysql, key, cert, ca, capath, cipher); + return next_proxy->ssl_set(key, cert, ca, capath, cipher); } bool MYSQL_PROXY::change_user(const char* user, const char* passwd, const char* db) { - return mysql_change_user(mysql, user, passwd, db); + return next_proxy->change_user(user, passwd, db); } bool MYSQL_PROXY::real_connect( @@ -125,65 +110,62 @@ bool MYSQL_PROXY::real_connect( const char* db, unsigned int port, const char* unix_socket, unsigned long clientflag) { - const MYSQL* new_mysql = mysql_real_connect(mysql, host, user, passwd, db, port, unix_socket, clientflag); - return new_mysql != nullptr; + return next_proxy->real_connect(host, user, passwd, db, port, unix_socket, clientflag); } int MYSQL_PROXY::select_db(const char* db) { - return mysql_select_db(mysql, db); + return next_proxy->select_db(db); } int MYSQL_PROXY::query(const char* q) { - return mysql_query(mysql, q); + return next_proxy->query(q); } int MYSQL_PROXY::real_query(const char* q, unsigned long length) { - return mysql_real_query(mysql, q, length); + return next_proxy->real_query(q, length); } MYSQL_RES* MYSQL_PROXY::store_result() { - return mysql_store_result(mysql); + return next_proxy->store_result(); } MYSQL_RES* MYSQL_PROXY::use_result() { - return mysql_use_result(mysql); + return next_proxy->use_result(); } struct CHARSET_INFO* MYSQL_PROXY::get_character_set() const { - return this->mysql->charset; + return next_proxy->get_character_set(); } void MYSQL_PROXY::get_character_set_info(MY_CHARSET_INFO* charset) { - mysql_get_character_set_info(mysql, charset); + next_proxy->get_character_set_info(charset); } bool MYSQL_PROXY::autocommit(bool auto_mode) { - return mysql_autocommit(mysql, auto_mode); + return next_proxy->autocommit(auto_mode); } int MYSQL_PROXY::next_result() { - return mysql_next_result(mysql); + return next_proxy->next_result(); } int MYSQL_PROXY::stmt_next_result(MYSQL_STMT* stmt) { - return mysql_stmt_next_result(stmt); + return next_proxy->stmt_next_result(stmt); } void MYSQL_PROXY::close() { - mysql_close(mysql); - mysql = nullptr; + next_proxy->close(); } bool MYSQL_PROXY::real_connect_dns_srv( const char* dns_srv_name, const char* user, const char* passwd, const char* db, unsigned long client_flag) { - const MYSQL* new_mysql = mysql_real_connect_dns_srv(mysql, dns_srv_name, user, passwd, db, client_flag); - return new_mysql != nullptr; + return next_proxy->real_connect_dns_srv(dns_srv_name, user, passwd, db, client_flag); } int MYSQL_PROXY::ping() { - return mysql_ping(mysql); + return next_proxy->ping(); } unsigned long MYSQL_PROXY::get_client_version(void) { @@ -191,227 +173,213 @@ unsigned long MYSQL_PROXY::get_client_version(void) { } int MYSQL_PROXY::get_option(mysql_option option, const void* arg) { - return mysql_get_option(mysql, option, arg); + return next_proxy->get_option(option, arg); } int MYSQL_PROXY::options4(mysql_option option, const void* arg1, const void* arg2) { - return mysql_options4(mysql, option, arg1, arg2); + return next_proxy->options4(option, arg1, arg2); } int MYSQL_PROXY::options(mysql_option option, const void* arg) { - return mysql_options(mysql, option, arg); + return next_proxy->options(option, arg); } void MYSQL_PROXY::free_result(MYSQL_RES* result) { - mysql_free_result(result); + next_proxy->free_result(result); } void MYSQL_PROXY::data_seek(MYSQL_RES* result, uint64_t offset) { - mysql_data_seek(result, offset); + next_proxy->data_seek(result, offset); } MYSQL_ROW_OFFSET MYSQL_PROXY::row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) { - return mysql_row_seek(result, offset); + return next_proxy->row_seek(result, offset); } MYSQL_FIELD_OFFSET MYSQL_PROXY::field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) { - return mysql_field_seek(result, offset); + return next_proxy->field_seek(result, offset); } MYSQL_ROW MYSQL_PROXY::fetch_row(MYSQL_RES* result) { - return mysql_fetch_row(result); + return next_proxy->fetch_row(result); } unsigned long* MYSQL_PROXY::fetch_lengths(MYSQL_RES* result) { - return mysql_fetch_lengths(result); + return next_proxy->fetch_lengths(result); } MYSQL_FIELD* MYSQL_PROXY::fetch_field(MYSQL_RES* result) { - return mysql_fetch_field(result); + return next_proxy->fetch_field(result); } MYSQL_RES* MYSQL_PROXY::list_fields(const char* table, const char* wild) { - return mysql_list_fields(mysql, table, wild); + return next_proxy->list_fields(table, wild); } unsigned long MYSQL_PROXY::real_escape_string(char* to, const char* from, unsigned long length) { - return mysql_real_escape_string(mysql, to, from, length); + return next_proxy->real_escape_string(to, from, length); } bool MYSQL_PROXY::bind_param(unsigned n_params, MYSQL_BIND* binds, const char** names) { - return mysql_bind_param(mysql, n_params, binds, names); + return next_proxy->bind_param(n_params, binds, names); } MYSQL_STMT* MYSQL_PROXY::stmt_init() { - return mysql_stmt_init(mysql); + return next_proxy->stmt_init(); } int MYSQL_PROXY::stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length) { - return mysql_stmt_prepare(stmt, query, length); + return next_proxy->stmt_prepare(stmt, query, length); } int MYSQL_PROXY::stmt_execute(MYSQL_STMT* stmt) { - return mysql_stmt_execute(stmt); + return next_proxy->stmt_execute(stmt); } int MYSQL_PROXY::stmt_fetch(MYSQL_STMT* stmt) { - return mysql_stmt_fetch(stmt); + return next_proxy->stmt_fetch(stmt); } int MYSQL_PROXY::stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, unsigned int column, unsigned long offset) { - return mysql_stmt_fetch_column(stmt, bind_arg, column, offset); + return next_proxy->stmt_fetch_column(stmt, bind_arg, column, offset); } int MYSQL_PROXY::stmt_store_result(MYSQL_STMT* stmt) { - return mysql_stmt_store_result(stmt); + return next_proxy->stmt_store_result(stmt); } unsigned long MYSQL_PROXY::stmt_param_count(MYSQL_STMT* stmt) { - return mysql_stmt_param_count(stmt); + return next_proxy->stmt_param_count(stmt); } bool MYSQL_PROXY::stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { - return mysql_stmt_bind_param(stmt, bnd); + return next_proxy->stmt_bind_param(stmt, bnd); } bool MYSQL_PROXY::stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { - return mysql_stmt_bind_result(stmt, bnd); + return next_proxy->stmt_bind_result(stmt, bnd); } bool MYSQL_PROXY::stmt_close(MYSQL_STMT* stmt) { - return mysql_stmt_close(stmt); + return next_proxy->stmt_close(stmt); } bool MYSQL_PROXY::stmt_reset(MYSQL_STMT* stmt) { - return mysql_stmt_reset(stmt); + return next_proxy->stmt_reset(stmt); } bool MYSQL_PROXY::stmt_free_result(MYSQL_STMT* stmt) { - return mysql_stmt_free_result(stmt); + return next_proxy->stmt_free_result(stmt); } bool MYSQL_PROXY::stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, const char* data, unsigned long length) { - return mysql_stmt_send_long_data(stmt, param_number, data, length); + return next_proxy->stmt_send_long_data(stmt, param_number, data, length); } MYSQL_RES* MYSQL_PROXY::stmt_result_metadata(MYSQL_STMT* stmt) { - return mysql_stmt_result_metadata(stmt); + return next_proxy->stmt_result_metadata(stmt); } unsigned int MYSQL_PROXY::stmt_errno(MYSQL_STMT* stmt) { - return mysql_stmt_errno(stmt); + return next_proxy->stmt_errno(stmt); } const char* MYSQL_PROXY::stmt_error(MYSQL_STMT* stmt) { - return mysql_stmt_error(stmt); + return next_proxy->stmt_error(stmt); } MYSQL_ROW_OFFSET MYSQL_PROXY::stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) { - return mysql_stmt_row_seek(stmt, offset); + return next_proxy->stmt_row_seek(stmt, offset); } MYSQL_ROW_OFFSET MYSQL_PROXY::stmt_row_tell(MYSQL_STMT* stmt) { - return mysql_stmt_row_tell(stmt); + return next_proxy->stmt_row_tell(stmt); } void MYSQL_PROXY::stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) { - mysql_stmt_data_seek(stmt, offset); + next_proxy->stmt_data_seek(stmt, offset); } uint64_t MYSQL_PROXY::stmt_num_rows(MYSQL_STMT* stmt) { - return mysql_stmt_num_rows(stmt); + return next_proxy->stmt_num_rows(stmt); } uint64_t MYSQL_PROXY::stmt_affected_rows(MYSQL_STMT* stmt) { - return mysql_stmt_affected_rows(stmt); + return next_proxy->stmt_affected_rows(stmt); } unsigned int MYSQL_PROXY::stmt_field_count(MYSQL_STMT* stmt) { - return mysql_stmt_field_count(stmt); + return next_proxy->stmt_field_count(stmt); } st_mysql_client_plugin* MYSQL_PROXY::client_find_plugin(const char* name, int type) { - return mysql_client_find_plugin(mysql, name, type); + return next_proxy->client_find_plugin(name, type); } bool MYSQL_PROXY::is_connected() { - return this->mysql != nullptr && this->mysql->net.vio; + return next_proxy->is_connected(); } void MYSQL_PROXY::set_last_error_code(unsigned int error_code) { - this->mysql->net.last_errno = error_code; + next_proxy->set_last_error_code(error_code); } char* MYSQL_PROXY::get_last_error() const { - return this->mysql->net.last_error; + return next_proxy->get_last_error(); } unsigned int MYSQL_PROXY::get_last_error_code() const { - return this->mysql->net.last_errno; + return next_proxy->get_last_error_code(); } char* MYSQL_PROXY::get_sqlstate() const { - return this->mysql->net.sqlstate; + return next_proxy->get_sqlstate(); } char* MYSQL_PROXY::get_server_version() const { - return this->mysql->server_version; + return next_proxy->get_server_version(); } uint64_t MYSQL_PROXY::get_affected_rows() const { - return this->mysql->affected_rows; + return next_proxy->get_affected_rows(); } void MYSQL_PROXY::set_affected_rows(uint64_t num_rows) { - this->mysql->affected_rows = num_rows; + next_proxy->set_affected_rows(num_rows); } char* MYSQL_PROXY::get_host_info() const { - return this->mysql->host_info; + return next_proxy->get_host_info(); } std::string MYSQL_PROXY::get_host() { - return (this->mysql && this->mysql->host) ? this->mysql->host : this->host->get_host(); + return next_proxy->get_host(); } unsigned int MYSQL_PROXY::get_port() { - return (this->mysql) ? this->mysql->port : this->host->get_port(); + return next_proxy->get_port(); } unsigned long MYSQL_PROXY::get_max_packet() const { - return this->mysql->net.max_packet; + return next_proxy->get_max_packet(); } unsigned long MYSQL_PROXY::get_server_capabilities() const { - return this->mysql->server_capabilities; + return next_proxy->get_server_capabilities(); } unsigned int MYSQL_PROXY::get_server_status() const { - return this->mysql->server_status; + return next_proxy->get_server_status(); } void MYSQL_PROXY::set_connection(MYSQL_PROXY* mysql_proxy) { - close(); - this->mysql = mysql_proxy->mysql; - mysql_proxy->mysql = nullptr; - // delete the ds initialized in CONNECTION_HANDLER::clone_dbc() - mysql_proxy->delete_ds(); - delete mysql_proxy; + next_proxy->set_connection(mysql_proxy); } void MYSQL_PROXY::close_socket() { - MYLOG_DBC_TRACE(dbc, "Closing socket"); - int ret = 0; - if (mysql->net.fd != INVALID_SOCKET && (ret = shutdown(mysql->net.fd, SHUT_RDWR))) { - MYLOG_DBC_TRACE(dbc, "shutdown() with return code: %d, error message: %s,", ret, strerror(socket_errno)); - } - // Yield to main thread to handle socket shutdown - std::this_thread::sleep_for(SOCKET_CLOSE_DELAY); - if (mysql->net.fd != INVALID_SOCKET && (ret = ::closesocket(mysql->net.fd))) { - MYLOG_DBC_TRACE(dbc, "closesocket() with return code: %d, error message: %s,", ret, strerror(socket_errno)); - } + next_proxy->close_socket(); } void MYSQL_PROXY::set_next_proxy(MYSQL_PROXY* next_proxy) { @@ -421,3 +389,7 @@ void MYSQL_PROXY::set_next_proxy(MYSQL_PROXY* next_proxy) { this->next_proxy = next_proxy; } + +MYSQL* MYSQL_PROXY::move_mysql_connection() { + return next_proxy ? next_proxy->move_mysql_connection() : nullptr; +} diff --git a/driver/mysql_proxy.h b/driver/mysql_proxy.h index 5ec55477d..e9d5c0df7 100644 --- a/driver/mysql_proxy.h +++ b/driver/mysql_proxy.h @@ -30,9 +30,7 @@ #ifndef __MYSQL_PROXY__ #define __MYSQL_PROXY__ -#include - -#include "host_info.h" +//#include "MYODBC_MYSQL.h" struct DBC; struct DataSource; @@ -163,14 +161,12 @@ class MYSQL_PROXY { virtual void set_next_proxy(MYSQL_PROXY* next_proxy); + virtual MYSQL* move_mysql_connection(); + protected: DBC* dbc = nullptr; DataSource* ds = nullptr; MYSQL_PROXY* next_proxy = nullptr; - -private: - MYSQL* mysql = nullptr; - std::shared_ptr host = nullptr; }; #endif /* __MYSQL_PROXY__ */ diff --git a/driver/topology_service.h b/driver/topology_service.h index cf5dfd8dd..f963ea430 100644 --- a/driver/topology_service.h +++ b/driver/topology_service.h @@ -30,6 +30,8 @@ #ifndef __TOPOLOGYSERVICE_H__ #define __TOPOLOGYSERVICE_H__ +#include "MYODBC_MYSQL.h" + #include "cluster_aware_metrics_container.h" #include "cluster_topology_info.h" #include "mysql_proxy.h" @@ -39,6 +41,7 @@ #include #include + // TODO - consider - do we really need miliseconds for refresh? - the default numbers here are already 30 seconds.000; #define DEFAULT_REFRESH_RATE_IN_MILLISECONDS 30000 #define WRITER_SESSION_ID "MASTER_SESSION_ID" diff --git a/unit_testing/efm_proxy_test.cc b/unit_testing/efm_proxy_test.cc index ee0412088..b3ef68c39 100644 --- a/unit_testing/efm_proxy_test.cc +++ b/unit_testing/efm_proxy_test.cc @@ -27,6 +27,8 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. +#include "driver/efm_proxy.h" + #include #include diff --git a/unit_testing/mock_objects.h b/unit_testing/mock_objects.h index bc22bd6b0..b31cbb6b6 100644 --- a/unit_testing/mock_objects.h +++ b/unit_testing/mock_objects.h @@ -35,6 +35,7 @@ #include "driver/mysql_proxy.h" #include "driver/failover.h" #include "driver/monitor_thread_container.h" +#include "driver/monitor_service.h" #ifdef WIN32 #ifdef _DEBUG @@ -80,6 +81,7 @@ class MOCK_MYSQL_PROXY : public MYSQL_PROXY { MOCK_METHOD(void, close, ()); MOCK_METHOD(void, init, ()); MOCK_METHOD(int, ping, ()); + MOCK_METHOD(void, delete_ds, ()); }; class MOCK_TOPOLOGY_SERVICE : public TOPOLOGY_SERVICE { diff --git a/unit_testing/test_utils.h b/unit_testing/test_utils.h index 01ca1f504..2231adcca 100644 --- a/unit_testing/test_utils.h +++ b/unit_testing/test_utils.h @@ -31,6 +31,8 @@ #define __TESTUTILS_H__ #include "driver/driver.h" +#include "driver/monitor.h" +#include "driver/monitor_thread_container.h" void allocate_odbc_handles(SQLHENV& env, DBC*& dbc, DataSource*& ds); void cleanup_odbc_handles(SQLHENV& env, DBC*& dbc, DataSource*& ds, bool call_myodbc_end = false); From 61cd1ac6b74ffdfe80c47dcfaeddd220817fbfd0 Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Fri, 17 Mar 2023 00:19:04 -0700 Subject: [PATCH 2/7] remove commented include --- driver/dummy_proxy.cc | 2 -- driver/mysql_proxy.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/driver/dummy_proxy.cc b/driver/dummy_proxy.cc index 8cc797ef9..378c0d108 100644 --- a/driver/dummy_proxy.cc +++ b/driver/dummy_proxy.cc @@ -29,8 +29,6 @@ #include "dummy_proxy.h" -//#include "driver.h" - #include namespace { diff --git a/driver/mysql_proxy.h b/driver/mysql_proxy.h index e9d5c0df7..671c30a22 100644 --- a/driver/mysql_proxy.h +++ b/driver/mysql_proxy.h @@ -30,8 +30,6 @@ #ifndef __MYSQL_PROXY__ #define __MYSQL_PROXY__ -//#include "MYODBC_MYSQL.h" - struct DBC; struct DataSource; From 12b7633703014f3ec35316f802336989a27c3ad6 Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Fri, 17 Mar 2023 00:27:07 -0700 Subject: [PATCH 3/7] include thread header in dummy proxy --- driver/dummy_proxy.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/driver/dummy_proxy.cc b/driver/dummy_proxy.cc index 378c0d108..de7e35059 100644 --- a/driver/dummy_proxy.cc +++ b/driver/dummy_proxy.cc @@ -30,6 +30,7 @@ #include "dummy_proxy.h" #include +#include namespace { const auto SOCKET_CLOSE_DELAY = std::chrono::milliseconds(100); From b9bb46aba2f36d41e73381beb17af15e47a3a673 Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Fri, 17 Mar 2023 13:48:09 -0700 Subject: [PATCH 4/7] rename mysql_proxy to connection_proxy --- driver/CMakeLists.txt | 8 +- driver/ansi.cc | 2 +- driver/catalog.cc | 40 ++-- driver/catalog_no_i_s.cc | 72 ++++---- driver/cluster_aware_metrics_container.cc | 6 +- driver/connect.cc | 114 ++++++------ driver/connection_handler.cc | 14 +- driver/connection_handler.h | 6 +- .../{mysql_proxy.cc => connection_proxy.cc} | 174 +++++++++--------- driver/{mysql_proxy.h => connection_proxy.h} | 18 +- driver/cursor.cc | 46 ++--- driver/driver.h | 10 +- driver/dummy_proxy.cc | 10 +- driver/dummy_proxy.h | 6 +- driver/efm_proxy.cc | 14 +- driver/efm_proxy.h | 12 +- driver/error.cc | 18 +- driver/error.h | 8 +- driver/execute.cc | 28 +-- driver/failover.h | 14 +- driver/failover_handler.cc | 4 +- driver/handle.cc | 32 ++-- driver/info.cc | 36 ++-- driver/monitor.cc | 28 +-- driver/monitor.h | 6 +- driver/monitor_connection_context.cc | 2 +- driver/my_prepared_stmt.cc | 48 ++--- driver/my_stmt.cc | 68 +++---- driver/myutil.h | 12 +- driver/options.cc | 32 ++-- driver/results.cc | 14 +- driver/secrets_manager_proxy.cc | 80 ++++++++ driver/secrets_manager_proxy.h | 173 +++++++++++++++++ driver/topology_service.cc | 16 +- driver/topology_service.h | 8 +- driver/unicode.cc | 6 +- driver/utility.cc | 40 ++-- unit_testing/efm_proxy_test.cc | 30 +-- unit_testing/failover_reader_handler_test.cc | 28 +-- unit_testing/failover_writer_handler_test.cc | 60 +++--- unit_testing/mock_objects.h | 18 +- .../monitor_connection_context_test.cc | 2 +- unit_testing/monitor_test.cc | 14 +- unit_testing/topology_service_test.cc | 4 +- 44 files changed, 817 insertions(+), 564 deletions(-) rename driver/{mysql_proxy.cc => connection_proxy.cc} (53%) rename driver/{mysql_proxy.h => connection_proxy.h} (94%) create mode 100644 driver/secrets_manager_proxy.cc create mode 100644 driver/secrets_manager_proxy.h diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt index 1fa0648ae..9ce046b57 100644 --- a/driver/CMakeLists.txt +++ b/driver/CMakeLists.txt @@ -60,11 +60,11 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT}) base_metrics_holder.cc catalog.cc catalog_no_i_s.cc cluster_topology_info.cc cluster_aware_hit_metrics_holder.cc cluster_aware_metrics_container.cc cluster_aware_metrics.cc cluster_aware_time_metrics_holder.cc - connect.cc connection_handler.cc cursor.cc desc.cc dll.cc driver.cc dummy_proxy.cc efm_proxy.cc + connect.cc connection_handler.cc connection_proxy.cc cursor.cc desc.cc dll.cc driver.cc dummy_proxy.cc efm_proxy.cc error.cc execute.cc failover_handler.cc failover_reader_handler.cc failover_writer_handler.cc handle.cc host_info.cc info.cc monitor.cc monitor_connection_context.cc monitor_service.cc monitor_thread_container.cc - my_prepared_stmt.cc my_stmt.cc mylog.cc mysql_proxy.cc options.cc parse.cc prepare.cc query_parsing.cc + my_prepared_stmt.cc my_stmt.cc mylog.cc connection_proxy.cc options.cc parse.cc prepare.cc query_parsing.cc results.cc topology_service.cc transact.cc utility.cc) IF(UNICODE) @@ -83,9 +83,9 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT}) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/driver/driver.rc.cmake ${CMAKE_SOURCE_DIR}/driver/driver${CONNECTOR_DRIVER_TYPE_SHORT}.rc @ONLY) SET(DRIVER_SRCS ${DRIVER_SRCS} driver${CONNECTOR_DRIVER_TYPE_SHORT}.def driver${CONNECTOR_DRIVER_TYPE_SHORT}.rc base_metrics_holder.h catalog.h cluster_aware_hit_metrics_holder.h cluster_aware_metrics_container.h - cluster_aware_metrics.h cluster_aware_time_metrics_holder.h cluster_topology_info.h connection_handler.h + cluster_aware_metrics.h cluster_aware_time_metrics_holder.h cluster_topology_info.h connection_handler.h connection_proxy.h driver.h dummy_proxy.h efm_proxy.h error.h failover.h host_info.h monitor.h monitor_connection_context.h monitor_service.h - monitor_thread_container.h mylog.h mysql_proxy.h myutil.h parse.h query_parsing.h topology_service.h + monitor_thread_container.h mylog.h myutil.h parse.h query_parsing.h topology_service.h ../MYODBC_MYSQL.h ../MYODBC_CONF.h ../MYODBC_ODBC.h) ENDIF(WIN32) diff --git a/driver/ansi.cc b/driver/ansi.cc index 4c5019046..f04208ed3 100644 --- a/driver/ansi.cc +++ b/driver/ansi.cc @@ -212,7 +212,7 @@ SQLDescribeCol(SQLHSTMT hstmt, SQLUSMALLINT column, if (free_value == -1) { - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } diff --git a/driver/catalog.cc b/driver/catalog.cc index bd2d68592..a6635e422 100644 --- a/driver/catalog.cc +++ b/driver/catalog.cc @@ -160,7 +160,7 @@ create_fake_resultset(STMT *stmt, MYSQL_ROW rowval, size_t rowsize, else { if (stmt->result) - stmt->dbc->mysql_proxy->free_result(stmt->result); + stmt->dbc->connection_proxy->free_result(stmt->result); } /* Free if result data was not in row storage */ @@ -178,7 +178,7 @@ create_fake_resultset(STMT *stmt, MYSQL_ROW rowval, size_t rowsize, x_free(stmt->result); x_free(stmt->result_array); - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } stmt->fake_result= 1; @@ -257,7 +257,7 @@ MYSQL_RES *db_status(STMT *stmt, std::string &db) return NULL; } - return stmt->dbc->mysql_proxy->store_result(); + return stmt->dbc->connection_proxy->store_result(); } @@ -285,7 +285,7 @@ static MYSQL_RES *table_status_i_s(STMT *stmt, my_bool show_tables, my_bool show_views) { - MYSQL_PROXY *mysql_proxy= stmt->dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= stmt->dbc->connection_proxy; /** the buffer size should count possible escapes */ my_bool clause_added= FALSE; std::string query; @@ -344,7 +344,7 @@ static MYSQL_RES *table_status_i_s(STMT *stmt, query.append("AND TABLE_NAME LIKE '"); if (wildcard) { - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)table_name, table_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)table_name, table_len); query.append(tmpbuff, cnt); } else @@ -365,7 +365,7 @@ static MYSQL_RES *table_status_i_s(STMT *stmt, return NULL; } - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -391,7 +391,7 @@ static MYSQL_RES *table_status_i_s_old(STMT *stmt, my_bool show_tables, my_bool show_views) { - MYSQL_PROXY *mysql_proxy= stmt->dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= stmt->dbc->connection_proxy; /** the buffer size should count possible escapes */ my_bool clause_added= FALSE; std::string query; @@ -449,7 +449,7 @@ static MYSQL_RES *table_status_i_s_old(STMT *stmt, query.append("WHERE TABLE_NAME LIKE '"); if (wildcard) { - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)table_name, table_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)table_name, table_len); query.append(tmpbuff, cnt); } else @@ -468,7 +468,7 @@ static MYSQL_RES *table_status_i_s_old(STMT *stmt, return NULL; } - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -528,7 +528,7 @@ int add_name_condition_oa_id(HSTMT hstmt, std::string &query, SQLCHAR * name, query.append("'"); char tmpbuff[1024]; - size_t cnt = stmt->dbc->mysql_proxy->real_escape_string(tmpbuff, (char *)name, name_len); + size_t cnt = stmt->dbc->connection_proxy->real_escape_string(tmpbuff, (char *)name, name_len); query.append(tmpbuff, cnt); query.append("' "); } @@ -574,7 +574,7 @@ int add_name_condition_pv_id(HSTMT hstmt, std::string &query, SQLCHAR * name, query.append("'"); char tmpbuff[1024]; - size_t cnt = stmt->dbc->mysql_proxy->real_escape_string(tmpbuff, (char *)name, name_len); + size_t cnt = stmt->dbc->connection_proxy->real_escape_string(tmpbuff, (char *)name, name_len); query.append(tmpbuff, cnt); query.append("' "); } @@ -820,7 +820,7 @@ columns_i_s(SQLHSTMT hstmt, SQLCHAR *catalog, unsigned long catalog_len, do_bind(params, column, MYSQL_TYPE_STRING, column_len); } query.append(" ORDER BY ORDINAL_POSITION"); - ODBC_STMT local_stmt(stmt->dbc->mysql_proxy); + ODBC_STMT local_stmt(stmt->dbc->connection_proxy); for (size_t i = 0; i < ccount; i++) { @@ -856,7 +856,7 @@ columns_i_s(SQLHSTMT hstmt, SQLCHAR *catalog, unsigned long catalog_len, is_access = true; #endif - size_t rows = stmt->dbc->mysql_proxy->stmt_num_rows(local_stmt); + size_t rows = stmt->dbc->connection_proxy->stmt_num_rows(local_stmt); stmt->m_row_storage.set_size(rows, SQLCOLUMNS_FIELDS); if (rows == 0) { @@ -869,7 +869,7 @@ columns_i_s(SQLHSTMT hstmt, SQLCHAR *catalog, unsigned long catalog_len, std::string db = get_database_name(stmt, catalog, catalog_len, schema, schema_len, false); size_t rnum = 1; - while(!stmt->dbc->mysql_proxy->stmt_fetch(local_stmt)) + while(!stmt->dbc->connection_proxy->stmt_fetch(local_stmt)) { CAT_SCHEMA_SET(data[0], data[1], db); /* TABLE_NAME */ @@ -1355,7 +1355,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, SQLSMALLINT fk_table_len) { STMT *stmt=(STMT *) hstmt; - MYSQL_PROXY *mysql_proxy= stmt->dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= stmt->dbc->connection_proxy; char tmpbuff[1024]; /* This should be big enough. */ char *update_rule, *delete_rule, *ref_constraints_join; SQLRETURN rc; @@ -1371,7 +1371,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, /* With 5.1, we can use REFERENTIAL_CONSTRAINTS to get even more info. */ - if (is_minimum_version(stmt->dbc->mysql_proxy->get_server_version(), "5.1")) + if (is_minimum_version(stmt->dbc->connection_proxy->get_server_version(), "5.1")) { update_rule= "CASE" " WHEN R.UPDATE_RULE = 'CASCADE' THEN 0" @@ -1440,7 +1440,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, if (!pk_db.empty()) { query.append("'"); - cnt = mysql_proxy->real_escape_string(tmpbuff, pk_db.c_str(), pk_db.length()); + cnt = connection_proxy->real_escape_string(tmpbuff, pk_db.c_str(), pk_db.length()); query.append(tmpbuff, cnt); query.append("' "); } @@ -1451,7 +1451,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, query.append("AND A.REFERENCED_TABLE_NAME = '"); - cnt =mysql_proxy->real_escape_string(tmpbuff, (char *)pk_table, pk_table_len); + cnt =connection_proxy->real_escape_string(tmpbuff, (char *)pk_table, pk_table_len); query.append(tmpbuff, cnt); query.append("' "); @@ -1465,7 +1465,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, if (!fk_db.empty()) { query.append("'"); - cnt = mysql_proxy->real_escape_string(tmpbuff, fk_db.c_str(), fk_db.length()); + cnt = connection_proxy->real_escape_string(tmpbuff, fk_db.c_str(), fk_db.length()); query.append(tmpbuff, cnt); query.append("' "); } @@ -1476,7 +1476,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, query.append("AND A.TABLE_NAME = '"); - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)fk_table, fk_table_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)fk_table, fk_table_len); query.append(tmpbuff, cnt); query.append("' "); diff --git a/driver/catalog_no_i_s.cc b/driver/catalog_no_i_s.cc index 9c71232bd..d41ca044c 100644 --- a/driver/catalog_no_i_s.cc +++ b/driver/catalog_no_i_s.cc @@ -145,7 +145,7 @@ static MYSQL_RES *server_list_dbkeys(STMT *stmt, SQLSMALLINT table_len) { DBC *dbc = stmt->dbc; - MYSQL_PROXY *mysql_proxy= dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= dbc->connection_proxy; char tmpbuff[1024]; std::string query; query.reserve(1024); @@ -169,7 +169,7 @@ static MYSQL_RES *server_list_dbkeys(STMT *stmt, MYLOG_DBC_TRACE(dbc, query.c_str()); if (exec_stmt_query(stmt, query.c_str(), query.length(), FALSE)) return NULL; - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -194,7 +194,7 @@ server_list_dbcolumns(STMT *stmt, { assert(stmt); DBC *dbc= stmt->dbc; - MYSQL_PROXY *mysql_proxy= dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= dbc->connection_proxy; MYSQL_RES *result; char buff[NAME_LEN * 2 + 64], column_buff[NAME_LEN * 2 + 64]; @@ -211,7 +211,7 @@ server_list_dbcolumns(STMT *stmt, strncpy(buff, (const char*)szCatalog, cbCatalog); buff[cbCatalog]= '\0'; - if (mysql_proxy->select_db(buff)) + if (connection_proxy->select_db(buff)) { return NULL; } @@ -222,15 +222,15 @@ server_list_dbcolumns(STMT *stmt, strncpy(column_buff, (const char*)szColumn, cbColumn); column_buff[cbColumn]= '\0'; - result = mysql_proxy->list_fields(buff, column_buff); + result = connection_proxy->list_fields(buff, column_buff); /* If before this call no database were selected - we cannot revert that */ if (cbCatalog && !dbc->database.empty()) { - if (mysql_proxy->select_db(dbc->database.c_str())) + if (connection_proxy->select_db(dbc->database.c_str())) { /* Well, probably have to return error here */ - mysql_proxy->free_result(result); + connection_proxy->free_result(result); return NULL; } } @@ -281,7 +281,7 @@ static MYSQL_RES *table_privs_raw_data( STMT * stmt, SQLSMALLINT table_len) { DBC *dbc= stmt->dbc; - MYSQL_PROXY *mysql_proxy= dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= dbc->connection_proxy; char tmpbuff[1024]; std::string query; size_t cnt = 0; @@ -290,7 +290,7 @@ static MYSQL_RES *table_privs_raw_data( STMT * stmt, query = "SELECT Db,User,Table_name,Grantor,Table_priv " "FROM mysql.tables_priv WHERE Table_name LIKE '"; - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)table, table_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)table, table_len); query.append(tmpbuff, cnt); query.append("' AND Db = "); @@ -298,7 +298,7 @@ static MYSQL_RES *table_privs_raw_data( STMT * stmt, if (catalog_len) { query.append("'"); - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)catalog, catalog_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)catalog, catalog_len); query.append(tmpbuff, cnt); query.append("'"); } @@ -311,7 +311,7 @@ static MYSQL_RES *table_privs_raw_data( STMT * stmt, if (exec_stmt_query(stmt, query.c_str(), query.length(), FALSE)) return NULL; - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -355,7 +355,7 @@ static MYSQL_RES *column_privs_raw_data(STMT * stmt, SQLSMALLINT column_len) { DBC *dbc = stmt->dbc; - MYSQL_PROXY *mysql_proxy = dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy = dbc->connection_proxy; char tmpbuff[1024]; std::string query; @@ -368,14 +368,14 @@ static MYSQL_RES *column_privs_raw_data(STMT * stmt, "FROM mysql.columns_priv AS c, mysql.tables_priv AS t " "WHERE c.Table_name = '"; - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)table, table_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)table, table_len); query.append(tmpbuff, cnt); query.append("' AND c.Db = "); if (catalog_len) { query.append("'"); - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)catalog, catalog_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)catalog, catalog_len); query.append(tmpbuff, cnt); query.append("'"); } @@ -383,7 +383,7 @@ static MYSQL_RES *column_privs_raw_data(STMT * stmt, query.append("DATABASE()"); query.append("AND c.Column_name LIKE '"); - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)column, column_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)column, column_len); query.append(tmpbuff, cnt); query.append("' AND c.Table_name = t.Table_name " @@ -392,7 +392,7 @@ static MYSQL_RES *column_privs_raw_data(STMT * stmt, if (exec_stmt_query(stmt, query.c_str(), query.length(), FALSE)) return NULL; - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -428,7 +428,7 @@ Lengths may not be SQL_NTS. @param[in] table_length Length of table name @return Result of SHOW CREATE TABLE , or NULL if there is an error -or empty result (check stmt->dbc->mysql_proxy->error_code() != 0) +or empty result (check stmt->dbc->connection_proxy->error_code() != 0) */ MYSQL_RES *server_show_create_table(STMT *stmt, SQLCHAR *catalog, @@ -464,7 +464,7 @@ MYSQL_RES *server_show_create_table(STMT *stmt, return NULL; } - return stmt->dbc->mysql_proxy->store_result(); + return stmt->dbc->connection_proxy->store_result(); } @@ -603,12 +603,12 @@ primary_keys_no_i_s(SQLHSTMT hstmt, if (!stmt->lengths) { - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } row_count= 0; - while ((row = stmt->dbc->mysql_proxy->fetch_row(stmt->result))) + while ((row = stmt->dbc->connection_proxy->fetch_row(stmt->result))) { if ( row[1][0] == '0' ) /* If unique index */ { @@ -698,23 +698,23 @@ static MYSQL_RES *server_list_proc_params(STMT *stmt, SQLSMALLINT par_name_len) { DBC *dbc = stmt->dbc; - MYSQL_PROXY *mysql_proxy= dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= dbc->connection_proxy; char tmpbuf[1024]; std::string qbuff; qbuff.reserve(2048); - auto append_escaped_string = [&mysql_proxy, &tmpbuf](std::string &outstr, + auto append_escaped_string = [&connection_proxy, &tmpbuf](std::string &outstr, SQLCHAR* str, SQLSMALLINT len) { tmpbuf[0] = '\0'; outstr.append("'"); - mysql_proxy->real_escape_string(tmpbuf, (char *)str, len); + connection_proxy->real_escape_string(tmpbuf, (char *)str, len); outstr.append(tmpbuf).append("'"); }; - if((is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.7"))) + if((is_minimum_version(dbc->connection_proxy->get_server_version(), "5.7"))) { qbuff = "select SPECIFIC_NAME, (IF(ISNULL(PARAMETER_NAME), " "concat('OUT RETURN_VALUE ', DTD_IDENTIFIER), " @@ -767,7 +767,7 @@ static MYSQL_RES *server_list_proc_params(STMT *stmt, if (exec_stmt_query(stmt, qbuff.c_str(), qbuff.length(), FALSE)) return NULL; - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -817,7 +817,7 @@ procedure_columns_no_i_s(SQLHSTMT hstmt, SQLPROCEDURECOLUMNS_FIELDS); auto &data = stmt->m_row_storage; - while ((row = stmt->dbc->mysql_proxy->fetch_row(proc_list_res))) + while ((row = stmt->dbc->connection_proxy->fetch_row(proc_list_res))) { char *token; char *param_str; @@ -970,7 +970,7 @@ procedure_columns_no_i_s(SQLHSTMT hstmt, SQLPROCEDURECOLUMNS_fields, SQLPROCEDURECOLUMNS_FIELDS); free_internal_result_buffers(stmt); - stmt->dbc->mysql_proxy->free_result(proc_list_res); + stmt->dbc->connection_proxy->free_result(proc_list_res); case EXCEPTION_TYPE::GENERAL: break; } @@ -1056,8 +1056,8 @@ special_columns_no_i_s(SQLHSTMT hstmt, SQLUSMALLINT fColType, (SQLSMALLINT colType) { uint f_count = 0; - stmt->dbc->mysql_proxy->field_seek(result, 0); - while (field = stmt->dbc->mysql_proxy->fetch_field(result)) + stmt->dbc->connection_proxy->field_seek(result, 0); + while (field = stmt->dbc->connection_proxy->fetch_field(result)) { if(colType == SQL_ROWVER) { @@ -1140,7 +1140,7 @@ special_columns_no_i_s(SQLHSTMT hstmt, SQLUSMALLINT fColType, /* Check if there is a primary (unique) key */ primary_key= 0; - while ((field = stmt->dbc->mysql_proxy->fetch_field(result))) + while ((field = stmt->dbc->connection_proxy->fetch_field(result))) { if ( field->flags & PRI_KEY_FLAG ) { @@ -1225,7 +1225,7 @@ statistics_no_i_s(SQLHSTMT hstmt, sizeof(SQLSTAT_values),MYF(0)); if (!stmt->array) { - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } @@ -1250,7 +1250,7 @@ statistics_no_i_s(SQLHSTMT hstmt, } } (*prev)= 0; - stmt->dbc->mysql_proxy->data_seek(stmt->result,0); /* Restore pointer */ + stmt->dbc->connection_proxy->data_seek(stmt->result,0); /* Restore pointer */ } set_row_count(stmt, stmt->result->row_count); @@ -1412,10 +1412,10 @@ tables_no_i_s(SQLHSTMT hstmt, user_tables, views); } - if (!stmt->result && stmt->dbc->mysql_proxy->error_code()) + if (!stmt->result && stmt->dbc->connection_proxy->error_code()) { /* unknown DB will return empty set from SQLTables */ - switch (stmt->dbc->mysql_proxy->error_code()) + switch (stmt->dbc->connection_proxy->error_code()) { case ER_BAD_DB_ERROR: throw ODBCEXCEPTION(EXCEPTION_TYPE::EMPTY_SET); @@ -1438,7 +1438,7 @@ tables_no_i_s(SQLHSTMT hstmt, free_internal_result_buffers(stmt); if (stmt->result) { - stmt->dbc->mysql_proxy->free_result(stmt->result); + stmt->dbc->connection_proxy->free_result(stmt->result); stmt->result = nullptr; } @@ -1450,7 +1450,7 @@ tables_no_i_s(SQLHSTMT hstmt, stmt->m_row_storage.set_size(row_count, SQLTABLES_FIELDS); int name_index = 0; - while ((row = stmt->dbc->mysql_proxy->fetch_row(stmt->result))) + while ((row = stmt->dbc->connection_proxy->fetch_row(stmt->result))) { int type_index = 2; int comment_index = 1; diff --git a/driver/cluster_aware_metrics_container.cc b/driver/cluster_aware_metrics_container.cc index b8cff9b5f..ce51ff6c9 100644 --- a/driver/cluster_aware_metrics_container.cc +++ b/driver/cluster_aware_metrics_container.cc @@ -142,9 +142,9 @@ std::shared_ptr CLUSTER_AWARE_METRICS_CONTAINER::get_inst std::string CLUSTER_AWARE_METRICS_CONTAINER::get_curr_conn_url() { std::string curr_url = "[Unknown Url]"; - if (dbc && dbc->mysql_proxy) { - curr_url = dbc->mysql_proxy->get_host(); - curr_url.append(":").append(std::to_string(dbc->mysql_proxy->get_port())); + if (dbc && dbc->connection_proxy) { + curr_url = dbc->connection_proxy->get_host(); + curr_url.append(":").append(std::to_string(dbc->connection_proxy->get_port())); } return curr_url; } diff --git a/driver/connect.cc b/driver/connect.cc index ac2d71079..15ec94621 100644 --- a/driver/connect.cc +++ b/driver/connect.cc @@ -100,7 +100,7 @@ void DBC::set_charset(std::string charset) std::string query = "SET NAMES " + charset; if (odbc_stmt(this, query.c_str(), query.length(), TRUE)) { - throw MYERROR("HY000", mysql_proxy); + throw MYERROR("HY000", connection_proxy); } } @@ -140,7 +140,7 @@ try { MY_CHARSET_INFO my_charset; - mysql_proxy->get_character_set_info(&my_charset); + connection_proxy->get_character_set_info(&my_charset); cxn_charset_info = get_charset(my_charset.number, MYF(0)); } @@ -357,7 +357,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) #endif - this->mysql_proxy->init(); + this->connection_proxy->init(); flags = get_client_flags(dsrc); @@ -365,17 +365,17 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (dsrc->allow_big_results || dsrc->safe) #if MYSQL_VERSION_ID >= 50709 - mysql_proxy->options(MYSQL_OPT_MAX_ALLOWED_PACKET, &max_long); + connection_proxy->options(MYSQL_OPT_MAX_ALLOWED_PACKET, &max_long); #else /* max_allowed_packet is a magical mysql macro. */ max_allowed_packet = ~0L; #endif if (dsrc->force_use_of_named_pipes) - mysql_proxy->options(MYSQL_OPT_NAMED_PIPE, NullS); + connection_proxy->options(MYSQL_OPT_NAMED_PIPE, NullS); if (dsrc->read_options_from_mycnf) - mysql_proxy->options(MYSQL_READ_DEFAULT_GROUP, "odbc"); + connection_proxy->options(MYSQL_READ_DEFAULT_GROUP, "odbc"); unsigned int connect_timeout, read_timeout, write_timeout; if (failover_enabled) @@ -391,9 +391,9 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) write_timeout = get_network_timeout(dsrc->write_timeout); } - mysql_proxy->options(MYSQL_OPT_CONNECT_TIMEOUT, &connect_timeout); - mysql_proxy->options(MYSQL_OPT_READ_TIMEOUT, &read_timeout); - mysql_proxy->options(MYSQL_OPT_WRITE_TIMEOUT, &write_timeout); + connection_proxy->options(MYSQL_OPT_CONNECT_TIMEOUT, &connect_timeout); + connection_proxy->options(MYSQL_OPT_READ_TIMEOUT, &read_timeout); + connection_proxy->options(MYSQL_OPT_WRITE_TIMEOUT, &write_timeout); /* Pluggable authentication was introduced in mysql 5.5.7 @@ -401,7 +401,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) #if MYSQL_VERSION_ID >= 50507 if (dsrc->plugin_dir) { - mysql_proxy->options(MYSQL_PLUGIN_DIR, + connection_proxy->options(MYSQL_PLUGIN_DIR, ds_get_utf8attr(dsrc->plugin_dir, &dsrc->plugin_dir8)); } @@ -412,13 +412,13 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) If plugin directory is not set we can use the dll location for a better chance of finding plugins. */ - mysql_proxy->options(MYSQL_PLUGIN_DIR, default_plugin_location.c_str()); + connection_proxy->options(MYSQL_PLUGIN_DIR, default_plugin_location.c_str()); } #endif if (dsrc->default_auth) { - mysql_proxy->options(MYSQL_DEFAULT_AUTH, + connection_proxy->options(MYSQL_DEFAULT_AUTH, ds_get_utf8attr(dsrc->default_auth, &dsrc->default_auth8)); } @@ -439,7 +439,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (fido_func || fido_callback_is_set) { struct st_mysql_client_plugin* plugin = - mysql_proxy->client_find_plugin( + connection_proxy->client_find_plugin( "authentication_fido_client", MYSQL_CLIENT_AUTHENTICATION_PLUGIN); @@ -464,7 +464,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) { /* load client authentication plugin if required */ struct st_mysql_client_plugin *plugin = - mysql_proxy->client_find_plugin("authentication_oci_client", + connection_proxy->client_find_plugin("authentication_oci_client", MYSQL_CLIENT_AUTHENTICATION_PLUGIN); if(!plugin) @@ -483,7 +483,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) #endif /* set SSL parameters */ - mysql_proxy->ssl_set(ds_get_utf8attr(dsrc->sslkey, &dsrc->sslkey8), + connection_proxy->ssl_set(ds_get_utf8attr(dsrc->sslkey, &dsrc->sslkey8), ds_get_utf8attr(dsrc->sslcert, &dsrc->sslcert8), ds_get_utf8attr(dsrc->sslca, &dsrc->sslca8), ds_get_utf8attr(dsrc->sslcapath, &dsrc->sslcapath8), @@ -491,7 +491,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) #if MYSQL_VERSION_ID < 80003 if (dsrc->sslverify) - mysql_proxy->options(MYSQL_OPT_SSL_VERIFY_SERVER_CERT, + connection_proxy->options(MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (const char *)&opt_ssl_verify_server_cert); #endif @@ -499,7 +499,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (dsrc->rsakey) { /* Read the public key on the client side */ - mysql_proxy->options(MYSQL_SERVER_PUBLIC_KEY, + connection_proxy->options(MYSQL_SERVER_PUBLIC_KEY, ds_get_utf8attr(dsrc->rsakey, &dsrc->rsakey8)); } #endif @@ -531,7 +531,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) } if (!tls_options.length() || - mysql_proxy->options(MYSQL_OPT_TLS_VERSION, tls_options.c_str())) + connection_proxy->options(MYSQL_OPT_TLS_VERSION, tls_options.c_str())) { return set_error("HY000", "SSL connection error: No valid TLS version available", 0); @@ -541,7 +541,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (dsrc->ssl_crl) { - if (mysql_proxy->options(MYSQL_OPT_SSL_CRL, + if (connection_proxy->options(MYSQL_OPT_SSL_CRL, ds_get_utf8attr(dsrc->ssl_crl, &dsrc->ssl_crl8))) { return set_error("HY000", "Failed to set the certificate revocation list file", 0); @@ -550,7 +550,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (dsrc->ssl_crlpath) { - if (mysql_proxy->options(MYSQL_OPT_SSL_CRLPATH, + if (connection_proxy->options(MYSQL_OPT_SSL_CRLPATH, ds_get_utf8attr(dsrc->ssl_crlpath, &dsrc->ssl_crlpath8))) { return set_error("HY000", "Failed to set the certificate revocation list path", 0); @@ -561,7 +561,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (dsrc->get_server_public_key) { /* Get the server public key */ - mysql_proxy->options(MYSQL_OPT_GET_SERVER_PUBLIC_KEY, (const void*)&on); + connection_proxy->options(MYSQL_OPT_GET_SERVER_PUBLIC_KEY, (const void*)&on); } #endif @@ -571,12 +571,12 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) Get the ANSI charset info before we change connection to UTF-8. */ MY_CHARSET_INFO my_charset; - mysql_proxy->get_character_set_info(&my_charset); + connection_proxy->get_character_set_info(&my_charset); ansi_charset_info= get_charset(my_charset.number, MYF(0)); /* We always use utf8 for the connection, and change it afterwards if needed. */ - mysql_proxy->options(MYSQL_SET_CHARSET_NAME, transport_charset); + connection_proxy->options(MYSQL_SET_CHARSET_NAME, transport_charset); cxn_charset_info= utf8_charset_info; } else @@ -590,12 +590,12 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (client_cs_name) { - mysql_proxy->options(MYSQL_SET_CHARSET_NAME, client_cs_name); + connection_proxy->options(MYSQL_SET_CHARSET_NAME, client_cs_name); ansi_charset_info= cxn_charset_info= get_charset_by_csname(client_cs_name, MYF(MY_CS_PRIMARY), MYF(0)); } #else MY_CHARSET_INFO my_charset; - mysql_proxy->get_character_set_info(&my_charset); + connection_proxy->get_character_set_info(&my_charset); ansi_charset_info= get_charset(my_charset.number, MYF(0)); #endif } @@ -603,30 +603,30 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) #if MYSQL_VERSION_ID >= 50610 if (dsrc->can_handle_exp_pwd) { - mysql_proxy->options(MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, (char *)&on); + connection_proxy->options(MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, (char *)&on); } #endif #if (MYSQL_VERSION_ID >= 50527 && MYSQL_VERSION_ID < 50600) || MYSQL_VERSION_ID >= 50607 if (dsrc->enable_cleartext_plugin) { - mysql_proxy->options(MYSQL_ENABLE_CLEARTEXT_PLUGIN, (char *)&on); + connection_proxy->options(MYSQL_ENABLE_CLEARTEXT_PLUGIN, (char *)&on); } #endif if (dsrc->enable_local_infile) { - mysql_proxy->options(MYSQL_OPT_LOCAL_INFILE, &on_int); + connection_proxy->options(MYSQL_OPT_LOCAL_INFILE, &on_int); } else { - mysql_proxy->options(MYSQL_OPT_LOCAL_INFILE, &off_int); + connection_proxy->options(MYSQL_OPT_LOCAL_INFILE, &off_int); } if (dsrc->load_data_local_dir && dsrc->load_data_local_dir[0]) { ds_get_utf8attr(dsrc->load_data_local_dir, &dsrc->load_data_local_dir8); - mysql_proxy->options(MYSQL_OPT_LOAD_DATA_LOCAL_DIR, + connection_proxy->options(MYSQL_OPT_LOAD_DATA_LOCAL_DIR, dsrc->load_data_local_dir8); } @@ -635,7 +635,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) { ds_get_utf8attr(dsrc->pwd1, &dsrc->pwd18); int fator = 1; - mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, dsrc->pwd18); } @@ -644,7 +644,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) { ds_get_utf8attr(dsrc->pwd2, &dsrc->pwd28); int fator = 2; - mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, dsrc->pwd28); } @@ -653,7 +653,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) { ds_get_utf8attr(dsrc->pwd3, &dsrc->pwd38); int fator = 3; - mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, dsrc->pwd38); } @@ -676,7 +676,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) // Don't do anything if there is no match with any of the available modes if (mode) - mysql_proxy->options(MYSQL_OPT_SSL_MODE, &mode); + connection_proxy->options(MYSQL_OPT_SSL_MODE, &mode); } #endif @@ -745,7 +745,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) { protocol = MYSQL_PROTOCOL_TCP; } - mysql_proxy->options(MYSQL_OPT_PROTOCOL, &protocol); + connection_proxy->options(MYSQL_OPT_PROTOCOL, &protocol); //Setting server and port to the dsrc->server8 and dsrc->port ds_set_strnattr(&dsrc->server8, (SQLCHAR*)host, strlen(host)); @@ -756,13 +756,13 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) //Aws::ShutdownAPI(options); const bool connect_result = dsrc->enable_dns_srv ? - mysql_proxy->real_connect_dns_srv(host, + connection_proxy->real_connect_dns_srv(host, ds_get_utf8attr(dsrc->uid, &dsrc->uid8), ds_get_utf8attr(dsrc->pwd, &dsrc->pwd8), ds_get_utf8attr(dsrc->database, &dsrc->database8), flags) : - mysql_proxy->real_connect(host, + connection_proxy->real_connect(host, ds_get_utf8attr(dsrc->uid, &dsrc->uid8), ds_get_utf8attr(dsrc->pwd, &dsrc->pwd8), ds_get_utf8attr(dsrc->database, &dsrc->database8), @@ -771,7 +771,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) flags); if (!connect_result) { - unsigned int native_error= mysql_proxy->error_code(); + unsigned int native_error= connection_proxy->error_code(); /* Before 5.6.11 error returned by server was ER_MUST_CHANGE_PASSWORD(1820). In 5.6.11 it changed to ER_MUST_CHANGE_PASSWORD_LOGIN(1862) @@ -795,7 +795,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) "this functionlaity", 0); } #endif - set_error("HY000", mysql_proxy->error(), native_error); + set_error("HY000", connection_proxy->error(), native_error); translate_error((char*)error.sqlstate.c_str(), MYERR_S1000, native_error); @@ -829,7 +829,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) } else { - switch (mysql_proxy->error_code()) + switch (connection_proxy->error_code()) { case ER_CON_COUNT_ERROR: case CR_SOCKET_CREATE_ERROR: @@ -841,7 +841,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) break; default: //If SQLSTATE not 08xxx, which is used for network errors - if(strncmp(mysql_proxy->sqlstate(), "08", 2) != 0) + if(strncmp(connection_proxy->sqlstate(), "08", 2) != 0) { //Return error and do not try another host return SQL_ERROR; @@ -868,9 +868,9 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) } } - has_query_attrs = mysql_proxy->get_server_capabilities() & CLIENT_QUERY_ATTRIBUTES; + has_query_attrs = connection_proxy->get_server_capabilities() & CLIENT_QUERY_ATTRIBUTES; - if (!is_minimum_version(mysql_proxy->get_server_version(), "4.1.1")) + if (!is_minimum_version(connection_proxy->get_server_version(), "4.1.1")) { close(); return set_error("08001", "Driver does not support server versions under 4.1.1", 0); @@ -925,12 +925,12 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) /* Set the statement error prefix based on the server version. */ strxmov(st_error_prefix, MYODBC_ERROR_PREFIX, "[mysqld-", - mysql_proxy->get_server_version(), "]", NullS); + connection_proxy->get_server_version(), "]", NullS); /* This needs to be set after connection, or it doesn't stick. */ if (ds->auto_reconnect) { - mysql_proxy->options(MYSQL_OPT_RECONNECT, (char *)&on); + connection_proxy->options(MYSQL_OPT_RECONNECT, (char *)&on); } /* Make sure autocommit is set as configured. */ @@ -944,7 +944,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) "SQL_AUTOCOMMIT_OFF changed to SQL_AUTOCOMMIT_ON", SQL_SUCCESS_WITH_INFO); } - else if (autocommit_is_on() && mysql_proxy->autocommit(FALSE)) + else if (autocommit_is_on() && connection_proxy->autocommit(FALSE)) { /** @todo set error */ goto error; @@ -953,7 +953,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) else if ((commit_flag == CHECK_AUTOCOMMIT_ON) && transactions_supported() && !autocommit_is_on()) { - if (mysql_proxy->autocommit(TRUE)) + if (connection_proxy->autocommit(TRUE)) { /** @todo set error */ goto error; @@ -992,7 +992,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) } } - mysql_proxy->get_option(MYSQL_OPT_NET_BUFFER_LENGTH, &net_buffer_len); + connection_proxy->get_option(MYSQL_OPT_NET_BUFFER_LENGTH, &net_buffer_len); guard.set_success(rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO); return rc; @@ -1033,7 +1033,7 @@ SQLRETURN SQL_API MySQLConnect(SQLHDBC hdbc, #else /* Can't connect if we're already connected. */ - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) return set_conn_error((DBC*)hdbc, MYERR_08002, NULL, 0); /* Reset error state */ @@ -1455,9 +1455,9 @@ SQLRETURN SQL_API SQLDisconnect(SQLHDBC hdbc) cluster_id_str = dbc->fh->cluster_id; } - if (((cluster_id_str == DEFAULT_CLUSTER_ID) || ds->gather_metrics_per_instance) && dbc->mysql_proxy) { - cluster_id_str = dbc->mysql_proxy->get_host(); - cluster_id_str.append(":").append(std::to_string(dbc->mysql_proxy->get_port())); + if (((cluster_id_str == DEFAULT_CLUSTER_ID) || ds->gather_metrics_per_instance) && dbc->connection_proxy) { + cluster_id_str = dbc->connection_proxy->get_host(); + cluster_id_str.append(":").append(std::to_string(dbc->connection_proxy->get_port())); } CLUSTER_AWARE_METRICS_CONTAINER::report_metrics( @@ -1493,10 +1493,10 @@ void DBC::execute_prep_stmt(MYSQL_STMT *pstmt, std::string &query, MYSQL_BIND *param_bind, MYSQL_BIND *result_bind) { if ( - mysql_proxy->stmt_prepare(pstmt, query.c_str(), query.length()) || - (param_bind && mysql_proxy->stmt_bind_param(pstmt, param_bind)) || - mysql_proxy->stmt_execute(pstmt) || - (result_bind && mysql_proxy->stmt_bind_result(pstmt, result_bind)) + connection_proxy->stmt_prepare(pstmt, query.c_str(), query.length()) || + (param_bind && connection_proxy->stmt_bind_param(pstmt, param_bind)) || + connection_proxy->stmt_execute(pstmt) || + (result_bind && connection_proxy->stmt_bind_result(pstmt, result_bind)) ) { set_error("HY000"); @@ -1505,7 +1505,7 @@ void DBC::execute_prep_stmt(MYSQL_STMT *pstmt, std::string &query, if ( - (result_bind && mysql_proxy->stmt_store_result(pstmt)) + (result_bind && connection_proxy->stmt_store_result(pstmt)) ) { set_error("HY000"); diff --git a/driver/connection_handler.cc b/driver/connection_handler.cc index 863b39055..b0b7497ed 100644 --- a/driver/connection_handler.cc +++ b/driver/connection_handler.cc @@ -34,7 +34,7 @@ #include "connection_handler.h" #include "driver.h" -#include "mysql_proxy.h" +#include "connection_proxy.h" #include #include @@ -60,7 +60,7 @@ SQLRETURN CONNECTION_HANDLER::do_connect(DBC* dbc_ptr, DataSource* ds, bool fail return dbc_ptr->connect(ds, failover_enabled); } -MYSQL_PROXY* CONNECTION_HANDLER::connect(const std::shared_ptr& host_info, DataSource* ds) { +CONNECTION_PROXY* CONNECTION_HANDLER::connect(const std::shared_ptr& host_info, DataSource* ds) { if (dbc == nullptr || host_info == nullptr) { return nullptr; @@ -74,13 +74,13 @@ MYSQL_PROXY* CONNECTION_HANDLER::connect(const std::shared_ptr& host_ DBC* dbc_clone = clone_dbc(dbc, ds_to_use); ds_set_wstrnattr(&ds_to_use->server, (SQLWCHAR*)new_host.c_str(), new_host.size()); - MYSQL_PROXY* new_connection = nullptr; + CONNECTION_PROXY* new_connection = nullptr; CLEAR_DBC_ERROR(dbc_clone); const SQLRETURN rc = do_connect(dbc_clone, ds_to_use, ds_to_use->enable_cluster_failover); if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - new_connection = dbc_clone->mysql_proxy; - dbc_clone->mysql_proxy = nullptr; + new_connection = dbc_clone->connection_proxy; + dbc_clone->connection_proxy = nullptr; // postpone the deletion of ds_to_use/dbc_clone->ds until we are done with new_connection dbc_clone->ds = nullptr; } @@ -91,11 +91,11 @@ MYSQL_PROXY* CONNECTION_HANDLER::connect(const std::shared_ptr& host_ } void CONNECTION_HANDLER::update_connection( - MYSQL_PROXY* new_connection, const std::string& new_host_name) { + CONNECTION_PROXY* new_connection, const std::string& new_host_name) { if (new_connection->is_connected()) { dbc->close(); - dbc->mysql_proxy->set_connection(new_connection); + dbc->connection_proxy->set_connection(new_connection); CLEAR_DBC_ERROR(dbc); diff --git a/driver/connection_handler.h b/driver/connection_handler.h index 43e7d577a..d5423527a 100644 --- a/driver/connection_handler.h +++ b/driver/connection_handler.h @@ -43,7 +43,7 @@ sqlwchar_string to_sqlwchar_string(const std::string& src); struct DBC; struct DataSource; -class MYSQL_PROXY; +class CONNECTION_PROXY; typedef short SQLRETURN; class CONNECTION_HANDLER { @@ -52,8 +52,8 @@ class CONNECTION_HANDLER { virtual ~CONNECTION_HANDLER(); virtual SQLRETURN do_connect(DBC* dbc_ptr, DataSource* ds, bool failover_enabled); - virtual MYSQL_PROXY* connect(const std::shared_ptr& host_info, DataSource* ds); - void update_connection(MYSQL_PROXY* new_connection, const std::string& new_host_name); + virtual CONNECTION_PROXY* connect(const std::shared_ptr& host_info, DataSource* ds); + void update_connection(CONNECTION_PROXY* new_connection, const std::string& new_host_name); private: DBC* dbc; diff --git a/driver/mysql_proxy.cc b/driver/connection_proxy.cc similarity index 53% rename from driver/mysql_proxy.cc rename to driver/connection_proxy.cc index 8f23dd1b6..7073ac3aa 100644 --- a/driver/mysql_proxy.cc +++ b/driver/connection_proxy.cc @@ -29,7 +29,7 @@ #include "driver.h" -MYSQL_PROXY::MYSQL_PROXY(DBC* dbc, DataSource* ds) : dbc{dbc}, ds{ds} { +CONNECTION_PROXY::CONNECTION_PROXY(DBC* dbc, DataSource* ds) : dbc{dbc}, ds{ds} { if (!this->dbc) { throw std::runtime_error("DBC cannot be null."); } @@ -39,73 +39,73 @@ MYSQL_PROXY::MYSQL_PROXY(DBC* dbc, DataSource* ds) : dbc{dbc}, ds{ds} { } } -MYSQL_PROXY::~MYSQL_PROXY() { +CONNECTION_PROXY::~CONNECTION_PROXY() { if (this->next_proxy) { delete next_proxy; } } -void MYSQL_PROXY::delete_ds() { +void CONNECTION_PROXY::delete_ds() { next_proxy->delete_ds(); } -uint64_t MYSQL_PROXY::num_rows(MYSQL_RES* res) { +uint64_t CONNECTION_PROXY::num_rows(MYSQL_RES* res) { return next_proxy->num_rows(res); } -unsigned int MYSQL_PROXY::num_fields(MYSQL_RES* res) { +unsigned int CONNECTION_PROXY::num_fields(MYSQL_RES* res) { return next_proxy->num_fields(res); } -MYSQL_FIELD* MYSQL_PROXY::fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) { +MYSQL_FIELD* CONNECTION_PROXY::fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) { return next_proxy->fetch_field_direct(res, fieldnr); } -MYSQL_ROW_OFFSET MYSQL_PROXY::row_tell(MYSQL_RES* res) { +MYSQL_ROW_OFFSET CONNECTION_PROXY::row_tell(MYSQL_RES* res) { return next_proxy->row_tell(res); } -unsigned int MYSQL_PROXY::field_count() { +unsigned int CONNECTION_PROXY::field_count() { return next_proxy->field_count(); } -uint64_t MYSQL_PROXY::affected_rows() { +uint64_t CONNECTION_PROXY::affected_rows() { return next_proxy->affected_rows(); } -unsigned int MYSQL_PROXY::error_code() { +unsigned int CONNECTION_PROXY::error_code() { return next_proxy->error_code(); } -const char* MYSQL_PROXY::error() { +const char* CONNECTION_PROXY::error() { return next_proxy->error(); } -const char* MYSQL_PROXY::sqlstate() { +const char* CONNECTION_PROXY::sqlstate() { return next_proxy->sqlstate(); } -unsigned long MYSQL_PROXY::thread_id() { +unsigned long CONNECTION_PROXY::thread_id() { return next_proxy->thread_id(); } -int MYSQL_PROXY::set_character_set(const char* csname) { +int CONNECTION_PROXY::set_character_set(const char* csname) { return next_proxy->set_character_set(csname); } -void MYSQL_PROXY::init() { +void CONNECTION_PROXY::init() { next_proxy->init(); } -bool MYSQL_PROXY::ssl_set(const char* key, const char* cert, const char* ca, const char* capath, const char* cipher) { +bool CONNECTION_PROXY::ssl_set(const char* key, const char* cert, const char* ca, const char* capath, const char* cipher) { return next_proxy->ssl_set(key, cert, ca, capath, cipher); } -bool MYSQL_PROXY::change_user(const char* user, const char* passwd, const char* db) { +bool CONNECTION_PROXY::change_user(const char* user, const char* passwd, const char* db) { return next_proxy->change_user(user, passwd, db); } -bool MYSQL_PROXY::real_connect( +bool CONNECTION_PROXY::real_connect( const char* host, const char* user, const char* passwd, const char* db, unsigned int port, const char* unix_socket, unsigned long clientflag) { @@ -113,276 +113,276 @@ bool MYSQL_PROXY::real_connect( return next_proxy->real_connect(host, user, passwd, db, port, unix_socket, clientflag); } -int MYSQL_PROXY::select_db(const char* db) { +int CONNECTION_PROXY::select_db(const char* db) { return next_proxy->select_db(db); } -int MYSQL_PROXY::query(const char* q) { +int CONNECTION_PROXY::query(const char* q) { return next_proxy->query(q); } -int MYSQL_PROXY::real_query(const char* q, unsigned long length) { +int CONNECTION_PROXY::real_query(const char* q, unsigned long length) { return next_proxy->real_query(q, length); } -MYSQL_RES* MYSQL_PROXY::store_result() { +MYSQL_RES* CONNECTION_PROXY::store_result() { return next_proxy->store_result(); } -MYSQL_RES* MYSQL_PROXY::use_result() { +MYSQL_RES* CONNECTION_PROXY::use_result() { return next_proxy->use_result(); } -struct CHARSET_INFO* MYSQL_PROXY::get_character_set() const { +struct CHARSET_INFO* CONNECTION_PROXY::get_character_set() const { return next_proxy->get_character_set(); } -void MYSQL_PROXY::get_character_set_info(MY_CHARSET_INFO* charset) { +void CONNECTION_PROXY::get_character_set_info(MY_CHARSET_INFO* charset) { next_proxy->get_character_set_info(charset); } -bool MYSQL_PROXY::autocommit(bool auto_mode) { +bool CONNECTION_PROXY::autocommit(bool auto_mode) { return next_proxy->autocommit(auto_mode); } -int MYSQL_PROXY::next_result() { +int CONNECTION_PROXY::next_result() { return next_proxy->next_result(); } -int MYSQL_PROXY::stmt_next_result(MYSQL_STMT* stmt) { +int CONNECTION_PROXY::stmt_next_result(MYSQL_STMT* stmt) { return next_proxy->stmt_next_result(stmt); } -void MYSQL_PROXY::close() { +void CONNECTION_PROXY::close() { next_proxy->close(); } -bool MYSQL_PROXY::real_connect_dns_srv( +bool CONNECTION_PROXY::real_connect_dns_srv( const char* dns_srv_name, const char* user, const char* passwd, const char* db, unsigned long client_flag) { return next_proxy->real_connect_dns_srv(dns_srv_name, user, passwd, db, client_flag); } -int MYSQL_PROXY::ping() { +int CONNECTION_PROXY::ping() { return next_proxy->ping(); } -unsigned long MYSQL_PROXY::get_client_version(void) { +unsigned long CONNECTION_PROXY::get_client_version(void) { return mysql_get_client_version(); } -int MYSQL_PROXY::get_option(mysql_option option, const void* arg) { +int CONNECTION_PROXY::get_option(mysql_option option, const void* arg) { return next_proxy->get_option(option, arg); } -int MYSQL_PROXY::options4(mysql_option option, const void* arg1, const void* arg2) { +int CONNECTION_PROXY::options4(mysql_option option, const void* arg1, const void* arg2) { return next_proxy->options4(option, arg1, arg2); } -int MYSQL_PROXY::options(mysql_option option, const void* arg) { +int CONNECTION_PROXY::options(mysql_option option, const void* arg) { return next_proxy->options(option, arg); } -void MYSQL_PROXY::free_result(MYSQL_RES* result) { +void CONNECTION_PROXY::free_result(MYSQL_RES* result) { next_proxy->free_result(result); } -void MYSQL_PROXY::data_seek(MYSQL_RES* result, uint64_t offset) { +void CONNECTION_PROXY::data_seek(MYSQL_RES* result, uint64_t offset) { next_proxy->data_seek(result, offset); } -MYSQL_ROW_OFFSET MYSQL_PROXY::row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) { +MYSQL_ROW_OFFSET CONNECTION_PROXY::row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) { return next_proxy->row_seek(result, offset); } -MYSQL_FIELD_OFFSET MYSQL_PROXY::field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) { +MYSQL_FIELD_OFFSET CONNECTION_PROXY::field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) { return next_proxy->field_seek(result, offset); } -MYSQL_ROW MYSQL_PROXY::fetch_row(MYSQL_RES* result) { +MYSQL_ROW CONNECTION_PROXY::fetch_row(MYSQL_RES* result) { return next_proxy->fetch_row(result); } -unsigned long* MYSQL_PROXY::fetch_lengths(MYSQL_RES* result) { +unsigned long* CONNECTION_PROXY::fetch_lengths(MYSQL_RES* result) { return next_proxy->fetch_lengths(result); } -MYSQL_FIELD* MYSQL_PROXY::fetch_field(MYSQL_RES* result) { +MYSQL_FIELD* CONNECTION_PROXY::fetch_field(MYSQL_RES* result) { return next_proxy->fetch_field(result); } -MYSQL_RES* MYSQL_PROXY::list_fields(const char* table, const char* wild) { +MYSQL_RES* CONNECTION_PROXY::list_fields(const char* table, const char* wild) { return next_proxy->list_fields(table, wild); } -unsigned long MYSQL_PROXY::real_escape_string(char* to, const char* from, unsigned long length) { +unsigned long CONNECTION_PROXY::real_escape_string(char* to, const char* from, unsigned long length) { return next_proxy->real_escape_string(to, from, length); } -bool MYSQL_PROXY::bind_param(unsigned n_params, MYSQL_BIND* binds, const char** names) { +bool CONNECTION_PROXY::bind_param(unsigned n_params, MYSQL_BIND* binds, const char** names) { return next_proxy->bind_param(n_params, binds, names); } -MYSQL_STMT* MYSQL_PROXY::stmt_init() { +MYSQL_STMT* CONNECTION_PROXY::stmt_init() { return next_proxy->stmt_init(); } -int MYSQL_PROXY::stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length) { +int CONNECTION_PROXY::stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length) { return next_proxy->stmt_prepare(stmt, query, length); } -int MYSQL_PROXY::stmt_execute(MYSQL_STMT* stmt) { +int CONNECTION_PROXY::stmt_execute(MYSQL_STMT* stmt) { return next_proxy->stmt_execute(stmt); } -int MYSQL_PROXY::stmt_fetch(MYSQL_STMT* stmt) { +int CONNECTION_PROXY::stmt_fetch(MYSQL_STMT* stmt) { return next_proxy->stmt_fetch(stmt); } -int MYSQL_PROXY::stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, unsigned int column, unsigned long offset) { +int CONNECTION_PROXY::stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, unsigned int column, unsigned long offset) { return next_proxy->stmt_fetch_column(stmt, bind_arg, column, offset); } -int MYSQL_PROXY::stmt_store_result(MYSQL_STMT* stmt) { +int CONNECTION_PROXY::stmt_store_result(MYSQL_STMT* stmt) { return next_proxy->stmt_store_result(stmt); } -unsigned long MYSQL_PROXY::stmt_param_count(MYSQL_STMT* stmt) { +unsigned long CONNECTION_PROXY::stmt_param_count(MYSQL_STMT* stmt) { return next_proxy->stmt_param_count(stmt); } -bool MYSQL_PROXY::stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { +bool CONNECTION_PROXY::stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { return next_proxy->stmt_bind_param(stmt, bnd); } -bool MYSQL_PROXY::stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { +bool CONNECTION_PROXY::stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { return next_proxy->stmt_bind_result(stmt, bnd); } -bool MYSQL_PROXY::stmt_close(MYSQL_STMT* stmt) { +bool CONNECTION_PROXY::stmt_close(MYSQL_STMT* stmt) { return next_proxy->stmt_close(stmt); } -bool MYSQL_PROXY::stmt_reset(MYSQL_STMT* stmt) { +bool CONNECTION_PROXY::stmt_reset(MYSQL_STMT* stmt) { return next_proxy->stmt_reset(stmt); } -bool MYSQL_PROXY::stmt_free_result(MYSQL_STMT* stmt) { +bool CONNECTION_PROXY::stmt_free_result(MYSQL_STMT* stmt) { return next_proxy->stmt_free_result(stmt); } -bool MYSQL_PROXY::stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, const char* data, +bool CONNECTION_PROXY::stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, const char* data, unsigned long length) { return next_proxy->stmt_send_long_data(stmt, param_number, data, length); } -MYSQL_RES* MYSQL_PROXY::stmt_result_metadata(MYSQL_STMT* stmt) { +MYSQL_RES* CONNECTION_PROXY::stmt_result_metadata(MYSQL_STMT* stmt) { return next_proxy->stmt_result_metadata(stmt); } -unsigned int MYSQL_PROXY::stmt_errno(MYSQL_STMT* stmt) { +unsigned int CONNECTION_PROXY::stmt_errno(MYSQL_STMT* stmt) { return next_proxy->stmt_errno(stmt); } -const char* MYSQL_PROXY::stmt_error(MYSQL_STMT* stmt) { +const char* CONNECTION_PROXY::stmt_error(MYSQL_STMT* stmt) { return next_proxy->stmt_error(stmt); } -MYSQL_ROW_OFFSET MYSQL_PROXY::stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) { +MYSQL_ROW_OFFSET CONNECTION_PROXY::stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) { return next_proxy->stmt_row_seek(stmt, offset); } -MYSQL_ROW_OFFSET MYSQL_PROXY::stmt_row_tell(MYSQL_STMT* stmt) { +MYSQL_ROW_OFFSET CONNECTION_PROXY::stmt_row_tell(MYSQL_STMT* stmt) { return next_proxy->stmt_row_tell(stmt); } -void MYSQL_PROXY::stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) { +void CONNECTION_PROXY::stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) { next_proxy->stmt_data_seek(stmt, offset); } -uint64_t MYSQL_PROXY::stmt_num_rows(MYSQL_STMT* stmt) { +uint64_t CONNECTION_PROXY::stmt_num_rows(MYSQL_STMT* stmt) { return next_proxy->stmt_num_rows(stmt); } -uint64_t MYSQL_PROXY::stmt_affected_rows(MYSQL_STMT* stmt) { +uint64_t CONNECTION_PROXY::stmt_affected_rows(MYSQL_STMT* stmt) { return next_proxy->stmt_affected_rows(stmt); } -unsigned int MYSQL_PROXY::stmt_field_count(MYSQL_STMT* stmt) { +unsigned int CONNECTION_PROXY::stmt_field_count(MYSQL_STMT* stmt) { return next_proxy->stmt_field_count(stmt); } -st_mysql_client_plugin* MYSQL_PROXY::client_find_plugin(const char* name, int type) { +st_mysql_client_plugin* CONNECTION_PROXY::client_find_plugin(const char* name, int type) { return next_proxy->client_find_plugin(name, type); } -bool MYSQL_PROXY::is_connected() { +bool CONNECTION_PROXY::is_connected() { return next_proxy->is_connected(); } -void MYSQL_PROXY::set_last_error_code(unsigned int error_code) { +void CONNECTION_PROXY::set_last_error_code(unsigned int error_code) { next_proxy->set_last_error_code(error_code); } -char* MYSQL_PROXY::get_last_error() const { +char* CONNECTION_PROXY::get_last_error() const { return next_proxy->get_last_error(); } -unsigned int MYSQL_PROXY::get_last_error_code() const { +unsigned int CONNECTION_PROXY::get_last_error_code() const { return next_proxy->get_last_error_code(); } -char* MYSQL_PROXY::get_sqlstate() const { +char* CONNECTION_PROXY::get_sqlstate() const { return next_proxy->get_sqlstate(); } -char* MYSQL_PROXY::get_server_version() const { +char* CONNECTION_PROXY::get_server_version() const { return next_proxy->get_server_version(); } -uint64_t MYSQL_PROXY::get_affected_rows() const { +uint64_t CONNECTION_PROXY::get_affected_rows() const { return next_proxy->get_affected_rows(); } -void MYSQL_PROXY::set_affected_rows(uint64_t num_rows) { +void CONNECTION_PROXY::set_affected_rows(uint64_t num_rows) { next_proxy->set_affected_rows(num_rows); } -char* MYSQL_PROXY::get_host_info() const { +char* CONNECTION_PROXY::get_host_info() const { return next_proxy->get_host_info(); } -std::string MYSQL_PROXY::get_host() { +std::string CONNECTION_PROXY::get_host() { return next_proxy->get_host(); } -unsigned int MYSQL_PROXY::get_port() { +unsigned int CONNECTION_PROXY::get_port() { return next_proxy->get_port(); } -unsigned long MYSQL_PROXY::get_max_packet() const { +unsigned long CONNECTION_PROXY::get_max_packet() const { return next_proxy->get_max_packet(); } -unsigned long MYSQL_PROXY::get_server_capabilities() const { +unsigned long CONNECTION_PROXY::get_server_capabilities() const { return next_proxy->get_server_capabilities(); } -unsigned int MYSQL_PROXY::get_server_status() const { +unsigned int CONNECTION_PROXY::get_server_status() const { return next_proxy->get_server_status(); } -void MYSQL_PROXY::set_connection(MYSQL_PROXY* mysql_proxy) { - next_proxy->set_connection(mysql_proxy); +void CONNECTION_PROXY::set_connection(CONNECTION_PROXY* connection_proxy) { + next_proxy->set_connection(connection_proxy); } -void MYSQL_PROXY::close_socket() { +void CONNECTION_PROXY::close_socket() { next_proxy->close_socket(); } -void MYSQL_PROXY::set_next_proxy(MYSQL_PROXY* next_proxy) { +void CONNECTION_PROXY::set_next_proxy(CONNECTION_PROXY* next_proxy) { if (this->next_proxy) { throw std::runtime_error("There is already a next proxy present!"); } @@ -390,6 +390,6 @@ void MYSQL_PROXY::set_next_proxy(MYSQL_PROXY* next_proxy) { this->next_proxy = next_proxy; } -MYSQL* MYSQL_PROXY::move_mysql_connection() { +MYSQL* CONNECTION_PROXY::move_mysql_connection() { return next_proxy ? next_proxy->move_mysql_connection() : nullptr; } diff --git a/driver/mysql_proxy.h b/driver/connection_proxy.h similarity index 94% rename from driver/mysql_proxy.h rename to driver/connection_proxy.h index 671c30a22..5c8b268b3 100644 --- a/driver/mysql_proxy.h +++ b/driver/connection_proxy.h @@ -27,16 +27,16 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. -#ifndef __MYSQL_PROXY__ -#define __MYSQL_PROXY__ +#ifndef __CONNECTION_PROXY__ +#define __CONNECTION_PROXY__ struct DBC; struct DataSource; -class MYSQL_PROXY { +class CONNECTION_PROXY { public: - MYSQL_PROXY(DBC* dbc, DataSource* ds); - virtual ~MYSQL_PROXY(); + CONNECTION_PROXY(DBC* dbc, DataSource* ds); + virtual ~CONNECTION_PROXY(); virtual void delete_ds(); virtual uint64_t num_rows(MYSQL_RES* res); @@ -153,18 +153,18 @@ class MYSQL_PROXY { virtual unsigned int get_server_status() const; - virtual void set_connection(MYSQL_PROXY* mysql_proxy); + virtual void set_connection(CONNECTION_PROXY* connection_proxy); virtual void close_socket(); - virtual void set_next_proxy(MYSQL_PROXY* next_proxy); + virtual void set_next_proxy(CONNECTION_PROXY* next_proxy); virtual MYSQL* move_mysql_connection(); protected: DBC* dbc = nullptr; DataSource* ds = nullptr; - MYSQL_PROXY* next_proxy = nullptr; + CONNECTION_PROXY* next_proxy = nullptr; }; -#endif /* __MYSQL_PROXY__ */ +#endif /* __CONNECTION_PROXY__ */ diff --git a/driver/cursor.cc b/driver/cursor.cc index bda25ce0b..74fc0abfc 100644 --- a/driver/cursor.cc +++ b/driver/cursor.cc @@ -51,7 +51,7 @@ /* Sets affected rows everewhere where SQLRowCOunt could look for */ void global_set_affected_rows(STMT * stmt, my_ulonglong rows) { - stmt->dbc->mysql_proxy->set_affected_rows(rows); + stmt->dbc->connection_proxy->set_affected_rows(rows); stmt->affected_rows = rows; /* Dirty hack. But not dirtier than the one above */ @@ -227,7 +227,7 @@ static my_bool check_if_usable_unique_key_exists(STMT *stmt) /* Use SHOW KEYS FROM table to check for keys. */ pos= myodbc_stpmov(buff, "SHOW KEYS FROM `"); - pos+= stmt->dbc->mysql_proxy->real_escape_string(pos, table, strlen(table)); + pos+= stmt->dbc->connection_proxy->real_escape_string(pos, table, strlen(table)); pos= myodbc_stpmov(pos, "`"); MYLOG_STMT_TRACE(stmt, buff); @@ -235,13 +235,13 @@ static my_bool check_if_usable_unique_key_exists(STMT *stmt) assert(stmt); LOCK_DBC(stmt->dbc); if (exec_stmt_query(stmt, buff, strlen(buff), FALSE) || - !(res = stmt->dbc->mysql_proxy->store_result())) + !(res = stmt->dbc->connection_proxy->store_result())) { stmt->set_error(MYERR_S1000); return FALSE; } - while ((row = stmt->dbc->mysql_proxy->fetch_row(res)) && + while ((row = stmt->dbc->connection_proxy->fetch_row(res)) && stmt->cursor.pk_count < MY_MAX_PK_PARTS) { int seq= atoi(row[3]); @@ -269,7 +269,7 @@ static my_bool check_if_usable_unique_key_exists(STMT *stmt) /* Forget about any key we had in progress, we didn't have it all. */ stmt->cursor.pk_count= seq_in_index= 0; } - stmt->dbc->mysql_proxy->free_result(res); + stmt->dbc->connection_proxy->free_result(res); /* Remember that we've figured this out already. */ stmt->cursor.pk_validated= 1; @@ -450,7 +450,7 @@ static bool insert_field_std(STMT *stmt, MYSQL_RES *result, iprec_(DESC_PARAM, DESC_IMP); DESCREC *aprec= &aprec_, *iprec= &iprec_; - MYSQL_FIELD *field= stmt->dbc->mysql_proxy->fetch_field_direct(result,nSrcCol); + MYSQL_FIELD *field= stmt->dbc->connection_proxy->fetch_field_direct(result,nSrcCol); MYSQL_ROW row_data; SQLLEN length; char as_string[50], *dummy; @@ -578,7 +578,7 @@ static SQLRETURN append_all_fields_std(STMT *stmt, std::string &str) MYLOG_STMT_TRACE(stmt, select.c_str()); LOCK_STMT(stmt); if (exec_stmt_query_std(stmt, select, false) || - !(presultAllColumns = stmt->dbc->mysql_proxy->store_result())) + !(presultAllColumns = stmt->dbc->connection_proxy->store_result())) { stmt->set_error(MYERR_S1000); return SQL_ERROR; @@ -588,10 +588,10 @@ static SQLRETURN append_all_fields_std(STMT *stmt, std::string &str) If the number of fields in the underlying table is not the same as our result set, we bail out -- we need them all! */ - if (stmt->dbc->mysql_proxy->num_fields(presultAllColumns) != - stmt->dbc->mysql_proxy->num_fields(result)) + if (stmt->dbc->connection_proxy->num_fields(presultAllColumns) != + stmt->dbc->connection_proxy->num_fields(result)) { - stmt->dbc->mysql_proxy->free_result(presultAllColumns); + stmt->dbc->connection_proxy->free_result(presultAllColumns); return SQL_ERROR; } @@ -614,7 +614,7 @@ static SQLRETURN append_all_fields_std(STMT *stmt, std::string &str) { stmt->set_error(MYERR_S1000, "Invalid use of floating point comparision in positioned operations",0); - stmt->dbc->mysql_proxy->free_result(presultAllColumns); + stmt->dbc->connection_proxy->free_result(presultAllColumns); return SQL_ERROR; } @@ -629,7 +629,7 @@ static SQLRETURN append_all_fields_std(STMT *stmt, std::string &str) str.append("="); if (insert_field_std(stmt, result, str, j)) { - stmt->dbc->mysql_proxy->free_result(presultAllColumns); + stmt->dbc->connection_proxy->free_result(presultAllColumns); return SQL_ERROR; } found_field= TRUE; @@ -642,12 +642,12 @@ static SQLRETURN append_all_fields_std(STMT *stmt, std::string &str) */ if (!found_field) { - stmt->dbc->mysql_proxy->free_result(presultAllColumns); + stmt->dbc->connection_proxy->free_result(presultAllColumns); return SQL_ERROR; } } - stmt->dbc->mysql_proxy->free_result(presultAllColumns); + stmt->dbc->connection_proxy->free_result(presultAllColumns); return SQL_SUCCESS; } @@ -732,7 +732,7 @@ static SQLRETURN build_set_clause_std(STMT *stmt, SQLULEN irow, { SQLLEN *pcbValue; - field= stmt->dbc->mysql_proxy->fetch_field_direct(result,ncol); + field= stmt->dbc->connection_proxy->fetch_field_direct(result,ncol); arrec= desc_get_rec(stmt->ard, ncol, FALSE); irrec= desc_get_rec(stmt->ird, ncol, FALSE); @@ -840,7 +840,7 @@ SQLRETURN my_pos_delete_std(STMT *stmt, STMT *stmtParam, nReturn= exec_stmt_query_std(stmt, str, false); if ( nReturn == SQL_SUCCESS || nReturn == SQL_SUCCESS_WITH_INFO ) { - stmtParam->affected_rows= stmt->dbc->mysql_proxy->affected_rows(); + stmtParam->affected_rows= stmt->dbc->connection_proxy->affected_rows(); nReturn= update_status(stmtParam,SQL_ROW_DELETED); } return nReturn; @@ -897,7 +897,7 @@ SQLRETURN my_pos_update_std( STMT * pStmtCursor, rc = my_SQLExecute( pStmtTemp ); if ( SQL_SUCCEEDED( rc ) ) { - pStmt->affected_rows = pStmtTemp->dbc->mysql_proxy->affected_rows(); + pStmt->affected_rows = pStmtTemp->dbc->connection_proxy->affected_rows(); rc = update_status( pStmt, SQL_ROW_UPDATED ); } else if (rc == SQL_NEED_DATA) @@ -1054,7 +1054,7 @@ static SQLRETURN setpos_delete_bookmark_std(STMT *stmt, std::string &query) /* execute our DELETE statement */ if (!(nReturn= exec_stmt_query_std(stmt, query, false))) { - affected_rows+= stmt->dbc->mysql_proxy->get_affected_rows(); + affected_rows+= stmt->dbc->connection_proxy->get_affected_rows(); } if (stmt->stmt_options.rowStatusPtr_ex) { @@ -1128,7 +1128,7 @@ static SQLRETURN setpos_delete_std(STMT *stmt, SQLUSMALLINT irow, /* execute our DELETE statement */ if (!(nReturn= exec_stmt_query_std(stmt, query, false))) { - affected_rows+= stmt->dbc->mysql_proxy->get_affected_rows(); + affected_rows+= stmt->dbc->connection_proxy->get_affected_rows(); } } while ( ++rowset_pos <= rowset_end ); @@ -1223,7 +1223,7 @@ static SQLRETURN setpos_update_bookmark_std(STMT *stmt, std::string &query) if (!(nReturn= exec_stmt_query_std(stmt, query, false))) { - affected+= stmt->dbc->mysql_proxy->affected_rows(); + affected+= stmt->dbc->connection_proxy->affected_rows(); } if (stmt->stmt_options.rowStatusPtr_ex) { @@ -1306,7 +1306,7 @@ static SQLRETURN setpos_update_std(STMT *stmt, SQLUSMALLINT irow, if (!(nReturn= exec_stmt_query_std(stmt, query, false))) { - affected+= stmt->dbc->mysql_proxy->affected_rows(); + affected+= stmt->dbc->connection_proxy->affected_rows(); } else if (!SQL_SUCCEEDED(nReturn)) { @@ -1387,7 +1387,7 @@ static SQLRETURN batch_insert_std( STMT *stmt, SQLULEN irow, std::string &query query.append("("); for ( ncol= 0; ncol < result->field_count; ++ncol ) { - MYSQL_FIELD *field= stmt->dbc->mysql_proxy->fetch_field_direct(result, ncol); + MYSQL_FIELD *field= stmt->dbc->connection_proxy->fetch_field_direct(result, ncol); DESCREC *arrec; SQLLEN ind_or_len= 0; @@ -1778,7 +1778,7 @@ SQLRETURN SQL_API my_SQLSetPos(SQLHSTMT hstmt, SQLSETPOSIROW irow, /* build list of column names */ for (nCol= 0; nCol < result->field_count; ++nCol) { - MYSQL_FIELD *field= stmt->dbc->mysql_proxy->fetch_field_direct(result, nCol); + MYSQL_FIELD *field= stmt->dbc->connection_proxy->fetch_field_direct(result, nCol); myodbc_append_quoted_name_std(ins_query, field->org_name); if (nCol < result->field_count - 1) ins_query.append(","); diff --git a/driver/driver.h b/driver/driver.h index 38eda0833..3d3e8aca0 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -45,7 +45,7 @@ #include "connection_handler.h" #include "failover.h" -#include "mysql_proxy.h" +#include "connection_proxy.h" /* Disable _attribute__ on non-gcc compilers. */ #if !defined(__attribute__) && !defined(__GNUC__) @@ -613,7 +613,7 @@ static std::atomic_ulong last_dbc_id{1}; struct DBC { ENV *env; - MYSQL_PROXY *mysql_proxy; + CONNECTION_PROXY *connection_proxy; std::list stmt_list; std::list desc_list; // Explicit descriptors STMT_OPTIONS stmt_options; @@ -660,11 +660,11 @@ struct DBC void init_proxy_chain(DataSource *dsrc); inline bool transactions_supported() { - return mysql_proxy->get_server_capabilities() & CLIENT_TRANSACTIONS; + return connection_proxy->get_server_capabilities() & CLIENT_TRANSACTIONS; } inline bool autocommit_is_on() { - return mysql_proxy->get_server_status() & SERVER_STATUS_AUTOCOMMIT; + return connection_proxy->get_server_status() & SERVER_STATUS_AUTOCOMMIT; } void close(); @@ -977,7 +977,7 @@ struct ODBC_STMT { MYSQL_STMT *m_stmt; - ODBC_STMT(MYSQL_PROXY *mysql_proxy) { m_stmt = mysql_proxy->stmt_init(); } + ODBC_STMT(CONNECTION_PROXY *connection_proxy) { m_stmt = connection_proxy->stmt_init(); } operator MYSQL_STMT*() { return m_stmt; } ~ODBC_STMT() { mysql_stmt_close(m_stmt); } // TODO Replace with proxy call }; diff --git a/driver/dummy_proxy.cc b/driver/dummy_proxy.cc index de7e35059..8d6df8005 100644 --- a/driver/dummy_proxy.cc +++ b/driver/dummy_proxy.cc @@ -36,7 +36,7 @@ namespace { const auto SOCKET_CLOSE_DELAY = std::chrono::milliseconds(100); } -DUMMY_PROXY::DUMMY_PROXY(DBC* dbc, DataSource* ds) : MYSQL_PROXY(dbc, ds) { +DUMMY_PROXY::DUMMY_PROXY(DBC* dbc, DataSource* ds) : CONNECTION_PROXY(dbc, ds) { this->host = get_host_info_from_ds(ds); } @@ -383,12 +383,12 @@ MYSQL* DUMMY_PROXY::move_mysql_connection() { return ret; } -void DUMMY_PROXY::set_connection(MYSQL_PROXY* mysql_proxy) { +void DUMMY_PROXY::set_connection(CONNECTION_PROXY* connection_proxy) { close(); - this->mysql = mysql_proxy->move_mysql_connection(); + this->mysql = connection_proxy->move_mysql_connection(); // delete the ds initialized in CONNECTION_HANDLER::clone_dbc() - mysql_proxy->delete_ds(); - delete mysql_proxy; + connection_proxy->delete_ds(); + delete connection_proxy; } void DUMMY_PROXY::close_socket() { diff --git a/driver/dummy_proxy.h b/driver/dummy_proxy.h index 23de9e839..472eaffa0 100644 --- a/driver/dummy_proxy.h +++ b/driver/dummy_proxy.h @@ -32,9 +32,9 @@ #include "driver.h" #include "host_info.h" -#include "mysql_proxy.h" +#include "connection_proxy.h" -class DUMMY_PROXY : public MYSQL_PROXY { +class DUMMY_PROXY : public CONNECTION_PROXY { public: DUMMY_PROXY(DBC* dbc, DataSource* ds); ~DUMMY_PROXY() override; @@ -156,7 +156,7 @@ class DUMMY_PROXY : public MYSQL_PROXY { MYSQL* move_mysql_connection() override; - void set_connection(MYSQL_PROXY* mysql_proxy) override; + void set_connection(CONNECTION_PROXY* connection_proxy) override; void close_socket() override; diff --git a/driver/efm_proxy.cc b/driver/efm_proxy.cc index 083be6f70..f52c2e399 100644 --- a/driver/efm_proxy.cc +++ b/driver/efm_proxy.cc @@ -36,12 +36,12 @@ namespace { EFM_PROXY::EFM_PROXY(DBC* dbc, DataSource* ds) : EFM_PROXY( dbc, ds, nullptr, std::make_shared(ds && ds->save_queries)) {} -EFM_PROXY::EFM_PROXY(DBC* dbc, DataSource* ds, MYSQL_PROXY* next_proxy) : EFM_PROXY( +EFM_PROXY::EFM_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy) : EFM_PROXY( dbc, ds, next_proxy, std::make_shared(ds && ds->save_queries)) {} -EFM_PROXY::EFM_PROXY(DBC* dbc, DataSource* ds, MYSQL_PROXY* next_proxy, +EFM_PROXY::EFM_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy, std::shared_ptr monitor_service) - : MYSQL_PROXY(dbc, ds), + : CONNECTION_PROXY(dbc, ds), monitor_service{std::move(monitor_service)} { this->next_proxy = next_proxy; @@ -103,13 +103,13 @@ void EFM_PROXY::generate_node_keys() { } } -void EFM_PROXY::set_next_proxy(MYSQL_PROXY* next_proxy) { - MYSQL_PROXY::set_next_proxy(next_proxy); +void EFM_PROXY::set_next_proxy(CONNECTION_PROXY* next_proxy) { + CONNECTION_PROXY::set_next_proxy(next_proxy); generate_node_keys(); } -void EFM_PROXY::set_connection(MYSQL_PROXY* mysql_proxy) { - next_proxy->set_connection(mysql_proxy); +void EFM_PROXY::set_connection(CONNECTION_PROXY* connection_proxy) { + next_proxy->set_connection(connection_proxy); if (monitor_service != nullptr && !node_keys.empty()) { monitor_service->stop_monitoring_for_all_connections(node_keys); diff --git a/driver/efm_proxy.h b/driver/efm_proxy.h index 6da6f145a..265aec6a4 100644 --- a/driver/efm_proxy.h +++ b/driver/efm_proxy.h @@ -32,13 +32,13 @@ #include "driver.h" #include "monitor_service.h" -#include "mysql_proxy.h" +#include "connection_proxy.h" -class EFM_PROXY : public MYSQL_PROXY { +class EFM_PROXY : public CONNECTION_PROXY { public: EFM_PROXY(DBC* dbc, DataSource* ds); - EFM_PROXY(DBC* dbc, DataSource* ds, MYSQL_PROXY* next_proxy); - EFM_PROXY(DBC* dbc, DataSource* ds, MYSQL_PROXY* next_proxy, std::shared_ptr monitor_service); + EFM_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy); + EFM_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy, std::shared_ptr monitor_service); int set_character_set(const char* csname) override; bool change_user(const char* user, const char* passwd, @@ -81,8 +81,8 @@ class EFM_PROXY : public MYSQL_PROXY { const char* user, const char* passwd, const char* db, unsigned long client_flag) override; - void set_connection(MYSQL_PROXY* mysql_proxy) override; - void set_next_proxy(MYSQL_PROXY* next_proxy) override; + void set_connection(CONNECTION_PROXY* connection_proxy) override; + void set_next_proxy(CONNECTION_PROXY* next_proxy) override; private: std::shared_ptr monitor_service = nullptr; diff --git a/driver/error.cc b/driver/error.cc index d75cd9397..de91938cf 100644 --- a/driver/error.cc +++ b/driver/error.cc @@ -292,11 +292,11 @@ SQLRETURN set_conn_error(DBC *dbc, myodbc_errid errid, const char *errtext, @type : myodbc3 internal @purpose : sets a myodbc_malloc() failure on a MYSQL* connection */ -void set_mem_error(MYSQL_PROXY* mysql_proxy) +void set_mem_error(CONNECTION_PROXY* connection_proxy) { - mysql_proxy->set_last_error_code(CR_OUT_OF_MEMORY); - myodbc_stpmov(mysql_proxy->get_last_error(), "Memory allocation failed"); - myodbc_stpmov(mysql_proxy->get_sqlstate(), "HY001"); + connection_proxy->set_last_error_code(CR_OUT_OF_MEMORY); + myodbc_stpmov(connection_proxy->get_last_error(), "Memory allocation failed"); + myodbc_stpmov(connection_proxy->get_sqlstate(), "HY001"); } @@ -307,7 +307,7 @@ void set_mem_error(MYSQL_PROXY* mysql_proxy) */ SQLRETURN handle_connection_error(STMT *stmt) { - unsigned int err= stmt->dbc->mysql_proxy->error_code(); + unsigned int err= stmt->dbc->connection_proxy->error_code(); switch (err) { case 0: /* no error */ return SQL_SUCCESS; @@ -320,13 +320,13 @@ SQLRETURN handle_connection_error(STMT *stmt) if (stmt->dbc->fh->trigger_failover_if_needed("08S01", error_code, error_msg)) return stmt->set_error(error_code, error_msg, 0); else - return stmt->set_error("08S01", stmt->dbc->mysql_proxy->error(), err); + return stmt->set_error("08S01", stmt->dbc->connection_proxy->error(), err); case CR_OUT_OF_MEMORY: - return stmt->set_error("HY001", stmt->dbc->mysql_proxy->error(), err); + return stmt->set_error("HY001", stmt->dbc->connection_proxy->error(), err); case CR_COMMANDS_OUT_OF_SYNC: case CR_UNKNOWN_ERROR: default: - return stmt->set_error("HY000", stmt->dbc->mysql_proxy->error(), err); + return stmt->set_error("HY000", stmt->dbc->connection_proxy->error(), err); } } @@ -501,7 +501,7 @@ MySQLGetDiagField(SQLSMALLINT handle_type, SQLHANDLE handle, SQLSMALLINT record, if (!stmt->result) *(SQLLEN *)num_value= 0; else - *(SQLLEN *)num_value= (SQLLEN) dbc->mysql_proxy->num_rows(stmt->result); + *(SQLLEN *)num_value= (SQLLEN) dbc->connection_proxy->num_rows(stmt->result); return SQL_SUCCESS; case SQL_DIAG_DYNAMIC_FUNCTION: diff --git a/driver/error.h b/driver/error.h index ad244f056..da61864ea 100644 --- a/driver/error.h +++ b/driver/error.h @@ -42,7 +42,7 @@ #ifndef __ERROR_H__ #define __ERROR_H__ -#include "mysql_proxy.h" +#include "connection_proxy.h" /* Including driver version definitions */ #include "../MYODBC_CONF.h" @@ -197,9 +197,9 @@ struct MYERROR sqlstate.clear(); } - MYERROR(const char* state, MYSQL_PROXY* mysql_proxy) : - MYERROR(state, mysql_proxy->error(), - mysql_proxy->error_code(), MYODBC_ERROR_PREFIX) + MYERROR(const char* state, CONNECTION_PROXY* connection_proxy) : + MYERROR(state, connection_proxy->error(), + connection_proxy->error_code(), MYODBC_ERROR_PREFIX) {} MYERROR(const char* state, std::string errmsg) : diff --git a/driver/execute.cc b/driver/execute.cc index b2927368a..a35352869 100644 --- a/driver/execute.cc +++ b/driver/execute.cc @@ -87,11 +87,11 @@ SQLRETURN do_query(STMT *stmt, char *query, SQLULEN query_length) if ( !is_server_alive( stmt->dbc ) ) { stmt->set_error("08S01" /* "HYT00" */, - stmt->dbc->mysql_proxy->error(), - stmt->dbc->mysql_proxy->error_code()); + stmt->dbc->connection_proxy->error(), + stmt->dbc->connection_proxy->error_code()); translate_error((char*)stmt->error.sqlstate.c_str(), MYERR_08S01 /* S1000 */, - stmt->dbc->mysql_proxy->error_code()); + stmt->dbc->connection_proxy->error_code()); goto exit; } @@ -135,21 +135,21 @@ SQLRETURN do_query(STMT *stmt, char *query, SQLULEN query_length) { native_error = 0; if (stmt->param_bind.size() && stmt->param_count) - native_error = stmt->dbc->mysql_proxy->stmt_bind_param(stmt->ssps, &stmt->param_bind[0]); + native_error = stmt->dbc->connection_proxy->stmt_bind_param(stmt->ssps, &stmt->param_bind[0]); if (native_error == 0) { - native_error = stmt->dbc->mysql_proxy->stmt_execute(stmt->ssps); + native_error = stmt->dbc->connection_proxy->stmt_execute(stmt->ssps); } else { stmt->set_error("HY000", - stmt->dbc->mysql_proxy->stmt_error(stmt->ssps), - stmt->dbc->mysql_proxy->stmt_errno(stmt->ssps)); + stmt->dbc->connection_proxy->stmt_error(stmt->ssps), + stmt->dbc->connection_proxy->stmt_errno(stmt->ssps)); /* For some errors - translating to more appropriate status */ translate_error((char*)stmt->error.sqlstate.c_str(), MYERR_S1000, - stmt->dbc->mysql_proxy->stmt_errno(stmt->ssps)); + stmt->dbc->connection_proxy->stmt_errno(stmt->ssps)); goto exit; } MYLOG_STMT_TRACE(stmt, "ssps has been executed"); @@ -199,10 +199,10 @@ SQLRETURN do_query(STMT *stmt, char *query, SQLULEN query_length) if (native_error) { - const auto error_code = stmt->dbc->mysql_proxy->error_code(); + const auto error_code = stmt->dbc->connection_proxy->error_code(); if (error_code) { - MYLOG_STMT_TRACE(stmt, stmt->dbc->mysql_proxy->error()); + MYLOG_STMT_TRACE(stmt, stmt->dbc->connection_proxy->error()); stmt->set_error("HY000"); // For some errors - translating to more appropriate status @@ -580,7 +580,7 @@ SQLRETURN convert_c_type2str(STMT *stmt, SQLSMALLINT ctype, DESCREC *iprec, if (has_utf8_maxlen4 && - !is_minimum_version(stmt->dbc->mysql_proxy->get_server_version(), "5.5.3")) + !is_minimum_version(stmt->dbc->connection_proxy->get_server_version(), "5.5.3")) { return stmt->set_error("HY000", "Server does not support 4-byte encoded " @@ -1300,7 +1300,7 @@ SQLRETURN insert_param(STMT *stmt, MYSQL_BIND *bind, DESC* apd, goto memerror; } - size_t added = dbc->mysql_proxy->real_escape_string(stmt->endbuf(), data, length); + size_t added = dbc->connection_proxy->real_escape_string(stmt->endbuf(), data, length); stmt->buf_add_pos(added); stmt->add_to_buffer("'", 1); } @@ -1807,7 +1807,7 @@ static SQLRETURN find_next_out_stream(STMT *stmt, SQLPOINTER *token) else { /* Magical out params fetch */ - stmt->dbc->mysql_proxy->stmt_fetch(stmt->ssps); + stmt->dbc->connection_proxy->stmt_fetch(stmt->ssps); stmt->out_params_state = OPS_PREFETCHED; return SQL_SUCCESS; @@ -1991,7 +1991,7 @@ SQLRETURN SQL_API SQLCancel(SQLHSTMT hstmt) { char buff[40]; /* buff is always big enough because max length of %lu is 15 */ - snprintf(buff, sizeof(buff), "KILL /*!50000 QUERY */ %lu", dbc->mysql_proxy->thread_id()); + snprintf(buff, sizeof(buff), "KILL /*!50000 QUERY */ %lu", dbc->connection_proxy->thread_id()); if (mysql_real_query(second, buff, strlen(buff))) { mysql_close(second); diff --git a/driver/failover.h b/driver/failover.h index 8d3d50fa2..6e4d895c1 100644 --- a/driver/failover.h +++ b/driver/failover.h @@ -33,20 +33,20 @@ #include "connection_handler.h" #include "topology_service.h" #include "mylog.h" -#include "mysql_proxy.h" +#include "connection_proxy.h" #include struct READER_FAILOVER_RESULT { bool connected = false; std::shared_ptr new_host; - MYSQL_PROXY* new_connection; + CONNECTION_PROXY* new_connection; READER_FAILOVER_RESULT() : connected{false}, new_host{nullptr}, new_connection{nullptr} {} READER_FAILOVER_RESULT(bool connected, std::shared_ptr new_host, - MYSQL_PROXY* new_connection) + CONNECTION_PROXY* new_connection) : connected{connected}, new_host{new_host}, new_connection{new_connection} {} @@ -110,7 +110,7 @@ struct WRITER_FAILOVER_RESULT { bool is_new_host = false; // True if process connected to a new host. False if // process re-connected to the same host std::shared_ptr new_topology; - MYSQL_PROXY* new_connection; + CONNECTION_PROXY* new_connection; WRITER_FAILOVER_RESULT() : connected{false}, @@ -120,7 +120,7 @@ struct WRITER_FAILOVER_RESULT { WRITER_FAILOVER_RESULT(bool connected, bool is_new_host, std::shared_ptr new_topology, - MYSQL_PROXY* new_connection) + CONNECTION_PROXY* new_connection) : connected{connected}, is_new_host{is_new_host}, new_topology{new_topology}, @@ -225,7 +225,7 @@ class FAILOVER { void release_new_connection(); std::shared_ptr connection_handler; std::shared_ptr topology_service; - MYSQL_PROXY* new_connection; + CONNECTION_PROXY* new_connection; std::shared_ptr logger = nullptr; unsigned long dbc_id = 0; }; @@ -285,7 +285,7 @@ class WAIT_NEW_WRITER_HANDLER : public FAILOVER { int read_topology_interval_ms = 5000; std::shared_ptr reader_handler; std::shared_ptr current_topology; - MYSQL_PROXY* reader_connection = nullptr; // To retrieve latest topology + CONNECTION_PROXY* reader_connection = nullptr; // To retrieve latest topology std::shared_ptr current_reader_host; void refresh_topology_and_connect_to_new_writer( diff --git a/driver/failover_handler.cc b/driver/failover_handler.cc index 467f64ff5..74924bdc9 100644 --- a/driver/failover_handler.cc +++ b/driver/failover_handler.cc @@ -368,7 +368,7 @@ SQLRETURN FAILOVER_HANDLER::create_connection_and_initialize_topology() { } metrics_container->register_invalid_initial_connection(false); - current_topology = topology_service->get_topology(dbc->mysql_proxy, false); + current_topology = topology_service->get_topology(dbc->connection_proxy, false); if (current_topology) { m_is_multi_writer_cluster = current_topology->is_multi_writer_cluster; m_is_cluster_topology_available = current_topology->total_hosts() > 0; @@ -393,7 +393,7 @@ SQLRETURN FAILOVER_HANDLER::create_connection_and_initialize_topology() { } SQLRETURN FAILOVER_HANDLER::reconnect(bool failover_enabled) { - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) { + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) { dbc->close(); } return connection_handler->do_connect(dbc, ds, failover_enabled); diff --git a/driver/handle.cc b/driver/handle.cc index 913cf7e9c..9aa1e80bd 100644 --- a/driver/handle.cc +++ b/driver/handle.cc @@ -77,7 +77,7 @@ bool ENV::has_connections() DBC::DBC(ENV *p_env) : id{last_dbc_id++}, env(p_env), - mysql_proxy(nullptr), + connection_proxy(nullptr), txn_isolation(DEFAULT_TXN_ISOLATION), last_query_time((time_t)time((time_t *)0)) { @@ -111,16 +111,16 @@ void DBC::free_explicit_descriptors() void DBC::close() { - mysql_proxy->close(); + connection_proxy->close(); } // construct a proxy chain, example: iam->efm->mysql void DBC::init_proxy_chain(DataSource* dsrc) { - MYSQL_PROXY *head = new DUMMY_PROXY(this, dsrc); + CONNECTION_PROXY *head = new DUMMY_PROXY(this, dsrc); if (dsrc->enable_failure_detection) { - MYSQL_PROXY* efm_proxy = new EFM_PROXY(this, dsrc); + CONNECTION_PROXY* efm_proxy = new EFM_PROXY(this, dsrc); efm_proxy->set_next_proxy(head); head = efm_proxy; } @@ -128,18 +128,18 @@ void DBC::init_proxy_chain(DataSource* dsrc) ds_get_utf8attr(dsrc->auth_mode, &dsrc->auth_mode8); if (!myodbc_strcasecmp(AUTH_MODE_IAM, reinterpret_cast(dsrc->auth_mode8))) { - // MYSQL_PROXY* iam_proxy = new IAM_PROXY(his, dsrc); + // CONNECTION_PROXY* iam_proxy = new IAM_PROXY(his, dsrc); // iam_proxy->set_next_proxy(head); // head = iam_proxy; } if (!myodbc_strcasecmp(AUTH_MODE_SECRETS_MANAGER, reinterpret_cast(dsrc->auth_mode8))) { - // MYSQL_PROXY* secrets_manager_proxy = new SECRETS_MANAGER_PROXY(his, dsrc); + // CONNECTION_PROXY* secrets_manager_proxy = new SECRETS_MANAGER_PROXY(his, dsrc); // secrets_manager_proxy->set_next_proxy(head); // head = secrets_manager_proxy; } - this->mysql_proxy = head; + this->connection_proxy = head; } DBC::~DBC() @@ -150,8 +150,8 @@ DBC::~DBC() if (ds) ds_delete(ds); - if (mysql_proxy) - delete mysql_proxy; + if (connection_proxy) + delete connection_proxy; if (fh) delete fh; @@ -171,7 +171,7 @@ SQLRETURN DBC::set_error(char * state, const char * message, uint errcode) SQLRETURN DBC::set_error(char * state) { - return set_error(state, mysql_proxy->error(), mysql_proxy->error_code()); + return set_error(state, connection_proxy->error(), connection_proxy->error_code()); } @@ -280,12 +280,12 @@ SQLRETURN SQL_API my_SQLAllocConnect(SQLHENV henv, SQLHDBC *phdbc) ++thread_count; - if (MYSQL_PROXY::get_client_version() < MIN_MYSQL_VERSION) + if (CONNECTION_PROXY::get_client_version() < MIN_MYSQL_VERSION) { char buff[255]; snprintf(buff, sizeof(buff), "Wrong libmysqlclient library version: %ld. MyODBC needs at least version: %ld", - MYSQL_PROXY::get_client_version(), MIN_MYSQL_VERSION); + CONNECTION_PROXY::get_client_version(), MIN_MYSQL_VERSION); return(set_env_error((ENV*)henv, MYERR_S1000, buff, 0)); } @@ -348,7 +348,7 @@ int wakeup_connection(DBC *dbc) { ds_get_utf8attr(ds->pwd1, &ds->pwd18); int fator = 2; - dbc->mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + dbc->connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, ds->pwd18); } @@ -357,7 +357,7 @@ int wakeup_connection(DBC *dbc) { ds_get_utf8attr(ds->pwd2, &ds->pwd28); int fator = 2; - dbc->mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + dbc->connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, ds->pwd28); } @@ -366,13 +366,13 @@ int wakeup_connection(DBC *dbc) { ds_get_utf8attr(ds->pwd3, &ds->pwd38); int fator = 3; - dbc->mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + dbc->connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, ds->pwd38); } #endif - if (dbc->mysql_proxy->change_user(ds_get_utf8attr(ds->uid, &ds->uid8), + if (dbc->connection_proxy->change_user(ds_get_utf8attr(ds->uid, &ds->uid8), ds_get_utf8attr(ds->pwd, &ds->pwd8), ds_get_utf8attr(ds->database, &ds->database8))) { diff --git a/driver/info.cc b/driver/info.cc index f09c3ba42..3845a8060 100644 --- a/driver/info.cc +++ b/driver/info.cc @@ -135,7 +135,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, 0); case SQL_COLLATION_SEQ: - MYINFO_SET_STR(dbc->mysql_proxy->get_character_set()->name); + MYINFO_SET_STR(dbc->connection_proxy->get_character_set()->name); case SQL_COLUMN_ALIAS: MYINFO_SET_STR("Y"); @@ -201,7 +201,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, case SQL_CREATE_VIEW: /** @todo SQL_CV_LOCAL ? */ - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_ULONG(SQL_CV_CREATE_VIEW | SQL_CV_CHECK_OPTION | SQL_CV_CASCADED); else @@ -228,7 +228,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_STR("N"); case SQL_DATABASE_NAME: - if (dbc->mysql_proxy->is_connected() && reget_current_catalog(dbc)) + if (dbc->connection_proxy->is_connected() && reget_current_catalog(dbc)) return dbc->set_error("HY000", "SQLGetInfo() failed to return current catalog.", 0); @@ -243,7 +243,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, case SQL_DBMS_VER: /** @todo technically this is not right: should be ##.##.#### */ - MYINFO_SET_STR(dbc->mysql_proxy->get_server_version()); + MYINFO_SET_STR(dbc->connection_proxy->get_server_version()); case SQL_DDL_INDEX: MYINFO_SET_ULONG(SQL_DI_CREATE_INDEX | SQL_DI_DROP_INDEX); @@ -286,7 +286,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_ULONG(SQL_DT_DROP_TABLE | SQL_DT_CASCADE | SQL_DT_RESTRICT); case SQL_DROP_VIEW: - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_ULONG(SQL_DV_DROP_VIEW | SQL_DV_CASCADE | SQL_DV_RESTRICT); else MYINFO_SET_ULONG(0); @@ -361,7 +361,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, We have INFORMATION_SCHEMA.SCHEMATA, but we don't report it because the driver exposes databases (schema) as catalogs. */ - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.1")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.1")) MYINFO_SET_ULONG(SQL_ISV_CHARACTER_SETS | SQL_ISV_COLLATIONS | SQL_ISV_COLUMN_PRIVILEGES | SQL_ISV_COLUMNS | SQL_ISV_KEY_COLUMN_USAGE | @@ -369,7 +369,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, /* SQL_ISV_SCHEMATA | */ SQL_ISV_TABLE_CONSTRAINTS | SQL_ISV_TABLE_PRIVILEGES | SQL_ISV_TABLES | SQL_ISV_VIEWS); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_ULONG(SQL_ISV_CHARACTER_SETS | SQL_ISV_COLLATIONS | SQL_ISV_COLUMN_PRIVILEGES | SQL_ISV_COLUMNS | SQL_ISV_KEY_COLUMN_USAGE | /* SQL_ISV_SCHEMATA | */ @@ -395,7 +395,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, the MySQL Reference Manual (which is, in turn, generated from the source) with the pre-reserved ODBC keywords removed. */ - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "8.0.22")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "8.0.22")) MYINFO_SET_STR("ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB," "CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR," "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED," @@ -420,7 +420,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, "TINYBLOB,TINYINT,TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED," "USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY," "VARCHARACTER,WHILE,X509,XOR,YEAR_MONTH,ZEROFILL"); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.7")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.7")) MYINFO_SET_STR("ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB," "CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR," "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED," @@ -445,7 +445,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, "TINYBLOB,TINYINT,TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED," "USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY," "VARCHARACTER,WHILE,X509,XOR,YEAR_MONTH,ZEROFILL"); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.6")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.6")) MYINFO_SET_STR("ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB," "CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR," "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED," @@ -470,7 +470,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, "TINYBLOB,TINYINT,TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED," "USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY," "VARCHARACTER,WHILE,X509,XOR,YEAR_MONTH,ZEROFILL"); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.5")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.5")) MYINFO_SET_STR("ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB," "CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR," "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED," @@ -493,7 +493,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, "TINYBLOB,TINYINT,TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED," "USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY," "VARCHARACTER,WHILE,X509,XOR,YEAR_MONTH,ZEROFILL"); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.1")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.1")) MYINFO_SET_STR("ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB," "CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR," "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED," @@ -515,7 +515,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, "TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED,USE,UTC_DATE," "UTC_TIME,UTC_TIMESTAMP,VARBINARY,VARCHARACTER,WHILE,X509," "XOR,YEAR_MONTH,ZEROFILL"); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_STR("ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB,CALL,CHANGE," "CONDITION,DATABASE,DATABASES,DAY_HOUR,DAY_MICROSECOND," "DAY_MINUTE,DAY_SECOND,DELAYED,DETERMINISTIC,DISTINCTROW," @@ -604,7 +604,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_USHORT(NAME_LEN); case SQL_MAX_INDEX_SIZE: - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_USHORT(3072); else MYINFO_SET_USHORT(1024); @@ -632,7 +632,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_USHORT(NAME_LEN); case SQL_MAX_TABLES_IN_SELECT: - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_USHORT(63); else MYINFO_SET_USHORT(31); @@ -690,13 +690,13 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_ULONG(SQL_PAS_NO_BATCH); case SQL_PROCEDURE_TERM: - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_STR("stored procedure"); else MYINFO_SET_STR(""); case SQL_PROCEDURES: - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_STR("Y"); else MYINFO_SET_STR("N"); @@ -735,7 +735,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_STR("\\"); case SQL_SERVER_NAME: - MYINFO_SET_STR(dbc->mysql_proxy->get_host_info()); + MYINFO_SET_STR(dbc->connection_proxy->get_host_info()); case SQL_SPECIAL_CHARACTERS: /* We can handle anything but / and \xff. */ diff --git a/driver/monitor.cc b/driver/monitor.cc index 7aa0341e8..3ee553087 100644 --- a/driver/monitor.cc +++ b/driver/monitor.cc @@ -33,7 +33,7 @@ #include "monitor_service.h" #include "mylog.h" -#include "mysql_proxy.h" +#include "connection_proxy.h" MONITOR::MONITOR( std::shared_ptr host_info, @@ -57,7 +57,7 @@ MONITOR::MONITOR( std::chrono::seconds failure_detection_timeout, std::chrono::milliseconds monitor_disposal_time, DataSource* ds, - MYSQL_PROXY* proxy, + CONNECTION_PROXY* proxy, bool enable_logging) { this->host = std::move(host_info); @@ -66,7 +66,7 @@ MONITOR::MONITOR( this->disposal_time = monitor_disposal_time; this->ds = ds_new(); ds_copy(this->ds, ds); - this->mysql_proxy = proxy; + this->connection_proxy = proxy; this->connection_check_interval = (std::chrono::milliseconds::max)(); if (enable_logging) this->logger = init_log_file(); @@ -78,9 +78,9 @@ MONITOR::~MONITOR() { this->ds = nullptr; } - if (this->mysql_proxy) { - delete this->mysql_proxy; - this->mysql_proxy = nullptr; + if (this->connection_proxy) { + delete this->connection_proxy; + this->connection_proxy = nullptr; } } @@ -191,7 +191,7 @@ std::chrono::milliseconds MONITOR::get_connection_check_interval() { } CONNECTION_STATUS MONITOR::check_connection_status() { - if (this->mysql_proxy == nullptr || !this->mysql_proxy->is_connected()) { + if (this->connection_proxy == nullptr || !this->connection_proxy->is_connected()) { const auto start = this->get_current_time(); bool connected = this->connect(); return CONNECTION_STATUS{ @@ -201,7 +201,7 @@ CONNECTION_STATUS MONITOR::check_connection_status() { } auto start = this->get_current_time(); - bool is_connection_active = this->mysql_proxy->ping() == 0; + bool is_connection_active = this->connection_proxy->ping() == 0; auto duration = this->get_current_time() - start; return CONNECTION_STATUS{ @@ -211,9 +211,9 @@ CONNECTION_STATUS MONITOR::check_connection_status() { } bool MONITOR::connect() { - if (this->mysql_proxy) { - this->mysql_proxy->close(); - delete this->mysql_proxy; + if (this->connection_proxy) { + this->connection_proxy->close(); + delete this->connection_proxy; } // Timeout shouldn't be 0 by now, but double check just in case unsigned int timeout_sec = this->failure_detection_timeout.count() == 0 ? failure_detection_timeout_default : this->failure_detection_timeout.count(); @@ -230,12 +230,12 @@ bool MONITOR::connect() { this->ds->enable_cluster_failover = false; this->ds->enable_failure_detection= false; - this->mysql_proxy = this->connection_handler->connect(this->host, this->ds); - if (!this->mysql_proxy) { + this->connection_proxy = this->connection_handler->connect(this->host, this->ds); + if (!this->connection_proxy) { return false; } - return this->mysql_proxy->is_connected(); + return this->connection_proxy->is_connected(); } std::chrono::milliseconds MONITOR::find_shortest_interval() { diff --git a/driver/monitor.h b/driver/monitor.h index e946678fd..7f8095559 100644 --- a/driver/monitor.h +++ b/driver/monitor.h @@ -44,7 +44,7 @@ struct CONNECTION_STATUS { struct DataSource; class MONITOR_SERVICE; -class MYSQL_PROXY; +class CONNECTION_PROXY; namespace { const std::chrono::milliseconds thread_sleep_when_inactive = std::chrono::milliseconds(100); @@ -66,7 +66,7 @@ class MONITOR : public std::enable_shared_from_this { std::chrono::seconds failure_detection_timeout, std::chrono::milliseconds monitor_disposal_time, DataSource* ds, - MYSQL_PROXY* proxy, + CONNECTION_PROXY* proxy, bool enable_logging = false); virtual ~MONITOR(); @@ -86,7 +86,7 @@ class MONITOR : public std::enable_shared_from_this { std::chrono::milliseconds disposal_time; std::list> contexts; std::chrono::steady_clock::time_point last_context_timestamp; - MYSQL_PROXY* mysql_proxy = nullptr; + CONNECTION_PROXY* connection_proxy = nullptr; DataSource* ds = nullptr; std::shared_ptr logger; std::mutex mutex_; diff --git a/driver/monitor_connection_context.cc b/driver/monitor_connection_context.cc index dc458ab94..1fe5e8aeb 100644 --- a/driver/monitor_connection_context.cc +++ b/driver/monitor_connection_context.cc @@ -188,7 +188,7 @@ void MONITOR_CONNECTION_CONTEXT::abort_connection() { if ((!get_connection_to_abort()) || (!is_active_context())) { return; } - connection_to_abort->mysql_proxy->close_socket(); + connection_to_abort->connection_proxy->close_socket(); } std::string MONITOR_CONNECTION_CONTEXT::build_node_keys_str() { diff --git a/driver/my_prepared_stmt.cc b/driver/my_prepared_stmt.cc index e140a1570..70acd5bae 100644 --- a/driver/my_prepared_stmt.cc +++ b/driver/my_prepared_stmt.cc @@ -67,7 +67,7 @@ static char * my_f_to_a(char * buf, size_t buf_size, double a) /* {{{ ssps_init() -I- */ void ssps_init(STMT *stmt) { - stmt->ssps= stmt->dbc->mysql_proxy->stmt_init(); + stmt->ssps= stmt->dbc->connection_proxy->stmt_init(); stmt->result_bind = 0; } @@ -156,7 +156,7 @@ BOOL ssps_get_out_params(STMT *stmt) /* Making bit field look "normally" */ if (stmt->result_bind[counter].buffer_type == MYSQL_TYPE_BIT) { - MYSQL_FIELD *field= stmt->dbc->mysql_proxy->fetch_field_direct(stmt->result, counter); + MYSQL_FIELD *field= stmt->dbc->connection_proxy->fetch_field_direct(stmt->result, counter); unsigned long long numeric; assert(field->type == MYSQL_TYPE_BIT); @@ -249,7 +249,7 @@ BOOL ssps_get_out_params(STMT *stmt) /* This MAGICAL fetch is required. If there are streams - it has to be after streams are all done, perhaps when stmt->out_params_state is changed from OPS_STREAMS_PENDING */ - stmt->dbc->mysql_proxy->stmt_fetch(stmt->ssps); + stmt->dbc->connection_proxy->stmt_fetch(stmt->ssps); } return TRUE; @@ -266,7 +266,7 @@ int ssps_get_result(STMT *stmt) { if (!if_forward_cache(stmt)) { - return stmt->dbc->mysql_proxy->stmt_store_result(stmt->ssps); + return stmt->dbc->connection_proxy->stmt_store_result(stmt->ssps); } else { @@ -347,7 +347,7 @@ void ssps_close(STMT *stmt) It can fail because the connection to the server is lost, which is still ok because the memory is freed anyway. */ - stmt->dbc->mysql_proxy->stmt_close(stmt->ssps); + stmt->dbc->connection_proxy->stmt_close(stmt->ssps); stmt->ssps= NULL; } stmt->buf_set_pos(0); @@ -365,9 +365,9 @@ SQLRETURN ssps_fetch_chunk(STMT *stmt, char *dest, unsigned long dest_bytes, uns bind.is_null= &is_null; bind.error= &error; - if (stmt->dbc->mysql_proxy->stmt_fetch_column(stmt->ssps, &bind, stmt->getdata.column, stmt->getdata.src_offset)) + if (stmt->dbc->connection_proxy->stmt_fetch_column(stmt->ssps, &bind, stmt->getdata.column, stmt->getdata.src_offset)) { - switch (stmt->dbc->mysql_proxy->stmt_errno(stmt->ssps)) + switch (stmt->dbc->connection_proxy->stmt_errno(stmt->ssps)) { case CR_INVALID_PARAMETER_NO: /* Shouldn't really happen here*/ @@ -600,14 +600,14 @@ static MYSQL_ROW fetch_varlength_columns(STMT *stmt, MYSQL_ROW values) } if (reallocated_buffers) - stmt->dbc->mysql_proxy->stmt_fetch_column(stmt->ssps, &stmt->result_bind[i], i, 0); + stmt->dbc->connection_proxy->stmt_fetch_column(stmt->ssps, &stmt->result_bind[i], i, 0); } } // Result buffers must be set again after reallocating if (reallocated_buffers) - stmt->dbc->mysql_proxy->stmt_bind_result(stmt->ssps, stmt->result_bind); + stmt->dbc->connection_proxy->stmt_bind_result(stmt->ssps, stmt->result_bind); fill_ird_data_lengths(stmt->ird, stmt->result_bind[0].length, stmt->result->field_count); @@ -675,7 +675,7 @@ void STMT::free_reset_out_params() if (out_params_state == OPS_STREAMS_PENDING) { /* Magical out params fetch */ - dbc->mysql_proxy->stmt_fetch(ssps); + dbc->connection_proxy->stmt_fetch(ssps); } out_params_state = OPS_UNKNOWN; apd->free_paramdata(); @@ -688,7 +688,7 @@ void STMT::free_reset_params() { if (ssps) { - dbc->mysql_proxy->stmt_reset(ssps); + dbc->connection_proxy->stmt_reset(ssps); } /* remove all params and reset count to 0 (per spec) */ /* http://msdn2.microsoft.com/en-us/library/ms709284.aspx */ @@ -736,7 +736,7 @@ STMT::~STMT() if (ssps != NULL) { - dbc->mysql_proxy->stmt_close(ssps); + dbc->connection_proxy->stmt_close(ssps); ssps = NULL; } @@ -767,7 +767,7 @@ SQLRETURN STMT::set_error(myodbc_errid errid, const char *errtext, SQLRETURN STMT::set_error(myodbc_errid errid) { - return set_error(errid, dbc->mysql_proxy->error(), dbc->mysql_proxy->error_code()); + return set_error(errid, dbc->connection_proxy->error(), dbc->connection_proxy->error_code()); } SQLRETURN STMT::set_error(const char *sqlstate, const char *msg, @@ -779,7 +779,7 @@ SQLRETURN STMT::set_error(const char *sqlstate, const char *msg, SQLRETURN STMT::set_error(const char *state) { - return set_error(state, dbc->mysql_proxy->error(), dbc->mysql_proxy->error_code()); + return set_error(state, dbc->connection_proxy->error(), dbc->connection_proxy->error_code()); } @@ -864,7 +864,7 @@ long STMT::compute_cur_row(unsigned fFetchType, SQLLEN irow) case SQL_NO_DATA: throw MYERROR(SQL_NO_DATA_FOUND); case SQL_ERROR: - set_error(MYERR_S1000, dbc->mysql_proxy->error(), 0); + set_error(MYERR_S1000, dbc->connection_proxy->error(), 0); throw error; } } @@ -919,7 +919,7 @@ int STMT::ssps_bind_result() for (i= 0; i < num_fields; ++i) { - MYSQL_FIELD *field= dbc->mysql_proxy->fetch_field_direct(result, i); + MYSQL_FIELD *field= dbc->connection_proxy->fetch_field_direct(result, i); st_buffer_size_type p= allocate_buffer_for_field(field, IS_PS_OUT_PARAMS(this)); @@ -946,10 +946,10 @@ int STMT::ssps_bind_result() } } - int rc = dbc->mysql_proxy->stmt_bind_result(ssps, result_bind); + int rc = dbc->connection_proxy->stmt_bind_result(ssps, result_bind); if (rc) { - set_error("HY000", dbc->mysql_proxy->stmt_error(ssps), 0); + set_error("HY000", dbc->connection_proxy->stmt_error(ssps), 0); } return rc; } @@ -1026,7 +1026,7 @@ SQLRETURN STMT::bind_query_attrs(bool use_ssps) MYSQL_BIND *bind = query_attr_bind.data(); const char** names = (const char**)query_attr_names.data(); - if (dbc->mysql_proxy->bind_param(rcount - param_count, + if (dbc->connection_proxy->bind_param(rcount - param_count, query_attr_bind.data(), (const char**)query_attr_names.data())) { @@ -1401,9 +1401,9 @@ T ssps_get_int64(STMT *stmt, ulong column_number, char *value, ulong length) SQLRETURN ssps_send_long_data(STMT *stmt, unsigned int param_number, const char *chunk, unsigned long length) { - if ( stmt->dbc->mysql_proxy->stmt_send_long_data(stmt->ssps, param_number, chunk, length)) + if ( stmt->dbc->connection_proxy->stmt_send_long_data(stmt->ssps, param_number, chunk, length)) { - uint err = stmt->dbc->mysql_proxy->stmt_errno(stmt->ssps); + uint err = stmt->dbc->connection_proxy->stmt_errno(stmt->ssps); switch (err) { case CR_INVALID_BUFFER_USE: @@ -1414,12 +1414,12 @@ SQLRETURN ssps_send_long_data(STMT *stmt, unsigned int param_number, const char if (stmt->dbc->fh->trigger_failover_if_needed("08S01", error_code, error_msg)) return stmt->set_error(error_code, error_msg, 0); else - return stmt->set_error("08S01", stmt->dbc->mysql_proxy->stmt_error(stmt->ssps), err); + return stmt->set_error("08S01", stmt->dbc->connection_proxy->stmt_error(stmt->ssps), err); case CR_COMMANDS_OUT_OF_SYNC: case CR_UNKNOWN_ERROR: - return stmt->set_error("HY000", stmt->dbc->mysql_proxy->stmt_error(stmt->ssps), err); + return stmt->set_error("HY000", stmt->dbc->connection_proxy->stmt_error(stmt->ssps), err); case CR_OUT_OF_MEMORY: - return stmt->set_error("HY001", stmt->dbc->mysql_proxy->stmt_error(stmt->ssps), err); + return stmt->set_error("HY001", stmt->dbc->connection_proxy->stmt_error(stmt->ssps), err); default: return stmt->set_error("HY000", "unhandled error from mysql_stmt_send_long_data", 0 ); } diff --git a/driver/my_stmt.cc b/driver/my_stmt.cc index 70c708fec..53ddff7d5 100644 --- a/driver/my_stmt.cc +++ b/driver/my_stmt.cc @@ -53,17 +53,17 @@ BOOL returned_result(STMT *stmt) MYSQL_RES *temp_res= NULL; if ((stmt->result != NULL) || - (temp_res= stmt->dbc->mysql_proxy->stmt_result_metadata(stmt->ssps)) != NULL) + (temp_res= stmt->dbc->connection_proxy->stmt_result_metadata(stmt->ssps)) != NULL) { /* mysql_free_result checks for NULL, so we can always call it */ - stmt->dbc->mysql_proxy->free_result(temp_res); + stmt->dbc->connection_proxy->free_result(temp_res); return TRUE; } return FALSE; } else { - return stmt->dbc->mysql_proxy->field_count() > 0; + return stmt->dbc->connection_proxy->field_count() > 0; } } @@ -76,7 +76,7 @@ my_bool free_current_result(STMT *stmt) if (ssps_used(stmt)) { free_result_bind(stmt); - res= stmt->dbc->mysql_proxy->stmt_free_result(stmt->ssps); + res= stmt->dbc->connection_proxy->stmt_free_result(stmt->ssps); } free_internal_result_buffers(stmt); /* We need to always free stmt->result because SSPS keep metadata there */ @@ -95,11 +95,11 @@ static MYSQL_RES* stmt_get_result(STMT *stmt, BOOL force_use) /* We can't use USE_RESULT because SQLRowCount will fail in this case! */ if (if_forward_cache(stmt) || force_use) { - return stmt->dbc->mysql_proxy->use_result(); + return stmt->dbc->connection_proxy->use_result(); } else { - return stmt->dbc->mysql_proxy->store_result(); + return stmt->dbc->connection_proxy->store_result(); } } @@ -110,11 +110,11 @@ MYSQL_RES * get_result_metadata(STMT *stmt, BOOL force_use) { free_internal_result_buffers(stmt); /* just a precaution, mysql_free_result checks for NULL anywat */ - stmt->dbc->mysql_proxy->free_result(stmt->result); + stmt->dbc->connection_proxy->free_result(stmt->result); if (ssps_used(stmt)) { - stmt->result = stmt->dbc->mysql_proxy->stmt_result_metadata(stmt->ssps); + stmt->result = stmt->dbc->connection_proxy->stmt_result_metadata(stmt->ssps); } else { @@ -151,13 +151,13 @@ size_t STMT::field_count() { if (ssps) { - return dbc->mysql_proxy->stmt_field_count(ssps); + return dbc->connection_proxy->stmt_field_count(ssps); } else { return result && result->field_count > 0 ? result->field_count : - dbc->mysql_proxy->field_count(); + dbc->connection_proxy->field_count(); } } @@ -166,12 +166,12 @@ my_ulonglong affected_rows(STMT *stmt) { if (ssps_used(stmt)) { - return stmt->dbc->mysql_proxy->stmt_affected_rows(stmt->ssps); + return stmt->dbc->connection_proxy->stmt_affected_rows(stmt->ssps); } else { /* In some cases in c/odbc it cannot be used instead of mysql_num_rows */ - return stmt->dbc->mysql_proxy->affected_rows(); + return stmt->dbc->connection_proxy->affected_rows(); } } @@ -194,11 +194,11 @@ my_ulonglong num_rows(STMT *stmt) if (ssps_used(stmt)) { - return offset + stmt->dbc->mysql_proxy->stmt_num_rows(stmt->ssps); + return offset + stmt->dbc->connection_proxy->stmt_num_rows(stmt->ssps); } else { - return offset + stmt->dbc->mysql_proxy->num_rows(stmt->result); + return offset + stmt->dbc->connection_proxy->num_rows(stmt->result); } } @@ -216,7 +216,7 @@ MYSQL_ROW STMT::fetch_row(bool read_unbuffered) if (read_unbuffered || m_row_storage.eof()) { /* Reading results from network */ - err = dbc->mysql_proxy->stmt_fetch(ssps); + err = dbc->connection_proxy->stmt_fetch(ssps); } else { @@ -227,8 +227,8 @@ MYSQL_ROW STMT::fetch_row(bool read_unbuffered) switch (err) { case 1: - set_error("HY000", dbc->mysql_proxy->stmt_error(ssps), - dbc->mysql_proxy->stmt_errno(ssps)); + set_error("HY000", dbc->connection_proxy->stmt_error(ssps), + dbc->connection_proxy->stmt_errno(ssps)); throw error; case MYSQL_NO_DATA: return nullptr; @@ -241,7 +241,7 @@ MYSQL_ROW STMT::fetch_row(bool read_unbuffered) } else { - return dbc->mysql_proxy->fetch_row(result); + return dbc->connection_proxy->fetch_row(result); } } @@ -254,7 +254,7 @@ unsigned long* fetch_lengths(STMT *stmt) } else { - return stmt->dbc->mysql_proxy->fetch_lengths(stmt->result); + return stmt->dbc->connection_proxy->fetch_lengths(stmt->result); } } @@ -263,11 +263,11 @@ MYSQL_ROW_OFFSET row_seek(STMT *stmt, MYSQL_ROW_OFFSET offset) { if (ssps_used(stmt)) { - return stmt->dbc->mysql_proxy->stmt_row_seek(stmt->ssps, offset); + return stmt->dbc->connection_proxy->stmt_row_seek(stmt->ssps, offset); } else { - return stmt->dbc->mysql_proxy->row_seek(stmt->result, offset); + return stmt->dbc->connection_proxy->row_seek(stmt->result, offset); } } @@ -276,11 +276,11 @@ void data_seek(STMT *stmt, my_ulonglong offset) { if (ssps_used(stmt)) { - stmt->dbc->mysql_proxy->stmt_data_seek(stmt->ssps, offset); + stmt->dbc->connection_proxy->stmt_data_seek(stmt->ssps, offset); } else { - stmt->dbc->mysql_proxy->data_seek(stmt->result, offset); + stmt->dbc->connection_proxy->data_seek(stmt->result, offset); } } @@ -289,11 +289,11 @@ MYSQL_ROW_OFFSET row_tell(STMT *stmt) { if (ssps_used(stmt)) { - return stmt->dbc->mysql_proxy->stmt_row_tell(stmt->ssps); + return stmt->dbc->connection_proxy->stmt_row_tell(stmt->ssps); } else { - return stmt->dbc->mysql_proxy->row_tell(stmt->result); + return stmt->dbc->connection_proxy->row_tell(stmt->result); } } @@ -304,11 +304,11 @@ int next_result(STMT *stmt) if (ssps_used(stmt)) { - return stmt->dbc->mysql_proxy->stmt_next_result(stmt->ssps); + return stmt->dbc->connection_proxy->stmt_next_result(stmt->ssps); } else { - return stmt->dbc->mysql_proxy->next_result(); + return stmt->dbc->connection_proxy->next_result(); } } @@ -435,7 +435,7 @@ SQLRETURN prepare(STMT *stmt, char * query, SQLINTEGER query_length, actually parameter markers in it */ if (!stmt->dbc->ds->no_ssps && (PARAM_COUNT(stmt->query) || force_prepare) && !IS_BATCH(&stmt->query) - && preparable_on_server(&stmt->query, stmt->dbc->mysql_proxy->get_server_version())) + && preparable_on_server(&stmt->query, stmt->dbc->connection_proxy->get_server_version())) { MYLOG_STMT_TRACE(stmt, "Using prepared statement"); ssps_init(stmt); @@ -449,32 +449,32 @@ SQLRETURN prepare(STMT *stmt, char * query, SQLINTEGER query_length, if (reset_sql_limit) set_sql_select_limit(stmt->dbc, 0, false); - int prep_res = stmt->dbc->mysql_proxy->stmt_prepare(stmt->ssps, query, query_length); + int prep_res = stmt->dbc->connection_proxy->stmt_prepare(stmt->ssps, query, query_length); if (prep_res) { - MYLOG_STMT_TRACE(stmt, stmt->dbc->mysql_proxy->error()); + MYLOG_STMT_TRACE(stmt, stmt->dbc->connection_proxy->error()); stmt->set_error("HY000"); translate_error((char*)stmt->error.sqlstate.c_str(), MYERR_S1000, - stmt->dbc->mysql_proxy->error_code()); + stmt->dbc->connection_proxy->error_code()); return SQL_ERROR; } - stmt->param_count= stmt->dbc->mysql_proxy->stmt_param_count(stmt->ssps); + stmt->param_count= stmt->dbc->connection_proxy->stmt_param_count(stmt->ssps); free_internal_result_buffers(stmt); /* make sure we free the result from the previous time */ if (stmt->result) { - stmt->dbc->mysql_proxy->free_result(stmt->result); + stmt->dbc->connection_proxy->free_result(stmt->result); stmt->result = NULL; } /* Getting result metadata */ stmt->fake_result = false; // reset in case it was set before - if ((stmt->result = stmt->dbc->mysql_proxy->stmt_result_metadata(stmt->ssps))) + if ((stmt->result = stmt->dbc->connection_proxy->stmt_result_metadata(stmt->ssps))) { /*stmt->state= ST_SS_PREPARED;*/ fix_result_types(stmt); diff --git a/driver/myutil.h b/driver/myutil.h index f5f2c6148..542caec27 100755 --- a/driver/myutil.h +++ b/driver/myutil.h @@ -47,9 +47,9 @@ #define if_forward_cache(st) ((st)->stmt_options.cursor_type == SQL_CURSOR_FORWARD_ONLY && \ (st)->dbc->ds->dont_cache_result) -#define trans_supported(db) ((db)->mysql_proxy->get_server_capabilities() & CLIENT_TRANSACTIONS) -#define autocommit_on(db) ((db)->mysql_proxy->get_server_status() & SERVER_STATUS_AUTOCOMMIT) -#define is_no_backslashes_escape_mode(db) ((db)->mysql_proxy->get_server_status() & SERVER_STATUS_NO_BACKSLASH_ESCAPES) +#define trans_supported(db) ((db)->connection_proxy->get_server_capabilities() & CLIENT_TRANSACTIONS) +#define autocommit_on(db) ((db)->connection_proxy->get_server_status() & SERVER_STATUS_AUTOCOMMIT) +#define is_no_backslashes_escape_mode(db) ((db)->connection_proxy->get_server_status() & SERVER_STATUS_NO_BACKSLASH_ESCAPES) #define reset_ptr(x) {if (x) x= 0;} #define digit(A) ((int) (A - '0')) @@ -184,7 +184,7 @@ SQLRETURN set_desc_error (DESC *desc, char *state, const char *message, uint errcode); SQLRETURN handle_connection_error (STMT *stmt); my_bool is_connection_lost (uint errcode); -void set_mem_error (MYSQL_PROXY *mysql_proxy); +void set_mem_error (CONNECTION_PROXY *connection_proxy); void translate_error (char *save_state, myodbc_errid errid, uint mysql_err); SQLSMALLINT get_sql_data_type_from_str(const char *mysql_type_name); @@ -373,7 +373,7 @@ unsigned long long binary2ull(char* src, uint64 srcLen); void fill_ird_data_lengths (DESC *ird, ulong *lengths, uint fields); /* Functions to work with prepared and regular statements */ -#define IS_PS_OUT_PARAMS(_stmt) ((_stmt)->dbc->mysql_proxy->get_server_status() & SERVER_PS_OUT_PARAMS) +#define IS_PS_OUT_PARAMS(_stmt) ((_stmt)->dbc->connection_proxy->get_server_status() & SERVER_PS_OUT_PARAMS) /* my_stmt.c */ BOOL ssps_used (STMT *stmt); BOOL returned_result (STMT *stmt); @@ -422,7 +422,7 @@ void stmt_result_free(STMT * stmt) x_free(stmt->result); } else - stmt->dbc->mysql_proxy->free_result(stmt->result); + stmt->dbc->connection_proxy->free_result(stmt->result); stmt->result = NULL; } diff --git a/driver/options.cc b/driver/options.cc index 45c3da1df..6928cf44f 100644 --- a/driver/options.cc +++ b/driver/options.cc @@ -272,7 +272,7 @@ MySQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER Attribute, case SQL_ATTR_AUTOCOMMIT: if (ValuePtr != (SQLPOINTER) SQL_AUTOCOMMIT_ON) { - if (dbc->mysql_proxy == nullptr || !dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy == nullptr || !dbc->connection_proxy->is_connected()) { dbc->commit_flag= CHECK_AUTOCOMMIT_OFF; return SQL_SUCCESS; @@ -284,7 +284,7 @@ MySQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER Attribute, if (autocommit_on(dbc)) return odbc_stmt(dbc,"SET AUTOCOMMIT=0", SQL_NTS, TRUE); } - else if (dbc->mysql_proxy == nullptr || !dbc->mysql_proxy->is_connected()) + else if (dbc->connection_proxy == nullptr || !dbc->connection_proxy->is_connected()) { dbc->commit_flag= CHECK_AUTOCOMMIT_ON; return SQL_SUCCESS; @@ -296,7 +296,7 @@ MySQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER Attribute, case SQL_ATTR_LOGIN_TIMEOUT: { /* we can't change timeout values in post connect state */ - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) { return set_conn_error(dbc, MYERR_S1011, NULL, 0); } @@ -340,11 +340,11 @@ MySQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER Attribute, if (!(db= fix_str((char *)ldb, (char *)ValuePtr, StringLengthPtr))) return set_conn_error((DBC*)hdbc,MYERR_S1009,NULL, 0); - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) { - if (dbc->mysql_proxy->select_db((char*) db)) + if (dbc->connection_proxy->select_db((char*) db)) { - set_conn_error(dbc, MYERR_S1000, dbc->mysql_proxy->error(), dbc->mysql_proxy->error_code()); + set_conn_error(dbc, MYERR_S1000, dbc->connection_proxy->error(), dbc->connection_proxy->error_code()); return SQL_ERROR; } } @@ -375,7 +375,7 @@ MySQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER Attribute, break; case SQL_ATTR_TXN_ISOLATION: - if (dbc->mysql_proxy == nullptr || !dbc->mysql_proxy->is_connected()) /* no connection yet */ + if (dbc->connection_proxy == nullptr || !dbc->connection_proxy->is_connected()) /* no connection yet */ { dbc->txn_isolation= (SQLINTEGER)(SQLLEN)ValuePtr; return SQL_SUCCESS; @@ -495,8 +495,8 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, case SQL_ATTR_CONNECTION_DEAD: /* If waking up fails - we return "connection is dead", no matter what really the reason is */ if (dbc->need_to_wakeup != 0 && wakeup_connection(dbc) - || dbc->need_to_wakeup == 0 && dbc->mysql_proxy->ping() && - is_connection_lost(dbc->mysql_proxy->error_code())) + || dbc->need_to_wakeup == 0 && dbc->connection_proxy->ping() && + is_connection_lost(dbc->connection_proxy->error_code())) *((SQLUINTEGER *)num_attr)= SQL_CD_TRUE; else *((SQLUINTEGER *)num_attr)= SQL_CD_FALSE; @@ -508,7 +508,7 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, break; case SQL_ATTR_CURRENT_CATALOG: - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) { + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) { if (reget_current_catalog(dbc)) { return set_handle_error(SQL_HANDLE_DBC, hdbc, MYERR_S1000, @@ -539,7 +539,7 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, break; case SQL_ATTR_PACKET_SIZE: - *((SQLUINTEGER*)num_attr) = dbc->mysql_proxy->get_max_packet(); + *((SQLUINTEGER*)num_attr) = dbc->connection_proxy->get_max_packet(); break; case SQL_ATTR_TXN_ISOLATION: @@ -553,13 +553,13 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, Unless we're not connected yet, then we just assume it will be REPEATABLE READ, which is the server default. */ - if (dbc->mysql_proxy == nullptr || !dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy == nullptr || !dbc->connection_proxy->is_connected()) { *((SQLINTEGER *)num_attr)= SQL_TRANSACTION_REPEATABLE_READ; break; } - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "8.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "8.0")) result = odbc_stmt(dbc, "SELECT @@transaction_isolation", SQL_NTS, TRUE); else result = odbc_stmt(dbc, "SELECT @@tx_isolation", SQL_NTS, TRUE); @@ -574,8 +574,8 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, MYSQL_RES *res; MYSQL_ROW row; - if ((res= dbc->mysql_proxy->store_result()) && - (row = dbc->mysql_proxy->fetch_row(res))) + if ((res= dbc->connection_proxy->store_result()) && + (row = dbc->connection_proxy->fetch_row(res))) { if (strncmp(row[0], "READ-UNCOMMITTED", 16) == 0) { dbc->txn_isolation= SQL_TRANSACTION_READ_UNCOMMITTED; @@ -590,7 +590,7 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, dbc->txn_isolation= SQL_TRANSACTION_SERIALIZABLE; } } - dbc->mysql_proxy->free_result(res); + dbc->connection_proxy->free_result(res); } } diff --git a/driver/results.cc b/driver/results.cc index 5e61210d6..bb8ab42c3 100644 --- a/driver/results.cc +++ b/driver/results.cc @@ -382,7 +382,7 @@ sql_get_data(STMT *stmt, SQLSMALLINT fCType, uint column_number, SQLPOINTER rgbValue, SQLLEN cbValueMax, SQLLEN *pcbValue, char *value, ulong length, DESCREC *arrec) { - MYSQL_FIELD *field= stmt->dbc->mysql_proxy->fetch_field_direct(stmt->result, column_number); + MYSQL_FIELD *field= stmt->dbc->connection_proxy->fetch_field_direct(stmt->result, column_number); SQLLEN temp; long long numeric_value = 0; unsigned long long u_numeric_value = 0; @@ -1599,7 +1599,7 @@ SQLRETURN SQL_API SQLMoreResults( SQLHSTMT hstmt ) /* call to next_result() failed */ if (nRetVal > 0) { - nRetVal= stmt->dbc->mysql_proxy->error_code(); + nRetVal= stmt->dbc->connection_proxy->error_code(); switch ( nRetVal ) { @@ -1612,7 +1612,7 @@ SQLRETURN SQL_API SQLMoreResults( SQLHSTMT hstmt ) if (stmt->dbc->fh->trigger_failover_if_needed("08S01", error_code, error_msg)) nReturn = stmt->set_error(error_code, error_msg, 0); else - nReturn = stmt->set_error(error_code, stmt->dbc->mysql_proxy->error(), nRetVal); + nReturn = stmt->set_error(error_code, stmt->dbc->connection_proxy->error(), nRetVal); goto exitSQLMoreResults; case CR_COMMANDS_OUT_OF_SYNC: case CR_UNKNOWN_ERROR: @@ -2032,7 +2032,7 @@ SQLRETURN SQL_API myodbc_single_fetch( SQLHSTMT hstmt, stmt->set_error("01S07", "One or more row has error.", 0); return SQL_SUCCESS_WITH_INFO; //SQL_NO_DATA_FOUND case SQL_ERROR: return stmt->set_error(MYERR_S1000, - stmt->dbc->mysql_proxy->error(), 0); + stmt->dbc->connection_proxy->error(), 0); } } else @@ -2178,7 +2178,7 @@ SQLRETURN SQL_API myodbc_single_fetch( SQLHSTMT hstmt, stmt->rows_found_in_set= 1; *pcrow= cur_row; - disconnected= is_connection_lost(stmt->dbc->mysql_proxy->error_code()) + disconnected= is_connection_lost(stmt->dbc->connection_proxy->error_code()) && handle_connection_error(stmt); if ( upd_status && stmt->ird->rows_processed_ptr ) @@ -2270,7 +2270,7 @@ SQLRETURN SQL_API my_SQLExtendedFetch( SQLHSTMT hstmt, return SQL_NO_DATA_FOUND; case OPS_STREAMS_PENDING: /* Magical out params fetch */ - stmt->dbc->mysql_proxy->stmt_fetch(stmt->ssps); + stmt->dbc->connection_proxy->stmt_fetch(stmt->ssps); default: /* TODO: Need to remember real fetch' result */ /* just in case... */ @@ -2467,7 +2467,7 @@ SQLRETURN SQL_API my_SQLExtendedFetch( SQLHSTMT hstmt, stmt->rows_found_in_set= i; *pcrow= i; - disconnected= is_connection_lost(stmt->dbc->mysql_proxy->error_code()) + disconnected= is_connection_lost(stmt->dbc->connection_proxy->error_code()) && handle_connection_error(stmt); if ( upd_status && stmt->ird->rows_processed_ptr ) diff --git a/driver/secrets_manager_proxy.cc b/driver/secrets_manager_proxy.cc new file mode 100644 index 000000000..75c96facd --- /dev/null +++ b/driver/secrets_manager_proxy.cc @@ -0,0 +1,80 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License, version 2.0 +// (GPLv2), as published by the Free Software Foundation, with the +// following additional permissions: +// +// This program is distributed with certain software that is licensed +// under separate terms, as designated in a particular file or component +// or in the license documentation. Without limiting your rights under +// the GPLv2, the authors of this program hereby grant you an additional +// permission to link the program and your derivative works with the +// separately licensed software that they have included with the program. +// +// Without limiting the foregoing grant of rights under the GPLv2 and +// additional permission as to separately licensed software, this +// program is also subject to the Universal FOSS Exception, version 1.0, +// a copy of which can be found along with its FAQ at +// http://oss.oracle.com/licenses/universal-foss-exception. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License, version 2.0, for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// http://www.gnu.org/licenses/gpl-2.0.html. + +#include +#include + +#include "secrets_manager_proxy.h" + +#include "installer.h" + +using namespace Aws::SecretsManager; + +SECRETS_MANAGER_PROXY::SECRETS_MANAGER_PROXY(DBC* dbc, DataSource* ds) : SECRETS_MANAGER_PROXY( + dbc, ds, nullptr) {} + + +SECRETS_MANAGER_PROXY::SECRETS_MANAGER_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy) : CONNECTION_PROXY(dbc, ds) { + Aws::InitAPI(this->SDK_options); + + Aws::Client::ClientConfiguration config; + const char* region = ds_get_utf8attr(ds->auth_region, &ds->auth_region8); + config.region = region ? region : "us-east-1"; + + this->sm_client = SecretsManagerClient(config); + + const Aws::String secret_ID = ds_get_utf8attr(ds->auth_secret_id, &ds->auth_secret_id8); + + Model::GetSecretValueRequest request; + request.SetSecretId(secret_ID); + + auto getSecretValueOutcome = this->sm_client.GetSecretValue(request); + if (getSecretValueOutcome.IsSuccess()) { + std::cout << "Secret is: " << getSecretValueOutcome.GetResult().GetSecretString() << std::endl; + } + else { + std::cout << "Failed with Error: " << getSecretValueOutcome.GetError() << std::endl; + } + + this->next_proxy = next_proxy; +} + +SECRETS_MANAGER_PROXY::~SECRETS_MANAGER_PROXY() { + Aws::ShutdownAPI(this->SDK_options); +} + +bool SECRETS_MANAGER_PROXY::real_connect(const char* host, const char* user, const char* passwd, const char* db, unsigned int port, const char* unix_socket, unsigned long clientflag) { + + const bool ret = next_proxy->real_connect(host, user, passwd, db, port, unix_socket, clientflag); + return ret; +} + +void SECRETS_MANAGER_PROXY::set_next_proxy(CONNECTION_PROXY* next_proxy) { + CONNECTION_PROXY::set_next_proxy(next_proxy); +} diff --git a/driver/secrets_manager_proxy.h b/driver/secrets_manager_proxy.h new file mode 100644 index 000000000..6b13818b2 --- /dev/null +++ b/driver/secrets_manager_proxy.h @@ -0,0 +1,173 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License, version 2.0 +// (GPLv2), as published by the Free Software Foundation, with the +// following additional permissions: +// +// This program is distributed with certain software that is licensed +// under separate terms, as designated in a particular file or component +// or in the license documentation. Without limiting your rights under +// the GPLv2, the authors of this program hereby grant you an additional +// permission to link the program and your derivative works with the +// separately licensed software that they have included with the program. +// +// Without limiting the foregoing grant of rights under the GPLv2 and +// additional permission as to separately licensed software, this +// program is also subject to the Universal FOSS Exception, version 1.0, +// a copy of which can be found along with its FAQ at +// http://oss.oracle.com/licenses/universal-foss-exception. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License, version 2.0, for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// http://www.gnu.org/licenses/gpl-2.0.html. + +#ifndef __SECRETS_MANAGER_PROXY__ +#define __SECRETS_MANAGER_PROXY__ + +#include +#include + +#include + +#include "connection_proxy.h" + +class SECRETS_MANAGER_PROXY : public CONNECTION_PROXY { + public: + SECRETS_MANAGER_PROXY(DBC* dbc, DataSource* ds); + SECRETS_MANAGER_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy); + ~SECRETS_MANAGER_PROXY(); + + void delete_ds() override; + uint64_t num_rows(MYSQL_RES* res) override; + unsigned int num_fields(MYSQL_RES* res) override; + MYSQL_FIELD* fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) override; + MYSQL_ROW_OFFSET row_tell(MYSQL_RES* res) override; + + unsigned int field_count() override; + uint64_t affected_rows() override; + unsigned int error_code() override; + const char* error() override; + const char* sqlstate() override; + unsigned long thread_id() override; + int set_character_set(const char* csname) override; + + void init() override; + bool ssl_set(const char* key, const char* cert, const char* ca, + const char* capath, const char* cipher) override; + bool change_user(const char* user, const char* passwd, + const char* db) override; + bool real_connect(const char* host, const char* user, + const char* passwd, const char* db, unsigned int port, + const char* unix_socket, unsigned long clientflag) override; + int select_db(const char* db) override; + int query(const char* q) override; + int real_query(const char* q, unsigned long length) override; + MYSQL_RES* store_result() override; + MYSQL_RES* use_result() override; + struct CHARSET_INFO* get_character_set() const override; + void get_character_set_info(MY_CHARSET_INFO* charset) override; + + int ping() override; + int options(enum mysql_option option, const void* arg) override; + int options4(enum mysql_option option, const void* arg1, + const void* arg2) override; + int get_option(enum mysql_option option, const void* arg) override; + void free_result(MYSQL_RES* result) override; + void data_seek(MYSQL_RES* result, uint64_t offset) override; + MYSQL_ROW_OFFSET row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) override; + MYSQL_FIELD_OFFSET field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) override; + MYSQL_ROW fetch_row(MYSQL_RES* result) override; + + unsigned long* fetch_lengths(MYSQL_RES* result) override; + MYSQL_FIELD* fetch_field(MYSQL_RES* result) override; + MYSQL_RES* list_fields(const char* table, const char* wild) override; + unsigned long real_escape_string(char* to, const char* from, + unsigned long length) override; + + bool bind_param(unsigned n_params, MYSQL_BIND* binds, + const char** names) override; + + MYSQL_STMT* stmt_init() override; + int stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length) override; + int stmt_execute(MYSQL_STMT* stmt) override; + int stmt_fetch(MYSQL_STMT* stmt) override; + int stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, + unsigned int column, unsigned long offset) override; + int stmt_store_result(MYSQL_STMT* stmt) override; + unsigned long stmt_param_count(MYSQL_STMT* stmt) override; + bool stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; + bool stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; + bool stmt_close(MYSQL_STMT* stmt) override; + bool stmt_reset(MYSQL_STMT* stmt) override; + bool stmt_free_result(MYSQL_STMT* stmt) override; + bool stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, + const char* data, unsigned long length) override; + MYSQL_RES* stmt_result_metadata(MYSQL_STMT* stmt) override; + unsigned int stmt_errno(MYSQL_STMT* stmt) override; + const char* stmt_error(MYSQL_STMT* stmt) override; + MYSQL_ROW_OFFSET stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) override; + MYSQL_ROW_OFFSET stmt_row_tell(MYSQL_STMT* stmt) override; + void stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) override; + uint64_t stmt_num_rows(MYSQL_STMT* stmt) override; + uint64_t stmt_affected_rows(MYSQL_STMT* stmt) override; + unsigned int stmt_field_count(MYSQL_STMT* stmt) override; + + bool autocommit(bool auto_mode) override; + int next_result() override; + int stmt_next_result(MYSQL_STMT* stmt) override; + void close() override; + + bool real_connect_dns_srv(const char* dns_srv_name, + const char* user, const char* passwd, + const char* db, unsigned long client_flag) override; + struct st_mysql_client_plugin* client_find_plugin( + const char* name, int type) override; + + bool is_connected() override; + + void set_last_error_code(unsigned int error_code) override; + + char* get_last_error() const override; + + unsigned int get_last_error_code() const override; + + char* get_sqlstate() const override; + + char* get_server_version() const override; + + uint64_t get_affected_rows() const override; + + void set_affected_rows(uint64_t num_rows) override; + + char* get_host_info() const override; + + std::string get_host() override; + + unsigned int get_port() override; + + unsigned long get_max_packet() const override; + + unsigned long get_server_capabilities() const override; + + unsigned int get_server_status() const override; + + void set_connection(CONNECTION_PROXY* connection_proxy) override; + + void close_socket() override; + + void set_next_proxy(CONNECTION_PROXY* next_proxy) override; + +private: + Aws::SecretsManager::SecretsManagerClient sm_client; + Aws::SDKOptions SDK_options; + + Aws::String fetch_latest_credentials(); +}; + +#endif /* __SECRETS_MANAGER_PROXY__ */ diff --git a/driver/topology_service.cc b/driver/topology_service.cc index 2d81f0ea0..a92632d3e 100644 --- a/driver/topology_service.cc +++ b/driver/topology_service.cc @@ -167,7 +167,7 @@ std::shared_ptr TOPOLOGY_SERVICE::get_cached_topology() { //TODO consider the return value //Note to determine whether or not force_update succeeded one would compare // CLUSTER_TOPOLOGY_INFO->time_last_updated() prior and after the call if non-null information was given prior. -std::shared_ptr TOPOLOGY_SERVICE::get_topology(MYSQL_PROXY* connection, bool force_update) +std::shared_ptr TOPOLOGY_SERVICE::get_topology(CONNECTION_PROXY* connection, bool force_update) { //TODO reconsider using this cache. It appears that we only store information for the current cluster Id. // therefore instead of a map we can just keep CLUSTER_TOPOLOGY_INFO* topology_info member variable. @@ -219,9 +219,9 @@ void TOPOLOGY_SERVICE::put_to_cache(std::shared_ptr topol lock.unlock(); } -MYSQL_RES* TOPOLOGY_SERVICE::try_execute_query(MYSQL_PROXY* mysql_proxy, const char* query) { - if (mysql_proxy != nullptr && mysql_proxy->query(query) == 0) { - return mysql_proxy->store_result(); +MYSQL_RES* TOPOLOGY_SERVICE::try_execute_query(CONNECTION_PROXY* connection_proxy, const char* query) { + if (connection_proxy != nullptr && connection_proxy->query(query) == 0) { + return connection_proxy->store_result(); } return nullptr; @@ -270,17 +270,17 @@ std::shared_ptr TOPOLOGY_SERVICE::create_host(MYSQL_ROW& row) { } // If no host information retrieved return NULL -std::shared_ptr TOPOLOGY_SERVICE::query_for_topology(MYSQL_PROXY* mysql_proxy) { +std::shared_ptr TOPOLOGY_SERVICE::query_for_topology(CONNECTION_PROXY* connection_proxy) { std::shared_ptr topology_info = nullptr; std::chrono::steady_clock::time_point start_time_ms = std::chrono::steady_clock::now(); - if (MYSQL_RES* result = try_execute_query(mysql_proxy, RETRIEVE_TOPOLOGY_SQL)) { + if (MYSQL_RES* result = try_execute_query(connection_proxy, RETRIEVE_TOPOLOGY_SQL)) { topology_info = std::make_shared(); std::map> instances; MYSQL_ROW row; int writer_count = 0; - while ((row = mysql_proxy->fetch_row(result))) { + while ((row = connection_proxy->fetch_row(result))) { std::shared_ptr host_info = create_host(row); if (host_info) { // Only mark the first/latest writer as true writer @@ -296,7 +296,7 @@ std::shared_ptr TOPOLOGY_SERVICE::query_for_topology(MYSQ } } } - mysql_proxy->free_result(result); + connection_proxy->free_result(result); topology_info->is_multi_writer_cluster = writer_count > 1; if (writer_count == 0) { diff --git a/driver/topology_service.h b/driver/topology_service.h index f963ea430..60f4b6d4d 100644 --- a/driver/topology_service.h +++ b/driver/topology_service.h @@ -34,7 +34,7 @@ #include "cluster_aware_metrics_container.h" #include "cluster_topology_info.h" -#include "mysql_proxy.h" +#include "connection_proxy.h" #include #include @@ -63,7 +63,7 @@ class TOPOLOGY_SERVICE { virtual void set_cluster_instance_template(std::shared_ptr host_template); //is this equivalent to setcluster_instance_host virtual std::shared_ptr get_topology( - MYSQL_PROXY* connection, bool force_update = false); + CONNECTION_PROXY* connection, bool force_update = false); std::shared_ptr get_cached_topology(); std::shared_ptr get_last_used_reader(); @@ -106,7 +106,7 @@ class TOPOLOGY_SERVICE { std::shared_ptr metrics_container; bool refresh_needed(std::time_t last_updated); - std::shared_ptr query_for_topology(MYSQL_PROXY* connection); + std::shared_ptr query_for_topology(CONNECTION_PROXY* connection); std::shared_ptr create_host(MYSQL_ROW& row); std::string get_host_endpoint(const char* node_name); static bool does_instance_exist( @@ -116,7 +116,7 @@ class TOPOLOGY_SERVICE { std::shared_ptr get_from_cache(); void put_to_cache(std::shared_ptr topology_info); - MYSQL_RES* try_execute_query(MYSQL_PROXY* mysql_proxy, const char* query); + MYSQL_RES* try_execute_query(CONNECTION_PROXY* connection_proxy, const char* query); }; #endif /* __TOPOLOGYSERVICE_H__ */ diff --git a/driver/unicode.cc b/driver/unicode.cc index 203388db8..1e6c382d2 100644 --- a/driver/unicode.cc +++ b/driver/unicode.cc @@ -287,7 +287,7 @@ SQLDescribeColW(SQLHSTMT hstmt, SQLUSMALLINT column, if (free_value == -1) { - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } @@ -299,7 +299,7 @@ SQLDescribeColW(SQLHSTMT hstmt, SQLUSMALLINT column, { if (free_value) x_free(value); - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } @@ -1030,7 +1030,7 @@ SQLSetConnectAttrWImpl(SQLHDBC hdbc, SQLINTEGER attribute, "than 0 but was not SQL_NTS " , 0); } - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) value= sqlwchar_as_sqlchar(dbc->cxn_charset_info, (SQLWCHAR*)value, &len, &errors); else diff --git a/driver/utility.cc b/driver/utility.cc index 2fe192cfa..f12b07499 100755 --- a/driver/utility.cc +++ b/driver/utility.cc @@ -109,18 +109,18 @@ SQLRETURN odbc_stmt(DBC *dbc, const char *query, } // return immediately if not connected - if (!dbc->mysql_proxy->is_connected()) + if (!dbc->connection_proxy->is_connected()) { return set_conn_error(dbc, MYERR_08S01, "The active SQL connection was lost. Please discard this connection.", 0); } bool server_alive = is_server_alive(dbc); - if (!server_alive || dbc->mysql_proxy->real_query(query, query_length)) + if (!server_alive || dbc->connection_proxy->real_query(query, query_length)) { - const unsigned int mysql_error_code = dbc->mysql_proxy->error_code(); + const unsigned int mysql_error_code = dbc->connection_proxy->error_code(); - MYLOG_DBC_TRACE(dbc, dbc->mysql_proxy->error()); - result = set_conn_error(dbc, MYERR_S1000, dbc->mysql_proxy->error(), mysql_error_code); + MYLOG_DBC_TRACE(dbc, dbc->connection_proxy->error()); + result = set_conn_error(dbc, MYERR_S1000, dbc->connection_proxy->error(), mysql_error_code); if (!server_alive || is_connection_lost(mysql_error_code)) { @@ -128,7 +128,7 @@ SQLRETURN odbc_stmt(DBC *dbc, const char *query, if (rollback) { MYLOG_DBC_TRACE(dbc, "Rolling back"); - dbc->mysql_proxy->real_query("ROLLBACK", 8); + dbc->connection_proxy->real_query("ROLLBACK", 8); } const char *error_code, *error_msg; @@ -197,7 +197,7 @@ void fix_row_lengths(STMT *stmt, const long* fix_rules, uint row, uint field_cou return; row_lengths = stmt->lengths.get() + row * field_count; - orig_lengths = stmt->dbc->mysql_proxy->fetch_lengths(stmt->result); + orig_lengths = stmt->dbc->connection_proxy->fetch_lengths(stmt->result); for (i= 0; i < field_count; ++i) { @@ -2521,7 +2521,7 @@ bool is_server_alive( DBC *dbc ) if ( (ulong)(seconds - dbc->last_query_time) >= CHECK_IF_ALIVE ) { - if ( dbc->mysql_proxy->ping() ) + if ( dbc->connection_proxy->ping() ) { /* BUG: 14639 @@ -2538,7 +2538,7 @@ bool is_server_alive( DBC *dbc ) PAH - 9.MAR.06 */ - if (is_connection_lost(dbc->mysql_proxy->error_code())) + if (is_connection_lost(dbc->connection_proxy->error_code())) server_alive = false; } } @@ -2580,8 +2580,8 @@ int reget_current_catalog(DBC *dbc) MYSQL_RES *res; MYSQL_ROW row; - if ( (res= dbc->mysql_proxy->store_result()) && - (row = dbc->mysql_proxy->fetch_row(res))) + if ( (res= dbc->connection_proxy->store_result()) && + (row = dbc->connection_proxy->fetch_row(res))) { /* if (cmp_database(row[0], dbc->database)) */ { @@ -2591,7 +2591,7 @@ int reget_current_catalog(DBC *dbc) } } } - dbc->mysql_proxy->free_result(res); + dbc->connection_proxy->free_result(res); } return 0; @@ -3818,7 +3818,7 @@ void set_row_count(STMT *stmt, my_ulonglong rows) if (stmt != NULL && stmt->result != NULL) { stmt->result->row_count= rows; - stmt->dbc->mysql_proxy->set_affected_rows(rows); + stmt->dbc->connection_proxy->set_affected_rows(rows); } } @@ -4315,19 +4315,19 @@ int get_session_variable(STMT *stmt, const char *var, char *result, size_t resul return 0; } - res = stmt->dbc->mysql_proxy->store_result(); + res = stmt->dbc->connection_proxy->store_result(); if (!res) return 0; - row = stmt->dbc->mysql_proxy->fetch_row(res); + row = stmt->dbc->connection_proxy->fetch_row(res); if (row) { strncpy(result, row[1], result_size); - stmt->dbc->mysql_proxy->free_result(res); + stmt->dbc->connection_proxy->free_result(res); return strlen(result); } - stmt->dbc->mysql_proxy->free_result(res); + stmt->dbc->connection_proxy->free_result(res); } return 0; @@ -4348,7 +4348,7 @@ SQLRETURN set_query_timeout(STMT *stmt, SQLULEN new_value) SQLRETURN rc= SQL_SUCCESS; if (new_value == stmt->stmt_options.query_timeout || - !is_minimum_version(stmt->dbc->mysql_proxy->get_server_version(), "5.7.8")) + !is_minimum_version(stmt->dbc->connection_proxy->get_server_version(), "5.7.8")) { /* Do nothing if setting same timeout or MySQL server older than 5.7.8 */ return SQL_SUCCESS; @@ -4378,7 +4378,7 @@ SQLULEN get_query_timeout(STMT *stmt) { SQLULEN query_timeout= SQL_QUERY_TIMEOUT_DEFAULT; /* 0 */ - if (is_minimum_version(stmt->dbc->mysql_proxy->get_server_version(), "5.7.8")) + if (is_minimum_version(stmt->dbc->connection_proxy->get_server_version(), "5.7.8")) { /* Be cautious with very long values even if they don't make sense */ char query_timeout_char[32]= {0}; @@ -4397,7 +4397,7 @@ const char get_identifier_quote(STMT *stmt) { const char tick= '`', quote= '"', empty= ' '; - if (is_minimum_version(stmt->dbc->mysql_proxy->get_server_version(), "3.23.06")) + if (is_minimum_version(stmt->dbc->connection_proxy->get_server_version(), "3.23.06")) { /* The full list of all SQL modes takes over 512 symbols, so we reserve diff --git a/unit_testing/efm_proxy_test.cc b/unit_testing/efm_proxy_test.cc index b3ef68c39..ee159d056 100644 --- a/unit_testing/efm_proxy_test.cc +++ b/unit_testing/efm_proxy_test.cc @@ -44,7 +44,7 @@ class EFMProxyTest : public testing::Test { DBC* dbc; DataSource* ds; std::shared_ptr mock_monitor_service; - MOCK_MYSQL_PROXY* mock_mysql_proxy; + MOCK_CONNECTION_PROXY* mock_connection_proxy; static void SetUpTestSuite() {} @@ -59,7 +59,7 @@ class EFMProxyTest : public testing::Test { ds->enable_failure_detection = true; mock_monitor_service = std::make_shared(); - mock_mysql_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_connection_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); } void TearDown() override { @@ -68,13 +68,13 @@ class EFMProxyTest : public testing::Test { }; TEST_F(EFMProxyTest, NullDBC) { - EXPECT_THROW(EFM_PROXY efm_proxy(nullptr, ds, mock_mysql_proxy), std::runtime_error); - delete mock_mysql_proxy; + EXPECT_THROW(EFM_PROXY efm_proxy(nullptr, ds, mock_connection_proxy), std::runtime_error); + delete mock_connection_proxy; } TEST_F(EFMProxyTest, NullDS) { - EXPECT_THROW(EFM_PROXY efm_proxy(dbc, nullptr, mock_mysql_proxy), std::runtime_error); - delete mock_mysql_proxy; + EXPECT_THROW(EFM_PROXY efm_proxy(dbc, nullptr, mock_connection_proxy), std::runtime_error); + delete mock_connection_proxy; } TEST_F(EFMProxyTest, FailureDetectionDisabled) { @@ -82,10 +82,10 @@ TEST_F(EFMProxyTest, FailureDetectionDisabled) { EXPECT_CALL(*mock_monitor_service, start_monitoring(_, _, _, _, _, _, _, _, _)).Times(0); EXPECT_CALL(*mock_monitor_service, stop_monitoring(_)).Times(0); - EXPECT_CALL(*mock_mysql_proxy, init()); - EXPECT_CALL(*mock_mysql_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_connection_proxy, init()); + EXPECT_CALL(*mock_connection_proxy, mock_connection_proxy_destructor()); - EFM_PROXY efm_proxy(dbc, ds, mock_mysql_proxy, mock_monitor_service); + EFM_PROXY efm_proxy(dbc, ds, mock_connection_proxy, mock_monitor_service); efm_proxy.init(); } @@ -96,19 +96,19 @@ TEST_F(EFMProxyTest, FailureDetectionEnabled) { EXPECT_CALL(*mock_monitor_service, start_monitoring(_, _, _, _, _, _, _, _, _)).WillOnce(Return(mock_context)); EXPECT_CALL(*mock_monitor_service, stop_monitoring(mock_context)).Times(1); - EXPECT_CALL(*mock_mysql_proxy, query("")); - EXPECT_CALL(*mock_mysql_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_connection_proxy, query("")); + EXPECT_CALL(*mock_connection_proxy, mock_connection_proxy_destructor()); - EFM_PROXY efm_proxy(dbc, ds, mock_mysql_proxy, mock_monitor_service); + EFM_PROXY efm_proxy(dbc, ds, mock_connection_proxy, mock_monitor_service); efm_proxy.query(""); } TEST_F(EFMProxyTest, DoesNotNeedMonitoring) { EXPECT_CALL(*mock_monitor_service, start_monitoring(_, _, _, _, _, _, _, _, _)).Times(0); EXPECT_CALL(*mock_monitor_service, stop_monitoring(_)).Times(0); - EXPECT_CALL(*mock_mysql_proxy, close()); - EXPECT_CALL(*mock_mysql_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_connection_proxy, close()); + EXPECT_CALL(*mock_connection_proxy, mock_connection_proxy_destructor()); - EFM_PROXY efm_proxy(dbc, ds, mock_mysql_proxy, mock_monitor_service); + EFM_PROXY efm_proxy(dbc, ds, mock_connection_proxy, mock_monitor_service); efm_proxy.close(); } diff --git a/unit_testing/failover_reader_handler_test.cc b/unit_testing/failover_reader_handler_test.cc index 04724b510..00255f89d 100644 --- a/unit_testing/failover_reader_handler_test.cc +++ b/unit_testing/failover_reader_handler_test.cc @@ -57,9 +57,9 @@ class FailoverReaderHandlerTest : public testing::Test { static std::shared_ptr reader_c_host; static std::shared_ptr writer_host; - MOCK_MYSQL_PROXY* mock_reader_a_proxy; - MOCK_MYSQL_PROXY* mock_reader_b_proxy; - MOCK_MYSQL_PROXY* mock_writer_proxy; + MOCK_CONNECTION_PROXY* mock_reader_a_proxy; + MOCK_CONNECTION_PROXY* mock_reader_b_proxy; + MOCK_CONNECTION_PROXY* mock_writer_proxy; static std::shared_ptr topology; @@ -238,7 +238,7 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Failure) { // Verify that reader failover handler connects to a reader node that is marked up. // Expected result: new connection to reader A TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Reader) { - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_ts, get_topology(_, true)).WillRepeatedly(Return(topology)); @@ -265,7 +265,7 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Reader) { // Verify that reader failover handler connects to a writer node. // Expected result: new connection to writer TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Writer) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_ts, get_topology(_, true)).WillRepeatedly(Return(topology)); @@ -291,8 +291,8 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Writer) { // Verify that reader failover handler connects to the fastest reader node available that is marked up. // Expected result: new connection to reader A TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_FastestHost) { - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_b_proxy = new MOCK_MYSQL_PROXY(dbc, ds); // Will be free'd during failover as it is slower + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_b_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); // Will be free'd during failover as it is slower // May not have actually connected during failover // Cannot delete at the end as it may cause double delete @@ -329,15 +329,15 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_FastestHost) { // Expected result: no connection TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Timeout) { // Connections should automatically free inside failover - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_b_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_b_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_ts, get_topology(_, true)).WillRepeatedly(Return(topology)); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_b_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_b_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_connection_handler, connect(_, nullptr)).WillRepeatedly(Return(nullptr)); EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)).WillRepeatedly(Invoke([&]() { @@ -382,8 +382,8 @@ TEST_F(FailoverReaderHandlerTest, Failover_Failure) { // Verify that reader failover handler connects to a faster reader node. // Expected result: new connection to reader A TEST_F(FailoverReaderHandlerTest, Failover_Success_Reader) { - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_b_proxy = new MOCK_MYSQL_PROXY(dbc, ds); // Will be free'd during failover to timeout / too slow + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_b_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); // Will be free'd during failover to timeout / too slow // May not have actually connected during failover // Cannot delete at the end as it may cause double delete @@ -399,7 +399,7 @@ TEST_F(FailoverReaderHandlerTest, Failover_Success_Reader) { EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_b_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_b_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_connection_handler, connect(_, nullptr)).WillRepeatedly(Return(nullptr)); EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)).WillRepeatedly( diff --git a/unit_testing/failover_writer_handler_test.cc b/unit_testing/failover_writer_handler_test.cc index d21cead6a..86b94b7e5 100644 --- a/unit_testing/failover_writer_handler_test.cc +++ b/unit_testing/failover_writer_handler_test.cc @@ -65,10 +65,10 @@ class FailoverWriterHandlerTest : public testing::Test { std::shared_ptr mock_ts; std::shared_ptr mock_reader_handler; std::shared_ptr mock_connection_handler; - MOCK_MYSQL_PROXY* mock_reader_a_proxy; - MOCK_MYSQL_PROXY* mock_reader_b_proxy; - MOCK_MYSQL_PROXY* mock_writer_proxy; - MOCK_MYSQL_PROXY* mock_new_writer_proxy; + MOCK_CONNECTION_PROXY* mock_reader_a_proxy; + MOCK_CONNECTION_PROXY* mock_reader_b_proxy; + MOCK_CONNECTION_PROXY* mock_writer_proxy; + MOCK_CONNECTION_PROXY* mock_new_writer_proxy; static void SetUpTestSuite() {} @@ -113,7 +113,7 @@ class FailoverWriterHandlerTest : public testing::Test { // taskB: fail to connect to any reader due to exception // expected test result: new connection by taskA TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_TaskBEmptyReaderResult) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_writer_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_ts, get_topology(_, true)) @@ -153,8 +153,8 @@ TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_TaskBEmptyReaderResult) { // time than taskA // expected test result: new connection by taskA TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_SlowReaderA) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); // May not have actually connected during failover // Cannot delete at the end as it may cause double delete @@ -213,12 +213,12 @@ TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_SlowReaderA) { // writer is not new (defer to taskA) // expected test result: new connection by taskA TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_TaskBDefers) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_writer_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) .WillRepeatedly(Invoke([&]() { @@ -259,9 +259,9 @@ TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_TaskBDefers) { // taskB: successfully connect to readerA and then to new-writer // expected test result: new connection to writer by taskB TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_SlowWriter) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_new_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_new_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); // May not have actually connected during failover // Cannot delete at the end as it may cause double delete @@ -274,12 +274,12 @@ TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_SlowWriter) { new_topology->add_host(reader_b_host); EXPECT_CALL(*mock_writer_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_writer_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_writer_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_new_writer_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) .WillRepeatedly(Invoke([&]() { @@ -323,9 +323,9 @@ TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_SlowWriter) { // taskB: successfully connect to readerA and then to new-writer // expected test result: new connection to writer by taskB TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_TaskADefers) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_new_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_new_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); auto new_topology = std::make_shared(); new_topology->add_host(new_writer_host); @@ -334,12 +334,12 @@ TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_TaskADefers) { new_topology->add_host(reader_b_host); EXPECT_CALL(*mock_writer_proxy, is_connected()).WillOnce(Return(true)); - EXPECT_CALL(*mock_writer_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_writer_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_new_writer_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) .WillOnce(Return(mock_writer_proxy)) @@ -382,10 +382,10 @@ TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_TaskADefers) { // taskB: successfully connect to readerA and then fail to connect to writer due to failover timeout // expected test result: no connection TEST_F(FailoverWriterHandlerTest, FailedToConnect_FailoverTimeout) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_new_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_b_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_new_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_b_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); auto new_topology = std::make_shared(); new_topology->add_host(new_writer_host); @@ -393,13 +393,13 @@ TEST_F(FailoverWriterHandlerTest, FailedToConnect_FailoverTimeout) { new_topology->add_host(reader_b_host); EXPECT_CALL(*mock_writer_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_writer_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_writer_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_new_writer_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_new_writer_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_new_writer_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); @@ -448,8 +448,8 @@ TEST_F(FailoverWriterHandlerTest, FailedToConnect_FailoverTimeout) { // taskB: successfully connect to readerA and then fail to connect to writer // expected test result: no connection TEST_F(FailoverWriterHandlerTest, FailedToConnect_TaskAFailed_TaskBWriterFailed) { - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_b_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_b_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); auto new_topology = std::make_shared(); new_topology->add_host(new_writer_host); @@ -457,7 +457,7 @@ TEST_F(FailoverWriterHandlerTest, FailedToConnect_TaskAFailed_TaskBWriterFailed) new_topology->add_host(reader_b_host); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); diff --git a/unit_testing/mock_objects.h b/unit_testing/mock_objects.h index b31cbb6b6..ec26c0d50 100644 --- a/unit_testing/mock_objects.h +++ b/unit_testing/mock_objects.h @@ -32,7 +32,7 @@ #include -#include "driver/mysql_proxy.h" +#include "driver/connection_proxy.h" #include "driver/failover.h" #include "driver/monitor_thread_container.h" #include "driver/monitor_service.h" @@ -51,14 +51,14 @@ DataSource* ds_new(); void ds_delete(DataSource* ds); void ds_copy(DataSource* ds, DataSource* ds_source); -class MOCK_MYSQL_PROXY : public MYSQL_PROXY { +class MOCK_CONNECTION_PROXY : public CONNECTION_PROXY { public: - MOCK_MYSQL_PROXY(DBC* dbc, DataSource* ds) : MYSQL_PROXY(dbc, ds) { + MOCK_CONNECTION_PROXY(DBC* dbc, DataSource* ds) : CONNECTION_PROXY(dbc, ds) { this->ds = ds_new(); ds_copy(this->ds, ds); }; - ~MOCK_MYSQL_PROXY() override { - mock_mysql_proxy_destructor(); + ~MOCK_CONNECTION_PROXY() override { + mock_connection_proxy_destructor(); if (this->ds) { ds_delete(this->ds); this->ds = nullptr; @@ -77,7 +77,7 @@ class MOCK_MYSQL_PROXY : public MYSQL_PROXY { MOCK_METHOD(char**, fetch_row, (MYSQL_RES*)); MOCK_METHOD(void, free_result, (MYSQL_RES*)); MOCK_METHOD(void, close_socket, ()); - MOCK_METHOD(void, mock_mysql_proxy_destructor, ()); + MOCK_METHOD(void, mock_connection_proxy_destructor, ()); MOCK_METHOD(void, close, ()); MOCK_METHOD(void, init, ()); MOCK_METHOD(int, ping, ()); @@ -90,7 +90,7 @@ class MOCK_TOPOLOGY_SERVICE : public TOPOLOGY_SERVICE { MOCK_METHOD(void, set_cluster_id, (std::string)); MOCK_METHOD(void, set_cluster_instance_template, (std::shared_ptr)); - MOCK_METHOD(std::shared_ptr, get_topology, (MYSQL_PROXY*, bool)); + MOCK_METHOD(std::shared_ptr, get_topology, (CONNECTION_PROXY*, bool)); MOCK_METHOD(void, mark_host_down, (std::shared_ptr)); MOCK_METHOD(void, mark_host_up, (std::shared_ptr)); }; @@ -105,7 +105,7 @@ class MOCK_READER_HANDLER : public FAILOVER_READER_HANDLER { class MOCK_CONNECTION_HANDLER : public CONNECTION_HANDLER { public: MOCK_CONNECTION_HANDLER() : CONNECTION_HANDLER(nullptr) {} - MOCK_METHOD(MYSQL_PROXY*, connect, (const std::shared_ptr&, DataSource*)); + MOCK_METHOD(CONNECTION_PROXY*, connect, (const std::shared_ptr&, DataSource*)); MOCK_METHOD(SQLRETURN, do_connect, (DBC*, DataSource*, bool)); }; @@ -130,7 +130,7 @@ class MOCK_CLUSTER_AWARE_METRICS_CONTAINER : public CLUSTER_AWARE_METRICS_CONTAI class MOCK_MONITOR : public MONITOR { public: MOCK_MONITOR(std::shared_ptr host, std::chrono::milliseconds disposal_time, - MYSQL_PROXY* monitor_proxy) + CONNECTION_PROXY* monitor_proxy) : MONITOR(host, nullptr, std::chrono::seconds{5}, disposal_time, nullptr, monitor_proxy) {} MOCK_METHOD(void, start_monitoring, (std::shared_ptr)); diff --git a/unit_testing/monitor_connection_context_test.cc b/unit_testing/monitor_connection_context_test.cc index 1cf963412..88595c0b2 100644 --- a/unit_testing/monitor_connection_context_test.cc +++ b/unit_testing/monitor_connection_context_test.cc @@ -60,7 +60,7 @@ class MonitorConnectionContextTest : public testing::Test { void SetUp() override { allocate_odbc_handles(env, connection_to_abort, ds); - connection_to_abort->mysql_proxy = new MOCK_MYSQL_PROXY(connection_to_abort, ds); + connection_to_abort->connection_proxy = new MOCK_CONNECTION_PROXY(connection_to_abort, ds); context = new MONITOR_CONNECTION_CONTEXT(connection_to_abort, node_keys, failure_detection_time, diff --git a/unit_testing/monitor_test.cc b/unit_testing/monitor_test.cc index 52e27d8c7..584cc970c 100644 --- a/unit_testing/monitor_test.cc +++ b/unit_testing/monitor_test.cc @@ -62,7 +62,7 @@ class MonitorTest : public testing::Test { DataSource* ds; std::shared_ptr host; std::shared_ptr monitor; - MOCK_MYSQL_PROXY* mock_proxy; + MOCK_CONNECTION_PROXY* mock_proxy; std::shared_ptr mock_connection_handler; std::shared_ptr mock_context_short_interval; std::shared_ptr mock_context_long_interval; @@ -142,7 +142,7 @@ TEST_F(MonitorTest, StopMonitoringTwiceWithSameContext) { } TEST_F(MonitorTest, IsConnectionHealthyWithNoExistingConnection) { - mock_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_connection_handler, connect(host, _)) .WillOnce(Return(mock_proxy)); @@ -156,7 +156,7 @@ TEST_F(MonitorTest, IsConnectionHealthyWithNoExistingConnection) { } TEST_F(MonitorTest, IsConnectionHealthyOrUnhealthy) { - mock_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_connection_handler, connect(host, _)) .WillRepeatedly(Return(mock_proxy)); @@ -179,7 +179,7 @@ TEST_F(MonitorTest, IsConnectionHealthyOrUnhealthy) { } TEST_F(MonitorTest, IsConnectionHealthyAfterFailedConnection) { - mock_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_connection_handler, connect(host, _)) .WillOnce(Return(mock_proxy)); @@ -224,7 +224,7 @@ TEST_F(MonitorTest, RunWithoutContext) { } TEST_F(MonitorTest, RunWithContext) { - auto proxy = new MOCK_MYSQL_PROXY(dbc, ds); + auto proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_connection_handler, connect(host, _)) .WillOnce(Return(proxy)); @@ -275,7 +275,7 @@ TEST_F(MonitorTest, RunWithContext) { // Verify that if 0 timeout is passed in, we should set it to default value TEST_F(MonitorTest, ZeroEFMTimeout) { - auto proxy = new MOCK_MYSQL_PROXY(dbc, ds); + auto proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*proxy, is_connected()).WillRepeatedly(Return(true)); @@ -299,7 +299,7 @@ TEST_F(MonitorTest, ZeroEFMTimeout) { // Verify that if non-zero timeout is passed in, we should set it to that value TEST_F(MonitorTest, NonZeroEFMTimeout) { - auto proxy = new MOCK_MYSQL_PROXY(dbc, ds); + auto proxy = new MOCK_CONNECTION_PROXY(dbc, ds); auto timeout = std::chrono::seconds(1); EXPECT_CALL(*proxy, is_connected()).WillRepeatedly(Return(true)); diff --git a/unit_testing/topology_service_test.cc b/unit_testing/topology_service_test.cc index 3fddab7c9..6db9d5035 100644 --- a/unit_testing/topology_service_test.cc +++ b/unit_testing/topology_service_test.cc @@ -41,7 +41,7 @@ using ::testing::ReturnNew; using ::testing::StrEq; namespace { - MOCK_MYSQL_PROXY* mock_proxy; + MOCK_CONNECTION_PROXY* mock_proxy; TOPOLOGY_SERVICE* ts; std::shared_ptr cluster_instance; @@ -75,7 +75,7 @@ class TopologyServiceTest : public testing::Test { void SetUp() override { allocate_odbc_handles(env, dbc, ds); - mock_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_proxy, store_result()).WillRepeatedly(ReturnNew()); EXPECT_CALL(*mock_proxy, free_result(_)).WillRepeatedly(DeleteArg<0>()); ts->set_refresh_rate(DEFAULT_REFRESH_RATE_IN_MILLISECONDS); From c60846308a0c2b435bb85b4d9c35520c8961cfd0 Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Fri, 17 Mar 2023 15:07:41 -0700 Subject: [PATCH 5/7] rename dummy proxy to mysql proxy --- driver/CMakeLists.txt | 8 +- driver/handle.cc | 4 +- driver/{dummy_proxy.cc => mysql_proxy.cc} | 170 +++++++++++----------- driver/{dummy_proxy.h => mysql_proxy.h} | 14 +- 4 files changed, 98 insertions(+), 98 deletions(-) rename driver/{dummy_proxy.cc => mysql_proxy.cc} (62%) rename driver/{dummy_proxy.h => mysql_proxy.h} (96%) diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt index 9ce046b57..6f45719ee 100644 --- a/driver/CMakeLists.txt +++ b/driver/CMakeLists.txt @@ -60,11 +60,11 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT}) base_metrics_holder.cc catalog.cc catalog_no_i_s.cc cluster_topology_info.cc cluster_aware_hit_metrics_holder.cc cluster_aware_metrics_container.cc cluster_aware_metrics.cc cluster_aware_time_metrics_holder.cc - connect.cc connection_handler.cc connection_proxy.cc cursor.cc desc.cc dll.cc driver.cc dummy_proxy.cc efm_proxy.cc + connect.cc connection_handler.cc connection_proxy.cc cursor.cc desc.cc dll.cc driver.cc efm_proxy.cc error.cc execute.cc failover_handler.cc failover_reader_handler.cc failover_writer_handler.cc handle.cc host_info.cc info.cc monitor.cc monitor_connection_context.cc monitor_service.cc monitor_thread_container.cc - my_prepared_stmt.cc my_stmt.cc mylog.cc connection_proxy.cc options.cc parse.cc prepare.cc query_parsing.cc + my_prepared_stmt.cc my_stmt.cc mylog.cc mysql_proxy.cc options.cc parse.cc prepare.cc query_parsing.cc results.cc topology_service.cc transact.cc utility.cc) IF(UNICODE) @@ -84,8 +84,8 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT}) SET(DRIVER_SRCS ${DRIVER_SRCS} driver${CONNECTOR_DRIVER_TYPE_SHORT}.def driver${CONNECTOR_DRIVER_TYPE_SHORT}.rc base_metrics_holder.h catalog.h cluster_aware_hit_metrics_holder.h cluster_aware_metrics_container.h cluster_aware_metrics.h cluster_aware_time_metrics_holder.h cluster_topology_info.h connection_handler.h connection_proxy.h - driver.h dummy_proxy.h efm_proxy.h error.h failover.h host_info.h monitor.h monitor_connection_context.h monitor_service.h - monitor_thread_container.h mylog.h myutil.h parse.h query_parsing.h topology_service.h + driver.h efm_proxy.h error.h failover.h host_info.h monitor.h monitor_connection_context.h monitor_service.h + monitor_thread_container.h mylog.h mysql_proxy.h myutil.h parse.h query_parsing.h topology_service.h ../MYODBC_MYSQL.h ../MYODBC_CONF.h ../MYODBC_ODBC.h) ENDIF(WIN32) diff --git a/driver/handle.cc b/driver/handle.cc index 9aa1e80bd..87f8411fd 100644 --- a/driver/handle.cc +++ b/driver/handle.cc @@ -48,7 +48,7 @@ ****************************************************************************/ #include "driver.h" -#include "dummy_proxy.h" +#include "mysql_proxy.h" #include "efm_proxy.h" #include @@ -117,7 +117,7 @@ void DBC::close() // construct a proxy chain, example: iam->efm->mysql void DBC::init_proxy_chain(DataSource* dsrc) { - CONNECTION_PROXY *head = new DUMMY_PROXY(this, dsrc); + CONNECTION_PROXY *head = new MYSQL_PROXY(this, dsrc); if (dsrc->enable_failure_detection) { CONNECTION_PROXY* efm_proxy = new EFM_PROXY(this, dsrc); diff --git a/driver/dummy_proxy.cc b/driver/mysql_proxy.cc similarity index 62% rename from driver/dummy_proxy.cc rename to driver/mysql_proxy.cc index 8d6df8005..042692f8e 100644 --- a/driver/dummy_proxy.cc +++ b/driver/mysql_proxy.cc @@ -27,7 +27,7 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. -#include "dummy_proxy.h" +#include "mysql_proxy.h" #include #include @@ -36,73 +36,73 @@ namespace { const auto SOCKET_CLOSE_DELAY = std::chrono::milliseconds(100); } -DUMMY_PROXY::DUMMY_PROXY(DBC* dbc, DataSource* ds) : CONNECTION_PROXY(dbc, ds) { +MYSQL_PROXY::MYSQL_PROXY(DBC* dbc, DataSource* ds) : CONNECTION_PROXY(dbc, ds) { this->host = get_host_info_from_ds(ds); } -DUMMY_PROXY::~DUMMY_PROXY() { +MYSQL_PROXY::~MYSQL_PROXY() { if (this->mysql) { close(); } } -uint64_t DUMMY_PROXY::num_rows(MYSQL_RES* res) { +uint64_t MYSQL_PROXY::num_rows(MYSQL_RES* res) { return mysql_num_rows(res); } -unsigned int DUMMY_PROXY::num_fields(MYSQL_RES* res) { +unsigned int MYSQL_PROXY::num_fields(MYSQL_RES* res) { return mysql_num_fields(res); } -MYSQL_FIELD* DUMMY_PROXY::fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) { +MYSQL_FIELD* MYSQL_PROXY::fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) { return mysql_fetch_field_direct(res, fieldnr); } -MYSQL_ROW_OFFSET DUMMY_PROXY::row_tell(MYSQL_RES* res) { +MYSQL_ROW_OFFSET MYSQL_PROXY::row_tell(MYSQL_RES* res) { return mysql_row_tell(res); } -unsigned int DUMMY_PROXY::field_count() { +unsigned int MYSQL_PROXY::field_count() { return mysql_field_count(mysql); } -uint64_t DUMMY_PROXY::affected_rows() { +uint64_t MYSQL_PROXY::affected_rows() { return mysql_affected_rows(mysql); } -unsigned int DUMMY_PROXY::error_code() { +unsigned int MYSQL_PROXY::error_code() { return mysql_errno(mysql); } -const char* DUMMY_PROXY::error() { +const char* MYSQL_PROXY::error() { return mysql_error(mysql); } -const char* DUMMY_PROXY::sqlstate() { +const char* MYSQL_PROXY::sqlstate() { return mysql_sqlstate(mysql); } -unsigned long DUMMY_PROXY::thread_id() { +unsigned long MYSQL_PROXY::thread_id() { return mysql_thread_id(mysql); } -int DUMMY_PROXY::set_character_set(const char* csname) { +int MYSQL_PROXY::set_character_set(const char* csname) { return mysql_set_character_set(mysql, csname); } -void DUMMY_PROXY::init() { +void MYSQL_PROXY::init() { this->mysql = mysql_init(nullptr); } -bool DUMMY_PROXY::ssl_set(const char* key, const char* cert, const char* ca, const char* capath, const char* cipher) { +bool MYSQL_PROXY::ssl_set(const char* key, const char* cert, const char* ca, const char* capath, const char* cipher) { return mysql_ssl_set(mysql, key, cert, ca, capath, cipher); } -bool DUMMY_PROXY::change_user(const char* user, const char* passwd, const char* db) { +bool MYSQL_PROXY::change_user(const char* user, const char* passwd, const char* db) { return mysql_change_user(mysql, user, passwd, db); } -bool DUMMY_PROXY::real_connect( +bool MYSQL_PROXY::real_connect( const char* host, const char* user, const char* passwd, const char* db, unsigned int port, const char* unix_socket, unsigned long clientflag) { @@ -111,52 +111,52 @@ bool DUMMY_PROXY::real_connect( return new_mysql != nullptr; } -int DUMMY_PROXY::select_db(const char* db) { +int MYSQL_PROXY::select_db(const char* db) { return mysql_select_db(mysql, db); } -int DUMMY_PROXY::query(const char* q) { +int MYSQL_PROXY::query(const char* q) { return mysql_query(mysql, q); } -int DUMMY_PROXY::real_query(const char* q, unsigned long length) { +int MYSQL_PROXY::real_query(const char* q, unsigned long length) { return mysql_real_query(mysql, q, length); } -MYSQL_RES* DUMMY_PROXY::store_result() { +MYSQL_RES* MYSQL_PROXY::store_result() { return mysql_store_result(mysql); } -MYSQL_RES* DUMMY_PROXY::use_result() { +MYSQL_RES* MYSQL_PROXY::use_result() { return mysql_use_result(mysql); } -struct CHARSET_INFO* DUMMY_PROXY::get_character_set() const { +struct CHARSET_INFO* MYSQL_PROXY::get_character_set() const { return this->mysql->charset; } -void DUMMY_PROXY::get_character_set_info(MY_CHARSET_INFO* charset) { +void MYSQL_PROXY::get_character_set_info(MY_CHARSET_INFO* charset) { mysql_get_character_set_info(mysql, charset); } -bool DUMMY_PROXY::autocommit(bool auto_mode) { +bool MYSQL_PROXY::autocommit(bool auto_mode) { return mysql_autocommit(mysql, auto_mode); } -int DUMMY_PROXY::next_result() { +int MYSQL_PROXY::next_result() { return mysql_next_result(mysql); } -int DUMMY_PROXY::stmt_next_result(MYSQL_STMT* stmt) { +int MYSQL_PROXY::stmt_next_result(MYSQL_STMT* stmt) { return mysql_stmt_next_result(stmt); } -void DUMMY_PROXY::close() { +void MYSQL_PROXY::close() { mysql_close(mysql); mysql = nullptr; } -bool DUMMY_PROXY::real_connect_dns_srv( +bool MYSQL_PROXY::real_connect_dns_srv( const char* dns_srv_name, const char* user, const char* passwd, const char* db, unsigned long client_flag) { @@ -164,226 +164,226 @@ bool DUMMY_PROXY::real_connect_dns_srv( return new_mysql != nullptr; } -int DUMMY_PROXY::ping() { +int MYSQL_PROXY::ping() { return mysql_ping(mysql); } -int DUMMY_PROXY::get_option(mysql_option option, const void* arg) { +int MYSQL_PROXY::get_option(mysql_option option, const void* arg) { return mysql_get_option(mysql, option, arg); } -int DUMMY_PROXY::options4(mysql_option option, const void* arg1, const void* arg2) { +int MYSQL_PROXY::options4(mysql_option option, const void* arg1, const void* arg2) { return mysql_options4(mysql, option, arg1, arg2); } -int DUMMY_PROXY::options(mysql_option option, const void* arg) { +int MYSQL_PROXY::options(mysql_option option, const void* arg) { return mysql_options(mysql, option, arg); } -void DUMMY_PROXY::free_result(MYSQL_RES* result) { +void MYSQL_PROXY::free_result(MYSQL_RES* result) { mysql_free_result(result); } -void DUMMY_PROXY::data_seek(MYSQL_RES* result, uint64_t offset) { +void MYSQL_PROXY::data_seek(MYSQL_RES* result, uint64_t offset) { mysql_data_seek(result, offset); } -MYSQL_ROW_OFFSET DUMMY_PROXY::row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) { +MYSQL_ROW_OFFSET MYSQL_PROXY::row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) { return mysql_row_seek(result, offset); } -MYSQL_FIELD_OFFSET DUMMY_PROXY::field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) { +MYSQL_FIELD_OFFSET MYSQL_PROXY::field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) { return mysql_field_seek(result, offset); } -MYSQL_ROW DUMMY_PROXY::fetch_row(MYSQL_RES* result) { +MYSQL_ROW MYSQL_PROXY::fetch_row(MYSQL_RES* result) { return mysql_fetch_row(result); } -unsigned long* DUMMY_PROXY::fetch_lengths(MYSQL_RES* result) { +unsigned long* MYSQL_PROXY::fetch_lengths(MYSQL_RES* result) { return mysql_fetch_lengths(result); } -MYSQL_FIELD* DUMMY_PROXY::fetch_field(MYSQL_RES* result) { +MYSQL_FIELD* MYSQL_PROXY::fetch_field(MYSQL_RES* result) { return mysql_fetch_field(result); } -MYSQL_RES* DUMMY_PROXY::list_fields(const char* table, const char* wild) { +MYSQL_RES* MYSQL_PROXY::list_fields(const char* table, const char* wild) { return mysql_list_fields(mysql, table, wild); } -unsigned long DUMMY_PROXY::real_escape_string(char* to, const char* from, unsigned long length) { +unsigned long MYSQL_PROXY::real_escape_string(char* to, const char* from, unsigned long length) { return mysql_real_escape_string(mysql, to, from, length); } -bool DUMMY_PROXY::bind_param(unsigned n_params, MYSQL_BIND* binds, const char** names) { +bool MYSQL_PROXY::bind_param(unsigned n_params, MYSQL_BIND* binds, const char** names) { return mysql_bind_param(mysql, n_params, binds, names); } -MYSQL_STMT* DUMMY_PROXY::stmt_init() { +MYSQL_STMT* MYSQL_PROXY::stmt_init() { return mysql_stmt_init(mysql); } -int DUMMY_PROXY::stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length) { +int MYSQL_PROXY::stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length) { return mysql_stmt_prepare(stmt, query, length); } -int DUMMY_PROXY::stmt_execute(MYSQL_STMT* stmt) { +int MYSQL_PROXY::stmt_execute(MYSQL_STMT* stmt) { return mysql_stmt_execute(stmt); } -int DUMMY_PROXY::stmt_fetch(MYSQL_STMT* stmt) { +int MYSQL_PROXY::stmt_fetch(MYSQL_STMT* stmt) { return mysql_stmt_fetch(stmt); } -int DUMMY_PROXY::stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, unsigned int column, unsigned long offset) { +int MYSQL_PROXY::stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, unsigned int column, unsigned long offset) { return mysql_stmt_fetch_column(stmt, bind_arg, column, offset); } -int DUMMY_PROXY::stmt_store_result(MYSQL_STMT* stmt) { +int MYSQL_PROXY::stmt_store_result(MYSQL_STMT* stmt) { return mysql_stmt_store_result(stmt); } -unsigned long DUMMY_PROXY::stmt_param_count(MYSQL_STMT* stmt) { +unsigned long MYSQL_PROXY::stmt_param_count(MYSQL_STMT* stmt) { return mysql_stmt_param_count(stmt); } -bool DUMMY_PROXY::stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { +bool MYSQL_PROXY::stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { return mysql_stmt_bind_param(stmt, bnd); } -bool DUMMY_PROXY::stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { +bool MYSQL_PROXY::stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { return mysql_stmt_bind_result(stmt, bnd); } -bool DUMMY_PROXY::stmt_close(MYSQL_STMT* stmt) { +bool MYSQL_PROXY::stmt_close(MYSQL_STMT* stmt) { return mysql_stmt_close(stmt); } -bool DUMMY_PROXY::stmt_reset(MYSQL_STMT* stmt) { +bool MYSQL_PROXY::stmt_reset(MYSQL_STMT* stmt) { return mysql_stmt_reset(stmt); } -bool DUMMY_PROXY::stmt_free_result(MYSQL_STMT* stmt) { +bool MYSQL_PROXY::stmt_free_result(MYSQL_STMT* stmt) { return mysql_stmt_free_result(stmt); } -bool DUMMY_PROXY::stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, const char* data, +bool MYSQL_PROXY::stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, const char* data, unsigned long length) { return mysql_stmt_send_long_data(stmt, param_number, data, length); } -MYSQL_RES* DUMMY_PROXY::stmt_result_metadata(MYSQL_STMT* stmt) { +MYSQL_RES* MYSQL_PROXY::stmt_result_metadata(MYSQL_STMT* stmt) { return mysql_stmt_result_metadata(stmt); } -unsigned int DUMMY_PROXY::stmt_errno(MYSQL_STMT* stmt) { +unsigned int MYSQL_PROXY::stmt_errno(MYSQL_STMT* stmt) { return mysql_stmt_errno(stmt); } -const char* DUMMY_PROXY::stmt_error(MYSQL_STMT* stmt) { +const char* MYSQL_PROXY::stmt_error(MYSQL_STMT* stmt) { return mysql_stmt_error(stmt); } -MYSQL_ROW_OFFSET DUMMY_PROXY::stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) { +MYSQL_ROW_OFFSET MYSQL_PROXY::stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) { return mysql_stmt_row_seek(stmt, offset); } -MYSQL_ROW_OFFSET DUMMY_PROXY::stmt_row_tell(MYSQL_STMT* stmt) { +MYSQL_ROW_OFFSET MYSQL_PROXY::stmt_row_tell(MYSQL_STMT* stmt) { return mysql_stmt_row_tell(stmt); } -void DUMMY_PROXY::stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) { +void MYSQL_PROXY::stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) { mysql_stmt_data_seek(stmt, offset); } -uint64_t DUMMY_PROXY::stmt_num_rows(MYSQL_STMT* stmt) { +uint64_t MYSQL_PROXY::stmt_num_rows(MYSQL_STMT* stmt) { return mysql_stmt_num_rows(stmt); } -uint64_t DUMMY_PROXY::stmt_affected_rows(MYSQL_STMT* stmt) { +uint64_t MYSQL_PROXY::stmt_affected_rows(MYSQL_STMT* stmt) { return mysql_stmt_affected_rows(stmt); } -unsigned int DUMMY_PROXY::stmt_field_count(MYSQL_STMT* stmt) { +unsigned int MYSQL_PROXY::stmt_field_count(MYSQL_STMT* stmt) { return mysql_stmt_field_count(stmt); } -st_mysql_client_plugin* DUMMY_PROXY::client_find_plugin(const char* name, int type) { +st_mysql_client_plugin* MYSQL_PROXY::client_find_plugin(const char* name, int type) { return mysql_client_find_plugin(mysql, name, type); } -bool DUMMY_PROXY::is_connected() { +bool MYSQL_PROXY::is_connected() { return this->mysql != nullptr && this->mysql->net.vio; } -void DUMMY_PROXY::set_last_error_code(unsigned int error_code) { +void MYSQL_PROXY::set_last_error_code(unsigned int error_code) { this->mysql->net.last_errno = error_code; } -char* DUMMY_PROXY::get_last_error() const { +char* MYSQL_PROXY::get_last_error() const { return this->mysql->net.last_error; } -unsigned int DUMMY_PROXY::get_last_error_code() const { +unsigned int MYSQL_PROXY::get_last_error_code() const { return this->mysql->net.last_errno; } -char* DUMMY_PROXY::get_sqlstate() const { +char* MYSQL_PROXY::get_sqlstate() const { return this->mysql->net.sqlstate; } -char* DUMMY_PROXY::get_server_version() const { +char* MYSQL_PROXY::get_server_version() const { return this->mysql->server_version; } -uint64_t DUMMY_PROXY::get_affected_rows() const { +uint64_t MYSQL_PROXY::get_affected_rows() const { return this->mysql->affected_rows; } -void DUMMY_PROXY::set_affected_rows(uint64_t num_rows) { +void MYSQL_PROXY::set_affected_rows(uint64_t num_rows) { this->mysql->affected_rows = num_rows; } -char* DUMMY_PROXY::get_host_info() const { +char* MYSQL_PROXY::get_host_info() const { return this->mysql->host_info; } -std::string DUMMY_PROXY::get_host() { +std::string MYSQL_PROXY::get_host() { return (this->mysql && this->mysql->host) ? this->mysql->host : this->host->get_host(); } -unsigned int DUMMY_PROXY::get_port() { +unsigned int MYSQL_PROXY::get_port() { return (this->mysql) ? this->mysql->port : this->host->get_port(); } -unsigned long DUMMY_PROXY::get_max_packet() const { +unsigned long MYSQL_PROXY::get_max_packet() const { return this->mysql->net.max_packet; } -unsigned long DUMMY_PROXY::get_server_capabilities() const { +unsigned long MYSQL_PROXY::get_server_capabilities() const { return this->mysql->server_capabilities; } -unsigned int DUMMY_PROXY::get_server_status() const { +unsigned int MYSQL_PROXY::get_server_status() const { return this->mysql->server_status; } -void DUMMY_PROXY::delete_ds() { +void MYSQL_PROXY::delete_ds() { if (ds) { ds_delete(ds); ds = nullptr; } } -MYSQL* DUMMY_PROXY::move_mysql_connection() { +MYSQL* MYSQL_PROXY::move_mysql_connection() { MYSQL* ret = this->mysql; this->mysql = nullptr; return ret; } -void DUMMY_PROXY::set_connection(CONNECTION_PROXY* connection_proxy) { +void MYSQL_PROXY::set_connection(CONNECTION_PROXY* connection_proxy) { close(); this->mysql = connection_proxy->move_mysql_connection(); // delete the ds initialized in CONNECTION_HANDLER::clone_dbc() @@ -391,7 +391,7 @@ void DUMMY_PROXY::set_connection(CONNECTION_PROXY* connection_proxy) { delete connection_proxy; } -void DUMMY_PROXY::close_socket() { +void MYSQL_PROXY::close_socket() { MYLOG_DBC_TRACE(dbc, "Closing socket"); int ret = 0; if (mysql->net.fd != INVALID_SOCKET && (ret = shutdown(mysql->net.fd, SHUT_RDWR))) { diff --git a/driver/dummy_proxy.h b/driver/mysql_proxy.h similarity index 96% rename from driver/dummy_proxy.h rename to driver/mysql_proxy.h index 472eaffa0..37fef3638 100644 --- a/driver/dummy_proxy.h +++ b/driver/mysql_proxy.h @@ -27,17 +27,17 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. -#ifndef __DUMMY_PROXY__ -#define __DUMMY_PROXY__ +#ifndef __MYSQL_PROXY__ +#define __MYSQL_PROXY__ #include "driver.h" #include "host_info.h" #include "connection_proxy.h" -class DUMMY_PROXY : public CONNECTION_PROXY { +class MYSQL_PROXY : public CONNECTION_PROXY { public: - DUMMY_PROXY(DBC* dbc, DataSource* ds); - ~DUMMY_PROXY() override; + MYSQL_PROXY(DBC* dbc, DataSource* ds); + ~MYSQL_PROXY() override; uint64_t num_rows(MYSQL_RES* res) override; unsigned int num_fields(MYSQL_RES* res) override; @@ -163,7 +163,7 @@ class DUMMY_PROXY : public CONNECTION_PROXY { protected: DBC* dbc = nullptr; DataSource* ds = nullptr; - DUMMY_PROXY* next_proxy = nullptr; + MYSQL_PROXY* next_proxy = nullptr; private: MYSQL* mysql = nullptr; @@ -171,4 +171,4 @@ class DUMMY_PROXY : public CONNECTION_PROXY { }; -#endif /* __DUMMY_PROXY__ */ +#endif /* __MYSQL_PROXY__ */ From d0a70a0339af228397bf9cb972708951a25ed33a Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Fri, 17 Mar 2023 15:32:21 -0700 Subject: [PATCH 6/7] remove secrets manager proxy as it should be a different PR --- driver/driver.h | 2 +- driver/secrets_manager_proxy.cc | 80 --------------- driver/secrets_manager_proxy.h | 173 -------------------------------- 3 files changed, 1 insertion(+), 254 deletions(-) delete mode 100644 driver/secrets_manager_proxy.cc delete mode 100644 driver/secrets_manager_proxy.h diff --git a/driver/driver.h b/driver/driver.h index 3d3e8aca0..0ec145fd1 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -613,7 +613,7 @@ static std::atomic_ulong last_dbc_id{1}; struct DBC { ENV *env; - CONNECTION_PROXY *connection_proxy; + CONNECTION_PROXY *connection_proxy; std::list stmt_list; std::list desc_list; // Explicit descriptors STMT_OPTIONS stmt_options; diff --git a/driver/secrets_manager_proxy.cc b/driver/secrets_manager_proxy.cc deleted file mode 100644 index 75c96facd..000000000 --- a/driver/secrets_manager_proxy.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License, version 2.0 -// (GPLv2), as published by the Free Software Foundation, with the -// following additional permissions: -// -// This program is distributed with certain software that is licensed -// under separate terms, as designated in a particular file or component -// or in the license documentation. Without limiting your rights under -// the GPLv2, the authors of this program hereby grant you an additional -// permission to link the program and your derivative works with the -// separately licensed software that they have included with the program. -// -// Without limiting the foregoing grant of rights under the GPLv2 and -// additional permission as to separately licensed software, this -// program is also subject to the Universal FOSS Exception, version 1.0, -// a copy of which can be found along with its FAQ at -// http://oss.oracle.com/licenses/universal-foss-exception. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License, version 2.0, for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see -// http://www.gnu.org/licenses/gpl-2.0.html. - -#include -#include - -#include "secrets_manager_proxy.h" - -#include "installer.h" - -using namespace Aws::SecretsManager; - -SECRETS_MANAGER_PROXY::SECRETS_MANAGER_PROXY(DBC* dbc, DataSource* ds) : SECRETS_MANAGER_PROXY( - dbc, ds, nullptr) {} - - -SECRETS_MANAGER_PROXY::SECRETS_MANAGER_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy) : CONNECTION_PROXY(dbc, ds) { - Aws::InitAPI(this->SDK_options); - - Aws::Client::ClientConfiguration config; - const char* region = ds_get_utf8attr(ds->auth_region, &ds->auth_region8); - config.region = region ? region : "us-east-1"; - - this->sm_client = SecretsManagerClient(config); - - const Aws::String secret_ID = ds_get_utf8attr(ds->auth_secret_id, &ds->auth_secret_id8); - - Model::GetSecretValueRequest request; - request.SetSecretId(secret_ID); - - auto getSecretValueOutcome = this->sm_client.GetSecretValue(request); - if (getSecretValueOutcome.IsSuccess()) { - std::cout << "Secret is: " << getSecretValueOutcome.GetResult().GetSecretString() << std::endl; - } - else { - std::cout << "Failed with Error: " << getSecretValueOutcome.GetError() << std::endl; - } - - this->next_proxy = next_proxy; -} - -SECRETS_MANAGER_PROXY::~SECRETS_MANAGER_PROXY() { - Aws::ShutdownAPI(this->SDK_options); -} - -bool SECRETS_MANAGER_PROXY::real_connect(const char* host, const char* user, const char* passwd, const char* db, unsigned int port, const char* unix_socket, unsigned long clientflag) { - - const bool ret = next_proxy->real_connect(host, user, passwd, db, port, unix_socket, clientflag); - return ret; -} - -void SECRETS_MANAGER_PROXY::set_next_proxy(CONNECTION_PROXY* next_proxy) { - CONNECTION_PROXY::set_next_proxy(next_proxy); -} diff --git a/driver/secrets_manager_proxy.h b/driver/secrets_manager_proxy.h deleted file mode 100644 index 6b13818b2..000000000 --- a/driver/secrets_manager_proxy.h +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License, version 2.0 -// (GPLv2), as published by the Free Software Foundation, with the -// following additional permissions: -// -// This program is distributed with certain software that is licensed -// under separate terms, as designated in a particular file or component -// or in the license documentation. Without limiting your rights under -// the GPLv2, the authors of this program hereby grant you an additional -// permission to link the program and your derivative works with the -// separately licensed software that they have included with the program. -// -// Without limiting the foregoing grant of rights under the GPLv2 and -// additional permission as to separately licensed software, this -// program is also subject to the Universal FOSS Exception, version 1.0, -// a copy of which can be found along with its FAQ at -// http://oss.oracle.com/licenses/universal-foss-exception. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License, version 2.0, for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see -// http://www.gnu.org/licenses/gpl-2.0.html. - -#ifndef __SECRETS_MANAGER_PROXY__ -#define __SECRETS_MANAGER_PROXY__ - -#include -#include - -#include - -#include "connection_proxy.h" - -class SECRETS_MANAGER_PROXY : public CONNECTION_PROXY { - public: - SECRETS_MANAGER_PROXY(DBC* dbc, DataSource* ds); - SECRETS_MANAGER_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy); - ~SECRETS_MANAGER_PROXY(); - - void delete_ds() override; - uint64_t num_rows(MYSQL_RES* res) override; - unsigned int num_fields(MYSQL_RES* res) override; - MYSQL_FIELD* fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) override; - MYSQL_ROW_OFFSET row_tell(MYSQL_RES* res) override; - - unsigned int field_count() override; - uint64_t affected_rows() override; - unsigned int error_code() override; - const char* error() override; - const char* sqlstate() override; - unsigned long thread_id() override; - int set_character_set(const char* csname) override; - - void init() override; - bool ssl_set(const char* key, const char* cert, const char* ca, - const char* capath, const char* cipher) override; - bool change_user(const char* user, const char* passwd, - const char* db) override; - bool real_connect(const char* host, const char* user, - const char* passwd, const char* db, unsigned int port, - const char* unix_socket, unsigned long clientflag) override; - int select_db(const char* db) override; - int query(const char* q) override; - int real_query(const char* q, unsigned long length) override; - MYSQL_RES* store_result() override; - MYSQL_RES* use_result() override; - struct CHARSET_INFO* get_character_set() const override; - void get_character_set_info(MY_CHARSET_INFO* charset) override; - - int ping() override; - int options(enum mysql_option option, const void* arg) override; - int options4(enum mysql_option option, const void* arg1, - const void* arg2) override; - int get_option(enum mysql_option option, const void* arg) override; - void free_result(MYSQL_RES* result) override; - void data_seek(MYSQL_RES* result, uint64_t offset) override; - MYSQL_ROW_OFFSET row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) override; - MYSQL_FIELD_OFFSET field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) override; - MYSQL_ROW fetch_row(MYSQL_RES* result) override; - - unsigned long* fetch_lengths(MYSQL_RES* result) override; - MYSQL_FIELD* fetch_field(MYSQL_RES* result) override; - MYSQL_RES* list_fields(const char* table, const char* wild) override; - unsigned long real_escape_string(char* to, const char* from, - unsigned long length) override; - - bool bind_param(unsigned n_params, MYSQL_BIND* binds, - const char** names) override; - - MYSQL_STMT* stmt_init() override; - int stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length) override; - int stmt_execute(MYSQL_STMT* stmt) override; - int stmt_fetch(MYSQL_STMT* stmt) override; - int stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, - unsigned int column, unsigned long offset) override; - int stmt_store_result(MYSQL_STMT* stmt) override; - unsigned long stmt_param_count(MYSQL_STMT* stmt) override; - bool stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; - bool stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; - bool stmt_close(MYSQL_STMT* stmt) override; - bool stmt_reset(MYSQL_STMT* stmt) override; - bool stmt_free_result(MYSQL_STMT* stmt) override; - bool stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, - const char* data, unsigned long length) override; - MYSQL_RES* stmt_result_metadata(MYSQL_STMT* stmt) override; - unsigned int stmt_errno(MYSQL_STMT* stmt) override; - const char* stmt_error(MYSQL_STMT* stmt) override; - MYSQL_ROW_OFFSET stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) override; - MYSQL_ROW_OFFSET stmt_row_tell(MYSQL_STMT* stmt) override; - void stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) override; - uint64_t stmt_num_rows(MYSQL_STMT* stmt) override; - uint64_t stmt_affected_rows(MYSQL_STMT* stmt) override; - unsigned int stmt_field_count(MYSQL_STMT* stmt) override; - - bool autocommit(bool auto_mode) override; - int next_result() override; - int stmt_next_result(MYSQL_STMT* stmt) override; - void close() override; - - bool real_connect_dns_srv(const char* dns_srv_name, - const char* user, const char* passwd, - const char* db, unsigned long client_flag) override; - struct st_mysql_client_plugin* client_find_plugin( - const char* name, int type) override; - - bool is_connected() override; - - void set_last_error_code(unsigned int error_code) override; - - char* get_last_error() const override; - - unsigned int get_last_error_code() const override; - - char* get_sqlstate() const override; - - char* get_server_version() const override; - - uint64_t get_affected_rows() const override; - - void set_affected_rows(uint64_t num_rows) override; - - char* get_host_info() const override; - - std::string get_host() override; - - unsigned int get_port() override; - - unsigned long get_max_packet() const override; - - unsigned long get_server_capabilities() const override; - - unsigned int get_server_status() const override; - - void set_connection(CONNECTION_PROXY* connection_proxy) override; - - void close_socket() override; - - void set_next_proxy(CONNECTION_PROXY* next_proxy) override; - -private: - Aws::SecretsManager::SecretsManagerClient sm_client; - Aws::SDKOptions SDK_options; - - Aws::String fetch_latest_credentials(); -}; - -#endif /* __SECRETS_MANAGER_PROXY__ */ From 1c46ecdd3d03c027abe9e74c8c38c98198e3904b Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Fri, 17 Mar 2023 16:45:46 -0700 Subject: [PATCH 7/7] include in alphabetical order --- driver/connection_handler.cc | 2 +- driver/connection_proxy.h | 2 ++ driver/driver.h | 2 +- driver/efm_proxy.cc | 2 +- driver/efm_proxy.h | 2 +- driver/failover.h | 2 +- driver/handle.cc | 2 +- driver/monitor.cc | 2 +- driver/mysql_proxy.h | 2 +- 9 files changed, 10 insertions(+), 8 deletions(-) diff --git a/driver/connection_handler.cc b/driver/connection_handler.cc index b0b7497ed..d934b9f0c 100644 --- a/driver/connection_handler.cc +++ b/driver/connection_handler.cc @@ -33,8 +33,8 @@ */ #include "connection_handler.h" -#include "driver.h" #include "connection_proxy.h" +#include "driver.h" #include #include diff --git a/driver/connection_proxy.h b/driver/connection_proxy.h index 5c8b268b3..b12160548 100644 --- a/driver/connection_proxy.h +++ b/driver/connection_proxy.h @@ -30,6 +30,8 @@ #ifndef __CONNECTION_PROXY__ #define __CONNECTION_PROXY__ +#include "MYODBC_MYSQL.h" + struct DBC; struct DataSource; diff --git a/driver/driver.h b/driver/driver.h index 0ec145fd1..d25adb780 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -44,8 +44,8 @@ #include "util/installer.h" #include "connection_handler.h" -#include "failover.h" #include "connection_proxy.h" +#include "failover.h" /* Disable _attribute__ on non-gcc compilers. */ #if !defined(__attribute__) && !defined(__GNUC__) diff --git a/driver/efm_proxy.cc b/driver/efm_proxy.cc index f52c2e399..6fa4a8132 100644 --- a/driver/efm_proxy.cc +++ b/driver/efm_proxy.cc @@ -109,7 +109,7 @@ void EFM_PROXY::set_next_proxy(CONNECTION_PROXY* next_proxy) { } void EFM_PROXY::set_connection(CONNECTION_PROXY* connection_proxy) { - next_proxy->set_connection(connection_proxy); + CONNECTION_PROXY::set_connection(connection_proxy); if (monitor_service != nullptr && !node_keys.empty()) { monitor_service->stop_monitoring_for_all_connections(node_keys); diff --git a/driver/efm_proxy.h b/driver/efm_proxy.h index 265aec6a4..4cdba86ad 100644 --- a/driver/efm_proxy.h +++ b/driver/efm_proxy.h @@ -30,9 +30,9 @@ #ifndef __EFM_PROXY__ #define __EFM_PROXY__ +#include "connection_proxy.h" #include "driver.h" #include "monitor_service.h" -#include "connection_proxy.h" class EFM_PROXY : public CONNECTION_PROXY { public: diff --git a/driver/failover.h b/driver/failover.h index 6e4d895c1..032a02b56 100644 --- a/driver/failover.h +++ b/driver/failover.h @@ -31,9 +31,9 @@ #define __FAILOVER_H__ #include "connection_handler.h" +#include "connection_proxy.h" #include "topology_service.h" #include "mylog.h" -#include "connection_proxy.h" #include diff --git a/driver/handle.cc b/driver/handle.cc index 87f8411fd..aae776416 100644 --- a/driver/handle.cc +++ b/driver/handle.cc @@ -48,8 +48,8 @@ ****************************************************************************/ #include "driver.h" -#include "mysql_proxy.h" #include "efm_proxy.h" +#include "mysql_proxy.h" #include diff --git a/driver/monitor.cc b/driver/monitor.cc index 3ee553087..eac8cef25 100644 --- a/driver/monitor.cc +++ b/driver/monitor.cc @@ -31,9 +31,9 @@ #include "driver.h" #include "monitor.h" +#include "connection_proxy.h" #include "monitor_service.h" #include "mylog.h" -#include "connection_proxy.h" MONITOR::MONITOR( std::shared_ptr host_info, diff --git a/driver/mysql_proxy.h b/driver/mysql_proxy.h index 37fef3638..06df35d92 100644 --- a/driver/mysql_proxy.h +++ b/driver/mysql_proxy.h @@ -30,9 +30,9 @@ #ifndef __MYSQL_PROXY__ #define __MYSQL_PROXY__ +#include "connection_proxy.h" #include "driver.h" #include "host_info.h" -#include "connection_proxy.h" class MYSQL_PROXY : public CONNECTION_PROXY { public: