changed mysqladmin.c to mysqladmin.cc

    no need for dvlags to have DEFINE_CXA_PURE_VIRTUAL anymore
    aligned the parsing of connectstring, retries for connect, allocation of nodeid for all cluster nodes
    removed all dependencies of LocalConfig, except for mgmapi internals
    enabled multiple management servrs to fetch data configurations from eachother
parent 22973f11
...@@ -28,6 +28,7 @@ bin_PROGRAMS = mysql mysqladmin mysqlcheck mysqlshow \ ...@@ -28,6 +28,7 @@ bin_PROGRAMS = mysql mysqladmin mysqlcheck mysqlshow \
noinst_HEADERS = sql_string.h completion_hash.h my_readline.h \ noinst_HEADERS = sql_string.h completion_hash.h my_readline.h \
client_priv.h client_priv.h
mysql_SOURCES = mysql.cc readline.cc sql_string.cc completion_hash.cc mysql_SOURCES = mysql.cc readline.cc sql_string.cc completion_hash.cc
mysqladmin_SOURCES = mysqladmin.cc
mysql_LDADD = @readline_link@ @TERMCAP_LIB@ $(LDADD) $(CXXLDFLAGS) mysql_LDADD = @readline_link@ @TERMCAP_LIB@ $(LDADD) $(CXXLDFLAGS)
mysqlbinlog_LDADD = $(LDADD) $(CXXLDFLAGS) mysqlbinlog_LDADD = $(LDADD) $(CXXLDFLAGS)
mysql_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) $(DEPLIB) mysql_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) $(DEPLIB)
......
...@@ -1287,9 +1287,6 @@ static my_bool wait_pidfile(char *pidfile, time_t last_modified, ...@@ -1287,9 +1287,6 @@ static my_bool wait_pidfile(char *pidfile, time_t last_modified,
} }
DBUG_RETURN(error); DBUG_RETURN(error);
} }
#ifdef HAVE_NDBCLUSTER_DB
/* lib linked in contains c++ code */
#ifdef __GNUC__ #ifdef __GNUC__
FIX_GCC_LINKING_PROBLEM FIX_GCC_LINKING_PROBLEM
#endif #endif
#endif
...@@ -399,7 +399,6 @@ then ...@@ -399,7 +399,6 @@ then
then then
if $CXX -v 2>&1 | grep 'version 3' > /dev/null 2>&1 if $CXX -v 2>&1 | grep 'version 3' > /dev/null 2>&1
then then
CFLAGS="$CFLAGS -DDEFINE_CXA_PURE_VIRTUAL"
CXXFLAGS="$CXXFLAGS -DUSE_MYSYS_NEW -DDEFINE_CXA_PURE_VIRTUAL" CXXFLAGS="$CXXFLAGS -DUSE_MYSYS_NEW -DDEFINE_CXA_PURE_VIRTUAL"
fi fi
fi fi
......
...@@ -356,11 +356,28 @@ extern "C" { ...@@ -356,11 +356,28 @@ extern "C" {
/** /**
* Create a handle to a management server * Create a handle to a management server
* *
* @param connect_string Connect string to the management server,
*
* @return A management handle<br> * @return A management handle<br>
* or NULL if no management handle could be created. * or NULL if no management handle could be created.
*/ */
NdbMgmHandle ndb_mgm_create_handle(); NdbMgmHandle ndb_mgm_create_handle();
/**
* Set connecst string to management server
*
* @param handle Management handle
* @param connect_string Connect string to the management server,
*
* @return -1 on error.
*/
int ndb_mgm_set_connectstring(NdbMgmHandle handle,
const char *connect_string);
int ndb_mgm_get_configuration_nodeid(NdbMgmHandle handle);
int ndb_mgm_get_connected_port(NdbMgmHandle handle);
const char *ndb_mgm_get_connected_host(NdbMgmHandle handle);
/** /**
* Destroy a management server handle * Destroy a management server handle
* *
...@@ -378,11 +395,10 @@ extern "C" { ...@@ -378,11 +395,10 @@ extern "C" {
* Connect to a management server * Connect to a management server
* *
* @param handle Management handle. * @param handle Management handle.
* @param mgmsrv Hostname and port of the management server,
* "hostname:port".
* @return -1 on error. * @return -1 on error.
*/ */
int ndb_mgm_connect(NdbMgmHandle handle, const char * mgmsrv); int ndb_mgm_connect(NdbMgmHandle handle, int no_retries,
int retry_delay_in_seconds, int verbose);
/** /**
* Disconnect from a management server * Disconnect from a management server
...@@ -709,9 +725,7 @@ extern "C" { ...@@ -709,9 +725,7 @@ extern "C" {
void ndb_mgm_destroy_configuration(struct ndb_mgm_configuration *); void ndb_mgm_destroy_configuration(struct ndb_mgm_configuration *);
int ndb_mgm_alloc_nodeid(NdbMgmHandle handle, int ndb_mgm_alloc_nodeid(NdbMgmHandle handle,
unsigned version, unsigned version, int nodetype);
unsigned *pnodeid,
int nodetype);
/** /**
* Config iterator * Config iterator
*/ */
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <ndb_types.h> #include <ndb_types.h>
#include <mgmapi.h> #include <mgmapi.h>
#include <BaseString.hpp> #include <BaseString.hpp>
#include <LocalConfig.hpp>
/** /**
* @class ConfigRetriever * @class ConfigRetriever
...@@ -28,10 +27,11 @@ ...@@ -28,10 +27,11 @@
*/ */
class ConfigRetriever { class ConfigRetriever {
public: public:
ConfigRetriever(LocalConfig &local_config, Uint32 version, Uint32 nodeType); ConfigRetriever(const char * _connect_string,
Uint32 version, Uint32 nodeType);
~ConfigRetriever(); ~ConfigRetriever();
int do_connect(int exit_on_connect_failure= false); int do_connect(int no_retries, int retry_delay_in_seconds, int verbose);
/** /**
* Get configuration for current node. * Get configuration for current node.
...@@ -46,12 +46,14 @@ public: ...@@ -46,12 +46,14 @@ public:
*/ */
struct ndb_mgm_configuration * getConfig(); struct ndb_mgm_configuration * getConfig();
void resetError();
int hasError();
const char * getErrorString(); const char * getErrorString();
/** /**
* @return Node id of this node (as stated in local config or connectString) * @return Node id of this node (as stated in local config or connectString)
*/ */
Uint32 allocNodeId(); Uint32 allocNodeId(int no_retries, int retry_delay_in_seconds);
/** /**
* Get config using socket * Get config using socket
...@@ -68,22 +70,26 @@ public: ...@@ -68,22 +70,26 @@ public:
*/ */
bool verifyConfig(const struct ndb_mgm_configuration *, Uint32 nodeid); bool verifyConfig(const struct ndb_mgm_configuration *, Uint32 nodeid);
Uint32 get_mgmd_port() const {return m_mgmd_port;}; Uint32 get_mgmd_port() const;
const char *get_mgmd_host() const {return m_mgmd_host;}; const char *get_mgmd_host() const;
Uint32 get_configuration_nodeid() const;
private: private:
BaseString errorString; BaseString errorString;
enum ErrorType { enum ErrorType {
CR_ERROR = 0, CR_NO_ERROR = 0,
CR_RETRY = 1 CR_ERROR = 1,
CR_RETRY = 2
}; };
ErrorType latestErrorType; ErrorType latestErrorType;
void setError(ErrorType, const char * errorMsg); void setError(ErrorType, const char * errorMsg);
struct LocalConfig& _localConfig;
Uint32 _ownNodeId; Uint32 _ownNodeId;
/*
Uint32 m_mgmd_port; Uint32 m_mgmd_port;
const char *m_mgmd_host; const char *m_mgmd_host;
*/
Uint32 m_version; Uint32 m_version;
Uint32 m_node_type; Uint32 m_node_type;
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#define CLUSTER_CONNECTION_HPP #define CLUSTER_CONNECTION_HPP
class TransporterFacade; class TransporterFacade;
class LocalConfig;
class ConfigRetriever; class ConfigRetriever;
class NdbThread; class NdbThread;
...@@ -38,7 +37,6 @@ private: ...@@ -38,7 +37,6 @@ private:
void connect_thread(); void connect_thread();
char *m_connect_string; char *m_connect_string;
TransporterFacade *m_facade; TransporterFacade *m_facade;
LocalConfig *m_local_config;
ConfigRetriever *m_config_retriever; ConfigRetriever *m_config_retriever;
NdbThread *m_connect_thread; NdbThread *m_connect_thread;
int (*m_connect_callback)(void); int (*m_connect_callback)(void);
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <ConfigRetriever.hpp> #include <ConfigRetriever.hpp>
#include <SocketServer.hpp> #include <SocketServer.hpp>
#include "LocalConfig.hpp"
#include <NdbSleep.h> #include <NdbSleep.h>
#include <NdbOut.hpp> #include <NdbOut.hpp>
...@@ -45,90 +44,62 @@ ...@@ -45,90 +44,62 @@
//**************************************************************************** //****************************************************************************
//**************************************************************************** //****************************************************************************
ConfigRetriever::ConfigRetriever(LocalConfig &local_config, ConfigRetriever::ConfigRetriever(const char * _connect_string,
Uint32 version, Uint32 node_type) Uint32 version, Uint32 node_type)
: _localConfig(local_config)
{ {
m_handle= 0;
m_version = version; m_version = version;
m_node_type = node_type; m_node_type = node_type;
_ownNodeId = _localConfig._ownNodeId; _ownNodeId= 0;
}
m_handle= ndb_mgm_create_handle();
ConfigRetriever::~ConfigRetriever(){ if (m_handle == 0) {
setError(CR_ERROR, "Unable to allocate mgm handle");
return;
}
if (ndb_mgm_set_connectstring(m_handle, _connect_string))
{
setError(CR_ERROR, ndb_mgm_get_latest_error_desc(m_handle));
return;
}
resetError();
}
ConfigRetriever::~ConfigRetriever()
{
if (m_handle) { if (m_handle) {
ndb_mgm_disconnect(m_handle); ndb_mgm_disconnect(m_handle);
ndb_mgm_destroy_handle(&m_handle); ndb_mgm_destroy_handle(&m_handle);
} }
} }
Uint32
ConfigRetriever::get_configuration_nodeid() const
{
return ndb_mgm_get_configuration_nodeid(m_handle);
}
Uint32 ConfigRetriever::get_mgmd_port() const
{
return ndb_mgm_get_connected_port(m_handle);
}
const char *ConfigRetriever::get_mgmd_host() const
{
return ndb_mgm_get_connected_host(m_handle);
}
//**************************************************************************** //****************************************************************************
//**************************************************************************** //****************************************************************************
int int
ConfigRetriever::do_connect(int exit_on_connect_failure){ ConfigRetriever::do_connect(int no_retries,
int retry_delay_in_seconds, int verbose)
m_mgmd_port= 0; {
m_mgmd_host= 0; return
(ndb_mgm_connect(m_handle,no_retries,retry_delay_in_seconds,verbose)==0) ?
if(!m_handle) 0 : -1;
m_handle= ndb_mgm_create_handle();
if (m_handle == 0) {
setError(CR_ERROR, "Unable to allocate mgm handle");
return -1;
}
int retry = 1;
int retry_max = 12; // Max number of retry attempts
int retry_interval= 5; // Seconds between each retry
while(retry < retry_max){
Uint32 type = CR_ERROR;
BaseString tmp;
for (unsigned int i = 0; i<_localConfig.ids.size(); i++){
MgmtSrvrId * m = &_localConfig.ids[i];
DBUG_PRINT("info",("trying %s:%d",
m->name.c_str(),
m->port));
switch(m->type){
case MgmId_TCP:
tmp.assfmt("%s:%d", m->name.c_str(), m->port);
if (ndb_mgm_connect(m_handle, tmp.c_str()) == 0) {
m_mgmd_port= m->port;
m_mgmd_host= m->name.c_str();
DBUG_PRINT("info",("connected to ndb_mgmd at %s:%d",
m_mgmd_host,
m_mgmd_port));
return 0;
}
setError(CR_RETRY, ndb_mgm_get_latest_error_desc(m_handle));
case MgmId_File:
break;
}
}
if(latestErrorType == CR_RETRY){
DBUG_PRINT("info",("CR_RETRY"));
if (exit_on_connect_failure)
return 1;
REPORT_WARNING("Failed to retrieve cluster configuration");
ndbout << "(Cause of failure: " << getErrorString() << ")" << endl;
ndbout << "Attempt " << retry << " of " << retry_max << ". "
<< "Trying again in "<< retry_interval <<" seconds..."
<< endl << endl;
NdbSleep_SecSleep(retry_interval);
} else {
break;
}
retry++;
}
ndb_mgm_destroy_handle(&m_handle);
m_handle= 0;
m_mgmd_port= 0;
m_mgmd_host= 0;
return -1;
} }
//**************************************************************************** //****************************************************************************
...@@ -140,22 +111,9 @@ ConfigRetriever::getConfig() { ...@@ -140,22 +111,9 @@ ConfigRetriever::getConfig() {
struct ndb_mgm_configuration * p = 0; struct ndb_mgm_configuration * p = 0;
if(m_handle != 0){ if(m_handle != 0)
p = getConfig(m_handle); p = getConfig(m_handle);
} else {
for (unsigned int i = 0; i<_localConfig.ids.size(); i++){
MgmtSrvrId * m = &_localConfig.ids[i];
switch(m->type){
case MgmId_File:
p = getConfig(m->name.c_str());
break;
case MgmId_TCP:
break;
}
if(p)
break;
}
}
if(p == 0) if(p == 0)
return 0; return 0;
...@@ -227,6 +185,16 @@ ConfigRetriever::setError(ErrorType et, const char * s){ ...@@ -227,6 +185,16 @@ ConfigRetriever::setError(ErrorType et, const char * s){
latestErrorType = et; latestErrorType = et;
} }
void
ConfigRetriever::resetError(){
setError(CR_NO_ERROR,0);
}
int
ConfigRetriever::hasError()
{
return latestErrorType != CR_NO_ERROR;
}
const char * const char *
ConfigRetriever::getErrorString(){ ConfigRetriever::getErrorString(){
...@@ -341,16 +309,23 @@ ConfigRetriever::verifyConfig(const struct ndb_mgm_configuration * conf, Uint32 ...@@ -341,16 +309,23 @@ ConfigRetriever::verifyConfig(const struct ndb_mgm_configuration * conf, Uint32
} }
Uint32 Uint32
ConfigRetriever::allocNodeId(){ ConfigRetriever::allocNodeId(int no_retries, int retry_delay_in_seconds)
unsigned nodeid= _ownNodeId; {
_ownNodeId= 0;
if(m_handle != 0){ if(m_handle != 0)
int res= ndb_mgm_alloc_nodeid(m_handle, m_version, &nodeid, m_node_type); {
if(res != 0) { while (1)
{
int res= ndb_mgm_alloc_nodeid(m_handle, m_version, m_node_type);
if(res >= 0)
return _ownNodeId= (Uint32)res;
if (no_retries == 0)
break;
no_retries--;
NdbSleep_SecSleep(retry_delay_in_seconds);
}
setError(CR_ERROR, ndb_mgm_get_latest_error_desc(m_handle)); setError(CR_ERROR, ndb_mgm_get_latest_error_desc(m_handle));
} else
setError(CR_ERROR, "management server handle not initialized");
return 0; return 0;
}
}
return _ownNodeId= nodeid;
} }
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include <ndb_version.h> #include <ndb_version.h>
#include "Configuration.hpp" #include "Configuration.hpp"
#include <LocalConfig.hpp>
#include <TransporterRegistry.hpp> #include <TransporterRegistry.hpp>
#include "vm/SimBlockList.hpp" #include "vm/SimBlockList.hpp"
...@@ -69,16 +68,9 @@ int main(int argc, char** argv) ...@@ -69,16 +68,9 @@ int main(int argc, char** argv)
return NRT_Default; return NRT_Default;
} }
LocalConfig local_config;
if (!local_config.init(theConfig->getConnectString(),0)){
local_config.printError();
local_config.printUsage();
return NRT_Default;
}
{ // Do configuration { // Do configuration
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
theConfig->fetch_configuration(local_config); theConfig->fetch_configuration();
} }
chdir(NdbConfig_get_path(0)); chdir(NdbConfig_get_path(0));
...@@ -141,7 +133,7 @@ int main(int argc, char** argv) ...@@ -141,7 +133,7 @@ int main(int argc, char** argv)
exit(0); exit(0);
} }
g_eventLogger.info("Ndb has terminated (pid %d) restarting", child); g_eventLogger.info("Ndb has terminated (pid %d) restarting", child);
theConfig->fetch_configuration(local_config); theConfig->fetch_configuration();
} }
g_eventLogger.info("Angel pid: %d ndb pid: %d", getppid(), getpid()); g_eventLogger.info("Angel pid: %d ndb pid: %d", getppid(), getpid());
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <ndb_global.h> #include <ndb_global.h>
#include <ndb_opts.h> #include <ndb_opts.h>
#include <LocalConfig.hpp>
#include "Configuration.hpp" #include "Configuration.hpp"
#include <ErrorHandlingMacros.hpp> #include <ErrorHandlingMacros.hpp>
#include "GlobalData.hpp" #include "GlobalData.hpp"
...@@ -189,7 +188,7 @@ Configuration::closeConfiguration(){ ...@@ -189,7 +188,7 @@ Configuration::closeConfiguration(){
} }
void void
Configuration::fetch_configuration(LocalConfig &local_config){ Configuration::fetch_configuration(){
/** /**
* Fetch configuration from management server * Fetch configuration from management server
*/ */
...@@ -199,8 +198,17 @@ Configuration::fetch_configuration(LocalConfig &local_config){ ...@@ -199,8 +198,17 @@ Configuration::fetch_configuration(LocalConfig &local_config){
m_mgmd_port= 0; m_mgmd_port= 0;
m_mgmd_host= 0; m_mgmd_host= 0;
m_config_retriever= new ConfigRetriever(local_config, NDB_VERSION, NODE_TYPE_DB); m_config_retriever= new ConfigRetriever(getConnectString(),
if(m_config_retriever->do_connect() == -1){ NDB_VERSION, NODE_TYPE_DB);
if (m_config_retriever->hasError())
{
ERROR_SET(fatal, ERR_INVALID_CONFIG,
"Could not connect initialize handle to management server",
m_config_retriever->getErrorString());
}
if(m_config_retriever->do_connect(12,5,1) == -1){
const char * s = m_config_retriever->getErrorString(); const char * s = m_config_retriever->getErrorString();
if(s == 0) if(s == 0)
s = "No error given!"; s = "No error given!";
...@@ -215,13 +223,7 @@ Configuration::fetch_configuration(LocalConfig &local_config){ ...@@ -215,13 +223,7 @@ Configuration::fetch_configuration(LocalConfig &local_config){
ConfigRetriever &cr= *m_config_retriever; ConfigRetriever &cr= *m_config_retriever;
if((globalData.ownId = cr.allocNodeId()) == 0){ globalData.ownId = cr.allocNodeId(2 /*retry*/,3 /*delay*/);
for(Uint32 i = 0; i<3; i++){
NdbSleep_SecSleep(3);
if((globalData.ownId = cr.allocNodeId()) != 0)
break;
}
}
if(globalData.ownId == 0){ if(globalData.ownId == 0){
ERROR_SET(fatal, ERR_INVALID_CONFIG, ERROR_SET(fatal, ERR_INVALID_CONFIG,
...@@ -599,7 +601,8 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ ...@@ -599,7 +601,8 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){
Uint32 noOfTCScanRecords = noOfScanRecords; Uint32 noOfTCScanRecords = noOfScanRecords;
{ {
Uint32 noOfAccTables= noOfTables + noOfUniqueHashIndexes; Uint32 noOfAccTables= noOfTables + noOfUniqueHashIndexes *
noOfOrderedIndexes /* should be removed */;
/** /**
* Acc Size Alt values * Acc Size Alt values
*/ */
...@@ -758,13 +761,14 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ ...@@ -758,13 +761,14 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){
* Tux Size Alt values * Tux Size Alt values
*/ */
cfg.put(CFG_TUX_INDEX, cfg.put(CFG_TUX_INDEX,
noOfOrderedIndexes); noOfMetaTables /*noOfOrderedIndexes*/);
cfg.put(CFG_TUX_FRAGMENT, cfg.put(CFG_TUX_FRAGMENT,
2 * NO_OF_FRAG_PER_NODE * noOfOrderedIndexes * noOfReplicas); 2 * NO_OF_FRAG_PER_NODE * noOfMetaTables /*noOfOrderedIndexes*/ *
noOfReplicas);
cfg.put(CFG_TUX_ATTRIBUTE, cfg.put(CFG_TUX_ATTRIBUTE,
noOfOrderedIndexes * 4); noOfMetaTables /*noOfOrderedIndexes*/ * 4);
cfg.put(CFG_TUX_SCAN_OP, noOfLocalScanRecords); cfg.put(CFG_TUX_SCAN_OP, noOfLocalScanRecords);
} }
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include <ndb_types.h> #include <ndb_types.h>
class ConfigRetriever; class ConfigRetriever;
class LocalConfig;
class Configuration { class Configuration {
public: public:
...@@ -33,7 +32,7 @@ public: ...@@ -33,7 +32,7 @@ public:
*/ */
bool init(int argc, char** argv); bool init(int argc, char** argv);
void fetch_configuration(LocalConfig &local_config); void fetch_configuration();
void setupConfiguration(); void setupConfiguration();
void closeConfiguration(); void closeConfiguration();
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <LocalConfig.hpp> #include "LocalConfig.hpp"
#include <NdbEnv.h> #include <NdbEnv.h>
#include <NdbConfig.h> #include <NdbConfig.h>
#include <NdbAutoPtr.hpp> #include <NdbAutoPtr.hpp>
...@@ -294,4 +294,19 @@ LocalConfig::readConnectString(const char * connectString, ...@@ -294,4 +294,19 @@ LocalConfig::readConnectString(const char * connectString,
return return_value; return return_value;
} }
char *
LocalConfig::makeConnectString(char *buf, int sz)
{
int p= BaseString::snprintf(buf,sz,"nodeid=%d", _ownNodeId);
for (int i = 0; (i < ids.size()) && (sz-p > 0); i++)
{
if (ids[i].type != MgmId_TCP)
continue;
p+=BaseString::snprintf(buf+p,sz-p,",%s:%d",
ids[i].name.c_str(), ids[i].port);
}
buf[sz-1]=0;
return buf;
}
template class Vector<MgmtSrvrId>; template class Vector<MgmtSrvrId>;
...@@ -61,6 +61,7 @@ struct LocalConfig { ...@@ -61,6 +61,7 @@ struct LocalConfig {
bool parseHostName(const char *buf); bool parseHostName(const char *buf);
bool parseFileName(const char *buf); bool parseFileName(const char *buf);
bool parseString(const char *buf, BaseString &err); bool parseString(const char *buf, BaseString &err);
char * makeConnectString(char *buf, int sz);
}; };
#endif // LocalConfig_H #endif // LocalConfig_H
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <LocalConfig.hpp> #include <LocalConfig.hpp>
#include <NdbAutoPtr.hpp> #include <NdbAutoPtr.hpp>
#include <NdbSleep.h>
#include <NdbTCP.h> #include <NdbTCP.h>
#include "mgmapi.h" #include "mgmapi.h"
#include "mgmapi_debug.h" #include "mgmapi_debug.h"
...@@ -83,8 +84,8 @@ typedef Parser<ParserDummy> Parser_t; ...@@ -83,8 +84,8 @@ typedef Parser<ParserDummy> Parser_t;
#define NDB_MGM_MAX_ERR_DESC_SIZE 256 #define NDB_MGM_MAX_ERR_DESC_SIZE 256
struct ndb_mgm_handle { struct ndb_mgm_handle {
char * hostname; char * connectstring;
unsigned short port; int cfg_i;
int connected; int connected;
int last_error; int last_error;
...@@ -95,7 +96,7 @@ struct ndb_mgm_handle { ...@@ -95,7 +96,7 @@ struct ndb_mgm_handle {
NDB_SOCKET_TYPE socket; NDB_SOCKET_TYPE socket;
char cfg_ptr[sizeof(LocalConfig)]; LocalConfig cfg;
#ifdef MGMAPI_LOG #ifdef MGMAPI_LOG
FILE* logfile; FILE* logfile;
...@@ -148,14 +149,16 @@ ndb_mgm_create_handle() ...@@ -148,14 +149,16 @@ ndb_mgm_create_handle()
h->connected = 0; h->connected = 0;
h->last_error = 0; h->last_error = 0;
h->last_error_line = 0; h->last_error_line = 0;
h->hostname = 0;
h->socket = NDB_INVALID_SOCKET; h->socket = NDB_INVALID_SOCKET;
h->read_timeout = 50000; h->read_timeout = 50000;
h->write_timeout = 100; h->write_timeout = 100;
h->cfg_i = 0;
new (h->cfg_ptr) LocalConfig;
strncpy(h->last_error_desc, "No error", NDB_MGM_MAX_ERR_DESC_SIZE); strncpy(h->last_error_desc, "No error", NDB_MGM_MAX_ERR_DESC_SIZE);
new (&(h->cfg)) LocalConfig;
h->cfg.init(0, 0);
#ifdef MGMAPI_LOG #ifdef MGMAPI_LOG
h->logfile = 0; h->logfile = 0;
#endif #endif
...@@ -163,6 +166,23 @@ ndb_mgm_create_handle() ...@@ -163,6 +166,23 @@ ndb_mgm_create_handle()
return h; return h;
} }
extern "C"
int
ndb_mgm_set_connectstring(NdbMgmHandle handle, const char * mgmsrv)
{
new (&(handle->cfg)) LocalConfig;
if (!handle->cfg.init(mgmsrv, 0) ||
handle->cfg.ids.size() == 0)
{
new (&(handle->cfg)) LocalConfig;
handle->cfg.init(0, 0); /* reset the LocalCongig */
SET_ERROR(handle, NDB_MGM_ILLEGAL_CONNECT_STRING, "");
return -1;
}
handle->cfg_i= 0;
return 0;
}
/** /**
* Destroy a handle * Destroy a handle
*/ */
...@@ -175,14 +195,13 @@ ndb_mgm_destroy_handle(NdbMgmHandle * handle) ...@@ -175,14 +195,13 @@ ndb_mgm_destroy_handle(NdbMgmHandle * handle)
if((* handle)->connected){ if((* handle)->connected){
ndb_mgm_disconnect(* handle); ndb_mgm_disconnect(* handle);
} }
my_free((* handle)->hostname,MYF(MY_ALLOW_ZERO_PTR));
#ifdef MGMAPI_LOG #ifdef MGMAPI_LOG
if ((* handle)->logfile != 0){ if ((* handle)->logfile != 0){
fclose((* handle)->logfile); fclose((* handle)->logfile);
(* handle)->logfile = 0; (* handle)->logfile = 0;
} }
#endif #endif
((LocalConfig*)((*handle)->cfg_ptr))->~LocalConfig(); (*handle)->cfg.~LocalConfig();
my_free((char*)* handle,MYF(MY_ALLOW_ZERO_PTR)); my_free((char*)* handle,MYF(MY_ALLOW_ZERO_PTR));
* handle = 0; * handle = 0;
} }
...@@ -314,7 +333,8 @@ ndb_mgm_call(NdbMgmHandle handle, const ParserRow<ParserDummy> *command_reply, ...@@ -314,7 +333,8 @@ ndb_mgm_call(NdbMgmHandle handle, const ParserRow<ParserDummy> *command_reply,
*/ */
extern "C" extern "C"
int int
ndb_mgm_connect(NdbMgmHandle handle, const char * mgmsrv) ndb_mgm_connect(NdbMgmHandle handle, int no_retries,
int retry_delay_in_seconds, int verbose)
{ {
SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_connect"); SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_connect");
CHECK_HANDLE(handle, -1); CHECK_HANDLE(handle, -1);
...@@ -331,36 +351,48 @@ ndb_mgm_connect(NdbMgmHandle handle, const char * mgmsrv) ...@@ -331,36 +351,48 @@ ndb_mgm_connect(NdbMgmHandle handle, const char * mgmsrv)
/** /**
* Do connect * Do connect
*/ */
LocalConfig *cfg= (LocalConfig*)(handle->cfg_ptr); LocalConfig &cfg= handle->cfg;
new (cfg) LocalConfig;
if (!cfg->init(mgmsrv, 0) ||
cfg->ids.size() == 0)
{
SET_ERROR(handle, NDB_MGM_ILLEGAL_CONNECT_STRING, "");
return -1;
}
NDB_SOCKET_TYPE sockfd= NDB_INVALID_SOCKET; NDB_SOCKET_TYPE sockfd= NDB_INVALID_SOCKET;
Uint32 i; Uint32 i;
for (i = 0; i < cfg->ids.size(); i++) while (sockfd == NDB_INVALID_SOCKET)
{ {
if (cfg->ids[i].type != MgmId_TCP) // do all the mgmt servers
for (i = 0; i < cfg.ids.size(); i++)
{
if (cfg.ids[i].type != MgmId_TCP)
continue; continue;
SocketClient s(cfg->ids[i].name.c_str(), cfg->ids[i].port); SocketClient s(cfg.ids[i].name.c_str(), cfg.ids[i].port);
sockfd = s.connect(); sockfd = s.connect();
if (sockfd != NDB_INVALID_SOCKET) if (sockfd != NDB_INVALID_SOCKET)
break; break;
} }
if (sockfd == NDB_INVALID_SOCKET) if (sockfd != NDB_INVALID_SOCKET)
{ break;
if (verbose > 0) {
char buf[1024];
ndbout_c("Unable to connect with connect string: %s",
cfg.makeConnectString(buf,sizeof(buf)));
verbose= -1;
}
if (no_retries == 0) {
char buf[1024];
setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__, setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__,
"Unable to connect using connectstring %s", mgmsrv); "Unable to connect with connect string: %s",
cfg.makeConnectString(buf,sizeof(buf)));
return -1; return -1;
} }
if (verbose == -1) {
ndbout << "retrying every " << retry_delay_in_seconds << " seconds:";
verbose= -2;
}
NdbSleep_SecSleep(retry_delay_in_seconds);
if (verbose == -2) {
ndbout << " " << no_retries;
}
no_retries--;
}
my_free(handle->hostname,MYF(MY_ALLOW_ZERO_PTR)); handle->cfg_i = i;
handle->hostname = my_strdup(cfg->ids[i].name.c_str(),MYF(MY_WME));
handle->port = cfg->ids[i].port;
handle->socket = sockfd; handle->socket = sockfd;
handle->connected = 1; handle->connected = 1;
...@@ -1068,7 +1100,9 @@ ndb_mgm_listen_event(NdbMgmHandle handle, int filter[]) ...@@ -1068,7 +1100,9 @@ ndb_mgm_listen_event(NdbMgmHandle handle, int filter[])
}; };
CHECK_HANDLE(handle, -1); CHECK_HANDLE(handle, -1);
SocketClient s(handle->hostname, handle->port); const char *hostname= ndb_mgm_get_connected_host(handle);
int port= ndb_mgm_get_connected_port(handle);
SocketClient s(hostname, port);
const NDB_SOCKET_TYPE sockfd = s.connect(); const NDB_SOCKET_TYPE sockfd = s.connect();
if (sockfd < 0) { if (sockfd < 0) {
setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__, setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__,
...@@ -1613,16 +1647,37 @@ ndb_mgm_destroy_configuration(struct ndb_mgm_configuration *cfg) ...@@ -1613,16 +1647,37 @@ ndb_mgm_destroy_configuration(struct ndb_mgm_configuration *cfg)
extern "C" extern "C"
int int
ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, unsigned *pnodeid, int nodetype) ndb_mgm_get_configuration_nodeid(NdbMgmHandle handle)
{
CHECK_HANDLE(handle, 0);
return handle->cfg._ownNodeId;
}
extern "C"
int ndb_mgm_get_connected_port(NdbMgmHandle handle)
{
return handle->cfg.ids[handle->cfg_i].port;
}
extern "C"
const char *ndb_mgm_get_connected_host(NdbMgmHandle handle)
{ {
return handle->cfg.ids[handle->cfg_i].name.c_str();
}
extern "C"
int
ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, int nodetype)
{
CHECK_HANDLE(handle, 0); CHECK_HANDLE(handle, 0);
CHECK_CONNECTED(handle, 0); CHECK_CONNECTED(handle, 0);
int nodeid= handle->cfg._ownNodeId;
Properties args; Properties args;
args.put("version", version); args.put("version", version);
args.put("nodetype", nodetype); args.put("nodetype", nodetype);
args.put("nodeid", *pnodeid); args.put("nodeid", nodeid);
args.put("user", "mysqld"); args.put("user", "mysqld");
args.put("password", "mysqld"); args.put("password", "mysqld");
args.put("public key", "a public key"); args.put("public key", "a public key");
...@@ -1638,26 +1693,29 @@ ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, unsigned *pnodei ...@@ -1638,26 +1693,29 @@ ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, unsigned *pnodei
prop= ndb_mgm_call(handle, reply, "get nodeid", &args); prop= ndb_mgm_call(handle, reply, "get nodeid", &args);
CHECK_REPLY(prop, -1); CHECK_REPLY(prop, -1);
int res= -1; nodeid= -1;
do { do {
const char * buf; const char * buf;
if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){ if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){
const char *hostname= ndb_mgm_get_connected_host(handle);
unsigned port= ndb_mgm_get_connected_port(handle);
BaseString err; BaseString err;
err.assfmt("Could not alloc node id at %s port %d: %s", err.assfmt("Could not alloc node id at %s port %d: %s",
handle->hostname, handle->port, buf); hostname, port, buf);
setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__, setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__,
err.c_str()); err.c_str());
break; break;
} }
if(!prop->get("nodeid", pnodeid) != 0){ Uint32 _nodeid;
if(!prop->get("nodeid", &_nodeid) != 0){
ndbout_c("ERROR Message: <nodeid Unspecified>\n"); ndbout_c("ERROR Message: <nodeid Unspecified>\n");
break; break;
} }
res= 0; nodeid= _nodeid;
}while(0); }while(0);
delete prop; delete prop;
return res; return nodeid;
} }
/***************************************************************************** /*****************************************************************************
......
...@@ -153,7 +153,6 @@ class CommandInterpreter { ...@@ -153,7 +153,6 @@ class CommandInterpreter {
NdbMgmHandle m_mgmsrv; NdbMgmHandle m_mgmsrv;
bool connected; bool connected;
const char *host;
int try_reconnect; int try_reconnect;
#ifdef HAVE_GLOBAL_REPLICATION #ifdef HAVE_GLOBAL_REPLICATION
NdbRepHandle m_repserver; NdbRepHandle m_repserver;
...@@ -193,7 +192,7 @@ extern "C" { ...@@ -193,7 +192,7 @@ extern "C" {
{ {
return (Ndb_mgmclient_handle) new Ndb_mgmclient(connect_string); return (Ndb_mgmclient_handle) new Ndb_mgmclient(connect_string);
} }
int ndb_mgmclient_execute(Ndb_mgmclient_handle h, int argc, const char** argv) int ndb_mgmclient_execute(Ndb_mgmclient_handle h, int argc, char** argv)
{ {
return ((Ndb_mgmclient*)h)->execute(argc, argv, 1); return ((Ndb_mgmclient*)h)->execute(argc, argv, 1);
} }
...@@ -226,7 +225,7 @@ extern "C" { ...@@ -226,7 +225,7 @@ extern "C" {
#include <util/InputStream.hpp> #include <util/InputStream.hpp>
#include <util/OutputStream.hpp> #include <util/OutputStream.hpp>
int Ndb_mgmclient::execute(int argc, const char** argv, int _try_reconnect) int Ndb_mgmclient::execute(int argc, char** argv, int _try_reconnect)
{ {
if (argc <= 0) if (argc <= 0)
return 0; return 0;
...@@ -379,15 +378,16 @@ CommandInterpreter::CommandInterpreter(const char *_host) ...@@ -379,15 +378,16 @@ CommandInterpreter::CommandInterpreter(const char *_host)
m_mgmsrv = ndb_mgm_create_handle(); m_mgmsrv = ndb_mgm_create_handle();
if(m_mgmsrv == NULL) { if(m_mgmsrv == NULL) {
ndbout_c("Cannot create handle to management server."); ndbout_c("Cannot create handle to management server.");
exit(-1);
}
if (ndb_mgm_set_connectstring(m_mgmsrv, _host))
{
printError(); printError();
exit(-1);
} }
connected = false; connected = false;
try_reconnect = 0; try_reconnect = 0;
if (_host)
host= my_strdup(_host,MYF(MY_WME));
else
host= 0;
#ifdef HAVE_GLOBAL_REPLICATION #ifdef HAVE_GLOBAL_REPLICATION
rep_host = NULL; rep_host = NULL;
m_repserver = NULL; m_repserver = NULL;
...@@ -402,8 +402,6 @@ CommandInterpreter::~CommandInterpreter() ...@@ -402,8 +402,6 @@ CommandInterpreter::~CommandInterpreter()
{ {
connected = false; connected = false;
ndb_mgm_destroy_handle(&m_mgmsrv); ndb_mgm_destroy_handle(&m_mgmsrv);
my_free((char *)host,MYF(MY_ALLOW_ZERO_PTR));
host = NULL;
} }
static bool static bool
...@@ -438,19 +436,9 @@ bool ...@@ -438,19 +436,9 @@ bool
CommandInterpreter::connect() CommandInterpreter::connect()
{ {
if(!connected) { if(!connected) {
int tries = try_reconnect; // tries == 0 => infinite if(!ndb_mgm_connect(m_mgmsrv, try_reconnect-1, 5, 1))
while(!connected) {
if(ndb_mgm_connect(m_mgmsrv, host) == -1) {
ndbout << "Cannot connect to management server (" << host << ").";
tries--;
if (tries == 0)
break;
ndbout << "Retrying in 5 seconds." << endl;
NdbSleep_SecSleep(5);
} else
connected = true; connected = true;
} }
}
return connected; return connected;
} }
......
...@@ -30,9 +30,10 @@ extern "C" int add_history(const char *command); /* From readline directory */ ...@@ -30,9 +30,10 @@ extern "C" int add_history(const char *command); /* From readline directory */
#include <NdbMain.h> #include <NdbMain.h>
#include <NdbHost.h> #include <NdbHost.h>
#include <BaseString.hpp>
#include <NdbOut.hpp>
#include <mgmapi.h> #include <mgmapi.h>
#include <ndb_version.h> #include <ndb_version.h>
#include <LocalConfig.hpp>
#include "ndb_mgmclient.hpp" #include "ndb_mgmclient.hpp"
......
...@@ -23,7 +23,7 @@ extern "C" { ...@@ -23,7 +23,7 @@ extern "C" {
typedef void* Ndb_mgmclient_handle; typedef void* Ndb_mgmclient_handle;
Ndb_mgmclient_handle ndb_mgmclient_handle_create(const char *connect_string); Ndb_mgmclient_handle ndb_mgmclient_handle_create(const char *connect_string);
int ndb_mgmclient_execute(Ndb_mgmclient_handle, int argc, const char** argv); int ndb_mgmclient_execute(Ndb_mgmclient_handle, int argc, char** argv);
int ndb_mgmclient_handle_destroy(Ndb_mgmclient_handle); int ndb_mgmclient_handle_destroy(Ndb_mgmclient_handle);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -24,7 +24,7 @@ public: ...@@ -24,7 +24,7 @@ public:
Ndb_mgmclient(const char*); Ndb_mgmclient(const char*);
~Ndb_mgmclient(); ~Ndb_mgmclient();
int execute(const char *_line, int _try_reconnect=-1); int execute(const char *_line, int _try_reconnect=-1);
int execute(int argc, const char** argv, int _try_reconnect=-1); int execute(int argc, char** argv, int _try_reconnect=-1);
int disconnect(); int disconnect();
private: private:
CommandInterpreter *m_cmd; CommandInterpreter *m_cmd;
......
...@@ -399,16 +399,20 @@ MgmtSrvr::getPort() const { ...@@ -399,16 +399,20 @@ MgmtSrvr::getPort() const {
} }
/* Constructor */ /* Constructor */
MgmtSrvr::MgmtSrvr(NodeId nodeId, int MgmtSrvr::init()
SocketServer *socket_server, {
const BaseString &configFilename, if ( _ownNodeId > 0)
LocalConfig &local_config, return 0;
Config * config): return -1;
}
MgmtSrvr::MgmtSrvr(SocketServer *socket_server,
const char *config_filename,
const char *connect_string) :
_blockNumber(1), // Hard coded block number since it makes it easy to send _blockNumber(1), // Hard coded block number since it makes it easy to send
// signals to other management servers. // signals to other management servers.
m_socket_server(socket_server), m_socket_server(socket_server),
_ownReference(0), _ownReference(0),
m_local_config(local_config),
theSignalIdleList(NULL), theSignalIdleList(NULL),
theWaitState(WAIT_SUBSCRIBE_CONF), theWaitState(WAIT_SUBSCRIBE_CONF),
m_statisticsListner(this) m_statisticsListner(this)
...@@ -416,6 +420,8 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId, ...@@ -416,6 +420,8 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
DBUG_ENTER("MgmtSrvr::MgmtSrvr"); DBUG_ENTER("MgmtSrvr::MgmtSrvr");
_ownNodeId= 0;
_config = NULL; _config = NULL;
_isStopThread = false; _isStopThread = false;
...@@ -426,11 +432,42 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId, ...@@ -426,11 +432,42 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
theFacade = 0; theFacade = 0;
m_newConfig = NULL; m_newConfig = NULL;
m_configFilename = configFilename; m_configFilename.assign(config_filename);
m_nextConfigGenerationNumber = 0; m_nextConfigGenerationNumber = 0;
_config = (config == 0 ? readConfig() : config); m_config_retriever= new ConfigRetriever(connect_string,
NDB_VERSION, NDB_MGM_NODE_TYPE_MGM);
// first try to allocate nodeid from another management server
if(m_config_retriever->do_connect(0,0,0) == 0)
{
int tmp_nodeid= 0;
tmp_nodeid= m_config_retriever->allocNodeId(0 /*retry*/,0 /*delay*/);
if (tmp_nodeid == 0)
{
ndbout_c(m_config_retriever->getErrorString());
exit(-1);
}
// read config from other managent server
_config= fetchConfig();
if (_config == 0)
{
ndbout << m_config_retriever->getErrorString() << endl;
exit(-1);
}
_ownNodeId= tmp_nodeid;
}
if (_ownNodeId == 0)
{
// read config locally
_config= readConfig();
if (_config == 0) {
ndbout << "Unable to read config file" << endl;
exit(-1);
}
}
theMgmtWaitForResponseCondPtr = NdbCondition_Create(); theMgmtWaitForResponseCondPtr = NdbCondition_Create();
...@@ -443,9 +480,11 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId, ...@@ -443,9 +480,11 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
nodeTypes[i] = (enum ndb_mgm_node_type)-1; nodeTypes[i] = (enum ndb_mgm_node_type)-1;
m_connect_address[i].s_addr= 0; m_connect_address[i].s_addr= 0;
} }
{ {
ndb_mgm_configuration_iterator * iter = ndb_mgm_create_configuration_iterator ndb_mgm_configuration_iterator
(config->m_configValues, CFG_SECTION_NODE); *iter = ndb_mgm_create_configuration_iterator(_config->m_configValues,
CFG_SECTION_NODE);
for(ndb_mgm_first(iter); ndb_mgm_valid(iter); ndb_mgm_next(iter)){ for(ndb_mgm_first(iter); ndb_mgm_valid(iter); ndb_mgm_next(iter)){
unsigned type, id; unsigned type, id;
if(ndb_mgm_get_int_parameter(iter, CFG_TYPE_OF_SECTION, &type) != 0) if(ndb_mgm_get_int_parameter(iter, CFG_TYPE_OF_SECTION, &type) != 0)
...@@ -478,8 +517,6 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId, ...@@ -478,8 +517,6 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
} }
_props = NULL; _props = NULL;
_ownNodeId= 0;
NodeId tmp= nodeId;
BaseString error_string; BaseString error_string;
if ((m_node_id_mutex = NdbMutex_Create()) == 0) if ((m_node_id_mutex = NdbMutex_Create()) == 0)
...@@ -488,43 +525,25 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId, ...@@ -488,43 +525,25 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
exit(-1); exit(-1);
} }
#if 0 if (_ownNodeId == 0) // we did not get node id from other server
char my_hostname[256]; {
struct sockaddr_in tmp_addr; NodeId tmp= m_config_retriever->get_configuration_nodeid();
SOCKET_SIZE_TYPE addrlen= sizeof(tmp_addr);
if (!g_no_nodeid_checks) {
if (gethostname(my_hostname, sizeof(my_hostname))) {
ndbout << "error: gethostname() - " << strerror(errno) << endl;
exit(-1);
}
if (Ndb_getInAddr(&(((sockaddr_in*)&tmp_addr)->sin_addr),my_hostname)) {
ndbout << "error: Ndb_getInAddr(" << my_hostname << ") - "
<< strerror(errno) << endl;
exit(-1);
}
}
if (!alloc_node_id(&tmp, NDB_MGM_NODE_TYPE_MGM,
(struct sockaddr *)&tmp_addr,
&addrlen, error_string)){
ndbout << "Unable to obtain requested nodeid: "
<< error_string.c_str() << endl;
exit(-1);
}
#else
if (!alloc_node_id(&tmp, NDB_MGM_NODE_TYPE_MGM, if (!alloc_node_id(&tmp, NDB_MGM_NODE_TYPE_MGM,
0, 0, error_string)){ 0, 0, error_string)){
ndbout << "Unable to obtain requested nodeid: " ndbout << "Unable to obtain requested nodeid: "
<< error_string.c_str() << endl; << error_string.c_str() << endl;
exit(-1); exit(-1);
} }
#endif
_ownNodeId = tmp; _ownNodeId = tmp;
}
{ {
DBUG_PRINT("info", ("verifyConfig")); DBUG_PRINT("info", ("verifyConfig"));
ConfigRetriever cr(m_local_config, NDB_VERSION, NDB_MGM_NODE_TYPE_MGM); if (!m_config_retriever->verifyConfig(_config->m_configValues,
if (!cr.verifyConfig(config->m_configValues, _ownNodeId)) { _ownNodeId))
ndbout << cr.getErrorString() << endl; {
ndbout << m_config_retriever->getErrorString() << endl;
exit(-1); exit(-1);
} }
} }
...@@ -657,6 +676,8 @@ MgmtSrvr::~MgmtSrvr() ...@@ -657,6 +676,8 @@ MgmtSrvr::~MgmtSrvr()
NdbThread_WaitFor(m_signalRecvThread, &res); NdbThread_WaitFor(m_signalRecvThread, &res);
NdbThread_Destroy(&m_signalRecvThread); NdbThread_Destroy(&m_signalRecvThread);
} }
if (m_config_retriever)
delete m_config_retriever;
} }
//**************************************************************************** //****************************************************************************
......
...@@ -175,11 +175,10 @@ public: ...@@ -175,11 +175,10 @@ public:
/* Constructor */ /* Constructor */
MgmtSrvr(NodeId nodeId, /* Local nodeid */ MgmtSrvr(SocketServer *socket_server,
SocketServer *socket_server, const char *config_filename, /* Where to save config */
const BaseString &config_filename, /* Where to save config */ const char *connect_string);
LocalConfig &local_config, /* Ndb.cfg filename */ int init();
Config * config);
NodeId getOwnNodeId() const {return _ownNodeId;}; NodeId getOwnNodeId() const {return _ownNodeId;};
/** /**
...@@ -538,7 +537,6 @@ private: ...@@ -538,7 +537,6 @@ private:
NdbMutex *m_configMutex; NdbMutex *m_configMutex;
const Config * _config; const Config * _config;
Config * m_newConfig; Config * m_newConfig;
LocalConfig &m_local_config;
BaseString m_configFilename; BaseString m_configFilename;
Uint32 m_nextConfigGenerationNumber; Uint32 m_nextConfigGenerationNumber;
...@@ -755,6 +753,9 @@ private: ...@@ -755,6 +753,9 @@ private:
Config *_props; Config *_props;
int send(class NdbApiSignal* signal, Uint32 node, Uint32 node_type); int send(class NdbApiSignal* signal, Uint32 node, Uint32 node_type);
ConfigRetriever *m_config_retriever;
public: public:
/** /**
* This method does not exist * This method does not exist
......
...@@ -272,30 +272,20 @@ MgmtSrvr::saveConfig(const Config *conf) { ...@@ -272,30 +272,20 @@ MgmtSrvr::saveConfig(const Config *conf) {
Config * Config *
MgmtSrvr::readConfig() { MgmtSrvr::readConfig() {
Config *conf = NULL; Config *conf;
if(m_configFilename.length() != 0) {
/* Use config file */
InitConfigFileParser parser; InitConfigFileParser parser;
conf = parser.parseConfig(m_configFilename.c_str()); conf = parser.parseConfig(m_configFilename.c_str());
if(conf == NULL) {
/* Try to get configuration from other MGM server */
return fetchConfig();
}
}
return conf; return conf;
} }
Config * Config *
MgmtSrvr::fetchConfig() { MgmtSrvr::fetchConfig() {
ConfigRetriever cr(m_local_config, NDB_VERSION, NODE_TYPE_MGM); struct ndb_mgm_configuration * tmp = m_config_retriever->getConfig();
struct ndb_mgm_configuration * tmp = cr.getConfig();
if(tmp != 0){ if(tmp != 0){
Config * conf = new Config(); Config * conf = new Config();
conf->m_configValues = tmp; conf->m_configValues = tmp;
return conf; return conf;
} }
return 0; return 0;
} }
......
...@@ -62,7 +62,6 @@ struct MgmGlobals { ...@@ -62,7 +62,6 @@ struct MgmGlobals {
int non_interactive; int non_interactive;
int interactive; int interactive;
const char * config_filename; const char * config_filename;
const char * local_config_filename;
/** Stuff found in environment or in local config */ /** Stuff found in environment or in local config */
NodeId localNodeId; NodeId localNodeId;
...@@ -70,9 +69,6 @@ struct MgmGlobals { ...@@ -70,9 +69,6 @@ struct MgmGlobals {
char * interface_name; char * interface_name;
int port; int port;
/** The configuration of the cluster */
Config * cluster_config;
/** The Mgmt Server */ /** The Mgmt Server */
MgmtSrvr * mgmObject; MgmtSrvr * mgmObject;
...@@ -86,9 +82,6 @@ static MgmGlobals glob; ...@@ -86,9 +82,6 @@ static MgmGlobals glob;
/****************************************************************************** /******************************************************************************
* Function prototypes * Function prototypes
******************************************************************************/ ******************************************************************************/
static bool readLocalConfig();
static bool readGlobalConfig();
/** /**
* Global variables * Global variables
*/ */
...@@ -122,9 +115,6 @@ static struct my_option my_long_options[] = ...@@ -122,9 +115,6 @@ static struct my_option my_long_options[] =
{ "daemon", 'd', "Run ndb_mgmd in daemon mode (default)", { "daemon", 'd', "Run ndb_mgmd in daemon mode (default)",
(gptr*) &glob.daemon, (gptr*) &glob.daemon, 0, (gptr*) &glob.daemon, (gptr*) &glob.daemon, 0,
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 }, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 },
{ "l", 'l', "Specify configuration file connect string (default Ndb.cfg if available)",
(gptr*) &glob.local_config_filename, (gptr*) &glob.local_config_filename, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "interactive", 256, "Run interactive. Not supported but provided for testing purposes", { "interactive", 256, "Run interactive. Not supported but provided for testing purposes",
(gptr*) &glob.interactive, (gptr*) &glob.interactive, 0, (gptr*) &glob.interactive, (gptr*) &glob.interactive, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
...@@ -212,29 +202,16 @@ int main(int argc, char** argv) ...@@ -212,29 +202,16 @@ int main(int argc, char** argv)
MgmApiService * mapi = new MgmApiService(); MgmApiService * mapi = new MgmApiService();
/**************************** glob.mgmObject = new MgmtSrvr(glob.socketServer,
* Read configuration files * glob.config_filename,
****************************/ opt_connect_str);
LocalConfig local_config;
if(!local_config.init(opt_connect_str,glob.local_config_filename)){
local_config.printError();
goto error_end;
}
glob.localNodeId = local_config._ownNodeId;
if (!readGlobalConfig()) if (glob.mgmObject->init())
goto error_end; goto error_end;
glob.mgmObject = new MgmtSrvr(glob.localNodeId, glob.socketServer,
BaseString(glob.config_filename),
local_config,
glob.cluster_config);
chdir(NdbConfig_get_path(0)); chdir(NdbConfig_get_path(0));
glob.cluster_config = 0;
glob.localNodeId= glob.mgmObject->getOwnNodeId(); glob.localNodeId= glob.mgmObject->getOwnNodeId();
if (glob.localNodeId == 0) { if (glob.localNodeId == 0) {
goto error_end; goto error_end;
} }
...@@ -345,9 +322,7 @@ MgmGlobals::MgmGlobals(){ ...@@ -345,9 +322,7 @@ MgmGlobals::MgmGlobals(){
// Default values // Default values
port = 0; port = 0;
config_filename = NULL; config_filename = NULL;
local_config_filename = NULL;
interface_name = 0; interface_name = 0;
cluster_config = 0;
daemon = 1; daemon = 1;
non_interactive = 0; non_interactive = 0;
interactive = 0; interactive = 0;
...@@ -360,27 +335,6 @@ MgmGlobals::~MgmGlobals(){ ...@@ -360,27 +335,6 @@ MgmGlobals::~MgmGlobals(){
delete socketServer; delete socketServer;
if (mgmObject) if (mgmObject)
delete mgmObject; delete mgmObject;
if (cluster_config)
delete cluster_config;
if (interface_name) if (interface_name)
free(interface_name); free(interface_name);
} }
/**
* @fn readGlobalConfig
* @param glob : Global variables
* @return true if success, false otherwise.
*/
static bool
readGlobalConfig() {
if(glob.config_filename == NULL)
return false;
/* Use config file */
InitConfigFileParser parser;
glob.cluster_config = parser.parseConfig(glob.config_filename);
if(glob.cluster_config == 0){
return false;
}
return true;
}
...@@ -45,7 +45,6 @@ Ndb_cluster_connection::Ndb_cluster_connection(const char *connect_string) ...@@ -45,7 +45,6 @@ Ndb_cluster_connection::Ndb_cluster_connection(const char *connect_string)
else else
m_connect_string= 0; m_connect_string= 0;
m_config_retriever= 0; m_config_retriever= 0;
m_local_config= 0;
m_connect_thread= 0; m_connect_thread= 0;
m_connect_callback= 0; m_connect_callback= 0;
...@@ -125,38 +124,31 @@ int Ndb_cluster_connection::connect(int reconnect) ...@@ -125,38 +124,31 @@ int Ndb_cluster_connection::connect(int reconnect)
do { do {
if (m_config_retriever == 0) if (m_config_retriever == 0)
{ {
if (m_local_config == 0) { m_config_retriever=
m_local_config= new LocalConfig(); new ConfigRetriever(m_connect_string, NDB_VERSION, NODE_TYPE_API);
if (!m_local_config->init(m_connect_string,0)) { if (m_config_retriever->hasError())
ndbout_c("Configuration error: Unable to retrieve local config"); {
m_local_config->printError(); printf("Could not connect initialize handle to management server",
m_local_config->printUsage(); m_config_retriever->getErrorString());
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
} }
m_config_retriever=
new ConfigRetriever(*m_local_config, NDB_VERSION, NODE_TYPE_API);
}
else else
if (reconnect == 0) if (reconnect == 0)
DBUG_RETURN(0); DBUG_RETURN(0);
if (reconnect) if (reconnect)
{ {
int r= m_config_retriever->do_connect(1); int r= m_config_retriever->do_connect(0,0,0);
if (r == 1) if (r == 1)
DBUG_RETURN(1); // mgmt server not up yet DBUG_RETURN(1); // mgmt server not up yet
if (r == -1) if (r == -1)
break; break;
} }
else else
if(m_config_retriever->do_connect() == -1) if(m_config_retriever->do_connect(12,5,1) == -1)
break; break;
Uint32 nodeId = m_config_retriever->allocNodeId(); Uint32 nodeId = m_config_retriever->allocNodeId(4/*retries*/,3/*delay*/);
for(Uint32 i = 0; nodeId == 0 && i<5; i++){
NdbSleep_SecSleep(3);
nodeId = m_config_retriever->allocNodeId();
}
if(nodeId == 0) if(nodeId == 0)
break; break;
ndb_mgm_configuration * props = m_config_retriever->getConfig(); ndb_mgm_configuration * props = m_config_retriever->getConfig();
...@@ -200,8 +192,6 @@ Ndb_cluster_connection::~Ndb_cluster_connection() ...@@ -200,8 +192,6 @@ Ndb_cluster_connection::~Ndb_cluster_connection()
my_free(m_connect_string,MYF(MY_ALLOW_ZERO_PTR)); my_free(m_connect_string,MYF(MY_ALLOW_ZERO_PTR));
if (m_config_retriever) if (m_config_retriever)
delete m_config_retriever; delete m_config_retriever;
if (m_local_config)
delete m_local_config;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include <NdbOut.hpp> #include <NdbOut.hpp>
#include <NdbSleep.h> #include <NdbSleep.h>
#include <kernel/ndb_limits.h> #include <kernel/ndb_limits.h>
#include <LocalConfig.hpp>
#include <NDBT.hpp> #include <NDBT.hpp>
...@@ -85,39 +84,8 @@ int main(int argc, char** argv){ ...@@ -85,39 +84,8 @@ int main(int argc, char** argv){
char buf[255]; char buf[255];
_hostName = argv[0]; _hostName = argv[0];
if (_hostName == NULL){ if (_hostName == 0)
LocalConfig lcfg; _hostName= opt_connect_str;
if(!lcfg.init(opt_connect_str, 0))
{
lcfg.printError();
lcfg.printUsage();
g_err << "Error parsing local config file" << endl;
return NDBT_ProgramExit(NDBT_FAILED);
}
for (unsigned i = 0; i<lcfg.ids.size();i++)
{
MgmtSrvrId * m = &lcfg.ids[i];
switch(m->type){
case MgmId_TCP:
snprintf(buf, 255, "%s:%d", m->name.c_str(), m->port);
_hostName = buf;
break;
case MgmId_File:
break;
default:
break;
}
if (_hostName != NULL)
break;
}
if (_hostName == NULL)
{
g_err << "No management servers configured in local config file" << endl;
return NDBT_ProgramExit(NDBT_FAILED);
}
}
if (_no_contact) { if (_no_contact) {
if (waitClusterStatus(_hostName, NDB_MGM_NODE_STATUS_NO_CONTACT, _timeout) != 0) if (waitClusterStatus(_hostName, NDB_MGM_NODE_STATUS_NO_CONTACT, _timeout) != 0)
...@@ -216,7 +184,13 @@ waitClusterStatus(const char* _addr, ...@@ -216,7 +184,13 @@ waitClusterStatus(const char* _addr,
return -1; return -1;
} }
g_info << "Connecting to mgmsrv at " << _addr << endl; g_info << "Connecting to mgmsrv at " << _addr << endl;
if (ndb_mgm_connect(handle, _addr) == -1) { if (ndb_mgm_set_connectstring(handle, _addr))
{
MGMERR(handle);
g_err << "Connectstring " << _addr << " invalid" << endl;
return -1;
}
if (ndb_mgm_connect(handle,0,0,1)) {
MGMERR(handle); MGMERR(handle);
g_err << "Connection to " << _addr << " failed" << endl; g_err << "Connection to " << _addr << " failed" << endl;
return -1; return -1;
......
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