Commit b740b235 authored by Marko Mäkelä's avatar Marko Mäkelä

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.
parent 56843d62
......@@ -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);
}
/*********************************************************************//**
......
......@@ -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);
}
......
/*****************************************************************************
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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment