1
by brian
clean slate |
1 |
/******************************************************
|
2 |
Insert buffer
|
|
3 |
||
4 |
(c) 1997 Innobase Oy
|
|
5 |
||
6 |
Created 7/19/1997 Heikki Tuuri
|
|
7 |
*******************************************************/
|
|
8 |
||
9 |
#ifndef ibuf0ibuf_h
|
|
10 |
#define ibuf0ibuf_h
|
|
11 |
||
12 |
#include "univ.i" |
|
13 |
||
14 |
#include "dict0mem.h" |
|
15 |
#include "dict0dict.h" |
|
16 |
#include "mtr0mtr.h" |
|
17 |
#include "que0types.h" |
|
18 |
#include "ibuf0types.h" |
|
19 |
#include "fsp0fsp.h" |
|
20 |
||
21 |
extern ibuf_t* ibuf; |
|
22 |
||
23 |
/**********************************************************************
|
|
24 |
Creates the insert buffer data struct for a single tablespace. Reads the
|
|
25 |
root page of the insert buffer tree in the tablespace. This function can
|
|
26 |
be called only after the dictionary system has been initialized, as this
|
|
27 |
creates also the insert buffer table and index for this tablespace. */
|
|
28 |
||
29 |
ibuf_data_t* |
|
30 |
ibuf_data_init_for_space( |
|
31 |
/*=====================*/
|
|
32 |
/* out, own: ibuf data struct, linked to the list
|
|
33 |
in ibuf control structure. */
|
|
34 |
ulint space); /* in: space id */ |
|
35 |
/**********************************************************************
|
|
36 |
Creates the insert buffer data structure at a database startup and
|
|
37 |
initializes the data structures for the insert buffer of each tablespace. */
|
|
38 |
||
39 |
void
|
|
40 |
ibuf_init_at_db_start(void); |
|
41 |
/*=======================*/
|
|
42 |
/*************************************************************************
|
|
43 |
Reads the biggest tablespace id from the high end of the insert buffer
|
|
44 |
tree and updates the counter in fil_system. */
|
|
45 |
||
46 |
void
|
|
47 |
ibuf_update_max_tablespace_id(void); |
|
48 |
/*===============================*/
|
|
49 |
/*************************************************************************
|
|
50 |
Initializes an ibuf bitmap page. */
|
|
51 |
||
52 |
void
|
|
53 |
ibuf_bitmap_page_init( |
|
54 |
/*==================*/
|
|
55 |
page_t* page, /* in: bitmap page */ |
|
56 |
mtr_t* mtr); /* in: mtr */ |
|
57 |
/****************************************************************************
|
|
58 |
Resets the free bits of the page in the ibuf bitmap. This is done in a
|
|
59 |
separate mini-transaction, hence this operation does not restrict further
|
|
60 |
work to only ibuf bitmap operations, which would result if the latch to the
|
|
61 |
bitmap page were kept. */
|
|
62 |
||
63 |
void
|
|
64 |
ibuf_reset_free_bits_with_type( |
|
65 |
/*===========================*/
|
|
66 |
ulint type, /* in: index type */ |
|
67 |
page_t* page); /* in: index page; free bits are set to 0 if the index |
|
68 |
is non-clustered and non-unique and the page level is
|
|
69 |
0 */
|
|
70 |
/****************************************************************************
|
|
71 |
Resets the free bits of the page in the ibuf bitmap. This is done in a
|
|
72 |
separate mini-transaction, hence this operation does not restrict further
|
|
73 |
work to solely ibuf bitmap operations, which would result if the latch to
|
|
74 |
the bitmap page were kept. */
|
|
75 |
||
76 |
void
|
|
77 |
ibuf_reset_free_bits( |
|
78 |
/*=================*/
|
|
79 |
dict_index_t* index, /* in: index */ |
|
80 |
page_t* page); /* in: index page; free bits are set to 0 if |
|
81 |
the index is non-clustered and non-unique and
|
|
82 |
the page level is 0 */
|
|
83 |
/****************************************************************************
|
|
84 |
Updates the free bits of the page in the ibuf bitmap if there is not enough
|
|
85 |
free on the page any more. This is done in a separate mini-transaction, hence
|
|
86 |
this operation does not restrict further work to only ibuf bitmap operations,
|
|
87 |
which would result if the latch to the bitmap page were kept. */
|
|
88 |
UNIV_INLINE
|
|
89 |
void
|
|
90 |
ibuf_update_free_bits_if_full( |
|
91 |
/*==========================*/
|
|
92 |
dict_index_t* index, /* in: index */ |
|
93 |
page_t* page, /* in: index page to which we have added new |
|
94 |
records; the free bits are updated if the
|
|
95 |
index is non-clustered and non-unique and
|
|
96 |
the page level is 0, and the page becomes
|
|
97 |
fuller */
|
|
98 |
ulint max_ins_size,/* in: value of maximum insert size with |
|
99 |
reorganize before the latest operation
|
|
100 |
performed to the page */
|
|
101 |
ulint increase);/* in: upper limit for the additional space |
|
102 |
used in the latest operation, if known, or
|
|
103 |
ULINT_UNDEFINED */
|
|
104 |
/**************************************************************************
|
|
105 |
Updates the free bits for the page to reflect the present state. Does this
|
|
106 |
in the mtr given, which means that the latching order rules virtually
|
|
107 |
prevent any further operations for this OS thread until mtr is committed. */
|
|
108 |
||
109 |
void
|
|
110 |
ibuf_update_free_bits_low( |
|
111 |
/*======================*/
|
|
112 |
dict_index_t* index, /* in: index */ |
|
113 |
page_t* page, /* in: index page */ |
|
114 |
ulint max_ins_size, /* in: value of maximum insert size |
|
115 |
with reorganize before the latest
|
|
116 |
operation performed to the page */
|
|
117 |
mtr_t* mtr); /* in: mtr */ |
|
118 |
/**************************************************************************
|
|
119 |
Updates the free bits for the two pages to reflect the present state. Does
|
|
120 |
this in the mtr given, which means that the latching order rules virtually
|
|
121 |
prevent any further operations until mtr is committed. */
|
|
122 |
||
123 |
void
|
|
124 |
ibuf_update_free_bits_for_two_pages_low( |
|
125 |
/*====================================*/
|
|
126 |
dict_index_t* index, /* in: index */ |
|
127 |
page_t* page1, /* in: index page */ |
|
128 |
page_t* page2, /* in: index page */ |
|
129 |
mtr_t* mtr); /* in: mtr */ |
|
130 |
/**************************************************************************
|
|
131 |
A basic partial test if an insert to the insert buffer could be possible and
|
|
132 |
recommended. */
|
|
133 |
UNIV_INLINE
|
|
134 |
ibool
|
|
135 |
ibuf_should_try( |
|
136 |
/*============*/
|
|
137 |
dict_index_t* index, /* in: index where to insert */ |
|
138 |
ulint ignore_sec_unique); /* in: if != 0, we should |
|
139 |
ignore UNIQUE constraint on
|
|
140 |
a secondary index when we
|
|
141 |
decide */
|
|
142 |
/**********************************************************************
|
|
143 |
Returns TRUE if the current OS thread is performing an insert buffer
|
|
144 |
routine. */
|
|
145 |
||
146 |
ibool
|
|
147 |
ibuf_inside(void); |
|
148 |
/*=============*/
|
|
149 |
/* out: TRUE if inside an insert buffer routine: for instance,
|
|
150 |
a read-ahead of non-ibuf pages is then forbidden */
|
|
151 |
/***************************************************************************
|
|
152 |
Checks if a page address is an ibuf bitmap page (level 3 page) address. */
|
|
153 |
UNIV_INLINE
|
|
154 |
ibool
|
|
155 |
ibuf_bitmap_page( |
|
156 |
/*=============*/
|
|
157 |
/* out: TRUE if a bitmap page */
|
|
158 |
ulint page_no);/* in: page number */ |
|
159 |
/***************************************************************************
|
|
160 |
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */
|
|
161 |
||
162 |
ibool
|
|
163 |
ibuf_page( |
|
164 |
/*======*/
|
|
165 |
/* out: TRUE if level 2 or level 3 page */
|
|
166 |
ulint space, /* in: space id */ |
|
167 |
ulint page_no);/* in: page number */ |
|
168 |
/***************************************************************************
|
|
169 |
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */
|
|
170 |
||
171 |
ibool
|
|
172 |
ibuf_page_low( |
|
173 |
/*==========*/
|
|
174 |
/* out: TRUE if level 2 or level 3 page */
|
|
175 |
ulint space, /* in: space id */ |
|
176 |
ulint page_no,/* in: page number */ |
|
177 |
mtr_t* mtr); /* in: mtr which will contain an x-latch to the |
|
178 |
bitmap page if the page is not one of the fixed
|
|
179 |
address ibuf pages */
|
|
180 |
/***************************************************************************
|
|
181 |
Frees excess pages from the ibuf free list. This function is called when an OS
|
|
182 |
thread calls fsp services to allocate a new file segment, or a new page to a
|
|
183 |
file segment, and the thread did not own the fsp latch before this call. */
|
|
184 |
||
185 |
void
|
|
186 |
ibuf_free_excess_pages( |
|
187 |
/*===================*/
|
|
188 |
ulint space); /* in: space id */ |
|
189 |
/*************************************************************************
|
|
190 |
Makes an index insert to the insert buffer, instead of directly to the disk
|
|
191 |
page, if this is possible. Does not do insert if the index is clustered
|
|
192 |
or unique. */
|
|
193 |
||
194 |
ibool
|
|
195 |
ibuf_insert( |
|
196 |
/*========*/
|
|
197 |
/* out: TRUE if success */
|
|
198 |
dtuple_t* entry, /* in: index entry to insert */ |
|
199 |
dict_index_t* index, /* in: index where to insert */ |
|
200 |
ulint space, /* in: space id where to insert */ |
|
201 |
ulint page_no,/* in: page number where to insert */ |
|
202 |
que_thr_t* thr); /* in: query thread */ |
|
203 |
/*************************************************************************
|
|
204 |
When an index page is read from a disk to the buffer pool, this function
|
|
205 |
inserts to the page the possible index entries buffered in the insert buffer.
|
|
206 |
The entries are deleted from the insert buffer. If the page is not read, but
|
|
207 |
created in the buffer pool, this function deletes its buffered entries from
|
|
208 |
the insert buffer; there can exist entries for such a page if the page
|
|
209 |
belonged to an index which subsequently was dropped. */
|
|
210 |
||
211 |
void
|
|
212 |
ibuf_merge_or_delete_for_page( |
|
213 |
/*==========================*/
|
|
214 |
page_t* page, /* in: if page has been read from disk, pointer to |
|
215 |
the page x-latched, else NULL */
|
|
216 |
ulint space, /* in: space id of the index page */ |
|
217 |
ulint page_no,/* in: page number of the index page */ |
|
218 |
ibool update_ibuf_bitmap);/* in: normally this is set to TRUE, but if |
|
219 |
we have deleted or are deleting the tablespace, then we
|
|
220 |
naturally do not want to update a non-existent bitmap
|
|
221 |
page */
|
|
222 |
/*************************************************************************
|
|
223 |
Deletes all entries in the insert buffer for a given space id. This is used
|
|
224 |
in DISCARD TABLESPACE and IMPORT TABLESPACE.
|
|
225 |
NOTE: this does not update the page free bitmaps in the space. The space will
|
|
226 |
become CORRUPT when you call this function! */
|
|
227 |
||
228 |
void
|
|
229 |
ibuf_delete_for_discarded_space( |
|
230 |
/*============================*/
|
|
231 |
ulint space); /* in: space id */ |
|
232 |
/*************************************************************************
|
|
233 |
Contracts insert buffer trees by reading pages to the buffer pool. */
|
|
234 |
||
235 |
ulint
|
|
236 |
ibuf_contract( |
|
237 |
/*==========*/
|
|
238 |
/* out: a lower limit for the combined size in bytes
|
|
239 |
of entries which will be merged from ibuf trees to the
|
|
240 |
pages read, 0 if ibuf is empty */
|
|
241 |
ibool sync); /* in: TRUE if the caller wants to wait for the |
|
242 |
issued read with the highest tablespace address
|
|
243 |
to complete */
|
|
244 |
/*************************************************************************
|
|
245 |
Contracts insert buffer trees by reading pages to the buffer pool. */
|
|
246 |
||
247 |
ulint
|
|
248 |
ibuf_contract_for_n_pages( |
|
249 |
/*======================*/
|
|
250 |
/* out: a lower limit for the combined size in bytes
|
|
251 |
of entries which will be merged from ibuf trees to the
|
|
252 |
pages read, 0 if ibuf is empty */
|
|
253 |
ibool sync, /* in: TRUE if the caller wants to wait for the |
|
254 |
issued read with the highest tablespace address
|
|
255 |
to complete */
|
|
256 |
ulint n_pages);/* in: try to read at least this many pages to |
|
257 |
the buffer pool and merge the ibuf contents to
|
|
258 |
them */
|
|
259 |
/*************************************************************************
|
|
260 |
Parses a redo log record of an ibuf bitmap page init. */
|
|
261 |
||
262 |
byte* |
|
263 |
ibuf_parse_bitmap_init( |
|
264 |
/*===================*/
|
|
265 |
/* out: end of log record or NULL */
|
|
266 |
byte* ptr, /* in: buffer */ |
|
267 |
byte* end_ptr,/* in: buffer end */ |
|
268 |
page_t* page, /* in: page or NULL */ |
|
269 |
mtr_t* mtr); /* in: mtr or NULL */ |
|
270 |
#ifdef UNIV_IBUF_DEBUG
|
|
271 |
/**********************************************************************
|
|
272 |
Gets the ibuf count for a given page. */
|
|
273 |
||
274 |
ulint
|
|
275 |
ibuf_count_get( |
|
276 |
/*===========*/
|
|
277 |
/* out: number of entries in the insert buffer
|
|
278 |
currently buffered for this page */
|
|
279 |
ulint space, /* in: space id */ |
|
280 |
ulint page_no);/* in: page number */ |
|
281 |
#endif
|
|
282 |
/**********************************************************************
|
|
283 |
Looks if the insert buffer is empty. */
|
|
284 |
||
285 |
ibool
|
|
286 |
ibuf_is_empty(void); |
|
287 |
/*===============*/
|
|
288 |
/* out: TRUE if empty */
|
|
289 |
/**********************************************************************
|
|
290 |
Prints info of ibuf. */
|
|
291 |
||
292 |
void
|
|
293 |
ibuf_print( |
|
294 |
/*=======*/
|
|
295 |
FILE* file); /* in: file where to print */ |
|
296 |
||
297 |
#define IBUF_HEADER_PAGE_NO FSP_IBUF_HEADER_PAGE_NO
|
|
298 |
#define IBUF_TREE_ROOT_PAGE_NO FSP_IBUF_TREE_ROOT_PAGE_NO
|
|
299 |
||
300 |
/* The ibuf header page currently contains only the file segment header
|
|
301 |
for the file segment from which the pages for the ibuf tree are allocated */
|
|
302 |
#define IBUF_HEADER PAGE_DATA
|
|
303 |
#define IBUF_TREE_SEG_HEADER 0 /* fseg header for ibuf tree */ |
|
304 |
||
305 |
#ifndef UNIV_NONINL
|
|
306 |
#include "ibuf0ibuf.ic" |
|
307 |
#endif
|
|
308 |
||
309 |
#endif
|