Skip to content

Commit

Permalink
WL#11968 Patch 1(b), post-push fixes for patch #1.
Browse files Browse the repository at this point in the history
Patch #1 caused several problems in mysql-trunk related to ndbinfo
initialization and upgrade, including the failure of the test
ndb_76_inplace_upgrade and the failure of all NDB MTR tests in Pushbuild
on Windows. This patch fixes these issues, including fixes for
bug#33726826 and bug#33730799.

In ndbinfo, revert the removal of ndb$blocks and ndb$index_stats and the
change of blocks and index_stats from views to tables.

Improve the ndbinfo schema upgrade & initialization logic to better handle
such a change in the future. This logic now runs in two passes: first it
drops the known tables and views from current and previous versions, then
it creates the tables and views for the current version.

Add a new class method NdbDictionary::printColumnTypeDescription(). This
is needed for the ndbinfo.columns table in patch #2 but was missing from
patch #1. Add boilerplate index lookup initialization code that was
also missing.

Fix ndbinfo prefix determination on Windows.

Change-Id: I422856bcad4baf5ae9b14c1e3a1f2871bd6c5f59
  • Loading branch information
jdduncan committed Jan 12, 2022
1 parent fc36ff0 commit e14ee2a
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 101 deletions.
22 changes: 11 additions & 11 deletions mysql-test/suite/ndb/r/ndbinfo_plans.result
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ SELECT table_name, table_rows, avg_row_length
AND table_name not like '%cpu%'
ORDER BY table_name;
TABLE_NAME TABLE_ROWS AVG_ROW_LENGTH
blocks 29 20
index_stats 64 12
ndb$acc_operations 15 64
ndb$backup_id 1 20
ndb$blocks 29 20
ndb$columns 530 44
ndb$config_nodes 34 28
ndb$config_params 167 120
Expand All @@ -76,6 +75,7 @@ ndb$frag_locks 344 96
ndb$frag_mem_use 344 100
ndb$frag_operations 344 192
ndb$hwinfo 2 44
ndb$index_stats 64 12
ndb$logbuffers 8 40
ndb$logspaces 8 40
ndb$membership 2 88
Expand Down Expand Up @@ -110,8 +110,8 @@ count(*)
SELECT table_name from rowcounts WHERE est_rows = actual_rows
ORDER BY table_name;
table_name
blocks
ndb$backup_id
ndb$blocks
ndb$columns
ndb$config_nodes
ndb$config_params
Expand Down Expand Up @@ -153,7 +153,7 @@ SELECT table_name, constraint_name, column_name, ordinal_position
WHERE table_schema = 'ndbinfo'
ORDER BY table_name;
TABLE_NAME CONSTRAINT_NAME COLUMN_NAME ORDINAL_POSITION
blocks PRIMARY block_number 1
ndb$blocks PRIMARY block_number 1
ndb$config_params PRIMARY param_number 1
ndb$dblqh_tcconnect_state PRIMARY state_int_value 1
ndb$dbtc_apiconnect_state PRIMARY state_int_value 1
Expand Down Expand Up @@ -205,21 +205,21 @@ block_number 251
block_name NDBCNTR

explain format=tree select * from blocks where block_number in (250,251);
EXPLAIN -> Filter: (blocks.block_number in (250,251)) (cost=1.41 rows=2)
-> Index range scan on blocks using PRIMARY over (block_number = 250) OR (block_number = 251) (cost=1.41 rows=2)
EXPLAIN -> Filter: (ndb$blocks.block_number in (250,251)) (cost=1.41 rows=2)
-> Index range scan on ndb$blocks using PRIMARY over (block_number = 250) OR (block_number = 251) (cost=1.41 rows=2)

explain format=tree select * from blocks order by block_number;
EXPLAIN -> Index scan on blocks using PRIMARY (cost=3.40 rows=29)
EXPLAIN -> Index scan on ndb$blocks using PRIMARY (cost=3.40 rows=29)

explain format=tree select * from blocks where block_number < 250;
EXPLAIN -> Filter: (blocks.block_number < 250) (cost=4.76 rows=10)
-> Index range scan on blocks using PRIMARY over (block_number < 250) (cost=4.76 rows=10)
EXPLAIN -> Filter: (ndb$blocks.block_number < 250) (cost=4.76 rows=10)
-> Index range scan on ndb$blocks using PRIMARY over (block_number < 250) (cost=4.76 rows=10)

## Can scan backwards:
explain format=tree select * from blocks where block_number > 250
order by block_number desc;
EXPLAIN -> Filter: (blocks.block_number > 250) (cost=4.76 rows=10)
-> Index range scan on blocks using PRIMARY over (250 < block_number) (reverse) (cost=4.76 rows=10)
EXPLAIN -> Filter: (ndb$blocks.block_number > 250) (cost=4.76 rows=10)
-> Index range scan on ndb$blocks using PRIMARY over (250 < block_number) (reverse) (cost=4.76 rows=10)


select * from dict_obj_types where type_id = 6;
Expand Down
24 changes: 14 additions & 10 deletions sql/dd/ndbinfo_schema/init.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2019, 2021, Oracle and/or its affiliates.
/* Copyright (c) 2019, 2022, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -78,21 +78,18 @@ static bool check_ndbinfo_schema_has_correct_version(THD *thd) {
return tag_exists ? (version == MYSQL_VERSION_ID) : false;
}

static bool drop_and_create_table(THD *thd, const Plugin_table &table) {
static bool drop_object(THD *thd, const Plugin_table &table) {
dd::String_type drop_sql("DROP ");
drop_sql.append(table.get_object_type()); // TABLE or VIEW
drop_sql.append(" IF EXISTS ").append(table.get_qualified_name());

if (dd::execute_query(thd, drop_sql)) return true;
return dd::execute_query(thd, drop_sql);
}

static bool create_object(THD *thd, const Plugin_table &table) {
if (table.get_table_definition()) {
/* Create schema if needed */
if (create_schema(thd, table.get_schema_name())) return true;

/* Create table */
if (dd::execute_query(thd, table.get_ddl())) return true;
}

return false; // success
}

Expand Down Expand Up @@ -145,11 +142,18 @@ static bool initialize_ndbinfo(THD *thd) {
// Create the ndbinfo schema
if (create_schema(thd, "ndbinfo")) return true;

// Create each table or view defined in the list
// Drop all known tables & views (current version and previous versions)
bool failed = false;
for (const Plugin_table &table : ndbinfo_tables) {
if (!failed) {
failed = drop_and_create_table(thd, table);
failed = drop_object(thd, table);
}
}

// Create the current set of tables and views
for (const Plugin_table &table : ndbinfo_tables) {
if (!failed) {
failed = create_object(thd, table);
}
}

Expand Down
4 changes: 3 additions & 1 deletion storage/ndb/include/ndbapi/NdbDictionary.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2003, 2021, Oracle and/or its affiliates.
Copyright (c) 2003, 2022, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -2971,6 +2971,8 @@ class NdbDictionary {
const NdbDataPrintFormat& format,
const NdbDictionary::Column* c,
const void* val);
static
class NdbOut& printColumnTypeDescription(class NdbOut &, const Column &);

}; // class NdbDictionary

Expand Down
10 changes: 7 additions & 3 deletions storage/ndb/plugin/ha_ndbinfo.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2009, 2021, Oracle and/or its affiliates.
Copyright (c) 2009, 2022, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -354,6 +354,7 @@ int ha_ndbinfo::open(const char *name, int mode, uint, const dd::Table *) {
int err = g_ndbinfo->openTable(name, &m_impl.m_table);
if (err) {
assert(m_impl.m_table == 0);
ndb_log_info("NdbInfo::openTable failed for %s", name);
if (err == NdbInfo::ERR_NoSuchTable) {
if (g_ndb_cluster_connection->get_min_db_version() < NDB_VERSION_D) {
// The table does not exist but there is a data node from a lower
Expand Down Expand Up @@ -763,7 +764,10 @@ ulong ha_ndbinfo::index_flags(uint, uint, bool) const {
int ha_ndbinfo::index_init(uint index, bool) {
assert(index == 0);
active_index = index; // required
return rnd_init(true);
int err = rnd_init(true);
if (err != 0) return err;
m_impl.m_scan_op->initIndex(index);
return 0;
}

int ha_ndbinfo::index_end() { return rnd_end(); }
Expand Down Expand Up @@ -903,7 +907,7 @@ static int ndbinfo_init(void *plugin) {
char prefix[FN_REFLEN];
build_table_filename(prefix, sizeof(prefix) - 1, opt_ndbinfo_dbname,
opt_ndbinfo_table_prefix, "", 0);
DBUG_PRINT("info", ("prefix: '%s'", prefix));
ndb_log_info("ndbinfo prefix: '%s'", prefix);
assert(g_ndb_cluster_connection);
g_ndbinfo = new (std::nothrow) NdbInfo(g_ndb_cluster_connection, prefix);
if (!g_ndbinfo) {
Expand Down
153 changes: 91 additions & 62 deletions storage/ndb/plugin/ha_ndbinfo_sql.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2009, 2021, Oracle and/or its affiliates.
Copyright (c) 2009, 2022, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -83,6 +83,9 @@ static struct view {
"FROM `ndbinfo`.`ndb$membership` "
"GROUP BY arbitrator, arb_ticket, arb_connected"},
{"ndbinfo", "backup_id", "SELECT id FROM `ndbinfo`.`ndb$backup_id`"},
{"ndbinfo", "blocks",
"SELECT block_number, block_name "
"FROM `ndbinfo`.`ndb$blocks`"},
{"ndbinfo", "cluster_locks",
"SELECT "
"`ndbinfo`.`ndb$acc_operations`.`node_id` AS `node_id`,"
Expand Down Expand Up @@ -222,7 +225,7 @@ static struct view {
" END AS counter_name, "
"val "
"FROM `ndbinfo`.`ndb$counters` c "
"LEFT JOIN `ndbinfo`.`blocks` b "
"LEFT JOIN `ndbinfo`.`ndb$blocks` b "
"ON c.block_number = b.block_number"},
{"ndbinfo", "cpudata",
"SELECT * "
Expand Down Expand Up @@ -316,6 +319,9 @@ static struct view {
{"ndbinfo", "hwinfo",
"SELECT * "
"FROM `ndbinfo`.`ndb$hwinfo`"},
{"ndbinfo", "index_stats",
"SELECT * "
"FROM `ndbinfo`.`ndb$index_stats`"},
{"ndbinfo", "locks_per_fragment",
"SELECT name.fq_name, parent_name.fq_name AS parent_fq_name, "
"types.type_name AS type, table_id, node_id, block_instance, "
Expand Down Expand Up @@ -619,7 +625,7 @@ static struct view {
{"ndbinfo", "threadblocks",
"SELECT t.node_id, t.thr_no, b.block_name, t.block_instance "
"FROM `ndbinfo`.`ndb$threadblocks` t "
"LEFT JOIN `ndbinfo`.`blocks` b "
"LEFT JOIN `ndbinfo`.`ndb$blocks` b "
"ON t.block_number = b.block_number"},
{"ndbinfo", "threads",
"SELECT * "
Expand Down Expand Up @@ -647,68 +653,81 @@ static struct lookup {
const char *schema_name;
const char *lookup_table_name;
const char *columns;
} lookups[] = {
{
"ndbinfo",
"blocks",
"block_number INT UNSIGNED NOT NULL PRIMARY KEY, "
"block_name VARCHAR(512)",
},
{
"ndbinfo",
"index_stats",
"index_id INT UNSIGNED, "
"index_version INT UNSIGNED, "
"sample_version INT UNSIGNED",
},
{"ndbinfo", "ndb$backup_id",
"id BIGINT UNSIGNED, "
"fragment INT UNSIGNED, "
"row_id BIGINT UNSIGNED"},
{"ndbinfo", "ndb$config_params",
"param_number INT UNSIGNED NOT NULL PRIMARY KEY, "
"param_name VARCHAR(512), "
"param_description VARCHAR(512), "
"param_type VARCHAR(512), "
"param_default VARCHAR(512), "
"param_min VARCHAR(512), "
"param_max VARCHAR(512), "
"param_mandatory INT UNSIGNED, "
"param_status VARCHAR(512)"},
{
"ndbinfo",
"ndb$dblqh_tcconnect_state",
"state_int_value INT UNSIGNED NOT NULL PRIMARY KEY, "
"state_name VARCHAR(256), "
"state_friendly_name VARCHAR(256), "
"state_description VARCHAR(256)",
},
{
"ndbinfo",
"ndb$dbtc_apiconnect_state",
"state_int_value INT UNSIGNED NOT NULL PRIMARY KEY, "
"state_name VARCHAR(256), "
"state_friendly_name VARCHAR(256), "
"state_description VARCHAR(256)",
},
{
"ndbinfo",
"ndb$dict_obj_types",
"type_id INT UNSIGNED NOT NULL PRIMARY KEY, "
"type_name VARCHAR(512)",
},
{
"ndbinfo",
"ndb$error_messages",
"error_code INT UNSIGNED, "
"error_description VARCHAR(512), "
"error_status VARCHAR(512), "
"error_classification VARCHAR(512)",
},
};
} lookups[] = {{"ndbinfo", "ndb$backup_id",
"id BIGINT UNSIGNED, "
"fragment INT UNSIGNED, "
"row_id BIGINT UNSIGNED"},
{
"ndbinfo",
"ndb$blocks",
"block_number INT UNSIGNED NOT NULL PRIMARY KEY, "
"block_name VARCHAR(512)",
},
{"ndbinfo", "ndb$config_params",
"param_number INT UNSIGNED NOT NULL PRIMARY KEY, "
"param_name VARCHAR(512), "
"param_description VARCHAR(512), "
"param_type VARCHAR(512), "
"param_default VARCHAR(512), "
"param_min VARCHAR(512), "
"param_max VARCHAR(512), "
"param_mandatory INT UNSIGNED, "
"param_status VARCHAR(512)"},
{
"ndbinfo",
"ndb$dblqh_tcconnect_state",
"state_int_value INT UNSIGNED NOT NULL PRIMARY KEY, "
"state_name VARCHAR(256), "
"state_friendly_name VARCHAR(256), "
"state_description VARCHAR(256)",
},
{
"ndbinfo",
"ndb$dbtc_apiconnect_state",
"state_int_value INT UNSIGNED NOT NULL PRIMARY KEY, "
"state_name VARCHAR(256), "
"state_friendly_name VARCHAR(256), "
"state_description VARCHAR(256)",
},
{
"ndbinfo",
"ndb$dict_obj_types",
"type_id INT UNSIGNED NOT NULL PRIMARY KEY, "
"type_name VARCHAR(512)",
},
{
"ndbinfo",
"ndb$error_messages",
"error_code INT UNSIGNED, "
"error_description VARCHAR(512), "
"error_status VARCHAR(512), "
"error_classification VARCHAR(512)",
},
{
"ndbinfo",
"ndb$index_stats",
"index_id INT UNSIGNED, "
"index_version INT UNSIGNED, "
"sample_version INT UNSIGNED",
}};

static constexpr size_t num_lookups = sizeof(lookups) / sizeof(lookups[0]);

struct obsolete_object {
const char *schema_name;
const char *name;
};

/* Views that were present in previous versions */
static struct obsolete_object obsolete_views[] = {
{"ndbinfo", "dummy_view"} // replace this with an actual deleted view
};

/* Base tables that were present in previous versions */
static struct obsolete_object obsolete_tables[] = {
{"ndbinfo", "dummy_table"} // replace this with an actual deleted table
};

static int compare_names(const void *px, const void *py) {
const Ndbinfo::Table *const *x =
static_cast<const Ndbinfo::Table *const *>(px);
Expand Down Expand Up @@ -759,6 +778,16 @@ static Plugin_table *ndbinfo_define_table(const Ndbinfo::Table &table) {
}

bool ndbinfo_define_dd_tables(List<const Plugin_table> *plugin_tables) {
/* Drop views from previous versions */
for (const obsolete_object &v : obsolete_views)
plugin_tables->push_back(
new Plugin_view(v.schema_name, v.name, nullptr, nullptr));

/* Drop base tables from previous versions */
for (const obsolete_object &t : obsolete_tables)
plugin_tables->push_back(
new Plugin_table(t.schema_name, t.name, nullptr, nullptr, nullptr));

/* Sort Ndbinfo tables; define Ndbinfo tables as tables in DD */
const Ndbinfo::Table **tables =
new const Ndbinfo::Table *[Ndbinfo::getNumTables()];
Expand Down
Loading

0 comments on commit e14ee2a

Please sign in to comment.