mirror of
https://github.com/MariaDB/server.git
synced 2025-09-02 09:41:40 +03:00
Impl 3 of WL2278 - Dynamic port allocation of cluster nodes
- Change configuration handling so that no default ports are given, but instead 0 is set (port to be dynamic) - TransporterRegistry::start_service now only tries to connect when fetched port number > 0 ndb/include/util/SocketServer.hpp: Update prototype of setup() to take a pointer to the port (so we can return the port we bound to) ndb/src/common/transporter/TransporterRegistry.cpp: Only try to connect_client when we have a valid port number (i.e. > 0) ndb/src/common/util/SocketServer.cpp: ::setup(): Return the port we bound to ndb/src/cw/cpcd/main.cpp: Use new SocketServer::setup() api - returns port we bound to. ndb/src/mgmsrv/main.cpp: Conform to new SocketServer::setup() API (port is a pointer, returning the port we bound to) ndb/src/mgmsrv/ConfigInfo.cpp: fixPortNumber: Don't create port numbers when none are specified, just set 0 (dynamic) ndb/src/mgmsrv/MgmtSrvr.cpp: use DBUG_RETURN correctly in setConnectionDbParameter
This commit is contained in:
@@ -83,7 +83,7 @@ public:
|
|||||||
* bind & listen
|
* bind & listen
|
||||||
* Returns false if no success
|
* Returns false if no success
|
||||||
*/
|
*/
|
||||||
bool setup(Service *, unsigned short port, const char * pinterface = 0);
|
bool setup(Service *, unsigned short *port, const char * pinterface = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* start/stop the server
|
* start/stop the server
|
||||||
|
@@ -1153,13 +1153,16 @@ TransporterRegistry::start_clients_thread()
|
|||||||
&mgm_reply);
|
&mgm_reply);
|
||||||
DBUG_PRINT("info",("Got dynamic port %u for %d -> %d (ret: %d)",
|
DBUG_PRINT("info",("Got dynamic port %u for %d -> %d (ret: %d)",
|
||||||
server_port,t->getRemoteNodeId(),
|
server_port,t->getRemoteNodeId(),
|
||||||
t->getLocalNodeId()));
|
t->getLocalNodeId(),res));
|
||||||
if(res>=0)
|
if(res>=0)
|
||||||
t->set_r_port(server_port);
|
t->set_r_port(server_port);
|
||||||
else
|
else
|
||||||
ndbout_c("Failed to get dynamic port to connect to.");
|
ndbout_c("Failed to get dynamic port to connect to.");
|
||||||
}
|
}
|
||||||
t->connect_client();
|
if(t->get_r_port()>0)
|
||||||
|
t->connect_client();
|
||||||
|
else
|
||||||
|
NdbSleep_MilliSleep(400);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DISCONNECTING:
|
case DISCONNECTING:
|
||||||
@@ -1215,7 +1218,7 @@ TransporterRegistry::add_transporter_interface(NodeId remoteNodeId,
|
|||||||
for (unsigned i= 0; i < m_transporter_interface.size(); i++)
|
for (unsigned i= 0; i < m_transporter_interface.size(); i++)
|
||||||
{
|
{
|
||||||
Transporter_interface &tmp= m_transporter_interface[i];
|
Transporter_interface &tmp= m_transporter_interface[i];
|
||||||
if (port != tmp.m_service_port)
|
if (port != tmp.m_service_port || tmp.m_service_port==0)
|
||||||
continue;
|
continue;
|
||||||
if (interf != 0 && tmp.m_interface != 0 &&
|
if (interf != 0 && tmp.m_interface != 0 &&
|
||||||
strcmp(interf, tmp.m_interface) == 0)
|
strcmp(interf, tmp.m_interface) == 0)
|
||||||
@@ -1248,14 +1251,11 @@ TransporterRegistry::start_service(SocketServer& socket_server)
|
|||||||
for (unsigned i= 0; i < m_transporter_interface.size(); i++)
|
for (unsigned i= 0; i < m_transporter_interface.size(); i++)
|
||||||
{
|
{
|
||||||
Transporter_interface &t= m_transporter_interface[i];
|
Transporter_interface &t= m_transporter_interface[i];
|
||||||
if (t.m_service_port == 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
TransporterService *transporter_service =
|
TransporterService *transporter_service =
|
||||||
new TransporterService(new SocketAuthSimple("ndbd", "ndbd passwd"));
|
new TransporterService(new SocketAuthSimple("ndbd", "ndbd passwd"));
|
||||||
if(!socket_server.setup(transporter_service,
|
if(!socket_server.setup(transporter_service,
|
||||||
t.m_service_port, t.m_interface))
|
&t.m_service_port, t.m_interface))
|
||||||
{
|
{
|
||||||
ndbout_c("Unable to setup transporter service port: %s:%d!\n"
|
ndbout_c("Unable to setup transporter service port: %s:%d!\n"
|
||||||
"Please check if the port is already used,\n"
|
"Please check if the port is already used,\n"
|
||||||
|
@@ -82,15 +82,15 @@ SocketServer::tryBind(unsigned short port, const char * intface) {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
SocketServer::setup(SocketServer::Service * service,
|
SocketServer::setup(SocketServer::Service * service,
|
||||||
unsigned short port,
|
unsigned short * port,
|
||||||
const char * intface){
|
const char * intface){
|
||||||
DBUG_ENTER("SocketServer::setup");
|
DBUG_ENTER("SocketServer::setup");
|
||||||
DBUG_PRINT("enter",("interface=%s, port=%d", intface, port));
|
DBUG_PRINT("enter",("interface=%s, port=%u", intface, *port));
|
||||||
struct sockaddr_in servaddr;
|
struct sockaddr_in servaddr;
|
||||||
memset(&servaddr, 0, sizeof(servaddr));
|
memset(&servaddr, 0, sizeof(servaddr));
|
||||||
servaddr.sin_family = AF_INET;
|
servaddr.sin_family = AF_INET;
|
||||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
servaddr.sin_port = htons(port);
|
servaddr.sin_port = htons(*port);
|
||||||
|
|
||||||
if(intface != 0){
|
if(intface != 0){
|
||||||
if(Ndb_getInAddr(&servaddr.sin_addr, intface))
|
if(Ndb_getInAddr(&servaddr.sin_addr, intface))
|
||||||
@@ -119,7 +119,9 @@ SocketServer::setup(SocketServer::Service * service,
|
|||||||
NDB_CLOSE_SOCKET(sock);
|
NDB_CLOSE_SOCKET(sock);
|
||||||
DBUG_RETURN(false);
|
DBUG_RETURN(false);
|
||||||
}
|
}
|
||||||
|
socklen_t sock_len = sizeof(servaddr);
|
||||||
|
getsockname(sock,(struct sockaddr*)&servaddr,&sock_len);
|
||||||
|
DBUG_PRINT("info",("bound to %u",ntohs(servaddr.sin_port)));
|
||||||
if (listen(sock, m_maxSessions) == -1){
|
if (listen(sock, m_maxSessions) == -1){
|
||||||
DBUG_PRINT("error",("listen() - %d - %s",
|
DBUG_PRINT("error",("listen() - %d - %s",
|
||||||
errno, strerror(errno)));
|
errno, strerror(errno)));
|
||||||
@@ -131,6 +133,9 @@ SocketServer::setup(SocketServer::Service * service,
|
|||||||
i.m_socket = sock;
|
i.m_socket = sock;
|
||||||
i.m_service = service;
|
i.m_service = service;
|
||||||
m_services.push_back(i);
|
m_services.push_back(i);
|
||||||
|
|
||||||
|
*port = ntohs(servaddr.sin_port);
|
||||||
|
|
||||||
DBUG_RETURN(true);
|
DBUG_RETURN(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
|
|
||||||
static const char *work_dir = CPCD_DEFAULT_WORK_DIR;
|
static const char *work_dir = CPCD_DEFAULT_WORK_DIR;
|
||||||
static int port;
|
static short unsigned int port;
|
||||||
static int use_syslog;
|
static int use_syslog;
|
||||||
static const char *logfile = NULL;
|
static const char *logfile = NULL;
|
||||||
static const char *config_file = CPCD_DEFAULT_CONFIG_FILE;
|
static const char *config_file = CPCD_DEFAULT_CONFIG_FILE;
|
||||||
@@ -139,7 +139,7 @@ int main(int argc, char** argv){
|
|||||||
|
|
||||||
SocketServer * ss = new SocketServer();
|
SocketServer * ss = new SocketServer();
|
||||||
CPCDAPIService * serv = new CPCDAPIService(cpcd);
|
CPCDAPIService * serv = new CPCDAPIService(cpcd);
|
||||||
if(!ss->setup(serv, port)){
|
if(!ss->setup(serv, &port)){
|
||||||
logger.critical("Cannot setup server: %s", strerror(errno));
|
logger.critical("Cannot setup server: %s", strerror(errno));
|
||||||
sleep(1);
|
sleep(1);
|
||||||
delete ss;
|
delete ss;
|
||||||
|
@@ -3030,37 +3030,6 @@ fixPortNumber(InitConfigFileParser::Context & ctx, const char * data){
|
|||||||
Uint32 port= 0;
|
Uint32 port= 0;
|
||||||
if (!node->get("ServerPort", &port) &&
|
if (!node->get("ServerPort", &port) &&
|
||||||
!ctx.m_userProperties.get("ServerPort_", id1, &port)) {
|
!ctx.m_userProperties.get("ServerPort_", id1, &port)) {
|
||||||
Uint32 adder= 0;
|
|
||||||
{
|
|
||||||
BaseString server_port_adder(hostname);
|
|
||||||
server_port_adder.append("_ServerPortAdder");
|
|
||||||
ctx.m_userProperties.get(server_port_adder.c_str(), &adder);
|
|
||||||
ctx.m_userProperties.put(server_port_adder.c_str(), adder+1, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint32 base= 0;
|
|
||||||
if (!ctx.m_userProperties.get("ServerPortBase", &base)){
|
|
||||||
if(!(ctx.m_userDefaults &&
|
|
||||||
ctx.m_userDefaults->get("PortNumber", &base)) &&
|
|
||||||
!ctx.m_systemDefaults->get("PortNumber", &base)) {
|
|
||||||
base= strtoll(NDB_TCP_BASE_PORT,0,0);
|
|
||||||
// ctx.reportError("Cannot retrieve base port number");
|
|
||||||
// return false;
|
|
||||||
}
|
|
||||||
ctx.m_userProperties.put("ServerPortBase", base);
|
|
||||||
}
|
|
||||||
port= base + adder;
|
|
||||||
ctx.m_userProperties.put("ServerPort_", id1, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx.m_currentSection->contains("PortNumber")) {
|
|
||||||
ndbout << "PortNumber should no longer be specificied "
|
|
||||||
<< "per connection, please remove from config. "
|
|
||||||
<< "Will be changed to " << port << endl;
|
|
||||||
ctx.m_currentSection->put("PortNumber", port, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ctx.m_currentSection->put("PortNumber", port);
|
ctx.m_currentSection->put("PortNumber", port);
|
||||||
}
|
}
|
||||||
DBUG_PRINT("info", ("connection %d-%d port %d host %s",
|
DBUG_PRINT("info", ("connection %d-%d port %d host %s",
|
||||||
|
@@ -613,6 +613,26 @@ MgmtSrvr::start(BaseString &error_string)
|
|||||||
theFacade = 0;
|
theFacade = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TransporterRegistry *reg = theFacade->get_registry();
|
||||||
|
for(unsigned int i=0;i<reg->m_transporter_interface.size();i++) {
|
||||||
|
BaseString msg;
|
||||||
|
DBUG_PRINT("info",("Setting dynamic port %d->%d : %u",
|
||||||
|
reg->get_localNodeId(),
|
||||||
|
reg->m_transporter_interface[i].m_remote_nodeId,
|
||||||
|
reg->m_transporter_interface[i].m_service_port
|
||||||
|
)
|
||||||
|
);
|
||||||
|
int res = setConnectionDbParameter((int)reg->get_localNodeId(),
|
||||||
|
(int)reg->m_transporter_interface[i]
|
||||||
|
.m_remote_nodeId,
|
||||||
|
(int)CFG_CONNECTION_SERVER_PORT,
|
||||||
|
(int)reg->m_transporter_interface[i]
|
||||||
|
.m_service_port,
|
||||||
|
msg);
|
||||||
|
DBUG_PRINT("info",("Set result: %d: %s",res,msg.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_ownReference = numberToRef(_blockNumber, _ownNodeId);
|
_ownReference = numberToRef(_blockNumber, _ownNodeId);
|
||||||
|
|
||||||
@@ -2756,17 +2776,18 @@ MgmtSrvr::setConnectionDbParameter(int node1,
|
|||||||
Uint32 n1,n2;
|
Uint32 n1,n2;
|
||||||
iter.get(CFG_CONNECTION_NODE_1, &n1);
|
iter.get(CFG_CONNECTION_NODE_1, &n1);
|
||||||
iter.get(CFG_CONNECTION_NODE_2, &n2);
|
iter.get(CFG_CONNECTION_NODE_2, &n2);
|
||||||
if(n1 == (unsigned)node1 && n2 == (unsigned)node2)
|
if((n1 == (unsigned)node1 && n2 == (unsigned)node2)
|
||||||
|
|| (n1 == (unsigned)node2 && n2 == (unsigned)node1))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!iter.valid()) {
|
if(!iter.valid()) {
|
||||||
msg.assign("Unable to find connection between nodes");
|
msg.assign("Unable to find connection between nodes");
|
||||||
return -1;
|
DBUG_RETURN(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(iter.get(param, ¤t_value) < 0) {
|
if(iter.get(param, ¤t_value) < 0) {
|
||||||
msg.assign("Unable to get current value of parameter");
|
msg.assign("Unable to get current value of parameter");
|
||||||
return -1;
|
DBUG_RETURN(-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigValues::Iterator i2(_config->m_configValues->m_config,
|
ConfigValues::Iterator i2(_config->m_configValues->m_config,
|
||||||
@@ -2774,16 +2795,16 @@ MgmtSrvr::setConnectionDbParameter(int node1,
|
|||||||
|
|
||||||
if(i2.set(param, (unsigned)value) < 0) {
|
if(i2.set(param, (unsigned)value) < 0) {
|
||||||
msg.assign("Unable to set new value of parameter");
|
msg.assign("Unable to set new value of parameter");
|
||||||
return -1;
|
DBUG_RETURN(-4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(iter.get(param, &new_value) < 0) {
|
if(iter.get(param, &new_value) < 0) {
|
||||||
msg.assign("Unable to get parameter after setting it.");
|
msg.assign("Unable to get parameter after setting it.");
|
||||||
return -1;
|
DBUG_RETURN(-5);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.assfmt("%u -> %u",current_value,new_value);
|
msg.assfmt("%u -> %u",current_value,new_value);
|
||||||
return 1;
|
DBUG_RETURN(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -67,7 +67,7 @@ struct MgmGlobals {
|
|||||||
NodeId localNodeId;
|
NodeId localNodeId;
|
||||||
bool use_specific_ip;
|
bool use_specific_ip;
|
||||||
char * interface_name;
|
char * interface_name;
|
||||||
int port;
|
short unsigned int port;
|
||||||
|
|
||||||
/** The Mgmt Server */
|
/** The Mgmt Server */
|
||||||
MgmtSrvr * mgmObject;
|
MgmtSrvr * mgmObject;
|
||||||
@@ -233,7 +233,7 @@ int main(int argc, char** argv)
|
|||||||
glob.interface_name = 0;
|
glob.interface_name = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!glob.socketServer->setup(mapi, glob.port, glob.interface_name)){
|
if(!glob.socketServer->setup(mapi, &glob.port, glob.interface_name)){
|
||||||
ndbout_c("Unable to setup management port: %d!\n"
|
ndbout_c("Unable to setup management port: %d!\n"
|
||||||
"Please check if the port is already used,\n"
|
"Please check if the port is already used,\n"
|
||||||
"(perhaps a ndb_mgmd is already running),\n"
|
"(perhaps a ndb_mgmd is already running),\n"
|
||||||
|
Reference in New Issue
Block a user