Skip to content

Commit 54d003b

Browse files
blauddendahlerlend
authored andcommitted
Merge from mysql-trunk of:
BUG#35949017 Schema dist setup lockup Bug#35948153 Problem setting up events due to stale NdbApi dictionary cache [mysql#2] Bug#35948153 Problem setting up events due to stale NdbApi dictionary cache [mysql#1] Bug#32550019 Missing check for ndb_schema_result leads to schema dist timeout Change-Id: I4a32197992bf8b6899892f21587580788f828f34
1 parent 78c835a commit 54d003b

19 files changed

+148
-128
lines changed

mysql-test/suite/ndb_ddl/check_util_table_drop.inc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@ RESET BINARY LOGS AND GTIDS;
2626
--echo # Drop mysql.$util_table_name from NDB
2727
--exec $NDB_DROP_TABLE -d mysql $util_table_name
2828

29-
--connection mysqld1
30-
--echo # mysqld1: Wait until ready again...
31-
--source include/ndb_not_readonly.inc
32-
33-
--connection mysqld3
34-
--echo # mysqld3: Wait until ready again...
35-
--source include/ndb_not_readonly.inc
36-
37-
--connection mysqld5
38-
--echo # mysqld5: Wait until ready again...
39-
--source include/ndb_not_readonly.inc
29+
# Wait for all servers connected again
30+
let $i = 1;
31+
while($i <= $NUM_MYSQLDS)
32+
{
33+
--connection mysqld$i
34+
--echo # mysqld$i: Wait until ready again...
35+
--source include/ndb_not_readonly.inc
36+
inc $i;
37+
}
4038

4139
--connection mysqld5
4240
# NOTE! Neither drop of ndb_schema or ndb_schema_result should have a LOST_EVENT

mysql-test/suite/ndb_ddl/util_tables_drop.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ Dropping table ndb_schema...OK
1414
NDBT_ProgramExit: 0 - OK
1515

1616
# mysqld1: Wait until ready again...
17+
# mysqld2: Wait until ready again...
1718
# mysqld3: Wait until ready again...
19+
# mysqld4: Wait until ready again...
1820
# mysqld5: Wait until ready again...
21+
# mysqld6: Wait until ready again...
1922
# Check if a LOST_EVENTS event was written to the binlog
2023
include/show_binlog_events.inc
2124
Log_name Pos Event_type Server_id End_log_pos Info
@@ -44,8 +47,11 @@ Dropping table ndb_apply_status...OK
4447
NDBT_ProgramExit: 0 - OK
4548

4649
# mysqld1: Wait until ready again...
50+
# mysqld2: Wait until ready again...
4751
# mysqld3: Wait until ready again...
52+
# mysqld4: Wait until ready again...
4853
# mysqld5: Wait until ready again...
54+
# mysqld6: Wait until ready again...
4955
# Check if a LOST_EVENTS event was written to the binlog
5056
include/show_binlog_events.inc
5157
Log_name Pos Event_type Server_id End_log_pos Info
@@ -76,8 +82,11 @@ Dropping table ndb_schema_result...OK
7682
NDBT_ProgramExit: 0 - OK
7783

7884
# mysqld1: Wait until ready again...
85+
# mysqld2: Wait until ready again...
7986
# mysqld3: Wait until ready again...
87+
# mysqld4: Wait until ready again...
8088
# mysqld5: Wait until ready again...
89+
# mysqld6: Wait until ready again...
8190
# Check if a LOST_EVENTS event was written to the binlog
8291
include/show_binlog_events.inc
8392
Log_name Pos Event_type Server_id End_log_pos Info

mysql-test/suite/ndbcluster/stale_schema_event.cnf

Lines changed: 0 additions & 12 deletions
This file was deleted.

mysql-test/suite/ndbcluster/stale_schema_event.result

Lines changed: 0 additions & 10 deletions
This file was deleted.

mysql-test/suite/ndbcluster/stale_schema_event.test

Lines changed: 0 additions & 59 deletions
This file was deleted.

storage/ndb/include/ndbapi/Ndb.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,9 @@ class Ndb {
22152215

22162216
static const char *externalizeTableName(const char *internalTableName,
22172217
bool fullyQualifiedNames);
2218+
static BaseString internalize_table_name(const char *db_name,
2219+
const char *schema,
2220+
const char *table_name);
22182221
const BaseString internalize_table_name(const char *external_name) const;
22192222

22202223
static const char *externalizeIndexName(const char *internalIndexName,

storage/ndb/include/ndbapi/NdbDictionary.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,6 +2917,9 @@ class NdbDictionary {
29172917
int removeIndexGlobal(const Index &ndbidx, int invalidate) const;
29182918
int removeTableGlobal(const Table &ndbtab, int invalidate) const;
29192919
void invalidateDbGlobal(const char *dbname);
2920+
// Invalidate table by name if it exist in the cache
2921+
void invalidateTableGlobal(const char *dbName, const char *schemaName,
2922+
const char *tableName);
29202923
#endif
29212924

29222925
/*

storage/ndb/plugin/ha_ndbcluster_binlog.cc

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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"));

storage/ndb/plugin/ndb_dd_sync.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,9 @@ bool Ndb_dd_sync::synchronize_table(const char *schema_name,
11871187
const char *table_name) const {
11881188
ndb_log_verbose(1, "Synchronizing table '%s.%s'", schema_name, table_name);
11891189

1190+
// Invalidate potentially stale cached table
1191+
Ndb_table_guard::invalidate_table(m_thd_ndb->ndb, schema_name, table_name);
1192+
11901193
Ndb_table_guard ndbtab_g(m_thd_ndb->ndb, schema_name, table_name);
11911194
const NdbDictionary::Table *ndbtab = ndbtab_g.get_table();
11921195
if (!ndbtab) {

storage/ndb/plugin/ndb_metadata_sync.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,8 @@ bool Ndb_metadata_sync::sync_table(THD *thd, const std::string &schema_name,
913913
table_name.c_str());
914914

915915
// Invalidate the table in NdbApi
916-
Ndb_table_guard ndbtab_guard(ndb, schema_name.c_str(), table_name.c_str());
917-
ndbtab_guard.invalidate();
916+
Ndb_table_guard::invalidate_table(ndb, schema_name.c_str(),
917+
table_name.c_str());
918918
return true;
919919
}
920920

0 commit comments

Comments
 (0)