MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:jonas Date:October 10 2006 9:00am
Subject:bk commit into 5.1 tree (jonas:1.2060) BUG#13987
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of jonas. When jonas 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, 2006-10-10 11:00:20+02:00, jonas@stripped +7 -0
  ndb - bug#13987
    recommit in mysql-5.1-wl2325-5.0

  storage/ndb/include/mgmapi/mgmapi.h@stripped, 2006-10-10 11:00:18+02:00, jonas@stripped +13 -0
    fix bug in error handling in mgmprotocol

  storage/ndb/include/util/InputStream.hpp@stripped, 2006-10-10 11:00:18+02:00, jonas@stripped +1 -0
    fix bug in error handling in mgmprotocol

  storage/ndb/src/common/util/InputStream.cpp@stripped, 2006-10-10 11:00:18+02:00, jonas@stripped +24 -15
    fix bug in error handling in mgmprotocol

  storage/ndb/src/common/util/Parser.cpp@stripped, 2006-10-10 11:00:18+02:00, jonas@stripped +20 -15
    fix bug in error handling in mgmprotocol

  storage/ndb/src/common/util/socket_io.cpp@stripped, 2006-10-10 11:00:18+02:00, jonas@stripped +39 -31
    fix bug in error handling in mgmprotocol

  storage/ndb/src/mgmapi/mgmapi.cpp@stripped, 2006-10-10 11:00:18+02:00, jonas@stripped +14 -7
    fix bug in error handling in mgmprotocol

  storage/ndb/test/ndbapi/testMgm.cpp@stripped, 2006-10-10 11:00:19+02:00, jonas@stripped +27 -0
    fix bug in error handling in mgmprotocol

# 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:	jonas
# Host:	perch.ndb.mysql.com
# Root:	/home/jonas/src/mysql-5.1-wl2325-5.0

--- 1.50/storage/ndb/include/mgmapi/mgmapi.h	2006-10-10 11:00:23 +02:00
+++ 1.51/storage/ndb/include/mgmapi/mgmapi.h	2006-10-10 11:00:23 +02:00
@@ -1000,6 +1000,19 @@
 
 
   /**
+   * ndb_mgm_get_fd
+   *
+   * get the file descriptor of the handle.
+   * INTERNAL ONLY.
+   * USE FOR TESTING. OTHER USES ARE NOT A GOOD IDEA.
+   *
+   * @param  handle NDB management handle
+   * @return handle->socket
+   *
+   */
+  int ndb_mgm_get_fd(NdbMgmHandle handle);
+
+  /**
    * Get the node id of the mgm server we're connected to
    */
   Uint32 ndb_mgm_get_mgmd_nodeid(NdbMgmHandle handle);

--- 1.4/storage/ndb/include/util/InputStream.hpp	2006-10-10 11:00:23 +02:00
+++ 1.5/storage/ndb/include/util/InputStream.hpp	2006-10-10 11:00:23 +02:00
@@ -40,6 +40,7 @@
 class SocketInputStream : public InputStream {
   NDB_SOCKET_TYPE m_socket;
   unsigned m_timeout;
+  bool m_startover;
 public:
   SocketInputStream(NDB_SOCKET_TYPE socket, unsigned readTimeout = 1000);
   char* gets(char * buf, int bufLen);

--- 1.4/storage/ndb/src/common/util/InputStream.cpp	2006-10-10 11:00:23 +02:00
+++ 1.5/storage/ndb/src/common/util/InputStream.cpp	2006-10-10 11:00:23 +02:00
@@ -36,26 +36,35 @@
 
 SocketInputStream::SocketInputStream(NDB_SOCKET_TYPE socket, 
 				     unsigned readTimeout) 
-  : m_socket(socket) { 
-  m_timeout = readTimeout; 
+  : m_socket(socket) {
+  m_startover= true;
+  m_timeout = readTimeout;
 }
 
-char* 
+char*
 SocketInputStream::gets(char * buf, int bufLen) {
-  buf[0] = 77;
   assert(bufLen >= 2);
-  int res = readln_socket(m_socket, m_timeout, buf, bufLen - 1);
+  int offset= 0;
+  if(m_startover)
+  {
+    buf[0]= '\0';
+    m_startover= false;
+  }
+  else
+    offset= strlen(buf);
+
+  int res = readln_socket(m_socket, m_timeout, buf+offset, bufLen-offset);
+
+  if(res == 0)
+  {
+    buf[0]=0;
+    return buf;
+  }
+
+  m_startover= true;
+
   if(res == -1)
     return 0;
-  if(res == 0 && buf[0] == 77){ // select return 0
-    buf[0] = 0;
-  } else if(res == 0 && buf[0] == 0){ // only newline
-    buf[0] = '\n';
-    buf[1] = 0;
-  } else {
-    int len = strlen(buf);
-    buf[len + 1] = '\0';
-    buf[len] = '\n';
-  }
+
   return buf;
 }

--- 1.9/storage/ndb/src/common/util/Parser.cpp	2006-10-10 11:00:23 +02:00
+++ 1.10/storage/ndb/src/common/util/Parser.cpp	2006-10-10 11:00:23 +02:00
@@ -149,21 +149,26 @@
   bool ownStop = false;
   if(stop == 0)
     stop = &ownStop;
-  
+
   ctx->m_aliasUsed.clear();
-  
+
   const unsigned sz = sizeof(ctx->m_tokenBuffer);
   ctx->m_currentToken = input.gets(ctx->m_tokenBuffer, sz);
   if(Eof(ctx->m_currentToken)){
     ctx->m_status = Parser<Dummy>::Eof;
     DBUG_RETURN(false);
   }
-  
-  if(ctx->m_currentToken[0] == 0){
+
+  int last= strlen(ctx->m_currentToken);
+  if(last>0)
+    last--;
+
+  if(ctx->m_currentToken[last] !='\n'){
     ctx->m_status = Parser<Dummy>::NoLine;
+    ctx->m_tokenBuffer[0]= '\0';
     DBUG_RETURN(false);
   }
-  
+
   if(Empty(ctx->m_currentToken)){
     ctx->m_status = Parser<Dummy>::EmptyLine;
     DBUG_RETURN(false);
@@ -175,14 +180,14 @@
     ctx->m_status = Parser<Dummy>::UnknownCommand;
     DBUG_RETURN(false);
   }
-  
+
   Properties * p = new Properties();
-  
+
   bool invalidArgument = false;
   ctx->m_currentToken = input.gets(ctx->m_tokenBuffer, sz);
-  
-  while((! * stop) && 
-	!Eof(ctx->m_currentToken) && 
+
+  while((! * stop) &&
+	!Eof(ctx->m_currentToken) &&
 	!Empty(ctx->m_currentToken)){
     if(ctx->m_currentToken[0] != 0){
       trim(ctx->m_currentToken);
@@ -194,7 +199,7 @@
     }
     ctx->m_currentToken = input.gets(ctx->m_tokenBuffer, sz);
   }
-  
+
   if(invalidArgument){
     char buf[sz];
     char * tmp;
@@ -205,13 +210,13 @@
     }
     DBUG_RETURN(false);
   }
-  
+
   if(* stop){
     delete p;
     ctx->m_status = Parser<Dummy>::ExternalStop;
     DBUG_RETURN(false);
   }
-  
+
   if(!checkMandatory(ctx, p)){
     ctx->m_status = Parser<Dummy>::MissingMandatoryArgument;
     delete p;
@@ -227,9 +232,9 @@
     tmp.put("name", alias->name);
     tmp.put("realName", alias->realName);
     p->put("$ALIAS", i, &tmp);
-  }    
+  }
   p->put("$ALIAS", ctx->m_aliasUsed.size());
-  
+
   ctx->m_status = Parser<Dummy>::Ok;
   * pDst = p;
   DBUG_RETURN(true);

--- 1.8/storage/ndb/src/common/util/socket_io.cpp	2006-10-10 11:00:23 +02:00
+++ 1.9/storage/ndb/src/common/util/socket_io.cpp	2006-10-10 11:00:23 +02:00
@@ -48,58 +48,66 @@
 
 extern "C"
 int
-readln_socket(NDB_SOCKET_TYPE socket, int timeout_millis, 
+readln_socket(NDB_SOCKET_TYPE socket, int timeout_millis,
 	      char * buf, int buflen){
   if(buflen <= 1)
     return 0;
 
+  int sock_flags= fcntl(socket, F_GETFL);
+  if(fcntl(socket, F_SETFL, sock_flags | O_NONBLOCK) == -1)
+    return -1;
+
   fd_set readset;
   FD_ZERO(&readset);
   FD_SET(socket, &readset);
-  
+
   struct timeval timeout;
   timeout.tv_sec  = (timeout_millis / 1000);
   timeout.tv_usec = (timeout_millis % 1000) * 1000;
 
   const int selectRes = select(socket + 1, &readset, 0, 0, &timeout);
-  if(selectRes == 0)
+  if(selectRes == 0){
     return 0;
-  
+  }
+
   if(selectRes == -1){
+    fcntl(socket, F_SETFL, sock_flags);
     return -1;
   }
-  
-  int pos = 0; buf[pos] = 0;
-  while(true){
-    const int t = recv(socket, &buf[pos], 1, 0);
-    if(t != 1){
-      return -1;
-    }
-    if(buf[pos] == '\n'){
-      buf[pos] = 0;
 
-      if(pos > 0 && buf[pos-1] == '\r'){
-	pos--;
-	buf[pos] = 0;
+  const int t = recv(socket, buf, buflen, MSG_PEEK);
+
+  if(t < 1)
+  {
+    fcntl(socket, F_SETFL, sock_flags);
+    return -1;
+  }
+
+  for(int i=0; i< t;i++)
+  {
+    if(buf[i] == '\n'){
+      int r= recv(socket, buf, i+1, 0);
+      buf[i+1]= 0;
+      if(r < 1) {
+        fcntl(socket, F_SETFL, sock_flags);
+        return -1;
       }
 
-      return pos;
-    }
-    pos++;
-    if(pos == (buflen - 1)){
-      buf[pos] = 0;
-      return buflen;
-    }
-    
-    FD_ZERO(&readset);
-    FD_SET(socket, &readset);
-    timeout.tv_sec  = (timeout_millis / 1000);
-    timeout.tv_usec = (timeout_millis % 1000) * 1000;
-    const int selectRes = select(socket + 1, &readset, 0, 0, &timeout);
-    if(selectRes != 1){
-      return -1;
+      if(i > 0 && buf[i-1] == '\r'){
+        buf[i-1] = '\n';
+        buf[i]= '\0';
+      }
+
+      fcntl(socket, F_SETFL, sock_flags);
+      return r;
     }
   }
+
+  int r= recv(socket, buf, t, 0);
+  if(r>=0)
+    buf[r] = 0;
+  fcntl(socket, F_SETFL, sock_flags);
+  return r;
 }
 
 extern "C"

--- 1.61/storage/ndb/src/mgmapi/mgmapi.cpp	2006-10-10 11:00:23 +02:00
+++ 1.62/storage/ndb/src/mgmapi/mgmapi.cpp	2006-10-10 11:00:23 +02:00
@@ -485,6 +485,18 @@
 }
 
 /**
+ * Only used for low level testing
+ * Never to be used by end user.
+ * Or anybody who doesn't know exactly what they're doing.
+ */
+extern "C"
+int
+ndb_mgm_get_fd(NdbMgmHandle handle)
+{
+  return handle->socket;
+}
+
+/**
  * Disconnect from a mgm server
  */
 extern "C"
@@ -670,17 +682,13 @@
 
   char buf[1024];
   in.gets(buf, sizeof(buf));
-  if(buf[strlen(buf)-1] == '\n')
-    buf[strlen(buf)-1] = '\0';
 
-  if(strcmp("node status", buf) != 0) {
+  if(strcmp("node status\n", buf) != 0) {
     SET_ERROR(handle, NDB_MGM_ILLEGAL_NODE_STATUS, buf);
     return NULL;
   }
 
   in.gets(buf, sizeof(buf));
-  if(buf[strlen(buf)-1] == '\n')
-    buf[strlen(buf)-1] = '\0';
   
   BaseString tmp(buf);
   Vector<BaseString> split;
@@ -688,7 +696,7 @@
   if(split.size() != 2){
     return NULL;
   }
- 
+
   if(!(split[0].trim() == "nodes")){
     return NULL;
   }
@@ -2127,7 +2135,6 @@
   SocketOutputStream out(handle->socket);
   SocketInputStream in(handle->socket, handle->read_timeout);
   char buf[32];
-
   if (out.println("check connection"))
     goto ndb_mgm_check_connection_error;
 

--- 1.5/storage/ndb/test/ndbapi/testMgm.cpp	2006-10-10 11:00:23 +02:00
+++ 1.6/storage/ndb/test/ndbapi/testMgm.cpp	2006-10-10 11:00:23 +02:00
@@ -21,6 +21,8 @@
 #include <NdbRestarter.hpp>
 #include <Vector.hpp>
 #include <random.h>
+#include <mgmapi.h>
+#include <mgmapi_debug.h>
 
 int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
 
@@ -167,6 +169,26 @@
   return result;
 }
 
+int runTestApiSession(NDBT_Context* ctx, NDBT_Step* step)
+{
+  char *mgm= ctx->getRemoteMgm();
+
+  NdbMgmHandle h;
+  h= ndb_mgm_create_handle();
+  ndb_mgm_set_connectstring(h, mgm);
+  ndb_mgm_connect(h,0,0,0);
+  int s= ndb_mgm_get_fd(h);
+  write(s,"get",3);
+  ndb_mgm_disconnect(h);
+  ndb_mgm_destroy_handle(&h);
+  /** NOTE: WE CANNOT REALLY TEST ANYTHING in 5.0
+   *
+   * a more conservative patch for 5.0, full get and list
+   * sessions in 5.1.
+   *
+   * This is kept so that we can at least manually test easily
+   */
+}
 
 
 NDBT_TESTSUITE(testMgm);
@@ -174,6 +196,11 @@
 	 "Test single user mode"){
   INITIALIZER(runTestSingleUserMode);
   FINALIZER(runClearTable);
+}
+TESTCASE("ApiSessionFailure",
+	 "Test failures in MGMAPI session"){
+  INITIALIZER(runTestApiSession);
+
 }
 NDBT_TESTSUITE_END(testMgm);
 
Thread
bk commit into 5.1 tree (jonas:1.2060) BUG#13987jonas10 Oct