Commit 951b9186 authored by unknown's avatar unknown

bug#4529


ndb/include/mgmcommon/ConfigRetriever.hpp:
  Separate connect and all/fetch
ndb/include/mgmcommon/LocalConfig.hpp:
  Use BaseString
ndb/src/common/mgmcommon/ConfigRetriever.cpp:
  Separate connect and all/fetch
ndb/src/common/mgmcommon/LocalConfig.cpp:
  Removed useless onlyNodeId
ndb/src/kernel/main.cpp:
  Separeted Configuration fetch/setup
ndb/src/kernel/vm/Configuration.cpp:
  Separeted Configuration fetch/setup
ndb/src/kernel/vm/Configuration.hpp:
  Separeted Configuration fetch/setup
ndb/src/mgmapi/mgmapi.cpp:
  Fixed some return codes
ndb/src/mgmclient/main.cpp:
  LocalConfig update
ndb/src/mgmsrv/MgmtSrvr.cpp:
  Put mutex around reserving node'ids
ndb/src/mgmsrv/MgmtSrvr.hpp:
  Put mutex around reserving node'ids
ndb/src/mgmsrv/MgmtSrvrConfig.cpp:
  Changes ConfigRetreiver interface
ndb/src/mgmsrv/Services.cpp:
  Allow reserve same id twice
ndb/src/mgmsrv/main.cpp:
  Ignore SIGPIPE
ndb/src/ndbapi/TransporterFacade.cpp:
  ConfigRetriever interface
parent 7fad4e50
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <ndb_types.h> #include <ndb_types.h>
#include <mgmapi.h> #include <mgmapi.h>
#include <BaseString.hpp>
#include <LocalConfig.hpp>
/** /**
* @class ConfigRetriever * @class ConfigRetriever
...@@ -26,15 +28,16 @@ ...@@ -26,15 +28,16 @@
*/ */
class ConfigRetriever { class ConfigRetriever {
public: public:
ConfigRetriever(); ConfigRetriever(Uint32 version, Uint32 nodeType);
ConfigRetriever(const int id, const char* remoteHost, const int port);
~ConfigRetriever(); ~ConfigRetriever();
/** /**
* Read local config * Read local config
* @return Own node id, -1 means fail * @return Own node id, -1 means fail
*/ */
int init(bool onlyNodeId = false); int init();
int do_connect();
/** /**
* Get configuration for current (nodeId given in local config file) node. * Get configuration for current (nodeId given in local config file) node.
...@@ -47,7 +50,7 @@ public: ...@@ -47,7 +50,7 @@ public:
* @return ndb_mgm_configuration object if succeeded, * @return ndb_mgm_configuration object if succeeded,
* NULL if erroneous local config file or configuration error. * NULL if erroneous local config file or configuration error.
*/ */
struct ndb_mgm_configuration * getConfig(int versionId, int nodeType); struct ndb_mgm_configuration * getConfig();
const char * getErrorString(); const char * getErrorString();
...@@ -61,29 +64,22 @@ public: ...@@ -61,29 +64,22 @@ public:
*/ */
void setLocalConfigFileName(const char * connectString); void setLocalConfigFileName(const char * connectString);
/**
* Sets connectstring which can be used instead of local config file
* environment variables and Ndb.cfg has precidence over this
*/
void setDefaultConnectString(const char * defaultConnectString);
/** /**
* @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)
*/ */
inline Uint32 getOwnNodeId() { return _ownNodeId; } Uint32 allocNodeId();
/** /**
* Get config using socket * Get config using socket
*/ */
struct ndb_mgm_configuration * getConfig(const char * mgmhost, short port, struct ndb_mgm_configuration * getConfig(NdbMgmHandle handle);
int versionId, int nodetype);
/** /**
* Get config from file * Get config from file
*/ */
struct ndb_mgm_configuration * getConfig(const char * file, int versionId); struct ndb_mgm_configuration * getConfig(const char * file);
private: private:
char * errorString; BaseString errorString;
enum ErrorType { enum ErrorType {
CR_ERROR = 0, CR_ERROR = 0,
CR_RETRY = 1 CR_RETRY = 1
...@@ -91,20 +87,21 @@ private: ...@@ -91,20 +87,21 @@ private:
ErrorType latestErrorType; ErrorType latestErrorType;
void setError(ErrorType, const char * errorMsg); void setError(ErrorType, const char * errorMsg);
char * _localConfigFileName; BaseString _localConfigFileName;
struct LocalConfig * _localConfig; struct LocalConfig _localConfig;
int _ownNodeId; int _ownNodeId;
char * m_connectString; BaseString m_connectString;
char * m_defaultConnectString;
Uint32 m_version;
Uint32 m_node_type;
NdbMgmHandle m_handle; NdbMgmHandle m_handle;
/** /**
* Verify config * Verify config
*/ */
bool verifyConfig(const struct ndb_mgm_configuration *, int type); bool verifyConfig(const struct ndb_mgm_configuration *);
}; };
#endif #endif
......
...@@ -32,49 +32,35 @@ enum MgmtSrvrId_Type { ...@@ -32,49 +32,35 @@ enum MgmtSrvrId_Type {
struct MgmtSrvrId { struct MgmtSrvrId {
MgmtSrvrId_Type type; MgmtSrvrId_Type type;
union { BaseString name;
struct { unsigned int port;
char * remoteHost;
unsigned int port;
} tcp;
struct {
char * filename;
} file;
} data;
}; };
struct LocalConfig { struct LocalConfig {
int _ownNodeId; int _ownNodeId;
Vector<MgmtSrvrId> ids;
int size;
int items;
MgmtSrvrId ** ids;
int error_line; int error_line;
char error_msg[256]; char error_msg[256];
LocalConfig(); LocalConfig();
~LocalConfig(); ~LocalConfig();
bool init(bool onlyNodeId = false, bool init(const char *connectString = 0,
const char *connectString = 0, const char *fileName = 0);
const char *fileName = 0,
const char *defaultConnectString = 0);
void add(MgmtSrvrId *i);
void printError() const; void printError() const;
void printUsage() const; void printUsage() const;
void setError(int lineNumber, const char * _msg); void setError(int lineNumber, const char * _msg);
bool readConnectString(const char * connectString, bool onlyNodeId = false); bool readConnectString(const char *);
bool readFile(const char * filename, bool &fopenError, bool onlyNodeId = false); bool readFile(const char * file, bool &fopenError);
bool parseLine(char * line, int lineNumber); bool parseLine(char * line, int lineNumber);
bool parseNodeId(const char *buf); bool parseNodeId(const char *buf);
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, bool onlyNodeId, char *line); bool parseString(const char *buf, char *line);
}; };
#endif // LocalConfig_H #endif // LocalConfig_H
......
...@@ -20,16 +20,13 @@ ...@@ -20,16 +20,13 @@
#include <NdbAutoPtr.hpp> #include <NdbAutoPtr.hpp>
LocalConfig::LocalConfig(){ LocalConfig::LocalConfig(){
ids = 0; size = 0; items = 0;
error_line = 0; error_msg[0] = 0; error_line = 0; error_msg[0] = 0;
_ownNodeId= 0; _ownNodeId= 0;
} }
bool bool
LocalConfig::init(bool onlyNodeId, LocalConfig::init(const char *connectString,
const char *connectString, const char *fileName) {
const char *fileName,
const char *defaultConnectString) {
/** /**
* Escalation: * Escalation:
* 1. Check connectString * 1. Check connectString
...@@ -41,8 +38,8 @@ LocalConfig::init(bool onlyNodeId, ...@@ -41,8 +38,8 @@ LocalConfig::init(bool onlyNodeId,
*/ */
//1. Check connectString //1. Check connectString
if(connectString != 0) { if(connectString != 0 && connectString[0] != 0){
if(readConnectString(connectString, onlyNodeId)){ if(readConnectString(connectString)){
return true; return true;
} }
return false; return false;
...@@ -51,7 +48,7 @@ LocalConfig::init(bool onlyNodeId, ...@@ -51,7 +48,7 @@ LocalConfig::init(bool onlyNodeId,
//2. Check given filename //2. Check given filename
if (fileName && strlen(fileName) > 0) { if (fileName && strlen(fileName) > 0) {
bool fopenError; bool fopenError;
if(readFile(fileName, fopenError, onlyNodeId)){ if(readFile(fileName, fopenError)){
return true; return true;
} }
return false; return false;
...@@ -61,7 +58,7 @@ LocalConfig::init(bool onlyNodeId, ...@@ -61,7 +58,7 @@ LocalConfig::init(bool onlyNodeId,
char buf[255]; char buf[255];
if(NdbEnv_GetEnv("NDB_CONNECTSTRING", buf, sizeof(buf)) && if(NdbEnv_GetEnv("NDB_CONNECTSTRING", buf, sizeof(buf)) &&
strlen(buf) != 0){ strlen(buf) != 0){
if(readConnectString(buf, onlyNodeId)){ if(readConnectString(buf)){
return true; return true;
} }
return false; return false;
...@@ -72,7 +69,7 @@ LocalConfig::init(bool onlyNodeId, ...@@ -72,7 +69,7 @@ LocalConfig::init(bool onlyNodeId,
bool fopenError; bool fopenError;
char *buf= NdbConfig_NdbCfgName(1 /*true*/); char *buf= NdbConfig_NdbCfgName(1 /*true*/);
NdbAutoPtr<char> tmp_aptr(buf); NdbAutoPtr<char> tmp_aptr(buf);
if(readFile(buf, fopenError, onlyNodeId)) if(readFile(buf, fopenError))
return true; return true;
if (!fopenError) if (!fopenError)
return false; return false;
...@@ -83,24 +80,17 @@ LocalConfig::init(bool onlyNodeId, ...@@ -83,24 +80,17 @@ LocalConfig::init(bool onlyNodeId,
bool fopenError; bool fopenError;
char *buf= NdbConfig_NdbCfgName(0 /*false*/); char *buf= NdbConfig_NdbCfgName(0 /*false*/);
NdbAutoPtr<char> tmp_aptr(buf); NdbAutoPtr<char> tmp_aptr(buf);
if(readFile(buf, fopenError, onlyNodeId)) if(readFile(buf, fopenError))
return true; return true;
if (!fopenError) if (!fopenError)
return false; return false;
} }
//6. Check defaultConnectString
if(defaultConnectString != 0) {
if(readConnectString(defaultConnectString, onlyNodeId))
return true;
return false;
}
//7. Check //7. Check
{ {
char buf[256]; char buf[256];
snprintf(buf, sizeof(buf), "host=localhost:%u", NDB_BASE_PORT); snprintf(buf, sizeof(buf), "host=localhost:%u", NDB_BASE_PORT);
if(readConnectString(buf, onlyNodeId)) if(readConnectString(buf))
return true; return true;
} }
...@@ -110,30 +100,8 @@ LocalConfig::init(bool onlyNodeId, ...@@ -110,30 +100,8 @@ LocalConfig::init(bool onlyNodeId,
} }
LocalConfig::~LocalConfig(){ LocalConfig::~LocalConfig(){
for(int i = 0; i<items; i++){
if(ids[i]->type == MgmId_TCP)
free(ids[i]->data.tcp.remoteHost);
else if(ids[i]->type == MgmId_File)
free(ids[i]->data.file.filename);
delete ids[i];
}
if(ids != 0)
delete[] ids;
} }
void LocalConfig::add(MgmtSrvrId * i){
if(items == size){
MgmtSrvrId ** tmp = new MgmtSrvrId * [size+10];
if(ids != 0){
memcpy(tmp, ids, items*sizeof(MgmtSrvrId *));
delete []ids;
}
ids = tmp;
}
ids[items] = i;
items++;
}
void LocalConfig::setError(int lineNumber, const char * _msg) { void LocalConfig::setError(int lineNumber, const char * _msg) {
error_line = lineNumber; error_line = lineNumber;
strncpy(error_msg, _msg, sizeof(error_msg)); strncpy(error_msg, _msg, sizeof(error_msg));
...@@ -162,13 +130,13 @@ void LocalConfig::printUsage() const { ...@@ -162,13 +130,13 @@ void LocalConfig::printUsage() const {
<<endl<<endl; <<endl<<endl;
} }
char *nodeIdTokens[] = { const char *nodeIdTokens[] = {
"OwnProcessId %i", "OwnProcessId %i",
"nodeid=%i", "nodeid=%i",
0 0
}; };
char *hostNameTokens[] = { const char *hostNameTokens[] = {
"host://%[^:]:%i", "host://%[^:]:%i",
"host=%[^:]:%i", "host=%[^:]:%i",
"%[^:]:%i", "%[^:]:%i",
...@@ -176,7 +144,7 @@ char *hostNameTokens[] = { ...@@ -176,7 +144,7 @@ char *hostNameTokens[] = {
0 0
}; };
char *fileNameTokens[] = { const char *fileNameTokens[] = {
"file://%s", "file://%s",
"file=%s", "file=%s",
0 0
...@@ -196,11 +164,11 @@ LocalConfig::parseHostName(const char * buf){ ...@@ -196,11 +164,11 @@ LocalConfig::parseHostName(const char * buf){
int port; int port;
for(int i = 0; hostNameTokens[i] != 0; i++) { for(int i = 0; hostNameTokens[i] != 0; i++) {
if (sscanf(buf, hostNameTokens[i], tempString, &port) == 2) { if (sscanf(buf, hostNameTokens[i], tempString, &port) == 2) {
MgmtSrvrId* mgmtSrvrId = new MgmtSrvrId(); MgmtSrvrId mgmtSrvrId;
mgmtSrvrId->type = MgmId_TCP; mgmtSrvrId.type = MgmId_TCP;
mgmtSrvrId->data.tcp.remoteHost = strdup(tempString); mgmtSrvrId.name.assign(tempString);
mgmtSrvrId->data.tcp.port = port; mgmtSrvrId.port = port;
add(mgmtSrvrId); ids.push_back(mgmtSrvrId);
return true; return true;
} }
} }
...@@ -212,10 +180,10 @@ LocalConfig::parseFileName(const char * buf){ ...@@ -212,10 +180,10 @@ LocalConfig::parseFileName(const char * buf){
char tempString[1024]; char tempString[1024];
for(int i = 0; fileNameTokens[i] != 0; i++) { for(int i = 0; fileNameTokens[i] != 0; i++) {
if (sscanf(buf, fileNameTokens[i], tempString) == 1) { if (sscanf(buf, fileNameTokens[i], tempString) == 1) {
MgmtSrvrId* mgmtSrvrId = new MgmtSrvrId(); MgmtSrvrId mgmtSrvrId;
mgmtSrvrId->type = MgmId_File; mgmtSrvrId.type = MgmId_File;
mgmtSrvrId->data.file.filename = strdup(tempString); mgmtSrvrId.name.assign(tempString);
add(mgmtSrvrId); ids.push_back(mgmtSrvrId);
return true; return true;
} }
} }
...@@ -223,7 +191,7 @@ LocalConfig::parseFileName(const char * buf){ ...@@ -223,7 +191,7 @@ LocalConfig::parseFileName(const char * buf){
} }
bool bool
LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line){ LocalConfig::parseString(const char * connectString, char *line){
char * for_strtok; char * for_strtok;
char * copy = strdup(connectString); char * copy = strdup(connectString);
NdbAutoPtr<char> tmp_aptr(copy); NdbAutoPtr<char> tmp_aptr(copy);
...@@ -231,8 +199,7 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line ...@@ -231,8 +199,7 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line
bool b_nodeId = false; bool b_nodeId = false;
bool found_other = false; bool found_other = false;
for (char *tok = strtok_r(copy,";",&for_strtok); for (char *tok = strtok_r(copy,";",&for_strtok); tok != 0;
tok != 0 && !(onlyNodeId && b_nodeId);
tok = strtok_r(NULL, ";", &for_strtok)) { tok = strtok_r(NULL, ";", &for_strtok)) {
if (tok[0] == '#') continue; if (tok[0] == '#') continue;
...@@ -240,8 +207,6 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line ...@@ -240,8 +207,6 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line
if (!b_nodeId) // only one nodeid definition allowed if (!b_nodeId) // only one nodeid definition allowed
if (b_nodeId = parseNodeId(tok)) if (b_nodeId = parseNodeId(tok))
continue; continue;
if (onlyNodeId)
continue;
if (found_other = parseHostName(tok)) if (found_other = parseHostName(tok))
continue; continue;
if (found_other = parseFileName(tok)) if (found_other = parseFileName(tok))
...@@ -252,16 +217,17 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line ...@@ -252,16 +217,17 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line
return false; return false;
} }
if (!onlyNodeId && !found_other) { if (!found_other) {
if (line) if (line)
snprintf(line, 150, "Missing host/file name extry in \"%s\"", connectString); snprintf(line, 150, "Missing host/file name extry in \"%s\"",
connectString);
return false; return false;
} }
return true; return true;
} }
bool LocalConfig::readFile(const char * filename, bool &fopenError, bool onlyNodeId) bool LocalConfig::readFile(const char * filename, bool &fopenError)
{ {
char line[150], line2[150]; char line[150], line2[150];
...@@ -292,7 +258,7 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError, bool onlyNod ...@@ -292,7 +258,7 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError, bool onlyNod
strcat(theString, line); strcat(theString, line);
} }
bool return_value = parseString(theString, onlyNodeId, line); bool return_value = parseString(theString, line);
if (!return_value) { if (!return_value) {
snprintf(line2, 150, "Reading %s: %s", filename, line); snprintf(line2, 150, "Reading %s: %s", filename, line);
...@@ -305,9 +271,9 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError, bool onlyNod ...@@ -305,9 +271,9 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError, bool onlyNod
} }
bool bool
LocalConfig::readConnectString(const char * connectString, bool onlyNodeId){ LocalConfig::readConnectString(const char * connectString){
char line[150], line2[150]; char line[150], line2[150];
bool return_value = parseString(connectString, onlyNodeId, line); bool return_value = parseString(connectString, line);
if (!return_value) { if (!return_value) {
snprintf(line2, 150, "Reading NDB_CONNECTSTRING \"%s\": %s", connectString, line); snprintf(line2, 150, "Reading NDB_CONNECTSTRING \"%s\": %s", connectString, line);
setError(0,line2); setError(0,line2);
......
...@@ -69,9 +69,10 @@ NDB_MAIN(ndb_kernel){ ...@@ -69,9 +69,10 @@ NDB_MAIN(ndb_kernel){
} }
{ // Do configuration { // Do configuration
theConfig->setupConfiguration(); signal(SIGPIPE, SIG_IGN);
theConfig->fetch_configuration();
} }
if (theConfig->getDaemonMode()) { if (theConfig->getDaemonMode()) {
// Become a daemon // Become a daemon
char *lockfile= NdbConfig_PidFileName(globalData.ownId); char *lockfile= NdbConfig_PidFileName(globalData.ownId);
...@@ -88,8 +89,6 @@ NDB_MAIN(ndb_kernel){ ...@@ -88,8 +89,6 @@ NDB_MAIN(ndb_kernel){
/** /**
* Parent * Parent
*/ */
theConfig->closeConfiguration();
catchsigs(true); catchsigs(true);
int status = 0; int status = 0;
...@@ -132,11 +131,13 @@ NDB_MAIN(ndb_kernel){ ...@@ -132,11 +131,13 @@ 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();
} }
g_eventLogger.info("Angel pid: %d ndb pid: %d", getppid(), getpid()); g_eventLogger.info("Angel pid: %d ndb pid: %d", getppid(), getpid());
theConfig->setupConfiguration();
systemInfo(* theConfig, * theConfig->m_logLevel); systemInfo(* theConfig, * theConfig->m_logLevel);
// Load blocks // Load blocks
globalEmulatorData.theSimBlockList->load(* theConfig); globalEmulatorData.theSimBlockList->load(* theConfig);
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <ndb_limits.h> #include <ndb_limits.h>
#include "pc.hpp" #include "pc.hpp"
#include <LogLevel.hpp> #include <LogLevel.hpp>
#include <NdbSleep.h>
extern "C" { extern "C" {
void ndbSetOwnVersion(); void ndbSetOwnVersion();
...@@ -153,39 +154,82 @@ Configuration::closeConfiguration(){ ...@@ -153,39 +154,82 @@ Configuration::closeConfiguration(){
} }
void void
Configuration::setupConfiguration(){ Configuration::fetch_configuration(){
/** /**
* Fetch configuration from management server * Fetch configuration from management server
*/ */
if (m_config_retriever) { if (m_config_retriever) {
delete m_config_retriever; delete m_config_retriever;
} }
m_config_retriever= new ConfigRetriever();
ConfigRetriever &cr= *m_config_retriever;
cr.setConnectString(_connectString); m_config_retriever= new ConfigRetriever(NDB_VERSION, NODE_TYPE_DB);
stopOnError(true); m_config_retriever->setConnectString(_connectString ? _connectString : "");
ndb_mgm_configuration * p = cr.getConfig(NDB_VERSION, NODE_TYPE_DB); if(m_config_retriever->init() == -1 ||
m_config_retriever->do_connect() == -1){
const char * s = m_config_retriever->getErrorString();
if(s == 0)
s = "No error given!";
/* Set stop on error to true otherwise NDB will
go into an restart loop...
*/
ERROR_SET(fatal, ERR_INVALID_CONFIG, "Could connect to ndb_mgmd", s);
}
ConfigRetriever &cr= *m_config_retriever;
if((globalData.ownId = cr.allocNodeId()) == 0){
for(Uint32 i = 0; i<3; i++){
NdbSleep_SecSleep(3);
if(globalData.ownId = cr.allocNodeId())
break;
}
}
if(globalData.ownId == 0){
ERROR_SET(fatal, ERR_INVALID_CONFIG,
"Unable to alloc node id", m_config_retriever->getErrorString());
}
ndb_mgm_configuration * p = cr.getConfig();
if(p == 0){ if(p == 0){
const char * s = cr.getErrorString(); const char * s = cr.getErrorString();
if(s == 0) if(s == 0)
s = "No error given!"; s = "No error given!";
/* Set stop on error to true otherwise NDB will /* Set stop on error to true otherwise NDB will
go into an restart loop... go into an restart loop...
*/ */
ERROR_SET(fatal, ERR_INVALID_CONFIG, "Could not fetch configuration" ERROR_SET(fatal, ERR_INVALID_CONFIG, "Could not fetch configuration"
"/invalid configuration", s); "/invalid configuration", s);
} }
if(m_clusterConfig)
free(m_clusterConfig);
m_clusterConfig = p;
ndb_mgm_configuration_iterator iter(* p, CFG_SECTION_NODE);
if (iter.find(CFG_NODE_ID, globalData.ownId)){
ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", "DB missing");
}
if(iter.get(CFG_DB_STOP_ON_ERROR, &_stopOnError)){
ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched",
"StopOnError missing");
}
}
Uint32 nodeId = globalData.ownId = cr.getOwnNodeId(); void
Configuration::setupConfiguration(){
ndb_mgm_configuration * p = m_clusterConfig;
/** /**
* Configure transporters * Configure transporters
*/ */
{ {
int res = IPCConfig::configureTransporters(nodeId, int res = IPCConfig::configureTransporters(globalData.ownId,
* p, * p,
globalTransporterRegistry); globalTransporterRegistry);
if(res <= 0){ if(res <= 0){
...@@ -247,11 +291,6 @@ Configuration::setupConfiguration(){ ...@@ -247,11 +291,6 @@ Configuration::setupConfiguration(){
} }
} }
if(iter.get(CFG_DB_STOP_ON_ERROR, &_stopOnError)){
ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched",
"StopOnError missing");
}
if(iter.get(CFG_DB_STOP_ON_ERROR_INSERT, &m_restartOnErrorInsert)){ if(iter.get(CFG_DB_STOP_ON_ERROR_INSERT, &m_restartOnErrorInsert)){
ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched",
"RestartOnErrorInsert missing"); "RestartOnErrorInsert missing");
...@@ -268,7 +307,6 @@ Configuration::setupConfiguration(){ ...@@ -268,7 +307,6 @@ Configuration::setupConfiguration(){
ConfigValues* cf = ConfigValuesFactory::extractCurrentSection(iter.m_config); ConfigValues* cf = ConfigValuesFactory::extractCurrentSection(iter.m_config);
m_clusterConfig = p;
m_clusterConfigIter = ndb_mgm_create_configuration_iterator m_clusterConfigIter = ndb_mgm_create_configuration_iterator
(p, CFG_SECTION_NODE); (p, CFG_SECTION_NODE);
......
...@@ -32,6 +32,7 @@ public: ...@@ -32,6 +32,7 @@ public:
*/ */
bool init(int argc, const char** argv); bool init(int argc, const char** argv);
void fetch_configuration();
void setupConfiguration(); void setupConfiguration();
void closeConfiguration(); void closeConfiguration();
......
...@@ -1438,11 +1438,7 @@ ndb_mgm_get_configuration(NdbMgmHandle handle, unsigned int version) { ...@@ -1438,11 +1438,7 @@ ndb_mgm_get_configuration(NdbMgmHandle handle, unsigned int version) {
const Properties *prop; const Properties *prop;
prop = ndb_mgm_call(handle, reply, "get config", &args); prop = ndb_mgm_call(handle, reply, "get config", &args);
CHECK_REPLY(prop, 0);
if(prop == NULL) {
SET_ERROR(handle, EIO, "Unable to fetch config");
return 0;
}
do { do {
const char * buf; const char * buf;
...@@ -1537,17 +1533,14 @@ ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, unsigned *pnodei ...@@ -1537,17 +1533,14 @@ ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, unsigned *pnodei
const Properties *prop; const Properties *prop;
prop= ndb_mgm_call(handle, reply, "get nodeid", &args); prop= ndb_mgm_call(handle, reply, "get nodeid", &args);
CHECK_REPLY(prop, -1);
if(prop == NULL) {
SET_ERROR(handle, EIO, "Unable to alloc nodeid");
return -1;
}
int res= -1; int res= -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){
ndbout_c("ERROR Message: %s\n", buf); setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__,
"Could not alloc node id: %s",buf);
break; break;
} }
if(!prop->get("nodeid", pnodeid) != 0){ if(!prop->get("nodeid", pnodeid) != 0){
...@@ -1621,11 +1614,7 @@ ndb_mgm_set_int_parameter(NdbMgmHandle handle, ...@@ -1621,11 +1614,7 @@ ndb_mgm_set_int_parameter(NdbMgmHandle handle,
const Properties *prop; const Properties *prop;
prop= ndb_mgm_call(handle, reply, "set parameter", &args); prop= ndb_mgm_call(handle, reply, "set parameter", &args);
CHECK_REPLY(prop, -1);
if(prop == NULL) {
SET_ERROR(handle, EIO, "Unable set parameter");
return -1;
}
int res= -1; int res= -1;
do { do {
......
...@@ -47,10 +47,6 @@ handler(int sig){ ...@@ -47,10 +47,6 @@ handler(int sig){
int main(int argc, const char** argv){ int main(int argc, const char** argv){
int optind = 0; int optind = 0;
char _default_connectstring_buf[256];
snprintf(_default_connectstring_buf, sizeof(_default_connectstring_buf),
"host=localhost:%u", NDB_BASE_PORT);
const char *_default_connectstring= _default_connectstring_buf;
const char *_host = 0; const char *_host = 0;
int _port = 0; int _port = 0;
int _help = 0; int _help = 0;
...@@ -79,9 +75,9 @@ int main(int argc, const char** argv){ ...@@ -79,9 +75,9 @@ int main(int argc, const char** argv){
_port = atoi(argv[1]); _port = atoi(argv[1]);
} }
} else { } else {
if(cfg.init(false, 0, 0, _default_connectstring) && cfg.items > 0 && cfg.ids[0]->type == MgmId_TCP){ if(cfg.init(0, 0) && cfg.ids.size() > 0 && cfg.ids[0].type == MgmId_TCP){
_host = cfg.ids[0]->data.tcp.remoteHost; _host = cfg.ids[0].name.c_str();
_port = cfg.ids[0]->data.tcp.port; _port = cfg.ids[0].port;
} else { } else {
cfg.printError(); cfg.printError();
cfg.printUsage(); cfg.printUsage();
......
...@@ -584,18 +584,11 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId, ...@@ -584,18 +584,11 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
_ownNodeId= 0; _ownNodeId= 0;
NodeId tmp= nodeId; NodeId tmp= nodeId;
if (getFreeNodeId(&tmp, NDB_MGM_NODE_TYPE_MGM, 0, 0)){ if (!alloc_node_id(&tmp, NDB_MGM_NODE_TYPE_MGM, 0, 0)){
_ownNodeId= tmp; ndbout << "Unable to obtain requested nodeid " << nodeId;
if (nodeId != 0 && nodeId != tmp) {
ndbout << "Unable to obtain requested nodeid " << nodeId
<< " nodeid " << tmp << " available\n";
_ownNodeId= 0; // did not get nodeid requested
}
m_allocated_resources.reserve_node(_ownNodeId);
} else {
ndbout_c("Unable to retrieve own node id");
exit(-1); exit(-1);
} }
_ownNodeId = tmp;
} }
...@@ -2301,10 +2294,19 @@ MgmtSrvr::getNodeType(NodeId nodeId) const ...@@ -2301,10 +2294,19 @@ MgmtSrvr::getNodeType(NodeId nodeId) const
return nodeTypes[nodeId]; return nodeTypes[nodeId];
} }
#ifdef NDB_WIN32
static NdbMutex & f_node_id_mutex = * NdbMutex_Create();
#else
static NdbMutex f_node_id_mutex = NDB_MUTEX_INITIALIZER;
#endif
bool bool
MgmtSrvr::getFreeNodeId(NodeId * nodeId, enum ndb_mgm_node_type type, MgmtSrvr::alloc_node_id(NodeId * nodeId,
struct sockaddr *client_addr, socklen_t *client_addr_len) const enum ndb_mgm_node_type type,
struct sockaddr *client_addr,
socklen_t *client_addr_len)
{ {
Guard g(&f_node_id_mutex);
#if 0 #if 0
ndbout << "MgmtSrvr::getFreeNodeId type=" << type ndbout << "MgmtSrvr::getFreeNodeId type=" << type
<< " *nodeid=" << *nodeId << endl; << " *nodeid=" << *nodeId << endl;
...@@ -2365,6 +2367,7 @@ MgmtSrvr::getFreeNodeId(NodeId * nodeId, enum ndb_mgm_node_type type, ...@@ -2365,6 +2367,7 @@ MgmtSrvr::getFreeNodeId(NodeId * nodeId, enum ndb_mgm_node_type type,
} }
} }
*nodeId= tmp; *nodeId= tmp;
m_reserved_nodes.set(tmp);
#if 0 #if 0
ndbout << "MgmtSrvr::getFreeNodeId found type=" << type ndbout << "MgmtSrvr::getFreeNodeId found type=" << type
<< " *nodeid=" << *nodeId << endl; << " *nodeid=" << *nodeId << endl;
...@@ -2769,6 +2772,7 @@ MgmtSrvr::Allocated_resources::Allocated_resources(MgmtSrvr &m) ...@@ -2769,6 +2772,7 @@ MgmtSrvr::Allocated_resources::Allocated_resources(MgmtSrvr &m)
MgmtSrvr::Allocated_resources::~Allocated_resources() MgmtSrvr::Allocated_resources::~Allocated_resources()
{ {
Guard g(&f_node_id_mutex);
m_mgmsrv.m_reserved_nodes.bitANDC(m_reserved_nodes); m_mgmsrv.m_reserved_nodes.bitANDC(m_reserved_nodes);
} }
...@@ -2776,7 +2780,6 @@ void ...@@ -2776,7 +2780,6 @@ void
MgmtSrvr::Allocated_resources::reserve_node(NodeId id) MgmtSrvr::Allocated_resources::reserve_node(NodeId id)
{ {
m_reserved_nodes.set(id); m_reserved_nodes.set(id);
m_mgmsrv.m_reserved_nodes.set(id);
} }
int int
......
...@@ -78,6 +78,7 @@ public: ...@@ -78,6 +78,7 @@ public:
// methods to reserve/allocate resources which // methods to reserve/allocate resources which
// will be freed when running destructor // will be freed when running destructor
void reserve_node(NodeId id); void reserve_node(NodeId id);
bool is_reserved(NodeId nodeId) { return m_reserved_nodes.get(nodeId);}
private: private:
MgmtSrvr &m_mgmsrv; MgmtSrvr &m_mgmsrv;
NodeBitmask m_reserved_nodes; NodeBitmask m_reserved_nodes;
...@@ -465,8 +466,8 @@ public: ...@@ -465,8 +466,8 @@ public:
* @return false if none found * @return false if none found
*/ */
bool getNextNodeId(NodeId * _nodeId, enum ndb_mgm_node_type type) const ; bool getNextNodeId(NodeId * _nodeId, enum ndb_mgm_node_type type) const ;
bool getFreeNodeId(NodeId * _nodeId, enum ndb_mgm_node_type type, bool alloc_node_id(NodeId * _nodeId, enum ndb_mgm_node_type type,
struct sockaddr *client_addr, socklen_t *client_addr_len) const ; struct sockaddr *client_addr, socklen_t *client_addr_len);
/** /**
* *
......
...@@ -288,16 +288,15 @@ MgmtSrvr::readConfig() { ...@@ -288,16 +288,15 @@ MgmtSrvr::readConfig() {
Config * Config *
MgmtSrvr::fetchConfig() { MgmtSrvr::fetchConfig() {
ConfigRetriever cr; ConfigRetriever cr(NDB_VERSION, NODE_TYPE_MGM);
cr.setLocalConfigFileName(m_localNdbConfigFilename.c_str()); cr.setLocalConfigFileName(m_localNdbConfigFilename.c_str());
struct ndb_mgm_configuration * tmp = cr.getConfig(NDB_VERSION, struct ndb_mgm_configuration * tmp = cr.getConfig();
NODE_TYPE_MGM);
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;
} }
......
...@@ -401,34 +401,26 @@ MgmApiSession::get_nodeid(Parser_t::Context &, ...@@ -401,34 +401,26 @@ MgmApiSession::get_nodeid(Parser_t::Context &,
struct sockaddr addr; struct sockaddr addr;
socklen_t addrlen= sizeof(addr); socklen_t addrlen= sizeof(addr);
int r; int r = getpeername(m_socket, &addr, &addrlen);
if (r= getpeername(m_socket, &addr, &addrlen)) { if (r != 0 ) {
m_output->println(cmd); m_output->println(cmd);
m_output->println("result: getpeername(%d) failed, err= %d", m_socket, r); m_output->println("result: getpeername(%d) failed, err= %d", m_socket, r);
m_output->println(""); m_output->println("");
return; return;
} }
NodeId free_id= 0;
NodeId tmp= nodeid; NodeId tmp= nodeid;
if (m_mgmsrv.getFreeNodeId(&tmp, (enum ndb_mgm_node_type)nodetype, &addr, &addrlen)) if(tmp == 0 || !m_allocated_resources->is_reserved(tmp)){
free_id= tmp; if (!m_mgmsrv.alloc_node_id(&tmp, (enum ndb_mgm_node_type)nodetype,
&addr, &addrlen)){
if (nodeid != 0 && free_id != nodeid){ m_output->println(cmd);
m_output->println(cmd); m_output->println("result: no free nodeid %d for nodetype %d",
m_output->println("result: no free nodeid %d for nodetype %d", nodeid, nodetype);
nodeid, nodetype); m_output->println("");
m_output->println(""); return;
return; }
} }
if (free_id == 0){
m_output->println(cmd);
m_output->println("result: no free nodeid for nodetype %d", nodetype);
m_output->println("");
return;
}
#if 0 #if 0
if (!compatible){ if (!compatible){
m_output->println(cmd); m_output->println(cmd);
...@@ -438,14 +430,13 @@ MgmApiSession::get_nodeid(Parser_t::Context &, ...@@ -438,14 +430,13 @@ MgmApiSession::get_nodeid(Parser_t::Context &,
return; return;
} }
#endif #endif
m_output->println(cmd); m_output->println(cmd);
m_output->println("nodeid: %u", free_id); m_output->println("nodeid: %u", tmp);
m_output->println("result: Ok"); m_output->println("result: Ok");
m_output->println(""); m_output->println("");
m_allocated_resources->reserve_node(tmp);
m_allocated_resources->reserve_node(free_id);
return; return;
} }
......
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
#include <ndb_global.h> #include <ndb_global.h>
#include <signal.h>
#include "MgmtSrvr.hpp" #include "MgmtSrvr.hpp"
#include "EventLogger.hpp" #include "EventLogger.hpp"
#include <Config.hpp> #include <Config.hpp>
...@@ -229,6 +227,7 @@ NDB_MAIN(mgmsrv){ ...@@ -229,6 +227,7 @@ NDB_MAIN(mgmsrv){
} }
} }
signal(SIGPIPE, SIG_IGN);
if(!glob.mgmObject->start()){ if(!glob.mgmObject->start()){
ndbout_c("Unable to start management server."); ndbout_c("Unable to start management server.");
ndbout_c("Probably caused by illegal initial configuration file."); ndbout_c("Probably caused by illegal initial configuration file.");
...@@ -312,14 +311,13 @@ MgmGlobals::~MgmGlobals(){ ...@@ -312,14 +311,13 @@ MgmGlobals::~MgmGlobals(){
static bool static bool
readLocalConfig(){ readLocalConfig(){
// Read local config file // Read local config file
ConfigRetriever cr; LocalConfig lc;
cr.setLocalConfigFileName(glob.local_config_filename); int nodeid = lc.init(glob.local_config_filename);
int nodeid = cr.init(true);
if(nodeid == -1){ if(nodeid == -1){
return false; return false;
} }
glob.localNodeId = (NodeId)nodeid; glob.localNodeId = nodeid;
return true; return true;
} }
...@@ -342,18 +340,7 @@ readGlobalConfig() { ...@@ -342,18 +340,7 @@ readGlobalConfig() {
InitConfigFileParser parser; InitConfigFileParser parser;
glob.cluster_config = parser.parseConfig(glob.config_filename); glob.cluster_config = parser.parseConfig(glob.config_filename);
if(glob.cluster_config == 0){ if(glob.cluster_config == 0){
/** return false;
* Try to get configuration from other MGM server
* Note: Only new format
*/
glob.cluster_config = new Config();
ConfigRetriever cr;
cr.setLocalConfigFileName(glob.local_config_filename);
glob.cluster_config->m_configValues = cr.getConfig(NDB_VERSION,
NODE_TYPE_MGM);
if (glob.cluster_config->m_configValues == NULL)
return false;
} }
return true; return true;
} }
...@@ -343,27 +343,39 @@ TransporterFacade* ...@@ -343,27 +343,39 @@ TransporterFacade*
TransporterFacade::start_instance(const char * connectString){ TransporterFacade::start_instance(const char * connectString){
// TransporterFacade used from API get config from mgmt srvr // TransporterFacade used from API get config from mgmt srvr
s_config_retriever= new ConfigRetriever; s_config_retriever= new ConfigRetriever(NDB_VERSION, NODE_TYPE_API);
ConfigRetriever &configRetriever= *s_config_retriever; s_config_retriever->setConnectString(connectString);
configRetriever.setConnectString(connectString); const char* error = 0;
ndb_mgm_configuration * props = configRetriever.getConfig(NDB_VERSION, do {
NODE_TYPE_API); if(s_config_retriever->init() == -1)
if (props == 0) { break;
ndbout << "Configuration error: ";
const char* erString = configRetriever.getErrorString(); if(s_config_retriever->do_connect() == -1)
if (erString == 0) { break;
erString = "No error specified!";
} const Uint32 nodeId = s_config_retriever->allocNodeId();
ndbout << erString << endl; if(nodeId == 0)
return 0; break;
}
const int nodeId = configRetriever.getOwnNodeId();
ndb_mgm_configuration * props = s_config_retriever->getConfig();
TransporterFacade * tf = start_instance(nodeId, props); if(props == 0)
break;
TransporterFacade * tf = start_instance(nodeId, props);
free(props);
return tf;
} while(0);
free(props); ndbout << "Configuration error: ";
return tf; const char* erString = s_config_retriever->getErrorString();
if (erString == 0) {
erString = "No error specified!";
}
ndbout << erString << endl;
return 0;
} }
TransporterFacade* TransporterFacade*
......
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