1 /***************************************************************************** 2 3 Copyright (c) 2012, 2017, Oracle and/or its affiliates. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License along with 22 this program; if not, write to the Free Software Foundation, Inc., 23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA 24 25 *****************************************************************************/ 26 27 /**************************************************//** 28 @file include/dict0stats_bg.h 29 Code used for background table and index stats gathering. 30 31 Created Apr 26, 2012 Vasil Dimov 32 *******************************************************/ 33 34 #ifndef dict0stats_bg_h 35 #define dict0stats_bg_h 36 37 #include "univ.i" 38 39 #include "dict0types.h" /* dict_table_t, table_id_t */ 40 #include "os0sync.h" /* os_event_t */ 41 #include "os0thread.h" /* DECLARE_THREAD */ 42 43 /** Event to wake up the stats thread */ 44 extern os_event_t dict_stats_event; 45 46 /*****************************************************************//** 47 Add a table to the recalc pool, which is processed by the 48 background stats gathering thread. Only the table id is added to the 49 list, so the table can be closed after being enqueued and it will be 50 opened when needed. If the table does not exist later (has been DROPped), 51 then it will be removed from the pool and skipped. */ 52 UNIV_INTERN 53 void 54 dict_stats_recalc_pool_add( 55 /*=======================*/ 56 const dict_table_t* table); /*!< in: table to add */ 57 58 /*****************************************************************//** 59 Delete a given table from the auto recalc pool. 60 dict_stats_recalc_pool_del() */ 61 UNIV_INTERN 62 void 63 dict_stats_recalc_pool_del( 64 /*=======================*/ 65 const dict_table_t* table); /*!< in: table to remove */ 66 67 /** Yield the data dictionary latch when waiting 68 for the background thread to stop accessing a table. 69 @param trx transaction holding the data dictionary locks */ 70 #define DICT_BG_YIELD(trx) do { \ 71 row_mysql_unlock_data_dictionary(trx); \ 72 os_thread_sleep(250000); \ 73 row_mysql_lock_data_dictionary(trx); \ 74 } while (0) 75 76 /*****************************************************************//** 77 Request the background collection of statistics to stop for a table. 78 @retval true when no background process is active 79 @retval false when it is not safe to modify the table definition */ 80 UNIV_INLINE 81 bool 82 dict_stats_stop_bg( 83 /*===============*/ 84 dict_table_t* table) /*!< in/out: table */ 85 MY_ATTRIBUTE((warn_unused_result)); 86 87 /*****************************************************************//** 88 Wait until background stats thread has stopped using the specified table. 89 The caller must have locked the data dictionary using 90 row_mysql_lock_data_dictionary() and this function may unlock it temporarily 91 and restore the lock before it exits. 92 The background stats thread is guaranteed not to start using the specified 93 table after this function returns and before the caller unlocks the data 94 dictionary because it sets the BG_STAT_IN_PROGRESS bit in table->stats_bg_flag 95 under dict_sys->mutex. */ 96 UNIV_INTERN 97 void 98 dict_stats_wait_bg_to_stop_using_table( 99 /*===================================*/ 100 dict_table_t* table, /*!< in/out: table */ 101 trx_t* trx); /*!< in/out: transaction to use for 102 unlocking/locking the data dict */ 103 /*****************************************************************//** 104 Initialize global variables needed for the operation of dict_stats_thread(). 105 Must be called before dict_stats_thread() is started. */ 106 UNIV_INTERN 107 void 108 dict_stats_thread_init(); 109 /*====================*/ 110 111 /*****************************************************************//** 112 Free resources allocated by dict_stats_thread_init(), must be called 113 after dict_stats_thread() has exited. */ 114 UNIV_INTERN 115 void 116 dict_stats_thread_deinit(); 117 /*======================*/ 118 119 /*****************************************************************//** 120 This is the thread for background stats gathering. It pops tables, from 121 the auto recalc list and proceeds them, eventually recalculating their 122 statistics. 123 @return this function does not return, it calls os_thread_exit() */ 124 extern "C" UNIV_INTERN 125 os_thread_ret_t 126 DECLARE_THREAD(dict_stats_thread)( 127 /*==============================*/ 128 void* arg); /*!< in: a dummy parameter 129 required by os_thread_create */ 130 131 # ifndef UNIV_NONINL 132 # include "dict0stats_bg.ic" 133 # endif 134 135 #endif /* dict0stats_bg_h */ 136