diff --git a/driver/custom_endpoint_monitor.cc b/driver/custom_endpoint_monitor.cc index f655939fe..f715aa27d 100644 --- a/driver/custom_endpoint_monitor.cc +++ b/driver/custom_endpoint_monitor.cc @@ -93,11 +93,11 @@ bool CUSTOM_ENDPOINT_MONITOR::has_custom_endpoint_info() const { } void CUSTOM_ENDPOINT_MONITOR::run() { - MYLOG_TRACE(this->logger, 0, "Starting custom endpoint monitor for '%s'", this->custom_endpoint_host.c_str()); if (thread_pool.size() == 1) { // Each monitor should only have 1 thread. return; } + MYLOG_TRACE(this->logger, 0, "Starting custom endpoint monitor for '%s'", this->custom_endpoint_host.c_str()); thread_pool.resize(1); thread_pool.push([=](int id) { ++SDK_HELPER; diff --git a/driver/failover_handler.cc b/driver/failover_handler.cc index 821973678..fbb705e75 100644 --- a/driver/failover_handler.cc +++ b/driver/failover_handler.cc @@ -511,7 +511,7 @@ bool FAILOVER_HANDLER::failover_to_reader(const char*& new_error_code, const cha if (result->connected) { current_host = result->new_host; connection_handler->update_connection(result->new_connection, current_host->get_host()); - new_error_code = "08S02"; + new_error_code = "08S02"; // Failover succeeded error code. error_msg = "The active SQL connection has changed."; MYLOG_DBC_TRACE(dbc, "[FAILOVER_HANDLER] The active SQL connection has changed " @@ -520,7 +520,7 @@ bool FAILOVER_HANDLER::failover_to_reader(const char*& new_error_code, const cha return true; } else { MYLOG_DBC_TRACE(dbc, "[FAILOVER_HANDLER] Unable to establish SQL connection to reader node."); - new_error_code = "08S01"; + new_error_code = "08S01"; // Failover failed error code. error_msg = "The active SQL connection was lost."; return false; } @@ -549,7 +549,7 @@ bool FAILOVER_HANDLER::failover_to_writer(const char*& new_error_code, const cha const auto filtered_topology = this->topology_service->get_filtered_topology(new_topology); const auto allowed_hosts = filtered_topology->get_instances(); if (std::find(allowed_hosts.begin(), allowed_hosts.end(), new_host) == allowed_hosts.end()) { - new_error_code = "08S01"; + new_error_code = "08S01"; // Failover failed error code. error_msg = "The active SQL connection was lost."; MYLOG_DBC_TRACE( dbc, @@ -562,7 +562,7 @@ bool FAILOVER_HANDLER::failover_to_writer(const char*& new_error_code, const cha connection_handler->update_connection(result->new_connection, new_host->get_host()); - new_error_code = "08S02"; + new_error_code = "08S02"; // Failover succeeded error code. error_msg = "The active SQL connection has changed."; MYLOG_DBC_TRACE( dbc, diff --git a/driver/host_info.cc b/driver/host_info.cc index 139a5ad29..cf8d1d138 100644 --- a/driver/host_info.cc +++ b/driver/host_info.cc @@ -56,8 +56,6 @@ HOST_INFO::HOST_INFO(const char* host, int port, HOST_STATE state, bool is_write HOST_INFO::~HOST_INFO() {} /** - * Returns the host endpoint. - * * @return the host endpoint */ std::string HOST_INFO::get_host() { @@ -65,15 +63,11 @@ std::string HOST_INFO::get_host() { } /** - * Returns the host name. - * * @return the host name */ std::string HOST_INFO::get_host_id() { return host_id; } /** - * Returns the port. - * * @return the port */ int HOST_INFO::get_port() { @@ -81,8 +75,6 @@ int HOST_INFO::get_port() { } /** - * Returns a host:port representation of this host. - * * @return the host:port representation of this host */ std::string HOST_INFO::get_host_port_pair() { diff --git a/driver/host_info.h b/driver/host_info.h index 7fd64c1ad..2944d3ec1 100644 --- a/driver/host_info.h +++ b/driver/host_info.h @@ -80,8 +80,8 @@ class HOST_INFO { inline std::ostream& operator<<(std::ostream& str, HOST_INFO v) { char buf[1024]; - sprintf(buf, "HostSpec[host=%s, port=%d, %s, %s]", v.get_host().c_str(), v.get_port(), - v.is_host_writer() ? "WRITER" : "READER", v.last_updated.c_str()); + sprintf(buf, "HostSpec[host=%s, port=%d, %s, %s]", v.get_host(), v.get_port(), + v.is_host_writer() ? "WRITER" : "READER", v.last_updated); return str << std::string(buf); } diff --git a/driver/topology_service.cc b/driver/topology_service.cc index fb99c6465..72113a10e 100644 --- a/driver/topology_service.cc +++ b/driver/topology_service.cc @@ -191,21 +191,13 @@ std::shared_ptr TOPOLOGY_SERVICE::get_filtered_topology(s std::set blocked_list = this->allowed_and_blocked_hosts->get_blocked_host_ids(); const std::shared_ptr filtered_topology = std::make_shared(); - if (allowed_list.size() > 0) { - for (const auto& host : topology->get_instances()) { - if (allowed_list.find(host->get_host_id()) != allowed_list.end()) { - filtered_topology->add_host(host); - } + for (const auto& host : topology->get_instances()) { + if (allowed_list.find(host->get_host_id()) != allowed_list.end() + || blocked_list.find(host->get_host_id()) == blocked_list.end()) { + filtered_topology->add_host(host); } } - if (blocked_list.size() > 0) { - for (const auto& host : topology->get_instances()) { - if (blocked_list.find(host->get_host_id()) == blocked_list.end()) { - filtered_topology->add_host(host); - } - } - } return filtered_topology; } diff --git a/integration/connection_string_builder.h b/integration/connection_string_builder.h index 919442583..492e9e521 100644 --- a/integration/connection_string_builder.h +++ b/integration/connection_string_builder.h @@ -205,4 +205,4 @@ class ConnectionStringBuilder { int length = 0; }; -#endif /* __CONNECTIONSTRINGBUILDER_H__ */ \ No newline at end of file +#endif /* __CONNECTIONSTRINGBUILDER_H__ */ diff --git a/integration/custom_endpoint_integration_test.cc b/integration/custom_endpoint_integration_test.cc index c3585f8e9..f2202cfc2 100644 --- a/integration/custom_endpoint_integration_test.cc +++ b/integration/custom_endpoint_integration_test.cc @@ -52,9 +52,13 @@ class CustomEndpointIntegrationTest : public BaseFailoverIntegrationTest { static void TearDownTestSuite() { Aws::ShutdownAPI(options); } void SetUp() override { - SQLAllocHandle(SQL_HANDLE_ENV, nullptr, &env); + if (SQLAllocHandle(SQL_HANDLE_ENV, nullptr, &env) != SQL_SUCCESS) { + throw std::runtime_error("Failed to allocate handles for integration tests."); + } SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast(SQL_OV_ODBC3), 0); - SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc); + if (SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc) != SQL_SUCCESS) { + throw std::runtime_error("Failed to allocate handles for integration tests."); + } Aws::Auth::AWSCredentials credentials = SESSION_TOKEN.empty() ? Aws::Auth::AWSCredentials(Aws::String(ACCESS_KEY), Aws::String(SECRET_ACCESS_KEY))