List:Commits« Previous MessageNext Message »
From:Magnus Blåudd Date:October 28 2011 12:15pm
Subject:bzr push into mysql-5.5-cluster branch (magnus.blaudd:3645 to 3650)
View as plain text  
 3650 Magnus Blåudd	2011-10-28
      ndb schema dist
       - remove the setting of "magic flag" log_query and instead call the correct function directly

    modified:
      sql/ha_ndbcluster_binlog.cc
 3649 Magnus Blåudd	2011-10-28
      ndb schema dist
       - move variables into scope where they are used

    modified:
      sql/ha_ndbcluster_binlog.cc
 3648 Magnus Blåudd	2011-10-28
      ndb schema dist
       - make handle_schema_event non static function(i.e member)
      - rename handle_schema_event to handle_schema_op
       - remove the need to pass after epoch lists and memroot

    modified:
      sql/ha_ndbcluster_binlog.cc
 3647 Magnus Blåudd	2011-10-28
      ndb schema dist
       - add comments
       - remove useless comments and duplicate DBUG_PRINTs

    modified:
      sql/ha_ndbcluster_binlog.cc
 3646 Magnus Blåudd	2011-10-28
      ndb schema dist
       - move the switch on NdbDictionary::Event out of 'handle_schema_event',  making
        that function now only handle one Ndb_schema_op
      - remove the special "if" for INSERT or UPDATE

    modified:
      sql/ha_ndbcluster_binlog.cc
 3645 Magnus Blåudd	2011-10-28
      ndb schema dist
       - change 'ndbcluster_get_schema' (which  is a function to unpack a schema_op from event_data)
         to become private function on Ndb_schema_op and rename it to 'unpack_event'
      - create new static function Ndb_schema_op::create for creating and unpacking
        a Ndb_schema_op from event_data
      - use the new functions

    modified:
      sql/ha_ndbcluster_binlog.cc
=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2011-10-28 09:11:39 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2011-10-28 12:14:34 +0000
@@ -2615,34 +2615,36 @@ class Ndb_schema_event_handler {
   }
 
 
-  static int
-  handle_schema_event(THD *thd, Ndb *s_ndb,
-                      NdbEventOperation *pOp,
-                      List<Cluster_schema> *post_epoch_log_list,
-                      List<Cluster_schema> *post_epoch_unlock_list,
-                      MEM_ROOT *mem_root)
+  void
+  log_after_epoch(Ndb_schema_op* schema)
   {
-    DBUG_ENTER("handle_schema_event");
+    DBUG_ENTER("log_after_epoch");
+    m_post_epoch_log_list.push_back(schema, m_mem_root);
+    DBUG_VOID_RETURN;
+  }
+
+
+  void
+  unlock_after_epoch(Ndb_schema_op* schema)
+  {
+    DBUG_ENTER("unlock_after_epoch");
+    m_post_epoch_unlock_list.push_back(schema, m_mem_root);
+    DBUG_VOID_RETURN;
+  }
+
+
+  int
+  handle_schema_op(THD *thd, Ndb *s_ndb,
+                   NdbEventOperation *pOp)
+  {
+    DBUG_ENTER("handle_schema_op");
     const Ndb_event_data* event_data=
       static_cast<const Ndb_event_data*>(pOp->getCustomData());
-    NDB_SHARE *tmp_share= event_data->share;
-
-    NDBEVENT::TableEvent ev_type= pOp->getEventType();
-    DBUG_PRINT("enter", ("%s.%s  ev_type: %d",
-                         tmp_share->db, tmp_share->table_name, ev_type));
-    if (ev_type == NDBEVENT::TE_UPDATE ||
-        ev_type == NDBEVENT::TE_INSERT)
     {
-      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);
-      uint node_id= g_ndb_cluster_connection->node_id();
-
       Ndb_schema_op* schema=
         Ndb_schema_op::create(event_data, pOp->getAnyValue());
 
-      enum SCHEMA_OP_TYPE schema_type= (enum SCHEMA_OP_TYPE)schema->type;
+      const SCHEMA_OP_TYPE schema_type= (SCHEMA_OP_TYPE)schema->type;
 
       if (opt_ndb_extra_logging > 19)
       {
@@ -2666,6 +2668,7 @@ class Ndb_schema_event_handler {
          */
         DBUG_RETURN(0);
       }
+
       switch (schema_type)
       {
       case SOT_CLEAR_SLOCK:
@@ -2674,24 +2677,29 @@ class Ndb_schema_event_handler {
           schema events get inserted in the binlog after any data
           events
         */
-        post_epoch_log_list->push_back(schema, mem_root);
+        log_after_epoch(schema);
         DBUG_RETURN(0);
 
       case SOT_ALTER_TABLE_COMMIT:
       case SOT_RENAME_TABLE_PREPARE:
       case SOT_ONLINE_ALTER_TABLE_PREPARE:
       case SOT_ONLINE_ALTER_TABLE_COMMIT:
-        post_epoch_log_list->push_back(schema, mem_root);
-        post_epoch_unlock_list->push_back(schema, mem_root);
+        log_after_epoch(schema);
+        unlock_after_epoch(schema);
         DBUG_RETURN(0);
 
       default:
         break;
       }
 
+      const uint node_id= g_ndb_cluster_connection->node_id();
       if (schema->node_id != node_id)
       {
-        int log_query= 0, post_epoch_unlock= 0;
+        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;
  
         switch (schema_type)
         {
@@ -2707,7 +2715,7 @@ class Ndb_schema_event_handler {
                       schema->query + schema->query_length,
                       no_print_error);
             /* binlog dropping table after any table operations */
-            post_epoch_log_list->push_back(schema, mem_root);
+            log_after_epoch(schema);
             /* acknowledge this query _after_ epoch completion */
             post_epoch_unlock= 1;
           }
@@ -2722,7 +2730,7 @@ class Ndb_schema_event_handler {
                             (schema_type == SOT_DROP_TABLE ? "dropp" : "renam"),
                             schema->db, schema->name, schema->query,
                             schema->node_id);
-            log_query= 1;
+            write_schema_op_to_binlog(thd, schema);
           }
           // Fall through
 	case SOT_TRUNCATE_TABLE:
@@ -2742,7 +2750,7 @@ class Ndb_schema_event_handler {
           {
             {
               ndb->setDatabaseName(schema->db);
-              Ndb_table_guard ndbtab_g(dict, schema->name);
+              Ndb_table_guard ndbtab_g(ndb->getDictionary(), schema->name);
               ndbtab_g.invalidate();
             }
             TABLE_LIST table_list;
@@ -2777,7 +2785,7 @@ class Ndb_schema_event_handler {
           {
             print_could_not_discover_error(thd, schema);
           }
-          log_query= 1;
+          write_schema_op_to_binlog(thd, schema);
           break;
 
         case SOT_DROP_DB:
@@ -2790,7 +2798,7 @@ class Ndb_schema_event_handler {
                       schema->query + schema->query_length,
                       no_print_error);
             /* binlog dropping database after any table operations */
-            post_epoch_log_list->push_back(schema, mem_root);
+            log_after_epoch(schema);
             /* acknowledge this query _after_ epoch completion */
             post_epoch_unlock= 1;
           }
@@ -2801,7 +2809,7 @@ class Ndb_schema_event_handler {
                             "binlog schema event '%s' from node %d. ",
                             schema->db, schema->query,
                             schema->node_id);
-            log_query= 1;
+            write_schema_op_to_binlog(thd, schema);
           }
           break;
 
@@ -2813,7 +2821,7 @@ class Ndb_schema_event_handler {
           run_query(thd, schema->query,
                     schema->query + schema->query_length,
                     no_print_error);
-          log_query= 1;
+          write_schema_op_to_binlog(thd, schema);
           break;
         }
 
@@ -2834,13 +2842,13 @@ class Ndb_schema_event_handler {
           run_query(thd, cmd,
                     cmd + strlen(cmd),
                     no_print_error);
-          log_query= 1;
+          write_schema_op_to_binlog(thd, schema);
 	  break;
         }
 
         case SOT_TABLESPACE:
         case SOT_LOGFILE_GROUP:
-          log_query= 1;
+          write_schema_op_to_binlog(thd, schema);
           break;
 
         case SOT_ALTER_TABLE_COMMIT:
@@ -2854,124 +2862,18 @@ class Ndb_schema_event_handler {
           break;
 
         }
-        if (log_query)
-          write_schema_op_to_binlog(thd, schema);
+
         /* signal that schema operation has been handled */
         DBUG_DUMP("slock", (uchar*) schema->slock_buf, schema->slock_length);
         if (bitmap_is_set(&schema->slock, node_id))
         {
           if (post_epoch_unlock)
-            post_epoch_unlock_list->push_back(schema, mem_root);
+            unlock_after_epoch(schema);
           else
             ndbcluster_update_slock(thd, schema->db, schema->name,
                                     schema->id, schema->version);
         }
       }
-      DBUG_RETURN(0);
-    }
-    /*
-      the normal case of UPDATE/INSERT has already been handled
-    */
-    switch (ev_type)
-    {
-    case NDBEVENT::TE_DELETE:
-      // skip
-      break;
-    case NDBEVENT::TE_CLUSTER_FAILURE:
-      if (opt_ndb_extra_logging)
-        sql_print_information("NDB Binlog: cluster failure for %s at epoch %u/%u.",
-                              ndb_schema_share->key,
-                              (uint)(pOp->getGCI() >> 32),
-                              (uint)(pOp->getGCI()));
-      // fall through
-    case NDBEVENT::TE_DROP:
-      if (opt_ndb_extra_logging &&
-          ndb_binlog_tables_inited && ndb_binlog_running)
-        sql_print_information("NDB Binlog: ndb tables initially "
-                              "read only on reconnect.");
-
-      /* begin protect ndb_schema_share */
-      pthread_mutex_lock(&ndb_schema_share_mutex);
-      /* ndb_share reference binlog extra free */
-      DBUG_PRINT("NDB_SHARE", ("%s binlog extra free  use_count: %u",
-                               ndb_schema_share->key,
-                               ndb_schema_share->use_count));
-      free_share(&ndb_schema_share);
-      ndb_schema_share= 0;
-      ndb_binlog_tables_inited= FALSE;
-      ndb_binlog_is_ready= FALSE;
-      pthread_mutex_unlock(&ndb_schema_share_mutex);
-      /* end protect ndb_schema_share */
-
-      close_cached_tables(NULL, NULL, FALSE, FALSE, FALSE);
-      // fall through
-    case NDBEVENT::TE_ALTER:
-      ndb_handle_schema_change(thd, s_ndb, pOp, event_data);
-      break;
-    case NDBEVENT::TE_NODE_FAILURE:
-    {
-      uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()];
-      DBUG_ASSERT(node_id != 0xFF);
-      pthread_mutex_lock(&tmp_share->mutex);
-      bitmap_clear_all(&tmp_share->subscriber_bitmap[node_id]);
-      DBUG_PRINT("info",("NODE_FAILURE UNSUBSCRIBE[%d]", node_id));
-      if (opt_ndb_extra_logging)
-      {
-        sql_print_information("NDB Binlog: Node: %d, down,"
-                              " Subscriber bitmask %x%x",
-                              pOp->getNdbdNodeId(),
-                              tmp_share->subscriber_bitmap[node_id].bitmap[1],
-                              tmp_share->subscriber_bitmap[node_id].bitmap[0]);
-      }
-      pthread_mutex_unlock(&tmp_share->mutex);
-      (void) pthread_cond_signal(&injector_cond);
-      break;
-    }
-    case NDBEVENT::TE_SUBSCRIBE:
-    {
-      uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()];
-      uint8 req_id= pOp->getReqNodeId();
-      DBUG_ASSERT(req_id != 0 && node_id != 0xFF);
-      pthread_mutex_lock(&tmp_share->mutex);
-      bitmap_set_bit(&tmp_share->subscriber_bitmap[node_id], req_id);
-      DBUG_PRINT("info",("SUBSCRIBE[%d] %d", node_id, req_id));
-      if (opt_ndb_extra_logging)
-      {
-        sql_print_information("NDB Binlog: Node: %d, subscribe from node %d,"
-                              " Subscriber bitmask %x%x",
-                              pOp->getNdbdNodeId(),
-                              req_id,
-                              tmp_share->subscriber_bitmap[node_id].bitmap[1],
-                              tmp_share->subscriber_bitmap[node_id].bitmap[0]);
-      }
-      pthread_mutex_unlock(&tmp_share->mutex);
-      (void) pthread_cond_signal(&injector_cond);
-      break;
-    }
-    case NDBEVENT::TE_UNSUBSCRIBE:
-    {
-      uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()];
-      uint8 req_id= pOp->getReqNodeId();
-      DBUG_ASSERT(req_id != 0 && node_id != 0xFF);
-      pthread_mutex_lock(&tmp_share->mutex);
-      bitmap_clear_bit(&tmp_share->subscriber_bitmap[node_id], req_id);
-      DBUG_PRINT("info",("UNSUBSCRIBE[%d] %d", node_id, req_id));
-      if (opt_ndb_extra_logging)
-      {
-        sql_print_information("NDB Binlog: Node: %d, unsubscribe from node %d,"
-                              " Subscriber bitmask %x%x",
-                              pOp->getNdbdNodeId(),
-                              req_id,
-                              tmp_share->subscriber_bitmap[node_id].bitmap[1],
-                              tmp_share->subscriber_bitmap[node_id].bitmap[0]);
-      }
-      pthread_mutex_unlock(&tmp_share->mutex);
-      (void) pthread_cond_signal(&injector_cond);
-      break;
-    }
-    default:
-      sql_print_error("NDB Binlog: unknown non data event %d for %s. "
-                      "Ignoring...", (unsigned) ev_type, tmp_share->key);
     }
     DBUG_RETURN(0);
   }
@@ -3400,10 +3302,126 @@ public:
     if (!check_is_ndb_schema_event(event_data))
       DBUG_VOID_RETURN;
 
-    handle_schema_event(m_thd, s_ndb, pOp,
-                        &m_post_epoch_log_list,
-                        &m_post_epoch_unlock_list,
-                        m_mem_root);
+    const NDBEVENT::TableEvent ev_type= pOp->getEventType();
+    switch (ev_type)
+    {
+    case NDBEVENT::TE_INSERT:
+    case NDBEVENT::TE_UPDATE:
+      /* ndb_schema table, row INSERTed or UPDATEed*/
+      handle_schema_op(m_thd, s_ndb, pOp);
+      break;
+
+    case NDBEVENT::TE_DELETE:
+      /* ndb_schema table, row delete */
+      break;
+
+    case NDBEVENT::TE_CLUSTER_FAILURE:
+      if (opt_ndb_extra_logging)
+        sql_print_information("NDB Binlog: cluster failure for %s at epoch %u/%u.",
+                              ndb_schema_share->key,
+                              (uint)(pOp->getGCI() >> 32),
+                              (uint)(pOp->getGCI()));
+      // fall through
+    case NDBEVENT::TE_DROP:
+      /* ndb_schema table DROPped */
+      if (opt_ndb_extra_logging &&
+          ndb_binlog_tables_inited && ndb_binlog_running)
+        sql_print_information("NDB Binlog: ndb tables initially "
+                              "read only on reconnect.");
+
+      /* release the ndb_schema_share */
+      pthread_mutex_lock(&ndb_schema_share_mutex);
+      free_share(&ndb_schema_share);
+      ndb_schema_share= 0;
+      ndb_binlog_tables_inited= FALSE;
+      ndb_binlog_is_ready= FALSE;
+      pthread_mutex_unlock(&ndb_schema_share_mutex);
+
+      close_cached_tables(NULL, NULL, FALSE, FALSE, FALSE);
+      // fall through
+    case NDBEVENT::TE_ALTER:
+      /* ndb_schema table ALTERed */
+      ndb_handle_schema_change(m_thd, s_ndb, pOp, event_data);
+      break;
+
+    case NDBEVENT::TE_NODE_FAILURE:
+    {
+      /* Remove all subscribers for node from bitmap in ndb_schema_share */
+      NDB_SHARE *tmp_share= event_data->share;
+      uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()];
+      DBUG_ASSERT(node_id != 0xFF);
+      pthread_mutex_lock(&tmp_share->mutex);
+      bitmap_clear_all(&tmp_share->subscriber_bitmap[node_id]);
+      DBUG_PRINT("info",("NODE_FAILURE UNSUBSCRIBE[%d]", node_id));
+      if (opt_ndb_extra_logging)
+      {
+        sql_print_information("NDB Binlog: Node: %d, down,"
+                              " Subscriber bitmask %x%x",
+                              pOp->getNdbdNodeId(),
+                              tmp_share->subscriber_bitmap[node_id].bitmap[1],
+                              tmp_share->subscriber_bitmap[node_id].bitmap[0]);
+      }
+      pthread_mutex_unlock(&tmp_share->mutex);
+      (void) pthread_cond_signal(&injector_cond);
+      break;
+    }
+
+    case NDBEVENT::TE_SUBSCRIBE:
+    {
+      /* Add node as subscriber from bitmap in ndb_schema_share */
+      NDB_SHARE *tmp_share= event_data->share;
+      uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()];
+      uint8 req_id= pOp->getReqNodeId();
+      DBUG_ASSERT(req_id != 0 && node_id != 0xFF);
+      pthread_mutex_lock(&tmp_share->mutex);
+      bitmap_set_bit(&tmp_share->subscriber_bitmap[node_id], req_id);
+      DBUG_PRINT("info",("SUBSCRIBE[%d] %d", node_id, req_id));
+      if (opt_ndb_extra_logging)
+      {
+        sql_print_information("NDB Binlog: Node: %d, subscribe from node %d,"
+                              " Subscriber bitmask %x%x",
+                              pOp->getNdbdNodeId(),
+                              req_id,
+                              tmp_share->subscriber_bitmap[node_id].bitmap[1],
+                              tmp_share->subscriber_bitmap[node_id].bitmap[0]);
+      }
+      pthread_mutex_unlock(&tmp_share->mutex);
+      (void) pthread_cond_signal(&injector_cond);
+      break;
+    }
+
+    case NDBEVENT::TE_UNSUBSCRIBE:
+    {
+      /* Remove node as subscriber from bitmap in ndb_schema_share */
+      NDB_SHARE *tmp_share= event_data->share;
+      uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()];
+      uint8 req_id= pOp->getReqNodeId();
+      DBUG_ASSERT(req_id != 0 && node_id != 0xFF);
+      pthread_mutex_lock(&tmp_share->mutex);
+      bitmap_clear_bit(&tmp_share->subscriber_bitmap[node_id], req_id);
+      DBUG_PRINT("info",("UNSUBSCRIBE[%d] %d", node_id, req_id));
+      if (opt_ndb_extra_logging)
+      {
+        sql_print_information("NDB Binlog: Node: %d, unsubscribe from node %d,"
+                              " Subscriber bitmask %x%x",
+                              pOp->getNdbdNodeId(),
+                              req_id,
+                              tmp_share->subscriber_bitmap[node_id].bitmap[1],
+                              tmp_share->subscriber_bitmap[node_id].bitmap[0]);
+      }
+      pthread_mutex_unlock(&tmp_share->mutex);
+      (void) pthread_cond_signal(&injector_cond);
+      break;
+    }
+
+    default:
+    {
+      NDB_SHARE *tmp_share= event_data->share;
+      sql_print_error("NDB Binlog: unknown non data event %d for %s. "
+                      "Ignoring...", (unsigned) ev_type, tmp_share->key);
+    }
+    }
+
     DBUG_VOID_RETURN;
   }
 

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.5-cluster branch (magnus.blaudd:3645 to 3650) Magnus Blåudd1 Nov