summaryrefslogtreecommitdiff
path: root/ndb/src/mgmclient
diff options
context:
space:
mode:
authorunknown <stewart@mysql.com>2006-06-08 02:40:16 +1000
committerunknown <stewart@mysql.com>2006-06-08 02:40:16 +1000
commit8a7e206d71f00e2dcdfc134a433fee6c586a84d7 (patch)
tree8464550bcd859d5887f9ac50137bc5bdb2256588 /ndb/src/mgmclient
parentd1d2a7f694c694355d6fb08e79b3575f16db91ed (diff)
parentd1b37c77ef202f4d9b276b36000cd4ac4c19626a (diff)
downloadmariadb-git-8a7e206d71f00e2dcdfc134a433fee6c586a84d7.tar.gz
Merge mysql.com:/home/stewart/Documents/MySQL/5.0/jonas
into mysql.com:/home/stewart/Documents/MySQL/5.0/merge-queue ndb/include/mgmapi/mgmapi.h: Auto merged ndb/src/mgmapi/mgmapi.cpp: Auto merged ndb/src/mgmclient/CommandInterpreter.cpp: Auto merged ndb/src/mgmsrv/MgmtSrvr.hpp: Auto merged ndb/src/mgmsrv/Services.cpp: Auto merged ndb/src/mgmsrv/Services.hpp: Auto merged ndb/src/mgmsrv/MgmtSrvr.cpp: hand merge bug fix by tomas with my fix for stop/shutdown behaviour
Diffstat (limited to 'ndb/src/mgmclient')
-rw-r--r--ndb/src/mgmclient/CommandInterpreter.cpp239
1 files changed, 115 insertions, 124 deletions
diff --git a/ndb/src/mgmclient/CommandInterpreter.cpp b/ndb/src/mgmclient/CommandInterpreter.cpp
index 14cd3fba42b..58b98671b14 100644
--- a/ndb/src/mgmclient/CommandInterpreter.cpp
+++ b/ndb/src/mgmclient/CommandInterpreter.cpp
@@ -162,6 +162,7 @@ private:
NdbMgmHandle m_mgmsrv;
NdbMgmHandle m_mgmsrv2;
+ const char *m_constr;
bool m_connected;
int m_verbose;
int try_reconnect;
@@ -390,22 +391,7 @@ convert(const char* s, int& val) {
CommandInterpreter::CommandInterpreter(const char *_host,int verbose)
: m_verbose(verbose)
{
- m_mgmsrv = ndb_mgm_create_handle();
- if(m_mgmsrv == NULL) {
- ndbout_c("Cannot create handle to management server.");
- exit(-1);
- }
- m_mgmsrv2 = ndb_mgm_create_handle();
- if(m_mgmsrv2 == NULL) {
- ndbout_c("Cannot create 2:nd handle to management server.");
- exit(-1);
- }
- if (ndb_mgm_set_connectstring(m_mgmsrv, _host))
- {
- printError();
- exit(-1);
- }
-
+ m_constr= _host;
m_connected= false;
m_event_thread= 0;
try_reconnect = 0;
@@ -422,8 +408,6 @@ CommandInterpreter::CommandInterpreter(const char *_host,int verbose)
CommandInterpreter::~CommandInterpreter()
{
disconnect();
- ndb_mgm_destroy_handle(&m_mgmsrv);
- ndb_mgm_destroy_handle(&m_mgmsrv2);
}
static bool
@@ -445,15 +429,14 @@ emptyString(const char* s)
void
CommandInterpreter::printError()
{
- if (ndb_mgm_check_connection(m_mgmsrv))
- {
- m_connected= false;
- disconnect();
- }
ndbout_c("* %5d: %s",
ndb_mgm_get_latest_error(m_mgmsrv),
ndb_mgm_get_latest_error_msg(m_mgmsrv));
ndbout_c("* %s", ndb_mgm_get_latest_error_desc(m_mgmsrv));
+ if (ndb_mgm_check_connection(m_mgmsrv))
+ {
+ disconnect();
+ }
}
//*****************************************************************************
@@ -497,78 +480,97 @@ event_thread_run(void* m)
}
bool
-CommandInterpreter::connect()
+CommandInterpreter::connect()
{
DBUG_ENTER("CommandInterpreter::connect");
- if(!m_connected)
+
+ if(m_connected)
+ DBUG_RETURN(m_connected);
+
+ m_mgmsrv = ndb_mgm_create_handle();
+ if(m_mgmsrv == NULL) {
+ ndbout_c("Cannot create handle to management server.");
+ exit(-1);
+ }
+ m_mgmsrv2 = ndb_mgm_create_handle();
+ if(m_mgmsrv2 == NULL) {
+ ndbout_c("Cannot create 2:nd handle to management server.");
+ exit(-1);
+ }
+
+ if (ndb_mgm_set_connectstring(m_mgmsrv, m_constr))
{
- if(!ndb_mgm_connect(m_mgmsrv, try_reconnect-1, 5, 1))
+ printError();
+ exit(-1);
+ }
+
+ if(ndb_mgm_connect(m_mgmsrv, try_reconnect-1, 5, 1))
+ DBUG_RETURN(m_connected); // couldn't connect, always false
+
+ const char *host= ndb_mgm_get_connected_host(m_mgmsrv);
+ unsigned port= ndb_mgm_get_connected_port(m_mgmsrv);
+ BaseString constr;
+ constr.assfmt("%s:%d",host,port);
+ if(!ndb_mgm_set_connectstring(m_mgmsrv2, constr.c_str()) &&
+ !ndb_mgm_connect(m_mgmsrv2, try_reconnect-1, 5, 1))
+ {
+ DBUG_PRINT("info",("2:ndb connected to Management Server ok at: %s:%d",
+ host, port));
+ assert(m_event_thread == 0);
+ assert(do_event_thread == 0);
+ do_event_thread= 0;
+ m_event_thread = NdbThread_Create(event_thread_run,
+ (void**)&m_mgmsrv2,
+ 32768,
+ "CommandInterpreted_event_thread",
+ NDB_THREAD_PRIO_LOW);
+ if (m_event_thread != 0)
{
- const char *host= ndb_mgm_get_connected_host(m_mgmsrv);
- unsigned port= ndb_mgm_get_connected_port(m_mgmsrv);
- BaseString constr;
- constr.assfmt("%s:%d",host,port);
- if(!ndb_mgm_set_connectstring(m_mgmsrv2, constr.c_str()) &&
- !ndb_mgm_connect(m_mgmsrv2, try_reconnect-1, 5, 1))
- {
- DBUG_PRINT("info",("2:ndb connected to Management Server ok at: %s:%d",
- host, port));
- assert(m_event_thread == 0);
- assert(do_event_thread == 0);
- do_event_thread= 0;
- m_event_thread = NdbThread_Create(event_thread_run,
- (void**)&m_mgmsrv2,
- 32768,
- "CommandInterpreted_event_thread",
- NDB_THREAD_PRIO_LOW);
- if (m_event_thread != 0)
- {
- DBUG_PRINT("info",("Thread created ok, waiting for started..."));
- int iter= 1000; // try for 30 seconds
- while(do_event_thread == 0 &&
- iter-- > 0)
- NdbSleep_MilliSleep(30);
- }
- if (m_event_thread == 0 ||
- do_event_thread == 0 ||
- do_event_thread == -1)
- {
- DBUG_PRINT("info",("Warning, event thread startup failed, "
- "degraded printouts as result, errno=%d",
- errno));
- printf("Warning, event thread startup failed, "
- "degraded printouts as result, errno=%d\n", errno);
- do_event_thread= 0;
- if (m_event_thread)
- {
- void *res;
- NdbThread_WaitFor(m_event_thread, &res);
- NdbThread_Destroy(&m_event_thread);
- }
- ndb_mgm_disconnect(m_mgmsrv2);
- }
- }
- else
- {
- DBUG_PRINT("warning",
- ("Could not do 2:nd connect to mgmtserver for event listening"));
- DBUG_PRINT("info", ("code: %d, msg: %s",
- ndb_mgm_get_latest_error(m_mgmsrv2),
- ndb_mgm_get_latest_error_msg(m_mgmsrv2)));
- printf("Warning, event connect failed, degraded printouts as result\n");
- printf("code: %d, msg: %s\n",
- ndb_mgm_get_latest_error(m_mgmsrv2),
- ndb_mgm_get_latest_error_msg(m_mgmsrv2));
- }
- m_connected= true;
- DBUG_PRINT("info",("Connected to Management Server at: %s:%d", host, port));
- if (m_verbose)
+ DBUG_PRINT("info",("Thread created ok, waiting for started..."));
+ int iter= 1000; // try for 30 seconds
+ while(do_event_thread == 0 &&
+ iter-- > 0)
+ NdbSleep_MilliSleep(30);
+ }
+ if (m_event_thread == 0 ||
+ do_event_thread == 0 ||
+ do_event_thread == -1)
+ {
+ DBUG_PRINT("info",("Warning, event thread startup failed, "
+ "degraded printouts as result, errno=%d",
+ errno));
+ printf("Warning, event thread startup failed, "
+ "degraded printouts as result, errno=%d\n", errno);
+ do_event_thread= 0;
+ if (m_event_thread)
{
- printf("Connected to Management Server at: %s:%d\n",
- host, port);
+ void *res;
+ NdbThread_WaitFor(m_event_thread, &res);
+ NdbThread_Destroy(&m_event_thread);
}
+ ndb_mgm_disconnect(m_mgmsrv2);
}
}
+ else
+ {
+ DBUG_PRINT("warning",
+ ("Could not do 2:nd connect to mgmtserver for event listening"));
+ DBUG_PRINT("info", ("code: %d, msg: %s",
+ ndb_mgm_get_latest_error(m_mgmsrv2),
+ ndb_mgm_get_latest_error_msg(m_mgmsrv2)));
+ printf("Warning, event connect failed, degraded printouts as result\n");
+ printf("code: %d, msg: %s\n",
+ ndb_mgm_get_latest_error(m_mgmsrv2),
+ ndb_mgm_get_latest_error_msg(m_mgmsrv2));
+ }
+ m_connected= true;
+ DBUG_PRINT("info",("Connected to Management Server at: %s:%d", host, port));
+ if (m_verbose)
+ {
+ printf("Connected to Management Server at: %s:%d\n",
+ host, port);
+ }
+
DBUG_RETURN(m_connected);
}
@@ -576,20 +578,18 @@ bool
CommandInterpreter::disconnect()
{
DBUG_ENTER("CommandInterpreter::disconnect");
+
if (m_event_thread) {
void *res;
do_event_thread= 0;
NdbThread_WaitFor(m_event_thread, &res);
NdbThread_Destroy(&m_event_thread);
m_event_thread= 0;
- ndb_mgm_disconnect(m_mgmsrv2);
+ ndb_mgm_destroy_handle(&m_mgmsrv2);
}
if (m_connected)
{
- if (ndb_mgm_disconnect(m_mgmsrv) == -1) {
- ndbout_c("Could not disconnect from management server");
- printError();
- }
+ ndb_mgm_destroy_handle(&m_mgmsrv);
m_connected= false;
}
DBUG_RETURN(true);
@@ -1057,7 +1057,8 @@ CommandInterpreter::executeShutdown(char* parameters)
NdbAutoPtr<char> ap1((char*)state);
int result = 0;
- result = ndb_mgm_stop(m_mgmsrv, 0, 0);
+ int need_disconnect;
+ result = ndb_mgm_stop3(m_mgmsrv, -1, 0, 0, &need_disconnect);
if (result < 0) {
ndbout << "Shutdown of NDB Cluster node(s) failed." << endl;
printError();
@@ -1066,28 +1067,11 @@ CommandInterpreter::executeShutdown(char* parameters)
ndbout << result << " NDB Cluster node(s) have shutdown." << endl;
- int mgm_id= 0;
- mgm_id= ndb_mgm_get_mgmd_nodeid(m_mgmsrv);
- if (mgm_id == 0)
- {
- ndbout << "Unable to locate management server, "
- << "shutdown manually with <id> STOP"
+ if(need_disconnect) {
+ ndbout << "Disconnecting to allow management server to shutdown."
<< endl;
- return 1;
- }
-
- result = ndb_mgm_stop(m_mgmsrv, 1, &mgm_id);
- if (result <= 0) {
- ndbout << "Shutdown of NDB Cluster management server failed." << endl;
- printError();
- if (result == 0)
- return 1;
- return result;
+ disconnect();
}
-
- m_connected= false;
- disconnect();
- ndbout << "NDB Cluster management server shutdown." << endl;
return 0;
}
@@ -1311,12 +1295,7 @@ CommandInterpreter::executeConnect(char* parameters)
{
disconnect();
if (!emptyString(parameters)) {
- if (ndb_mgm_set_connectstring(m_mgmsrv,
- BaseString(parameters).trim().c_str()))
- {
- printError();
- return;
- }
+ m_constr= BaseString(parameters).trim().c_str();
}
connect();
}
@@ -1481,6 +1460,7 @@ CommandInterpreter::executeStop(Vector<BaseString> &command_list,
unsigned command_pos,
int *node_ids, int no_of_nodes)
{
+ int need_disconnect;
int abort= 0;
for (; command_pos < command_list.size(); command_pos++)
{
@@ -1495,7 +1475,8 @@ CommandInterpreter::executeStop(Vector<BaseString> &command_list,
return;
}
- int result= ndb_mgm_stop2(m_mgmsrv, no_of_nodes, node_ids, abort);
+ int result= ndb_mgm_stop3(m_mgmsrv, no_of_nodes, node_ids, abort,
+ &need_disconnect);
if (result < 0)
{
ndbout_c("Shutdown failed.");
@@ -1509,10 +1490,17 @@ CommandInterpreter::executeStop(Vector<BaseString> &command_list,
{
ndbout << "Node";
for (int i= 0; i < no_of_nodes; i++)
- ndbout << " " << node_ids[i];
+ ndbout << " " << node_ids[i];
ndbout_c(" has shutdown.");
}
}
+
+ if(need_disconnect)
+ {
+ ndbout << "Disconnecting to allow Management Server to shutdown" << endl;
+ disconnect();
+ }
+
}
void
@@ -1603,6 +1591,7 @@ CommandInterpreter::executeRestart(Vector<BaseString> &command_list,
int nostart= 0;
int initialstart= 0;
int abort= 0;
+ int need_disconnect= 0;
for (; command_pos < command_list.size(); command_pos++)
{
@@ -1627,9 +1616,9 @@ CommandInterpreter::executeRestart(Vector<BaseString> &command_list,
return;
}
- result= ndb_mgm_restart2(m_mgmsrv, no_of_nodes, node_ids,
- initialstart, nostart, abort);
-
+ result= ndb_mgm_restart3(m_mgmsrv, no_of_nodes, node_ids,
+ initialstart, nostart, abort, &need_disconnect);
+
if (result <= 0) {
ndbout_c("Restart failed.");
printError();
@@ -1645,6 +1634,8 @@ CommandInterpreter::executeRestart(Vector<BaseString> &command_list,
ndbout << " " << node_ids[i];
ndbout_c(" is being restarted");
}
+ if(need_disconnect)
+ disconnect();
}
}