List:Commits« Previous MessageNext Message »
From:magnus.blaudd Date:November 7 2011 11:22pm
Subject:bzr push into mysql-5.5-cluster branch (magnus.blaudd:3634 to 3635)
View as plain text  
 3635 magnus.blaudd@stripped	2011-11-08 [merge]
      Merge

    modified:
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster_binlog.cc
      sql/ha_ndbcluster_binlog.h
      sql/handler.cc
      sql/ndb_ndbapi_util.cc
      sql/ndb_ndbapi_util.h
 3634 John David Duncan	2011-11-07 [merge]
      merge from local working branch

    added:
      mysql-test/suite/ndb_memcache/r/unique_idx.result
      mysql-test/suite/ndb_memcache/t/unique_idx.test
    modified:
      storage/ndb/memcache/include/KeyPrefix.h
      storage/ndb/memcache/include/QueryPlan.h
      storage/ndb/memcache/include/workitem.h
      storage/ndb/memcache/scripts/pmpstack.awk
      storage/ndb/memcache/src/QueryPlan.cc
      storage/ndb/memcache/src/ndb_worker.cc
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2011-11-05 11:35:57 +0000
+++ b/sql/ha_ndbcluster.cc	2011-11-07 22:45:08 +0000
@@ -1915,30 +1915,6 @@ void ha_ndbcluster::release_blobs_buffer
   DBUG_VOID_RETURN;
 }
 
-/**
-  Get metadata for this table from NDB.
-
-  Check that frm-file on disk is equal to frm-file
-  of table accessed in NDB.
-
-  @retval
-    0    ok
-  @retval
-    -2   Meta data has changed; Re-read data and try again
-*/
-
-int cmp_frm(const NDBTAB *ndbtab, const void *pack_data,
-            size_t pack_length)
-{
-  DBUG_ENTER("cmp_frm");
-  /*
-    Compare FrmData in NDB with frm file from disk.
-  */
-  if ((pack_length != ndbtab->getFrmLength()) || 
-      (memcmp(pack_data, ndbtab->getFrmData(), pack_length)))
-    DBUG_RETURN(1);
-  DBUG_RETURN(0);
-}
 
 /*
   Does type support a default value?
@@ -12762,7 +12738,27 @@ void ha_ndbcluster::print_error(int erro
   if (error == HA_ERR_NO_PARTITION_FOUND)
     m_part_info->print_no_partition_found(table);
   else
+  {
+    if (error == HA_ERR_FOUND_DUPP_KEY &&
+        (table == NULL || table->file == NULL))
+    {
+      /*
+        This is a sideffect of 'ndbcluster_print_error' (called from
+        'ndbcluster_commit' and 'ndbcluster_rollback') which realises
+        that it "knows nothing" and creates a brand new ha_ndbcluster
+        in order to be able to call the print_error() function.
+        Unfortunately the new ha_ndbcluster hasn't been open()ed
+        and thus table pointer etc. is not set. Since handler::print_error()
+        will use that pointer without checking for NULL(it naturally
+        assumes an error can only be returned when the handler is open)
+        this would crash the mysqld unless it's handled here.
+      */
+      my_error(ER_DUP_KEY, errflag, table_share->table_name.str, error);
+      DBUG_VOID_RETURN;
+    }
+
     handler::print_error(error, errflag);
+  }
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2011-11-07 18:59:32 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2011-11-07 22:53:15 +0000
@@ -265,7 +265,7 @@ static void run_query(THD *thd, char *bu
 }
 
 static void
-ndb_binlog_close_shadow_table(THD *thd, NDB_SHARE *share)
+ndb_binlog_close_shadow_table(NDB_SHARE *share)
 {
   DBUG_ENTER("ndb_binlog_close_shadow_table");
   Ndb_event_data *event_data= share->event_data;
@@ -2533,6 +2533,7 @@ class Ndb_schema_event_handler {
   log_after_epoch(Ndb_schema_op* schema)
   {
     DBUG_ENTER("log_after_epoch");
+    assert(!is_post_epoch()); // Only before epoch
     m_post_epoch_log_list.push_back(schema, m_mem_root);
     DBUG_VOID_RETURN;
   }
@@ -2542,6 +2543,7 @@ class Ndb_schema_event_handler {
   unlock_after_epoch(Ndb_schema_op* schema)
   {
     DBUG_ENTER("unlock_after_epoch");
+    assert(!is_post_epoch()); // Only before epoch
     m_post_epoch_unlock_list.push_back(schema, m_mem_root);
     DBUG_VOID_RETURN;
   }
@@ -2553,7 +2555,8 @@ class Ndb_schema_event_handler {
   }
 
 
-  void ndbapi_invalidate_table(const char* db_name, const char* table_name)
+  void
+  ndbapi_invalidate_table(const char* db_name, const char* table_name) const
   {
     Thd_ndb *thd_ndb= get_thd_ndb(m_thd);
     Ndb *ndb= thd_ndb->ndb;
@@ -2564,7 +2567,8 @@ class Ndb_schema_event_handler {
   }
 
 
-  void mysqld_close_cached_table(const char* db_name, const char* table_name)
+  void
+  mysqld_close_cached_table(const char* db_name, const char* table_name) const
   {
      // Just mark table as "need reopen"
     const bool wait_for_refresh = false;
@@ -2581,6 +2585,21 @@ class Ndb_schema_event_handler {
   }
 
 
+  NDB_SHARE* get_share(Ndb_schema_op* schema) const
+  {
+    char key[FN_REFLEN + 1];
+    build_table_filename(key, sizeof(key) - 1,
+                         schema->db, schema->name, "", 0);
+    NDB_SHARE *share= ndbcluster_get_share(key, 0, FALSE, FALSE);
+    if (share)
+    {
+      DBUG_PRINT("NDB_SHARE", ("%s temporary  use_count: %u",
+                               share->key, share->use_count));
+    }
+    return share;
+  }
+
+
   bool
   check_if_local_tables_in_db(const char *dbname) const
   {
@@ -2609,9 +2628,10 @@ class Ndb_schema_event_handler {
     DBUG_RETURN(false);
   }
 
-  void handle_clear_slock(Ndb_schema_op* schema, bool post_epoch)
+
+  void handle_clear_slock(Ndb_schema_op* schema)
   {
-    if (!post_epoch)
+    if (!is_post_epoch())
     {
       /*
         handle slock after epoch is completed to ensure that
@@ -2682,6 +2702,207 @@ class Ndb_schema_event_handler {
   }
 
 
+  void
+  handle_offline_alter_table_commit(Ndb_schema_op* schema)
+  {
+    assert(is_post_epoch()); // Always after epoch
+
+    if (schema->node_id == own_nodeid())
+      return;
+
+    write_schema_op_to_binlog(m_thd, schema);
+    ndbapi_invalidate_table(schema->db, schema->name);
+    mysqld_close_cached_table(schema->db, schema->name);
+
+    NDB_SHARE *share= get_share(schema);
+    if (share)
+    {
+      pthread_mutex_lock(&share->mutex);
+      if (share->op)
+      {
+        Ndb_event_data *event_data=
+          (Ndb_event_data *) share->op->getCustomData();
+        if (event_data)
+          delete event_data;
+        share->op->setCustomData(NULL);
+        {
+          Mutex_guard injector_mutex_g(injector_mutex);
+          injector_ndb->dropEventOperation(share->op);
+        }
+        share->op= 0;
+        free_share(&share);
+      }
+      pthread_mutex_unlock(&share->mutex);
+
+      free_share(&share);
+    }
+
+    if (share)
+    {
+      /*
+        Free the share pointer early, ndb_create_table_from_engine()
+        may delete what share is pointing to as a sideeffect
+      */
+      DBUG_PRINT("NDB_SHARE", ("%s early free, use_count: %u",
+                               share->key, share->use_count));
+      free_share(&share);
+    }
+
+    if (ndbcluster_check_if_local_table(schema->db, schema->name) &&
+       !Ndb_dist_priv_util::is_distributed_priv_table(schema->db,
+                                                      schema->name))
+    {
+      sql_print_error("NDB Binlog: Skipping locally defined table '%s.%s' "
+                      "from binlog schema event '%s' from node %d.",
+                      schema->db, schema->name, schema->query,
+                      schema->node_id);
+      return;
+    }
+
+    if (ndb_create_table_from_engine(m_thd, schema->db, schema->name))
+    {
+      print_could_not_discover_error(m_thd, schema);
+    }
+  }
+
+
+  void
+  handle_online_alter_table_prepare(Ndb_schema_op* schema)
+  {
+    assert(is_post_epoch()); // Always after epoch
+
+    ndbapi_invalidate_table(schema->db, schema->name);
+    mysqld_close_cached_table(schema->db, schema->name);
+
+    int error= 0;
+    Thd_ndb *thd_ndb= get_thd_ndb(m_thd);
+    Ndb *ndb= thd_ndb->ndb;
+    Ndb_table_guard ndbtab_g(ndb->getDictionary(), schema->name);
+    const NDBTAB *ndbtab= ndbtab_g.get_table();
+    if (schema->node_id != own_nodeid())
+    {
+      char key[FN_REFLEN];
+      uchar *data= 0, *pack_data= 0;
+      size_t length, pack_length;
+
+      DBUG_PRINT("info", ("Detected frm change of table %s.%s",
+                          schema->db, schema->name));
+      write_schema_op_to_binlog(m_thd, schema);
+      build_table_filename(key, FN_LEN-1, schema->db, schema->name, NullS, 0);
+      /*
+        If the there is no local table shadowing the altered table and
+        it has an frm that is different than the one on disk then
+        overwrite it with the new table definition
+      */
+      if (!ndbcluster_check_if_local_table(schema->db, schema->name) &&
+          readfrm(key, &data, &length) == 0 &&
+          packfrm(data, length, &pack_data, &pack_length) == 0 &&
+          cmp_frm(ndbtab, pack_data, pack_length))
+      {
+        DBUG_DUMP("frm", (uchar*) ndbtab->getFrmData(),
+                  ndbtab->getFrmLength());
+        my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
+        data= NULL;
+        if ((error= unpackfrm(&data, &length,
+                              (const uchar*) ndbtab->getFrmData())) ||
+            (error= writefrm(key, data, length)))
+        {
+          sql_print_error("NDB: Failed write frm for %s.%s, error %d",
+                          schema->db, schema->name, error);
+        }
+      }
+      my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
+      my_free((char*)pack_data, MYF(MY_ALLOW_ZERO_PTR));
+    }
+    NDB_SHARE *share= get_share(schema);
+    if (share)
+    {
+      if (opt_ndb_extra_logging > 9)
+        sql_print_information("NDB Binlog: handeling online alter/rename");
+
+      pthread_mutex_lock(&share->mutex);
+      ndb_binlog_close_shadow_table(share);
+
+      if ((error= ndb_binlog_open_shadow_table(m_thd, share)))
+        sql_print_error("NDB Binlog: Failed to re-open shadow table %s.%s",
+                        schema->db, schema->name);
+      if (error)
+        pthread_mutex_unlock(&share->mutex);
+    }
+    if (!error && share)
+    {
+      if (share->event_data->shadow_table->s->primary_key == MAX_KEY)
+        share->flags|= NSF_HIDDEN_PK;
+      /*
+        Refresh share->flags to handle added BLOB columns
+      */
+      if (share->event_data->shadow_table->s->blob_fields != 0)
+        share->flags|= NSF_BLOB_FLAG;
+
+      /*
+        Start subscribing to data changes to the new table definition
+      */
+      String event_name(INJECTOR_EVENT_LEN);
+      ndb_rep_event_name(&event_name, schema->db, schema->name,
+                         get_binlog_full(share));
+      NdbEventOperation *tmp_op= share->op;
+      share->new_op= 0;
+      share->op= 0;
+
+      if (ndbcluster_create_event_ops(m_thd, share, ndbtab, event_name.c_ptr()))
+      {
+        sql_print_error("NDB Binlog:"
+                        "FAILED CREATE (DISCOVER) EVENT OPERATIONS Event: %s",
+                        event_name.c_ptr());
+      }
+      else
+      {
+        share->new_op= share->op;
+      }
+      share->op= tmp_op;
+      pthread_mutex_unlock(&share->mutex);
+
+      if (opt_ndb_extra_logging > 9)
+        sql_print_information("NDB Binlog: handeling online alter/rename done");
+    }
+    if (share)
+    {
+      free_share(&share);
+    }
+  }
+
+
+  void
+  handle_online_alter_table_commit(Ndb_schema_op* schema)
+  {
+    assert(is_post_epoch()); // Always after epoch
+
+    NDB_SHARE *share= get_share(schema);
+    if (share)
+    {
+      pthread_mutex_lock(&share->mutex);
+      if (share->op && share->new_op)
+      {
+        Ndb_event_data *event_data=
+          (Ndb_event_data *) share->op->getCustomData();
+        if (event_data)
+          delete event_data;
+        share->op->setCustomData(NULL);
+        {
+          Mutex_guard injector_mutex_g(injector_mutex);
+          injector_ndb->dropEventOperation(share->op);
+        }
+        share->op= share->new_op;
+        share->new_op= 0;
+        free_share(&share);
+      }
+      pthread_mutex_unlock(&share->mutex);
+
+      free_share(&share);
+    }
+  }
+
+
   int
   handle_schema_op(Ndb_schema_op* schema)
   {
@@ -2715,7 +2936,7 @@ class Ndb_schema_event_handler {
       switch (schema_type)
       {
       case SOT_CLEAR_SLOCK:
-        handle_clear_slock(schema, false);
+        handle_clear_slock(schema);
         DBUG_RETURN(0);
 
       case SOT_ALTER_TABLE_COMMIT:
@@ -2734,7 +2955,6 @@ class Ndb_schema_event_handler {
       {
         THD* thd= m_thd; // Code compatibility
         Thd_ndb *thd_ndb= get_thd_ndb(thd);
-        Ndb *ndb= thd_ndb->ndb;
         Thd_ndb_options_guard thd_ndb_options(thd_ndb);
 
         int post_epoch_unlock= 0;
@@ -2773,29 +2993,15 @@ class Ndb_schema_event_handler {
           // Fall through
 	case SOT_TRUNCATE_TABLE:
         {
-          char key[FN_REFLEN + 1];
-          build_table_filename(key, sizeof(key) - 1,
-                               schema->db, schema->name, "", 0);
-          /* ndb_share reference temporary, free below */
-          NDB_SHARE *share= get_share(key, 0, FALSE, FALSE);
-          if (share)
-          {
-            DBUG_PRINT("NDB_SHARE", ("%s temporary  use_count: %u",
-                                     share->key, share->use_count));
-          }
+          NDB_SHARE *share= get_share(schema);
           // invalidation already handled by binlog thread
           if (!share || !share->op)
           {
             ndbapi_invalidate_table(schema->db, schema->name);
             mysqld_close_cached_table(schema->db, schema->name);
           }
-          /* ndb_share reference temporary free */
           if (share)
-          {
-            DBUG_PRINT("NDB_SHARE", ("%s temporary free  use_count: %u",
-                                     share->key, share->use_count));
             free_share(&share);
-          }
         }
         if (schema_type != SOT_TRUNCATE_TABLE)
           break;
@@ -2908,6 +3114,7 @@ class Ndb_schema_event_handler {
     DBUG_RETURN(0);
   }
 
+
   void
   handle_schema_op_post_epoch(Ndb_schema_op* schema)
   {
@@ -2916,7 +3123,7 @@ class Ndb_schema_event_handler {
     Thd_ndb *thd_ndb= get_thd_ndb(thd);
     Ndb *ndb= thd_ndb->ndb;
     NDBDICT *dict= ndb->getDictionary();
-    Thd_ndb_options_guard thd_ndb_options(thd_ndb);
+
     DBUG_PRINT("info",
                ("%s.%s: log query_length: %d  query: '%s'  type: %d",
                 schema->db, schema->name,
@@ -2925,29 +3132,18 @@ class Ndb_schema_event_handler {
 
     {
       const SCHEMA_OP_TYPE schema_type= (SCHEMA_OP_TYPE)schema->type;
-      char key[FN_REFLEN + 1];
-      build_table_filename(key, sizeof(key) - 1, schema->db, schema->name, "", 0);
-      if (schema_type == SOT_CLEAR_SLOCK)
-      {
-        handle_clear_slock(schema, true);
-        DBUG_VOID_RETURN;
-      }
-
       if (opt_ndb_extra_logging > 9)
         sql_print_information("%s - %s.%s",
                               get_schema_type_name(schema_type),
                               schema->db ? schema->db : "(null)",
                               schema->name ? schema->name : "(null)");
 
-      /* ndb_share reference temporary, free below */
-      NDB_SHARE *share= get_share(key, 0, FALSE, FALSE);
-      if (share)
-      {
-        DBUG_PRINT("NDB_SHARE", ("%s temporary  use_count: %u",
-                                 share->key, share->use_count));
-      }
       switch (schema_type)
       {
+      case SOT_CLEAR_SLOCK:
+        handle_clear_slock(schema);
+        break;
+
       case SOT_DROP_DB:
         write_schema_op_to_binlog(thd, schema);
         break;
@@ -2959,197 +3155,46 @@ class Ndb_schema_event_handler {
         break;
 
       case SOT_RENAME_TABLE:
+      {
         write_schema_op_to_binlog(thd, schema);
+        NDB_SHARE *share= get_share(schema);
         if (share)
         {
           ndbcluster_rename_share(thd, share);
+          free_share(&share);
         }
         break;
+      }
 
       case SOT_RENAME_TABLE_PREPARE:
-        if (share &&
-            schema->node_id != g_ndb_cluster_connection->node_id())
-          ndbcluster_prepare_rename_share(share, schema->query);
-        break;
-
-      case SOT_ALTER_TABLE_COMMIT:
-        if (schema->node_id == g_ndb_cluster_connection->node_id())
+      {
+        if (schema->node_id == own_nodeid())
           break;
-        write_schema_op_to_binlog(thd, schema);
-        ndbapi_invalidate_table(schema->db, schema->name);
-        mysqld_close_cached_table(schema->db, schema->name);
+        NDB_SHARE *share= get_share(schema);
         if (share)
         {
-          if (share->op)
-          {
-            Ndb_event_data *event_data= (Ndb_event_data *) share->op->getCustomData();
-            if (event_data)
-              delete event_data;
-            share->op->setCustomData(NULL);
-            {
-              Mutex_guard injector_mutex_g(injector_mutex);
-              injector_ndb->dropEventOperation(share->op);
-            }
-            share->op= 0;
-            free_share(&share);
-          }
-          free_share(&share);
-        }
-
-        if (share)
-        {
-          /*
-            Free the share pointer early, ndb_create_table_from_engine()
-            may delete what share is pointing to as a sideeffect
-          */
-          DBUG_PRINT("NDB_SHARE", ("%s early free, use_count: %u",
-                                   share->key, share->use_count));
+          ndbcluster_prepare_rename_share(share, schema->query);
           free_share(&share);
-          share= 0;
         }
+        break;
+      }
 
-        thd_ndb_options.set(TNO_NO_LOCK_SCHEMA_OP);
-        if (ndbcluster_check_if_local_table(schema->db, schema->name) &&
-           !Ndb_dist_priv_util::is_distributed_priv_table(schema->db,
-                                                          schema->name))
-        {
-          sql_print_error("NDB Binlog: Skipping locally defined table '%s.%s' "
-                          "from binlog schema event '%s' from node %d.",
-                          schema->db, schema->name, schema->query,
-                          schema->node_id);
-        }
-        else if (ndb_create_table_from_engine(thd, schema->db, schema->name))
-        {
-          print_could_not_discover_error(thd, schema);
-        }
+      case SOT_ALTER_TABLE_COMMIT:
+        handle_offline_alter_table_commit(schema);
         break;
 
       case SOT_ONLINE_ALTER_TABLE_PREPARE:
-      {
-        int error= 0;
-        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
-        */
-        mysqld_close_cached_table(schema->db, schema->name);
-
-        if (schema->node_id != g_ndb_cluster_connection->node_id())
-        {
-          char key[FN_REFLEN];
-          uchar *data= 0, *pack_data= 0;
-          size_t length, pack_length;
- 
-          DBUG_PRINT("info", ("Detected frm change of table %s.%s",
-                              schema->db, schema->name));
-          write_schema_op_to_binlog(thd, schema);
-          build_table_filename(key, FN_LEN-1, schema->db, schema->name, NullS, 0);
-          /*
-            If the there is no local table shadowing the altered table and 
-            it has an frm that is different than the one on disk then 
-            overwrite it with the new table definition
-          */
-          if (!ndbcluster_check_if_local_table(schema->db, schema->name) &&
-              readfrm(key, &data, &length) == 0 &&
-              packfrm(data, length, &pack_data, &pack_length) == 0 &&
-              cmp_frm(ndbtab, pack_data, pack_length))
-          {
-            DBUG_DUMP("frm", (uchar*) ndbtab->getFrmData(), 
-                      ndbtab->getFrmLength());
-            my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
-            data= NULL;
-            if ((error= unpackfrm(&data, &length,
-                                  (const uchar*) ndbtab->getFrmData())) ||
-                (error= writefrm(key, data, length)))
-            {
-              sql_print_error("NDB: Failed write frm for %s.%s, error %d",
-                              schema->db, schema->name, error);
-            }
-          }
-          my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
-          my_free((char*)pack_data, MYF(MY_ALLOW_ZERO_PTR));
-        }
-        if (share)
-        {
-          if (opt_ndb_extra_logging > 9)
-            sql_print_information("NDB Binlog: handeling online alter/rename");
-
-          pthread_mutex_lock(&share->mutex);
-          ndb_binlog_close_shadow_table(thd, share);
-
-          if ((error= ndb_binlog_open_shadow_table(thd, share)))
-            sql_print_error("NDB Binlog: Failed to re-open shadow table %s.%s",
-                            schema->db, schema->name);
-          if (error)
-            pthread_mutex_unlock(&share->mutex);
-        }
-        if (!error && share)
-        {
-          if (share->event_data->shadow_table->s->primary_key == MAX_KEY)
-            share->flags|= NSF_HIDDEN_PK;
-          /*
-            Refresh share->flags to handle added BLOB columns
-          */
-          if (share->event_data->shadow_table->s->blob_fields != 0)
-            share->flags|= NSF_BLOB_FLAG;
-
-          /*
-            Start subscribing to data changes to the new table definition
-          */
-          String event_name(INJECTOR_EVENT_LEN);
-          ndb_rep_event_name(&event_name, schema->db, schema->name,
-                             get_binlog_full(share));
-          NdbEventOperation *tmp_op= share->op;
-          share->new_op= 0;
-          share->op= 0;
-
-          if (ndbcluster_create_event_ops(thd, share, ndbtab, event_name.c_ptr()))
-          {
-            sql_print_error("NDB Binlog:"
-                            "FAILED CREATE (DISCOVER) EVENT OPERATIONS Event: %s",
-                            event_name.c_ptr());
-          }
-          else
-          {
-            share->new_op= share->op;
-          }
-          share->op= tmp_op;
-          pthread_mutex_unlock(&share->mutex);
-
-          if (opt_ndb_extra_logging > 9)
-            sql_print_information("NDB Binlog: handeling online alter/rename done");
-        }
+        handle_online_alter_table_prepare(schema);
         break;
-      }
 
       case SOT_ONLINE_ALTER_TABLE_COMMIT:
-      {
-        if (share)
-        {
-          pthread_mutex_lock(&share->mutex);
-          if (share->op && share->new_op)
-          {
-            Ndb_event_data *event_data= (Ndb_event_data *) share->op->getCustomData();
-            if (event_data)
-              delete event_data;
-            share->op->setCustomData(NULL);
-            {
-              Mutex_guard injector_mutex_g(injector_mutex);
-              injector_ndb->dropEventOperation(share->op);
-            }
-            share->op= share->new_op;
-            share->new_op= 0;
-            free_share(&share);
-          }
-          pthread_mutex_unlock(&share->mutex);
-        }
+        handle_online_alter_table_commit(schema);
         break;
-      }
 
       case SOT_RENAME_TABLE_NEW:
+      {
         write_schema_op_to_binlog(thd, schema);
+        NDB_SHARE *share= get_share(schema);
         if (ndb_binlog_running && (!share || !share->op))
         {
           /*
@@ -3164,7 +3209,7 @@ class Ndb_schema_event_handler {
             free_share(&share);
             share= 0;
           }
-          thd_ndb_options.set(TNO_NO_LOCK_SCHEMA_OP);
+
           if (ndbcluster_check_if_local_table(schema->db, schema->name))
           {
             DBUG_PRINT("info", ("NDB Binlog: Skipping locally defined table '%s.%s'",
@@ -3179,25 +3224,22 @@ class Ndb_schema_event_handler {
             print_could_not_discover_error(thd, schema);
           }
         }
+        if (share)
+        {
+          free_share(&share);
+        }
         break;
+      }
 
       default:
         DBUG_ASSERT(FALSE);
       }
-
-      if (share)
-      {
-        /* ndb_share reference temporary free */
-        DBUG_PRINT("NDB_SHARE", ("%s temporary free  use_count: %u",
-                                 share->key, share->use_count));
-        free_share(&share);
-        share= 0;
-      }
     }
 
     DBUG_VOID_RETURN;
   }
 
+
   /*
     process any operations that should be done after
     the epoch is complete
@@ -3233,6 +3275,9 @@ class Ndb_schema_event_handler {
   THD* m_thd;
   MEM_ROOT* m_mem_root;
   uint m_own_nodeid;
+  bool m_post_epoch;
+
+  bool is_post_epoch(void) const { return m_post_epoch; };
 
   List<Ndb_schema_op> m_post_epoch_log_list;
   List<Ndb_schema_op> m_post_epoch_unlock_list;
@@ -3242,10 +3287,12 @@ public:
   Ndb_schema_event_handler(const Ndb_schema_event_handler&); // Not implemented
 
   Ndb_schema_event_handler(THD* thd, MEM_ROOT* mem_root, uint own_nodeid):
-    m_thd(thd), m_mem_root(mem_root), m_own_nodeid(own_nodeid)
+    m_thd(thd), m_mem_root(mem_root), m_own_nodeid(own_nodeid),
+    m_post_epoch(false)
   {
   }
 
+
   ~Ndb_schema_event_handler()
   {
     // There should be no work left todo...
@@ -3253,6 +3300,7 @@ public:
     DBUG_ASSERT(m_post_epoch_unlock_list.elements == 0);
   }
 
+
   void handle_event(Ndb* s_ndb, NdbEventOperation *pOp)
   {
     DBUG_ENTER("handle_event");
@@ -3390,10 +3438,14 @@ public:
     DBUG_VOID_RETURN;
   }
 
+
   void post_epoch()
   {
     if (m_post_epoch_log_list.elements > 0)
     {
+      // Set the flag used to check that functions are called at correct time
+      m_post_epoch= true;
+
       handle_schema_log_post_epoch(&m_post_epoch_log_list);
       // NOTE post_epoch_unlock_list may not be handled!
       handle_schema_unlock_post_epoch(&m_post_epoch_unlock_list);
@@ -5067,17 +5119,14 @@ int ndbcluster_create_binlog_setup(THD *
   DBUG_ASSERT(! IS_NDB_BLOB_PREFIX(table_name));
   DBUG_ASSERT(strlen(key) == key_len);
 
-  pthread_mutex_lock(&ndbcluster_mutex);
-  NDB_SHARE * share = get_share(key, table, TRUE, TRUE);
+  NDB_SHARE* share= get_share(key, table, true, false);
   if (share == 0)
   {
     /**
      * Failed to create share
      */
-    pthread_mutex_unlock(&ndbcluster_mutex);
     DBUG_RETURN(-1);
   }
-  pthread_mutex_unlock(&ndbcluster_mutex);
 
   pthread_mutex_lock(&share->mutex);
   if (get_binlog_nologging(share) || share->op != 0 || share->new_op != 0)

=== modified file 'sql/ha_ndbcluster_binlog.h'
--- a/sql/ha_ndbcluster_binlog.h	2011-11-02 09:28:48 +0000
+++ b/sql/ha_ndbcluster_binlog.h	2011-11-07 22:45:08 +0000
@@ -139,13 +139,6 @@ ndbcluster_show_status_binlog(THD* thd, 
                               enum ha_stat_type stat_type);
 
 /*
-  prototypes for ndb handler utility function also needed by
-  the ndb binlog code
-*/
-int cmp_frm(const NDBTAB *ndbtab, const void *pack_data,
-            size_t pack_length);
-
-/*
   Helper functions
 */
 bool

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2011-09-28 08:49:39 +0000
+++ b/sql/handler.cc	2011-11-07 21:32:26 +0000
@@ -3059,19 +3059,6 @@ err:
 uint handler::get_dup_key(int error)
 {
   DBUG_ENTER("handler::get_dup_key");
-#ifndef MCP_BUG59948
-  if (table == NULL || table->file == NULL)
-  {
-    /*
-      This is a sideffect of the ndbcluster_print_error() (called from
-      ndbcluster_commit and ndbcluster_rollback). The function realises that
-      it "knows nothing" so it creates brand new ha_ndbcluster in order to be
-      able to call print_error() function. Unfortunately the handler hasn't
-      been open()ed and thus table pointer is not set.
-     */
-    DBUG_RETURN(-1);
-  }
-#endif
   table->file->errkey  = (uint) -1;
   if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
       error == HA_ERR_FOUND_DUPP_UNIQUE || error == HA_ERR_NULL_IN_SPATIAL ||

=== modified file 'sql/ndb_ndbapi_util.cc'
--- a/sql/ndb_ndbapi_util.cc	2011-10-27 08:27:44 +0000
+++ b/sql/ndb_ndbapi_util.cc	2011-11-07 22:45:08 +0000
@@ -43,6 +43,21 @@ char *ndb_pack_varchar(const NdbDictiona
 }
 
 
+int
+cmp_frm(const NdbDictionary::Table* ndbtab, const void* pack_data,
+        size_t pack_length)
+{
+  DBUG_ENTER("cmp_frm");
+  /*
+    Compare the NDB tables FrmData with frm file blob in pack_data.
+  */
+  if ((pack_length != ndbtab->getFrmLength()) ||
+      (memcmp(pack_data, ndbtab->getFrmData(), pack_length)))
+    DBUG_RETURN(1);
+  DBUG_RETURN(0);
+}
+
+
 #ifndef MYSQL_SERVER
 #define MYSQL_SERVER
 #endif

=== modified file 'sql/ndb_ndbapi_util.h'
--- a/sql/ndb_ndbapi_util.h	2011-10-27 08:27:44 +0000
+++ b/sql/ndb_ndbapi_util.h	2011-11-07 22:45:08 +0000
@@ -38,4 +38,15 @@ int get_ndb_blobs_value(struct TABLE* ta
 char *ndb_pack_varchar(const NdbDictionary::Column *col,
                        char *buf, const char *str, int sz);
 
+/**
+  Check that frm-file blob in pack_data is equal
+  to frm-file of the NdbDictionary::Table.
+
+  @retval
+    0    ok
+*/
+
+int cmp_frm(const NdbDictionary::Table* ndbtab, const void* pack_data,
+            size_t pack_length);
+
 #endif

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.5-cluster branch (magnus.blaudd:3634 to 3635) magnus.blaudd11 Nov