diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-11-13 21:54:21 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-11-13 21:54:21 +0200 |
commit | d7a582489900ea175d9659304c4fdc39b3880014 (patch) | |
tree | 06a2485b15b84fedf197c573276441ea8d8bccb0 /sql/wsrep_mysqld.cc | |
parent | 97569d3c37a66bc941b933ac7c2cefa5430a5175 (diff) | |
parent | b2029c0300bf8c311ff5d9fdc4b73a9e48bf6930 (diff) | |
download | mariadb-git-d7a582489900ea175d9659304c4fdc39b3880014.tar.gz |
Merge 10.4 into 10.5
Diffstat (limited to 'sql/wsrep_mysqld.cc')
-rw-r--r-- | sql/wsrep_mysqld.cc | 76 |
1 files changed, 65 insertions, 11 deletions
diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index a6b0991e82b..1dfeb782bbe 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -1261,6 +1261,51 @@ void wsrep_keys_free(wsrep_key_arr_t* key_arr) key_arr->keys_len= 0; } +void +wsrep_append_fk_parent_table(THD* thd, TABLE_LIST* tables, wsrep::key_array* keys) +{ + if (!WSREP(thd) || !WSREP_CLIENT(thd)) return; + TABLE_LIST *table; + + thd->mdl_context.release_transactional_locks(); + uint counter; + MDL_savepoint mdl_savepoint= thd->mdl_context.mdl_savepoint(); + + if (thd->open_temporary_tables(tables) || + open_tables(thd, &tables, &counter, MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL)) + { + WSREP_DEBUG("unable to open table for FK checks for %s", thd->query()); + } + + for (table= tables; table; table= table->next_local) + { + if (!is_temporary_table(table) && table->table) + { + FOREIGN_KEY_INFO *f_key_info; + List<FOREIGN_KEY_INFO> f_key_list; + + table->table->file->get_foreign_key_list(thd, &f_key_list); + List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list); + while ((f_key_info=it++)) + { + WSREP_DEBUG("appended fkey %s", f_key_info->referenced_table->str); + keys->push_back(wsrep_prepare_key_for_toi(f_key_info->referenced_db->str, + f_key_info->referenced_table->str, + wsrep::key::shared)); + } + } + } + + /* close the table and release MDL locks */ + close_thread_tables(thd); + thd->mdl_context.rollback_to_savepoint(mdl_savepoint); + for (table= tables; table; table= table->next_local) + { + table->table= NULL; + table->mdl_request.ticket= NULL; + } +} + /*! * @param db Database string * @param table Table string @@ -1511,10 +1556,11 @@ wsrep_prepare_keys_for_alter_add_fk(const char* child_table_db, return ret; } -wsrep::key_array wsrep_prepare_keys_for_toi(const char* db, - const char* table, - const TABLE_LIST* table_list, - const Alter_info* alter_info) +wsrep::key_array wsrep_prepare_keys_for_toi(const char *db, + const char *table, + const TABLE_LIST *table_list, + const Alter_info *alter_info, + const wsrep::key_array *fk_tables) { wsrep::key_array ret; if (db || table) @@ -1534,8 +1580,13 @@ wsrep::key_array wsrep_prepare_keys_for_toi(const char* db, ret.insert(ret.end(), fk.begin(), fk.end()); } } + if (fk_tables && !fk_tables->empty()) + { + ret.insert(ret.end(), fk_tables->begin(), fk_tables->end()); + } return ret; } + /* * Construct Query_log_Event from thd query and serialize it * into buffer. @@ -2069,9 +2120,10 @@ fail: -1: TOI replication failed */ static int wsrep_TOI_begin(THD *thd, const char *db, const char *table, - const TABLE_LIST* table_list, - const Alter_info* alter_info, - const HA_CREATE_INFO* create_info) + const TABLE_LIST *table_list, + const Alter_info *alter_info, + const wsrep::key_array *fk_tables, + const HA_CREATE_INFO *create_info) { DBUG_ASSERT(wsrep_OSU_method_get(thd) == WSREP_OSU_TOI); @@ -2102,7 +2154,7 @@ static int wsrep_TOI_begin(THD *thd, const char *db, const char *table, struct wsrep_buf buff= { buf, buf_len }; wsrep::key_array key_array= - wsrep_prepare_keys_for_toi(db, table, table_list, alter_info); + wsrep_prepare_keys_for_toi(db, table, table_list, alter_info, fk_tables); if (thd->has_read_only_protection()) { @@ -2250,8 +2302,9 @@ static void wsrep_RSU_end(THD *thd) int wsrep_to_isolation_begin(THD *thd, const char *db_, const char *table_, const TABLE_LIST* table_list, - const Alter_info* alter_info, - const HA_CREATE_INFO* create_info) + const Alter_info *alter_info, + const wsrep::key_array *fk_tables, + const HA_CREATE_INFO *create_info) { /* No isolation for applier or replaying threads. @@ -2305,7 +2358,8 @@ int wsrep_to_isolation_begin(THD *thd, const char *db_, const char *table_, { switch (wsrep_OSU_method_get(thd)) { case WSREP_OSU_TOI: - ret= wsrep_TOI_begin(thd, db_, table_, table_list, alter_info, create_info); + ret= wsrep_TOI_begin(thd, db_, table_, table_list, alter_info, fk_tables, + create_info); break; case WSREP_OSU_RSU: ret= wsrep_RSU_begin(thd, db_, table_); |