1// Copyright 2014 Google
2
3#ifndef btr0scrub_h
4#define btr0scrub_h
5
6#include "univ.i"
7
8#include "dict0dict.h"
9#include "data0data.h"
10#include "page0cur.h"
11#include "mtr0mtr.h"
12#include "btr0types.h"
13
14/**
15 * enum describing page allocation status
16 */
17enum btr_scrub_page_allocation_status_t {
18 BTR_SCRUB_PAGE_FREE,
19 BTR_SCRUB_PAGE_ALLOCATED,
20 BTR_SCRUB_PAGE_ALLOCATION_UNKNOWN
21};
22
23/**
24* constants returned by btr_page_needs_scrubbing & btr_scrub_recheck_page
25*/
26#define BTR_SCRUB_PAGE 1 /* page should be scrubbed */
27#define BTR_SCRUB_SKIP_PAGE 2 /* no scrub & no action */
28#define BTR_SCRUB_SKIP_PAGE_AND_CLOSE_TABLE 3 /* no scrub & close table */
29#define BTR_SCRUB_SKIP_PAGE_AND_COMPLETE_SPACE 4 /* no scrub & complete space */
30#define BTR_SCRUB_TURNED_OFF 5 /* we detected that scrubbing
31 was disabled by global
32 variable */
33
34/**************************************************************//**
35struct for keeping scrub statistics. */
36struct btr_scrub_stat_t {
37 /* page reorganizations */
38 ulint page_reorganizations;
39 /* page splits */
40 ulint page_splits;
41 /* scrub failures */
42 ulint page_split_failures_underflow;
43 ulint page_split_failures_out_of_filespace;
44 ulint page_split_failures_missing_index;
45 ulint page_split_failures_unknown;
46};
47
48/**************************************************************//**
49struct for thread local scrub state. */
50struct btr_scrub_t {
51
52 /* current space */
53 ulint space;
54
55 /* is scrubbing enabled for this space */
56 bool scrubbing;
57
58 /* is current space compressed */
59 bool compressed;
60
61 dict_table_t* current_table;
62 dict_index_t* current_index;
63 /* savepoint for X_LATCH of block */
64 ulint savepoint;
65
66 /* statistic counters */
67 btr_scrub_stat_t scrub_stat;
68};
69
70/*********************************************************************
71Init scrub global variables */
72UNIV_INTERN
73void
74btr_scrub_init();
75
76/*********************************************************************
77Cleanup scrub globals */
78UNIV_INTERN
79void
80btr_scrub_cleanup();
81
82/***********************************************************************
83Return crypt statistics */
84UNIV_INTERN
85void
86btr_scrub_total_stat(
87/*==================*/
88 btr_scrub_stat_t *stat); /*!< out: stats to update */
89
90/**************************************************************//**
91Check if a page needs scrubbing
92* @return BTR_SCRUB_PAGE if page should be scrubbed
93* else btr_scrub_skip_page should be called
94* with this return value (and without any latches held)
95*/
96UNIV_INTERN
97int
98btr_page_needs_scrubbing(
99/*=====================*/
100 btr_scrub_t* scrub_data, /*!< in: scrub data */
101 buf_block_t* block, /*!< in: block to check, latched */
102 btr_scrub_page_allocation_status_t allocated); /*!< in: is block
103 allocated, free or
104 unknown */
105
106/****************************************************************
107Recheck if a page needs scrubbing, and if it does load appropriate
108table and index
109* @return BTR_SCRUB_PAGE if page should be scrubbed
110* else btr_scrub_skip_page should be called
111* with this return value (and without any latches held)
112*/
113UNIV_INTERN
114int
115btr_scrub_recheck_page(
116/*====================*/
117 btr_scrub_t* scrub_data, /*!< inut: scrub data */
118 buf_block_t* block, /*!< in: block */
119 btr_scrub_page_allocation_status_t allocated, /*!< in: is block
120 allocated or free */
121 mtr_t* mtr); /*!< in: mtr */
122
123/****************************************************************
124Perform actual scrubbing of page */
125UNIV_INTERN
126int
127btr_scrub_page(
128/*============*/
129 btr_scrub_t* scrub_data, /*!< in/out: scrub data */
130 buf_block_t* block, /*!< in: block */
131 btr_scrub_page_allocation_status_t allocated, /*!< in: is block
132 allocated or free */
133 mtr_t* mtr); /*!< in: mtr */
134
135/****************************************************************
136Perform cleanup needed for a page not needing scrubbing */
137UNIV_INTERN
138void
139btr_scrub_skip_page(
140/*============*/
141 btr_scrub_t* scrub_data, /*!< in/out: scrub data */
142 int needs_scrubbing); /*!< in: return value from
143 btr_page_needs_scrubbing or
144 btr_scrub_recheck_page which encodes what kind
145 of cleanup is needed */
146
147/****************************************************************
148Start iterating a space
149* @return true if scrubbing is turned on */
150UNIV_INTERN
151bool
152btr_scrub_start_space(
153/*===================*/
154 ulint space, /*!< in: space */
155 btr_scrub_t* scrub_data); /*!< in/out: scrub data */
156
157/** Complete iterating a space.
158@param[in,out] scrub_data scrub data */
159UNIV_INTERN
160void
161btr_scrub_complete_space(btr_scrub_t* scrub_data);
162
163#endif
164