From 6bd9c85acd73aac75c37bdfa15980569ba9fde99 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 11 Feb 2005 15:43:43 +1100 Subject: [PATCH] WL2278 Dynamic ports - Impl 6, "deal with mgm server restart and multiple mgm servers" - when connecting to a mgm server as a transporter, create a NdbMgmHandle - over this mgm handle, report the dynamic ports - then turn it into a transporter - this will re-report dynamic ports to mgmds when they restart (as we'll have to set up our transporter again). This will also report it to all mgmds (as we'll have transporters to all of them). ndb/include/mgmapi/mgmapi.h: Add ndb_mgm_convert_to_transporter - converts to a transporter connect - destroys the handle (without disconnecting) - returns socket ndb/include/transporter/TransporterRegistry.hpp: Add prototype for connect_ndb_mgmd ndb/include/util/SocketClient.hpp: Remove connect_without_auth Add get_port() and get_server_name() ndb/src/common/transporter/Transporter.cpp: use TransporterRegistry::connect_ndb_mgmd() to make the connection if isMgmConnection ndb/src/common/transporter/TransporterRegistry.cpp: Impliment TransporterRegistry::connect_ndb_mgmd - takes a SocketClient and constructs a connectstring. - uses this connect string to make a NdbMgmHandle - send dynamic ports to this mgm server - transform into a transporter connect - return socket ndb/src/common/util/SocketClient.cpp: Remove connect_without_auth ndb/src/kernel/main.cpp: Don't relay dynamic ports. We now do this on transporter connect ndb/src/mgmapi/mgmapi.cpp: Impliment ndb_mgm_convert_to_transporter - converts the mgm connection into a transporter connection - destroys the handle - returns the socket that should now be used as a transporter --- ndb/include/mgmapi/mgmapi.h | 14 ++++++ .../transporter/TransporterRegistry.hpp | 6 +++ ndb/include/util/SocketClient.hpp | 3 +- ndb/src/common/transporter/Transporter.cpp | 12 +---- .../transporter/TransporterRegistry.cpp | 44 +++++++++++++++++++ ndb/src/common/util/SocketClient.cpp | 21 --------- ndb/src/kernel/main.cpp | 11 ----- ndb/src/mgmapi/mgmapi.cpp | 21 +++++++++ 8 files changed, 88 insertions(+), 44 deletions(-) diff --git a/ndb/include/mgmapi/mgmapi.h b/ndb/include/mgmapi/mgmapi.h index de4286bdbfd..1870dac60ad 100644 --- a/ndb/include/mgmapi/mgmapi.h +++ b/ndb/include/mgmapi/mgmapi.h @@ -140,6 +140,7 @@ */ #include +#include #include "ndb_logevent.h" #include "mgmapi_config_parameters.h" @@ -970,6 +971,19 @@ extern "C" { int ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned version, int nodetype); + + + /** + * Convert connection to transporter + * @param handle NDB management handle. + * + * @return socket + * + * @note the socket is now able to be used as a transporter connection + */ + NDB_SOCKET_TYPE ndb_mgm_convert_to_transporter(NdbMgmHandle handle); + + /** * Config iterator */ diff --git a/ndb/include/transporter/TransporterRegistry.hpp b/ndb/include/transporter/TransporterRegistry.hpp index 665a2728d29..3773a0fc686 100644 --- a/ndb/include/transporter/TransporterRegistry.hpp +++ b/ndb/include/transporter/TransporterRegistry.hpp @@ -30,6 +30,7 @@ #include "TransporterDefinitions.hpp" #include +#include #include @@ -111,6 +112,11 @@ public: */ bool connect_server(NDB_SOCKET_TYPE sockfd); + /** + * use a mgmd connection to connect as a transporter + */ + NDB_SOCKET_TYPE connect_ndb_mgmd(SocketClient *sc); + /** * Remove all transporters */ diff --git a/ndb/include/util/SocketClient.hpp b/ndb/include/util/SocketClient.hpp index 5847c55f397..bf1ad7d45d6 100644 --- a/ndb/include/util/SocketClient.hpp +++ b/ndb/include/util/SocketClient.hpp @@ -35,8 +35,9 @@ public: m_port = port; m_servaddr.sin_port = htons(m_port); }; + unsigned short get_port() { return m_port; }; + char *get_server_name() { return m_server_name; }; NDB_SOCKET_TYPE connect(); - NDB_SOCKET_TYPE connect_without_auth(); bool close(); }; diff --git a/ndb/src/common/transporter/Transporter.cpp b/ndb/src/common/transporter/Transporter.cpp index f8bcf142a69..86fabc839c7 100644 --- a/ndb/src/common/transporter/Transporter.cpp +++ b/ndb/src/common/transporter/Transporter.cpp @@ -117,7 +117,7 @@ Transporter::connect_client() { return true; if(isMgmConnection) - sockfd= m_socket_client->connect_without_auth(); + sockfd= m_transporter_registry.connect_ndb_mgmd(m_socket_client); else sockfd= m_socket_client->connect(); @@ -131,16 +131,6 @@ Transporter::connect_client() { SocketOutputStream s_output(sockfd); SocketInputStream s_input(sockfd); - if(isMgmConnection) - { - /* - We issue the magic command to the management server to - switch into transporter mode. - */ - s_output.println("transporter connect"); - s_output.println(""); - } - // send info about own id // send info about own transporter type diff --git a/ndb/src/common/transporter/TransporterRegistry.cpp b/ndb/src/common/transporter/TransporterRegistry.cpp index a6cad7b921f..e98ab03dfd6 100644 --- a/ndb/src/common/transporter/TransporterRegistry.cpp +++ b/ndb/src/common/transporter/TransporterRegistry.cpp @@ -48,6 +48,7 @@ extern int g_ndb_shm_signum; #include #include +#include #include #include @@ -1483,4 +1484,47 @@ TransporterRegistry::get_transporter(NodeId nodeId) { return theTransporters[nodeId]; } +NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(SocketClient *sc) +{ + NdbMgmHandle h; + struct ndb_mgm_reply mgm_reply; + char *cs, c[100]; + bool d=false; + + h= ndb_mgm_create_handle(); + + if(strlen(sc->get_server_name())>80) + { + /* + * server name is long. malloc enough for it and the port number + */ + cs= (char*)malloc((strlen(sc->get_server_name())+20)*sizeof(char)); + if(!cs) + return -1; + d= true; + } + else + cs = &c[0]; + + snprintf(cs,(d)?strlen(sc->get_server_name()+20):sizeof(c), + "%s:%u",sc->get_server_name(),sc->get_port()); + + ndb_mgm_set_connectstring(h, cs); + + if(ndb_mgm_connect(h, 0, 0, 0)<0) + return -1; + + for(unsigned int i=0;i < m_transporter_interface.size();i++) + ndb_mgm_set_connection_int_parameter(h, + get_localNodeId(), + m_transporter_interface[i].m_remote_nodeId, + CFG_CONNECTION_SERVER_PORT, + m_transporter_interface[i].m_s_service_port, + &mgm_reply); + if(d) + free(cs); + + return ndb_mgm_convert_to_transporter(h); +} + template class Vector; diff --git a/ndb/src/common/util/SocketClient.cpp b/ndb/src/common/util/SocketClient.cpp index 1ac105881a2..38df1417eb8 100644 --- a/ndb/src/common/util/SocketClient.cpp +++ b/ndb/src/common/util/SocketClient.cpp @@ -60,27 +60,6 @@ SocketClient::init() return true; } -/** - * SocketClient::connect_without_auth() - * - * Temporarily disables authentication and connects. - * This is useful if you're trying to change what this - * SocketClient object is for (e.g. from mgm to ndb) - */ - -NDB_SOCKET_TYPE -SocketClient::connect_without_auth() -{ - SocketAuthenticator *tmp; - NDB_SOCKET_TYPE retval; - tmp= m_auth; - m_auth= NULL; - retval= connect(); - m_auth= tmp; - - return retval; -} - NDB_SOCKET_TYPE SocketClient::connect() { diff --git a/ndb/src/kernel/main.cpp b/ndb/src/kernel/main.cpp index 68fc52a6b68..b511f003429 100644 --- a/ndb/src/kernel/main.cpp +++ b/ndb/src/kernel/main.cpp @@ -205,17 +205,6 @@ int main(int argc, char** argv) socket_server.startServer(); - struct ndb_mgm_reply mgm_reply; - for(unsigned int i=0;iget_config_retriever()->get_mgmHandle(), - globalTransporterRegistry.get_localNodeId(), - globalTransporterRegistry.m_transporter_interface[i].m_remote_nodeId, - CFG_CONNECTION_SERVER_PORT, - globalTransporterRegistry.m_transporter_interface[i].m_s_service_port, - &mgm_reply); - - - // theConfig->closeConfiguration(); globalEmulatorData.theThreadConfig->ipControlLoop(); diff --git a/ndb/src/mgmapi/mgmapi.cpp b/ndb/src/mgmapi/mgmapi.cpp index 9974686cd4f..f6427204814 100644 --- a/ndb/src/mgmapi/mgmapi.cpp +++ b/ndb/src/mgmapi/mgmapi.cpp @@ -2148,4 +2148,25 @@ ndb_mgm_get_connection_int_parameter(NdbMgmHandle handle, DBUG_RETURN(res); } +extern "C" +NDB_SOCKET_TYPE +ndb_mgm_convert_to_transporter(NdbMgmHandle handle) +{ + NDB_SOCKET_TYPE s; + + CHECK_HANDLE(handle, -1); + CHECK_CONNECTED(handle, -2); + + handle->connected= 0; // we pretend we're disconnected + s= handle->socket; + + SocketOutputStream s_output(s); + s_output.println("transporter connect"); + s_output.println(""); + + ndb_mgm_destroy_handle(&handle); // set connected=0, so won't disconnect + + return s; +} + template class Vector*>;