diff options
author | unknown <stewart@mysql.com> | 2005-02-23 21:07:22 +1100 |
---|---|---|
committer | unknown <stewart@mysql.com> | 2005-02-23 21:07:22 +1100 |
commit | bb5a2f280f41178cb132e6c0e9db205cbc4abc9f (patch) | |
tree | b190ad7e885c8a3df91a3ddc9345c780566a7e65 /ndb | |
parent | 3bd6f299fc3aa8c0908c64b643a7ef97a9f1c3af (diff) | |
download | mariadb-git-bb5a2f280f41178cb132e6c0e9db205cbc4abc9f.tar.gz |
Use the mgm connection used for fetching configuration as a transporter.
ndb/include/mgmapi/mgmapi.h:
Add mgmapi call: ndb_mgm_get_mgmd_nodeid()
- returns the node id that the handle is connected to.
- returns 0 on error.
ndb/include/transporter/TransporterRegistry.hpp:
Add TransporterRegistry::connect_client(NdbMgmHandle h)
- uses a connected NdbMgmHandle to connect to the mgm server as a client.
- sets up a transporter connection
- used to transform the initial mgm connection (used for fetching configuration)
into a transporter connection
Added connect_ndb_mgmd(NdbMgmHandle h)
- turn the supplied mgm connection into a transporter connection
- return the socket
Improve comments on connect_ndb_mgmd(SocketClient)
ndb/src/common/transporter/Transporter.cpp:
Add Transporter::connect_client(NDB_SOCKET_TYPE)
- use an existing socket to make a transporter connection
ndb/src/common/transporter/Transporter.hpp:
Add connect_client(NDB_SOCKET_TYPE)
ndb/src/common/transporter/TransporterRegistry.cpp:
Add TransporterRegistry::connect_client(NdbMgmHandle)
- use an existing mgm connection to connect a transporter
- used to change the mgm connection used for fetching configuration into a transporter
Add connect_ndb_mgmd(NdbMgmHandle)
- use existing NdbMgmHandle
- convert to transporter
- return socket
ndb/src/kernel/vm/Configuration.cpp:
After fetching configuration, use the mgm connection as a transporter.
Fail fatally if this fails.
ndb/src/mgmapi/mgmapi.cpp:
Add ndb_mgm_get_mgmd_nodeid(h)
- returns the node id of the mgm server you're connected to.
ndb/src/mgmsrv/Services.cpp:
Add "get mgmd nodeid" mgmd call
returns 'nodeid' - the node id of the mgm server your connected to
ndb/src/mgmsrv/Services.hpp:
add prototype for get_mgmd_nodeid
Diffstat (limited to 'ndb')
-rw-r--r-- | ndb/include/mgmapi/mgmapi.h | 4 | ||||
-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 | 70 | ||||
-rw-r--r-- | ndb/src/kernel/vm/Configuration.cpp | 3 | ||||
-rw-r--r-- | ndb/src/mgmapi/mgmapi.cpp | 31 | ||||
-rw-r--r-- | ndb/src/mgmsrv/Services.cpp | 10 | ||||
-rw-r--r-- | ndb/src/mgmsrv/Services.hpp | 2 |
9 files changed, 123 insertions, 18 deletions
diff --git a/ndb/include/mgmapi/mgmapi.h b/ndb/include/mgmapi/mgmapi.h index 17c227853fe..f667c6d3a67 100644 --- a/ndb/include/mgmapi/mgmapi.h +++ b/ndb/include/mgmapi/mgmapi.h @@ -996,6 +996,10 @@ extern "C" { */ 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/transporter/TransporterRegistry.hpp b/ndb/include/transporter/TransporterRegistry.hpp index a31fa1d5ce2..f69cd058c65 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); + int TransporterRegistry::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..6d5f9457a24 100644 --- a/ndb/src/common/transporter/TransporterRegistry.cpp +++ b/ndb/src/common/transporter/TransporterRegistry.cpp @@ -1521,10 +1521,61 @@ TransporterRegistry::get_transporter(NodeId nodeId) { return theTransporters[nodeId]; } +int TransporterRegistry::connect_client(NdbMgmHandle h) +{ + DBUG_ENTER("TransporterRegistry::connect_client(NdbMgmHandle)"); + + Uint32 mgm_nodeid= ndb_mgm_get_mgmd_nodeid(h); + + Transporter * t = theTransporters[mgm_nodeid]; + if (!t) + return -1; + + 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 ) + { + 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; + } + + /** + * 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 +1613,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..02f4f2a9b98 100644 --- a/ndb/src/kernel/vm/Configuration.cpp +++ b/ndb/src/kernel/vm/Configuration.cpp @@ -313,6 +313,9 @@ Configuration::setupConfiguration(){ ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", "No transporters configured"); } + if(!globalTransporterRegistry.connect_client(m_config_retriever->get_mgmHandle())) + ERROR_SET(fatal, ERR_INVALID_CONFIG, "Connection to mgmd terminated before setup was complete", + "StopOnError missing"); } /** diff --git a/ndb/src/mgmapi/mgmapi.cpp b/ndb/src/mgmapi/mgmapi.cpp index bd4052f51d9..f326a77a8af 100644 --- a/ndb/src/mgmapi/mgmapi.cpp +++ b/ndb/src/mgmapi/mgmapi.cpp @@ -2208,4 +2208,35 @@ ndb_mgm_convert_to_transporter(NdbMgmHandle handle) 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); }; |