mirror of
https://github.com/MariaDB/server.git
synced 2026-05-02 13:15:32 +02:00
In the parent commit, dict_sys.latch could theoretically have been
replaced with a mutex. But, we can do better and merge dict_sys.mutex
into dict_sys.latch. Generally, every occurrence of dict_sys.mutex_lock()
will be replaced with dict_sys.lock().
The PERFORMANCE_SCHEMA instrumentation for dict_sys_mutex
will be removed along with dict_sys.mutex. The dict_sys.latch
will remain instrumented as dict_operation_lock.
Some use of dict_sys.lock() will be replaced with dict_sys.freeze(),
which we will reintroduce for the new shared mode. Most notably,
concurrent table lookups are possible as long as the tables are present
in the dict_sys cache. In particular, this will allow more concurrency
among InnoDB purge workers.
Because dict_sys.mutex will no longer 'throttle' the threads that purge
InnoDB transaction history, a performance degradation may be observed
unless innodb_purge_threads=1.
The table cache eviction policy will become FIFO-like,
similar to what happened to fil_system.LRU
in commit 45ed9dd957.
The name of the list dict_sys.table_LRU will become somewhat misleading;
that list contains tables that may be evicted, even though the
eviction policy no longer is least-recently-used but first-in-first-out.
(Note: Tables can never be evicted as long as locks exist on them or
the tables are in use by some thread.)
As demonstrated by the test perfschema.sxlock_func, there
will be less contention on dict_sys.latch, because some previous
use of exclusive latches will be replaced with shared latches.
fts_parse_sql_no_dict_lock(): Replaced with pars_sql().
fts_get_table_name_prefix(): Merged to fts_optimize_create().
dict_stats_update_transient_for_index(): Deduplicated some code.
ha_innobase::info_low(), dict_stats_stop_bg(): Use a combination
of dict_sys.latch and table->stats_mutex_lock() to cover the
changes of BG_STAT_SHOULD_QUIT, because the flag is being read
in dict_stats_update_persistent() while not holding dict_sys.latch.
row_discard_tablespace_for_mysql(): Protect stats_bg_flag by
exclusive dict_sys.latch, like most other code does.
row_quiesce_table_has_fts_index(): Remove unnecessary mutex
acquisition. FLUSH TABLES...FOR EXPORT is protected by MDL.
row_import::set_root_by_heuristic(): Remove unnecessary mutex
acquisition. ALTER TABLE...IMPORT TABLESPACE is protected by MDL.
row_ins_sec_index_entry_low(): Replace a call
to dict_set_corrupted_index_cache_only(). Reads of index->type
were not really protected by dict_sys.mutex, and writes
(flagging an index corrupted) should be extremely rare.
dict_stats_process_entry_from_defrag_pool(): Only freeze the dictionary,
do not lock it exclusively.
dict_stats_wait_bg_to_stop_using_table(), DICT_BG_YIELD: Remove trx.
We can simply invoke dict_sys.unlock() and dict_sys.lock() directly.
dict_acquire_mdl_shared()<trylock=false>: Assert that dict_sys.latch is
only held in shared more, not exclusive mode. Only acquire it in
exclusive mode if the table needs to be loaded to the cache.
dict_sys_t::acquire(): Remove. Relocating elements in dict_sys.table_LRU
would require holding an exclusive latch, which we want to avoid
for performance reasons.
dict_sys_t::allow_eviction(): Add the table first to dict_sys.table_LRU,
to compensate for the removal of dict_sys_t::acquire(). This function
is only invoked by INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS.
dict_table_open_on_id(), dict_table_open_on_name(): If dict_locked=false,
try to acquire dict_sys.latch in shared mode. Only acquire the latch in
exclusive mode if the table is not found in the cache.
Reviewed by: Thirunarayanan Balathandayuthapani
118 lines
4.1 KiB
C++
118 lines
4.1 KiB
C++
/*****************************************************************************
|
|
|
|
Copyright (c) 2012, 2017, Oracle and/or its affiliates. All Rights Reserved.
|
|
Copyright (c) 2017, 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
|
|
Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
/**************************************************//**
|
|
@file include/dict0stats_bg.h
|
|
Code used for background table and index stats gathering.
|
|
|
|
Created Apr 26, 2012 Vasil Dimov
|
|
*******************************************************/
|
|
|
|
#ifndef dict0stats_bg_h
|
|
#define dict0stats_bg_h
|
|
|
|
#include "dict0types.h"
|
|
#include "os0thread.h"
|
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
extern mysql_pfs_key_t recalc_pool_mutex_key;
|
|
#endif /* HAVE_PSI_INTERFACE */
|
|
|
|
#ifdef UNIV_DEBUG
|
|
/** Value of MySQL global used to disable dict_stats thread. */
|
|
extern my_bool innodb_dict_stats_disabled_debug;
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
/*****************************************************************//**
|
|
Delete a given table from the auto recalc pool.
|
|
dict_stats_recalc_pool_del() */
|
|
void
|
|
dict_stats_recalc_pool_del(
|
|
/*=======================*/
|
|
const dict_table_t* table); /*!< in: table to remove */
|
|
|
|
/** Yield the data dictionary latch when waiting
|
|
for the background thread to stop accessing a table.
|
|
@param trx transaction holding the data dictionary locks */
|
|
#define DICT_BG_YIELD do { \
|
|
dict_sys.unlock(); \
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(250)); \
|
|
dict_sys.lock(SRW_LOCK_CALL); \
|
|
} while (0)
|
|
|
|
/*****************************************************************//**
|
|
Request the background collection of statistics to stop for a table.
|
|
@retval true when no background process is active
|
|
@retval false when it is not safe to modify the table definition */
|
|
UNIV_INLINE
|
|
bool
|
|
dict_stats_stop_bg(
|
|
/*===============*/
|
|
dict_table_t* table) /*!< in/out: table */
|
|
{
|
|
ut_ad(!srv_read_only_mode);
|
|
ut_ad(dict_sys.locked());
|
|
|
|
if (!(table->stats_bg_flag & BG_STAT_IN_PROGRESS)) {
|
|
return(true);
|
|
}
|
|
|
|
/* In dict_stats_update_persistent() this flag is being read
|
|
while holding the mutex, not dict_sys.latch. */
|
|
table->stats_mutex_lock();
|
|
table->stats_bg_flag |= BG_STAT_SHOULD_QUIT;
|
|
table->stats_mutex_unlock();
|
|
return(false);
|
|
}
|
|
|
|
/*****************************************************************//**
|
|
Wait until background stats thread has stopped using the specified table.
|
|
The background stats thread is guaranteed not to start using the specified
|
|
table after this function returns and before the caller releases
|
|
dict_sys.latch. */
|
|
void dict_stats_wait_bg_to_stop_using_table(dict_table_t *table);
|
|
|
|
/*****************************************************************//**
|
|
Initialize global variables needed for the operation of dict_stats_thread().
|
|
Must be called before dict_stats task is started. */
|
|
void dict_stats_init();
|
|
|
|
/*****************************************************************//**
|
|
Free resources allocated by dict_stats_thread_init(), must be called
|
|
after dict_stats task has exited. */
|
|
void dict_stats_deinit();
|
|
|
|
#ifdef UNIV_DEBUG
|
|
/** Disables dict stats thread. It's used by:
|
|
SET GLOBAL innodb_dict_stats_disabled_debug = 1 (0).
|
|
@param[in] save immediate result from check function */
|
|
void dict_stats_disabled_debug_update(THD*, st_mysql_sys_var*, void*,
|
|
const void* save);
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
/** Start the dict stats timer. */
|
|
void dict_stats_start();
|
|
|
|
/** Shut down the dict_stats timer. */
|
|
void dict_stats_shutdown();
|
|
|
|
/** Reschedule dict stats timer to run now. */
|
|
void dict_stats_schedule_now();
|
|
|
|
#endif /* dict0stats_bg_h */
|