diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2021-09-18 14:39:32 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2021-09-18 14:39:32 +0300 |
commit | b740b2356d539a27f8a7a9e9b6455f31bc6c9196 (patch) | |
tree | d488c5da5c6d0ce5bf0507f1ce5b23f988eacc06 | |
parent | 56843d62f935d3859bf45b5ea5876a7b97fc118d (diff) | |
download | mariadb-git-b740b2356d539a27f8a7a9e9b6455f31bc6c9196.tar.gz |
MDEV-25919 fixup: Acquire MDL also in defragmentation
dict_stats_process_entry_from_defrag_pool(): Acquire MDL on the table
for which we are invoking dict_stats_save_defrag_stats(), to avoid
any race condition with DROP TABLE or similar operations.
-rw-r--r-- | storage/innobase/dict/dict0defrag_bg.cc | 31 | ||||
-rw-r--r-- | storage/innobase/dict/dict0stats_bg.cc | 2 | ||||
-rw-r--r-- | storage/innobase/include/dict0defrag_bg.h | 8 |
3 files changed, 18 insertions, 23 deletions
diff --git a/storage/innobase/dict/dict0defrag_bg.cc b/storage/innobase/dict/dict0defrag_bg.cc index 396b66941c5..35ffee7e0d0 100644 --- a/storage/innobase/dict/dict0defrag_bg.cc +++ b/storage/innobase/dict/dict0defrag_bg.cc @@ -173,10 +173,10 @@ dict_stats_defrag_pool_del( /*****************************************************************//** Get the first index that has been added for updating persistent defrag stats and eventually save its stats. */ -static void dict_stats_process_entry_from_defrag_pool() +static void dict_stats_process_entry_from_defrag_pool(THD *thd) { - table_id_t table_id; - index_id_t index_id; + table_id_t table_id; + index_id_t index_id; ut_ad(!srv_read_only_mode); @@ -185,31 +185,28 @@ static void dict_stats_process_entry_from_defrag_pool() /* no index in defrag pool */ return; - dict_sys.freeze(SRW_LOCK_CALL); - /* If the table is no longer cached, we've already lost the in memory stats so there's nothing really to write to disk. */ - dict_table_t *table= dict_sys.find_table(table_id); - dict_index_t *index= table && !table->corrupted - ? dict_table_find_index_on_id(table, index_id) : nullptr; - const bool save= index && !index->is_corrupted(); - if (save) - table->acquire(); - dict_sys.unfreeze(); - if (save) + MDL_ticket *mdl= nullptr; + if (dict_table_t *table= + dict_table_open_on_id(table_id, false, DICT_TABLE_OP_OPEN_ONLY_IF_CACHED, + thd, &mdl)) { - dict_stats_save_defrag_stats(index); - table->release(); + if (dict_index_t *index= !table->corrupted + ? dict_table_find_index_on_id(table, index_id) : nullptr) + if (!index->is_corrupted()) + dict_stats_save_defrag_stats(index); + dict_table_close(table, false, thd, mdl); } } /** Get the first index that has been added for updating persistent defrag stats and eventually save its stats. */ -void dict_defrag_process_entries_from_defrag_pool() +void dict_defrag_process_entries_from_defrag_pool(THD *thd) { while (!defrag_pool.empty()) - dict_stats_process_entry_from_defrag_pool(); + dict_stats_process_entry_from_defrag_pool(thd); } /*********************************************************************//** diff --git a/storage/innobase/dict/dict0stats_bg.cc b/storage/innobase/dict/dict0stats_bg.cc index 91c18c95851..676656122a3 100644 --- a/storage/innobase/dict/dict0stats_bg.cc +++ b/storage/innobase/dict/dict0stats_bg.cc @@ -391,7 +391,7 @@ static void dict_stats_func(void*) THD *thd= innobase_create_background_thd("InnoDB statistics"); set_current_thd(thd); while (dict_stats_process_entry_from_recalc_pool(thd)) {} - dict_defrag_process_entries_from_defrag_pool(); + dict_defrag_process_entries_from_defrag_pool(thd); set_current_thd(nullptr); innobase_destroy_background_thd(thd); } diff --git a/storage/innobase/include/dict0defrag_bg.h b/storage/innobase/include/dict0defrag_bg.h index 0edc6304788..679484ad64e 100644 --- a/storage/innobase/include/dict0defrag_bg.h +++ b/storage/innobase/include/dict0defrag_bg.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2016, 2020, MariaDB Corporation. +Copyright (c) 2016, 2021, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -80,12 +80,10 @@ dict_stats_defrag_pool_del( all entries for the table */ const dict_index_t* index); /*!< in: index to remove */ -/*****************************************************************//** +/** Get the first index that has been added for updating persistent defrag stats and eventually save its stats. */ -void -dict_defrag_process_entries_from_defrag_pool(); -/*===========================================*/ +void dict_defrag_process_entries_from_defrag_pool(THD *thd); /*********************************************************************//** Save defragmentation result. |