mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 05:22:25 +01:00
[PATCH] WL#3704 mgmapi timeouts: Add bool timeout flag to Streams
Index: ndb-work/storage/ndb/include/util/InputStream.hpp ===================================================================
This commit is contained in:
parent
c2f0a25dc4
commit
64361ee36f
6 changed files with 60 additions and 9 deletions
|
@ -50,10 +50,14 @@ class SocketInputStream : public InputStream {
|
|||
NDB_SOCKET_TYPE m_socket;
|
||||
unsigned m_timeout_ms;
|
||||
bool m_startover;
|
||||
bool m_timedout;
|
||||
public:
|
||||
SocketInputStream(NDB_SOCKET_TYPE socket, unsigned read_timeout_ms = 1000);
|
||||
virtual ~SocketInputStream() {}
|
||||
char* gets(char * buf, int bufLen);
|
||||
bool timedout() { return m_timedout; };
|
||||
void reset_timeout() { m_timedout= false; };
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -45,9 +45,12 @@ public:
|
|||
class SocketOutputStream : public OutputStream {
|
||||
NDB_SOCKET_TYPE m_socket;
|
||||
unsigned m_timeout_ms;
|
||||
bool m_timedout;
|
||||
public:
|
||||
SocketOutputStream(NDB_SOCKET_TYPE socket, unsigned write_timeout_ms = 1000);
|
||||
virtual ~SocketOutputStream() {}
|
||||
bool timedout() { return m_timedout; };
|
||||
void reset_timeout() { m_timedout= false; };
|
||||
|
||||
int print(const char * fmt, ...);
|
||||
int println(const char * fmt, ...);
|
||||
|
|
|
@ -38,10 +38,13 @@ SocketInputStream::SocketInputStream(NDB_SOCKET_TYPE socket,
|
|||
: m_socket(socket) {
|
||||
m_startover= true;
|
||||
m_timeout_ms = read_timeout_ms;
|
||||
m_timedout= false;
|
||||
}
|
||||
|
||||
char*
|
||||
SocketInputStream::gets(char * buf, int bufLen) {
|
||||
if(timedout())
|
||||
return 0;
|
||||
assert(bufLen >= 2);
|
||||
int offset= 0;
|
||||
if(m_startover)
|
||||
|
@ -63,7 +66,10 @@ SocketInputStream::gets(char * buf, int bufLen) {
|
|||
m_startover= true;
|
||||
|
||||
if(res == -1)
|
||||
{
|
||||
m_timedout= true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -45,21 +45,38 @@ SocketOutputStream::SocketOutputStream(NDB_SOCKET_TYPE socket,
|
|||
unsigned write_timeout_ms){
|
||||
m_socket = socket;
|
||||
m_timeout_ms = write_timeout_ms;
|
||||
m_timedout= false;
|
||||
}
|
||||
|
||||
int
|
||||
SocketOutputStream::print(const char * fmt, ...){
|
||||
va_list ap;
|
||||
|
||||
if(timedout())
|
||||
return -1;
|
||||
|
||||
va_start(ap, fmt);
|
||||
const int ret = vprint_socket(m_socket, m_timeout_ms, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (errno==ETIMEDOUT)
|
||||
m_timedout= true;
|
||||
|
||||
return ret;
|
||||
}
|
||||
int
|
||||
SocketOutputStream::println(const char * fmt, ...){
|
||||
va_list ap;
|
||||
|
||||
if(timedout())
|
||||
return -1;
|
||||
|
||||
va_start(ap, fmt);
|
||||
const int ret = vprintln_socket(m_socket, m_timeout_ms, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (errno==ETIMEDOUT)
|
||||
m_timedout= true;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1641,7 +1641,12 @@ MgmApiSession::get_mgmd_nodeid(Parser_t::Context &ctx,
|
|||
Properties const &args)
|
||||
{
|
||||
m_output->println("get mgmd nodeid reply");
|
||||
m_output->println("nodeid:%u",m_mgmsrv.getOwnNodeId());
|
||||
m_output->println("nodeid:%u",m_mgmsrv.getOwnNodeId());
|
||||
if(ERROR_INSERTED(1))
|
||||
{
|
||||
NdbSleep_SecSleep(10);
|
||||
}
|
||||
|
||||
m_output->println("");
|
||||
}
|
||||
|
||||
|
|
|
@ -218,16 +218,12 @@ int runTestApiTimeout1(NDBT_Context* ctx, NDBT_Step* step)
|
|||
ndb_mgm_set_connectstring(h, mgm);
|
||||
ndb_mgm_connect(h,0,0,0);
|
||||
|
||||
ndbout << "Connected" << endl;
|
||||
|
||||
if(ndb_mgm_check_connection(h) < 0)
|
||||
{
|
||||
result= NDBT_FAILED;
|
||||
goto done;
|
||||
}
|
||||
|
||||
ndbout << "Checked Connection" << endl;
|
||||
|
||||
ndb_mgm_reply reply;
|
||||
reply.return_code= 0;
|
||||
|
||||
|
@ -238,9 +234,7 @@ int runTestApiTimeout1(NDBT_Context* ctx, NDBT_Step* step)
|
|||
goto done;
|
||||
}
|
||||
|
||||
ndbout << "Inserted session error" << endl;
|
||||
|
||||
ndb_mgm_set_timeout(h,1000,1000);
|
||||
ndb_mgm_set_timeout(h,2500);
|
||||
|
||||
cc= ndb_mgm_check_connection(h);
|
||||
if(cc < 0)
|
||||
|
@ -248,7 +242,29 @@ int runTestApiTimeout1(NDBT_Context* ctx, NDBT_Step* step)
|
|||
else
|
||||
result= NDBT_FAILED;
|
||||
|
||||
ndbout << "Tried check connection with result: " << cc << endl;
|
||||
ndbout << "test 2" << endl;
|
||||
ndb_mgm_connect(h,0,0,0);
|
||||
|
||||
cc= ndb_mgm_get_mgmd_nodeid(h);
|
||||
if(cc==0)
|
||||
result= NDBT_OK;
|
||||
else
|
||||
result= NDBT_FAILED;
|
||||
|
||||
if(ndb_mgm_insert_error(h, 3, 0, &reply)< 0)
|
||||
{
|
||||
ndbout << "failed to remove inserted error " << endl;
|
||||
result= NDBT_FAILED;
|
||||
goto done;
|
||||
}
|
||||
|
||||
cc= ndb_mgm_get_mgmd_nodeid(h);
|
||||
ndbout << "got node id: " << cc << endl;
|
||||
if(cc==0)
|
||||
result= NDBT_FAILED;
|
||||
else
|
||||
result= NDBT_OK;
|
||||
|
||||
done:
|
||||
ndb_mgm_disconnect(h);
|
||||
ndb_mgm_destroy_handle(&h);
|
||||
|
|
Loading…
Reference in a new issue