Drizzled Public API Documentation

ibuf0ibuf.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (C) 1997, 2009, Innobase Oy. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15 St, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #pragma once
27 #ifndef ibuf0ibuf_h
28 #define ibuf0ibuf_h
29 
30 #include "univ.i"
31 
32 #include "mtr0mtr.h"
33 #include "dict0mem.h"
34 #include "fsp0fsp.h"
35 
36 #ifndef UNIV_HOTBACKUP
37 # include "ibuf0types.h"
38 
39 /* Possible operations buffered in the insert/whatever buffer. See
40 ibuf_insert(). DO NOT CHANGE THE VALUES OF THESE, THEY ARE STORED ON DISK. */
41 typedef enum {
42  IBUF_OP_INSERT = 0,
43  IBUF_OP_DELETE_MARK = 1,
44  IBUF_OP_DELETE = 2,
45 
46  /* Number of different operation types. */
47  IBUF_OP_COUNT = 3
48 } ibuf_op_t;
49 
53 typedef enum {
54  IBUF_USE_NONE = 0,
55  IBUF_USE_INSERT, /* insert */
56  IBUF_USE_DELETE_MARK, /* delete */
57  IBUF_USE_INSERT_DELETE_MARK, /* insert+delete */
58  IBUF_USE_DELETE, /* delete+purge */
59  IBUF_USE_ALL, /* insert+delete+purge */
60 
61  IBUF_USE_COUNT /* number of entries in ibuf_use_t */
62 } ibuf_use_t;
63 
65 extern ibuf_use_t ibuf_use;
66 
67 #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
68 
69 extern uint ibuf_debug;
70 #endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
71 
73 extern ibuf_t* ibuf;
74 
75 /* The purpose of the insert buffer is to reduce random disk access.
76 When we wish to insert a record into a non-unique secondary index and
77 the B-tree leaf page where the record belongs to is not in the buffer
78 pool, we insert the record into the insert buffer B-tree, indexed by
79 (space_id, page_no). When the page is eventually read into the buffer
80 pool, we look up the insert buffer B-tree for any modifications to the
81 page, and apply these upon the completion of the read operation. This
82 is called the insert buffer merge. */
83 
84 /* The insert buffer merge must always succeed. To guarantee this,
85 the insert buffer subsystem keeps track of the free space in pages for
86 which it can buffer operations. Two bits per page in the insert
87 buffer bitmap indicate the available space in coarse increments. The
88 free bits in the insert buffer bitmap must never exceed the free space
89 on a page. It is safe to decrement or reset the bits in the bitmap in
90 a mini-transaction that is committed before the mini-transaction that
91 affects the free space. It is unsafe to increment the bits in a
92 separately committed mini-transaction, because in crash recovery, the
93 free bits could momentarily be set too high. */
94 
95 /******************************************************************/
97 UNIV_INTERN
98 void
99 ibuf_init_at_db_start(void);
100 /*=======================*/
101 /*********************************************************************/
104 UNIV_INTERN
105 void
106 ibuf_update_max_tablespace_id(void);
107 /*===============================*/
108 /*********************************************************************/
110 UNIV_INTERN
111 void
112 ibuf_bitmap_page_init(
113 /*==================*/
114  buf_block_t* block,
115  mtr_t* mtr);
116 /************************************************************************/
125 UNIV_INTERN
126 void
127 ibuf_reset_free_bits(
128 /*=================*/
129  buf_block_t* block);
132 /************************************************************************/
145 UNIV_INLINE
146 void
148 /*==========================*/
149  buf_block_t* block,
154  ulint max_ins_size,
157  ulint increase);
160 /**********************************************************************/
168 UNIV_INTERN
169 void
170 ibuf_update_free_bits_low(
171 /*======================*/
172  const buf_block_t* block,
173  ulint max_ins_size,
178  mtr_t* mtr);
179 /**********************************************************************/
187 UNIV_INTERN
188 void
189 ibuf_update_free_bits_zip(
190 /*======================*/
191  buf_block_t* block,
192  mtr_t* mtr);
193 /**********************************************************************/
200 UNIV_INTERN
201 void
202 ibuf_update_free_bits_for_two_pages_low(
203 /*====================================*/
204  ulint zip_size,
206  buf_block_t* block1,
207  buf_block_t* block2,
208  mtr_t* mtr);
209 /**********************************************************************/
212 UNIV_INLINE
213 ibool
215 /*============*/
216  dict_index_t* index,
217  ulint ignore_sec_unique);
221 /******************************************************************/
228 UNIV_INTERN
229 ibool
230 ibuf_inside(void);
231 /*=============*/
232 /***********************************************************************/
235 UNIV_INLINE
236 ibool
238 /*=============*/
239  ulint zip_size,
241  ulint page_no);
242 /***********************************************************************/
246 UNIV_INTERN
247 ibool
248 ibuf_page(
249 /*======*/
250  ulint space,
251  ulint zip_size,
252  ulint page_no,
253  mtr_t* mtr);
257 /***********************************************************************/
261 UNIV_INTERN
262 void
263 ibuf_free_excess_pages(void);
264 /*========================*/
265 /*********************************************************************/
270 UNIV_INTERN
271 ibool
272 ibuf_insert(
273 /*========*/
274  ibuf_op_t op,
275  const dtuple_t* entry,
276  dict_index_t* index,
277  ulint space,
278  ulint zip_size,
279  ulint page_no,
280  que_thr_t* thr);
281 /*********************************************************************/
288 UNIV_INTERN
289 void
291 /*==========================*/
292  buf_block_t* block,
295  ulint space,
296  ulint page_no,
297  ulint zip_size,
299  ibool update_ibuf_bitmap);
304 /*********************************************************************/
309 UNIV_INTERN
310 void
312 /*============================*/
313  ulint space);
314 /*********************************************************************/
319 UNIV_INTERN
320 ulint
321 ibuf_contract(
322 /*==========*/
323  ibool sync);
326 /*********************************************************************/
331 UNIV_INTERN
332 ulint
333 ibuf_contract_for_n_pages(
334 /*======================*/
335  ibool sync,
338  ulint n_pages);
341 #endif /* !UNIV_HOTBACKUP */
342 /*********************************************************************/
345 UNIV_INTERN
346 byte*
347 ibuf_parse_bitmap_init(
348 /*===================*/
349  byte* ptr,
350  byte* end_ptr,
351  buf_block_t* block,
352  mtr_t* mtr);
353 #ifndef UNIV_HOTBACKUP
354 #ifdef UNIV_IBUF_COUNT_DEBUG
355 /******************************************************************/
359 UNIV_INTERN
360 ulint
361 ibuf_count_get(
362 /*===========*/
363  ulint space,
364  ulint page_no);
365 #endif
366 /******************************************************************/
369 UNIV_INTERN
370 ibool
371 ibuf_is_empty(void);
372 /*===============*/
373 /******************************************************************/
375 UNIV_INTERN
376 void
377 ibuf_print(
378 /*=======*/
379  FILE* file);
380 /********************************************************************
381 Read the first two bytes from a record's fourth field (counter field in new
382 records; something else in older records).
383 @return "counter" field, or ULINT_UNDEFINED if for some reason it can't be read */
384 UNIV_INTERN
385 ulint
386 ibuf_rec_get_counter(
387 /*=================*/
388  const rec_t* rec);
389 /******************************************************************/
391 UNIV_INTERN
392 void
393 ibuf_close(void);
394 /*============*/
395 
396 #define IBUF_HEADER_PAGE_NO FSP_IBUF_HEADER_PAGE_NO
397 #define IBUF_TREE_ROOT_PAGE_NO FSP_IBUF_TREE_ROOT_PAGE_NO
398 
399 #endif /* !UNIV_HOTBACKUP */
400 
401 /* The ibuf header page currently contains only the file segment header
402 for the file segment from which the pages for the ibuf tree are allocated */
403 #define IBUF_HEADER PAGE_DATA
404 #define IBUF_TREE_SEG_HEADER 0 /* fseg header for ibuf tree */
405 
406 /* The insert buffer tree itself is always located in space 0. */
407 #define IBUF_SPACE_ID 0
408 
409 #ifndef UNIV_NONINL
410 #include "ibuf0ibuf.ic"
411 #endif
412 
413 #endif