diff options
author | stewart@mysql.com <> | 2005-02-24 18:46:13 +1100 |
---|---|---|
committer | stewart@mysql.com <> | 2005-02-24 18:46:13 +1100 |
commit | e94e9fa644cf0e604dbba1b97312bd45031df9e9 (patch) | |
tree | 12b7a42db01fab950bb6e10fdc735f742835d6f8 /ndb | |
parent | 2952f73c168e879b2aac82c77f711c1fb1356862 (diff) | |
parent | 336f4cc80826821175ce98b62a51aa06f0007165 (diff) | |
download | mariadb-git-e94e9fa644cf0e604dbba1b97312bd45031df9e9.tar.gz |
Merge mysql.com:/home/stewart/Documents/MySQL/5.0/ndb
into mysql.com:/home/stewart/Documents/MySQL/5.0/ndb-dynamic-ports
Diffstat (limited to 'ndb')
-rw-r--r-- | ndb/include/mgmapi/mgmapi.h | 6 | ||||
-rw-r--r-- | ndb/include/mgmcommon/ConfigRetriever.hpp | 1 | ||||
-rw-r--r-- | ndb/include/transporter/TransporterRegistry.hpp | 11 | ||||
-rw-r--r-- | ndb/src/common/transporter/Transporter.cpp | 9 | ||||
-rw-r--r-- | ndb/src/common/transporter/Transporter.hpp | 1 | ||||
-rw-r--r-- | ndb/src/common/transporter/TransporterRegistry.cpp | 93 | ||||
-rw-r--r-- | ndb/src/kernel/vm/Configuration.cpp | 20 | ||||
-rw-r--r-- | ndb/src/kernel/vm/Configuration.hpp | 4 | ||||
-rw-r--r-- | ndb/src/mgmapi/mgmapi.cpp | 43 | ||||
-rw-r--r-- | ndb/src/mgmsrv/Services.cpp | 10 | ||||
-rw-r--r-- | ndb/src/mgmsrv/Services.hpp | 2 |
11 files changed, 171 insertions, 29 deletions
diff --git a/ndb/include/mgmapi/mgmapi.h b/ndb/include/mgmapi/mgmapi.h index 17c227853fe..726552d63d1 100644 --- a/ndb/include/mgmapi/mgmapi.h +++ b/ndb/include/mgmapi/mgmapi.h @@ -994,8 +994,12 @@ extern "C" { * * @note the socket is now able to be used as a transporter connection */ - NDB_SOCKET_TYPE ndb_mgm_convert_to_transporter(NdbMgmHandle handle); + NDB_SOCKET_TYPE ndb_mgm_convert_to_transporter(NdbMgmHandle *handle); + /** + * Get the node id of the mgm server we're connected to + */ + Uint32 ndb_mgm_get_mgmd_nodeid(NdbMgmHandle handle); /** * Config iterator diff --git a/ndb/include/mgmcommon/ConfigRetriever.hpp b/ndb/include/mgmcommon/ConfigRetriever.hpp index b91bb362837..95d257dea23 100644 --- a/ndb/include/mgmcommon/ConfigRetriever.hpp +++ b/ndb/include/mgmcommon/ConfigRetriever.hpp @@ -76,6 +76,7 @@ public: const char *get_mgmd_host() const; const char *get_connectstring(char *buf, int buf_sz) const; NdbMgmHandle get_mgmHandle() { return m_handle; }; + NdbMgmHandle* get_mgmHandlePtr() { return &m_handle; }; Uint32 get_configuration_nodeid() const; private: diff --git a/ndb/include/transporter/TransporterRegistry.hpp b/ndb/include/transporter/TransporterRegistry.hpp index a31fa1d5ce2..363cdabe10a 100644 --- a/ndb/include/transporter/TransporterRegistry.hpp +++ b/ndb/include/transporter/TransporterRegistry.hpp @@ -116,12 +116,21 @@ public: */ bool connect_server(NDB_SOCKET_TYPE sockfd); + bool connect_client(NdbMgmHandle *h); + /** - * use a mgmd connection to connect as a transporter + * Given a SocketClient, creates a NdbMgmHandle, turns it into a transporter + * and returns the socket. */ NDB_SOCKET_TYPE connect_ndb_mgmd(SocketClient *sc); /** + * Given a connected NdbMgmHandle, turns it into a transporter + * and returns the socket. + */ + NDB_SOCKET_TYPE connect_ndb_mgmd(NdbMgmHandle *h); + + /** * Remove all transporters */ void removeAll(); diff --git a/ndb/src/common/transporter/Transporter.cpp b/ndb/src/common/transporter/Transporter.cpp index a888d98b832..86e9b8c8171 100644 --- a/ndb/src/common/transporter/Transporter.cpp +++ b/ndb/src/common/transporter/Transporter.cpp @@ -124,6 +124,15 @@ Transporter::connect_client() { else sockfd= m_socket_client->connect(); + connect_client(sockfd); +} + +bool +Transporter::connect_client(NDB_SOCKET_TYPE sockfd) { + + if(m_connected) + return true; + if (sockfd == NDB_INVALID_SOCKET) return false; diff --git a/ndb/src/common/transporter/Transporter.hpp b/ndb/src/common/transporter/Transporter.hpp index 5b25afa0d89..53414f1179d 100644 --- a/ndb/src/common/transporter/Transporter.hpp +++ b/ndb/src/common/transporter/Transporter.hpp @@ -44,6 +44,7 @@ public: * Use isConnected() to check status */ bool connect_client(); + bool connect_client(NDB_SOCKET_TYPE sockfd); bool connect_server(NDB_SOCKET_TYPE socket); /** diff --git a/ndb/src/common/transporter/TransporterRegistry.cpp b/ndb/src/common/transporter/TransporterRegistry.cpp index b8dd2d1f561..34d5a770018 100644 --- a/ndb/src/common/transporter/TransporterRegistry.cpp +++ b/ndb/src/common/transporter/TransporterRegistry.cpp @@ -1365,6 +1365,8 @@ TransporterRegistry::add_transporter_interface(NodeId remoteNodeId, bool TransporterRegistry::start_service(SocketServer& socket_server) { + struct ndb_mgm_reply mgm_reply; + DBUG_ENTER("TransporterRegistry::start_service"); if (m_transporter_interface.size() > 0 && !nodeIdSpecified) { @@ -1372,6 +1374,11 @@ TransporterRegistry::start_service(SocketServer& socket_server) DBUG_RETURN(false); } + if(!ndb_mgm_is_connected(m_mgm_handle)) + ndb_mgm_connect(m_mgm_handle, 0, 0, 0); + if(!ndb_mgm_is_connected(m_mgm_handle)) + DBUG_RETURN(false); + for (unsigned i= 0; i < m_transporter_interface.size(); i++) { Transporter_interface &t= m_transporter_interface[i]; @@ -1404,6 +1411,18 @@ TransporterRegistry::start_service(SocketServer& socket_server) } t.m_s_service_port= (t.m_s_service_port<=0)?-port:port; // -`ve if dynamic DBUG_PRINT("info", ("t.m_s_service_port = %d",t.m_s_service_port)); + + if(t.m_s_service_port < 0 + && ndb_mgm_set_connection_int_parameter(m_mgm_handle, + get_localNodeId(), + t.m_remote_nodeId, + CFG_CONNECTION_SERVER_PORT, + t.m_s_service_port, + &mgm_reply) < 0) + { + delete transporter_service; + DBUG_RETURN(false); + } transporter_service->setTransporterRegistry(this); } DBUG_RETURN(true); @@ -1521,10 +1540,65 @@ TransporterRegistry::get_transporter(NodeId nodeId) { return theTransporters[nodeId]; } +bool TransporterRegistry::connect_client(NdbMgmHandle *h) +{ + DBUG_ENTER("TransporterRegistry::connect_client(NdbMgmHandle)"); + + Uint32 mgm_nodeid= ndb_mgm_get_mgmd_nodeid(*h); + + if(!mgm_nodeid) + return false; + + Transporter * t = theTransporters[mgm_nodeid]; + if (!t) + return false; + + DBUG_RETURN(t->connect_client(connect_ndb_mgmd(h))); +} + +/** + * Given a connected NdbMgmHandle, turns it into a transporter + * and returns the socket. + */ +NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(NdbMgmHandle *h) +{ + struct ndb_mgm_reply mgm_reply; + + if ( h==NULL || *h == NULL ) + { + return NDB_INVALID_SOCKET; + } + + for(unsigned int i=0;i < m_transporter_interface.size();i++) + if (m_transporter_interface[i].m_s_service_port < 0 + && 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) < 0) + { + ndb_mgm_destroy_handle(h); + return NDB_INVALID_SOCKET; + } + + /** + * convert_to_transporter also disposes of the handle (i.e. we don't leak + * memory here. + */ + NDB_SOCKET_TYPE sockfd= ndb_mgm_convert_to_transporter(h); + if ( sockfd == NDB_INVALID_SOCKET) + ndb_mgm_destroy_handle(h); + return sockfd; +} + +/** + * Given a SocketClient, creates a NdbMgmHandle, turns it into a transporter + * and returns the socket. + */ NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(SocketClient *sc) { NdbMgmHandle h= ndb_mgm_create_handle(); - struct ndb_mgm_reply mgm_reply; if ( h == NULL ) { @@ -1562,22 +1636,7 @@ NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(SocketClient *sc) return NDB_INVALID_SOCKET; } - for(unsigned int i=0;i < m_transporter_interface.size();i++) - if (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) < 0) - { - ndb_mgm_destroy_handle(&h); - return NDB_INVALID_SOCKET; - } - - NDB_SOCKET_TYPE sockfd= ndb_mgm_convert_to_transporter(h); - if ( sockfd == NDB_INVALID_SOCKET) - ndb_mgm_destroy_handle(&h); - return sockfd; + return connect_ndb_mgmd(&h); } template class Vector<TransporterRegistry::Transporter_interface>; diff --git a/ndb/src/kernel/vm/Configuration.cpp b/ndb/src/kernel/vm/Configuration.cpp index 3170939f8d8..29455e5b115 100644 --- a/ndb/src/kernel/vm/Configuration.cpp +++ b/ndb/src/kernel/vm/Configuration.cpp @@ -154,6 +154,7 @@ Configuration::Configuration() m_config_retriever= 0; m_clusterConfig= 0; m_clusterConfigIter= 0; + m_mgmd_host= NULL; } Configuration::~Configuration(){ @@ -166,6 +167,9 @@ Configuration::~Configuration(){ if(_backupPath != NULL) free(_backupPath); + if(m_mgmd_host) + free(m_mgmd_host); + if (m_config_retriever) { delete m_config_retriever; } @@ -210,8 +214,16 @@ Configuration::fetch_configuration(){ ERROR_SET(fatal, ERR_INVALID_CONFIG, "Could not connect to ndb_mgmd", s); } - m_mgmd_port= m_config_retriever->get_mgmd_port(); - m_mgmd_host= m_config_retriever->get_mgmd_host(); + { + m_mgmd_port= m_config_retriever->get_mgmd_port(); + /** + * We copy the mgmd host as the handle is later + * destroyed, so a pointer won't work + */ + int len= strlen(m_config_retriever->get_mgmd_host()); + m_mgmd_host= (char*)malloc(sizeof(char)*len); + strcpy(m_mgmd_host,m_config_retriever->get_mgmd_host()); + } ConfigRetriever &cr= *m_config_retriever; @@ -313,6 +325,10 @@ Configuration::setupConfiguration(){ ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", "No transporters configured"); } + if(!globalTransporterRegistry.connect_client( + m_config_retriever->get_mgmHandlePtr())) + ERROR_SET(fatal, ERR_INVALID_CONFIG, "Connection to mgmd terminated before setup was complete", + "StopOnError missing"); } /** diff --git a/ndb/src/kernel/vm/Configuration.hpp b/ndb/src/kernel/vm/Configuration.hpp index a257881e353..dd690665413 100644 --- a/ndb/src/kernel/vm/Configuration.hpp +++ b/ndb/src/kernel/vm/Configuration.hpp @@ -67,7 +67,7 @@ public: const ndb_mgm_configuration_iterator * getOwnConfigIterator() const; Uint32 get_mgmd_port() const {return m_mgmd_port;}; - const char *get_mgmd_host() const {return m_mgmd_host;}; + char *get_mgmd_host() const {return m_mgmd_host;}; ConfigRetriever* get_config_retriever() { return m_config_retriever; }; class LogLevel * m_logLevel; @@ -99,7 +99,7 @@ private: bool _initialStart; char * _connectString; Uint32 m_mgmd_port; - const char *m_mgmd_host; + char *m_mgmd_host; bool _daemonMode; void calcSizeAlt(class ConfigValues * ); diff --git a/ndb/src/mgmapi/mgmapi.cpp b/ndb/src/mgmapi/mgmapi.cpp index bd4052f51d9..99b6efe320b 100644 --- a/ndb/src/mgmapi/mgmapi.cpp +++ b/ndb/src/mgmapi/mgmapi.cpp @@ -2189,23 +2189,54 @@ ndb_mgm_get_connection_int_parameter(NdbMgmHandle handle, extern "C" NDB_SOCKET_TYPE -ndb_mgm_convert_to_transporter(NdbMgmHandle handle) +ndb_mgm_convert_to_transporter(NdbMgmHandle *handle) { NDB_SOCKET_TYPE s; - CHECK_HANDLE(handle, NDB_INVALID_SOCKET); - CHECK_CONNECTED(handle, NDB_INVALID_SOCKET); + CHECK_HANDLE((*handle), NDB_INVALID_SOCKET); + CHECK_CONNECTED((*handle), NDB_INVALID_SOCKET); - handle->connected= 0; // we pretend we're disconnected - s= handle->socket; + (*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 + ndb_mgm_destroy_handle(handle); // set connected=0, so won't disconnect return s; } +extern "C" +Uint32 +ndb_mgm_get_mgmd_nodeid(NdbMgmHandle handle) +{ + Uint32 nodeid=0; + + DBUG_ENTER("ndb_mgm_get_mgmd_nodeid"); + CHECK_HANDLE(handle, 0); + CHECK_CONNECTED(handle, 0); + + Properties args; + + const ParserRow<ParserDummy> reply[]= { + MGM_CMD("get mgmd nodeid reply", NULL, ""), + MGM_ARG("nodeid", Int, Mandatory, "Node ID"), + MGM_END() + }; + + const Properties *prop; + prop = ndb_mgm_call(handle, reply, "get mgmd nodeid", &args); + CHECK_REPLY(prop, 0); + + if(!prop->get("nodeid",&nodeid)){ + ndbout_c("Unable to get value"); + return 0; + } + + delete prop; + DBUG_RETURN(nodeid); +} + template class Vector<const ParserRow<ParserDummy>*>; diff --git a/ndb/src/mgmsrv/Services.cpp b/ndb/src/mgmsrv/Services.cpp index fdfe2f92aca..cbed7998e29 100644 --- a/ndb/src/mgmsrv/Services.cpp +++ b/ndb/src/mgmsrv/Services.cpp @@ -266,6 +266,8 @@ ParserRow<MgmApiSession> commands[] = { MGM_CMD("transporter connect", &MgmApiSession::transporter_connect, ""), + MGM_CMD("get mgmd nodeid", &MgmApiSession::get_mgmd_nodeid, ""), + MGM_END() }; @@ -1554,5 +1556,13 @@ MgmApiSession::transporter_connect(Parser_t::Context &ctx, m_mgmsrv.transporter_connect(s); } +void +MgmApiSession::get_mgmd_nodeid(Parser_t::Context &ctx, + Properties const &args) { + m_output->println("get mgmd nodeid reply"); + m_output->println("nodeid:%u",m_mgmsrv.getOwnNodeId()); + m_output->println(""); +} + template class MutexVector<int>; template class Vector<ParserRow<MgmApiSession> const*>; diff --git a/ndb/src/mgmsrv/Services.hpp b/ndb/src/mgmsrv/Services.hpp index e4fddea7d04..ff9008b05a8 100644 --- a/ndb/src/mgmsrv/Services.hpp +++ b/ndb/src/mgmsrv/Services.hpp @@ -99,6 +99,8 @@ public: void check_connection(Parser_t::Context &ctx, const class Properties &args); void transporter_connect(Parser_t::Context &ctx, Properties const &args); + + void get_mgmd_nodeid(Parser_t::Context &ctx, Properties const &args); void repCommand(Parser_t::Context &ctx, const class Properties &args); }; |