List:Commits« Previous MessageNext Message »
From:magnus.blaudd Date:November 7 2011 7:14pm
Subject:bzr push into mysql-5.5-cluster branch (magnus.blaudd:3629 to 3632)
View as plain text  
 3632 magnus.blaudd@stripped	2011-11-07
      ndb - add missing new line in ndb_share.cc

    modified:
      sql/ndb_share.cc
 3631 magnus.blaudd@stripped	2011-11-07 [merge]
      Merge in latest ndb schema dist fixes

    modified:
      sql/ha_ndbcluster_binlog.cc
 3630 magnus.blaudd@stripped	2011-11-07 [merge]
      Merge

    modified:
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster_binlog.cc
      sql/ha_ndbcluster_binlog.h
      sql/ndb_schema_dist.cc
      sql/ndb_schema_dist.h
      sql/ndb_share.cc
      sql/ndb_share.h
 3629 Jonas Oreland	2011-11-07 [merge]
      ndb - merge 71 to 72

    added:
      mysql-test/suite/ndb/r/ndb_multi_update_delete.result
      mysql-test/suite/ndb/t/ndb_multi_update_delete.test
    modified:
      sql/sql_select.cc
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2011-10-31 16:43:45 +0000
+++ b/sql/ha_ndbcluster.cc	2011-11-05 11:35:57 +0000
@@ -10001,13 +10001,13 @@ int ha_ndbcluster::create(const char *na
   
     DBUG_RETURN(HA_ERR_NO_CONNECTION);
 
-  /*
-    Don't allow table creation unless
-    schema distribution table is setup
-    ( unless it is a creation of the schema dist table itself )
-  */
-  if (!ndb_schema_share)
+
+  if (!ndb_schema_dist_is_ready())
   {
+    /*
+      Don't allow table creation unless schema distribution is ready
+      ( unless it is a creation of the schema dist table itself )
+    */
     if (!(strcmp(m_dbname, NDB_REP_DB) == 0 &&
           strcmp(m_tabname, NDB_SCHEMA_TABLE) == 0))
     {
@@ -10534,7 +10534,7 @@ cleanup_failed:
                          get_binlog_full(share));
       int do_event_op= ndb_binlog_running;
 
-      if (!ndb_schema_share &&
+      if (!ndb_schema_dist_is_ready() &&
           strcmp(share->db, NDB_REP_DB) == 0 &&
           strcmp(share->table_name, NDB_SCHEMA_TABLE) == 0)
         do_event_op= 1;
@@ -11089,13 +11089,10 @@ ha_ndbcluster::drop_table_impl(THD *thd,
   NDBDICT *dict= ndb->getDictionary();
   int ndb_table_id= 0;
   int ndb_table_version= 0;
-  /*
-    Don't allow drop table unless
-    schema distribution table is setup
-  */
-  if (!ndb_schema_share)
+
+  if (!ndb_schema_dist_is_ready())
   {
-    DBUG_PRINT("info", ("Schema distribution table not setup"));
+    /* Don't allow drop table unless schema distribution is ready */
     DBUG_RETURN(HA_ERR_NO_CONNECTION);
   }
   /* ndb_share reference temporary */
@@ -11245,15 +11242,10 @@ int ha_ndbcluster::delete_table(const ch
   set_dbname(name);
   set_tabname(name);
 
-  /*
-    Don't allow drop table unless
-    schema distribution table is setup
-  */
-  if (!ndb_schema_share)
+  if (!ndb_schema_dist_is_ready())
   {
-    DBUG_PRINT("info", ("Schema distribution table not setup"));
-    error= HA_ERR_NO_CONNECTION;
-    goto err;
+    /* Don't allow drop table unless schema distribution is ready */
+    DBUG_RETURN(HA_ERR_NO_CONNECTION);
   }
 
   if (check_ndb_connection(thd))
@@ -12100,15 +12092,13 @@ static void ndbcluster_drop_database(han
 {
   THD *thd= current_thd;
   DBUG_ENTER("ndbcluster_drop_database");
-  /*
-    Don't allow drop database unless
-    schema distribution table is setup
-  */
-  if (!ndb_schema_share)
+
+  if (!ndb_schema_dist_is_ready())
   {
-    DBUG_PRINT("info", ("Schema distribution table not setup"));
+    /* Don't allow drop database unless schema distribution is ready */
     DBUG_VOID_RETURN;
   }
+
   ndbcluster_drop_database_impl(thd, path);
   char db[FN_REFLEN];
   ha_ndbcluster::set_dbname(path, db);
@@ -13723,32 +13713,17 @@ NDB_SHARE *ndbcluster_get_share(NDB_SHAR
 }
 
 
-/*
-  Get a share object for key
-
-  Returns share for key, and increases the refcount on the share.
-
-  create_if_not_exists == TRUE:
-    creates share if it does not alreade exist
-    returns 0 only due to out of memory, and then sets my_error
-
-  create_if_not_exists == FALSE:
-    returns 0 if share does not exist
-
-  have_lock == TRUE, pthread_mutex_lock(&ndbcluster_mutex) already taken
-*/
-
+static inline
 NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table,
-                                bool create_if_not_exists,
-                                bool have_lock)
+                                bool create_if_not_exists)
 {
   NDB_SHARE *share;
   uint length= (uint) strlen(key);
   DBUG_ENTER("ndbcluster_get_share");
   DBUG_PRINT("enter", ("key: '%s'", key));
 
-  if (!have_lock)
-    pthread_mutex_lock(&ndbcluster_mutex);
+  safe_mutex_assert_owner(&ndbcluster_mutex);
+
   if (!(share= (NDB_SHARE*) my_hash_search(&ndbcluster_open_tables,
                                            (const uchar*) key,
                                            length)))
@@ -13756,8 +13731,6 @@ NDB_SHARE *ndbcluster_get_share(const ch
     if (!create_if_not_exists)
     {
       DBUG_PRINT("error", ("get_share: %s does not exist", key));
-      if (!have_lock)
-        pthread_mutex_unlock(&ndbcluster_mutex);
       DBUG_RETURN(0);
     }
     if ((share= (NDB_SHARE*) my_malloc(sizeof(*share),
@@ -13779,8 +13752,6 @@ NDB_SHARE *ndbcluster_get_share(const ch
         free_root(&share->mem_root, MYF(0));
         my_free((uchar*) share, 0);
         *root_ptr= old_root;
-        if (!have_lock)
-          pthread_mutex_unlock(&ndbcluster_mutex);
         DBUG_RETURN(0);
       }
       thr_lock_init(&share->lock);
@@ -13796,8 +13767,6 @@ NDB_SHARE *ndbcluster_get_share(const ch
         DBUG_PRINT("error", ("get_share: %s could not init share", key));
         ndbcluster_real_free_share(&share);
         *root_ptr= old_root;
-        if (!have_lock)
-          pthread_mutex_unlock(&ndbcluster_mutex);
         DBUG_RETURN(0);
       }
       *root_ptr= old_root;
@@ -13805,8 +13774,6 @@ NDB_SHARE *ndbcluster_get_share(const ch
     else
     {
       DBUG_PRINT("error", ("get_share: failed to alloc share"));
-      if (!have_lock)
-        pthread_mutex_unlock(&ndbcluster_mutex);
       my_error(ER_OUTOFMEMORY, MYF(0), static_cast<int>(sizeof(*share)));
       DBUG_RETURN(0);
     }
@@ -13817,8 +13784,36 @@ NDB_SHARE *ndbcluster_get_share(const ch
 
   dbug_print_open_tables();
   dbug_print_share("ndbcluster_get_share:", share);
+  DBUG_RETURN(share);
+}
+
+
+/**
+  Get NDB_SHARE for key
+
+  Returns share for key, and increases the refcount on the share.
+
+  @param create_if_not_exists, creates share if it does not already exist
+  @param have_lock, ndbcluster_mutex already locked
+*/
+
+NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table,
+                                bool create_if_not_exists,
+                                bool have_lock)
+{
+  NDB_SHARE *share;
+  DBUG_ENTER("ndbcluster_get_share");
+  DBUG_PRINT("enter", ("key: '%s', create_if_not_exists: %d, have_lock: %d",
+                       key, create_if_not_exists, have_lock));
+
+  if (!have_lock)
+    pthread_mutex_lock(&ndbcluster_mutex);
+
+  share= ndbcluster_get_share(key, table, create_if_not_exists);
+
   if (!have_lock)
     pthread_mutex_unlock(&ndbcluster_mutex);
+
   DBUG_RETURN(share);
 }
 
@@ -13843,25 +13838,8 @@ void ndbcluster_real_free_share(NDB_SHAR
     found= my_hash_delete(&ndbcluster_open_tables, (uchar*) *share) == 0;
   }
   assert(found);
-  thr_lock_delete(&(*share)->lock);
-  pthread_mutex_destroy(&(*share)->mutex);
 
-#ifdef HAVE_NDB_BINLOG
-  if ((*share)->m_cfn_share && (*share)->m_cfn_share->m_ex_tab && g_ndb)
-  {
-    NDBDICT *dict= g_ndb->getDictionary();
-    dict->removeTableGlobal(*(*share)->m_cfn_share->m_ex_tab, 0);
-    (*share)->m_cfn_share->m_ex_tab= 0;
-  }
-#endif
-  (*share)->new_op= 0;
-  if ((*share)->event_data)
-  {
-    delete (*share)->event_data;
-    (*share)->event_data= 0;
-  }
-  free_root(&(*share)->mem_root, MYF(0));
-  my_free((uchar*) *share, MYF(0));
+  NDB_SHARE::destroy(*share);
   *share= 0;
 
   dbug_print_open_tables();

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2011-11-01 09:59:30 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2011-11-07 18:59:32 +0000
@@ -2354,7 +2354,6 @@ class Ndb_schema_event_handler {
     int retries= 100;
     int retry_sleep= 30; /* 30 milliseconds, transaction */
     const NDBCOL *col[SCHEMA_SIZE];
-    unsigned sz[SCHEMA_SIZE];
 
     MY_BITMAP slock;
     uint32 bitbuf[SCHEMA_SLOCK_SIZE/4];
@@ -2374,8 +2373,7 @@ class Ndb_schema_event_handler {
         col[i]= ndbtab->getColumn(i);
         if (i != SCHEMA_QUERY_I)
         {
-          sz[i]= col[i]->getLength();
-          DBUG_ASSERT(sz[i] <= sizeof(tmp_buf));
+          DBUG_ASSERT(col[i]->getLength() <= sizeof(tmp_buf));
         }
       }
     }
@@ -2496,36 +2494,36 @@ class Ndb_schema_event_handler {
   }
 
 
-  bool check_is_ndb_schema_event(const Ndb_event_data* event_data) const
-  {
-    if (!event_data)
-    {
-      // Received event without event data pointer
-      assert(false);
-      return false;
-    }
-
-    NDB_SHARE *share= event_data->share;
-    if (!share)
-    {
-      // Received event where the event_data is not properly initialized
-      assert(false);
-      return false;
-    }
-    assert(event_data->shadow_table);
-    assert(event_data->ndb_value[0]);
-    assert(event_data->ndb_value[1]);
-
-    pthread_mutex_lock(&ndb_schema_share_mutex);
-    if (share != ndb_schema_share)
-    {
-      // Received event from s_ndb not pointing at the ndb_schema_share
-      pthread_mutex_unlock(&ndb_schema_share_mutex);
-      assert(false);
-      return false;
-    }
-    assert(!strncmp(share->db, STRING_WITH_LEN(NDB_REP_DB)));
-    assert(!strncmp(share->table_name, STRING_WITH_LEN(NDB_SCHEMA_TABLE)));
+  bool check_is_ndb_schema_event(const Ndb_event_data* event_data) const
+  {
+    if (!event_data)
+    {
+      // Received event without event data pointer
+      assert(false);
+      return false;
+    }
+
+    NDB_SHARE *share= event_data->share;
+    if (!share)
+    {
+      // Received event where the event_data is not properly initialized
+      assert(false);
+      return false;
+    }
+    assert(event_data->shadow_table);
+    assert(event_data->ndb_value[0]);
+    assert(event_data->ndb_value[1]);
+
+    pthread_mutex_lock(&ndb_schema_share_mutex);
+    if (share != ndb_schema_share)
+    {
+      // Received event from s_ndb not pointing at the ndb_schema_share
+      pthread_mutex_unlock(&ndb_schema_share_mutex);
+      assert(false);
+      return false;
+    }
+    assert(!strncmp(share->db, STRING_WITH_LEN(NDB_REP_DB)));
+    assert(!strncmp(share->table_name, STRING_WITH_LEN(NDB_SCHEMA_TABLE)));
     pthread_mutex_unlock(&ndb_schema_share_mutex);
     return true;
   }
@@ -2555,6 +2553,34 @@ class Ndb_schema_event_handler {
   }
 
 
+  void ndbapi_invalidate_table(const char* db_name, const char* table_name)
+  {
+    Thd_ndb *thd_ndb= get_thd_ndb(m_thd);
+    Ndb *ndb= thd_ndb->ndb;
+
+    ndb->setDatabaseName(db_name);
+    Ndb_table_guard ndbtab_g(ndb->getDictionary(), table_name);
+    ndbtab_g.invalidate();
+  }
+
+
+  void mysqld_close_cached_table(const char* db_name, const char* table_name)
+  {
+     // Just mark table as "need reopen"
+    const bool wait_for_refresh = false;
+    // Not waiting -> no timeout needed
+    const ulong timeout = 0;
+
+    TABLE_LIST table_list;
+    memset(&table_list, 0, sizeof(table_list));
+    table_list.db= (char*)db_name;
+    table_list.alias= table_list.table_name= (char*)table_name;
+
+    close_cached_tables(m_thd, &table_list,
+                        wait_for_refresh, timeout);
+  }
+
+
   bool
   check_if_local_tables_in_db(const char *dbname) const
   {
@@ -2760,16 +2786,8 @@ class Ndb_schema_event_handler {
           // invalidation already handled by binlog thread
           if (!share || !share->op)
           {
-            {
-              ndb->setDatabaseName(schema->db);
-              Ndb_table_guard ndbtab_g(ndb->getDictionary(), schema->name);
-              ndbtab_g.invalidate();
-            }
-            TABLE_LIST table_list;
-            memset(&table_list, 0, sizeof(table_list));
-            table_list.db= schema->db;
-            table_list.alias= table_list.table_name= schema->name;
-            close_cached_tables(thd, &table_list, FALSE, FALSE, FALSE);
+            ndbapi_invalidate_table(schema->db, schema->name);
+            mysqld_close_cached_table(schema->db, schema->name);
           }
           /* ndb_share reference temporary free */
           if (share)
@@ -2936,18 +2954,8 @@ class Ndb_schema_event_handler {
 
       case SOT_DROP_TABLE:
         write_schema_op_to_binlog(thd, schema);
-        {
-          ndb->setDatabaseName(schema->db);
-          Ndb_table_guard ndbtab_g(dict, schema->name);
-          ndbtab_g.invalidate();
-        }
-        {
-          TABLE_LIST table_list;
-          memset(&table_list, 0, sizeof(table_list));
-          table_list.db= schema->db;
-          table_list.alias= table_list.table_name= schema->name;
-          close_cached_tables(thd, &table_list, FALSE, FALSE, FALSE);
-        }
+        ndbapi_invalidate_table(schema->db, schema->name);
+        mysqld_close_cached_table(schema->db, schema->name);
         break;
 
       case SOT_RENAME_TABLE:
@@ -2968,18 +2976,8 @@ class Ndb_schema_event_handler {
         if (schema->node_id == g_ndb_cluster_connection->node_id())
           break;
         write_schema_op_to_binlog(thd, schema);
-        {
-          ndb->setDatabaseName(schema->db);
-          Ndb_table_guard ndbtab_g(dict, schema->name);
-          ndbtab_g.invalidate();
-        }
-        {
-          TABLE_LIST table_list;
-          memset(&table_list, 0, sizeof(table_list));
-          table_list.db= schema->db;
-          table_list.alias= table_list.table_name= schema->name;
-          close_cached_tables(thd, &table_list, FALSE, FALSE, FALSE);
-        }
+        ndbapi_invalidate_table(schema->db, schema->name);
+        mysqld_close_cached_table(schema->db, schema->name);
         if (share)
         {
           if (share->op)
@@ -3029,23 +3027,14 @@ class Ndb_schema_event_handler {
       case SOT_ONLINE_ALTER_TABLE_PREPARE:
       {
         int error= 0;
-        ndb->setDatabaseName(schema->db);
-        {
-          Ndb_table_guard ndbtab_g(dict, schema->name);
-          ndbtab_g.get_table();
-          ndbtab_g.invalidate();
-        }
+        ndbapi_invalidate_table(schema->db, schema->name);
         Ndb_table_guard ndbtab_g(dict, schema->name);
         const NDBTAB *ndbtab= ndbtab_g.get_table();
         /*
           Refresh local frm file and dictionary cache if
           remote on-line alter table
         */
-        TABLE_LIST table_list;
-        memset(&table_list, 0, sizeof(table_list));
-        table_list.db= (char *)schema->db;
-        table_list.alias= table_list.table_name= (char *)schema->name;
-        close_cached_tables(thd, &table_list, TRUE, FALSE, FALSE);
+        mysqld_close_cached_table(schema->db, schema->name);
 
         if (schema->node_id != g_ndb_cluster_connection->node_id())
         {
@@ -3266,13 +3255,13 @@ public:
 
   void handle_event(Ndb* s_ndb, NdbEventOperation *pOp)
   {
-    DBUG_ENTER("handle_event");
-
-    const Ndb_event_data *event_data=
-      static_cast<const Ndb_event_data*>(pOp->getCustomData());
-
-    if (!check_is_ndb_schema_event(event_data))
-      DBUG_VOID_RETURN;
+    DBUG_ENTER("handle_event");
+
+    const Ndb_event_data *event_data=
+      static_cast<const Ndb_event_data*>(pOp->getCustomData());
+
+    if (!check_is_ndb_schema_event(event_data))
+      DBUG_VOID_RETURN;
 
     const NDBEVENT::TableEvent ev_type= pOp->getEventType();
     switch (ev_type)

=== modified file 'sql/ha_ndbcluster_binlog.h'
--- a/sql/ha_ndbcluster_binlog.h	2011-10-31 15:37:40 +0000
+++ b/sql/ha_ndbcluster_binlog.h	2011-11-02 09:28:48 +0000
@@ -131,7 +131,6 @@ bool ndb_binlog_setup(THD *thd);
 bool ndb_binlog_is_read_only(void);
 
 extern NDB_SHARE *ndb_apply_status_share;
-extern NDB_SHARE *ndb_schema_share;
 
 extern my_bool ndb_binlog_running;
 

=== modified file 'sql/ndb_schema_dist.cc'
--- a/sql/ndb_schema_dist.cc	2011-10-31 15:10:59 +0000
+++ b/sql/ndb_schema_dist.cc	2011-11-02 09:28:48 +0000
@@ -65,3 +65,14 @@ get_schema_type_name(uint type)
   }
   return "<unknown>";
 }
+
+extern struct NDB_SHARE* ndb_schema_share;
+
+bool ndb_schema_dist_is_ready(void)
+{
+  if (ndb_schema_share)
+    return true;
+
+  DBUG_PRINT("info", ("ndb schema dist not ready"));
+  return false;
+}

=== modified file 'sql/ndb_schema_dist.h'
--- a/sql/ndb_schema_dist.h	2011-10-31 15:10:59 +0000
+++ b/sql/ndb_schema_dist.h	2011-11-02 09:28:48 +0000
@@ -22,6 +22,14 @@
 #include <my_global.h>
 
 
+/**
+  Check if schema distribution has been initialized and is
+  ready. Will return true when the component is properly setup
+  to receive schema op events from the cluster.
+*/
+bool ndb_schema_dist_is_ready(void);
+
+
 /*
   The numbers below must not change as they
   are passed between mysql servers, and if changed

=== modified file 'sql/ndb_share.cc'
--- a/sql/ndb_share.cc	2011-03-08 09:04:24 +0000
+++ b/sql/ndb_share.cc	2011-11-07 19:00:35 +0000
@@ -16,3 +16,33 @@
 */
 
 #include "ndb_share.h"
+#include "ndb_event_data.h"
+
+#include <my_sys.h>
+
+extern Ndb* g_ndb;
+
+void
+NDB_SHARE::destroy(NDB_SHARE* share)
+{
+  thr_lock_delete(&share->lock);
+  pthread_mutex_destroy(&share->mutex);
+
+#ifdef HAVE_NDB_BINLOG
+  if (share->m_cfn_share && share->m_cfn_share->m_ex_tab && g_ndb)
+  {
+    NdbDictionary::Dictionary *dict= g_ndb->getDictionary();
+    dict->removeTableGlobal(*(share->m_cfn_share->m_ex_tab), 0);
+    share->m_cfn_share->m_ex_tab= 0;
+  }
+#endif
+  share->new_op= 0;
+  if (share->event_data)
+  {
+    delete share->event_data;
+    share->event_data= 0;
+  }
+  free_root(&share->mem_root, MYF(0));
+  my_free(share);
+}
+

=== modified file 'sql/ndb_share.h'
--- a/sql/ndb_share.h	2011-10-31 15:57:15 +0000
+++ b/sql/ndb_share.h	2011-11-05 11:35:57 +0000
@@ -187,6 +187,8 @@ struct NDB_SHARE {
   char *old_names; // for rename table
   MY_BITMAP *subscriber_bitmap;
   class NdbEventOperation *new_op;
+
+  static void destroy(NDB_SHARE* share);
 };
 
 

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.5-cluster branch (magnus.blaudd:3629 to 3632) magnus.blaudd9 Nov