Commit 2d217a50 authored by unknown's avatar unknown

Merge tulin@bk-internal.mysql.com:/home/bk/mysql-5.0-ndb

into poseidon.ndb.mysql.com:/home/tomas/mysql-5.0-ndb
parents 891d1fcb e3a27f0c
...@@ -994,8 +994,12 @@ extern "C" { ...@@ -994,8 +994,12 @@ extern "C" {
* *
* @note the socket is now able to be used as a transporter connection * @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 * Config iterator
......
...@@ -76,6 +76,7 @@ public: ...@@ -76,6 +76,7 @@ public:
const char *get_mgmd_host() const; const char *get_mgmd_host() const;
const char *get_connectstring(char *buf, int buf_sz) const; const char *get_connectstring(char *buf, int buf_sz) const;
NdbMgmHandle get_mgmHandle() { return m_handle; }; NdbMgmHandle get_mgmHandle() { return m_handle; };
NdbMgmHandle* get_mgmHandlePtr() { return &m_handle; };
Uint32 get_configuration_nodeid() const; Uint32 get_configuration_nodeid() const;
private: private:
......
...@@ -116,11 +116,20 @@ public: ...@@ -116,11 +116,20 @@ public:
*/ */
bool connect_server(NDB_SOCKET_TYPE sockfd); 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); 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 * Remove all transporters
*/ */
......
...@@ -124,6 +124,15 @@ Transporter::connect_client() { ...@@ -124,6 +124,15 @@ Transporter::connect_client() {
else else
sockfd= m_socket_client->connect(); 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) if (sockfd == NDB_INVALID_SOCKET)
return false; return false;
......
...@@ -44,6 +44,7 @@ public: ...@@ -44,6 +44,7 @@ public:
* Use isConnected() to check status * Use isConnected() to check status
*/ */
bool connect_client(); bool connect_client();
bool connect_client(NDB_SOCKET_TYPE sockfd);
bool connect_server(NDB_SOCKET_TYPE socket); bool connect_server(NDB_SOCKET_TYPE socket);
/** /**
......
...@@ -1365,6 +1365,8 @@ TransporterRegistry::add_transporter_interface(NodeId remoteNodeId, ...@@ -1365,6 +1365,8 @@ TransporterRegistry::add_transporter_interface(NodeId remoteNodeId,
bool bool
TransporterRegistry::start_service(SocketServer& socket_server) TransporterRegistry::start_service(SocketServer& socket_server)
{ {
struct ndb_mgm_reply mgm_reply;
DBUG_ENTER("TransporterRegistry::start_service"); DBUG_ENTER("TransporterRegistry::start_service");
if (m_transporter_interface.size() > 0 && !nodeIdSpecified) if (m_transporter_interface.size() > 0 && !nodeIdSpecified)
{ {
...@@ -1521,63 +1523,87 @@ TransporterRegistry::get_transporter(NodeId nodeId) { ...@@ -1521,63 +1523,87 @@ TransporterRegistry::get_transporter(NodeId nodeId) {
return theTransporters[nodeId]; return theTransporters[nodeId];
} }
NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(SocketClient *sc) bool TransporterRegistry::connect_client(NdbMgmHandle *h)
{ {
NdbMgmHandle h= ndb_mgm_create_handle(); DBUG_ENTER("TransporterRegistry::connect_client(NdbMgmHandle)");
struct ndb_mgm_reply mgm_reply;
if ( h == NULL ) Uint32 mgm_nodeid= ndb_mgm_get_mgmd_nodeid(*h);
{
return NDB_INVALID_SOCKET;
}
/** if(!mgm_nodeid)
* Set connectstring return false;
*/
{ Transporter * t = theTransporters[mgm_nodeid];
char c[100]; if (!t)
char *cs= &c[0]; return false;
unsigned len= strlen(sc->get_server_name())+20;
if( len > sizeof(c) ) DBUG_RETURN(t->connect_client(connect_ndb_mgmd(h)));
{ }
/*
* server name is long. malloc enough for it and the port number /**
* Given a connected NdbMgmHandle, turns it into a transporter
* and returns the socket.
*/ */
cs= (char*)malloc(len*sizeof(char)); NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(NdbMgmHandle *h)
if(!cs) {
{ struct ndb_mgm_reply mgm_reply;
ndb_mgm_destroy_handle(&h);
return NDB_INVALID_SOCKET;
}
}
snprintf(cs,len,"%s:%u",sc->get_server_name(),sc->get_port());
ndb_mgm_set_connectstring(h, cs);
if(cs != &c[0])
free(cs);
}
if(ndb_mgm_connect(h, 0, 0, 0)<0) if ( h==NULL || *h == NULL )
{ {
ndb_mgm_destroy_handle(&h);
return NDB_INVALID_SOCKET; return NDB_INVALID_SOCKET;
} }
for(unsigned int i=0;i < m_transporter_interface.size();i++) for(unsigned int i=0;i < m_transporter_interface.size();i++)
if (ndb_mgm_set_connection_int_parameter(h, if (m_transporter_interface[i].m_s_service_port < 0
&& ndb_mgm_set_connection_int_parameter(*h,
get_localNodeId(), get_localNodeId(),
m_transporter_interface[i].m_remote_nodeId, m_transporter_interface[i].m_remote_nodeId,
CFG_CONNECTION_SERVER_PORT, CFG_CONNECTION_SERVER_PORT,
m_transporter_interface[i].m_s_service_port, m_transporter_interface[i].m_s_service_port,
&mgm_reply) < 0) &mgm_reply) < 0)
{ {
ndb_mgm_destroy_handle(&h); ndb_mgm_destroy_handle(h);
return NDB_INVALID_SOCKET; 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); NDB_SOCKET_TYPE sockfd= ndb_mgm_convert_to_transporter(h);
if ( sockfd == NDB_INVALID_SOCKET) if ( sockfd == NDB_INVALID_SOCKET)
ndb_mgm_destroy_handle(&h); ndb_mgm_destroy_handle(h);
return sockfd; 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();
if ( h == NULL )
{
return NDB_INVALID_SOCKET;
}
/**
* Set connectstring
*/
{
BaseString cs;
cs.assfmt("%s:%u",sc->get_server_name(),sc->get_port());
ndb_mgm_set_connectstring(h, cs.c_str());
}
if(ndb_mgm_connect(h, 0, 0, 0)<0)
{
ndb_mgm_destroy_handle(&h);
return NDB_INVALID_SOCKET;
}
return connect_ndb_mgmd(&h);
}
template class Vector<TransporterRegistry::Transporter_interface>; template class Vector<TransporterRegistry::Transporter_interface>;
...@@ -190,6 +190,13 @@ int main(int argc, char** argv) ...@@ -190,6 +190,13 @@ int main(int argc, char** argv)
exit(-1); exit(-1);
} }
// Re-use the mgm handle as a transporter
if(!globalTransporterRegistry.connect_client(
theConfig->get_config_retriever()->get_mgmHandlePtr()))
ERROR_SET(fatal, ERR_INVALID_CONFIG,
"Connection to mgmd terminated before setup was complete",
"StopOnError missing");
if (!globalTransporterRegistry.start_clients()){ if (!globalTransporterRegistry.start_clients()){
ndbout_c("globalTransporterRegistry.start_clients() failed"); ndbout_c("globalTransporterRegistry.start_clients() failed");
exit(-1); exit(-1);
......
...@@ -189,7 +189,6 @@ Configuration::fetch_configuration(){ ...@@ -189,7 +189,6 @@ Configuration::fetch_configuration(){
} }
m_mgmd_port= 0; m_mgmd_port= 0;
m_mgmd_host= 0;
m_config_retriever= new ConfigRetriever(getConnectString(), m_config_retriever= new ConfigRetriever(getConnectString(),
NDB_VERSION, NODE_TYPE_DB); NDB_VERSION, NODE_TYPE_DB);
...@@ -211,7 +210,7 @@ Configuration::fetch_configuration(){ ...@@ -211,7 +210,7 @@ Configuration::fetch_configuration(){
} }
m_mgmd_port= m_config_retriever->get_mgmd_port(); m_mgmd_port= m_config_retriever->get_mgmd_port();
m_mgmd_host= m_config_retriever->get_mgmd_host(); m_mgmd_host.assign(m_config_retriever->get_mgmd_host());
ConfigRetriever &cr= *m_config_retriever; ConfigRetriever &cr= *m_config_retriever;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#ifndef Configuration_H #ifndef Configuration_H
#define Configuration_H #define Configuration_H
#include <util/BaseString.hpp>
#include <mgmapi.h> #include <mgmapi.h>
#include <ndb_types.h> #include <ndb_types.h>
...@@ -67,7 +68,7 @@ public: ...@@ -67,7 +68,7 @@ public:
const ndb_mgm_configuration_iterator * getOwnConfigIterator() const; const ndb_mgm_configuration_iterator * getOwnConfigIterator() const;
Uint32 get_mgmd_port() const {return m_mgmd_port;}; Uint32 get_mgmd_port() const {return m_mgmd_port;};
const char *get_mgmd_host() const {return m_mgmd_host;}; const char *get_mgmd_host() const {return m_mgmd_host.c_str();};
ConfigRetriever* get_config_retriever() { return m_config_retriever; }; ConfigRetriever* get_config_retriever() { return m_config_retriever; };
class LogLevel * m_logLevel; class LogLevel * m_logLevel;
...@@ -99,7 +100,7 @@ private: ...@@ -99,7 +100,7 @@ private:
bool _initialStart; bool _initialStart;
char * _connectString; char * _connectString;
Uint32 m_mgmd_port; Uint32 m_mgmd_port;
const char *m_mgmd_host; BaseString m_mgmd_host;
bool _daemonMode; bool _daemonMode;
void calcSizeAlt(class ConfigValues * ); void calcSizeAlt(class ConfigValues * );
......
...@@ -2189,23 +2189,54 @@ ndb_mgm_get_connection_int_parameter(NdbMgmHandle handle, ...@@ -2189,23 +2189,54 @@ ndb_mgm_get_connection_int_parameter(NdbMgmHandle handle,
extern "C" extern "C"
NDB_SOCKET_TYPE NDB_SOCKET_TYPE
ndb_mgm_convert_to_transporter(NdbMgmHandle handle) ndb_mgm_convert_to_transporter(NdbMgmHandle *handle)
{ {
NDB_SOCKET_TYPE s; NDB_SOCKET_TYPE s;
CHECK_HANDLE(handle, NDB_INVALID_SOCKET); CHECK_HANDLE((*handle), NDB_INVALID_SOCKET);
CHECK_CONNECTED(handle, NDB_INVALID_SOCKET); CHECK_CONNECTED((*handle), NDB_INVALID_SOCKET);
handle->connected= 0; // we pretend we're disconnected (*handle)->connected= 0; // we pretend we're disconnected
s= handle->socket; s= (*handle)->socket;
SocketOutputStream s_output(s); SocketOutputStream s_output(s);
s_output.println("transporter connect"); s_output.println("transporter connect");
s_output.println(""); 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; 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>*>; template class Vector<const ParserRow<ParserDummy>*>;
...@@ -266,6 +266,8 @@ ParserRow<MgmApiSession> commands[] = { ...@@ -266,6 +266,8 @@ ParserRow<MgmApiSession> commands[] = {
MGM_CMD("transporter connect", &MgmApiSession::transporter_connect, ""), MGM_CMD("transporter connect", &MgmApiSession::transporter_connect, ""),
MGM_CMD("get mgmd nodeid", &MgmApiSession::get_mgmd_nodeid, ""),
MGM_END() MGM_END()
}; };
...@@ -1554,5 +1556,13 @@ MgmApiSession::transporter_connect(Parser_t::Context &ctx, ...@@ -1554,5 +1556,13 @@ MgmApiSession::transporter_connect(Parser_t::Context &ctx,
m_mgmsrv.transporter_connect(s); 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 MutexVector<int>;
template class Vector<ParserRow<MgmApiSession> const*>; template class Vector<ParserRow<MgmApiSession> const*>;
...@@ -100,6 +100,8 @@ public: ...@@ -100,6 +100,8 @@ public:
void transporter_connect(Parser_t::Context &ctx, Properties const &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); void repCommand(Parser_t::Context &ctx, const class Properties &args);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment