Commit f9bad1ae authored by unknown's avatar unknown

several config fixes for ndb, see respective file


ndb/include/debugger/EventLogger.hpp:
  removed unused method
ndb/include/mgmcommon/ConfigRetriever.hpp:
  put NdbMgmHandle in ConfigRetriever to enable holding connection open until setup complete
ndb/include/mgmcommon/NdbConfig.h:
  moved naming of all "ndb" file into NdbConfig.c
ndb/include/ndb_global.h:
  introduced define NDB_BASE_PORT to control default port for ndb
ndb/src/common/debugger/EventLogger.cpp:
  removed unused method
ndb/src/common/mgmcommon/ConfigInfo.cpp:
  introduced define NDB_BASE_PORT to control default port for ndb
  + added setting default Id's on nodes
ndb/src/common/mgmcommon/ConfigRetriever.cpp:
  put NdbMgmHandle in ConfigRetriever to enable holding connection open until setup complete
ndb/src/common/mgmcommon/IPCConfig.cpp:
  changed error message
ndb/src/common/mgmcommon/LocalConfig.cpp:
  introduced define NDB_BASE_PORT to control default port for ndb
ndb/src/common/mgmcommon/NdbConfig.c:
  moved naming of all "ndb" file into NdbConfig.c
ndb/src/common/transporter/TransporterRegistry.cpp:
  spelling errors
ndb/src/kernel/error/ErrorReporter.cpp:
  moved naming of all "ndb" file into NdbConfig.c
ndb/src/kernel/error/ErrorReporter.hpp:
  moved naming of all "ndb" file into NdbConfig.c
ndb/src/kernel/main.cpp:
  moved naming of all "ndb" file into NdbConfig.c
ndb/src/kernel/vm/Configuration.cpp:
  moved allocation of ConfigRetriever object to Configuration to enable holing "config" open until setup finished
ndb/src/kernel/vm/Configuration.hpp:
  moved allocation of ConfigRetriever object to Configuration to enable holing "config" open until setup finished
ndb/src/mgmclient/main.cpp:
  fix default port number
ndb/src/mgmsrv/MgmtSrvr.cpp:
  fix default port
ndb/src/mgmsrv/Services.cpp:
  added spec of transporter in get_nodeid
ndb/src/mgmsrv/main.cpp:
  moved naming of all "ndb" file into NdbConfig.c
ndb/src/ndbapi/TransporterFacade.cpp:
  moved allocation of ConfigRetriever object to TransporterFacade to enable holing "config" open until setup finished
ndb/src/ndbapi/TransporterFacade.hpp:
  moved allocation of ConfigRetriever object to TransporterFacade to enable holing "config" open until setup finished
parent e99fe597
...@@ -72,13 +72,6 @@ public: ...@@ -72,13 +72,6 @@ public:
*/ */
~EventLogger(); ~EventLogger();
/**
* Open/create the eventlog, the default name is 'cluster.log'.
*
* @return true if successful.
*/
bool open();
/** /**
* Opens/creates the eventlog with the specified filename. * Opens/creates the eventlog with the specified filename.
* *
......
...@@ -99,6 +99,8 @@ private: ...@@ -99,6 +99,8 @@ private:
char * m_connectString; char * m_connectString;
char * m_defaultConnectString; char * m_defaultConnectString;
NdbMgmHandle m_handle;
/** /**
* Verify config * Verify config
*/ */
......
...@@ -21,11 +21,14 @@ ...@@ -21,11 +21,14 @@
extern "C" { extern "C" {
#endif #endif
const char* NdbConfig_HomePath(char* buf, int buflen); char* NdbConfig_NdbCfgName(int with_ndb_home);
char* NdbConfig_ErrorFileName(int node_id);
const char* NdbConfig_NdbCfgName(char* buf, int buflen, int with_ndb_home); char* NdbConfig_ClusterLogFileName(int node_id);
const char* NdbConfig_ErrorFileName(char* buf, int buflen); char* NdbConfig_SignalLogFileName(int node_id);
const char* NdbConfig_ClusterLogFileName(char* buf, int buflen); char* NdbConfig_TraceFileName(int node_id, int file_no);
char* NdbConfig_NextTraceFileName(int node_id);
char* NdbConfig_PidFileName(int node_id);
char* NdbConfig_StdoutFileName(int node_id);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <my_global.h> #include <my_global.h>
#define NDB_BASE_PORT 2200
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32) #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
#define NDB_WIN32 #define NDB_WIN32
#else #else
......
...@@ -1350,15 +1350,6 @@ EventLogger::EventLogger() : Logger(), m_logLevel(), m_filterLevel(15) ...@@ -1350,15 +1350,6 @@ EventLogger::EventLogger() : Logger(), m_logLevel(), m_filterLevel(15)
EventLogger::~EventLogger() EventLogger::~EventLogger()
{ {
}
bool
EventLogger::open()
{
char clusterLog[128];
NdbConfig_ClusterLogFileName(clusterLog, 128);
return open(clusterLog);
} }
bool bool
......
...@@ -103,7 +103,7 @@ ConfigInfo::m_SectionRules[] = { ...@@ -103,7 +103,7 @@ ConfigInfo::m_SectionRules[] = {
{ "OSE", fixHostname, "HostName1" }, { "OSE", fixHostname, "HostName1" },
{ "OSE", fixHostname, "HostName2" }, { "OSE", fixHostname, "HostName2" },
{ "TCP", fixPortNumber, 0 }, { "TCP", fixPortNumber, 0 }, // has to come after fixHostName
//{ "SHM", fixShmKey, 0 }, //{ "SHM", fixShmKey, 0 },
/** /**
...@@ -337,7 +337,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { ...@@ -337,7 +337,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = {
ConfigInfo::USED, ConfigInfo::USED,
false, false,
ConfigInfo::INT, ConfigInfo::INT,
2202, NDB_BASE_PORT+2,
0, 0,
0x7FFFFFFF }, 0x7FFFFFFF },
...@@ -1382,7 +1382,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { ...@@ -1382,7 +1382,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = {
ConfigInfo::USED, ConfigInfo::USED,
false, false,
ConfigInfo::INT, ConfigInfo::INT,
2200, NDB_BASE_PORT,
0, 0,
0x7FFFFFFF }, 0x7FFFFFFF },
...@@ -1566,7 +1566,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { ...@@ -1566,7 +1566,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = {
ConfigInfo::USED, ConfigInfo::USED,
false, false,
ConfigInfo::INT, ConfigInfo::INT,
2202, NDB_BASE_PORT+2,
0, 0,
0x7FFFFFFF }, 0x7FFFFFFF },
...@@ -2517,11 +2517,27 @@ transformNode(InitConfigFileParser::Context & ctx, const char * data){ ...@@ -2517,11 +2517,27 @@ transformNode(InitConfigFileParser::Context & ctx, const char * data){
Uint32 id; Uint32 id;
if(!ctx.m_currentSection->get("Id", &id)){ if(!ctx.m_currentSection->get("Id", &id)){
Uint32 nextNodeId= 1;
ctx.m_userProperties.get("NextNodeId", &nextNodeId);
id= nextNodeId;
while (ctx.m_userProperties.get("AllocatedNodeId_", id, &id))
id++;
ctx.m_userProperties.put("NextNodeId", id+1, true);
ctx.m_currentSection->put("Id", id);
#if 0
ctx.reportError("Mandatory parameter Id missing from section " ctx.reportError("Mandatory parameter Id missing from section "
"[%s] starting at line: %d", "[%s] starting at line: %d",
ctx.fname, ctx.m_sectionLineno); ctx.fname, ctx.m_sectionLineno);
return false; return false;
#endif
} else if(ctx.m_userProperties.get("AllocatedNodeId_", id, &id)) {
ctx.reportError("Duplicate Id in section "
"[%s] starting at line: %d",
ctx.fname, ctx.m_sectionLineno);
return false;
} }
ctx.m_userProperties.put("AllocatedNodeId_", id, id);
snprintf(ctx.pname, sizeof(ctx.pname), "Node_%d", id); snprintf(ctx.pname, sizeof(ctx.pname), "Node_%d", id);
ctx.m_currentSection->put("Type", ctx.fname); ctx.m_currentSection->put("Type", ctx.fname);
...@@ -3317,7 +3333,7 @@ bool add_server_ports(Vector<ConfigInfo::ConfigRuleSection>&sections, ...@@ -3317,7 +3333,7 @@ bool add_server_ports(Vector<ConfigInfo::ConfigRuleSection>&sections,
#if 0 #if 0
Properties * props= ctx.m_config; Properties * props= ctx.m_config;
Properties computers; Properties computers;
Uint32 port_base = 2202; Uint32 port_base = NDB_BASE_PORT+2;
Uint32 nNodes; Uint32 nNodes;
ctx.m_userProperties.get("NoOfNodes", &nNodes); ctx.m_userProperties.get("NoOfNodes", &nNodes);
......
...@@ -45,13 +45,15 @@ ...@@ -45,13 +45,15 @@
ConfigRetriever::ConfigRetriever() { ConfigRetriever::ConfigRetriever() {
_localConfigFileName = NULL; _localConfigFileName = 0;
m_defaultConnectString = NULL; m_defaultConnectString = 0;
errorString = 0; errorString = 0;
_localConfig = new LocalConfig(); _localConfig = new LocalConfig();
m_connectString = NULL; m_connectString = 0;
m_handle= 0;
} }
ConfigRetriever::~ConfigRetriever(){ ConfigRetriever::~ConfigRetriever(){
...@@ -68,6 +70,11 @@ ConfigRetriever::~ConfigRetriever(){ ...@@ -68,6 +70,11 @@ ConfigRetriever::~ConfigRetriever(){
free(errorString); free(errorString);
delete _localConfig; delete _localConfig;
if (m_handle) {
ndb_mgm_disconnect(m_handle);
ndb_mgm_destroy_handle(&m_handle);
}
} }
...@@ -158,45 +165,51 @@ ConfigRetriever::getConfig(const char * mgmhost, ...@@ -158,45 +165,51 @@ ConfigRetriever::getConfig(const char * mgmhost,
short port, short port,
int versionId, int versionId,
int nodetype){ int nodetype){
if (m_handle) {
ndb_mgm_disconnect(m_handle);
ndb_mgm_destroy_handle(&m_handle);
}
NdbMgmHandle h; m_handle = ndb_mgm_create_handle();
h = ndb_mgm_create_handle();
if (h == NULL) { if (m_handle == 0) {
setError(CR_ERROR, "Unable to allocate mgm handle"); setError(CR_ERROR, "Unable to allocate mgm handle");
return 0; return 0;
} }
BaseString tmp; BaseString tmp;
tmp.assfmt("%s:%d", mgmhost, port); tmp.assfmt("%s:%d", mgmhost, port);
if (ndb_mgm_connect(h, tmp.c_str()) != 0) { if (ndb_mgm_connect(m_handle, tmp.c_str()) != 0) {
setError(CR_RETRY, ndb_mgm_get_latest_error_desc(h)); setError(CR_RETRY, ndb_mgm_get_latest_error_desc(m_handle));
ndb_mgm_destroy_handle(&h); ndb_mgm_destroy_handle(&m_handle);
m_handle= 0;
return 0; return 0;
} }
ndb_mgm_configuration * conf = ndb_mgm_get_configuration(h, versionId); ndb_mgm_configuration * conf = ndb_mgm_get_configuration(m_handle, versionId);
if(conf == 0){ if(conf == 0){
setError(CR_ERROR, ndb_mgm_get_latest_error_desc(h)); setError(CR_ERROR, ndb_mgm_get_latest_error_desc(m_handle));
ndb_mgm_destroy_handle(&h); ndb_mgm_disconnect(m_handle);
ndb_mgm_destroy_handle(&m_handle);
m_handle= 0;
return 0; return 0;
} }
{ {
unsigned nodeid= getOwnNodeId(); unsigned nodeid= getOwnNodeId();
int res= ndb_mgm_alloc_nodeid(h, versionId, &nodeid, nodetype); int res= ndb_mgm_alloc_nodeid(m_handle, versionId, &nodeid, nodetype);
if(res != 0) { if(res != 0) {
setError(CR_ERROR, ndb_mgm_get_latest_error_desc(h)); setError(CR_ERROR, ndb_mgm_get_latest_error_desc(m_handle));
ndb_mgm_destroy_handle(&h); ndb_mgm_disconnect(m_handle);
ndb_mgm_destroy_handle(&m_handle);
m_handle= 0;
return 0; return 0;
} }
_ownNodeId= nodeid; _ownNodeId= nodeid;
} }
ndb_mgm_disconnect(h);
ndb_mgm_destroy_handle(&h);
return conf; return conf;
#if 0 #if 0
bool compatible; bool compatible;
......
...@@ -443,7 +443,7 @@ IPCConfig::configureTransporters(Uint32 nodeId, ...@@ -443,7 +443,7 @@ IPCConfig::configureTransporters(Uint32 nodeId,
if (nodeId <= nodeId1 && nodeId <= nodeId2) { if (nodeId <= nodeId1 && nodeId <= nodeId2) {
if (server_port && server_port != conf.port) { if (server_port && server_port != conf.port) {
ndbout << "internal error in config setup line=" << __LINE__ << endl; ndbout << "internal error in config setup of server ports line= " << __LINE__ << endl;
exit(-1); exit(-1);
} }
server_port= conf.port; server_port= conf.port;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "LocalConfig.hpp" #include "LocalConfig.hpp"
#include <NdbEnv.h> #include <NdbEnv.h>
#include <NdbConfig.h> #include <NdbConfig.h>
#include <NdbAutoPtr.hpp>
LocalConfig::LocalConfig(){ LocalConfig::LocalConfig(){
ids = 0; size = 0; items = 0; ids = 0; size = 0; items = 0;
...@@ -69,10 +70,10 @@ LocalConfig::init(bool onlyNodeId, ...@@ -69,10 +70,10 @@ LocalConfig::init(bool onlyNodeId,
//4. Check Ndb.cfg in NDB_HOME //4. Check Ndb.cfg in NDB_HOME
{ {
bool fopenError; bool fopenError;
char buf[256]; char *buf= NdbConfig_NdbCfgName(1 /*true*/);
if(readFile(NdbConfig_NdbCfgName(buf, sizeof(buf), 1 /*true*/), fopenError, onlyNodeId)){ NdbAutoPtr<char> tmp_aptr(buf);
if(readFile(buf, fopenError, onlyNodeId))
return true; return true;
}
if (!fopenError) if (!fopenError)
return false; return false;
} }
...@@ -80,24 +81,26 @@ LocalConfig::init(bool onlyNodeId, ...@@ -80,24 +81,26 @@ LocalConfig::init(bool onlyNodeId,
//5. Check Ndb.cfg in cwd //5. Check Ndb.cfg in cwd
{ {
bool fopenError; bool fopenError;
char buf[256]; char *buf= NdbConfig_NdbCfgName(0 /*false*/);
if(readFile(NdbConfig_NdbCfgName(buf, sizeof(buf), 0 /*false*/), fopenError, onlyNodeId)){ NdbAutoPtr<char> tmp_aptr(buf);
if(readFile(buf, fopenError, onlyNodeId))
return true; return true;
}
if (!fopenError) if (!fopenError)
return false; return false;
} }
//6. Check defaultConnectString //6. Check defaultConnectString
if(defaultConnectString != 0) { if(defaultConnectString != 0) {
if(readConnectString(defaultConnectString, onlyNodeId)){ if(readConnectString(defaultConnectString, onlyNodeId))
return true; return true;
}
return false; return false;
} }
//7. Check //7. Check
if(readConnectString("host=localhost:2200", onlyNodeId)){ {
char buf[256];
snprintf(buf, sizeof(buf), "host=localhost:%u", NDB_BASE_PORT);
if(readConnectString(buf, onlyNodeId))
return true; return true;
} }
...@@ -150,12 +153,12 @@ void LocalConfig::printUsage() const { ...@@ -150,12 +153,12 @@ void LocalConfig::printUsage() const {
ndbout << "1. Put a Ndb.cfg file in the directory where you start"<<endl ndbout << "1. Put a Ndb.cfg file in the directory where you start"<<endl
<< " the node. "<< endl << " the node. "<< endl
<< " Ex: Ndb.cfg" << endl << " Ex: Ndb.cfg" << endl
<< " | nodeid=11;host=localhost:2200"<<endl<<endl; << " | host=localhost:"<<NDB_BASE_PORT<<endl;
ndbout << "2. Use the environment variable NDB_CONNECTSTRING to "<<endl ndbout << "2. Use the environment variable NDB_CONNECTSTRING to "<<endl
<< " provide this information." <<endl << " provide this information." <<endl
<< " Ex: " << endl << " Ex: " << endl
<< " >export NDB_CONNECTSTRING=\"nodeid=11;host=localhost:2200\"" << " >export NDB_CONNECTSTRING=\"host=localhost:"<<NDB_BASE_PORT<<"\""
<<endl<<endl; <<endl<<endl;
} }
......
...@@ -18,43 +18,92 @@ ...@@ -18,43 +18,92 @@
#include <NdbConfig.h> #include <NdbConfig.h>
#include <NdbEnv.h> #include <NdbEnv.h>
const char* static char*
NdbConfig_HomePath(char* buf, int buflen){ NdbConfig_AllocHomePath(int _len)
const char* p; {
p = NdbEnv_GetEnv("NDB_HOME", buf, buflen); const char *path= NdbEnv_GetEnv("NDB_HOME", 0, 0);
if (p == NULL){ int len= _len;
strlcpy(buf, "", buflen); int path_len= 0;
p = buf;
} else { if (path)
const int len = strlen(buf); path_len= strlen(path);
if(len != 0 && buf[len-1] != '/'){
buf[len] = '/'; len+= path_len;
buf[len+1] = 0; char *buf= malloc(len);
} if (path_len > 0)
} snprintf(buf, len, "%s%c", path, DIR_SEPARATOR);
return p;
}
const char*
NdbConfig_NdbCfgName(char* buf, int buflen, int with_ndb_home){
if (with_ndb_home)
NdbConfig_HomePath(buf, buflen);
else else
buf[0] = 0; buf[0]= 0;
strlcat(buf, "Ndb.cfg", buflen);
return buf;
}
char*
NdbConfig_NdbCfgName(int with_ndb_home){
char *buf;
int len= 0;
if (with_ndb_home) {
buf= NdbConfig_AllocHomePath(128);
len= strlen(buf);
} else
buf= malloc(128);
snprintf(buf+len, 128, "Ndb.cfg");
return buf;
}
char*
NdbConfig_ErrorFileName(int node_id){
char *buf= NdbConfig_AllocHomePath(128);
int len= strlen(buf);
snprintf(buf+len, 128, "ndb_%u_error.log", node_id);
return buf;
}
char*
NdbConfig_ClusterLogFileName(int node_id){
char *buf= NdbConfig_AllocHomePath(128);
int len= strlen(buf);
snprintf(buf+len, 128, "ndb_%u_cluster.log", node_id);
return buf;
}
char*
NdbConfig_SignalLogFileName(int node_id){
char *buf= NdbConfig_AllocHomePath(128);
int len= strlen(buf);
snprintf(buf+len, 128, "ndb_%u_signal.log", node_id);
return buf;
}
char*
NdbConfig_TraceFileName(int node_id, int file_no){
char *buf= NdbConfig_AllocHomePath(128);
int len= strlen(buf);
snprintf(buf+len, 128, "ndb_%u_trace.log.%u", node_id, file_no);
return buf;
}
char*
NdbConfig_NextTraceFileName(int node_id){
char *buf= NdbConfig_AllocHomePath(128);
int len= strlen(buf);
snprintf(buf+len, 128, "ndb_%u_trace.log.next", node_id);
return buf; return buf;
} }
const char* char*
NdbConfig_ErrorFileName(char* buf, int buflen){ NdbConfig_PidFileName(int node_id){
NdbConfig_HomePath(buf, buflen); char *buf= NdbConfig_AllocHomePath(128);
strlcat(buf, "error.log", buflen); int len= strlen(buf);
snprintf(buf+len, 128, "ndb_%u.pid", node_id);
return buf; return buf;
} }
const char* char*
NdbConfig_ClusterLogFileName(char* buf, int buflen){ NdbConfig_StdoutFileName(int node_id){
NdbConfig_HomePath(buf, buflen); char *buf= NdbConfig_AllocHomePath(128);
strlcat(buf, "cluster.log", buflen); int len= strlen(buf);
snprintf(buf+len, 128, "ndb_%u_out.log", node_id);
return buf; return buf;
} }
...@@ -85,11 +85,11 @@ SocketServer::Session * TransporterService::newSession(NDB_SOCKET_TYPE sockfd) ...@@ -85,11 +85,11 @@ SocketServer::Session * TransporterService::newSession(NDB_SOCKET_TYPE sockfd)
Transporter *t= m_transporter_registry->theTransporters[nodeId]; Transporter *t= m_transporter_registry->theTransporters[nodeId];
// send info about own id (just as response to acnowledge connection) // send info about own id (just as response to acknowledge connection)
SocketOutputStream s_output(sockfd); SocketOutputStream s_output(sockfd);
s_output.println("%d", t->getLocalNodeId()); s_output.println("%d", t->getLocalNodeId());
// setup transporter (transporter responsable for closing sockfd) // setup transporter (transporter responsible for closing sockfd)
t->connect_server(sockfd); t->connect_server(sockfd);
} }
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include <NdbConfig.h> #include <NdbConfig.h>
#include <Configuration.hpp> #include <Configuration.hpp>
#include <NdbAutoPtr.hpp>
#define MESSAGE_LENGTH 400 #define MESSAGE_LENGTH 400
const char* errorType[] = { const char* errorType[] = {
...@@ -66,23 +68,23 @@ ErrorReporter::formatTimeStampString(){ ...@@ -66,23 +68,23 @@ ErrorReporter::formatTimeStampString(){
return (const char *)&theDateTimeString; return (const char *)&theDateTimeString;
} }
void int
ErrorReporter::formatTraceFileName(char* theName, int maxLen){ ErrorReporter::get_trace_no(){
FILE *stream; FILE *stream;
unsigned int traceFileNo; unsigned int traceFileNo;
char fileNameBuf[255];
char buf[255];
NdbConfig_HomePath(fileNameBuf, 255); char *file_name= NdbConfig_NextTraceFileName(globalData.ownId);
strncat(fileNameBuf, "NextTraceFileNo.log", 255); NdbAutoPtr<char> tmp_aptr(file_name);
/* /*
* Read last number from tracefile * Read last number from tracefile
*/ */
stream = fopen(fileNameBuf, "r+"); stream = fopen(file_name, "r+");
if (stream == NULL){ if (stream == NULL){
traceFileNo = 1; traceFileNo = 1;
} else { } else {
char buf[255];
fgets(buf, 255, stream); fgets(buf, 255, stream);
const int scan = sscanf(buf, "%u", &traceFileNo); const int scan = sscanf(buf, "%u", &traceFileNo);
if(scan != 1){ if(scan != 1){
...@@ -103,16 +105,13 @@ ErrorReporter::formatTraceFileName(char* theName, int maxLen){ ...@@ -103,16 +105,13 @@ ErrorReporter::formatTraceFileName(char* theName, int maxLen){
/** /**
* Save new number to the file * Save new number to the file
*/ */
stream = fopen(fileNameBuf, "w"); stream = fopen(file_name, "w");
if(stream != NULL){ if(stream != NULL){
fprintf(stream, "%u", traceFileNo); fprintf(stream, "%u", traceFileNo);
fclose(stream); fclose(stream);
} }
/**
* Format trace file name return traceFileNo;
*/
snprintf(theName, maxLen, "%sNDB_TraceFile_%u.trace",
NdbConfig_HomePath(fileNameBuf, 255), traceFileNo);
} }
...@@ -214,16 +213,22 @@ WriteMessage(ErrorCategory thrdType, int thrdMessageID, ...@@ -214,16 +213,22 @@ WriteMessage(ErrorCategory thrdType, int thrdMessageID,
unsigned offset; unsigned offset;
unsigned long maxOffset; // Maximum size of file. unsigned long maxOffset; // Maximum size of file.
char theMessage[MESSAGE_LENGTH]; char theMessage[MESSAGE_LENGTH];
char theTraceFileName[255];
char theErrorFileName[255]; /**
ErrorReporter::formatTraceFileName(theTraceFileName, 255); * Format trace file name
*/
int file_no= ErrorReporter::get_trace_no();
char *theTraceFileName= NdbConfig_TraceFileName(globalData.ownId, file_no);
NdbAutoPtr<char> tmp_aptr1(theTraceFileName);
// The first 69 bytes is info about the current offset // The first 69 bytes is info about the current offset
Uint32 noMsg = globalEmulatorData.theConfiguration->maxNoOfErrorLogs(); Uint32 noMsg = globalEmulatorData.theConfiguration->maxNoOfErrorLogs();
maxOffset = (69 + (noMsg * MESSAGE_LENGTH)); maxOffset = (69 + (noMsg * MESSAGE_LENGTH));
NdbConfig_ErrorFileName(theErrorFileName, 255); char *theErrorFileName= (char *)NdbConfig_ErrorFileName(globalData.ownId);
NdbAutoPtr<char> tmp_aptr2(theErrorFileName);
stream = fopen(theErrorFileName, "r+"); stream = fopen(theErrorFileName, "r+");
if (stream == NULL) { /* If the file could not be opened. */ if (stream == NULL) { /* If the file could not be opened. */
......
...@@ -81,7 +81,7 @@ public: ...@@ -81,7 +81,7 @@ public:
const char* theNameOfTheTraceFile, const char* theNameOfTheTraceFile,
char* messptr); char* messptr);
static void formatTraceFileName(char* theName, int maxLen); static int get_trace_no();
static const char* formatTimeStampString(); static const char* formatTimeStampString();
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
#include <LogLevel.hpp> #include <LogLevel.hpp>
#include <EventLogger.hpp> #include <EventLogger.hpp>
#include <NodeState.hpp>
#include <NdbAutoPtr.hpp>
#if defined NDB_SOLARIS // ok #if defined NDB_SOLARIS // ok
#include <sys/processor.h> // For system informatio #include <sys/processor.h> // For system informatio
...@@ -71,15 +72,12 @@ NDB_MAIN(ndb_kernel){ ...@@ -71,15 +72,12 @@ NDB_MAIN(ndb_kernel){
theConfig->setupConfiguration(); theConfig->setupConfiguration();
} }
// Get NDB_HOME path
char homePath[255];
NdbConfig_HomePath(homePath, 255);
if (theConfig->getDaemonMode()) { if (theConfig->getDaemonMode()) {
// Become a daemon // Become a daemon
char lockfile[255], logfile[255]; char *lockfile= NdbConfig_PidFileName(globalData.ownId);
snprintf(lockfile, 255, "%snode%d.pid", homePath, globalData.ownId); char *logfile= NdbConfig_StdoutFileName(globalData.ownId);
snprintf(logfile, 255, "%snode%d.out", homePath, globalData.ownId); NdbAutoPtr<char> tmp_aptr1(lockfile), tmp_aptr2(logfile);
if (NdbDaemon_Make(lockfile, logfile, 0) == -1) { if (NdbDaemon_Make(lockfile, logfile, 0) == -1) {
ndbout << "Cannot become daemon: " << NdbDaemon_ErrorText << endl; ndbout << "Cannot become daemon: " << NdbDaemon_ErrorText << endl;
return 1; return 1;
...@@ -90,6 +88,8 @@ NDB_MAIN(ndb_kernel){ ...@@ -90,6 +88,8 @@ NDB_MAIN(ndb_kernel){
/** /**
* Parent * Parent
*/ */
theConfig->closeConfiguration();
catchsigs(true); catchsigs(true);
int status = 0; int status = 0;
...@@ -147,9 +147,9 @@ NDB_MAIN(ndb_kernel){ ...@@ -147,9 +147,9 @@ NDB_MAIN(ndb_kernel){
#ifdef VM_TRACE #ifdef VM_TRACE
// Create a signal logger // Create a signal logger
char buf[255]; char *buf= NdbConfig_SignalLogFileName(globalData.ownId);
strcpy(buf, homePath); NdbAutoPtr<char> tmp_aptr(buf);
FILE * signalLog = fopen(strncat(buf,"Signal.log", 255), "a"); FILE * signalLog = fopen(buf, "a");
globalSignalLoggers.setOwnNodeId(globalData.ownId); globalSignalLoggers.setOwnNodeId(globalData.ownId);
globalSignalLoggers.setOutputStream(signalLog); globalSignalLoggers.setOutputStream(signalLog);
#endif #endif
...@@ -185,6 +185,8 @@ NDB_MAIN(ndb_kernel){ ...@@ -185,6 +185,8 @@ NDB_MAIN(ndb_kernel){
socket_server.startServer(); socket_server.startServer();
// theConfig->closeConfiguration();
globalEmulatorData.theThreadConfig->ipControlLoop(); globalEmulatorData.theThreadConfig->ipControlLoop();
NdbShutdown(NST_Normal); NdbShutdown(NST_Normal);
......
...@@ -138,6 +138,7 @@ Configuration::Configuration() ...@@ -138,6 +138,7 @@ Configuration::Configuration()
_fsPath = 0; _fsPath = 0;
_initialStart = false; _initialStart = false;
_daemonMode = false; _daemonMode = false;
m_config_retriever= 0;
} }
Configuration::~Configuration(){ Configuration::~Configuration(){
...@@ -146,6 +147,18 @@ Configuration::~Configuration(){ ...@@ -146,6 +147,18 @@ Configuration::~Configuration(){
if(_fsPath != NULL) if(_fsPath != NULL)
free(_fsPath); free(_fsPath);
if (m_config_retriever) {
delete m_config_retriever;
}
}
void
Configuration::closeConfiguration(){
if (m_config_retriever) {
delete m_config_retriever;
}
m_config_retriever= 0;
} }
void void
...@@ -153,7 +166,12 @@ Configuration::setupConfiguration(){ ...@@ -153,7 +166,12 @@ Configuration::setupConfiguration(){
/** /**
* Fetch configuration from management server * Fetch configuration from management server
*/ */
ConfigRetriever cr; if (m_config_retriever) {
delete m_config_retriever;
}
m_config_retriever= new ConfigRetriever();
ConfigRetriever &cr= *m_config_retriever;
cr.setConnectString(_connectString); cr.setConnectString(_connectString);
stopOnError(true); stopOnError(true);
ndb_mgm_configuration * p = cr.getConfig(NDB_VERSION, NODE_TYPE_DB); ndb_mgm_configuration * p = cr.getConfig(NDB_VERSION, NODE_TYPE_DB);
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include <mgmapi.h> #include <mgmapi.h>
#include <ndb_types.h> #include <ndb_types.h>
class ConfigRetriever;
class Configuration { class Configuration {
public: public:
Configuration(); Configuration();
...@@ -31,6 +33,7 @@ public: ...@@ -31,6 +33,7 @@ public:
bool init(int argc, const char** argv); bool init(int argc, const char** argv);
void setupConfiguration(); void setupConfiguration();
void closeConfiguration();
bool lockPagesInMainMemory() const; bool lockPagesInMainMemory() const;
...@@ -78,6 +81,8 @@ private: ...@@ -78,6 +81,8 @@ private:
ndb_mgm_configuration_iterator * m_clusterConfigIter; ndb_mgm_configuration_iterator * m_clusterConfigIter;
ndb_mgm_configuration_iterator * m_ownConfigIterator; ndb_mgm_configuration_iterator * m_ownConfigIterator;
ConfigRetriever *m_config_retriever;
/** /**
* arguments to NDB process * arguments to NDB process
*/ */
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <signal.h> #include <signal.h>
const char *progname = "mgmtclient"; const char *progname = "ndb_mgm";
static CommandInterpreter* com; static CommandInterpreter* com;
...@@ -47,7 +47,10 @@ handler(int sig){ ...@@ -47,7 +47,10 @@ handler(int sig){
int main(int argc, const char** argv){ int main(int argc, const char** argv){
int optind = 0; int optind = 0;
const char *_default_connectstring = "host=localhost:2200;nodeid=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;
......
...@@ -47,6 +47,8 @@ ...@@ -47,6 +47,8 @@
#include "NodeLogLevel.hpp" #include "NodeLogLevel.hpp"
#include <NdbConfig.h> #include <NdbConfig.h>
#include <NdbAutoPtr.hpp>
#include <mgmapi.h> #include <mgmapi.h>
#include <mgmapi_configuration.hpp> #include <mgmapi_configuration.hpp>
#include <mgmapi_config_parameters.h> #include <mgmapi_config_parameters.h>
...@@ -240,9 +242,8 @@ MgmtSrvr::startEventLog() ...@@ -240,9 +242,8 @@ MgmtSrvr::startEventLog()
const char * tmp; const char * tmp;
BaseString logdest; BaseString logdest;
char clusterLog[MAXPATHLEN]; char *clusterLog= NdbConfig_ClusterLogFileName(_ownNodeId);
NdbConfig_ClusterLogFileName(clusterLog, sizeof(clusterLog)); NdbAutoPtr<char> tmp_aptr(clusterLog);
if(ndb_mgm_get_string_parameter(iter, CFG_LOG_DESTINATION, &tmp) == 0){ if(ndb_mgm_get_string_parameter(iter, CFG_LOG_DESTINATION, &tmp) == 0){
logdest.assign(tmp); logdest.assign(tmp);
...@@ -2325,7 +2326,7 @@ MgmtSrvr::getFreeNodeId(NodeId * nodeId, enum ndb_mgm_node_type type, ...@@ -2325,7 +2326,7 @@ MgmtSrvr::getFreeNodeId(NodeId * nodeId, enum ndb_mgm_node_type type,
// getsockname(int s, struct sockaddr *name, socklen_t *namelen); // getsockname(int s, struct sockaddr *name, socklen_t *namelen);
if (config_hostname && config_hostname[0] != 0) { if (config_hostname && config_hostname[0] != 0 && client_addr) {
// check hostname compatability // check hostname compatability
struct in_addr config_addr; struct in_addr config_addr;
if(Ndb_getInAddr(&config_addr, config_hostname) != 0 if(Ndb_getInAddr(&config_addr, config_hostname) != 0
......
...@@ -124,6 +124,7 @@ ParserRow<MgmApiSession> commands[] = { ...@@ -124,6 +124,7 @@ ParserRow<MgmApiSession> commands[] = {
MGM_CMD("get nodeid", &MgmApiSession::get_nodeid, ""), MGM_CMD("get nodeid", &MgmApiSession::get_nodeid, ""),
MGM_ARG("version", Int, Mandatory, "Configuration version number"), MGM_ARG("version", Int, Mandatory, "Configuration version number"),
MGM_ARG("nodetype", Int, Mandatory, "Node type"), MGM_ARG("nodetype", Int, Mandatory, "Node type"),
MGM_ARG("transporter", String, Optional, "Transporter type"),
MGM_ARG("nodeid", Int, Optional, "Node ID"), MGM_ARG("nodeid", Int, Optional, "Node ID"),
MGM_ARG("user", String, Mandatory, "Password"), MGM_ARG("user", String, Mandatory, "Password"),
MGM_ARG("password", String, Mandatory, "Password"), MGM_ARG("password", String, Mandatory, "Password"),
...@@ -359,12 +360,14 @@ MgmApiSession::get_nodeid(Parser_t::Context &, ...@@ -359,12 +360,14 @@ MgmApiSession::get_nodeid(Parser_t::Context &,
{ {
const char *cmd= "get nodeid reply"; const char *cmd= "get nodeid reply";
Uint32 version, nodeid= 0, nodetype= 0xff; Uint32 version, nodeid= 0, nodetype= 0xff;
const char * transporter;
const char * user; const char * user;
const char * password; const char * password;
const char * public_key; const char * public_key;
args.get("version", &version); args.get("version", &version);
args.get("nodetype", &nodetype); args.get("nodetype", &nodetype);
args.get("transporter", &transporter);
args.get("nodeid", &nodeid); args.get("nodeid", &nodeid);
args.get("user", &user); args.get("user", &user);
args.get("password", &password); args.get("password", &password);
...@@ -388,9 +391,10 @@ MgmApiSession::get_nodeid(Parser_t::Context &, ...@@ -388,9 +391,10 @@ MgmApiSession::get_nodeid(Parser_t::Context &,
struct sockaddr addr; struct sockaddr addr;
socklen_t addrlen; socklen_t addrlen;
if (getsockname(m_socket, &addr, &addrlen)) { int r;
if (r= getsockname(m_socket, &addr, &addrlen)) {
m_output->println(cmd); m_output->println(cmd);
m_output->println("result: getsockname(%d)", m_socket); m_output->println("result: getsockname(%d) failed, err= %d", m_socket, r);
m_output->println(""); m_output->println("");
return; return;
} }
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include <mgmapi_config_parameters.h> #include <mgmapi_config_parameters.h>
#include <getarg.h> #include <getarg.h>
#include <NdbAutoPtr.hpp>
#if defined NDB_OSE || defined NDB_SOFTOSE #if defined NDB_OSE || defined NDB_SOFTOSE
#include <efs.h> #include <efs.h>
#else #else
...@@ -217,10 +219,10 @@ NDB_MAIN(mgmsrv){ ...@@ -217,10 +219,10 @@ NDB_MAIN(mgmsrv){
if (glob.daemon) { if (glob.daemon) {
// Become a daemon // Become a daemon
char homePath[255],lockfile[255], logfile[255]; char *lockfile= NdbConfig_PidFileName(glob.localNodeId);
NdbConfig_HomePath(homePath, 255); char *logfile= NdbConfig_StdoutFileName(glob.localNodeId);
snprintf(lockfile, 255, "%snode%d.pid", homePath, glob.localNodeId); NdbAutoPtr<char> tmp_aptr1(lockfile), tmp_aptr2(logfile);
snprintf(logfile, 255, "%snode%d.out", homePath, glob.localNodeId);
if (NdbDaemon_Make(lockfile, logfile, 0) == -1) { if (NdbDaemon_Make(lockfile, logfile, 0) == -1) {
ndbout << "Cannot become daemon: " << NdbDaemon_ErrorText << endl; ndbout << "Cannot become daemon: " << NdbDaemon_ErrorText << endl;
return 1; return 1;
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#endif #endif
TransporterFacade* TransporterFacade::theFacadeInstance = NULL; TransporterFacade* TransporterFacade::theFacadeInstance = NULL;
ConfigRetriever *TransporterFacade::s_config_retriever= 0;
/***************************************************************************** /*****************************************************************************
...@@ -333,11 +333,15 @@ atexit_stop_instance(){ ...@@ -333,11 +333,15 @@ atexit_stop_instance(){
* *
* Which is protected by a mutex * Which is protected by a mutex
*/ */
TransporterFacade* 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
ConfigRetriever configRetriever; s_config_retriever= new ConfigRetriever;
ConfigRetriever &configRetriever= *s_config_retriever;
configRetriever.setConnectString(connectString); configRetriever.setConnectString(connectString);
ndb_mgm_configuration * props = configRetriever.getConfig(NDB_VERSION, ndb_mgm_configuration * props = configRetriever.getConfig(NDB_VERSION,
NODE_TYPE_API); NODE_TYPE_API);
...@@ -390,6 +394,14 @@ TransporterFacade::start_instance(int nodeId, ...@@ -390,6 +394,14 @@ TransporterFacade::start_instance(int nodeId,
return tf; return tf;
} }
void
TransporterFacade::close_configuration(){
if (s_config_retriever) {
delete s_config_retriever;
s_config_retriever= 0;
}
}
/** /**
* Note that this function need no locking since its * Note that this function need no locking since its
* only called from the destructor of Ndb (the NdbObject) * only called from the destructor of Ndb (the NdbObject)
...@@ -398,6 +410,9 @@ TransporterFacade::start_instance(int nodeId, ...@@ -398,6 +410,9 @@ TransporterFacade::start_instance(int nodeId,
*/ */
void void
TransporterFacade::stop_instance(){ TransporterFacade::stop_instance(){
close_configuration();
if(theFacadeInstance == NULL){ if(theFacadeInstance == NULL){
/** /**
* We are called from atexit function * We are called from atexit function
......
...@@ -29,6 +29,7 @@ class ClusterMgr; ...@@ -29,6 +29,7 @@ class ClusterMgr;
class ArbitMgr; class ArbitMgr;
class IPCConfig; class IPCConfig;
struct ndb_mgm_configuration; struct ndb_mgm_configuration;
class ConfigRetriever;
class Ndb; class Ndb;
class NdbApiSignal; class NdbApiSignal;
...@@ -56,6 +57,7 @@ public: ...@@ -56,6 +57,7 @@ public:
static TransporterFacade* instance(); static TransporterFacade* instance();
static TransporterFacade* start_instance(int, const ndb_mgm_configuration*); static TransporterFacade* start_instance(int, const ndb_mgm_configuration*);
static TransporterFacade* start_instance(const char *connectString); static TransporterFacade* start_instance(const char *connectString);
static void close_configuration();
static void stop_instance(); static void stop_instance();
/** /**
...@@ -218,6 +220,7 @@ public: ...@@ -218,6 +220,7 @@ 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;
......
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