summaryrefslogtreecommitdiff
path: root/storage/innobase/dict/dict0stats_bg.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/innobase/dict/dict0stats_bg.cc')
-rw-r--r--storage/innobase/dict/dict0stats_bg.cc141
1 files changed, 76 insertions, 65 deletions
diff --git a/storage/innobase/dict/dict0stats_bg.cc b/storage/innobase/dict/dict0stats_bg.cc
index 7aefa6a1d4d..eca3756152a 100644
--- a/storage/innobase/dict/dict0stats_bg.cc
+++ b/storage/innobase/dict/dict0stats_bg.cc
@@ -23,11 +23,13 @@ Code used for background table and index stats gathering.
Created Apr 25, 2012 Vasil Dimov
*******************************************************/
-#include "row0mysql.h"
-#include "srv0start.h"
+#include "dict0dict.h"
#include "dict0dict.h"
#include "dict0stats.h"
#include "dict0stats_bg.h"
+#include "row0mysql.h"
+#include "srv0start.h"
+#include "ut0new.h"
#ifdef UNIV_NONINL
# include "dict0stats_bg.ic"
@@ -41,34 +43,47 @@ Created Apr 25, 2012 Vasil Dimov
#define SHUTTING_DOWN() (srv_shutdown_state != SRV_SHUTDOWN_NONE)
/** Event to wake up the stats thread */
-UNIV_INTERN os_event_t dict_stats_event = NULL;
+os_event_t dict_stats_event = NULL;
/** This mutex protects the "recalc_pool" variable. */
static ib_mutex_t recalc_pool_mutex;
static ib_mutex_t defrag_pool_mutex;
-#ifdef HAVE_PSI_INTERFACE
-static mysql_pfs_key_t recalc_pool_mutex_key;
static mysql_pfs_key_t defrag_pool_mutex_key;
-#endif /* HAVE_PSI_INTERFACE */
/** The number of tables that can be added to "recalc_pool" before
it is enlarged */
-static const ulint RECALC_POOL_INITIAL_SLOTS = 128;
+static const ulint RECALC_POOL_INITIAL_SLOTS = 128;
+static const ulint DEFRAG_POOL_INITIAL_SLOTS = 128;
+
+/** Allocator type, used by std::vector */
+typedef ut_allocator<table_id_t>
+ recalc_pool_allocator_t;
/** The multitude of tables whose stats are to be automatically
recalculated - an STL vector */
-typedef std::vector<table_id_t> recalc_pool_t;
-static recalc_pool_t recalc_pool;
+typedef std::vector<table_id_t, recalc_pool_allocator_t>
+ recalc_pool_t;
+
+/** Iterator type for iterating over the elements of objects of type
+recalc_pool_t. */
+typedef recalc_pool_t::iterator
+ recalc_pool_iterator_t;
-typedef recalc_pool_t::iterator recalc_pool_iterator_t;
+/** Pool where we store information on which tables are to be processed
+by background statistics gathering. */
+static recalc_pool_t* recalc_pool;
/** Indices whose defrag stats need to be saved to persistent storage.*/
struct defrag_pool_item_t {
table_id_t table_id;
index_id_t index_id;
};
-typedef std::vector<defrag_pool_item_t> defrag_pool_t;
-static defrag_pool_t defrag_pool;
+
+typedef ut_allocator<defrag_pool_item_t>
+ defrag_pool_allocator_t;
+typedef std::vector<defrag_pool_item_t, defrag_pool_allocator_t>
+ defrag_pool_t;
+static defrag_pool_t* defrag_pool;
typedef defrag_pool_t::iterator defrag_pool_iterator_t;
/*****************************************************************//**
@@ -79,9 +94,18 @@ dict_stats_pool_init()
/*=========================*/
{
ut_ad(!srv_read_only_mode);
-
- recalc_pool.reserve(RECALC_POOL_INITIAL_SLOTS);
- defrag_pool.reserve(RECALC_POOL_INITIAL_SLOTS);
+ /* JAN: TODO: MySQL 5.7 PSI
+ const PSI_memory_key key = mem_key_dict_stats_bg_recalc_pool_t;
+ const PSI_memory_key key2 = mem_key_dict_defrag_pool_t;
+
+ recalc_pool = UT_NEW(recalc_pool_t(recalc_pool_allocator_t(key)), key);
+ defrag_pool = UT_NEW(defrag_pool_t(defrag_pool_allocator_t(key2)), key2);
+
+ defrag_pool->reserve(DEFRAG_POOL_INITIAL_SLOTS);
+ recalc_pool->reserve(RECALC_POOL_INITIAL_SLOTS);
+ */
+ recalc_pool = new std::vector<table_id_t, recalc_pool_allocator_t>();
+ defrag_pool = new std::vector<defrag_pool_item_t, defrag_pool_allocator_t>();
}
/*****************************************************************//**
@@ -94,22 +118,11 @@ dict_stats_pool_deinit()
{
ut_ad(!srv_read_only_mode);
- recalc_pool.clear();
- defrag_pool.clear();
- /*
- recalc_pool may still have its buffer allocated. It will free it when
- its destructor is called.
- The problem is, memory leak detector is run before the recalc_pool's
- destructor is invoked, and will report recalc_pool's buffer as leaked
- memory. To avoid that, we force recalc_pool to surrender its buffer
- to empty_pool object, which will free it when leaving this function:
- */
- recalc_pool_t recalc_empty_pool;
- defrag_pool_t defrag_empty_pool;
- memset(&recalc_empty_pool, 0, sizeof(recalc_pool_t));
- memset(&defrag_empty_pool, 0, sizeof(defrag_pool_t));
- recalc_pool.swap(recalc_empty_pool);
- defrag_pool.swap(defrag_empty_pool);
+ recalc_pool->clear();
+ defrag_pool->clear();
+
+ UT_DELETE(recalc_pool);
+ UT_DELETE(defrag_pool);
}
/*****************************************************************//**
@@ -118,7 +131,6 @@ background stats gathering thread. Only the table id is added to the
list, so the table can be closed after being enqueued and it will be
opened when needed. If the table does not exist later (has been DROPped),
then it will be removed from the pool and skipped. */
-UNIV_INTERN
void
dict_stats_recalc_pool_add(
/*=======================*/
@@ -129,8 +141,8 @@ dict_stats_recalc_pool_add(
mutex_enter(&recalc_pool_mutex);
/* quit if already in the list */
- for (recalc_pool_iterator_t iter = recalc_pool.begin();
- iter != recalc_pool.end();
+ for (recalc_pool_iterator_t iter = recalc_pool->begin();
+ iter != recalc_pool->end();
++iter) {
if (*iter == table->id) {
@@ -139,7 +151,7 @@ dict_stats_recalc_pool_add(
}
}
- recalc_pool.push_back(table->id);
+ recalc_pool->push_back(table->id);
mutex_exit(&recalc_pool_mutex);
@@ -161,14 +173,14 @@ dict_stats_recalc_pool_get(
mutex_enter(&recalc_pool_mutex);
- if (recalc_pool.empty()) {
+ if (recalc_pool->empty()) {
mutex_exit(&recalc_pool_mutex);
return(false);
}
- *id = recalc_pool[0];
+ *id = recalc_pool->at(0);
- recalc_pool.erase(recalc_pool.begin());
+ recalc_pool->erase(recalc_pool->begin());
mutex_exit(&recalc_pool_mutex);
@@ -178,7 +190,6 @@ dict_stats_recalc_pool_get(
/*****************************************************************//**
Delete a given table from the auto recalc pool.
dict_stats_recalc_pool_del() */
-UNIV_INTERN
void
dict_stats_recalc_pool_del(
/*=======================*/
@@ -191,13 +202,13 @@ dict_stats_recalc_pool_del(
ut_ad(table->id > 0);
- for (recalc_pool_iterator_t iter = recalc_pool.begin();
- iter != recalc_pool.end();
+ for (recalc_pool_iterator_t iter = recalc_pool->begin();
+ iter != recalc_pool->end();
++iter) {
if (*iter == table->id) {
/* erase() invalidates the iterator */
- recalc_pool.erase(iter);
+ recalc_pool->erase(iter);
break;
}
}
@@ -224,8 +235,8 @@ dict_stats_defrag_pool_add(
mutex_enter(&defrag_pool_mutex);
/* quit if already in the list */
- for (defrag_pool_iterator_t iter = defrag_pool.begin();
- iter != defrag_pool.end();
+ for (defrag_pool_iterator_t iter = defrag_pool->begin();
+ iter != defrag_pool->end();
++iter) {
if ((*iter).table_id == index->table->id
&& (*iter).index_id == index->id) {
@@ -236,7 +247,7 @@ dict_stats_defrag_pool_add(
item.table_id = index->table->id;
item.index_id = index->id;
- defrag_pool.push_back(item);
+ defrag_pool->push_back(item);
mutex_exit(&defrag_pool_mutex);
@@ -260,16 +271,16 @@ dict_stats_defrag_pool_get(
mutex_enter(&defrag_pool_mutex);
- if (defrag_pool.empty()) {
+ if (defrag_pool->empty()) {
mutex_exit(&defrag_pool_mutex);
return(false);
}
- defrag_pool_item_t& item = defrag_pool.back();
+ defrag_pool_item_t& item = defrag_pool->back();
*table_id = item.table_id;
*index_id = item.index_id;
- defrag_pool.pop_back();
+ defrag_pool->pop_back();
mutex_exit(&defrag_pool_mutex);
@@ -292,14 +303,14 @@ dict_stats_defrag_pool_del(
mutex_enter(&defrag_pool_mutex);
- defrag_pool_iterator_t iter = defrag_pool.begin();
- while (iter != defrag_pool.end()) {
+ defrag_pool_iterator_t iter = defrag_pool->begin();
+ while (iter != defrag_pool->end()) {
if ((table && (*iter).table_id == table->id)
|| (index
&& (*iter).table_id == index->table->id
&& (*iter).index_id == index->id)) {
/* erase() invalidates the iterator */
- iter = defrag_pool.erase(iter);
+ iter = defrag_pool->erase(iter);
if (index)
break;
} else {
@@ -319,7 +330,6 @@ The background stats thread is guaranteed not to start using the specified
table after this function returns and before the caller unlocks the data
dictionary because it sets the BG_STAT_IN_PROGRESS bit in table->stats_bg_flag
under dict_sys->mutex. */
-UNIV_INTERN
void
dict_stats_wait_bg_to_stop_using_table(
/*===================================*/
@@ -335,14 +345,13 @@ dict_stats_wait_bg_to_stop_using_table(
/*****************************************************************//**
Initialize global variables needed for the operation of dict_stats_thread()
Must be called before dict_stats_thread() is started. */
-UNIV_INTERN
void
dict_stats_thread_init()
/*====================*/
{
ut_a(!srv_read_only_mode);
- dict_stats_event = os_event_create();
+ dict_stats_event = os_event_create(0);
/* The recalc_pool_mutex is acquired from:
1) the background stats gathering thread before any other latch
@@ -357,19 +366,18 @@ dict_stats_thread_init()
and dict_operation_lock (SYNC_DICT_OPERATION) have been locked
(thus a level <SYNC_DICT && <SYNC_DICT_OPERATION would do)
So we choose SYNC_STATS_AUTO_RECALC to be about below SYNC_DICT. */
- mutex_create(recalc_pool_mutex_key, &recalc_pool_mutex,
- SYNC_STATS_AUTO_RECALC);
+
+ mutex_create(LATCH_ID_RECALC_POOL, &recalc_pool_mutex);
/* We choose SYNC_STATS_DEFRAG to be below SYNC_FSP_PAGE. */
- mutex_create(defrag_pool_mutex_key, &defrag_pool_mutex,
- SYNC_STATS_DEFRAG);
+ mutex_create(LATCH_ID_DEFRAGMENT_MUTEX, &defrag_pool_mutex);
+
dict_stats_pool_init();
}
/*****************************************************************//**
Free resources allocated by dict_stats_thread_init(), must be called
after dict_stats_thread() has exited. */
-UNIV_INTERN
void
dict_stats_thread_deinit()
/*======================*/
@@ -380,12 +388,9 @@ dict_stats_thread_deinit()
dict_stats_pool_deinit();
mutex_free(&recalc_pool_mutex);
- memset(&recalc_pool_mutex, 0x0, sizeof(recalc_pool_mutex));
-
mutex_free(&defrag_pool_mutex);
- memset(&defrag_pool_mutex, 0x0, sizeof(defrag_pool_mutex));
- os_event_free(dict_stats_event);
+ os_event_destroy(dict_stats_event);
dict_stats_event = NULL;
}
@@ -523,7 +528,7 @@ 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() */
-extern "C" UNIV_INTERN
+extern "C"
os_thread_ret_t
DECLARE_THREAD(dict_stats_thread)(
/*==============================*/
@@ -532,6 +537,12 @@ DECLARE_THREAD(dict_stats_thread)(
{
ut_a(!srv_read_only_mode);
+#ifdef UNIV_PFS_THREAD
+ /* JAN: TODO: MySQL 5.7 PSI
+ pfs_register_thread(dict_stats_thread_key);
+ */
+#endif /* UNIV_PFS_THREAD */
+
srv_dict_stats_thread_active = TRUE;
while (!SHUTTING_DOWN()) {
@@ -550,7 +561,7 @@ DECLARE_THREAD(dict_stats_thread)(
dict_stats_process_entry_from_recalc_pool();
- while (defrag_pool.size())
+ while (defrag_pool->size())
dict_stats_process_entry_from_defrag_pool();
os_event_reset(dict_stats_event);