3645 magnus.blaudd@stripped 2011-11-09
ndb schema dist
- first step towards determing in one place if NDB_SHARE should subscribe
to events
- move as much as possible for initializing share into 'NDB_SHARE::create'
- share pointer is required both in 'ndbcluster_create_event' and 'ndbcluster_create_event_ops'
modified:
sql/ha_ndbcluster.cc
sql/ha_ndbcluster_binlog.cc
sql/ndb_share.cc
sql/ndb_share.h
3644 magnus.blaudd@stripped 2011-11-08
ndb schema dist
- factor out the code which creates a NDB_SHARE into 'NDB_SHARE::create'
modified:
sql/ha_ndbcluster.cc
sql/ndb_share.h
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc 2011-11-08 21:07:35 +0000
+++ b/sql/ha_ndbcluster.cc 2011-11-09 06:31:45 +0000
@@ -13608,6 +13608,7 @@ int ndbcluster_undo_rename_share(THD *th
return 0;
}
+
int ndbcluster_rename_share(THD *thd, NDB_SHARE *share)
{
NDB_SHARE *tmp;
@@ -13740,6 +13741,29 @@ NDB_SHARE::create(const char* key, size_
share->commit_count= 0;
share->commit_count_lock= 0;
+#ifdef HAVE_NDB_BINLOG
+ share->m_cfn_share= NULL;
+#endif
+
+ share->op= 0;
+ share->new_op= 0;
+ share->event_data= 0;
+
+ {
+ // Create array of bitmap for keeping track of subscribed nodes
+ // NOTE! Only the NDB_SHARE for ndb_schema really needs this
+ int no_nodes= g_ndb_cluster_connection->no_db_nodes();
+ share->subscriber_bitmap= (MY_BITMAP*)
+ alloc_root(&share->mem_root, no_nodes * sizeof(MY_BITMAP));
+ for (int i= 0; i < no_nodes; i++)
+ {
+ bitmap_init(&share->subscriber_bitmap[i],
+ (Uint32*)alloc_root(&share->mem_root, max_ndb_nodes/8),
+ max_ndb_nodes, FALSE);
+ bitmap_clear_all(&share->subscriber_bitmap[i]);
+ }
+ }
+
if (ndbcluster_binlog_init_share(current_thd, share, table))
{
DBUG_PRINT("error", ("get_share: %s could not init share", key));
=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc 2011-11-08 10:34:21 +0000
+++ b/sql/ha_ndbcluster_binlog.cc 2011-11-09 06:31:45 +0000
@@ -362,48 +362,9 @@ ndb_binlog_open_shadow_table(THD *thd, N
*/
int ndbcluster_binlog_init_share(THD *thd, NDB_SHARE *share, TABLE *_table)
{
- MEM_ROOT *mem_root= &share->mem_root;
- int do_event_op= ndb_binlog_running;
- int error= 0;
DBUG_ENTER("ndbcluster_binlog_init_share");
-#ifdef HAVE_NDB_BINLOG
- share->m_cfn_share= NULL;
-#endif
-
- share->op= 0;
- share->new_op= 0;
- share->event_data= 0;
-
- if (!ndb_schema_share &&
- strcmp(share->db, NDB_REP_DB) == 0 &&
- strcmp(share->table_name, NDB_SCHEMA_TABLE) == 0)
- do_event_op= 1;
- else if (!ndb_apply_status_share &&
- strcmp(share->db, NDB_REP_DB) == 0 &&
- strcmp(share->table_name, NDB_APPLY_TABLE) == 0)
- do_event_op= 1;
-
- if (Ndb_dist_priv_util::is_distributed_priv_table(share->db,
- share->table_name))
- {
- do_event_op= 0;
- }
-
- {
- int i, no_nodes= g_ndb_cluster_connection->no_db_nodes();
- share->subscriber_bitmap= (MY_BITMAP*)
- alloc_root(mem_root, no_nodes * sizeof(MY_BITMAP));
- for (i= 0; i < no_nodes; i++)
- {
- bitmap_init(&share->subscriber_bitmap[i],
- (Uint32*)alloc_root(mem_root, max_ndb_nodes/8),
- max_ndb_nodes, FALSE);
- bitmap_clear_all(&share->subscriber_bitmap[i]);
- }
- }
-
- if (!do_event_op)
+ if (!share->need_events(ndb_binlog_running))
{
if (_table)
{
@@ -416,7 +377,7 @@ int ndbcluster_binlog_init_share(THD *th
{
share->flags|= NSF_NO_BINLOG;
}
- DBUG_RETURN(error);
+ DBUG_RETURN(0);
}
DBUG_RETURN(ndb_binlog_open_shadow_table(thd, share));
@@ -2751,10 +2712,12 @@ class Ndb_schema_event_handler {
void
handle_offline_alter_table_commit(Ndb_schema_op* schema)
{
+ DBUG_ENTER("handle_offline_alter_table_commit");
+
assert(is_post_epoch()); // Always after epoch
if (schema->node_id == own_nodeid())
- return;
+ DBUG_VOID_RETURN;
write_schema_op_to_binlog(m_thd, schema);
ndbapi_invalidate_table(schema->db, schema->name);
@@ -2802,13 +2765,14 @@ class Ndb_schema_event_handler {
"from binlog schema event '%s' from node %d.",
schema->db, schema->name, schema->query,
schema->node_id);
- return;
+ DBUG_VOID_RETURN;
}
if (ndb_create_table_from_engine(m_thd, schema->db, schema->name))
{
print_could_not_discover_error(m_thd, schema);
}
+ DBUG_VOID_RETURN;
}
@@ -5147,7 +5111,6 @@ int ndbcluster_create_binlog_setup(THD *
const char *table_name,
TABLE * table)
{
- int do_event_op= ndb_binlog_running;
DBUG_ENTER("ndbcluster_create_binlog_setup");
DBUG_PRINT("enter",("key: %s key_len: %d %s.%s",
key, key_len, db, table_name));
@@ -5171,25 +5134,7 @@ int ndbcluster_create_binlog_setup(THD *
DBUG_RETURN(0); // replication already setup, or should not
}
- if (Ndb_dist_priv_util::is_distributed_priv_table(db, table_name))
- {
- // The distributed privilege tables are distributed by writing
- // the CREATE USER, GRANT, REVOKE etc. to ndb_schema -> no need
- // to listen to events from this table
- DBUG_PRINT("info", ("Skipping binlogging of table %s/%s", db, table_name));
- do_event_op= 0;
- }
-
- if (!ndb_schema_share &&
- strcmp(share->db, NDB_REP_DB) == 0 &&
- strcmp(share->table_name, NDB_SCHEMA_TABLE) == 0)
- do_event_op= 1;
- else if (!ndb_apply_status_share &&
- strcmp(share->db, NDB_REP_DB) == 0 &&
- strcmp(share->table_name, NDB_APPLY_TABLE) == 0)
- do_event_op= 1;
-
- if (!do_event_op)
+ if (!share->need_events(ndb_binlog_running))
{
set_binlog_nologging(share);
pthread_mutex_unlock(&share->mutex);
@@ -5296,11 +5241,8 @@ ndbcluster_create_event(THD *thd, Ndb *n
ndbtab->getName(), ndbtab->getObjectVersion(),
event_name, share ? share->key : "(nil)"));
DBUG_ASSERT(! IS_NDB_BLOB_PREFIX(ndbtab->getName()));
- if (!share)
- {
- DBUG_PRINT("info", ("share == NULL"));
- DBUG_RETURN(0);
- }
+ DBUG_ASSERT(share);
+
if (get_binlog_nologging(share))
{
if (opt_ndb_extra_logging && ndb_binlog_running)
@@ -5480,8 +5422,7 @@ ndbcluster_create_event_ops(THD *thd, ND
DBUG_ENTER("ndbcluster_create_event_ops");
DBUG_PRINT("enter", ("table: %s event: %s", ndbtab->getName(), event_name));
DBUG_ASSERT(! IS_NDB_BLOB_PREFIX(ndbtab->getName()));
-
- DBUG_ASSERT(share != 0);
+ DBUG_ASSERT(share);
if (get_binlog_nologging(share))
{
@@ -5495,7 +5436,6 @@ ndbcluster_create_event_ops(THD *thd, ND
assert(!Ndb_dist_priv_util::is_distributed_priv_table(share->db,
share->table_name));
- Ndb_event_data *event_data= share->event_data;
int do_ndb_schema_share= 0, do_ndb_apply_status_share= 0;
#ifdef HAVE_NDB_BINLOG
uint len= (int)strlen(share->table_name);
@@ -5520,6 +5460,10 @@ ndbcluster_create_event_ops(THD *thd, ND
DBUG_RETURN(0);
}
+ // Check that the share agrees
+ DBUG_ASSERT(share->need_events(ndb_binlog_running));
+
+ Ndb_event_data *event_data= share->event_data;
if (share->op)
{
event_data= (Ndb_event_data *) share->op->getCustomData();
=== modified file 'sql/ndb_share.cc'
--- a/sql/ndb_share.cc 2011-11-07 19:00:35 +0000
+++ b/sql/ndb_share.cc 2011-11-09 06:31:45 +0000
@@ -17,6 +17,8 @@
#include "ndb_share.h"
#include "ndb_event_data.h"
+#include "ndb_dist_priv_util.h"
+#include "ha_ndbcluster_tables.h"
#include <my_sys.h>
@@ -46,3 +48,50 @@ NDB_SHARE::destroy(NDB_SHARE* share)
my_free(share);
}
+
+bool
+NDB_SHARE::need_events(bool default_on) const
+{
+ DBUG_ENTER("NDB_SHARE::need_events");
+ DBUG_PRINT("enter", ("db: %s, table_name: %s",
+ db, table_name));
+
+ if (default_on)
+ {
+ // Events are on by default, check if it should be turned off
+
+ if (Ndb_dist_priv_util::is_distributed_priv_table(db, table_name))
+ {
+ /*
+ The distributed privilege tables are distributed by writing
+ the CREATE USER, GRANT, REVOKE etc. to ndb_schema -> no need
+ to listen to events from those table
+ */
+ DBUG_PRINT("exit", ("no events for dist priv table"));
+ DBUG_RETURN(false);
+ }
+
+ DBUG_PRINT("exit", ("need events(the default for this mysqld)"));
+ DBUG_RETURN(true);
+ }
+
+ // Events are off by default, check if it should be turned on
+ if (strcmp(db, NDB_REP_DB) == 0)
+ {
+ // The table is in "mysql" database
+ if (strcmp(table_name, NDB_SCHEMA_TABLE) == 0)
+ {
+ DBUG_PRINT("exit", ("need events for " NDB_SCHEMA_TABLE));
+ DBUG_RETURN(true);
+ }
+
+ if (strcmp(table_name, NDB_APPLY_TABLE) == 0)
+ {
+ DBUG_PRINT("exit", ("need events for " NDB_APPLY_TABLE));
+ DBUG_RETURN(true);
+ }
+ }
+
+ DBUG_PRINT("exit", ("no events(the default for this mysqld)"));
+ DBUG_RETURN(false);
+}
=== modified file 'sql/ndb_share.h'
--- a/sql/ndb_share.h 2011-11-08 21:07:35 +0000
+++ b/sql/ndb_share.h 2011-11-09 06:31:45 +0000
@@ -192,6 +192,12 @@ struct NDB_SHARE {
struct TABLE* table, const char* db_name,
const char* table_name);
static void destroy(NDB_SHARE* share);
+
+ /*
+ Returns true if this share need to subscribe to
+ events from the table.
+ */
+ bool need_events(bool default_on) const;
};
No bundle (reason: useless for push emails).
| Thread |
|---|
| • bzr push into mysql-5.5-cluster branch (magnus.blaudd:3644 to 3645) | magnus.blaudd | 11 Nov |