[PATCH] WL#3704 mgmapi timeouts: consolidate NdbMgmHandle timeouts into one

Only one timeout value is needed. Also saves 8bytes per NdbMgmHandle :)

Index: ndb-work/storage/ndb/include/mgmapi/mgmapi.h
===================================================================
parent 450d8965
...@@ -546,8 +546,7 @@ extern "C" { ...@@ -546,8 +546,7 @@ extern "C" {
const char *ndb_mgm_get_connectstring(NdbMgmHandle handle, char *buf, int buf_sz); const char *ndb_mgm_get_connectstring(NdbMgmHandle handle, char *buf, int buf_sz);
/** /**
* Sets the number of seconds to wait for connect(2) during ndb_mgm_connect * DEPRICATED: use ndb_mgm_set_timeout instead.
* Default is no timeout
* *
* @param handle NdbMgmHandle * @param handle NdbMgmHandle
* @param seconds number of seconds * @param seconds number of seconds
...@@ -556,15 +555,16 @@ extern "C" { ...@@ -556,15 +555,16 @@ extern "C" {
int ndb_mgm_set_connect_timeout(NdbMgmHandle handle, unsigned int seconds); int ndb_mgm_set_connect_timeout(NdbMgmHandle handle, unsigned int seconds);
/** /**
* Sets the number of milliseconds for timeout for read and write operations * Sets the number of milliseconds for timeout of network operations
* to the socket * Default is 60 seconds.
* Default is 50,000 for read, 1000 for write * Only increments of 1000 ms are supported. No function is gaurenteed
* to return in a fraction of a second.
* *
* @param handle NdbMgmHandle * @param handle NdbMgmHandle
* @param rw_milliseconds number of milliseconds * @param timeout_ms number of milliseconds
* @return zero on success * @return zero on success
*/ */
int ndb_mgm_set_timeout(NdbMgmHandle handle, unsigned int rw_milliseconds); int ndb_mgm_set_timeout(NdbMgmHandle handle, unsigned int timeout_ms);
/** /**
* Connects to a management server. Connectstring is set by * Connects to a management server. Connectstring is set by
......
...@@ -91,9 +91,7 @@ struct ndb_mgm_handle { ...@@ -91,9 +91,7 @@ struct ndb_mgm_handle {
int last_error; int last_error;
int last_error_line; int last_error_line;
char last_error_desc[NDB_MGM_MAX_ERR_DESC_SIZE]; char last_error_desc[NDB_MGM_MAX_ERR_DESC_SIZE];
int read_timeout; unsigned int timeout;
int write_timeout;
unsigned int connect_timeout;
NDB_SOCKET_TYPE socket; NDB_SOCKET_TYPE socket;
...@@ -187,9 +185,7 @@ ndb_mgm_create_handle() ...@@ -187,9 +185,7 @@ ndb_mgm_create_handle()
h->last_error = 0; h->last_error = 0;
h->last_error_line = 0; h->last_error_line = 0;
h->socket = NDB_INVALID_SOCKET; h->socket = NDB_INVALID_SOCKET;
h->read_timeout = 50000; h->timeout = 60000;
h->write_timeout = 100;
h->connect_timeout = 0;
h->cfg_i = -1; h->cfg_i = -1;
h->errstream = stdout; h->errstream = stdout;
h->m_name = 0; h->m_name = 0;
...@@ -346,8 +342,8 @@ ndb_mgm_call(NdbMgmHandle handle, const ParserRow<ParserDummy> *command_reply, ...@@ -346,8 +342,8 @@ ndb_mgm_call(NdbMgmHandle handle, const ParserRow<ParserDummy> *command_reply,
DBUG_ENTER("ndb_mgm_call"); DBUG_ENTER("ndb_mgm_call");
DBUG_PRINT("enter",("handle->socket: %d, cmd: %s", DBUG_PRINT("enter",("handle->socket: %d, cmd: %s",
handle->socket, cmd)); handle->socket, cmd));
SocketOutputStream out(handle->socket, handle->write_timeout); SocketOutputStream out(handle->socket, handle->timeout);
SocketInputStream in(handle->socket, handle->read_timeout); SocketInputStream in(handle->socket, handle->timeout);
out.println(cmd); out.println(cmd);
#ifdef MGMAPI_LOG #ifdef MGMAPI_LOG
...@@ -469,20 +465,17 @@ int ndb_mgm_is_connected(NdbMgmHandle handle) ...@@ -469,20 +465,17 @@ int ndb_mgm_is_connected(NdbMgmHandle handle)
extern "C" extern "C"
int ndb_mgm_set_connect_timeout(NdbMgmHandle handle, unsigned int seconds) int ndb_mgm_set_connect_timeout(NdbMgmHandle handle, unsigned int seconds)
{ {
if(!handle) return ndb_mgm_set_timeout(handle, seconds*1000);
return -1;
handle->connect_timeout= seconds;
return 0; return 0;
} }
extern "C" extern "C"
int ndb_mgm_set_timeout(NdbMgmHandle handle, unsigned int rw_milliseconds) int ndb_mgm_set_timeout(NdbMgmHandle handle, unsigned int timeout_ms)
{ {
if(!handle) if(!handle)
return -1; return -1;
handle->read_timeout= handle->write_timeout= rw_milliseconds; handle->timeout= timeout_ms;
return 0; return 0;
} }
...@@ -515,7 +508,7 @@ ndb_mgm_connect(NdbMgmHandle handle, int no_retries, ...@@ -515,7 +508,7 @@ ndb_mgm_connect(NdbMgmHandle handle, int no_retries,
NDB_SOCKET_TYPE sockfd= NDB_INVALID_SOCKET; NDB_SOCKET_TYPE sockfd= NDB_INVALID_SOCKET;
Uint32 i; Uint32 i;
SocketClient s(0, 0); SocketClient s(0, 0);
s.set_connect_timeout(handle->connect_timeout); s.set_connect_timeout(handle->timeout);
if (!s.init()) if (!s.init())
{ {
fprintf(handle->errstream, fprintf(handle->errstream,
...@@ -825,8 +818,8 @@ ndb_mgm_get_status(NdbMgmHandle handle) ...@@ -825,8 +818,8 @@ ndb_mgm_get_status(NdbMgmHandle handle)
CHECK_HANDLE(handle, NULL); CHECK_HANDLE(handle, NULL);
CHECK_CONNECTED(handle, NULL); CHECK_CONNECTED(handle, NULL);
SocketOutputStream out(handle->socket, handle->write_timeout); SocketOutputStream out(handle->socket, handle->timeout);
SocketInputStream in(handle->socket, handle->read_timeout); SocketInputStream in(handle->socket, handle->timeout);
out.println("get status"); out.println("get status");
out.println(""); out.println("");
...@@ -1226,10 +1219,10 @@ ndb_mgm_restart3(NdbMgmHandle handle, int no_of_nodes, const int * node_list, ...@@ -1226,10 +1219,10 @@ ndb_mgm_restart3(NdbMgmHandle handle, int no_of_nodes, const int * node_list,
args.put("initialstart", initial); args.put("initialstart", initial);
args.put("nostart", nostart); args.put("nostart", nostart);
const Properties *reply; const Properties *reply;
const int timeout = handle->read_timeout; const int timeout = handle->timeout;
handle->read_timeout= 5*60*1000; // 5 minutes handle->timeout= 5*60*1000; // 5 minutes
reply = ndb_mgm_call(handle, restart_reply_v1, "restart all", &args); reply = ndb_mgm_call(handle, restart_reply_v1, "restart all", &args);
handle->read_timeout= timeout; handle->timeout= timeout;
CHECK_REPLY(handle, reply, -1); CHECK_REPLY(handle, reply, -1);
BaseString result; BaseString result;
...@@ -1262,13 +1255,13 @@ ndb_mgm_restart3(NdbMgmHandle handle, int no_of_nodes, const int * node_list, ...@@ -1262,13 +1255,13 @@ ndb_mgm_restart3(NdbMgmHandle handle, int no_of_nodes, const int * node_list,
args.put("nostart", nostart); args.put("nostart", nostart);
const Properties *reply; const Properties *reply;
const int timeout = handle->read_timeout; const int timeout = handle->timeout;
handle->read_timeout= 5*60*1000; // 5 minutes handle->timeout= 5*60*1000; // 5 minutes
if(use_v2) if(use_v2)
reply = ndb_mgm_call(handle, restart_reply_v2, "restart node v2", &args); reply = ndb_mgm_call(handle, restart_reply_v2, "restart node v2", &args);
else else
reply = ndb_mgm_call(handle, restart_reply_v1, "restart node", &args); reply = ndb_mgm_call(handle, restart_reply_v1, "restart node", &args);
handle->read_timeout= timeout; handle->timeout= timeout;
if(reply != NULL) { if(reply != NULL) {
BaseString result; BaseString result;
reply->get("result", result); reply->get("result", result);
...@@ -2038,13 +2031,13 @@ ndb_mgm_start_backup(NdbMgmHandle handle, int wait_completed, ...@@ -2038,13 +2031,13 @@ ndb_mgm_start_backup(NdbMgmHandle handle, int wait_completed,
args.put("completed", wait_completed); args.put("completed", wait_completed);
const Properties *reply; const Properties *reply;
{ // start backup can take some time, set timeout high { // start backup can take some time, set timeout high
Uint64 old_timeout= handle->read_timeout; Uint64 old_timeout= handle->timeout;
if (wait_completed == 2) if (wait_completed == 2)
handle->read_timeout= 48*60*60*1000; // 48 hours handle->timeout= 48*60*60*1000; // 48 hours
else if (wait_completed == 1) else if (wait_completed == 1)
handle->read_timeout= 10*60*1000; // 10 minutes handle->timeout= 10*60*1000; // 10 minutes
reply = ndb_mgm_call(handle, start_backup_reply, "start backup", &args); reply = ndb_mgm_call(handle, start_backup_reply, "start backup", &args);
handle->read_timeout= old_timeout; handle->timeout= old_timeout;
} }
CHECK_REPLY(handle, reply, -1); CHECK_REPLY(handle, reply, -1);
...@@ -2151,7 +2144,7 @@ ndb_mgm_get_configuration(NdbMgmHandle handle, unsigned int version) { ...@@ -2151,7 +2144,7 @@ ndb_mgm_get_configuration(NdbMgmHandle handle, unsigned int version) {
int read = 0; int read = 0;
size_t start = 0; size_t start = 0;
do { do {
if((read = read_socket(handle->socket, handle->read_timeout, if((read = read_socket(handle->socket, handle->timeout,
&buf64[start], len-start)) < 1){ &buf64[start], len-start)) < 1){
delete[] buf64; delete[] buf64;
buf64 = 0; buf64 = 0;
...@@ -2484,8 +2477,8 @@ int ...@@ -2484,8 +2477,8 @@ int
ndb_mgm_check_connection(NdbMgmHandle handle){ ndb_mgm_check_connection(NdbMgmHandle handle){
CHECK_HANDLE(handle, 0); CHECK_HANDLE(handle, 0);
CHECK_CONNECTED(handle, 0); CHECK_CONNECTED(handle, 0);
SocketOutputStream out(handle->socket, handle->write_timeout); SocketOutputStream out(handle->socket, handle->timeout);
SocketInputStream in(handle->socket, handle->read_timeout); SocketInputStream in(handle->socket, handle->timeout);
char buf[32]; char buf[32];
if (out.println("check connection")) if (out.println("check connection"))
goto ndb_mgm_check_connection_error; goto ndb_mgm_check_connection_error;
...@@ -2614,7 +2607,7 @@ ndb_mgm_convert_to_transporter(NdbMgmHandle *handle) ...@@ -2614,7 +2607,7 @@ ndb_mgm_convert_to_transporter(NdbMgmHandle *handle)
(*handle)->connected= 0; // we pretend we're disconnected (*handle)->connected= 0; // we pretend we're disconnected
s= (*handle)->socket; s= (*handle)->socket;
SocketOutputStream s_output(s, (*handle)->write_timeout); SocketOutputStream s_output(s, (*handle)->timeout);
s_output.println("transporter connect"); s_output.println("transporter connect");
s_output.println(""); s_output.println("");
...@@ -2690,11 +2683,11 @@ int ndb_mgm_end_session(NdbMgmHandle handle) ...@@ -2690,11 +2683,11 @@ int ndb_mgm_end_session(NdbMgmHandle handle)
CHECK_CONNECTED(handle, 0); CHECK_CONNECTED(handle, 0);
DBUG_ENTER("ndb_mgm_end_session"); DBUG_ENTER("ndb_mgm_end_session");
SocketOutputStream s_output(handle->socket, handle->write_timeout); SocketOutputStream s_output(handle->socket, handle->timeout);
s_output.println("end session"); s_output.println("end session");
s_output.println(""); s_output.println("");
SocketInputStream in(handle->socket, handle->read_timeout); SocketInputStream in(handle->socket, handle->timeout);
char buf[32]; char buf[32];
in.gets(buf, sizeof(buf)); in.gets(buf, sizeof(buf));
CHECK_TIMEDOUT_RET(handle, in, s_output, -1); CHECK_TIMEDOUT_RET(handle, in, s_output, -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