List:Commits« Previous MessageNext Message »
From:Pekka Nousiainen Date:September 19 2011 6:20pm
Subject:bzr push into mysql-5.1-telco-7.0 branch (pekka.nousiainen:4534 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
 4535 Jonas Oreland	2011-09-19
      ndb index stat - use variable together with condition-variable, so that pthread_signal "doesn't get lost"

    modified:
      sql/ha_ndb_index_stat.cc
 4534 Pekka Nousiainen	2011-09-19
      wl#4124 z04_ms4.diff
      4-test-ndb-index-stat-partitions

    added:
      mysql-test/suite/ndb/r/ndb_index_stat_partitions.result
      mysql-test/suite/ndb/t/ndb_index_stat_partitions.test
=== modified file 'sql/ha_ndb_index_stat.cc'
--- a/sql/ha_ndb_index_stat.cc	2011-09-02 06:43:38 +0000
+++ b/sql/ha_ndb_index_stat.cc	2011-09-19 09:26:42 +0000
@@ -24,6 +24,9 @@
 #include <mysql/plugin.h>
 #include <ctype.h>
 
+// Do we have waiter...
+static bool ndb_index_stat_waiter= false;
+
 // copied from ha_ndbcluster_binlog.h
 
 extern handlerton *ndbcluster_hton;
@@ -1845,7 +1848,7 @@ ndb_index_stat_thread_func(void *arg __a
   for (;;)
   {
     pthread_mutex_lock(&LOCK_ndb_index_stat_thread);
-    if (!ndbcluster_terminating) {
+    if (!ndbcluster_terminating && ndb_index_stat_waiter == false) {
       int ret= pthread_cond_timedwait(&COND_ndb_index_stat_thread,
                                       &LOCK_ndb_index_stat_thread,
                                       &abstime);
@@ -1855,6 +1858,7 @@ ndb_index_stat_thread_func(void *arg __a
     }
     if (ndbcluster_terminating) /* Shutting down server */
       goto ndb_index_stat_thread_end;
+    ndb_index_stat_waiter= false;
     pthread_mutex_unlock(&LOCK_ndb_index_stat_thread);
 
     /* const bool enable_ok_new= THDVAR(NULL, index_stat_enable); */
@@ -2002,6 +2006,7 @@ ndb_index_stat_wait(Ndb_index_stat *st,
     DBUG_PRINT("index_stat", ("st %s wait count:%u",
                               st->id, ++count));
     pthread_mutex_lock(&LOCK_ndb_index_stat_thread);
+    ndb_index_stat_waiter= true;
     pthread_cond_signal(&COND_ndb_index_stat_thread);
     pthread_mutex_unlock(&LOCK_ndb_index_stat_thread);
     set_timespec(abstime, 1);

=== 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/mgmsrv/MgmtSrvr.cpp'
--- a/storage/ndb/src/mgmsrv/MgmtSrvr.cpp	2011-09-14 12:22:49 +0000
+++ b/storage/ndb/src/mgmsrv/MgmtSrvr.cpp	2011-09-19 14:10:19 +0000
@@ -735,12 +735,6 @@ MgmtSrvr::get_packed_config_from_node(No
     DBUG_RETURN(false);
   }
 
-  if (nodeId == getOwnNodeId())
-  {
-    DBUG_RETURN(m_config_manager->get_packed_config(NDB_MGM_NODE_TYPE_API,
-                                                    &buf64, error));
-  }
-
   if (getNodeType(nodeId) != NDB_MGM_NODE_TYPE_NDB)
   {
     error.assfmt("Node %d is not a data node. ", nodeId);

=== 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/testMgm.cpp'
--- a/storage/ndb/test/ndbapi/testMgm.cpp	2011-09-13 08:58:27 +0000
+++ b/storage/ndb/test/ndbapi/testMgm.cpp	2011-09-19 14:10:19 +0000
@@ -811,13 +811,16 @@ check_get_config_illegal_node(NdbMgmd& m
 static bool
 check_get_config_wrong_type(NdbMgmd& mgmd)
 {
+  int myChoice = myRandom48(2);
+  ndb_mgm_node_type randomAllowedType = (myChoice) ?
+                                        NDB_MGM_NODE_TYPE_API :
+                                        NDB_MGM_NODE_TYPE_MGM;
   int nodeId = 0;
-
-  if (get_nodeid_of_type(mgmd, NDB_MGM_NODE_TYPE_API, &nodeId))
+  if (get_nodeid_of_type(mgmd, randomAllowedType, &nodeId))
   {
     return get_config_from_illegal_node(mgmd, nodeId);
   }
-  // No API nodes found.
+  // No API/MGM nodes found.
   return true;
 }
 
@@ -842,15 +845,10 @@ int runGetConfigFromNode(NDBT_Context* c
   int loops= ctx->getNumLoops();
   for (int l= 0; l < loops; l++)
   {
-    /* Get config from a node of type:
-     * NDB_MGM_NODE_TYPE_NDB or NDB_MGM_NODE_TYPE_MGM
+    /* Get config from a node of type: * NDB_MGM_NODE_TYPE_NDB
      */
-    int myChoice = myRandom48(2);
-    ndb_mgm_node_type randomAllowedType = (myChoice) ?
-                                          NDB_MGM_NODE_TYPE_NDB :
-                                          NDB_MGM_NODE_TYPE_MGM;
     int nodeId = 0;
-    if (get_nodeid_of_type(mgmd, randomAllowedType, &nodeId))
+    if (get_nodeid_of_type(mgmd,  NDB_MGM_NODE_TYPE_NDB, &nodeId))
     {
       struct ndb_mgm_configuration* conf =
         ndb_mgm_get_configuration_from_node(mgmd.handle(), nodeId);

=== 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 (pekka.nousiainen:4534 to 4537) Pekka Nousiainen20 Sep