MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:tomas Date:April 3 2006 5:11pm
Subject:bk commit into 5.1 tree (tomas:1.2279) BUG#18596
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of tomas. When tomas does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2279 06/04/03 19:11:20 tomas@stripped +2 -0
  Bug #18596 binlog schema event auto push causes mysqld errors
  - move slock bitmask to separate hash list, object living only during query

  sql/ha_ndbcluster_binlog.cc
    1.41 06/04/03 19:11:11 tomas@stripped +162 -65
    Bug #18596 binlog schema event auto push causes mysqld errors
    - move slock bitmask to separate hash list, object living only during query

  sql/ha_ndbcluster.h
    1.129 06/04/03 19:11:11 tomas@stripped +0 -2
    Bug #18596 binlog schema event auto push causes mysqld errors

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	tomas
# Host:	poseidon.ndb.mysql.com
# Root:	/home/tomas/mysql-5.1-new

--- 1.128/sql/ha_ndbcluster.h	2006-03-24 10:42:17 +01:00
+++ 1.129/sql/ha_ndbcluster.h	2006-04-03 19:11:11 +02:00
@@ -115,8 +115,6 @@
   TABLE *table;
   NdbValue *ndb_value[2];
   MY_BITMAP *subscriber_bitmap;
-  MY_BITMAP slock_bitmap;
-  uint32 slock[256/32]; // 256 bits for lock status of table
 #endif
 } NDB_SHARE;
 

--- 1.40/sql/ha_ndbcluster_binlog.cc	2006-03-24 10:12:26 +01:00
+++ 1.41/sql/ha_ndbcluster_binlog.cc	2006-04-03 19:11:11 +02:00
@@ -86,6 +86,22 @@
 NDB_SHARE *apply_status_share= 0;
 NDB_SHARE *schema_share= 0;
 
+/* Schema object distribution handling */
+HASH ndb_schema_objects;
+typedef struct st_ndb_schema_object {
+  pthread_mutex_t mutex;
+  char *key;
+  uint key_length;
+  uint use_count;
+  MY_BITMAP slock_bitmap;
+  uint32 slock[256/32]; // 256 bits for lock status of table
+} NDB_SCHEMA_OBJECT;
+static NDB_SCHEMA_OBJECT *ndb_get_schema_object(const char *key,
+                                                my_bool create_if_not_exists,
+                                                my_bool have_lock);
+static void ndb_free_schema_object(NDB_SCHEMA_OBJECT **ndb_schema_object,
+                                   bool have_lock);
+
 /* instantiated in storage/ndb/src/ndbapi/Ndbif.cpp */
 extern Uint64 g_latest_trans_gci;
 
@@ -328,9 +344,6 @@
                   max_ndb_nodes, false);
       bitmap_clear_all(&share->subscriber_bitmap[i]);
     }
-    bitmap_init(&share->slock_bitmap, share->slock,
-                sizeof(share->slock)*8, false);
-    bitmap_clear_all(&share->slock_bitmap);
   }
 
   if (!do_event_op)
@@ -952,7 +965,6 @@
   }
 
   char tmp_buf2[FN_REFLEN];
-  int get_a_share= 0;
   switch (type)
   {
   case SOT_DROP_TABLE:
@@ -963,8 +975,6 @@
     query= tmp_buf2;
     query_length= (uint) (strxmov(tmp_buf2, "drop table `",
                                   table_name, "`", NullS) - tmp_buf2);
-    if (!share)
-      get_a_share= 1;
     break;
   case SOT_RENAME_TABLE:
     /* redo the rename table query as is may contain several tables */
@@ -972,14 +982,10 @@
     query_length= (uint) (strxmov(tmp_buf2, "rename table `",
                                   old_db, ".", old_table_name, "` to `",
                                   db, ".", table_name, "`", NullS) - tmp_buf2);
-    if (!share)
-      get_a_share= 1;
     break;
   case SOT_CREATE_TABLE:
     // fall through
   case SOT_ALTER_TABLE:
-    if (!share)
-      get_a_share= 1;
     break;
   case SOT_DROP_DB:
     break;
@@ -995,18 +1001,18 @@
     abort(); /* should not happen, programming error */
   }
 
-  if (get_a_share)
+  NDB_SCHEMA_OBJECT *ndb_schema_object;
   {
     char key[FN_REFLEN];
     build_table_filename(key, sizeof(key), db, table_name, "");
-    share= get_share(key, 0, false, false);
+    ndb_schema_object= ndb_get_schema_object(key, TRUE, FALSE);
   }
 
   const NdbError *ndb_error= 0;
   uint32 node_id= g_ndb_cluster_connection->node_id();
   Uint64 epoch= 0;
   MY_BITMAP schema_subscribers;
-  uint32 bitbuf[sizeof(schema_share->slock)/4];
+  uint32 bitbuf[sizeof(ndb_schema_object->slock)/4];
   {
     int i;
     bitmap_init(&schema_subscribers, bitbuf, sizeof(bitbuf)*8, false);
@@ -1022,11 +1028,12 @@
     (void) pthread_mutex_unlock(&schema_share->mutex);
     bitmap_clear_bit(&schema_subscribers, node_id);
       
-    if (share)
+    if (ndb_schema_object)
     {
-      (void) pthread_mutex_lock(&share->mutex);
-      memcpy(share->slock, schema_subscribers.bitmap, sizeof(share->slock));
-      (void) pthread_mutex_unlock(&share->mutex);
+      (void) pthread_mutex_lock(&ndb_schema_object->mutex);
+      memcpy(ndb_schema_object->slock, schema_subscribers.bitmap,
+             sizeof(ndb_schema_object->slock));
+      (void) pthread_mutex_unlock(&ndb_schema_object->mutex);
     }
 
     DBUG_DUMP("schema_subscribers", (char*)schema_subscribers.bitmap,
@@ -1158,20 +1165,17 @@
     Wait for other mysqld's to acknowledge the table operation
   */
   if (ndb_error == 0 &&
-      (type == SOT_CREATE_TABLE ||
-       type == SOT_RENAME_TABLE ||
-       type == SOT_ALTER_TABLE) &&
       !bitmap_is_clear_all(&schema_subscribers))
   {
     int max_timeout= 10;
-    (void) pthread_mutex_lock(&share->mutex);
+    (void) pthread_mutex_lock(&ndb_schema_object->mutex);
     while (1)
     {
       struct timespec abstime;
       int i;
       set_timespec(abstime, 1);
       (void) pthread_cond_timedwait(&injector_cond,
-                                    &share->mutex,
+                                    &ndb_schema_object->mutex,
                                     &abstime);
 
       (void) pthread_mutex_lock(&schema_share->mutex);
@@ -1184,14 +1188,14 @@
       }
       (void) pthread_mutex_unlock(&schema_share->mutex);
 
-      /* remove any unsubscribed from share->slock */
-      bitmap_intersect(&share->slock_bitmap, &schema_subscribers);
+      /* remove any unsubscribed from ndb_schema_object->slock */
+      bitmap_intersect(&ndb_schema_object->slock_bitmap, &schema_subscribers);
 
-      DBUG_DUMP("share->slock_bitmap.bitmap",
-                (char*)share->slock_bitmap.bitmap,
-                no_bytes_in_map(&share->slock_bitmap));
+      DBUG_DUMP("ndb_schema_object->slock_bitmap.bitmap",
+                (char*)ndb_schema_object->slock_bitmap.bitmap,
+                no_bytes_in_map(&ndb_schema_object->slock_bitmap));
 
-      if (bitmap_is_clear_all(&share->slock_bitmap))
+      if (bitmap_is_clear_all(&ndb_schema_object->slock_bitmap))
         break;
 
       max_timeout--;
@@ -1203,16 +1207,13 @@
       if (ndb_extra_logging)
         sql_print_information("NDB create table: "
                               "waiting max %u sec for create table %s.",
-                              max_timeout, share->key);
+                              max_timeout, ndb_schema_object->key);
     }
-    (void) pthread_mutex_unlock(&share->mutex);
+    (void) pthread_mutex_unlock(&ndb_schema_object->mutex);
   }
 
-  if (get_a_share && share)
-  {
-    free_share(&share);
-    share= 0;
-  }
+  if (ndb_schema_object)
+    ndb_free_schema_object(&ndb_schema_object, FALSE);
 
   DBUG_RETURN(0);
 }
@@ -1529,12 +1530,12 @@
                                       MEM_ROOT *mem_root)
 {
   DBUG_ENTER("ndb_binlog_thread_handle_schema_event");
-  NDB_SHARE *share= (NDB_SHARE *)pOp->getCustomData();
-  if (share && schema_share == share)
+  NDB_SHARE *tmp_share= (NDB_SHARE *)pOp->getCustomData();
+  if (tmp_share && schema_share == tmp_share)
   {
     NDBEVENT::TableEvent ev_type= pOp->getEventType();
     DBUG_PRINT("enter", ("%s.%s  ev_type: %d",
-                         share->db, share->table_name, ev_type));
+                         tmp_share->db, tmp_share->table_name, ev_type));
     if (ev_type == NDBEVENT::TE_UPDATE ||
         ev_type == NDBEVENT::TE_INSERT)
     {
@@ -1543,7 +1544,7 @@
       MY_BITMAP slock;
       bitmap_init(&slock, schema->slock, 8*SCHEMA_SLOCK_SIZE, false);
       uint node_id= g_ndb_cluster_connection->node_id();
-      ndbcluster_get_schema(share, schema);
+      ndbcluster_get_schema(tmp_share, schema);
       if (schema->node_id != node_id)
       {
         int log_query= 0, post_epoch_unlock= 0;
@@ -1628,18 +1629,24 @@
           break;
         case SOT_CLEAR_SLOCK:
         {
-          if (share)
+          pthread_mutex_lock(&ndbcluster_mutex);
+          NDB_SCHEMA_OBJECT *ndb_schema_object=
+            (NDB_SCHEMA_OBJECT*) hash_search(&ndb_schema_objects,
+                                             (byte*) key, strlen(key));
+          if (ndb_schema_object)
           {
-            pthread_mutex_lock(&share->mutex);
-            memcpy(share->slock, schema->slock, sizeof(share->slock));
-            DBUG_DUMP("share->slock_bitmap.bitmap",
-                      (char*)share->slock_bitmap.bitmap,
-                      no_bytes_in_map(&share->slock_bitmap));
-            pthread_mutex_unlock(&share->mutex);
+            pthread_mutex_lock(&ndb_schema_object->mutex);
+            memcpy(ndb_schema_object->slock, schema->slock,
+                   sizeof(ndb_schema_object->slock));
+            DBUG_DUMP("ndb_schema_object->slock_bitmap.bitmap",
+                      (char*)ndb_schema_object->slock_bitmap.bitmap,
+                      no_bytes_in_map(&ndb_schema_object->slock_bitmap));
+            pthread_mutex_unlock(&ndb_schema_object->mutex);
             pthread_cond_signal(&injector_cond);
-            free_share(&share);
-            share= 0;
           }
+          if (share)
+            free_share(&share, TRUE);
+          pthread_mutex_unlock(&ndbcluster_mutex);
           DBUG_RETURN(0);
         }
         case SOT_TABLESPACE:
@@ -1687,24 +1694,24 @@
       schema_share= 0;
       // fall through
     case NDBEVENT::TE_ALTER:
-      ndb_handle_schema_change(thd, ndb, pOp, share);
+      ndb_handle_schema_change(thd, ndb, pOp, tmp_share);
       break;
     case NDBEVENT::TE_NODE_FAILURE:
     {
       uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()];
       DBUG_ASSERT(node_id != 0xFF);
-      (void) pthread_mutex_lock(&share->mutex);
-      bitmap_clear_all(&share->subscriber_bitmap[node_id]);
+      (void) 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 (ndb_extra_logging)
       {
         sql_print_information("NDB Binlog: Node: %d, down,"
                               " Subscriber bitmask %x%x",
                               pOp->getNdbdNodeId(),
-                              share->subscriber_bitmap[node_id].bitmap[1],
-                              share->subscriber_bitmap[node_id].bitmap[0]);
+                              tmp_share->subscriber_bitmap[node_id].bitmap[1],
+                              tmp_share->subscriber_bitmap[node_id].bitmap[0]);
       }
-      (void) pthread_mutex_unlock(&share->mutex);
+      (void) pthread_mutex_unlock(&tmp_share->mutex);
       (void) pthread_cond_signal(&injector_cond);
       break;
     }
@@ -1713,8 +1720,8 @@
       uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()];
       uint8 req_id= pOp->getReqNodeId();
       DBUG_ASSERT(req_id != 0 && node_id != 0xFF);
-      (void) pthread_mutex_lock(&share->mutex);
-      bitmap_set_bit(&share->subscriber_bitmap[node_id], req_id);
+      (void) 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 (ndb_extra_logging)
       {
@@ -1722,10 +1729,10 @@
                               " Subscriber bitmask %x%x",
                               pOp->getNdbdNodeId(),
                               req_id,
-                              share->subscriber_bitmap[node_id].bitmap[1],
-                              share->subscriber_bitmap[node_id].bitmap[0]);
+                              tmp_share->subscriber_bitmap[node_id].bitmap[1],
+                              tmp_share->subscriber_bitmap[node_id].bitmap[0]);
       }
-      (void) pthread_mutex_unlock(&share->mutex);
+      (void) pthread_mutex_unlock(&tmp_share->mutex);
       (void) pthread_cond_signal(&injector_cond);
       break;
     }
@@ -1734,8 +1741,8 @@
       uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()];
       uint8 req_id= pOp->getReqNodeId();
       DBUG_ASSERT(req_id != 0 && node_id != 0xFF);
-      (void) pthread_mutex_lock(&share->mutex);
-      bitmap_clear_bit(&share->subscriber_bitmap[node_id], req_id);
+      (void) 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 (ndb_extra_logging)
       {
@@ -1743,16 +1750,16 @@
                               " Subscriber bitmask %x%x",
                               pOp->getNdbdNodeId(),
                               req_id,
-                              share->subscriber_bitmap[node_id].bitmap[1],
-                              share->subscriber_bitmap[node_id].bitmap[0]);
+                              tmp_share->subscriber_bitmap[node_id].bitmap[1],
+                              tmp_share->subscriber_bitmap[node_id].bitmap[0]);
       }
-      (void) pthread_mutex_unlock(&share->mutex);
+      (void) 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, share->key);
+                      "Ignoring...", (unsigned) ev_type, tmp_share->key);
     }
   }
   DBUG_RETURN(0);
@@ -2888,6 +2895,90 @@
   Injector thread main loop
 ****************************************************************/
 
+static byte *ndb_schema_objects_get_key(NDB_SCHEMA_OBJECT *schema_object, uint *length,
+                                        my_bool not_used __attribute__((unused)))
+{
+  *length= schema_object->key_length;
+  return (byte*) schema_object->key;
+}
+
+static NDB_SCHEMA_OBJECT *ndb_get_schema_object(const char *key,
+                                                my_bool create_if_not_exists,
+                                                my_bool have_lock)
+{
+  NDB_SCHEMA_OBJECT *ndb_schema_object;
+  uint length= (uint) strlen(key);
+  DBUG_ENTER("ndb_get_schema_object");
+  DBUG_PRINT("enter", ("key: '%s'", key));
+
+  if (!have_lock)
+    pthread_mutex_lock(&ndbcluster_mutex);
+  while (!(ndb_schema_object=
+           (NDB_SCHEMA_OBJECT*) hash_search(&ndb_schema_objects,
+                                            (byte*) key,
+                                            length)))
+  {
+    if (!create_if_not_exists)
+    {
+      DBUG_PRINT("info", ("does not exist"));
+      break;
+    }
+    if (!(ndb_schema_object=
+          (NDB_SCHEMA_OBJECT*) my_malloc(sizeof(*ndb_schema_object) + length + 1,
+                                         MYF(MY_WME | MY_ZEROFILL))))
+    {
+      DBUG_PRINT("info", ("malloc error"));
+      break;
+    }
+    ndb_schema_object->key= (char *)(ndb_schema_object+1);
+    memcpy(ndb_schema_object->key, key, length + 1);
+    ndb_schema_object->key_length= length;
+    if (my_hash_insert(&ndb_schema_objects, (byte*) ndb_schema_object))
+    {
+      my_free((gptr) ndb_schema_object, 0);
+      break;
+    }
+    pthread_mutex_init(&ndb_schema_object->mutex, MY_MUTEX_INIT_FAST);
+    bitmap_init(&ndb_schema_object->slock_bitmap, ndb_schema_object->slock,
+                sizeof(ndb_schema_object->slock)*8, false);
+    bitmap_clear_all(&ndb_schema_object->slock_bitmap);
+    break;
+  }
+  if (ndb_schema_object)
+  {
+    ndb_schema_object->use_count++;
+    DBUG_PRINT("info", ("use_count: %d", ndb_schema_object->use_count));
+  }
+  if (!have_lock)
+    pthread_mutex_unlock(&ndbcluster_mutex);
+  DBUG_RETURN(ndb_schema_object);
+}
+
+
+static void ndb_free_schema_object(NDB_SCHEMA_OBJECT **ndb_schema_object,
+                                   bool have_lock)
+{
+  DBUG_ENTER("ndb_free_schema_object");
+  DBUG_PRINT("enter", ("key: '%s'", (*ndb_schema_object)->key));
+  if (!have_lock)
+    pthread_mutex_lock(&ndbcluster_mutex);
+  if (!--(*ndb_schema_object)->use_count)
+  {
+    DBUG_PRINT("info", ("use_count: %d", (*ndb_schema_object)->use_count));
+    hash_delete(&ndb_schema_objects, (byte*) *ndb_schema_object);
+    pthread_mutex_destroy(&(*ndb_schema_object)->mutex);
+    my_free((gptr) *ndb_schema_object, MYF(0));
+    *ndb_schema_object= 0;
+  }
+  else
+  {
+    DBUG_PRINT("info", ("use_count: %d", (*ndb_schema_object)->use_count));
+  }
+  if (!have_lock)
+    pthread_mutex_unlock(&ndbcluster_mutex);
+  DBUG_VOID_RETURN;
+}
+
 pthread_handler_t ndb_binlog_thread_func(void *arg)
 {
   THD *thd; /* needs to be first for thread_stack */
@@ -2961,6 +3052,10 @@
     goto err;
   }
 
+  /* init hash for schema object distribution */
+  (void) hash_init(&ndb_schema_objects, system_charset_info, 32, 0, 0,
+                   (hash_get_key)ndb_schema_objects_get_key, 0, 0);
+
   /*
     Expose global reference to our ndb object.
 
@@ -3359,6 +3454,8 @@
     delete ndb;
     ndb= 0;
   }
+
+  hash_free(&ndb_schema_objects);
 
   // Placed here to avoid a memory leak; TODO: check if needed
   net_end(&thd->net);
Thread
bk commit into 5.1 tree (tomas:1.2279) BUG#18596tomas3 Apr