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