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.

95 lines
3.5 KiB

  1. /*****************************************************************************
  2. Copyright (C) 2013, 2014 Facebook, Inc. All Rights Reserved.
  3. Copyright (C) 2014, 2017, MariaDB Corporation.
  4. This program is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free Software
  6. Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License along with
  11. this program; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
  13. *****************************************************************************/
  14. #ifndef btr0defragment_h
  15. #define btr0defragment_h
  16. #include "btr0pcur.h"
  17. /* Max number of pages to consider at once during defragmentation. */
  18. #define BTR_DEFRAGMENT_MAX_N_PAGES 32
  19. /** stats in btr_defragment */
  20. extern ulint btr_defragment_compression_failures;
  21. extern ulint btr_defragment_failures;
  22. extern ulint btr_defragment_count;
  23. /** Item in the work queue for btr_degrament_thread. */
  24. struct btr_defragment_item_t
  25. {
  26. btr_pcur_t* pcur; /* persistent cursor where
  27. btr_defragment_n_pages should start */
  28. os_event_t event; /* if not null, signal after work
  29. is done */
  30. bool removed; /* Mark an item as removed */
  31. ulonglong last_processed; /* timestamp of last time this index
  32. is processed by defragment thread */
  33. btr_defragment_item_t(btr_pcur_t* pcur, os_event_t event);
  34. ~btr_defragment_item_t();
  35. };
  36. /******************************************************************//**
  37. Initialize defragmentation. */
  38. void
  39. btr_defragment_init(void);
  40. /******************************************************************//**
  41. Shutdown defragmentation. */
  42. void
  43. btr_defragment_shutdown();
  44. /******************************************************************//**
  45. Check whether the given index is in btr_defragment_wq. */
  46. bool
  47. btr_defragment_find_index(
  48. dict_index_t* index); /*!< Index to find. */
  49. /******************************************************************//**
  50. Add an index to btr_defragment_wq. Return a pointer to os_event if this
  51. is a synchronized defragmentation. */
  52. os_event_t
  53. btr_defragment_add_index(
  54. dict_index_t* index, /*!< index to be added */
  55. dberr_t* err); /*!< out: error code */
  56. /******************************************************************//**
  57. When table is dropped, this function is called to mark a table as removed in
  58. btr_efragment_wq. The difference between this function and the remove_index
  59. function is this will not NULL the event. */
  60. void
  61. btr_defragment_remove_table(
  62. dict_table_t* table); /*!< Index to be removed. */
  63. /******************************************************************//**
  64. Mark an index as removed from btr_defragment_wq. */
  65. void
  66. btr_defragment_remove_index(
  67. dict_index_t* index); /*!< Index to be removed. */
  68. /*********************************************************************//**
  69. Check whether we should save defragmentation statistics to persistent storage.*/
  70. UNIV_INTERN
  71. void
  72. btr_defragment_save_defrag_stats_if_needed(
  73. dict_index_t* index); /*!< in: index */
  74. /** Merge consecutive b-tree pages into fewer pages to defragment indexes */
  75. extern "C" UNIV_INTERN
  76. os_thread_ret_t
  77. DECLARE_THREAD(btr_defragment_thread)(void*);
  78. /** Whether btr_defragment_thread is active */
  79. extern bool btr_defragment_thread_active;
  80. #endif