moved LocalConfig out of config retriver

parent 65629eb2
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
*/ */
class ConfigRetriever { class ConfigRetriever {
public: public:
ConfigRetriever(Uint32 version, Uint32 nodeType); ConfigRetriever(LocalConfig &local_config, Uint32 version, Uint32 nodeType);
~ConfigRetriever(); ~ConfigRetriever();
/** /**
...@@ -54,16 +54,6 @@ public: ...@@ -54,16 +54,6 @@ public:
const char * getErrorString(); const char * getErrorString();
/**
* Sets connectstring which can be used instead of local config file
*/
void setConnectString(const char * connectString);
/**
* Sets name of local config file (usually not needed)
*/
void setLocalConfigFileName(const char * connectString);
/** /**
* @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)
*/ */
...@@ -93,12 +83,9 @@ private: ...@@ -93,12 +83,9 @@ private:
void setError(ErrorType, const char * errorMsg); void setError(ErrorType, const char * errorMsg);
BaseString _localConfigFileName; struct LocalConfig& _localConfig;
struct LocalConfig _localConfig;
Uint32 _ownNodeId; Uint32 _ownNodeId;
BaseString m_connectString;
Uint32 m_version; Uint32 m_version;
Uint32 m_node_type; Uint32 m_node_type;
NdbMgmHandle m_handle; NdbMgmHandle m_handle;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#define CLUSTER_CONNECTION_HPP #define CLUSTER_CONNECTION_HPP
class TransporterFacade; class TransporterFacade;
class LocalConfig;
class ConfigRetriever; class ConfigRetriever;
class NdbThread; class NdbThread;
...@@ -37,6 +38,7 @@ private: ...@@ -37,6 +38,7 @@ 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);
......
...@@ -45,8 +45,10 @@ ...@@ -45,8 +45,10 @@
//**************************************************************************** //****************************************************************************
//**************************************************************************** //****************************************************************************
ConfigRetriever::ConfigRetriever(Uint32 version, Uint32 node_type) { ConfigRetriever::ConfigRetriever(LocalConfig &local_config,
Uint32 version, Uint32 node_type)
: _localConfig(local_config)
{
m_handle= 0; m_handle= 0;
m_version = version; m_version = version;
m_node_type = node_type; m_node_type = node_type;
...@@ -66,15 +68,6 @@ ConfigRetriever::~ConfigRetriever(){ ...@@ -66,15 +68,6 @@ ConfigRetriever::~ConfigRetriever(){
int int
ConfigRetriever::init() { ConfigRetriever::init() {
if (!_localConfig.init(m_connectString.c_str(),
_localConfigFileName.c_str())){
setError(CR_ERROR, "error in retrieving contact info for mgmtsrvr");
_localConfig.printError();
_localConfig.printUsage();
return -1;
}
return _ownNodeId = _localConfig._ownNodeId; return _ownNodeId = _localConfig._ownNodeId;
} }
...@@ -230,16 +223,6 @@ ConfigRetriever::getErrorString(){ ...@@ -230,16 +223,6 @@ ConfigRetriever::getErrorString(){
return errorString.c_str(); return errorString.c_str();
} }
void
ConfigRetriever::setLocalConfigFileName(const char * localConfigFileName) {
_localConfigFileName.assign(localConfigFileName ? localConfigFileName : "");
}
void
ConfigRetriever::setConnectString(const char * connectString) {
m_connectString.assign(connectString ? connectString : "");
}
bool bool
ConfigRetriever::verifyConfig(const struct ndb_mgm_configuration * conf, Uint32 nodeid){ ConfigRetriever::verifyConfig(const struct ndb_mgm_configuration * conf, Uint32 nodeid){
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#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"
...@@ -67,12 +68,19 @@ NDB_MAIN(ndb_kernel){ ...@@ -67,12 +68,19 @@ NDB_MAIN(ndb_kernel){
// Parse command line options // Parse command line options
Configuration* theConfig = globalEmulatorData.theConfiguration; Configuration* theConfig = globalEmulatorData.theConfiguration;
if(!theConfig->init(argc, argv)){ if(!theConfig->init(argc, argv)){
return 0; 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(); theConfig->fetch_configuration(local_config);
} }
chdir(NdbConfig_get_path(0)); chdir(NdbConfig_get_path(0));
...@@ -135,7 +143,7 @@ NDB_MAIN(ndb_kernel){ ...@@ -135,7 +143,7 @@ NDB_MAIN(ndb_kernel){
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(); theConfig->fetch_configuration(local_config);
} }
g_eventLogger.info("Angel pid: %d ndb pid: %d", getppid(), getpid()); g_eventLogger.info("Angel pid: %d ndb pid: %d", getppid(), getpid());
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <ndb_global.h> #include <ndb_global.h>
#include <LocalConfig.hpp>
#include "Configuration.hpp" #include "Configuration.hpp"
#include <ErrorHandlingMacros.hpp> #include <ErrorHandlingMacros.hpp>
#include "GlobalData.hpp" #include "GlobalData.hpp"
...@@ -184,7 +185,7 @@ Configuration::closeConfiguration(){ ...@@ -184,7 +185,7 @@ Configuration::closeConfiguration(){
} }
void void
Configuration::fetch_configuration(){ Configuration::fetch_configuration(LocalConfig &local_config){
/** /**
* Fetch configuration from management server * Fetch configuration from management server
*/ */
...@@ -192,8 +193,7 @@ Configuration::fetch_configuration(){ ...@@ -192,8 +193,7 @@ Configuration::fetch_configuration(){
delete m_config_retriever; delete m_config_retriever;
} }
m_config_retriever= new ConfigRetriever(NDB_VERSION, NODE_TYPE_DB); m_config_retriever= new ConfigRetriever(local_config, NDB_VERSION, NODE_TYPE_DB);
m_config_retriever->setConnectString(_connectString ? _connectString : "");
if(m_config_retriever->init() == -1 || if(m_config_retriever->init() == -1 ||
m_config_retriever->do_connect() == -1){ m_config_retriever->do_connect() == -1){
...@@ -416,6 +416,11 @@ Configuration::setRestartOnErrorInsert(int i){ ...@@ -416,6 +416,11 @@ Configuration::setRestartOnErrorInsert(int i){
m_restartOnErrorInsert = i; m_restartOnErrorInsert = i;
} }
const char *
Configuration::getConnectString() const {
return _connectString;
}
char * char *
Configuration::getConnectStringCopy() const { Configuration::getConnectStringCopy() const {
if(_connectString != 0) if(_connectString != 0)
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <ndb_types.h> #include <ndb_types.h>
class ConfigRetriever; class ConfigRetriever;
class LocalConfig;
class Configuration { class Configuration {
public: public:
...@@ -32,7 +33,7 @@ public: ...@@ -32,7 +33,7 @@ public:
*/ */
bool init(int argc, const char** argv); bool init(int argc, const char** argv);
void fetch_configuration(); void fetch_configuration(LocalConfig &local_config);
void setupConfiguration(); void setupConfiguration();
void closeConfiguration(); void closeConfiguration();
...@@ -54,6 +55,7 @@ public: ...@@ -54,6 +55,7 @@ public:
const char * programName() const; const char * programName() const;
const char * fileSystemPath() const; const char * fileSystemPath() const;
const char * backupFilePath() const; const char * backupFilePath() const;
const char * getConnectString() const;
char * getConnectStringCopy() const; char * getConnectStringCopy() const;
/** /**
......
...@@ -401,7 +401,7 @@ MgmtSrvr::getPort() const { ...@@ -401,7 +401,7 @@ MgmtSrvr::getPort() const {
/* Constructor */ /* Constructor */
MgmtSrvr::MgmtSrvr(NodeId nodeId, MgmtSrvr::MgmtSrvr(NodeId nodeId,
const BaseString &configFilename, const BaseString &configFilename,
const BaseString &ndb_config_filename, LocalConfig &local_config,
Config * config): Config * config):
_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.
...@@ -409,7 +409,9 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId, ...@@ -409,7 +409,9 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
m_allocated_resources(*this), m_allocated_resources(*this),
theSignalIdleList(NULL), theSignalIdleList(NULL),
theWaitState(WAIT_SUBSCRIBE_CONF), theWaitState(WAIT_SUBSCRIBE_CONF),
m_statisticsListner(this){ m_statisticsListner(this),
m_local_config(local_config)
{
DBUG_ENTER("MgmtSrvr::MgmtSrvr"); DBUG_ENTER("MgmtSrvr::MgmtSrvr");
...@@ -424,7 +426,6 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId, ...@@ -424,7 +426,6 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
m_newConfig = NULL; m_newConfig = NULL;
m_configFilename = configFilename; m_configFilename = configFilename;
m_localNdbConfigFilename = ndb_config_filename;
m_nextConfigGenerationNumber = 0; m_nextConfigGenerationNumber = 0;
...@@ -514,7 +515,7 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId, ...@@ -514,7 +515,7 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
{ {
DBUG_PRINT("info", ("verifyConfig")); DBUG_PRINT("info", ("verifyConfig"));
ConfigRetriever cr(NDB_VERSION, NDB_MGM_NODE_TYPE_MGM); ConfigRetriever cr(m_local_config, NDB_VERSION, NDB_MGM_NODE_TYPE_MGM);
if (!cr.verifyConfig(config->m_configValues, _ownNodeId)) { if (!cr.verifyConfig(config->m_configValues, _ownNodeId)) {
ndbout << cr.getErrorString() << endl; ndbout << cr.getErrorString() << endl;
exit(-1); exit(-1);
......
...@@ -173,7 +173,7 @@ public: ...@@ -173,7 +173,7 @@ public:
MgmtSrvr(NodeId nodeId, /* Local nodeid */ MgmtSrvr(NodeId nodeId, /* Local nodeid */
const BaseString &config_filename, /* Where to save config */ const BaseString &config_filename, /* Where to save config */
const BaseString &ndb_config_filename, /* Ndb.cfg filename */ LocalConfig &local_config, /* Ndb.cfg filename */
Config * config); Config * config);
NodeId getOwnNodeId() const {return _ownNodeId;}; NodeId getOwnNodeId() const {return _ownNodeId;};
...@@ -528,8 +528,8 @@ private: ...@@ -528,8 +528,8 @@ 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;
BaseString m_localNdbConfigFilename;
Uint32 m_nextConfigGenerationNumber; Uint32 m_nextConfigGenerationNumber;
NodeBitmask m_reserved_nodes; NodeBitmask m_reserved_nodes;
......
...@@ -288,8 +288,7 @@ MgmtSrvr::readConfig() { ...@@ -288,8 +288,7 @@ MgmtSrvr::readConfig() {
Config * Config *
MgmtSrvr::fetchConfig() { MgmtSrvr::fetchConfig() {
ConfigRetriever cr(NDB_VERSION, NODE_TYPE_MGM); ConfigRetriever cr(m_local_config, NDB_VERSION, NODE_TYPE_MGM);
cr.setLocalConfigFileName(m_localNdbConfigFilename.c_str());
struct ndb_mgm_configuration * tmp = cr.getConfig(); struct ndb_mgm_configuration * tmp = cr.getConfig();
if(tmp != 0){ if(tmp != 0){
Config * conf = new Config(); Config * conf = new Config();
......
...@@ -173,15 +173,19 @@ NDB_MAIN(mgmsrv){ ...@@ -173,15 +173,19 @@ NDB_MAIN(mgmsrv){
/**************************** /****************************
* Read configuration files * * Read configuration files *
****************************/ ****************************/
if (!readLocalConfig()) LocalConfig local_config;
if(!local_config.init(0,glob.local_config_filename)){
local_config.printError();
goto error_end; goto error_end;
}
glob.localNodeId = local_config._ownNodeId;
if (!readGlobalConfig()) if (!readGlobalConfig())
goto error_end; goto error_end;
glob.mgmObject = new MgmtSrvr(glob.localNodeId, glob.mgmObject = new MgmtSrvr(glob.localNodeId,
BaseString(glob.config_filename), BaseString(glob.config_filename),
BaseString(glob.local_config_filename == 0 ? local_config,
"" : glob.local_config_filename),
glob.cluster_config); glob.cluster_config);
chdir(NdbConfig_get_path(0)); chdir(NdbConfig_get_path(0));
...@@ -320,25 +324,6 @@ MgmGlobals::~MgmGlobals(){ ...@@ -320,25 +324,6 @@ MgmGlobals::~MgmGlobals(){
free(interface_name); free(interface_name);
} }
/**
* @fn readLocalConfig
* @param glob : Global variables
* @return true if success, false otherwise.
*/
static bool
readLocalConfig(){
// Read local config file
LocalConfig lc;
if(!lc.init(0,glob.local_config_filename)){
lc.printError();
return false;
}
glob.localNodeId = lc._ownNodeId;
return true;
}
/** /**
* @fn readGlobalConfig * @fn readGlobalConfig
* @param glob : Global variables * @param glob : Global variables
......
...@@ -236,7 +236,6 @@ public: ...@@ -236,7 +236,6 @@ public:
NdbMutex* theMutexPtr; NdbMutex* theMutexPtr;
private: private:
static TransporterFacade* theFacadeInstance; static TransporterFacade* theFacadeInstance;
static ConfigRetriever *s_config_retriever;
public: public:
GlobalDictCache m_globalDictCache; GlobalDictCache m_globalDictCache;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <ndb_global.h> #include <ndb_global.h>
#include <my_pthread.h> #include <my_pthread.h>
#include <my_sys.h>
#include <ndb_cluster_connection.hpp> #include <ndb_cluster_connection.hpp>
#include <TransporterFacade.hpp> #include <TransporterFacade.hpp>
...@@ -30,14 +31,18 @@ static int g_run_connect_thread= 0; ...@@ -30,14 +31,18 @@ static int g_run_connect_thread= 0;
Ndb_cluster_connection::Ndb_cluster_connection(const char *connect_string) Ndb_cluster_connection::Ndb_cluster_connection(const char *connect_string)
{ {
DBUG_ENTER("Ndb_cluster_connection");
DBUG_PRINT("enter",("Ndb_cluster_connection this=0x%x", this));
m_facade= TransporterFacade::theFacadeInstance= new TransporterFacade(); m_facade= TransporterFacade::theFacadeInstance= new TransporterFacade();
if (connect_string) if (connect_string)
m_connect_string= strdup(connect_string); m_connect_string= my_strdup(connect_string,MYF(MY_WME));
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;
DBUG_VOID_RETURN;
} }
extern "C" pthread_handler_decl(run_ndb_cluster_connection_connect_thread, me) extern "C" pthread_handler_decl(run_ndb_cluster_connection_connect_thread, me)
...@@ -99,8 +104,16 @@ int Ndb_cluster_connection::connect(int reconnect) ...@@ -99,8 +104,16 @@ int Ndb_cluster_connection::connect(int reconnect)
do { do {
if (m_config_retriever == 0) if (m_config_retriever == 0)
{ {
m_config_retriever= new ConfigRetriever(NDB_VERSION, NODE_TYPE_API); if (m_local_config == 0) {
m_config_retriever->setConnectString(m_connect_string); m_local_config= new LocalConfig();
if (m_local_config->init(m_connect_string,0)) {
ndbout << "Configuration error: Unable to retrieve local config" << endl;
m_local_config->printError();
m_local_config->printUsage();
DBUG_RETURN(-1);
}
}
m_config_retriever= new ConfigRetriever(*m_local_config, NDB_VERSION, NODE_TYPE_API);
if(m_config_retriever->init() == -1) if(m_config_retriever->init() == -1)
break; break;
} }
...@@ -145,6 +158,8 @@ int Ndb_cluster_connection::connect(int reconnect) ...@@ -145,6 +158,8 @@ int Ndb_cluster_connection::connect(int reconnect)
Ndb_cluster_connection::~Ndb_cluster_connection() Ndb_cluster_connection::~Ndb_cluster_connection()
{ {
DBUG_ENTER("~Ndb_cluster_connection");
DBUG_PRINT("enter",("~Ndb_cluster_connection this=0x%x", this));
TransporterFacade::stop_instance(); TransporterFacade::stop_instance();
if (m_connect_thread) if (m_connect_thread)
{ {
...@@ -161,10 +176,12 @@ Ndb_cluster_connection::~Ndb_cluster_connection() ...@@ -161,10 +176,12 @@ Ndb_cluster_connection::~Ndb_cluster_connection()
abort(); abort();
TransporterFacade::theFacadeInstance= 0; TransporterFacade::theFacadeInstance= 0;
} }
if (m_connect_string) my_free(m_connect_string,MYF(MY_ALLOW_ZERO_PTR));
free(m_connect_string);
if (m_config_retriever) if (m_config_retriever)
delete m_config_retriever; delete m_config_retriever;
if (m_local_config == 0)
delete m_local_config;
DBUG_VOID_RETURN;
} }
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