From: magnus.blaudd Date: November 8 2011 9:59am Subject: bzr push into mysql-5.5-cluster branch (magnus.blaudd:3637 to 3640) List-Archive: http://lists.mysql.com/commits/141848 Message-Id: <201111080959.pA89xMs8012363@acsmt356.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3640 magnus.blaudd@stripped 2011-11-08 ndb schema dist - remove uneccesary if modified: sql/ha_ndbcluster_binlog.cc 3639 magnus.blaudd@stripped 2011-11-08 ndb schema dist - move extraction of Ndb* from thd to the only scope where it's used in function modified: sql/ha_ndbcluster_binlog.cc 3638 magnus.blaudd@stripped 2011-11-08 ndb schema dist - factor out function for writing new frm from ndb into mysqld data dictionary modified: sql/ha_ndbcluster_binlog.cc 3637 magnus.blaudd@stripped 2011-11-08 ndb schema dist - use sizeof() instead of hardcoded value FN_LEN which doesn't match the size of the buffer(s) used - FN_LEN = 256 and FN_REFLEN =512 modified: sql/ha_ndbcluster_binlog.cc === modified file 'sql/ha_ndbcluster_binlog.cc' --- a/sql/ha_ndbcluster_binlog.cc 2011-11-08 09:38:06 +0000 +++ b/sql/ha_ndbcluster_binlog.cc 2011-11-08 09:58:19 +0000 @@ -2585,6 +2585,48 @@ class Ndb_schema_event_handler { } + void + mysqld_write_frm_from_ndb(const char* db_name, + const char* table_name) const + { + Thd_ndb *thd_ndb= get_thd_ndb(m_thd); + Ndb *ndb= thd_ndb->ndb; + Ndb_table_guard ndbtab_g(ndb->getDictionary(), table_name); + const NDBTAB *ndbtab= ndbtab_g.get_table(); + + char key[FN_REFLEN]; + build_table_filename(key, sizeof(key)-1, + db_name, table_name, NullS, 0); + + uchar *data= 0, *pack_data= 0; + size_t length, pack_length; + + if (readfrm(key, &data, &length) == 0 && + packfrm(data, length, &pack_data, &pack_length) == 0 && + cmp_frm(ndbtab, pack_data, pack_length)) + { + DBUG_PRINT("info", ("Detected frm change of table %s.%s", + db_name, table_name)); + + DBUG_DUMP("frm", (uchar*) ndbtab->getFrmData(), + ndbtab->getFrmLength()); + my_free(data); + data= NULL; + + int error; + 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", + db_name, table_name, error); + } + } + my_free(data); + my_free(pack_data); + } + + NDB_SHARE* get_share(Ndb_schema_op* schema) const { char key[FN_REFLEN + 1]; @@ -2774,97 +2816,71 @@ class Ndb_schema_event_handler { 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, sizeof(key)-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); - } + if (!ndbcluster_check_if_local_table(schema->db, schema->name)) + { + mysqld_write_frm_from_ndb(schema->db, schema->name); } - 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"); + sql_print_information("NDB Binlog: handling online alter/rename"); pthread_mutex_lock(&share->mutex); ndb_binlog_close_shadow_table(share); - if ((error= ndb_binlog_open_shadow_table(m_thd, share))) + if (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 (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 (opt_ndb_extra_logging > 9) - sql_print_information("NDB Binlog: handeling online alter/rename done"); + 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 (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: handling online " + "alter/rename done"); + } } if (share) { @@ -3452,7 +3468,7 @@ public: }; /********************************************************************* - Internal helper functions for handeling of the cluster replication tables + Internal helper functions for handling of the cluster replication tables - ndb_binlog_index - ndb_apply_status *********************************************************************/ No bundle (reason: useless for push emails).