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_INLINE
111 void
113 /*===========*/
114  mtr_t* mtr)
115  __attribute__((nonnull));
116 /***************************************************************/
118 UNIV_INLINE
119 void
121 /*============*/
122  mtr_t* mtr)
123  __attribute__((nonnull));
124 /*********************************************************************/
126 UNIV_INTERN
127 void
128 ibuf_bitmap_page_init(
129 /*==================*/
130  buf_block_t* block,
131  mtr_t* mtr);
132 /************************************************************************/
141 UNIV_INTERN
142 void
143 ibuf_reset_free_bits(
144 /*=================*/
145  buf_block_t* block);
148 /************************************************************************/
161 UNIV_INLINE
162 void
164 /*==========================*/
165  buf_block_t* block,
170  ulint max_ins_size,
173  ulint increase);
176 /**********************************************************************/
184 UNIV_INTERN
185 void
186 ibuf_update_free_bits_low(
187 /*======================*/
188  const buf_block_t* block,
189  ulint max_ins_size,
194  mtr_t* mtr);
195 /**********************************************************************/
203 UNIV_INTERN
204 void
205 ibuf_update_free_bits_zip(
206 /*======================*/
207  buf_block_t* block,
208  mtr_t* mtr);
209 /**********************************************************************/
216 UNIV_INTERN
217 void
218 ibuf_update_free_bits_for_two_pages_low(
219 /*====================================*/
220  ulint zip_size,
222  buf_block_t* block1,
223  buf_block_t* block2,
224  mtr_t* mtr);
225 /**********************************************************************/
228 UNIV_INLINE
229 ibool
231 /*============*/
232  dict_index_t* index,
233  ulint ignore_sec_unique);
237 /******************************************************************/
244 UNIV_INLINE
245 ibool
247 /*========*/
248  const mtr_t* mtr)
249  __attribute__((nonnull, pure));
250 /***********************************************************************/
253 UNIV_INLINE
254 ibool
256 /*=============*/
257  ulint zip_size,
259  ulint page_no);
260 /***********************************************************************/
264 UNIV_INTERN
265 ibool
266 ibuf_page_low(
267 /*==========*/
268  ulint space,
269  ulint zip_size,
270  ulint page_no,
271 #ifdef UNIV_DEBUG
272  ibool x_latch,
274 #endif /* UNIV_DEBUG */
275  const char* file,
276  ulint line,
277  mtr_t* mtr)
282  __attribute__((warn_unused_result));
283 #ifdef UNIV_DEBUG
284 
291 # define ibuf_page(space, zip_size, page_no, mtr) \
292  ibuf_page_low(space, zip_size, page_no, TRUE, __FILE__, __LINE__, mtr)
293 #else /* UVIV_DEBUG */
294 
301 # define ibuf_page(space, zip_size, page_no, mtr) \
302  ibuf_page_low(space, zip_size, page_no, __FILE__, __LINE__, mtr)
303 #endif /* UVIV_DEBUG */
304 /***********************************************************************/
308 UNIV_INTERN
309 void
310 ibuf_free_excess_pages(void);
311 /*========================*/
312 /*********************************************************************/
317 UNIV_INTERN
318 ibool
319 ibuf_insert(
320 /*========*/
321  ibuf_op_t op,
322  const dtuple_t* entry,
323  dict_index_t* index,
324  ulint space,
325  ulint zip_size,
326  ulint page_no,
327  que_thr_t* thr);
328 /*********************************************************************/
335 UNIV_INTERN
336 void
337 ibuf_merge_or_delete_for_page(
338 /*==========================*/
339  buf_block_t* block,
342  ulint space,
343  ulint page_no,
344  ulint zip_size,
346  ibool update_ibuf_bitmap);
351 /*********************************************************************/
356 UNIV_INTERN
357 void
358 ibuf_delete_for_discarded_space(
359 /*============================*/
360  ulint space);
361 /*********************************************************************/
366 UNIV_INTERN
367 ulint
368 ibuf_contract(
369 /*==========*/
370  ibool sync);
373 /*********************************************************************/
378 UNIV_INTERN
379 ulint
380 ibuf_contract_for_n_pages(
381 /*======================*/
382  ibool sync,
385  ulint n_pages);
388 #endif /* !UNIV_HOTBACKUP */
389 /*********************************************************************/
392 UNIV_INTERN
393 byte*
394 ibuf_parse_bitmap_init(
395 /*===================*/
396  byte* ptr,
397  byte* end_ptr,
398  buf_block_t* block,
399  mtr_t* mtr);
400 #ifndef UNIV_HOTBACKUP
401 #ifdef UNIV_IBUF_COUNT_DEBUG
402 /******************************************************************/
406 UNIV_INTERN
407 ulint
408 ibuf_count_get(
409 /*===========*/
410  ulint space,
411  ulint page_no);
412 #endif
413 /******************************************************************/
416 UNIV_INTERN
417 ibool
418 ibuf_is_empty(void);
419 /*===============*/
420 /******************************************************************/
422 UNIV_INTERN
423 void
424 ibuf_print(
425 /*=======*/
426  FILE* file);
427 /********************************************************************
428 Read the first two bytes from a record's fourth field (counter field in new
429 records; something else in older records).
430 @return "counter" field, or ULINT_UNDEFINED if for some reason it can't be read */
431 UNIV_INTERN
432 ulint
433 ibuf_rec_get_counter(
434 /*=================*/
435  const rec_t* rec);
436 /******************************************************************/
438 UNIV_INTERN
439 void
440 ibuf_close(void);
441 /*============*/
442 
443 #define IBUF_HEADER_PAGE_NO FSP_IBUF_HEADER_PAGE_NO
444 #define IBUF_TREE_ROOT_PAGE_NO FSP_IBUF_TREE_ROOT_PAGE_NO
445 
446 #endif /* !UNIV_HOTBACKUP */
447 
448 /* The ibuf header page currently contains only the file segment header
449 for the file segment from which the pages for the ibuf tree are allocated */
450 #define IBUF_HEADER PAGE_DATA
451 #define IBUF_TREE_SEG_HEADER 0 /* fseg header for ibuf tree */
452 
453 /* The insert buffer tree itself is always located in space 0. */
454 #define IBUF_SPACE_ID 0
455 
456 #ifndef UNIV_NONINL
457 #include "ibuf0ibuf.ic"
458 #endif
459 
460 #endif