Skip to content

Commit 071cda5

Browse files
luquninikep
authored andcommitted
add is_dd_engine_change_in_progress() to check dd_engine change (facebook#1378)
Summary: Innodb SE need to know whether DD engine change is in progress for its handler API to return correct data. such as get_se_private_data() should return mysql.dd_properties table data is DD engine change in in progress and also DDSE is rocksdb. Expose is_dd_engine_change information in dd.h. also update other places to use is_dd_engine_change variable to check whether DD engine change is in progress. Pull Request resolved: facebook#1378 Differential Revision: D50715910
1 parent a07a1b7 commit 071cda5

File tree

7 files changed

+37
-8
lines changed

7 files changed

+37
-8
lines changed

sql/dd/dd.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ class Dictionary *get_dictionary();
7878
template <typename X>
7979
X *create_object();
8080

81+
/**
82+
Whether DD engine is changing in progress,such as INNODB DDSE to MyRocks DDSE
83+
or vice versa.
84+
*/
85+
bool is_dd_engine_change_in_progress();
86+
8187
///////////////////////////////////////////////////////////////////////////
8288

8389
} // namespace dd

sql/dd/impl/bootstrap/bootstrapper.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,8 @@ bool sync_meta_data(THD *thd) {
18951895

18961896
bool update_properties(THD *thd, const std::set<String_type> *create_set,
18971897
const std::set<String_type> *remove_set,
1898-
const String_type &target_table_schema_name) {
1898+
const String_type &target_table_schema_name,
1899+
std::set<String_type> *innodb_set) {
18991900
/*
19001901
Populate the dd properties with the SQL DDL and SE private data.
19011902
Store meta data of non-inert tables only.
@@ -1953,6 +1954,10 @@ bool update_properties(THD *thd, const std::set<String_type> *create_set,
19531954
// All non-abandoned tables should have a table object present.
19541955
assert(dd_table != nullptr);
19551956

1957+
// Record all innodb table name
1958+
if (innodb_set != nullptr && dd_table->engine() == "InnoDB") {
1959+
innodb_set->insert(dd_table->name());
1960+
}
19561961
std::unique_ptr<dd::Properties> tbl_props(
19571962
dd::Properties::parse_properties(""));
19581963

sql/dd/impl/bootstrap/bootstrapper.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,15 @@ bool sync_meta_data(THD *thd);
383383
version of DD.
384384
@param target_table_schema_name Schema name in which the final changes are
385385
required.
386+
@param innodb_set A set of create_set table names whose engine
387+
is innodb
386388
387389
@return Upon failure, return true, otherwise false.
388390
*/
389391
bool update_properties(THD *thd, const std::set<String_type> *create_set,
390392
const std::set<String_type> *remove_set,
391-
const String_type &target_table_schema_name);
393+
const String_type &target_table_schema_name,
394+
std::set<String_type> *innodb_set = nullptr);
392395

393396
/**
394397
Updates the DD Version in the DD_properties table to the current version.

sql/dd/impl/dd.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "sql/dd/dd.h"
2424

2525
#include "sql/dd/cache/object_registry.h"
26+
#include "sql/dd/impl/bootstrap/bootstrap_ctx.h" // dd::DD_bootstrap_ctx
2627
#include "sql/dd/impl/cache/shared_dictionary_cache.h" // dd::cache::Shared_...
2728
#include "sql/dd/impl/dictionary_impl.h" // dd::Dictionary_impl
2829
#include "sql/dd/impl/system_registry.h" // dd::System_tables
@@ -79,6 +80,10 @@ X *create_object() {
7980
return dynamic_cast<X *>(new (std::nothrow) typename X::Impl());
8081
}
8182

83+
bool is_dd_engine_change_in_progress() {
84+
return bootstrap::DD_bootstrap_ctx::instance().is_dd_engine_change();
85+
}
86+
8287
template Charset_impl *create_object<Charset_impl>();
8388
template Collation *create_object<Collation>();
8489
template Collation_impl *create_object<Collation_impl>();

sql/dd/impl/upgrade/dd.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,8 @@ bool update_object_ids(THD *thd, const std::set<String_type> &create_set,
10831083
*/
10841084
bool update_myrocks_table_names(THD *thd, const String_type &old_schema_name,
10851085
const String_type &new_schema_name,
1086-
const std::set<String_type> &table_names) {
1086+
const std::set<String_type> &table_names,
1087+
const std::set<String_type> &filter_table_names) {
10871088
assert(default_dd_storage_engine == DEFAULT_DD_ROCKSDB);
10881089
assert(bootstrap::DD_bootstrap_ctx::instance().is_dd_engine_change());
10891090

@@ -1097,8 +1098,12 @@ bool update_myrocks_table_names(THD *thd, const String_type &old_schema_name,
10971098
assert(false);
10981099
return true;
10991100
}
1101+
11001102
bool err = false;
11011103
for (const auto &table_name : table_names) {
1104+
// Skip some tables, such as InnoDB tables
1105+
if (filter_table_names.find(table_name) != filter_table_names.cend())
1106+
continue;
11021107
char old_table[FN_REFLEN + 1];
11031108
char new_table[FN_REFLEN + 1];
11041109
// old table full name under old schema name
@@ -1181,7 +1186,7 @@ bool upgrade_dd_properties_table(THD *thd, Object_id mysql_schema_id,
11811186
!dd::end_transaction(thd, false) &&
11821187
update_myrocks_table_names(thd, target_table_schema_name,
11831188
MYSQL_SCHEMA_NAME.str,
1184-
{dd_property_table_name})) {
1189+
{dd_property_table_name}, {})) {
11851190
LogErr(ERROR_LEVEL, ER_LOG_PRINTF_MSG,
11861191
"Failed to update myrocks table name for dd_properties table");
11871192
return true;
@@ -1284,8 +1289,9 @@ bool upgrade_tables(THD *thd) {
12841289
- Finally, update the version numbers and commit. In update_versions(),
12851290
the atomic switch will either be committed.
12861291
*/
1287-
if (update_properties(thd, &create_set, &remove_set,
1288-
target_table_schema_name) ||
1292+
std::set<String_type> innodb_set = {};
1293+
if (update_properties(thd, &create_set, &remove_set, target_table_schema_name,
1294+
&innodb_set) ||
12891295
update_object_ids(thd, create_set, remove_set, mysql_schema_id,
12901296
target_table_schema_id, target_table_schema_name,
12911297
actual_table_schema_id))
@@ -1296,7 +1302,8 @@ bool upgrade_tables(THD *thd) {
12961302
(default_dd_storage_engine == DEFAULT_DD_ROCKSDB) &&
12971303
!dd::end_transaction(thd, false) &&
12981304
update_myrocks_table_names(thd, target_table_schema_name,
1299-
MYSQL_SCHEMA_NAME.str, create_set)) {
1305+
MYSQL_SCHEMA_NAME.str, create_set,
1306+
innodb_set)) {
13001307
LogErr(ERROR_LEVEL, ER_LOG_PRINTF_MSG,
13011308
"Failed to update myrocks table name for non-dd_properties tables");
13021309
return true;

sql/sql_table.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18998,6 +18998,7 @@ static bool check_engine(THD *thd, const char *db_name, const char *table_name,
1899818998
handlerton **new_engine = &create_info->db_type;
1899918999

1900019000
if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE) && !opt_initialize &&
19001+
!dd::is_dd_engine_change_in_progress() &&
1900119002
ha_check_user_table_blocked(thd, *new_engine, db_name)) {
1900219003
handlerton *default_engine = ha_default_handlerton(thd);
1900319004
bool no_substitution = (!is_engine_substitution_allowed(thd));

storage/innobase/handler/ha_innodb.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15164,7 +15164,9 @@ bool ha_innobase::get_se_private_data(dd::Table *dd_table, bool reset) {
1516415164
dict_sys_t::s_dd_table_ids.clear();
1516515165
}
1516615166

15167-
if (!innobase_is_ddse()) {
15167+
// Similar to boostrap, During DDSE change, SQL layer may also ask
15168+
// se_private_data for other DD tables
15169+
if (!innobase_is_ddse() && !dd::is_dd_engine_change_in_progress()) {
1516815170
if (dd_table->name() == "dd_properties_placeholder") {
1516915171
n_tables = 0;
1517015172
n_indexes = 0;

0 commit comments

Comments
 (0)