List:Commits« Previous MessageNext Message »
From:magnus.blaudd Date:September 19 2011 2:25pm
Subject:bzr push into mysql-5.1-telco-7.0 branch (magnus.blaudd:4536 to 4537)
View as plain text  
 4537 magnus.blaudd@stripped	2011-09-19 [merge]
      Merge

    modified:
      storage/ndb/include/mgmcommon/ConfigRetriever.hpp
      storage/ndb/src/common/mgmcommon/ConfigRetriever.cpp
      storage/ndb/src/mgmapi/mgmapi.cpp
      storage/ndb/src/ndbapi/ndb_cluster_connection.cpp
      storage/ndb/test/ndbapi/testNdbApi.cpp
 4536 Maitrayi Sabaratnam	2011-09-19
      Bug 11766870 - 60097: NDB_CONFIG TO DUMP CONFIG VERSION FOR DATA NODES-Testfix

    modified:
      storage/ndb/src/mgmsrv/MgmtSrvr.cpp
      storage/ndb/test/ndbapi/testMgm.cpp
=== modified file 'storage/ndb/include/mgmcommon/ConfigRetriever.hpp'
--- a/storage/ndb/include/mgmcommon/ConfigRetriever.hpp	2011-06-30 15:59:25 +0000
+++ b/storage/ndb/include/mgmcommon/ConfigRetriever.hpp	2011-09-19 12:08:00 +0000
@@ -59,6 +59,8 @@ public:
    * @return Node id of this node (as stated in local config or connectString)
    */
   Uint32 allocNodeId(int no_retries, int retry_delay_in_seconds);
+  Uint32 allocNodeId(int no_retries, int retry_delay_in_seconds,
+                     int verbose, int& error);
 
   int setNodeId(Uint32 nodeid);
 

=== modified file 'storage/ndb/src/common/mgmcommon/ConfigRetriever.cpp'
--- a/storage/ndb/src/common/mgmcommon/ConfigRetriever.cpp	2011-07-04 13:37:56 +0000
+++ b/storage/ndb/src/common/mgmcommon/ConfigRetriever.cpp	2011-09-19 12:08:00 +0000
@@ -366,34 +366,48 @@ ConfigRetriever::setNodeId(Uint32 nodeid
 }
 
 Uint32
-ConfigRetriever::allocNodeId(int no_retries, int retry_delay_in_seconds)
+ConfigRetriever::allocNodeId(int no_retries, int retry_delay_in_seconds,
+                             int verbose, int& error)
 {
-  int res;
-  if(m_handle != 0)
+  if (!m_handle)
   {
-    while (1)
-    {
-      if(!ndb_mgm_is_connected(m_handle))
-	if(!ndb_mgm_connect(m_handle, 0, 0, 0))
-	  goto next;
+    setError(CR_ERROR, "management server handle not initialized");
+    return 0;  // Error
+  }
 
-      res= ndb_mgm_alloc_nodeid(m_handle, m_version, m_node_type,
-                                no_retries == 0 /* only log last retry */);
-      if(res >= 0)
-	return (Uint32)res;
+  while (1)
+  {
+    if (ndb_mgm_is_connected(m_handle) == 1 ||
+        ndb_mgm_connect(m_handle, 0, 0, verbose) == 0)
+    {
+      int res =
+        ndb_mgm_alloc_nodeid(m_handle, m_version, m_node_type,
+                             no_retries == 0 /* only log last retry */);
+      if (res >= 0)
+        return (Uint32)res; // Sucess!!
+    }
 
-  next:
-      int error = ndb_mgm_get_latest_error(m_handle);
-      if (no_retries == 0 || error == NDB_MGM_ALLOCID_CONFIG_MISMATCH)
-	break;
-      no_retries--;
-      NdbSleep_SecSleep(retry_delay_in_seconds);
+    error = ndb_mgm_get_latest_error(m_handle);
+    if (no_retries == 0 ||                        /* No more retries */
+        error == NDB_MGM_ALLOCID_CONFIG_MISMATCH) /* Fatal error */
+    {
+      break;
     }
-    BaseString tmp(ndb_mgm_get_latest_error_msg(m_handle));
-    tmp.append(" : ");
-    tmp.append(ndb_mgm_get_latest_error_desc(m_handle));
-    setError(CR_ERROR, tmp.c_str());
-  } else
-    setError(CR_ERROR, "management server handle not initialized");    
-  return 0;
+    no_retries--;
+    NdbSleep_SecSleep(retry_delay_in_seconds);
+  }
+  BaseString tmp;
+  tmp.assfmt("%s: %s",
+             ndb_mgm_get_latest_error_msg(m_handle),
+             ndb_mgm_get_latest_error_desc(m_handle));
+  setError(CR_ERROR, tmp.c_str());
+  return 0; // Error
+}
+
+
+Uint32
+ConfigRetriever::allocNodeId(int no_retries, int retry_delay_in_seconds)
+{
+  int error;
+  return allocNodeId(no_retries, retry_delay_in_seconds, 0, error);
 }

=== modified file 'storage/ndb/src/mgmapi/mgmapi.cpp'
--- a/storage/ndb/src/mgmapi/mgmapi.cpp	2011-07-04 13:37:56 +0000
+++ b/storage/ndb/src/mgmapi/mgmapi.cpp	2011-09-19 11:59:09 +0000
@@ -2685,6 +2685,7 @@ ndb_mgm_alloc_nodeid(NdbMgmHandle handle
 {
   DBUG_ENTER("ndb_mgm_alloc_nodeid");
   CHECK_HANDLE(handle, 0);
+  SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_alloc_nodeid");
   CHECK_CONNECTED(handle, 0);
   union { long l; char c[sizeof(long)]; } endian_check;
 

=== modified file 'storage/ndb/src/ndbapi/ndb_cluster_connection.cpp'
--- a/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp	2011-09-13 09:10:52 +0000
+++ b/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp	2011-09-19 12:08:00 +0000
@@ -822,22 +822,38 @@ int Ndb_cluster_connection_impl::connect
       DBUG_PRINT("exit", ("no m_config_retriever, ret: -1"));
       DBUG_RETURN(-1);
     }
-    if (m_config_retriever->do_connect(no_retries,
-                                       retry_delay_in_seconds,
-                                       verbose))
+
+    // the allocNodeId function will connect if not connected
+    int alloc_error;
+    Uint32 nodeId = m_config_retriever->allocNodeId(no_retries,
+                                                   retry_delay_in_seconds,
+                                                   verbose, alloc_error);
+    if (!nodeId)
     {
-      char buf[1024];
-      m_latest_error = 1;
-      m_latest_error_msg.assfmt("Connect using '%s' timed out",
-                                get_connectstring(buf, sizeof(buf)));
-      DBUG_PRINT("exit", ("mgmt server not up yet, ret: 1"));
-      DBUG_RETURN(1); // mgmt server not up yet
-    }
+      // Failed to allocate nodeid from mgmt server, find out
+      // the cause and set proper error message
+
+      if (!m_config_retriever->is_connected())
+      {
+        // Could not connect to mgmt server
+        m_latest_error = alloc_error;
+        m_latest_error_msg.assfmt("%s", m_config_retriever->getErrorString());
+        DBUG_RETURN(1); // Recoverable error
+      }
 
-    Uint32 nodeId = m_config_retriever->allocNodeId(10/*retries*/,
-                                                    3/*delay*/);
-    if(nodeId == 0)
+      if (alloc_error == NDB_MGM_ALLOCID_ERROR)
+      {
+        // A nodeid for this node was found in config, but it was not
+        // free right now. Retry later and it might be free.
+        m_latest_error = alloc_error;
+        m_latest_error_msg.assfmt("%s", m_config_retriever->getErrorString());
+        DBUG_RETURN(1); // Recoverable error
+      }
+
+      // Fatal error, use default error
       break;
+    }
+
     ndb_mgm_configuration * props = m_config_retriever->getConfig(nodeId);
     if(props == 0)
       break;

=== modified file 'storage/ndb/test/ndbapi/testNdbApi.cpp'
--- a/storage/ndb/test/ndbapi/testNdbApi.cpp	2011-09-13 09:00:25 +0000
+++ b/storage/ndb/test/ndbapi/testNdbApi.cpp	2011-09-19 12:08:00 +0000
@@ -4705,6 +4705,113 @@ int runNdbClusterConnect(NDBT_Context* c
 }
 
 
+static bool
+check_connect_no_such_host()
+{
+  for (int i = 0; i < 3; i++)
+  {
+    const char* no_such_host = "no_such_host:1186";
+    Ndb_cluster_connection con(no_such_host);
+
+    const int verbose = 1;
+    int res = con.connect(i, i, verbose);
+    if (res != 1)
+    {
+      g_err << "Ndb_cluster_connection.connect(" << i << "," << i
+            << ", 1) to '" << no_such_host << "' returned " << res
+            << " instead of expected 1" << endl;
+      return false;
+    }
+    g_info << "Ndb_cluster_connection.connect(" << i << "," << i
+           << ", 1) to '" << no_such_host << "' returned " << res
+           << " and message '" << con.get_latest_error_msg() << "'"<< endl;
+  }
+  return true;
+}
+
+
+static bool
+check_connect_until_no_more_nodeid(const char* constr)
+{
+  bool result = true;
+  Vector<Ndb_cluster_connection*> connections;
+  while(true)
+  {
+    Ndb_cluster_connection* con = new Ndb_cluster_connection(constr);
+    if (!con)
+    {
+      g_err << "Failed to create another Ndb_cluster_connection" << endl;
+      result = false;
+      break;
+    }
+    connections.push_back(con);
+    g_info << "connections: " << connections.size() << endl;
+
+    const int verbose = 1;
+    int res = con->connect(0, 0, verbose);
+    if (res != 0)
+    {
+      g_info << "Ndb_cluster_connection.connect(0,0,1) returned " << res
+             << " and error message set to : '" << con->get_latest_error_msg()
+             << "'" << endl;
+
+      if (res != 1)
+      {
+        // The error returned should be 1
+        g_err << "Unexpected return code " << res << " returned" << endl;
+        result = false;
+      }
+      else if (strstr(con->get_latest_error_msg(),
+                      "No free node id found for mysqld(API)") == NULL)
+      {
+        // The error message should end with "No free node id
+        // found for mysqld(API)" since this host is configured in the config
+        g_err << "Unexpected error message " << con->get_latest_error_msg()
+              << " returned" << endl;
+        result = false;
+      }
+      else
+      {
+        ndbout << "check_connect_until_no_more_nodeid OK!" << endl;
+      }
+      break;
+    }
+  }
+
+  while(connections.size())
+  {
+    Ndb_cluster_connection* con = connections[0];
+    g_info << "releasing connection, size: " << connections.size() << endl;
+    delete con;
+    connections.erase(0);
+  }
+  assert(connections.size() == 0);
+
+  return result;
+}
+
+
+int runNdbClusterConnectionConnect(NDBT_Context* ctx, NDBT_Step* step)
+{
+  // Get connectstring from main connection
+  char constr[256];
+  if(!ctx->m_cluster_connection.get_connectstring(constr,
+                                                  sizeof(constr)))
+  {
+    g_err << "Too short buffer for connectstring" << endl;
+    return NDBT_FAILED;
+  }
+
+  if (!check_connect_no_such_host() ||
+      !check_connect_until_no_more_nodeid(constr))
+  {
+    return NDBT_FAILED;
+  }
+
+  return NDBT_OK;
+}
+
+
 NDBT_TESTSUITE(testNdbApi);
 TESTCASE("MaxNdb", 
 	 "Create Ndb objects until no more can be created\n"){ 
@@ -4928,6 +5035,11 @@ TESTCASE("NdbClusterConnect",
   INITIALIZER(runNdbClusterConnectInit);
   STEPS(runNdbClusterConnect, MAX_NODES);
 }
+TESTCASE("NdbClusterConnectionConnect",
+         "Test Ndb_cluster_connection::connect()")
+{
+  INITIALIZER(runNdbClusterConnectionConnect);
+}
 
 NDBT_TESTSUITE_END(testNdbApi);
 
@@ -4940,3 +5052,4 @@ int main(int argc, const char** argv){
 
 template class Vector<Ndb*>;
 template class Vector<NdbConnection*>;
+template class Vector<Ndb_cluster_connection*>;

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.1-telco-7.0 branch (magnus.blaudd:4536 to 4537) magnus.blaudd20 Sep