Commit facaf4f7 authored by tomas@poseidon.ndb.mysql.com's avatar tomas@poseidon.ndb.mysql.com

Merge tulin@bk-internal.mysql.com:/home/bk/mysql-4.1

into poseidon.ndb.mysql.com:/home/tomas/mysql-4.1-clean
parents 14b60dfc 8c3144c1
...@@ -379,18 +379,30 @@ ndb_mgm_connect(NdbMgmHandle handle, int no_retries, ...@@ -379,18 +379,30 @@ ndb_mgm_connect(NdbMgmHandle handle, int no_retries,
setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__, setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__,
"Unable to connect with connect string: %s", "Unable to connect with connect string: %s",
cfg.makeConnectString(buf,sizeof(buf))); cfg.makeConnectString(buf,sizeof(buf)));
if (verbose == -2)
ndbout << ", failed." << endl;
return -1; return -1;
} }
if (verbose == -1) { if (verbose == -1) {
ndbout << "retrying every " << retry_delay_in_seconds << " seconds:"; ndbout << "Retrying every " << retry_delay_in_seconds << " seconds";
if (no_retries > 0)
ndbout << ". Attempts left:";
else
ndbout << ", until connected.";;
ndbout << flush;
verbose= -2; verbose= -2;
} }
NdbSleep_SecSleep(retry_delay_in_seconds); if (no_retries > 0) {
if (verbose == -2) { if (verbose == -2) {
ndbout << " " << no_retries; ndbout << " " << no_retries;
ndbout << flush;
}
no_retries--;
} }
no_retries--; NdbSleep_SecSleep(retry_delay_in_seconds);
} }
if (verbose == -2)
ndbout << endl;
handle->cfg_i = i; handle->cfg_i = i;
......
...@@ -44,7 +44,7 @@ public: ...@@ -44,7 +44,7 @@ public:
* Constructor * Constructor
* @param mgmtSrvr: Management server to use when executing commands * @param mgmtSrvr: Management server to use when executing commands
*/ */
CommandInterpreter(const char *); CommandInterpreter(const char *, int verbose);
~CommandInterpreter(); ~CommandInterpreter();
/** /**
...@@ -94,6 +94,7 @@ private: ...@@ -94,6 +94,7 @@ private:
*/ */
void executeHelp(char* parameters); void executeHelp(char* parameters);
void executeShow(char* parameters); void executeShow(char* parameters);
void executeConnect(char* parameters);
void executePurge(char* parameters); void executePurge(char* parameters);
void executeShutdown(char* parameters); void executeShutdown(char* parameters);
void executeRun(char* parameters); void executeRun(char* parameters);
...@@ -153,6 +154,7 @@ private: ...@@ -153,6 +154,7 @@ private:
NdbMgmHandle m_mgmsrv; NdbMgmHandle m_mgmsrv;
bool connected; bool connected;
int m_verbose;
int try_reconnect; int try_reconnect;
#ifdef HAVE_GLOBAL_REPLICATION #ifdef HAVE_GLOBAL_REPLICATION
NdbRepHandle m_repserver; NdbRepHandle m_repserver;
...@@ -169,9 +171,9 @@ private: ...@@ -169,9 +171,9 @@ private:
#include "ndb_mgmclient.hpp" #include "ndb_mgmclient.hpp"
#include "ndb_mgmclient.h" #include "ndb_mgmclient.h"
Ndb_mgmclient::Ndb_mgmclient(const char *host) Ndb_mgmclient::Ndb_mgmclient(const char *host,int verbose)
{ {
m_cmd= new CommandInterpreter(host); m_cmd= new CommandInterpreter(host,verbose);
} }
Ndb_mgmclient::~Ndb_mgmclient() Ndb_mgmclient::~Ndb_mgmclient()
{ {
...@@ -275,6 +277,7 @@ static const char* helpText = ...@@ -275,6 +277,7 @@ static const char* helpText =
"REP CONNECT <host:port> Connect to REP server on host:port\n" "REP CONNECT <host:port> Connect to REP server on host:port\n"
#endif #endif
"PURGE STALE SESSIONS Reset reserved nodeid's in the mgmt server\n" "PURGE STALE SESSIONS Reset reserved nodeid's in the mgmt server\n"
"CONNECT Connect to management server (reconnect if already connected)\n"
"QUIT Quit management client\n" "QUIT Quit management client\n"
; ;
...@@ -373,7 +376,8 @@ convert(const char* s, int& val) { ...@@ -373,7 +376,8 @@ convert(const char* s, int& val) {
/* /*
* Constructor * Constructor
*/ */
CommandInterpreter::CommandInterpreter(const char *_host) CommandInterpreter::CommandInterpreter(const char *_host,int verbose)
: m_verbose(verbose)
{ {
m_mgmsrv = ndb_mgm_create_handle(); m_mgmsrv = ndb_mgm_create_handle();
if(m_mgmsrv == NULL) { if(m_mgmsrv == NULL) {
...@@ -437,7 +441,15 @@ CommandInterpreter::connect() ...@@ -437,7 +441,15 @@ CommandInterpreter::connect()
{ {
if(!connected) { if(!connected) {
if(!ndb_mgm_connect(m_mgmsrv, try_reconnect-1, 5, 1)) if(!ndb_mgm_connect(m_mgmsrv, try_reconnect-1, 5, 1))
{
connected = true; connected = true;
if (m_verbose)
{
printf("Connected to Management Server at: %s:%d\n",
ndb_mgm_get_connected_host(m_mgmsrv),
ndb_mgm_get_connected_port(m_mgmsrv));
}
}
} }
return connected; return connected;
} }
...@@ -445,7 +457,7 @@ CommandInterpreter::connect() ...@@ -445,7 +457,7 @@ CommandInterpreter::connect()
bool bool
CommandInterpreter::disconnect() CommandInterpreter::disconnect()
{ {
if (ndb_mgm_disconnect(m_mgmsrv) == -1) { if (connected && (ndb_mgm_disconnect(m_mgmsrv) == -1)) {
ndbout_c("Could not disconnect from management server"); ndbout_c("Could not disconnect from management server");
printError(); printError();
} }
...@@ -459,18 +471,21 @@ CommandInterpreter::disconnect() ...@@ -459,18 +471,21 @@ CommandInterpreter::disconnect()
int int
CommandInterpreter::execute(const char *_line, int _try_reconnect) CommandInterpreter::execute(const char *_line, int _try_reconnect)
{ {
DBUG_ENTER("CommandInterpreter::execute");
DBUG_PRINT("info",("line=\"%s\"",_line));
if (_try_reconnect >= 0) if (_try_reconnect >= 0)
try_reconnect=_try_reconnect; try_reconnect=_try_reconnect;
char * line; char * line;
if(_line == NULL) { if(_line == NULL) {
// ndbout << endl; // ndbout << endl;
return false; DBUG_RETURN(false);
} }
line = my_strdup(_line,MYF(MY_WME)); line = my_strdup(_line,MYF(MY_WME));
My_auto_ptr<char> ptr(line); My_auto_ptr<char> ptr(line);
if (emptyString(line)) { if (emptyString(line)) {
return true; DBUG_RETURN(true);
} }
for (unsigned int i = 0; i < strlen(line); ++i) { for (unsigned int i = 0; i < strlen(line); ++i) {
...@@ -484,41 +499,49 @@ CommandInterpreter::execute(const char *_line, int _try_reconnect) ...@@ -484,41 +499,49 @@ CommandInterpreter::execute(const char *_line, int _try_reconnect)
if (strcmp(firstToken, "HELP") == 0 || if (strcmp(firstToken, "HELP") == 0 ||
strcmp(firstToken, "?") == 0) { strcmp(firstToken, "?") == 0) {
executeHelp(allAfterFirstToken); executeHelp(allAfterFirstToken);
return true; DBUG_RETURN(true);
}
else if (strcmp(firstToken, "CONNECT") == 0) {
executeConnect(allAfterFirstToken);
DBUG_RETURN(true);
} }
else if (strcmp(firstToken, "SHOW") == 0) {
if (!connect())
DBUG_RETURN(true);
if (strcmp(firstToken, "SHOW") == 0) {
executeShow(allAfterFirstToken); executeShow(allAfterFirstToken);
return true; DBUG_RETURN(true);
} }
else if (strcmp(firstToken, "SHUTDOWN") == 0) { else if (strcmp(firstToken, "SHUTDOWN") == 0) {
executeShutdown(allAfterFirstToken); executeShutdown(allAfterFirstToken);
return true; DBUG_RETURN(true);
} }
else if (strcmp(firstToken, "CLUSTERLOG") == 0){ else if (strcmp(firstToken, "CLUSTERLOG") == 0){
executeClusterLog(allAfterFirstToken); executeClusterLog(allAfterFirstToken);
return true; DBUG_RETURN(true);
} }
else if(strcmp(firstToken, "START") == 0 && else if(strcmp(firstToken, "START") == 0 &&
allAfterFirstToken != NULL && allAfterFirstToken != NULL &&
strncmp(allAfterFirstToken, "BACKUP", sizeof("BACKUP") - 1) == 0){ strncmp(allAfterFirstToken, "BACKUP", sizeof("BACKUP") - 1) == 0){
executeStartBackup(allAfterFirstToken); executeStartBackup(allAfterFirstToken);
return true; DBUG_RETURN(true);
} }
else if(strcmp(firstToken, "ABORT") == 0 && else if(strcmp(firstToken, "ABORT") == 0 &&
allAfterFirstToken != NULL && allAfterFirstToken != NULL &&
strncmp(allAfterFirstToken, "BACKUP", sizeof("BACKUP") - 1) == 0){ strncmp(allAfterFirstToken, "BACKUP", sizeof("BACKUP") - 1) == 0){
executeAbortBackup(allAfterFirstToken); executeAbortBackup(allAfterFirstToken);
return true; DBUG_RETURN(true);
} }
else if (strcmp(firstToken, "PURGE") == 0) { else if (strcmp(firstToken, "PURGE") == 0) {
executePurge(allAfterFirstToken); executePurge(allAfterFirstToken);
return true; DBUG_RETURN(true);
} }
#ifdef HAVE_GLOBAL_REPLICATION #ifdef HAVE_GLOBAL_REPLICATION
else if(strcmp(firstToken, "REPLICATION") == 0 || else if(strcmp(firstToken, "REPLICATION") == 0 ||
strcmp(firstToken, "REP") == 0) { strcmp(firstToken, "REP") == 0) {
executeRep(allAfterFirstToken); executeRep(allAfterFirstToken);
return true; DBUG_RETURN(true);
} }
#endif // HAVE_GLOBAL_REPLICATION #endif // HAVE_GLOBAL_REPLICATION
else if(strcmp(firstToken, "ENTER") == 0 && else if(strcmp(firstToken, "ENTER") == 0 &&
...@@ -526,14 +549,14 @@ CommandInterpreter::execute(const char *_line, int _try_reconnect) ...@@ -526,14 +549,14 @@ CommandInterpreter::execute(const char *_line, int _try_reconnect)
strncmp(allAfterFirstToken, "SINGLE USER MODE ", strncmp(allAfterFirstToken, "SINGLE USER MODE ",
sizeof("SINGLE USER MODE") - 1) == 0){ sizeof("SINGLE USER MODE") - 1) == 0){
executeEnterSingleUser(allAfterFirstToken); executeEnterSingleUser(allAfterFirstToken);
return true; DBUG_RETURN(true);
} }
else if(strcmp(firstToken, "EXIT") == 0 && else if(strcmp(firstToken, "EXIT") == 0 &&
allAfterFirstToken != NULL && allAfterFirstToken != NULL &&
strncmp(allAfterFirstToken, "SINGLE USER MODE ", strncmp(allAfterFirstToken, "SINGLE USER MODE ",
sizeof("SINGLE USER MODE") - 1) == 0){ sizeof("SINGLE USER MODE") - 1) == 0){
executeExitSingleUser(allAfterFirstToken); executeExitSingleUser(allAfterFirstToken);
return true; DBUG_RETURN(true);
} }
else if (strcmp(firstToken, "ALL") == 0) { else if (strcmp(firstToken, "ALL") == 0) {
analyseAfterFirstToken(-1, allAfterFirstToken); analyseAfterFirstToken(-1, allAfterFirstToken);
...@@ -542,7 +565,7 @@ CommandInterpreter::execute(const char *_line, int _try_reconnect) ...@@ -542,7 +565,7 @@ CommandInterpreter::execute(const char *_line, int _try_reconnect)
strcmp(firstToken, "EXIT") == 0 || strcmp(firstToken, "EXIT") == 0 ||
strcmp(firstToken, "BYE") == 0) && strcmp(firstToken, "BYE") == 0) &&
allAfterFirstToken == NULL){ allAfterFirstToken == NULL){
return false; DBUG_RETURN(false);
} else { } else {
/** /**
* First token should be a digit, node ID * First token should be a digit, node ID
...@@ -552,18 +575,18 @@ CommandInterpreter::execute(const char *_line, int _try_reconnect) ...@@ -552,18 +575,18 @@ CommandInterpreter::execute(const char *_line, int _try_reconnect)
if (! convert(firstToken, nodeId)) { if (! convert(firstToken, nodeId)) {
ndbout << "Invalid command: " << line << endl; ndbout << "Invalid command: " << line << endl;
ndbout << "Type HELP for help." << endl << endl; ndbout << "Type HELP for help." << endl << endl;
return true; DBUG_RETURN(true);
} }
if (nodeId < 0) { if (nodeId < 0) {
ndbout << "Invalid node ID: " << firstToken << "." << endl; ndbout << "Invalid node ID: " << firstToken << "." << endl;
return true; DBUG_RETURN(true);
} }
analyseAfterFirstToken(nodeId, allAfterFirstToken); analyseAfterFirstToken(nodeId, allAfterFirstToken);
} }
return true; DBUG_RETURN(true);
} }
...@@ -692,7 +715,6 @@ CommandInterpreter::executeForAll(const char * cmd, ExecuteFunction fun, ...@@ -692,7 +715,6 @@ CommandInterpreter::executeForAll(const char * cmd, ExecuteFunction fun,
ndbout_c("Trying to start all nodes of system."); ndbout_c("Trying to start all nodes of system.");
ndbout_c("Use ALL STATUS to see the system start-up phases."); ndbout_c("Use ALL STATUS to see the system start-up phases.");
} else { } else {
connect();
struct ndb_mgm_cluster_state *cl= ndb_mgm_get_status(m_mgmsrv); struct ndb_mgm_cluster_state *cl= ndb_mgm_get_status(m_mgmsrv);
if(cl == 0){ if(cl == 0){
ndbout_c("Unable get status from management server"); ndbout_c("Unable get status from management server");
...@@ -826,8 +848,6 @@ CommandInterpreter::executeHelp(char* parameters) ...@@ -826,8 +848,6 @@ CommandInterpreter::executeHelp(char* parameters)
void void
CommandInterpreter::executeShutdown(char* parameters) CommandInterpreter::executeShutdown(char* parameters)
{ {
connect();
ndb_mgm_cluster_state *state = ndb_mgm_get_status(m_mgmsrv); ndb_mgm_cluster_state *state = ndb_mgm_get_status(m_mgmsrv);
if(state == NULL) { if(state == NULL) {
ndbout_c("Could not get status"); ndbout_c("Could not get status");
...@@ -979,7 +999,6 @@ CommandInterpreter::executePurge(char* parameters) ...@@ -979,7 +999,6 @@ CommandInterpreter::executePurge(char* parameters)
int i; int i;
char *str; char *str;
connect();
if (ndb_mgm_purge_stale_sessions(m_mgmsrv, &str)) { if (ndb_mgm_purge_stale_sessions(m_mgmsrv, &str)) {
ndbout_c("Command failed"); ndbout_c("Command failed");
...@@ -999,7 +1018,6 @@ void ...@@ -999,7 +1018,6 @@ void
CommandInterpreter::executeShow(char* parameters) CommandInterpreter::executeShow(char* parameters)
{ {
int i; int i;
connect();
if (emptyString(parameters)) { if (emptyString(parameters)) {
ndbout << "Cluster Configuration" << endl ndbout << "Cluster Configuration" << endl
<< "---------------------" << endl; << "---------------------" << endl;
...@@ -1087,6 +1105,12 @@ CommandInterpreter::executeShow(char* parameters) ...@@ -1087,6 +1105,12 @@ CommandInterpreter::executeShow(char* parameters)
} }
} }
void
CommandInterpreter::executeConnect(char* parameters)
{
disconnect();
connect();
}
//***************************************************************************** //*****************************************************************************
//***************************************************************************** //*****************************************************************************
...@@ -1094,7 +1118,6 @@ void ...@@ -1094,7 +1118,6 @@ void
CommandInterpreter::executeClusterLog(char* parameters) CommandInterpreter::executeClusterLog(char* parameters)
{ {
int i; int i;
connect();
if (parameters != 0 && strlen(parameters) != 0) { if (parameters != 0 && strlen(parameters) != 0) {
enum ndb_mgm_clusterlog_level severity = NDB_MGM_CLUSTERLOG_ALL; enum ndb_mgm_clusterlog_level severity = NDB_MGM_CLUSTERLOG_ALL;
int isOk = true; int isOk = true;
...@@ -1240,7 +1263,6 @@ CommandInterpreter::executeClusterLog(char* parameters) ...@@ -1240,7 +1263,6 @@ CommandInterpreter::executeClusterLog(char* parameters)
void void
CommandInterpreter::executeStop(int processId, const char *, bool all) CommandInterpreter::executeStop(int processId, const char *, bool all)
{ {
connect();
int result = 0; int result = 0;
if(all) { if(all) {
result = ndb_mgm_stop(m_mgmsrv, 0, 0); result = ndb_mgm_stop(m_mgmsrv, 0, 0);
...@@ -1262,7 +1284,6 @@ CommandInterpreter::executeStop(int processId, const char *, bool all) ...@@ -1262,7 +1284,6 @@ CommandInterpreter::executeStop(int processId, const char *, bool all)
void void
CommandInterpreter::executeEnterSingleUser(char* parameters) CommandInterpreter::executeEnterSingleUser(char* parameters)
{ {
connect();
strtok(parameters, " "); strtok(parameters, " ");
struct ndb_mgm_reply reply; struct ndb_mgm_reply reply;
char* id = strtok(NULL, " "); char* id = strtok(NULL, " ");
...@@ -1289,7 +1310,6 @@ CommandInterpreter::executeEnterSingleUser(char* parameters) ...@@ -1289,7 +1310,6 @@ CommandInterpreter::executeEnterSingleUser(char* parameters)
void void
CommandInterpreter::executeExitSingleUser(char* parameters) CommandInterpreter::executeExitSingleUser(char* parameters)
{ {
connect();
int result = ndb_mgm_exit_single_user(m_mgmsrv, 0); int result = ndb_mgm_exit_single_user(m_mgmsrv, 0);
if (result != 0) { if (result != 0) {
ndbout_c("Exiting single user mode failed."); ndbout_c("Exiting single user mode failed.");
...@@ -1304,7 +1324,6 @@ void ...@@ -1304,7 +1324,6 @@ void
CommandInterpreter::executeStart(int processId, const char* parameters, CommandInterpreter::executeStart(int processId, const char* parameters,
bool all) bool all)
{ {
connect();
int result; int result;
if(all) { if(all) {
result = ndb_mgm_start(m_mgmsrv, 0, 0); result = ndb_mgm_start(m_mgmsrv, 0, 0);
...@@ -1328,7 +1347,6 @@ void ...@@ -1328,7 +1347,6 @@ void
CommandInterpreter::executeRestart(int processId, const char* parameters, CommandInterpreter::executeRestart(int processId, const char* parameters,
bool all) bool all)
{ {
connect();
int result; int result;
int nostart = 0; int nostart = 0;
int initialstart = 0; int initialstart = 0;
...@@ -1378,7 +1396,6 @@ CommandInterpreter::executeDumpState(int processId, const char* parameters, ...@@ -1378,7 +1396,6 @@ CommandInterpreter::executeDumpState(int processId, const char* parameters,
ndbout << "Expected argument" << endl; ndbout << "Expected argument" << endl;
return; return;
} }
connect();
Uint32 no = 0; Uint32 no = 0;
int pars[25]; int pars[25];
...@@ -1418,7 +1435,6 @@ CommandInterpreter::executeStatus(int processId, ...@@ -1418,7 +1435,6 @@ CommandInterpreter::executeStatus(int processId,
return; return;
} }
connect();
ndb_mgm_node_status status; ndb_mgm_node_status status;
Uint32 startPhase, version; Uint32 startPhase, version;
bool system; bool system;
...@@ -1469,7 +1485,6 @@ void ...@@ -1469,7 +1485,6 @@ void
CommandInterpreter::executeLogLevel(int processId, const char* parameters, CommandInterpreter::executeLogLevel(int processId, const char* parameters,
bool all) bool all)
{ {
connect();
(void) all; (void) all;
BaseString tmp(parameters); BaseString tmp(parameters);
...@@ -1525,7 +1540,6 @@ void CommandInterpreter::executeError(int processId, ...@@ -1525,7 +1540,6 @@ void CommandInterpreter::executeError(int processId,
return; return;
} }
connect();
// Copy parameters since strtok will modify it // Copy parameters since strtok will modify it
char* newpar = my_strdup(parameters,MYF(MY_WME)); char* newpar = my_strdup(parameters,MYF(MY_WME));
My_auto_ptr<char> ap1(newpar); My_auto_ptr<char> ap1(newpar);
...@@ -1589,7 +1603,6 @@ void ...@@ -1589,7 +1603,6 @@ void
CommandInterpreter::executeLog(int processId, CommandInterpreter::executeLog(int processId,
const char* parameters, bool all) const char* parameters, bool all)
{ {
connect();
struct ndb_mgm_reply reply; struct ndb_mgm_reply reply;
Vector<const char *> blocks; Vector<const char *> blocks;
if (! parseBlockSpecification(parameters, blocks)) { if (! parseBlockSpecification(parameters, blocks)) {
...@@ -1657,7 +1670,6 @@ CommandInterpreter::executeTestOn(int processId, ...@@ -1657,7 +1670,6 @@ CommandInterpreter::executeTestOn(int processId,
ndbout << "No parameters expected to this command." << endl; ndbout << "No parameters expected to this command." << endl;
return; return;
} }
connect();
struct ndb_mgm_reply reply; struct ndb_mgm_reply reply;
int result = ndb_mgm_start_signallog(m_mgmsrv, processId, &reply); int result = ndb_mgm_start_signallog(m_mgmsrv, processId, &reply);
if (result != 0) { if (result != 0) {
...@@ -1676,7 +1688,6 @@ CommandInterpreter::executeTestOff(int processId, ...@@ -1676,7 +1688,6 @@ CommandInterpreter::executeTestOff(int processId,
ndbout << "No parameters expected to this command." << endl; ndbout << "No parameters expected to this command." << endl;
return; return;
} }
connect();
struct ndb_mgm_reply reply; struct ndb_mgm_reply reply;
int result = ndb_mgm_stop_signallog(m_mgmsrv, processId, &reply); int result = ndb_mgm_stop_signallog(m_mgmsrv, processId, &reply);
if (result != 0) { if (result != 0) {
...@@ -1798,8 +1809,6 @@ CommandInterpreter::executeEventReporting(int processId, ...@@ -1798,8 +1809,6 @@ CommandInterpreter::executeEventReporting(int processId,
ndbout << "Expected argument" << endl; ndbout << "Expected argument" << endl;
return; return;
} }
connect();
BaseString tmp(parameters); BaseString tmp(parameters);
Vector<BaseString> spec; Vector<BaseString> spec;
tmp.split(spec, "="); tmp.split(spec, "=");
...@@ -1850,7 +1859,6 @@ CommandInterpreter::executeEventReporting(int processId, ...@@ -1850,7 +1859,6 @@ CommandInterpreter::executeEventReporting(int processId,
void void
CommandInterpreter::executeStartBackup(char* /*parameters*/) CommandInterpreter::executeStartBackup(char* /*parameters*/)
{ {
connect();
struct ndb_mgm_reply reply; struct ndb_mgm_reply reply;
unsigned int backupId; unsigned int backupId;
...@@ -1897,8 +1905,6 @@ CommandInterpreter::executeStartBackup(char* /*parameters*/) ...@@ -1897,8 +1905,6 @@ CommandInterpreter::executeStartBackup(char* /*parameters*/)
void void
CommandInterpreter::executeAbortBackup(char* parameters) CommandInterpreter::executeAbortBackup(char* parameters)
{ {
connect();
strtok(parameters, " "); strtok(parameters, " ");
struct ndb_mgm_reply reply; struct ndb_mgm_reply reply;
char* id = strtok(NULL, "\0"); char* id = strtok(NULL, "\0");
...@@ -1952,7 +1958,6 @@ CommandInterpreter::executeRep(char* parameters) ...@@ -1952,7 +1958,6 @@ CommandInterpreter::executeRep(char* parameters)
return; return;
} }
connect();
char * line = my_strdup(parameters,MYF(MY_WME)); char * line = my_strdup(parameters,MYF(MY_WME));
My_auto_ptr<char> ap1((char*)line); My_auto_ptr<char> ap1((char*)line);
char * firstToken = strtok(line, " "); char * firstToken = strtok(line, " ");
......
...@@ -56,17 +56,18 @@ handler(int sig){ ...@@ -56,17 +56,18 @@ handler(int sig){
} }
} }
static const char default_prompt[]= "ndb_mgm> ";
static unsigned _try_reconnect; static unsigned _try_reconnect;
static char *opt_connect_str= 0; static char *opt_connect_str= 0;
static const char *prompt= default_prompt;
static struct my_option my_long_options[] = static struct my_option my_long_options[] =
{ {
NDB_STD_OPTS("ndb_mgm"), NDB_STD_OPTS("ndb_mgm"),
{ "try-reconnect", 't', { "try-reconnect", 't',
"Specify number of retries for connecting to ndb_mgmd, default infinite", "Specify number of tries for connecting to ndb_mgmd (0 = infinite)",
(gptr*) &_try_reconnect, (gptr*) &_try_reconnect, 0, (gptr*) &_try_reconnect, (gptr*) &_try_reconnect, 0,
GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, GET_UINT, REQUIRED_ARG, 3, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}; };
static void short_usage_sub(void) static void short_usage_sub(void)
...@@ -116,13 +117,13 @@ read_and_execute(int _try_reconnect) ...@@ -116,13 +117,13 @@ read_and_execute(int _try_reconnect)
} }
#ifdef HAVE_READLINE #ifdef HAVE_READLINE
/* Get a line from the user. */ /* Get a line from the user. */
line_read = readline ("ndb_mgm> "); line_read = readline (prompt);
/* If the line has any text in it, save it on the history. */ /* If the line has any text in it, save it on the history. */
if (line_read && *line_read) if (line_read && *line_read)
add_history (line_read); add_history (line_read);
#else #else
static char linebuffer[254]; static char linebuffer[254];
fputs("ndb_mgm> ", stdout); fputs(prompt, stdout);
linebuffer[sizeof(linebuffer)-1]=0; linebuffer[sizeof(linebuffer)-1]=0;
line_read = fgets(linebuffer, sizeof(linebuffer)-1, stdin); line_read = fgets(linebuffer, sizeof(linebuffer)-1, stdin);
if (line_read == linebuffer) { if (line_read == linebuffer) {
...@@ -155,12 +156,16 @@ int main(int argc, char** argv){ ...@@ -155,12 +156,16 @@ int main(int argc, char** argv){
opt_connect_str= buf; opt_connect_str= buf;
} }
if (!isatty(0))
{
prompt= 0;
}
ndbout << "-- NDB Cluster -- Management Client --" << endl; ndbout << "-- NDB Cluster -- Management Client --" << endl;
printf("Connecting to Management Server: %s\n", opt_connect_str ? opt_connect_str : "default");
signal(SIGPIPE, handler); signal(SIGPIPE, handler);
com = new Ndb_mgmclient(opt_connect_str); com = new Ndb_mgmclient(opt_connect_str,1);
while(read_and_execute(_try_reconnect)); while(read_and_execute(_try_reconnect));
delete com; delete com;
......
...@@ -21,7 +21,7 @@ class CommandInterpreter; ...@@ -21,7 +21,7 @@ class CommandInterpreter;
class Ndb_mgmclient class Ndb_mgmclient
{ {
public: public:
Ndb_mgmclient(const char*); Ndb_mgmclient(const char*,int verbose=0);
~Ndb_mgmclient(); ~Ndb_mgmclient();
int execute(const char *_line, int _try_reconnect=-1); int execute(const char *_line, int _try_reconnect=-1);
int execute(int argc, char** argv, int _try_reconnect=-1); int execute(int argc, char** argv, int _try_reconnect=-1);
......
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