2013-03-25 23:03:13 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
|
2017-10-25 20:35:33 +02:00
|
|
|
Copyright (c) 2012, 2017, Oracle and/or its affiliates. All Rights Reserved.
|
2018-05-01 00:10:37 +02:00
|
|
|
Copyright (c) 2017, 2018, MariaDB Corporation.
|
2013-03-25 23:03:13 +01:00
|
|
|
|
|
|
|
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.,
|
2019-05-11 18:25:02 +02:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
2013-03-25 23:03:13 +01:00
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************//**
|
|
|
|
@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
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
#include "dict0types.h"
|
|
|
|
#include "os0event.h"
|
|
|
|
#include "os0thread.h"
|
2013-03-25 23:03:13 +01:00
|
|
|
|
2017-02-17 09:32:21 +01:00
|
|
|
/** Event to wake up dict_stats_thread on dict_stats_recalc_pool_add()
|
|
|
|
or shutdown. Not protected by any mutex. */
|
2013-03-25 23:03:13 +01:00
|
|
|
extern os_event_t dict_stats_event;
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
extern mysql_pfs_key_t dict_stats_recalc_pool_mutex_key;
|
|
|
|
#endif /* HAVE_PSI_INTERFACE */
|
|
|
|
|
2016-09-06 08:43:16 +02:00
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
/** Value of MySQL global used to disable dict_stats thread. */
|
|
|
|
extern my_bool innodb_dict_stats_disabled_debug;
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
2013-03-25 23:03:13 +01:00
|
|
|
/*****************************************************************//**
|
|
|
|
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 */
|
2014-02-01 09:33:26 +01:00
|
|
|
|
|
|
|
/** Yield the data dictionary latch when waiting
|
|
|
|
for the background thread to stop accessing a table.
|
|
|
|
@param trx transaction holding the data dictionary locks */
|
2017-10-25 20:35:33 +02:00
|
|
|
#define DICT_BG_YIELD(trx) do { \
|
2014-02-01 09:33:26 +01:00
|
|
|
row_mysql_unlock_data_dictionary(trx); \
|
|
|
|
os_thread_sleep(250000); \
|
|
|
|
row_mysql_lock_data_dictionary(trx); \
|
|
|
|
} 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 */
|
2016-04-22 10:50:45 +02:00
|
|
|
{
|
|
|
|
ut_ad(!srv_read_only_mode);
|
2019-05-17 13:32:53 +02:00
|
|
|
ut_ad(mutex_own(&dict_sys.mutex));
|
2016-04-22 10:50:45 +02:00
|
|
|
|
|
|
|
if (!(table->stats_bg_flag & BG_STAT_IN_PROGRESS)) {
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
table->stats_bg_flag |= BG_STAT_SHOULD_QUIT;
|
|
|
|
return(false);
|
|
|
|
}
|
2013-03-25 23:03:13 +01:00
|
|
|
|
|
|
|
/*****************************************************************//**
|
2014-02-01 09:33:26 +01:00
|
|
|
Wait until background stats thread has stopped using the specified table.
|
2013-03-25 23:03:13 +01:00
|
|
|
The caller must have locked the data dictionary using
|
|
|
|
row_mysql_lock_data_dictionary() and this function may unlock it temporarily
|
|
|
|
and restore the lock before it exits.
|
2014-02-01 09:33:26 +01:00
|
|
|
The background stats thread is guaranteed not to start using the specified
|
|
|
|
table after this function returns and before the caller unlocks the data
|
2013-03-25 23:03:13 +01:00
|
|
|
dictionary because it sets the BG_STAT_IN_PROGRESS bit in table->stats_bg_flag
|
2019-05-17 13:32:53 +02:00
|
|
|
under dict_sys.mutex. */
|
2013-03-25 23:03:13 +01:00
|
|
|
void
|
2014-02-01 09:33:26 +01:00
|
|
|
dict_stats_wait_bg_to_stop_using_table(
|
|
|
|
/*===================================*/
|
|
|
|
dict_table_t* table, /*!< in/out: table */
|
2013-03-25 23:03:13 +01:00
|
|
|
trx_t* trx); /*!< in/out: transaction to use for
|
|
|
|
unlocking/locking the data dict */
|
|
|
|
/*****************************************************************//**
|
|
|
|
Initialize global variables needed for the operation of dict_stats_thread().
|
2014-02-01 09:33:26 +01:00
|
|
|
Must be called before dict_stats_thread() is started. */
|
2013-03-25 23:03:13 +01:00
|
|
|
void
|
|
|
|
dict_stats_thread_init();
|
|
|
|
/*====================*/
|
|
|
|
|
|
|
|
/*****************************************************************//**
|
|
|
|
Free resources allocated by dict_stats_thread_init(), must be called
|
2014-02-01 09:33:26 +01:00
|
|
|
after dict_stats_thread() has exited. */
|
2013-03-25 23:03:13 +01:00
|
|
|
void
|
|
|
|
dict_stats_thread_deinit();
|
|
|
|
/*======================*/
|
|
|
|
|
2016-09-06 08:43:16 +02:00
|
|
|
#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 */
|
2018-05-01 00:10:37 +02:00
|
|
|
void dict_stats_disabled_debug_update(THD*, st_mysql_sys_var*, void*,
|
|
|
|
const void* save);
|
2016-09-06 08:43:16 +02:00
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
2013-03-25 23:03:13 +01:00
|
|
|
/*****************************************************************//**
|
|
|
|
This is the thread for background stats gathering. It pops tables, from
|
|
|
|
the auto recalc list and proceeds them, eventually recalculating their
|
|
|
|
statistics.
|
|
|
|
@return this function does not return, it calls os_thread_exit() */
|
2016-08-12 10:17:45 +02:00
|
|
|
extern "C"
|
2013-03-25 23:03:13 +01:00
|
|
|
os_thread_ret_t
|
|
|
|
DECLARE_THREAD(dict_stats_thread)(
|
|
|
|
/*==============================*/
|
|
|
|
void* arg); /*!< in: a dummy parameter
|
|
|
|
required by os_thread_create */
|
2014-02-01 09:33:26 +01:00
|
|
|
|
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log
When a slow shutdown is performed soon after spawning some work for
background threads that can create or commit transactions, it is possible
that new transactions are started or committed after the purge has finished.
This is violating the specification of innodb_fast_shutdown=0, namely that
the purge must be completed. (None of the history of the recent transactions
would be purged.)
Also, it is possible that the purge threads would exit in slow shutdown
while there exist active transactions, such as recovered incomplete
transactions that are being rolled back. Thus, the slow shutdown could
fail to purge some undo log that becomes purgeable after the transaction
commit or rollback.
srv_undo_sources: A flag that indicates if undo log can be generated
or the persistent, whether by background threads or by user SQL.
Even when this flag is clear, active transactions that already exist
in the system may be committed or rolled back.
innodb_shutdown(): Renamed from innobase_shutdown_for_mysql().
Do not return an error code; the operation never fails.
Clear the srv_undo_sources flag, and also ensure that the background
DROP TABLE queue is empty.
srv_purge_should_exit(): Do not allow the purge to exit if
srv_undo_sources are active or the background DROP TABLE queue is not
empty, or in slow shutdown, if any active transactions exist
(and are being rolled back).
srv_purge_coordinator_thread(): Remove some previous workarounds
for this bug.
innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active
and srv_dict_stats_thread_active directly. Set srv_undo_sources before
starting the purge subsystem, to prevent immediate shutdown of the purge.
Create dict_stats_thread and fts_optimize_thread immediately
after setting srv_undo_sources, so that shutdown can use this flag to
determine if these subsystems were started.
dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2.
srv_shutdown_table_bg_threads(): Remove (unused).
2017-06-08 14:43:06 +02:00
|
|
|
/** Shut down the dict_stats_thread. */
|
2016-09-06 08:43:16 +02:00
|
|
|
void
|
|
|
|
dict_stats_shutdown();
|
|
|
|
|
2013-03-25 23:03:13 +01:00
|
|
|
#endif /* dict0stats_bg_h */
|