1/*****************************************************************************
2
3Copyright (C) 2013, 2014 Facebook, Inc. All Rights Reserved.
4Copyright (C) 2014, 2017, MariaDB Corporation.
5
6This program is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free Software
8Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful, but WITHOUT
11ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License along with
15this program; if not, write to the Free Software Foundation, Inc.,
1651 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 */
29extern ulint btr_defragment_compression_failures;
30extern ulint btr_defragment_failures;
31extern ulint btr_defragment_count;
32
33/** Item in the work queue for btr_degrament_thread. */
34struct 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/******************************************************************//**
49Initialize defragmentation. */
50void
51btr_defragment_init(void);
52/******************************************************************//**
53Shutdown defragmentation. */
54void
55btr_defragment_shutdown();
56/******************************************************************//**
57Check whether the given index is in btr_defragment_wq. */
58bool
59btr_defragment_find_index(
60 dict_index_t* index); /*!< Index to find. */
61/******************************************************************//**
62Add an index to btr_defragment_wq. Return a pointer to os_event if this
63is a synchronized defragmentation. */
64os_event_t
65btr_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/******************************************************************//**
71When table is dropped, this function is called to mark a table as removed in
72btr_efragment_wq. The difference between this function and the remove_index
73function is this will not NULL the event. */
74void
75btr_defragment_remove_table(
76 dict_table_t* table); /*!< Index to be removed. */
77/******************************************************************//**
78Mark an index as removed from btr_defragment_wq. */
79void
80btr_defragment_remove_index(
81 dict_index_t* index); /*!< Index to be removed. */
82/*********************************************************************//**
83Check whether we should save defragmentation statistics to persistent storage.*/
84UNIV_INTERN
85void
86btr_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 */
90extern "C" UNIV_INTERN
91os_thread_ret_t
92DECLARE_THREAD(btr_defragment_thread)(void*);
93
94/** Whether btr_defragment_thread is active */
95extern bool btr_defragment_thread_active;
96
97#endif
98