@@ -1159,7 +1159,8 @@ bool Ndb_schema_dist_client::log_schema_op_impl(
11591159 }
11601160
11611161 // Check if schema distribution is still ready.
1162- if (m_share->have_event_operation () == false ) {
1162+ if (m_share->have_event_operation () == false ||
1163+ m_result_share->have_event_operation () == false ) {
11631164 // This case is unlikely, but there is small race between
11641165 // clients first check for schema distribution ready and schema op
11651166 // registered in the coordinator(since the message is passed
@@ -1221,19 +1222,9 @@ static void ndbcluster_binlog_event_operation_teardown(THD *thd, Ndb *is_ndb,
12211222 Ndb_event_data::get_event_data (pOp->getCustomData ());
12221223 NDB_SHARE *const share = event_data->share ;
12231224
1224- // Invalidate any cached NdbApi table if object version is lower
1225- // than what was used when setting up the NdbEventOperation
1226- // NOTE! This functionality need to be explained further
1227- {
1228- Thd_ndb *thd_ndb = get_thd_ndb (thd);
1229- Ndb *ndb = thd_ndb->ndb ;
1230- Ndb_table_guard ndbtab_g (ndb, share->db , share->table_name );
1231- const NDBTAB *ev_tab = pOp->getTable ();
1232- const NDBTAB *cache_tab = ndbtab_g.get_table ();
1233- if (cache_tab && cache_tab->getObjectId () == ev_tab->getObjectId () &&
1234- cache_tab->getObjectVersion () <= ev_tab->getObjectVersion ())
1235- ndbtab_g.invalidate ();
1236- }
1225+ // Since table has been dropped or cluster connection lost the NdbApi table
1226+ // should be invalidated in the global dictionary cache
1227+ Ndb_table_guard::invalidate_table (is_ndb, share->db , share->table_name );
12371228
12381229 // Close the table in MySQL Server
12391230 ndb_tdc_close_cached_table (thd, share->db , share->table_name );
@@ -2270,9 +2261,8 @@ class Ndb_schema_event_handler {
22702261 void ndbapi_invalidate_table (const std::string &db_name,
22712262 const std::string &table_name) const {
22722263 DBUG_TRACE;
2273- Ndb_table_guard ndbtab_g (m_thd_ndb->ndb , db_name.c_str (),
2274- table_name.c_str ());
2275- ndbtab_g.invalidate ();
2264+ Ndb_table_guard::invalidate_table (m_thd_ndb->ndb , db_name.c_str (),
2265+ table_name.c_str ());
22762266 }
22772267
22782268 NDB_SHARE *acquire_reference (const std::string &db, const std::string &name,
@@ -3163,6 +3153,8 @@ class Ndb_schema_event_handler {
31633153 if (schema->node_id == own_nodeid ()) return ;
31643154
31653155 write_schema_op_to_binlog (m_thd, schema);
3156+ ndbapi_invalidate_table (schema->db , schema->name );
3157+ ndb_tdc_close_cached_table (m_thd, schema->db .c_str (), schema->name .c_str ());
31663158
31673159 if (!create_table_from_engine (schema->db .c_str (), schema->name .c_str (),
31683160 true , /* force_overwrite */
@@ -4221,14 +4213,9 @@ class Ndb_schema_event_handler {
42214213 // take the GSL properly
42224214 assert (!m_thd_ndb->check_option (Thd_ndb::IS_SCHEMA_DIST_PARTICIPANT));
42234215
4224- // Sleep here will make other mysql server in same cluster setup to create
4225- // the schema result table in NDB before this mysql server. This also makes
4226- // the create table in the connection thread to acquire GSL before the
4227- // Binlog thread
4228- DBUG_EXECUTE_IF (" ndb_bi_sleep_before_gsl" , sleep (1 ););
42294216 // Protect the setup with GSL(Global Schema Lock)
42304217 Ndb_global_schema_lock_guard global_schema_lock_guard (m_thd);
4231- if (global_schema_lock_guard.lock ()) {
4218+ if (! global_schema_lock_guard.try_lock ()) {
42324219 ndb_log_info (" - failed to lock GSL" );
42334220 return true ;
42344221 }
@@ -5003,6 +4990,12 @@ static int ndbcluster_setup_binlog_for_share(THD *thd, Ndb *ndb,
50034990 return -1 ;
50044991 }
50054992 }
4993+ // The function that check if event exist will silently mark the NDB table
4994+ // definition as 'Invalid' when the event's table version does not match the
4995+ // cached NDB table definitions version. This indicates that the caller have
4996+ // used a stale version of the NDB table definition and is a problem which
4997+ // has to be fixed by the caller of this function.
4998+ assert (ndbtab->getObjectStatus () != NdbDictionary::Object::Invalid);
50064999
50075000 if (share->have_event_operation ()) {
50085001 DBUG_PRINT (" info" , (" binlogging already setup" ));
0 commit comments