@@ -1159,7 +1159,8 @@ bool Ndb_schema_dist_client::log_schema_op_impl(
1159
1159
}
1160
1160
1161
1161
// 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 ) {
1163
1164
// This case is unlikely, but there is small race between
1164
1165
// clients first check for schema distribution ready and schema op
1165
1166
// 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,
1221
1222
Ndb_event_data::get_event_data (pOp->getCustomData ());
1222
1223
NDB_SHARE *const share = event_data->share ;
1223
1224
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 );
1237
1228
1238
1229
// Close the table in MySQL Server
1239
1230
ndb_tdc_close_cached_table (thd, share->db , share->table_name );
@@ -2270,9 +2261,8 @@ class Ndb_schema_event_handler {
2270
2261
void ndbapi_invalidate_table (const std::string &db_name,
2271
2262
const std::string &table_name) const {
2272
2263
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 ());
2276
2266
}
2277
2267
2278
2268
NDB_SHARE *acquire_reference (const std::string &db, const std::string &name,
@@ -3163,6 +3153,8 @@ class Ndb_schema_event_handler {
3163
3153
if (schema->node_id == own_nodeid ()) return ;
3164
3154
3165
3155
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 ());
3166
3158
3167
3159
if (!create_table_from_engine (schema->db .c_str (), schema->name .c_str (),
3168
3160
true , /* force_overwrite */
@@ -4221,14 +4213,9 @@ class Ndb_schema_event_handler {
4221
4213
// take the GSL properly
4222
4214
assert (!m_thd_ndb->check_option (Thd_ndb::IS_SCHEMA_DIST_PARTICIPANT));
4223
4215
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 ););
4229
4216
// Protect the setup with GSL(Global Schema Lock)
4230
4217
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 ()) {
4232
4219
ndb_log_info (" - failed to lock GSL" );
4233
4220
return true ;
4234
4221
}
@@ -5003,6 +4990,12 @@ static int ndbcluster_setup_binlog_for_share(THD *thd, Ndb *ndb,
5003
4990
return -1 ;
5004
4991
}
5005
4992
}
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);
5006
4999
5007
5000
if (share->have_event_operation ()) {
5008
5001
DBUG_PRINT (" info" , (" binlogging already setup" ));
0 commit comments