summaryrefslogtreecommitdiff
path: root/ndb/src/mgmsrv
diff options
context:
space:
mode:
Diffstat (limited to 'ndb/src/mgmsrv')
-rw-r--r--ndb/src/mgmsrv/MgmtSrvr.cpp29
-rw-r--r--ndb/src/mgmsrv/MgmtSrvr.hpp5
-rw-r--r--ndb/src/mgmsrv/MgmtSrvrConfig.cpp7
-rw-r--r--ndb/src/mgmsrv/Services.cpp41
-rw-r--r--ndb/src/mgmsrv/main.cpp23
5 files changed, 43 insertions, 62 deletions
diff --git a/ndb/src/mgmsrv/MgmtSrvr.cpp b/ndb/src/mgmsrv/MgmtSrvr.cpp
index 523883f7832..55384a2f91e 100644
--- a/ndb/src/mgmsrv/MgmtSrvr.cpp
+++ b/ndb/src/mgmsrv/MgmtSrvr.cpp
@@ -584,18 +584,11 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
_ownNodeId= 0;
NodeId tmp= nodeId;
- if (getFreeNodeId(&tmp, NDB_MGM_NODE_TYPE_MGM, 0, 0)){
- _ownNodeId= tmp;
- 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");
+ if (!alloc_node_id(&tmp, NDB_MGM_NODE_TYPE_MGM, 0, 0)){
+ ndbout << "Unable to obtain requested nodeid " << nodeId;
exit(-1);
}
+ _ownNodeId = tmp;
}
@@ -2301,10 +2294,19 @@ MgmtSrvr::getNodeType(NodeId nodeId) const
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
-MgmtSrvr::getFreeNodeId(NodeId * nodeId, enum ndb_mgm_node_type type,
- struct sockaddr *client_addr, socklen_t *client_addr_len) const
+MgmtSrvr::alloc_node_id(NodeId * nodeId,
+ enum ndb_mgm_node_type type,
+ struct sockaddr *client_addr,
+ socklen_t *client_addr_len)
{
+ Guard g(&f_node_id_mutex);
#if 0
ndbout << "MgmtSrvr::getFreeNodeId type=" << type
<< " *nodeid=" << *nodeId << endl;
@@ -2365,6 +2367,7 @@ MgmtSrvr::getFreeNodeId(NodeId * nodeId, enum ndb_mgm_node_type type,
}
}
*nodeId= tmp;
+ m_reserved_nodes.set(tmp);
#if 0
ndbout << "MgmtSrvr::getFreeNodeId found type=" << type
<< " *nodeid=" << *nodeId << endl;
@@ -2769,6 +2772,7 @@ MgmtSrvr::Allocated_resources::Allocated_resources(MgmtSrvr &m)
MgmtSrvr::Allocated_resources::~Allocated_resources()
{
+ Guard g(&f_node_id_mutex);
m_mgmsrv.m_reserved_nodes.bitANDC(m_reserved_nodes);
}
@@ -2776,7 +2780,6 @@ void
MgmtSrvr::Allocated_resources::reserve_node(NodeId id)
{
m_reserved_nodes.set(id);
- m_mgmsrv.m_reserved_nodes.set(id);
}
int
diff --git a/ndb/src/mgmsrv/MgmtSrvr.hpp b/ndb/src/mgmsrv/MgmtSrvr.hpp
index f677cdbb2d0..661dcdfb784 100644
--- a/ndb/src/mgmsrv/MgmtSrvr.hpp
+++ b/ndb/src/mgmsrv/MgmtSrvr.hpp
@@ -78,6 +78,7 @@ public:
// methods to reserve/allocate resources which
// will be freed when running destructor
void reserve_node(NodeId id);
+ bool is_reserved(NodeId nodeId) { return m_reserved_nodes.get(nodeId);}
private:
MgmtSrvr &m_mgmsrv;
NodeBitmask m_reserved_nodes;
@@ -465,8 +466,8 @@ public:
* @return false if none found
*/
bool getNextNodeId(NodeId * _nodeId, enum ndb_mgm_node_type type) const ;
- bool getFreeNodeId(NodeId * _nodeId, enum ndb_mgm_node_type type,
- struct sockaddr *client_addr, socklen_t *client_addr_len) const ;
+ bool alloc_node_id(NodeId * _nodeId, enum ndb_mgm_node_type type,
+ struct sockaddr *client_addr, socklen_t *client_addr_len);
/**
*
diff --git a/ndb/src/mgmsrv/MgmtSrvrConfig.cpp b/ndb/src/mgmsrv/MgmtSrvrConfig.cpp
index 10316bd2851..44c2aadd1e2 100644
--- a/ndb/src/mgmsrv/MgmtSrvrConfig.cpp
+++ b/ndb/src/mgmsrv/MgmtSrvrConfig.cpp
@@ -288,16 +288,15 @@ MgmtSrvr::readConfig() {
Config *
MgmtSrvr::fetchConfig() {
- ConfigRetriever cr;
+ ConfigRetriever cr(NDB_VERSION, NODE_TYPE_MGM);
cr.setLocalConfigFileName(m_localNdbConfigFilename.c_str());
- struct ndb_mgm_configuration * tmp = cr.getConfig(NDB_VERSION,
- NODE_TYPE_MGM);
+ struct ndb_mgm_configuration * tmp = cr.getConfig();
if(tmp != 0){
Config * conf = new Config();
conf->m_configValues = tmp;
return conf;
}
-
+
return 0;
}
diff --git a/ndb/src/mgmsrv/Services.cpp b/ndb/src/mgmsrv/Services.cpp
index 99913face05..ec734fe24c5 100644
--- a/ndb/src/mgmsrv/Services.cpp
+++ b/ndb/src/mgmsrv/Services.cpp
@@ -401,34 +401,26 @@ MgmApiSession::get_nodeid(Parser_t::Context &,
struct sockaddr addr;
socklen_t addrlen= sizeof(addr);
- int r;
- if (r= getpeername(m_socket, &addr, &addrlen)) {
+ int r = getpeername(m_socket, &addr, &addrlen);
+ if (r != 0 ) {
m_output->println(cmd);
m_output->println("result: getpeername(%d) failed, err= %d", m_socket, r);
m_output->println("");
return;
}
- NodeId free_id= 0;
NodeId tmp= nodeid;
- if (m_mgmsrv.getFreeNodeId(&tmp, (enum ndb_mgm_node_type)nodetype, &addr, &addrlen))
- free_id= tmp;
-
- if (nodeid != 0 && free_id != nodeid){
- m_output->println(cmd);
- m_output->println("result: no free nodeid %d for nodetype %d",
- nodeid, nodetype);
- m_output->println("");
- return;
- }
+ if(tmp == 0 || !m_allocated_resources->is_reserved(tmp)){
+ if (!m_mgmsrv.alloc_node_id(&tmp, (enum ndb_mgm_node_type)nodetype,
+ &addr, &addrlen)){
+ m_output->println(cmd);
+ m_output->println("result: no free nodeid %d for nodetype %d",
+ nodeid, nodetype);
+ m_output->println("");
+ 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 (!compatible){
m_output->println(cmd);
@@ -438,14 +430,13 @@ MgmApiSession::get_nodeid(Parser_t::Context &,
return;
}
#endif
-
+
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("");
-
- m_allocated_resources->reserve_node(free_id);
-
+ m_allocated_resources->reserve_node(tmp);
+
return;
}
diff --git a/ndb/src/mgmsrv/main.cpp b/ndb/src/mgmsrv/main.cpp
index 0bbf042fbd6..9e39452891f 100644
--- a/ndb/src/mgmsrv/main.cpp
+++ b/ndb/src/mgmsrv/main.cpp
@@ -16,8 +16,6 @@
#include <ndb_global.h>
-#include <signal.h>
-
#include "MgmtSrvr.hpp"
#include "EventLogger.hpp"
#include <Config.hpp>
@@ -229,6 +227,7 @@ NDB_MAIN(mgmsrv){
}
}
+ signal(SIGPIPE, SIG_IGN);
if(!glob.mgmObject->start()){
ndbout_c("Unable to start management server.");
ndbout_c("Probably caused by illegal initial configuration file.");
@@ -312,14 +311,13 @@ MgmGlobals::~MgmGlobals(){
static bool
readLocalConfig(){
// Read local config file
- ConfigRetriever cr;
- cr.setLocalConfigFileName(glob.local_config_filename);
- int nodeid = cr.init(true);
+ LocalConfig lc;
+ int nodeid = lc.init(glob.local_config_filename);
if(nodeid == -1){
return false;
}
- glob.localNodeId = (NodeId)nodeid;
+ glob.localNodeId = nodeid;
return true;
}
@@ -342,18 +340,7 @@ readGlobalConfig() {
InitConfigFileParser parser;
glob.cluster_config = parser.parseConfig(glob.config_filename);
if(glob.cluster_config == 0){
- /**
- * 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 false;
}
return true;
}