#At file:///home/msvensson/mysql/7.0/ based on revid:magnus.blaudd@stripped4oewcza4y1
3100 Magnus Blåudd 2009-10-08 [merge]
Merge bug#45497
modified:
storage/ndb/include/util/SocketServer.hpp
storage/ndb/src/common/util/SocketServer.cpp
storage/ndb/src/mgmsrv/Services.cpp
storage/ndb/test/ndbapi/testMgm.cpp
=== modified file 'storage/ndb/include/util/SocketServer.hpp'
--- a/storage/ndb/include/util/SocketServer.hpp 2009-05-27 15:21:45 +0000
+++ b/storage/ndb/include/util/SocketServer.hpp 2009-09-29 10:26:01 +0000
@@ -136,8 +136,8 @@ private:
Vector<SessionInstance> m_sessions;
MutexVector<ServiceInstance> m_services;
unsigned m_maxSessions;
-
- void doAccept();
+
+ bool doAccept();
void checkSessionsImpl();
void startSession(SessionInstance &);
=== modified file 'storage/ndb/src/common/util/SocketServer.cpp'
--- a/storage/ndb/src/common/util/SocketServer.cpp 2009-09-08 15:12:34 +0000
+++ b/storage/ndb/src/common/util/SocketServer.cpp 2009-09-29 10:26:01 +0000
@@ -28,8 +28,6 @@
#include <NdbSleep.h>
#include <NdbTick.h>
-#define DEBUG(x) ndbout << x << endl;
-
SocketServer::SocketServer(unsigned maxSessions) :
m_sessions(10),
m_services(5),
@@ -159,7 +157,7 @@ SocketServer::setup(SocketServer::Servic
DBUG_RETURN(true);
}
-void
+bool
SocketServer::doAccept(){
fd_set readSet, exceptionSet;
FD_ZERO(&readSet);
@@ -173,7 +171,7 @@ SocketServer::doAccept(){
{
m_services.unlock();
my_sleep(1000);
- return;
+ return true;
}
#endif
@@ -195,7 +193,10 @@ SocketServer::doAccept(){
if(my_FD_ISSET(si.m_socket, &readSet)){
my_socket childSock = my_accept(si.m_socket, 0, 0);
if(!my_socket_valid(childSock))
- continue;
+ {
+ m_services.unlock();
+ return false;
+ }
SessionInstance s;
s.m_service = si.m_service;
@@ -207,17 +208,20 @@ SocketServer::doAccept(){
startSession(m_sessions.back());
m_session_mutex.unlock();
}
-
- continue;
- }
-
- if(my_FD_ISSET(si.m_socket, &exceptionSet)){
- DEBUG("socket in the exceptionSet");
+
continue;
}
+
+ if(my_FD_ISSET(si.m_socket, &exceptionSet))
+ {
+ m_services.unlock();
+ return false;
+ }
}
}
m_services.unlock();
+
+ return true;
}
extern "C"
@@ -264,11 +268,16 @@ SocketServer::doRun(){
while(!m_stopThread){
m_session_mutex.lock();
checkSessionsImpl();
- if(m_sessions.size() < m_maxSessions){
- m_session_mutex.unlock();
- doAccept();
- } else {
- m_session_mutex.unlock();
+ m_session_mutex.unlock();
+
+ if(m_sessions.size() >= m_maxSessions){
+ // Don't accept more connections yet
+ NdbSleep_MilliSleep(200);
+ continue;
+ }
+
+ if (!doAccept()){
+ // accept failed, step back
NdbSleep_MilliSleep(200);
}
}
=== modified file 'storage/ndb/src/mgmsrv/Services.cpp'
--- a/storage/ndb/src/mgmsrv/Services.cpp 2009-05-27 15:21:45 +0000
+++ b/storage/ndb/src/mgmsrv/Services.cpp 2009-09-29 10:26:01 +0000
@@ -399,12 +399,13 @@ MgmApiSession::runSession()
const char* msg= NULL;
switch(ctx.m_status) {
case Parser_t::Eof: // Client disconnected
- g_eventLogger->debug("%s: Disconnected!", name());
stop= true;
+ g_eventLogger->debug("%s: Eof!", name());
break;
case Parser_t::ExternalStop: // Stopped by other thread
stop= true;
+ g_eventLogger->debug("%s: ExternalStop!", name());
break;
case Parser_t::NoLine: // Normal read timeout
@@ -443,6 +444,8 @@ MgmApiSession::runSession()
}
+ g_eventLogger->debug("%s: Stopped!", name());
+
NdbMutex_Lock(m_mutex);
m_ctx= NULL;
if(my_socket_valid(m_socket))
@@ -451,6 +454,9 @@ MgmApiSession::runSession()
my_socket_invalidate(&m_socket);
}
NdbMutex_Unlock(m_mutex);
+
+ g_eventLogger->debug("%s: Disconnected!", name());
+
DBUG_VOID_RETURN;
}
=== modified file 'storage/ndb/test/ndbapi/testMgm.cpp'
--- a/storage/ndb/test/ndbapi/testMgm.cpp 2009-10-02 15:06:00 +0000
+++ b/storage/ndb/test/ndbapi/testMgm.cpp 2009-10-08 12:24:18 +0000
@@ -2399,6 +2399,59 @@ int runTestBug40922(NDBT_Context* ctx, N
}
+int runTestBug45497(NDBT_Context* ctx, NDBT_Step* step)
+{
+ int result = NDBT_OK;
+ int loops = ctx->getNumLoops();
+ Vector<NdbMgmd*> mgmds;
+
+ while(true)
+ {
+ NdbMgmd* mgmd = new NdbMgmd();
+
+ // Set quite short timeout
+ if (!mgmd->set_timeout(1000))
+ {
+ result = NDBT_FAILED;
+ break;
+ }
+
+ if (mgmd->connect())
+ {
+ mgmds.push_back(mgmd);
+ g_info << "connections: " << mgmds.size() << endl;
+ continue;
+ }
+
+ g_err << "Failed to make another connection, connections: "
+ << mgmds.size() << endl;
+
+
+ // Disconnect some connections
+ int to_disconnect = 10;
+ while(mgmds.size() && to_disconnect--)
+ {
+ g_info << "disconnnect, connections: " << mgmds.size() << endl;
+ NdbMgmd* mgmd = mgmds[0];
+ mgmds.erase(0);
+ delete mgmd;
+ }
+
+ if (loops-- == 0)
+ break;
+ }
+
+ while(mgmds.size())
+ {
+ NdbMgmd* mgmd = mgmds[0];
+ mgmds.erase(0);
+ delete mgmd;
+ }
+
+ return result;
+}
+
+
NDBT_TESTSUITE(testMgm);
DRIVER(DummyDriver); /* turn off use of NdbApi */
TESTCASE("ApiSessionFailure",
@@ -2526,6 +2579,10 @@ TESTCASE("Stress2",
// STEPS(runTestGetVersionUntilStopped, 5);
STEP(runSleepAndStop);
}
+TESTCASE("Bug45497",
+ "Connect to ndb_mgmd until it can't handle more connections"){
+ STEP(runTestBug45497);
+}
NDBT_TESTSUITE_END(testMgm);
int main(int argc, const char** argv){
@@ -2536,3 +2593,4 @@ int main(int argc, const char** argv){
return testMgm.execute(argc, argv);
}
+template class Vector<NdbMgmd*>;
Attachment: [text/bzr-bundle] bzr/magnus.blaudd@sun.com-20091008122418-ugsfietfwq4vy3nl.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-7.0 branch (magnus.blaudd:3100)Bug#45497 | Magnus Blåudd | 8 Oct |