You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
4.7 KiB

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