see respective file

parent a99f5c42
......@@ -182,8 +182,8 @@ const DepricationTransform f_deprication[] = {
,{ "TCP", "SendBufferSize", "SendBufferMemory", 0, 16384 }
,{ "TCP", "MaxReceiveSize", "ReceiveBufferMemory", 0, 16384 }
,{ "SHM", "ProcessId1", "NodeId1", 0, 1}
,{ "SHM", "ProcessId2", "NodeId2", 0, 1}
// ,{ "SHM", "ProcessId1", "NodeId1", 0, 1}
// ,{ "SHM", "ProcessId2", "NodeId2", 0, 1}
,{ "SCI", "ProcessId1", "NodeId1", 0, 1}
,{ "SCI", "ProcessId2", "NodeId2", 0, 1}
,{ "OSE", "ProcessId1", "NodeId1", 0, 1}
......@@ -246,7 +246,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = {
KEY_INTERNAL,
"HostName",
"COMPUTER",
"Hostname of computer (e.g. alzato.com)",
"Hostname of computer (e.g. mysql.com)",
ConfigInfo::USED,
false,
ConfigInfo::STRING,
......@@ -330,18 +330,6 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = {
0,
0x7FFFFFFF },
{
CFG_SYS_PORT_BASE,
"PortBase",
"SYSTEM",
"Base port for system",
ConfigInfo::USED,
false,
ConfigInfo::INT,
NDB_BASE_PORT+2,
0,
0x7FFFFFFF },
/***************************************************************************
* DB
***************************************************************************/
......@@ -2238,7 +2226,7 @@ const int ConfigInfo::m_NoOfParams = sizeof(m_ParamInfo) / sizeof(ParamInfo);
/****************************************************************************
* Ctor
****************************************************************************/
inline void require(bool v) { if(!v) abort();}
static void require(bool v) { if(!v) abort();}
ConfigInfo::ConfigInfo() {
Properties *section;
......@@ -2670,6 +2658,9 @@ transformSystem(InitConfigFileParser::Context & ctx, const char * data){
ctx.fname, ctx.m_sectionLineno);
return false;
}
ndbout << "transformSystem " << name << endl;
snprintf(ctx.pname, sizeof(ctx.pname), "SYSTEM_%s", name);
return true;
......@@ -2960,24 +2951,29 @@ fixPortNumber(InitConfigFileParser::Context & ctx, const char * data){
Uint32 port= 0;
if (!node->get("ServerPort", &port) && !ctx.m_userProperties.get("ServerPort_", id1, &port)) {
hostname.append("_ServerPortAdder");
Uint32 adder= 0;
ctx.m_userProperties.get(hostname.c_str(), &adder);
ctx.m_userProperties.put(hostname.c_str(), adder+1, true);
{
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;
Uint32 base= 0;
if(!(ctx.m_userDefaults && ctx.m_userDefaults->get("PortNumber", &base)) &&
!ctx.m_systemDefaults->get("PortNumber", &base)){
ctx.reportError("Cannot retrieve base port number");
return false;
}
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);
return true;
......
......@@ -192,7 +192,7 @@ LocalConfig::parseNodeId(const char * buf){
bool
LocalConfig::parseHostName(const char * buf){
char tempString[100];
char tempString[1024];
int port;
for(int i = 0; hostNameTokens[i] != 0; i++) {
if (sscanf(buf, hostNameTokens[i], tempString, &port) == 2) {
......@@ -209,7 +209,7 @@ LocalConfig::parseHostName(const char * buf){
bool
LocalConfig::parseFileName(const char * buf){
char tempString[100];
char tempString[1024];
for(int i = 0; fileNameTokens[i] != 0; i++) {
if (sscanf(buf, fileNameTokens[i], tempString) == 1) {
MgmtSrvrId* mgmtSrvrId = new MgmtSrvrId();
......@@ -224,10 +224,9 @@ LocalConfig::parseFileName(const char * buf){
bool
LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line){
bool return_value = true;
char * for_strtok;
char * copy = strdup(connectString);
NdbAutoPtr<char> tmp_aptr(copy);
bool b_nodeId = false;
bool found_other = false;
......@@ -248,18 +247,18 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line
if (found_other = parseFileName(tok))
continue;
if (line)
snprintf(line, 150, "Unexpected entry: \"%s\"", tok);
return_value = false;
break;
return false;
}
if (return_value && !onlyNodeId && !found_other) {
return_value = false;
if (!onlyNodeId && !found_other) {
if (line)
snprintf(line, 150, "Missing host/file name extry in \"%s\"", connectString);
return false;
}
free(copy);
return return_value;
return true;
}
bool LocalConfig::readFile(const char * filename, bool &fopenError, bool onlyNodeId)
......
......@@ -23,11 +23,8 @@
#include <NdbSleep.h>
#include <NdbOut.hpp>
#ifndef NDB_WIN32
#include <sys/ipc.h>
#include <sys/shm.h>
#endif
#include <InputStream.hpp>
#include <OutputStream.hpp>
SHM_Transporter::SHM_Transporter(TransporterRegistry &t_reg,
const char *lHostName,
......@@ -222,3 +219,127 @@ SHM_Transporter::prepareSend(const SignalHeader * const signalHeader,
return SEND_DISCONNECTED;
}
#endif
bool
SHM_Transporter::connect_server_impl(NDB_SOCKET_TYPE sockfd)
{
SocketOutputStream s_output(sockfd);
SocketInputStream s_input(sockfd);
char buf[256];
// Create
if(!_shmSegCreated){
if (!ndb_shm_create()) {
report_error(TE_SHM_UNABLE_TO_CREATE_SEGMENT);
NDB_CLOSE_SOCKET(sockfd);
return false;
}
_shmSegCreated = true;
}
// Attach
if(!_attached){
if (!ndb_shm_attach()) {
report_error(TE_SHM_UNABLE_TO_ATTACH_SEGMENT);
NDB_CLOSE_SOCKET(sockfd);
return false;
}
_attached = true;
}
// Send ok to client
s_output.println("shm server 1 ok");
// Wait for ok from client
if (s_input.gets(buf, 256) == 0) {
NDB_CLOSE_SOCKET(sockfd);
return false;
}
int r= connect_common(sockfd);
if (r) {
// Send ok to client
s_output.println("shm server 2 ok");
// Wait for ok from client
if (s_input.gets(buf, 256) == 0) {
NDB_CLOSE_SOCKET(sockfd);
return false;
}
}
NDB_CLOSE_SOCKET(sockfd);
return r;
}
bool
SHM_Transporter::connect_client_impl(NDB_SOCKET_TYPE sockfd)
{
SocketInputStream s_input(sockfd);
SocketOutputStream s_output(sockfd);
char buf[256];
// Wait for server to create and attach
if (s_input.gets(buf, 256) == 0) {
NDB_CLOSE_SOCKET(sockfd);
return false;
}
// Create
if(!_shmSegCreated){
if (!ndb_shm_get()) {
NDB_CLOSE_SOCKET(sockfd);
return false;
}
_shmSegCreated = true;
}
// Attach
if(!_attached){
if (!ndb_shm_attach()) {
report_error(TE_SHM_UNABLE_TO_ATTACH_SEGMENT);
NDB_CLOSE_SOCKET(sockfd);
return false;
}
_attached = true;
}
// Send ok to server
s_output.println("shm client 1 ok");
int r= connect_common(sockfd);
if (r) {
// Wait for ok from server
if (s_input.gets(buf, 256) == 0) {
NDB_CLOSE_SOCKET(sockfd);
return false;
}
// Send ok to server
s_output.println("shm client 2 ok");
}
NDB_CLOSE_SOCKET(sockfd);
return r;
}
bool
SHM_Transporter::connect_common(NDB_SOCKET_TYPE sockfd)
{
if (!checkConnected())
return false;
if(!setupBuffersDone) {
setupBuffers();
setupBuffersDone=true;
}
if(setupBuffersDone) {
NdbSleep_MilliSleep(m_timeOutMillis);
if(*serverStatusFlag == 1 && *clientStatusFlag == 1)
return true;
}
return false;
}
......@@ -108,6 +108,9 @@ protected:
bool connect_common(NDB_SOCKET_TYPE sockfd);
bool ndb_shm_create();
bool ndb_shm_get();
bool ndb_shm_attach();
/**
* Check if there are two processes attached to the segment (a connection)
......
......@@ -23,132 +23,40 @@
#include <NdbSleep.h>
#include <NdbOut.hpp>
#include <InputStream.hpp>
#include <OutputStream.hpp>
#include <sys/ipc.h>
#include <sys/shm.h>
bool
SHM_Transporter::connect_server_impl(NDB_SOCKET_TYPE sockfd)
SHM_Transporter::ndb_shm_create()
{
SocketOutputStream s_output(sockfd);
SocketInputStream s_input(sockfd);
if(!_shmSegCreated){
shmId = shmget(shmKey, shmSize, IPC_CREAT | 960);
if(shmId == -1){
if(shmId == -1) {
perror("shmget: ");
report_error(TE_SHM_UNABLE_TO_CREATE_SEGMENT);
NdbSleep_MilliSleep(m_timeOutMillis);
NDB_CLOSE_SOCKET(sockfd);
return false;
}
_shmSegCreated = true;
}
s_output.println("shm server 1 ok");
char buf[256];
if (s_input.gets(buf, 256) == 0) {
NDB_CLOSE_SOCKET(sockfd);
return false;
}
int r= connect_common(sockfd);
if (r) {
s_output.println("shm server 2 ok");
if (s_input.gets(buf, 256) == 0) {
NDB_CLOSE_SOCKET(sockfd);
return false;
}
}
NDB_CLOSE_SOCKET(sockfd);
return r;
return true;
}
bool
SHM_Transporter::connect_client_impl(NDB_SOCKET_TYPE sockfd)
SHM_Transporter::ndb_shm_get()
{
SocketInputStream s_input(sockfd);
SocketOutputStream s_output(sockfd);
char buf[256];
if (s_input.gets(buf, 256) == 0) {
NDB_CLOSE_SOCKET(sockfd);
return false;
}
if(!_shmSegCreated){
shmId = shmget(shmKey, shmSize, 0);
if(shmId == -1){
NdbSleep_MilliSleep(m_timeOutMillis);
NDB_CLOSE_SOCKET(sockfd);
return false;
}
_shmSegCreated = true;
}
s_output.println("shm client 1 ok");
int r= connect_common(sockfd);
if (r) {
if (s_input.gets(buf, 256) == 0) {
NDB_CLOSE_SOCKET(sockfd);
if(shmId == -1) {
perror("shmget: ");
return false;
}
s_output.println("shm client 2 ok");
}
NDB_CLOSE_SOCKET(sockfd);
return r;
return true;
}
bool
SHM_Transporter::connect_common(NDB_SOCKET_TYPE sockfd)
SHM_Transporter::ndb_shm_attach()
{
if(!_attached){
shmBuf = (char *)shmat(shmId, 0, 0);
if(shmBuf == 0){
report_error(TE_SHM_UNABLE_TO_ATTACH_SEGMENT);
NdbSleep_MilliSleep(m_timeOutMillis);
return false;
}
_attached = true;
}
struct shmid_ds info;
const int res = shmctl(shmId, IPC_STAT, &info);
if(res == -1){
report_error(TE_SHM_IPC_STAT);
NdbSleep_MilliSleep(m_timeOutMillis);
if(shmBuf == 0) {
perror("shmat: ");
return false;
}
if(info.shm_nattch == 2 && !setupBuffersDone) {
setupBuffers();
setupBuffersDone=true;
}
if(setupBuffersDone) {
NdbSleep_MilliSleep(m_timeOutMillis);
if(*serverStatusFlag==1 && *clientStatusFlag==1)
return true;
}
if(info.shm_nattch > 2){
report_error(TE_SHM_DISCONNECT);
NdbSleep_MilliSleep(m_timeOutMillis);
return false;
}
NdbSleep_MilliSleep(m_timeOutMillis);
return false;
}
bool
......@@ -190,4 +98,3 @@ SHM_Transporter::disconnectImpl(){
}
setupBuffersDone=false;
}
......@@ -106,17 +106,8 @@ Configuration::init(int argc, const char** argv){
_initialStart = true;
// Check connectstring
if (_connect_str){
if(_connect_str[0] == '-' ||
strstr(_connect_str, "host") == 0 ||
strstr(_connect_str, "nodeid") == 0) {
ndbout << "Illegal/empty connectString: " << _connect_str << endl;
arg_printusage(args, num_args, argv[0], desc);
return false;
}
if (_connect_str)
_connectString = strdup(_connect_str);
}
// Check deamon flag
if (_deamon)
......
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