moved LocalConfig out of config retriver

parent 65629eb2
......@@ -28,7 +28,7 @@
*/
class ConfigRetriever {
public:
ConfigRetriever(Uint32 version, Uint32 nodeType);
ConfigRetriever(LocalConfig &local_config, Uint32 version, Uint32 nodeType);
~ConfigRetriever();
/**
......@@ -54,16 +54,6 @@ public:
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)
*/
......@@ -93,12 +83,9 @@ private:
void setError(ErrorType, const char * errorMsg);
BaseString _localConfigFileName;
struct LocalConfig _localConfig;
struct LocalConfig& _localConfig;
Uint32 _ownNodeId;
BaseString m_connectString;
Uint32 m_version;
Uint32 m_node_type;
NdbMgmHandle m_handle;
......
......@@ -19,6 +19,7 @@
#define CLUSTER_CONNECTION_HPP
class TransporterFacade;
class LocalConfig;
class ConfigRetriever;
class NdbThread;
......@@ -37,6 +38,7 @@ private:
void connect_thread();
char *m_connect_string;
TransporterFacade *m_facade;
LocalConfig *m_local_config;
ConfigRetriever *m_config_retriever;
NdbThread *m_connect_thread;
int (*m_connect_callback)(void);
......
......@@ -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_version = version;
m_node_type = node_type;
......@@ -66,15 +68,6 @@ ConfigRetriever::~ConfigRetriever(){
int
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;
}
......@@ -230,16 +223,6 @@ ConfigRetriever::getErrorString(){
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
ConfigRetriever::verifyConfig(const struct ndb_mgm_configuration * conf, Uint32 nodeid){
......
......@@ -19,6 +19,7 @@
#include <ndb_version.h>
#include "Configuration.hpp"
#include <LocalConfig.hpp>
#include <TransporterRegistry.hpp>
#include "vm/SimBlockList.hpp"
......@@ -67,12 +68,19 @@ NDB_MAIN(ndb_kernel){
// Parse command line options
Configuration* theConfig = globalEmulatorData.theConfiguration;
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
signal(SIGPIPE, SIG_IGN);
theConfig->fetch_configuration();
theConfig->fetch_configuration(local_config);
}
chdir(NdbConfig_get_path(0));
......@@ -135,7 +143,7 @@ NDB_MAIN(ndb_kernel){
exit(0);
}
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());
......
......@@ -16,6 +16,7 @@
#include <ndb_global.h>
#include <LocalConfig.hpp>
#include "Configuration.hpp"
#include <ErrorHandlingMacros.hpp>
#include "GlobalData.hpp"
......@@ -184,7 +185,7 @@ Configuration::closeConfiguration(){
}
void
Configuration::fetch_configuration(){
Configuration::fetch_configuration(LocalConfig &local_config){
/**
* Fetch configuration from management server
*/
......@@ -192,8 +193,7 @@ Configuration::fetch_configuration(){
delete m_config_retriever;
}
m_config_retriever= new ConfigRetriever(NDB_VERSION, NODE_TYPE_DB);
m_config_retriever->setConnectString(_connectString ? _connectString : "");
m_config_retriever= new ConfigRetriever(local_config, NDB_VERSION, NODE_TYPE_DB);
if(m_config_retriever->init() == -1 ||
m_config_retriever->do_connect() == -1){
......@@ -416,6 +416,11 @@ Configuration::setRestartOnErrorInsert(int i){
m_restartOnErrorInsert = i;
}
const char *
Configuration::getConnectString() const {
return _connectString;
}
char *
Configuration::getConnectStringCopy() const {
if(_connectString != 0)
......
......@@ -21,6 +21,7 @@
#include <ndb_types.h>
class ConfigRetriever;
class LocalConfig;
class Configuration {
public:
......@@ -32,7 +33,7 @@ public:
*/
bool init(int argc, const char** argv);
void fetch_configuration();
void fetch_configuration(LocalConfig &local_config);
void setupConfiguration();
void closeConfiguration();
......@@ -54,6 +55,7 @@ public:
const char * programName() const;
const char * fileSystemPath() const;
const char * backupFilePath() const;
const char * getConnectString() const;
char * getConnectStringCopy() const;
/**
......
......@@ -401,7 +401,7 @@ MgmtSrvr::getPort() const {
/* Constructor */
MgmtSrvr::MgmtSrvr(NodeId nodeId,
const BaseString &configFilename,
const BaseString &ndb_config_filename,
LocalConfig &local_config,
Config * config):
_blockNumber(1), // Hard coded block number since it makes it easy to send
// signals to other management servers.
......@@ -409,7 +409,9 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
m_allocated_resources(*this),
theSignalIdleList(NULL),
theWaitState(WAIT_SUBSCRIBE_CONF),
m_statisticsListner(this){
m_statisticsListner(this),
m_local_config(local_config)
{
DBUG_ENTER("MgmtSrvr::MgmtSrvr");
......@@ -424,7 +426,6 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
m_newConfig = NULL;
m_configFilename = configFilename;
m_localNdbConfigFilename = ndb_config_filename;
m_nextConfigGenerationNumber = 0;
......@@ -514,7 +515,7 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
{
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)) {
ndbout << cr.getErrorString() << endl;
exit(-1);
......
......@@ -173,7 +173,7 @@ public:
MgmtSrvr(NodeId nodeId, /* Local nodeid */
const BaseString &config_filename, /* Where to save config */
const BaseString &ndb_config_filename, /* Ndb.cfg filename */
LocalConfig &local_config, /* Ndb.cfg filename */
Config * config);
NodeId getOwnNodeId() const {return _ownNodeId;};
......@@ -528,8 +528,8 @@ private:
NdbMutex *m_configMutex;
const Config * _config;
Config * m_newConfig;
LocalConfig &m_local_config;
BaseString m_configFilename;
BaseString m_localNdbConfigFilename;
Uint32 m_nextConfigGenerationNumber;
NodeBitmask m_reserved_nodes;
......
......@@ -288,8 +288,7 @@ MgmtSrvr::readConfig() {
Config *
MgmtSrvr::fetchConfig() {
ConfigRetriever cr(NDB_VERSION, NODE_TYPE_MGM);
cr.setLocalConfigFileName(m_localNdbConfigFilename.c_str());
ConfigRetriever cr(m_local_config, NDB_VERSION, NODE_TYPE_MGM);
struct ndb_mgm_configuration * tmp = cr.getConfig();
if(tmp != 0){
Config * conf = new Config();
......
......@@ -173,15 +173,19 @@ NDB_MAIN(mgmsrv){
/****************************
* Read configuration files *
****************************/
if (!readLocalConfig())
LocalConfig local_config;
if(!local_config.init(0,glob.local_config_filename)){
local_config.printError();
goto error_end;
}
glob.localNodeId = local_config._ownNodeId;
if (!readGlobalConfig())
goto error_end;
glob.mgmObject = new MgmtSrvr(glob.localNodeId,
BaseString(glob.config_filename),
BaseString(glob.local_config_filename == 0 ?
"" : glob.local_config_filename),
local_config,
glob.cluster_config);
chdir(NdbConfig_get_path(0));
......@@ -320,25 +324,6 @@ MgmGlobals::~MgmGlobals(){
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
* @param glob : Global variables
......
......@@ -236,7 +236,6 @@ public:
NdbMutex* theMutexPtr;
private:
static TransporterFacade* theFacadeInstance;
static ConfigRetriever *s_config_retriever;
public:
GlobalDictCache m_globalDictCache;
......
......@@ -16,6 +16,7 @@
#include <ndb_global.h>
#include <my_pthread.h>
#include <my_sys.h>
#include <ndb_cluster_connection.hpp>
#include <TransporterFacade.hpp>
......@@ -30,14 +31,18 @@ static int g_run_connect_thread= 0;
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();
if (connect_string)
m_connect_string= strdup(connect_string);
m_connect_string= my_strdup(connect_string,MYF(MY_WME));
else
m_connect_string= 0;
m_config_retriever= 0;
m_local_config= 0;
m_connect_thread= 0;
m_connect_callback= 0;
DBUG_VOID_RETURN;
}
extern "C" pthread_handler_decl(run_ndb_cluster_connection_connect_thread, me)
......@@ -99,8 +104,16 @@ int Ndb_cluster_connection::connect(int reconnect)
do {
if (m_config_retriever == 0)
{
m_config_retriever= new ConfigRetriever(NDB_VERSION, NODE_TYPE_API);
m_config_retriever->setConnectString(m_connect_string);
if (m_local_config == 0) {
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)
break;
}
......@@ -145,6 +158,8 @@ int Ndb_cluster_connection::connect(int reconnect)
Ndb_cluster_connection::~Ndb_cluster_connection()
{
DBUG_ENTER("~Ndb_cluster_connection");
DBUG_PRINT("enter",("~Ndb_cluster_connection this=0x%x", this));
TransporterFacade::stop_instance();
if (m_connect_thread)
{
......@@ -161,10 +176,12 @@ Ndb_cluster_connection::~Ndb_cluster_connection()
abort();
TransporterFacade::theFacadeInstance= 0;
}
if (m_connect_string)
free(m_connect_string);
my_free(m_connect_string,MYF(MY_ALLOW_ZERO_PTR));
if (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