From 6d12f230471ef218cf4a6b176de387d958dfddbe Mon Sep 17 00:00:00 2001 From: "stewart@mysql.com" <> Date: Tue, 15 Feb 2005 18:30:44 +1100 Subject: [PATCH 1/3] Don't ask mgm server for port to connect transporter to if we already have one; only ask if connect fails. Reconnect to mgm server in connect_clients thread if m_mgm_handle is disconnected. --- ndb/include/mgmapi/mgmapi.h | 7 ++++ .../transporter/TransporterRegistry.cpp | 37 +++++++++++++------ ndb/src/mgmapi/mgmapi.cpp | 11 ++++++ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/ndb/include/mgmapi/mgmapi.h b/ndb/include/mgmapi/mgmapi.h index 1870dac60ad..c2f326995d6 100644 --- a/ndb/include/mgmapi/mgmapi.h +++ b/ndb/include/mgmapi/mgmapi.h @@ -519,6 +519,13 @@ extern "C" { */ int ndb_mgm_connect(NdbMgmHandle handle, int no_retries, int retry_delay_in_seconds, int verbose); + /** + * Return true if connected. + * + * @param handle Management handle + * @return 0 if not connected, non-zero if connected. + */ + int ndb_mgm_is_connected(NdbMgmHandle handle); /** * Disconnects from a management server diff --git a/ndb/src/common/transporter/TransporterRegistry.cpp b/ndb/src/common/transporter/TransporterRegistry.cpp index b0bcf22acd4..0e78b2d548c 100644 --- a/ndb/src/common/transporter/TransporterRegistry.cpp +++ b/ndb/src/common/transporter/TransporterRegistry.cpp @@ -1211,11 +1211,37 @@ TransporterRegistry::start_clients_thread() switch(performStates[nodeId]){ case CONNECTING: if(!t->isConnected() && !t->isServer) { + int result= 0; + /** + * First, we try to connect (if we have a port number). + */ + if (theTransporterTypes[nodeId] != tt_TCP_TRANSPORTER + || t->get_s_port() > 0) + result= t->connect_client(); + + + if (result<0 && t->get_s_port()!=0) + { + ndbout_c("Error while trying to make connection (Node %u to" + " %u via port %u) error: %d. Retrying...", + t->getRemoteNodeId(), + t->getLocalNodeId(), + t->get_s_port()); + NdbSleep_MilliSleep(400); // wait before retrying + } + + /** + * If dynamic, get the port for connecting from the management server + */ if(t->get_s_port() <= 0) { // Port is dynamic int server_port= 0; struct ndb_mgm_reply mgm_reply; int res; + if(!ndb_mgm_is_connected(m_mgm_handle)) + if(ndb_mgm_connect(m_mgm_handle, 0, 0, 0)<0) + ndbout_c("Failed to reconnect to management server"); + res= ndb_mgm_get_connection_int_parameter(m_mgm_handle, t->getRemoteNodeId(), t->getLocalNodeId(), @@ -1231,17 +1257,6 @@ TransporterRegistry::start_clients_thread() else ndbout_c("Failed to get dynamic port to connect to: %d", res); } - if (theTransporterTypes[nodeId] != tt_TCP_TRANSPORTER - || t->get_s_port() > 0) { - int result = t->connect_client(); - if (result<0) - ndbout_c("Error while trying to make connection (Node %u to" - " %u via port %u) error: %d. Retrying...", - t->getRemoteNodeId(), - t->getLocalNodeId(), - t->get_s_port()); - } else - NdbSleep_MilliSleep(400); // wait before retrying } break; case DISCONNECTING: diff --git a/ndb/src/mgmapi/mgmapi.cpp b/ndb/src/mgmapi/mgmapi.cpp index 548f8cbf63c..cde0c9b5d9e 100644 --- a/ndb/src/mgmapi/mgmapi.cpp +++ b/ndb/src/mgmapi/mgmapi.cpp @@ -334,6 +334,17 @@ ndb_mgm_call(NdbMgmHandle handle, const ParserRow *command_reply, return p; } +/** + * Returns true if connected + */ +extern "C" +int ndb_mgm_is_connected(NdbMgmHandle handle) +{ + if(!handle) + return 0; + return handle->connected; +} + /** * Connect to a management server */ From d35395617b37d1e4ae54aac6018f8e43e7b7bf83 Mon Sep 17 00:00:00 2001 From: "stewart@mysql.com" <> Date: Tue, 15 Feb 2005 18:47:31 +1100 Subject: [PATCH 2/3] In connect_clients thread: - don't wait an extra 400ms before retrying a transporter connect if the port is dynamic --- ndb/src/common/transporter/TransporterRegistry.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/ndb/src/common/transporter/TransporterRegistry.cpp b/ndb/src/common/transporter/TransporterRegistry.cpp index 0e78b2d548c..4840741ca14 100644 --- a/ndb/src/common/transporter/TransporterRegistry.cpp +++ b/ndb/src/common/transporter/TransporterRegistry.cpp @@ -1221,14 +1221,11 @@ TransporterRegistry::start_clients_thread() if (result<0 && t->get_s_port()!=0) - { ndbout_c("Error while trying to make connection (Node %u to" " %u via port %u) error: %d. Retrying...", t->getRemoteNodeId(), t->getLocalNodeId(), t->get_s_port()); - NdbSleep_MilliSleep(400); // wait before retrying - } /** * If dynamic, get the port for connecting from the management server From 00e121f4a640e41916934008f935d85bfc5d8fc1 Mon Sep 17 00:00:00 2001 From: "stewart@mysql.com" <> Date: Tue, 15 Feb 2005 19:15:31 +1100 Subject: [PATCH 3/3] fixes in connect_client thread. g_eventLogger usage, correct condition on calling connect on Transporter --- ndb/src/common/transporter/TransporterRegistry.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ndb/src/common/transporter/TransporterRegistry.cpp b/ndb/src/common/transporter/TransporterRegistry.cpp index 4840741ca14..f07deafc98d 100644 --- a/ndb/src/common/transporter/TransporterRegistry.cpp +++ b/ndb/src/common/transporter/TransporterRegistry.cpp @@ -1215,17 +1215,17 @@ TransporterRegistry::start_clients_thread() /** * First, we try to connect (if we have a port number). */ - if (theTransporterTypes[nodeId] != tt_TCP_TRANSPORTER - || t->get_s_port() > 0) + if (t->get_s_port()) result= t->connect_client(); if (result<0 && t->get_s_port()!=0) - ndbout_c("Error while trying to make connection (Node %u to" - " %u via port %u) error: %d. Retrying...", - t->getRemoteNodeId(), - t->getLocalNodeId(), - t->get_s_port()); + g_eventLogger.warning("Error while trying to make connection " + "(Node %u to %u via port %u) " + "error: %d. Retrying...", + t->getRemoteNodeId(), + t->getLocalNodeId(), + t->get_s_port()); /** * If dynamic, get the port for connecting from the management server