3667 Magnus Blåudd 2011-10-31
ndb schema dist
- put the NDB_SCHEMA_OBJECT and it's hash in a seprate file.
- add comment desrcibing what NDB_SCHEM_OBJECT is used for.
added:
sql/ndb_schema_object.cc
sql/ndb_schema_object.h
modified:
sql/ha_ndbcluster_binlog.cc
storage/ndb/CMakeLists.txt
3666 Magnus Blåudd 2011-10-29
ndb schema dist
- move 'ndbcluster_check_if_local_tables_in_db' into the Ndb_schema_event_handler class
modified:
sql/ha_ndbcluster_binlog.cc
sql/ha_ndbcluster_binlog.h
=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc 2011-10-29 14:21:55 +0000
+++ b/sql/ha_ndbcluster_binlog.cc 2011-10-31 12:39:50 +0000
@@ -59,6 +59,7 @@ bool ndb_log_empty_epochs(void);
#include "ndb_anyvalue.h"
#include "ndb_binlog_extra_row_info.h"
#include "ndb_event_data.h"
+#include "ndb_schema_object.h"
/*
Timeout for syncing schema events between
@@ -158,24 +159,6 @@ static pthread_mutex_t ndb_schema_share_
extern my_bool opt_log_slave_updates;
static my_bool g_ndb_log_slave_updates;
-/* 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
- uint32 table_id;
- uint32 table_version;
-} 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);
-
#ifndef DBUG_OFF
/* purecov: begin deadcode */
static void print_records(TABLE *table, const uchar *record)
@@ -2914,8 +2897,7 @@ class Ndb_schema_event_handler {
/* Ack to any SQL thread waiting for schema op to complete */
pthread_mutex_lock(&ndbcluster_mutex);
NDB_SCHEMA_OBJECT *ndb_schema_object=
- (NDB_SCHEMA_OBJECT*) my_hash_search(&ndb_schema_objects,
- (const uchar*) key, strlen(key));
+ ndb_get_schema_object(key, false, true);
if (ndb_schema_object &&
(ndb_schema_object->table_id == schema->id &&
ndb_schema_object->table_version == schema->version))
@@ -6491,93 +6473,6 @@ handle_data_event(THD* thd, Ndb *ndb, Nd
Injector thread main loop
****************************************************************/
-static uchar *
-ndb_schema_objects_get_key(NDB_SCHEMA_OBJECT *schema_object,
- size_t *length,
- my_bool not_used __attribute__((unused)))
-{
- *length= schema_object->key_length;
- return (uchar*) 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*) my_hash_search(&ndb_schema_objects,
- (const uchar*) 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, (uchar*) ndb_schema_object))
- {
- my_free((uchar*) 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));
- my_hash_delete(&ndb_schema_objects, (uchar*) *ndb_schema_object);
- pthread_mutex_destroy(&(*ndb_schema_object)->mutex);
- my_free((uchar*) *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;
-}
-
-
static void
remove_event_operations(Ndb* ndb)
{
@@ -6749,10 +6644,6 @@ restart_cluster_failure:
goto err;
}
- /* init hash for schema object distribution */
- (void) my_hash_init(&ndb_schema_objects, system_charset_info, 32, 0, 0,
- (my_hash_get_key)ndb_schema_objects_get_key, 0, 0);
-
/*
Expose global reference to our ndb object.
@@ -7541,8 +7432,6 @@ restart_cluster_failure:
i_ndb= 0;
}
- my_hash_free(&ndb_schema_objects);
-
if (thd_ndb)
{
Thd_ndb::release(thd_ndb);
=== added file 'sql/ndb_schema_object.cc'
--- a/sql/ndb_schema_object.cc 1970-01-01 00:00:00 +0000
+++ b/sql/ndb_schema_object.cc 2011-10-31 12:39:50 +0000
@@ -0,0 +1,129 @@
+/*
+ Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "ndb_schema_object.h"
+
+#include "hash.h"
+
+
+extern pthread_mutex_t ndbcluster_mutex;
+
+
+static uchar *
+ndb_schema_objects_get_key(NDB_SCHEMA_OBJECT *schema_object,
+ size_t *length,
+ my_bool)
+{
+ *length= schema_object->key_length;
+ return (uchar*) schema_object->key;
+}
+
+class Ndb_schema_objects
+{
+public:
+ HASH m_hash;
+ Ndb_schema_objects()
+ {
+ (void)my_hash_init(&m_hash, &my_charset_bin, 1, 0, 0,
+ (my_hash_get_key)ndb_schema_objects_get_key, 0, 0);
+ }
+
+ ~Ndb_schema_objects()
+ {
+ my_hash_free(&m_hash);
+ }
+
+} ndb_schema_objects;
+
+
+NDB_SCHEMA_OBJECT *ndb_get_schema_object(const char *key,
+ bool create_if_not_exists,
+ 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*) my_hash_search(&ndb_schema_objects.m_hash,
+ (const uchar*) 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.m_hash, (uchar*) ndb_schema_object))
+ {
+ my_free(ndb_schema_object);
+ 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);
+}
+
+
+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));
+ my_hash_delete(&ndb_schema_objects.m_hash, (uchar*) *ndb_schema_object);
+ pthread_mutex_destroy(&(*ndb_schema_object)->mutex);
+ my_free(*ndb_schema_object);
+ *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;
+}
=== added file 'sql/ndb_schema_object.h'
--- a/sql/ndb_schema_object.h 1970-01-01 00:00:00 +0000
+++ b/sql/ndb_schema_object.h 2011-10-31 12:39:50 +0000
@@ -0,0 +1,55 @@
+/*
+ Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef NDB_SCHEMA_OBJECT_H
+#define NDB_SCHEMA_OBJECT_H
+
+/*
+ Used for communication between the SQL thread performing
+ a schema operation and the schema disctribution thread.
+
+ The SQL thread creates one NDB_SCHEMA_OBJECT in the hash and
+ when the schema distribution thread has received new events it will
+ update the entry with slock info from the other nodes in the
+ cluster, finally the slock bitmap will empty and the SQL thread
+ knows that the schema operation has completed and will delete
+ the entry.
+*/
+
+
+#include <my_pthread.h> // my_bitmap.h
+#include <my_bitmap.h>
+
+struct 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
+ uint32 table_id;
+ uint32 table_version;
+};
+
+NDB_SCHEMA_OBJECT *ndb_get_schema_object(const char *key,
+ bool create_if_not_exists,
+ bool have_lock);
+
+void ndb_free_schema_object(NDB_SCHEMA_OBJECT **ndb_schema_object,
+ bool have_lock);
+
+#endif
=== modified file 'storage/ndb/CMakeLists.txt'
--- a/storage/ndb/CMakeLists.txt 2011-10-29 09:02:21 +0000
+++ b/storage/ndb/CMakeLists.txt 2011-10-31 12:39:50 +0000
@@ -84,6 +84,7 @@ SET(NDBCLUSTER_SOURCES
../../sql/ndb_ndbapi_util.cc
../../sql/ndb_binlog_extra_row_info.cc
../../sql/ndb_event_data.cc
+ ../../sql/ndb_schema_object.cc
)
# Include directories used when building ha_ndbcluster
No bundle (reason: useless for push emails).| Thread |
|---|
| • bzr push into mysql-5.5-cluster branch (magnus.blaudd:3666 to 3667) | Magnus Blåudd | 1 Nov |