MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Stewart Smith Date:January 23 2007 6:08am
Subject:bk commit into 5.0 tree (stewart:1.2367) BUG#25487
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of stewart. When stewart does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-01-23 17:07:09+11:00, stewart@willster.(none) +5 -0
  Bug #25487  	deleting ndb_cluster_connection object takes long time
    
    aim is to:
    a) if set_connect_timeout called, timeout connect attempt (for retry on
    next call) after timeout period
    b) preserve existing blocking behaviour otherwise (for, e.g. mgmapi)
    
    Related to customer issue with long time deleting ndb_cluster_connection
    object. believe we're hanging on the connect(2) call until timeout (when
    we then realise we should exit the thread).

  ndb/include/mgmapi/mgmapi.h@stripped, 2007-01-23 17:06:24+11:00, stewart@willster.(none) +10 -0
    add ndb_mgm_set_connect_timeout

  ndb/include/util/SocketClient.hpp@stripped, 2007-01-23 17:06:32+11:00, stewart@willster.(none) +4 -0
    add timeout (seconds) for max time to wait for connection

  ndb/src/common/transporter/Transporter.cpp@stripped, 2007-01-23 17:06:32+11:00, stewart@willster.(none) +6 -2
    set limit on amount of time we'll wait for tcp connect

  ndb/src/common/util/SocketClient.cpp@stripped, 2007-01-23 17:06:32+11:00, stewart@willster.(none) +56 -4
    only try to connect for a maximum of timeout time

  ndb/src/mgmapi/mgmapi.cpp@stripped, 2007-01-23 17:06:33+11:00, stewart@willster.(none) +13 -0
    add ndb_mgm_set_connect_timeout

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	stewart
# Host:	willster.(none)
# Root:	/home/stewart/Documents/MySQL/5.0/bug25487

--- 1.53/ndb/include/mgmapi/mgmapi.h	2006-12-24 06:04:10 +11:00
+++ 1.54/ndb/include/mgmapi/mgmapi.h	2007-01-23 17:06:24 +11:00
@@ -541,6 +541,16 @@
   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
+   * Default is no timeout
+   *
+   * @param handle  NdbMgmHandle
+   * @param seconds number of seconds
+   * @return non-zero on success
+   */
+  int ndb_mgm_set_connect_timeout(NdbMgmHandle handle, unsigned int seconds);
+
+  /**
    * Connects to a management server. Connectstring is set by
    * ndb_mgm_set_connectstring().
    *

--- 1.23/ndb/src/common/transporter/Transporter.cpp	2006-12-24 06:04:14 +11:00
+++ 1.24/ndb/src/common/transporter/Transporter.cpp	2007-01-23 17:06:32 +11:00
@@ -79,9 +79,13 @@
   if (isServer)
     m_socket_client= 0;
   else
+  {
     m_socket_client= new SocketClient(remoteHostName, s_port,
 				      new SocketAuthSimple("ndbd",
 							   "ndbd passwd"));
+
+    m_socket_client->set_connect_timeout(m_timeOutMillis/1000);
+  }
   DBUG_VOID_RETURN;
 }
 
@@ -140,9 +144,9 @@
     }
     sockfd= m_socket_client->connect();
   }
-  
+
   return connect_client(sockfd);
-}  
+}
 
 bool
 Transporter::connect_client(NDB_SOCKET_TYPE sockfd) {

--- 1.67/ndb/src/mgmapi/mgmapi.cpp	2006-12-24 06:04:17 +11:00
+++ 1.68/ndb/src/mgmapi/mgmapi.cpp	2007-01-23 17:06:33 +11:00
@@ -93,6 +93,7 @@
   char last_error_desc[NDB_MGM_MAX_ERR_DESC_SIZE];
   int read_timeout;
   int write_timeout;
+  unsigned int connect_timeout;
 
   NDB_SOCKET_TYPE socket;
 
@@ -159,6 +160,7 @@
   h->socket          = NDB_INVALID_SOCKET;
   h->read_timeout    = 50000;
   h->write_timeout   = 100;
+  h->connect_timeout = 0;
   h->cfg_i           = -1;
   h->errstream       = stdout;
   h->m_name          = 0;
@@ -426,6 +428,16 @@
   return handle->connected;
 }
 
+extern "C"
+int ndb_mgm_set_connect_timeout(NdbMgmHandle handle, unsigned int seconds)
+{
+  if(!handle)
+    return -1;
+
+  handle->connect_timeout= seconds;
+  return 0;
+}
+
 /**
  * Connect to a management server
  */
@@ -456,6 +468,7 @@
   Uint32 i;
   int binderror = 0;
   SocketClient s(0, 0);
+  s.set_connect_timeout(handle->connect_timeout);
   if (!s.init())
   {
     fprintf(handle->errstream, 

--- 1.6/ndb/include/util/SocketClient.hpp	2006-12-24 06:04:12 +11:00
+++ 1.7/ndb/include/util/SocketClient.hpp	2007-01-23 17:06:32 +11:00
@@ -23,6 +23,7 @@
 {
   NDB_SOCKET_TYPE m_sockfd;
   struct sockaddr_in m_servaddr;
+  unsigned int m_connect_timeout_sec;
   unsigned short m_port;
   char *m_server_name;
   SocketAuthenticator *m_auth;
@@ -34,6 +35,9 @@
     m_port = port;
     m_servaddr.sin_port = htons(m_port);
   };
+  void set_connect_timeout(unsigned int s) {
+    m_connect_timeout_sec= s;
+  }
   unsigned short get_port() { return m_port; };
   char *get_server_name() { return m_server_name; };
   int bind(const char* toaddress, unsigned short toport);

--- 1.9/ndb/src/common/util/SocketClient.cpp	2006-12-24 06:04:14 +11:00
+++ 1.10/ndb/src/common/util/SocketClient.cpp	2007-01-23 17:06:32 +11:00
@@ -26,6 +26,7 @@
   m_port= port;
   m_server_name= server_name ? strdup(server_name) : 0;
   m_sockfd= NDB_INVALID_SOCKET;
+  m_connect_timeout_sec= 0;
 }
 
 SocketClient::~SocketClient()
@@ -58,7 +59,7 @@
   if (m_sockfd == NDB_INVALID_SOCKET) {
     return false;
   }
-  
+
   DBUG_PRINT("info",("NDB_SOCKET: %d", m_sockfd));
 
   return true;
@@ -104,6 +105,13 @@
 NDB_SOCKET_TYPE
 SocketClient::connect(const char *toaddress, unsigned short toport)
 {
+  fd_set rset, wset;
+  struct timeval tval;
+  int r;
+  bool use_timeout;
+  socklen_t len;
+  int flags;
+
   if (m_sockfd == NDB_INVALID_SOCKET)
   {
     if (!init()) {
@@ -127,13 +135,57 @@
     if (Ndb_getInAddr(&m_servaddr.sin_addr, m_server_name))
       return NDB_INVALID_SOCKET;
   }
-  
-  const int r = ::connect(m_sockfd, (struct sockaddr*) &m_servaddr, sizeof(m_servaddr));
-  if (r == -1) {
+
+  flags= fcntl(m_sockfd, F_GETFL, 0);
+  fcntl(m_sockfd, F_SETFL, flags | O_NONBLOCK);
+
+  r= ::connect(m_sockfd, (struct sockaddr*) &m_servaddr, sizeof(m_servaddr));
+
+  if (r == 0)
+    goto done; // connected immediately.
+
+  if (r < 0 && (errno != EINPROGRESS)) {
+    NDB_CLOSE_SOCKET(m_sockfd);
+    m_sockfd= NDB_INVALID_SOCKET;
+    return NDB_INVALID_SOCKET;
+  }
+
+  FD_ZERO(&rset);
+  FD_SET(m_sockfd, &rset);
+  wset= rset;
+  tval.tv_sec= m_connect_timeout_sec;
+  tval.tv_usec= 0;
+  use_timeout= m_connect_timeout_sec;
+
+  if ((r= select(m_sockfd+1, &rset, &wset, NULL,
+                 use_timeout? &tval : NULL)) == 0)
+  {
     NDB_CLOSE_SOCKET(m_sockfd);
     m_sockfd= NDB_INVALID_SOCKET;
     return NDB_INVALID_SOCKET;
   }
+
+  if (FD_ISSET(m_sockfd, &rset) || FD_ISSET(m_sockfd, &wset))
+  {
+    len= sizeof(r);
+    if (getsockopt(m_sockfd, SOL_SOCKET, SO_ERROR, &r, &len) < 0)
+    {
+      // Solaris got an error... different than others
+      NDB_CLOSE_SOCKET(m_sockfd);
+      m_sockfd= NDB_INVALID_SOCKET;
+      return NDB_INVALID_SOCKET;
+    }
+  }
+  else
+  {
+    // select error, probably m_sockfd not set.
+    NDB_CLOSE_SOCKET(m_sockfd);
+    m_sockfd= NDB_INVALID_SOCKET;
+    return NDB_INVALID_SOCKET;
+  }
+
+done:
+  fcntl(m_sockfd, F_SETFL, flags);
 
   if (m_auth) {
     if (!m_auth->client_authenticate(m_sockfd))
Thread
bk commit into 5.0 tree (stewart:1.2367) BUG#25487Stewart Smith23 Jan