summaryrefslogtreecommitdiff
path: root/ndb
diff options
context:
space:
mode:
authorunknown <stewart@mysql.com>2005-01-12 18:13:54 +1100
committerunknown <stewart@mysql.com>2005-01-12 18:13:54 +1100
commit5615ff29bbffe2f0c080b6a3cd7f944d9c23df67 (patch)
treef8c7ce80eaf1b1fe5df35c7f8e37852ff50b6d58 /ndb
parentd2e6def187b1950b62685964f83e19214c5a7539 (diff)
downloadmariadb-git-5615ff29bbffe2f0c080b6a3cd7f944d9c23df67.tar.gz
Impl4 of WL2278 - Dynamic port allocation of cluster nodes
When a node restarts it starts over again with fetching the configuration - It is not sure that it can use the "old dynamically allocated port number" again. - It should however try to reuse the old one, if not possible it should allocate a new one. One has to be able to distinguish between portnumbers specified originally in the config, and ones that has been dynamically added (the latter may be changed if "busy", but the first cannot be changed). We use negative portnumbers for ports that are ok to change. ndb/include/mgmapi/mgmapi_debug.h: change prototype for: ndb_mgm_set_connection_int_parameter ndb_mgm_get_connection_int_parameter Accept/set an int instead of an unsigned ndb/include/transporter/TransporterRegistry.hpp: Use an int (signed) to represent a port number. Zero means dynamic (but unassigned) >0 means static (defined in configuration) <0 means dynamic (and should be converted to positive before use) ndb/src/common/mgmcommon/IPCConfig.cpp: Set up the Transporter with a port number of the correct sign. ndb/src/common/transporter/TransporterRegistry.cpp: start_clients_thread: - handle negative port numbers add_transporter_interface: - accept signed integer as port number start_service: - If port is dynamic (<0), try to bind to it. if that fails (e.g. some other process has taken that port), then get a new dynamic port number. ndb/src/mgmapi/mgmapi.cpp: Use a signed integer for value in: ndb_mgm_set_connection_int_parameter ndb_mgm_get_connection_int_parameter Cast to a Uint32 for storage/retrieval to/from Properties ndb/src/mgmsrv/MgmtSrvr.cpp: getConnectionDbParameter - return value as integer (signed) - cast as Uint32 for iter.get ndb/src/mgmsrv/MgmtSrvr.hpp: Update prototype of getConnectionDbParameter int value (not unsigned anymore) ndb/src/mgmsrv/Services.cpp: MgmApiSession::getConnectionParameter - value is now signed
Diffstat (limited to 'ndb')
-rw-r--r--ndb/include/mgmapi/mgmapi_debug.h4
-rw-r--r--ndb/include/transporter/TransporterRegistry.hpp4
-rw-r--r--ndb/src/common/mgmcommon/IPCConfig.cpp3
-rw-r--r--ndb/src/common/transporter/TransporterRegistry.cpp40
-rw-r--r--ndb/src/mgmapi/mgmapi.cpp8
-rw-r--r--ndb/src/mgmsrv/MgmtSrvr.cpp6
-rw-r--r--ndb/src/mgmsrv/MgmtSrvr.hpp2
-rw-r--r--ndb/src/mgmsrv/Services.cpp4
8 files changed, 47 insertions, 24 deletions
diff --git a/ndb/include/mgmapi/mgmapi_debug.h b/ndb/include/mgmapi/mgmapi_debug.h
index cbf9878f163..32a89535456 100644
--- a/ndb/include/mgmapi/mgmapi_debug.h
+++ b/ndb/include/mgmapi/mgmapi_debug.h
@@ -146,7 +146,7 @@ extern "C" {
int node1,
int node2,
int param,
- unsigned value,
+ int value,
struct ndb_mgm_reply* reply);
/**
@@ -165,7 +165,7 @@ extern "C" {
int node1,
int node2,
int param,
- Uint32 *value,
+ int *value,
struct ndb_mgm_reply* reply);
#ifdef __cplusplus
diff --git a/ndb/include/transporter/TransporterRegistry.hpp b/ndb/include/transporter/TransporterRegistry.hpp
index da0849c3f50..a8197d75337 100644
--- a/ndb/include/transporter/TransporterRegistry.hpp
+++ b/ndb/include/transporter/TransporterRegistry.hpp
@@ -232,12 +232,12 @@ public:
class Transporter_interface {
public:
NodeId m_remote_nodeId;
- unsigned short m_service_port;
+ int m_service_port;
const char *m_interface;
};
Vector<Transporter_interface> m_transporter_interface;
void add_transporter_interface(NodeId remoteNodeId, const char *interf,
- unsigned short port);
+ int port);
Transporter* get_transporter(NodeId nodeId);
NodeId get_localNodeId() { return localNodeId; };
diff --git a/ndb/src/common/mgmcommon/IPCConfig.cpp b/ndb/src/common/mgmcommon/IPCConfig.cpp
index dd78e1dbfbd..06bd1d06328 100644
--- a/ndb/src/common/mgmcommon/IPCConfig.cpp
+++ b/ndb/src/common/mgmcommon/IPCConfig.cpp
@@ -371,6 +371,9 @@ IPCConfig::configureTransporters(Uint32 nodeId,
}
DBUG_PRINT("info", ("Transporter between this node %d and node %d using port %d, signalId %d, checksum %d",
nodeId, remoteNodeId, server_port, sendSignalId, checksum));
+ if((int)server_port<0)
+ server_port= -server_port; // A dynamic port
+
switch(type){
case CONNECTION_TYPE_SHM:{
SHM_TransporterConfiguration conf;
diff --git a/ndb/src/common/transporter/TransporterRegistry.cpp b/ndb/src/common/transporter/TransporterRegistry.cpp
index e55b61c5c6a..228403d9d4b 100644
--- a/ndb/src/common/transporter/TransporterRegistry.cpp
+++ b/ndb/src/common/transporter/TransporterRegistry.cpp
@@ -1191,7 +1191,7 @@ TransporterRegistry::start_clients_thread()
case CONNECTING:
if(!t->isConnected() && !t->isServer) {
if(t->get_r_port() <= 0) { // Port is dynamic
- Uint32 server_port= 0;
+ int server_port= 0;
struct ndb_mgm_reply mgm_reply;
int res;
@@ -1201,9 +1201,13 @@ TransporterRegistry::start_clients_thread()
CFG_CONNECTION_SERVER_PORT,
&server_port,
&mgm_reply);
- DBUG_PRINT("info",("Got dynamic port %u for %d -> %d (ret: %d)",
+ DBUG_PRINT("info",("Got %s port %u for %d -> %d (ret: %d)",
+ (server_port<=0)?"dynamic":"static",
server_port,t->getRemoteNodeId(),
t->getLocalNodeId(),res));
+ if(server_port<0)
+ server_port = -server_port; // was a dynamic port
+
if(res>=0)
t->set_r_port(server_port);
else
@@ -1265,7 +1269,7 @@ TransporterRegistry::stop_clients()
void
TransporterRegistry::add_transporter_interface(NodeId remoteNodeId,
const char *interf,
- unsigned short port)
+ int port)
{
DBUG_ENTER("TransporterRegistry::add_transporter_interface");
DBUG_PRINT("enter",("interface=%s, port= %d", interf, port));
@@ -1309,18 +1313,34 @@ TransporterRegistry::start_service(SocketServer& socket_server)
{
Transporter_interface &t= m_transporter_interface[i];
+ unsigned short port= t.m_service_port;
+ if(t.m_service_port<0)
+ port= -t.m_service_port; // is a dynamic port
TransporterService *transporter_service =
new TransporterService(new SocketAuthSimple("ndbd", "ndbd passwd"));
if(!socket_server.setup(transporter_service,
- &t.m_service_port, t.m_interface))
+ &port, t.m_interface))
{
- ndbout_c("Unable to setup transporter service port: %s:%d!\n"
- "Please check if the port is already used,\n"
- "(perhaps the node is already running)",
- t.m_interface ? t.m_interface : "*", t.m_service_port);
- delete transporter_service;
- return false;
+ DBUG_PRINT("info", ("Trying new port"));
+ port= 0;
+ if(t.m_service_port>0
+ || !socket_server.setup(transporter_service,
+ &port, t.m_interface))
+ {
+ /*
+ * If it wasn't a dynamically allocated port, or
+ * our attempts at getting a new dynamic port failed
+ */
+ ndbout_c("Unable to setup transporter service port: %s:%d!\n"
+ "Please check if the port is already used,\n"
+ "(perhaps the node is already running)",
+ t.m_interface ? t.m_interface : "*", t.m_service_port);
+ delete transporter_service;
+ return false;
+ }
}
+ t.m_service_port= (t.m_service_port<=0)?-port:port; // -`ve if dynamic
+ DBUG_PRINT("info", ("t.m_service_port = %d",t.m_service_port));
transporter_service->setTransporterRegistry(this);
}
return true;
diff --git a/ndb/src/mgmapi/mgmapi.cpp b/ndb/src/mgmapi/mgmapi.cpp
index 93ffeb8f2d3..0f03ed0a008 100644
--- a/ndb/src/mgmapi/mgmapi.cpp
+++ b/ndb/src/mgmapi/mgmapi.cpp
@@ -2050,7 +2050,7 @@ ndb_mgm_set_connection_int_parameter(NdbMgmHandle handle,
int node1,
int node2,
int param,
- unsigned value,
+ int value,
struct ndb_mgm_reply* mgmreply){
DBUG_ENTER("ndb_mgm_set_connection_int_parameter");
CHECK_HANDLE(handle, 0);
@@ -2060,7 +2060,7 @@ ndb_mgm_set_connection_int_parameter(NdbMgmHandle handle,
args.put("node1", node1);
args.put("node2", node2);
args.put("param", param);
- args.put("value", value);
+ args.put("value", (Uint32)value);
const ParserRow<ParserDummy> reply[]= {
MGM_CMD("set connection parameter reply", NULL, ""),
@@ -2093,7 +2093,7 @@ ndb_mgm_get_connection_int_parameter(NdbMgmHandle handle,
int node1,
int node2,
int param,
- Uint32 *value,
+ int *value,
struct ndb_mgm_reply* mgmreply){
DBUG_ENTER("ndb_mgm_get_connection_int_parameter");
CHECK_HANDLE(handle, -1);
@@ -2125,7 +2125,7 @@ ndb_mgm_get_connection_int_parameter(NdbMgmHandle handle,
res= 0;
} while(0);
- if(!prop->get("value",value)){
+ if(!prop->get("value",(Uint32*)value)){
ndbout_c("Unable to get value");
res = -4;
}
diff --git a/ndb/src/mgmsrv/MgmtSrvr.cpp b/ndb/src/mgmsrv/MgmtSrvr.cpp
index 81d5779c4bf..f85dff7c109 100644
--- a/ndb/src/mgmsrv/MgmtSrvr.cpp
+++ b/ndb/src/mgmsrv/MgmtSrvr.cpp
@@ -2849,7 +2849,7 @@ int
MgmtSrvr::getConnectionDbParameter(int node1,
int node2,
int param,
- unsigned *value,
+ int *value,
BaseString& msg){
DBUG_ENTER("MgmtSrvr::getConnectionDbParameter");
@@ -2874,12 +2874,12 @@ MgmtSrvr::getConnectionDbParameter(int node1,
return -1;
}
- if(iter.get(param, value) < 0) {
+ if(iter.get(param, (Uint32*)value) < 0) {
msg.assign("Unable to get current value of parameter");
return -1;
}
- msg.assfmt("%u",*value);
+ msg.assfmt("%d",*value);
DBUG_RETURN(1);
}
diff --git a/ndb/src/mgmsrv/MgmtSrvr.hpp b/ndb/src/mgmsrv/MgmtSrvr.hpp
index 450dbf15160..0d5f3f33b3c 100644
--- a/ndb/src/mgmsrv/MgmtSrvr.hpp
+++ b/ndb/src/mgmsrv/MgmtSrvr.hpp
@@ -510,7 +510,7 @@ public:
int setConnectionDbParameter(int node1, int node2, int param, int value,
BaseString& msg);
int getConnectionDbParameter(int node1, int node2, int param,
- unsigned *value, BaseString& msg);
+ int *value, BaseString& msg);
int set_connect_string(const char *str);
diff --git a/ndb/src/mgmsrv/Services.cpp b/ndb/src/mgmsrv/Services.cpp
index 6295d82b3be..45a59e03931 100644
--- a/ndb/src/mgmsrv/Services.cpp
+++ b/ndb/src/mgmsrv/Services.cpp
@@ -1373,7 +1373,7 @@ void
MgmApiSession::getConnectionParameter(Parser_t::Context &ctx,
Properties const &args) {
BaseString node1, node2, param;
- unsigned value = 0;
+ int value = 0;
args.get("node1", node1);
args.get("node2", node2);
@@ -1387,7 +1387,7 @@ MgmApiSession::getConnectionParameter(Parser_t::Context &ctx,
result);
m_output->println("get connection parameter reply");
- m_output->println("value: %u", value);
+ m_output->println("value: %d", value);
m_output->println("result: %s", (ret>0)?"Ok":result.c_str());
m_output->println("");
}