InnoDB Plugin  1.0
ibuf0ibuf.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #ifndef ibuf0ibuf_h
27 #define ibuf0ibuf_h
28 
29 #include "univ.i"
30 
31 #include "mtr0mtr.h"
32 #include "dict0mem.h"
33 #include "fsp0fsp.h"
34 
35 #ifndef UNIV_HOTBACKUP
36 # include "ibuf0types.h"
37 
40 #define CHANGE_BUFFER_DEFAULT_SIZE (25)
41 
42 /* Possible operations buffered in the insert/whatever buffer. See
43 ibuf_insert(). DO NOT CHANGE THE VALUES OF THESE, THEY ARE STORED ON DISK. */
44 typedef enum {
45  IBUF_OP_INSERT = 0,
46  IBUF_OP_DELETE_MARK = 1,
47  IBUF_OP_DELETE = 2,
48 
49  /* Number of different operation types. */
50  IBUF_OP_COUNT = 3
51 } ibuf_op_t;
52 
56 typedef enum {
57  IBUF_USE_NONE = 0,
58  IBUF_USE_INSERT, /* insert */
59  IBUF_USE_DELETE_MARK, /* delete */
60  IBUF_USE_INSERT_DELETE_MARK, /* insert+delete */
61  IBUF_USE_DELETE, /* delete+purge */
62  IBUF_USE_ALL, /* insert+delete+purge */
63 
64  IBUF_USE_COUNT /* number of entries in ibuf_use_t */
65 } ibuf_use_t;
66 
68 extern ibuf_use_t ibuf_use;
69 
71 extern ibuf_t* ibuf;
72 
73 /* The purpose of the insert buffer is to reduce random disk access.
74 When we wish to insert a record into a non-unique secondary index and
75 the B-tree leaf page where the record belongs to is not in the buffer
76 pool, we insert the record into the insert buffer B-tree, indexed by
77 (space_id, page_no). When the page is eventually read into the buffer
78 pool, we look up the insert buffer B-tree for any modifications to the
79 page, and apply these upon the completion of the read operation. This
80 is called the insert buffer merge. */
81 
82 /* The insert buffer merge must always succeed. To guarantee this,
83 the insert buffer subsystem keeps track of the free space in pages for
84 which it can buffer operations. Two bits per page in the insert
85 buffer bitmap indicate the available space in coarse increments. The
86 free bits in the insert buffer bitmap must never exceed the free space
87 on a page. It is safe to decrement or reset the bits in the bitmap in
88 a mini-transaction that is committed before the mini-transaction that
89 affects the free space. It is unsafe to increment the bits in a
90 separately committed mini-transaction, because in crash recovery, the
91 free bits could momentarily be set too high. */
92 
93 /******************************************************************/
95 UNIV_INTERN
96 void
98 /*=======================*/
99 /*********************************************************************/
101 UNIV_INTERN
102 void
104 /*=================*/
105  ulint new_val);
107 /*********************************************************************/
110 UNIV_INTERN
111 void
113 /*===============================*/
114 /***************************************************************/
116 UNIV_INLINE
117 void
119 /*===========*/
120  mtr_t* mtr)
121  __attribute__((nonnull));
122 /***************************************************************/
124 UNIV_INLINE
125 void
127 /*============*/
128  mtr_t* mtr)
129  __attribute__((nonnull));
130 /*********************************************************************/
132 UNIV_INTERN
133 void
135 /*==================*/
136  buf_block_t* block,
137  mtr_t* mtr);
138 /************************************************************************/
147 UNIV_INTERN
148 void
150 /*=================*/
151  buf_block_t* block);
154 /************************************************************************/
167 UNIV_INLINE
168 void
170 /*==========================*/
171  buf_block_t* block,
176  ulint max_ins_size,
179  ulint increase);
182 /**********************************************************************/
190 UNIV_INTERN
191 void
193 /*======================*/
194  const buf_block_t* block,
195  ulint max_ins_size,
200  mtr_t* mtr);
201 /**********************************************************************/
209 UNIV_INTERN
210 void
212 /*======================*/
213  buf_block_t* block,
214  mtr_t* mtr);
215 /**********************************************************************/
222 UNIV_INTERN
223 void
225 /*====================================*/
226  ulint zip_size,
228  buf_block_t* block1,
229  buf_block_t* block2,
230  mtr_t* mtr);
231 /**********************************************************************/
234 UNIV_INLINE
235 ibool
237 /*============*/
238  dict_index_t* index,
239  ulint ignore_sec_unique);
243 /******************************************************************/
250 UNIV_INLINE
251 ibool
253 /*========*/
254  const mtr_t* mtr)
255  __attribute__((nonnull, pure));
256 /***********************************************************************/
259 UNIV_INLINE
260 ibool
262 /*=============*/
263  ulint zip_size,
265  ulint page_no);
266 /***********************************************************************/
270 UNIV_INTERN
271 ibool
273 /*==========*/
274  ulint space,
275  ulint zip_size,
276  ulint page_no,
277 #ifdef UNIV_DEBUG
278  ibool x_latch,
280 #endif /* UNIV_DEBUG */
281  const char* file,
282  ulint line,
283  mtr_t* mtr)
288  __attribute__((warn_unused_result));
289 #ifdef UNIV_DEBUG
290 
297 # define ibuf_page(space, zip_size, page_no, mtr) \
298  ibuf_page_low(space, zip_size, page_no, TRUE, __FILE__, __LINE__, mtr)
299 #else /* UVIV_DEBUG */
300 
307 # define ibuf_page(space, zip_size, page_no, mtr) \
308  ibuf_page_low(space, zip_size, page_no, __FILE__, __LINE__, mtr)
309 #endif /* UVIV_DEBUG */
310 /***********************************************************************/
314 UNIV_INTERN
315 void
317 /*========================*/
318 /*********************************************************************/
323 UNIV_INTERN
324 ibool
326 /*========*/
327  ibuf_op_t op,
328  const dtuple_t* entry,
329  dict_index_t* index,
330  ulint space,
331  ulint zip_size,
332  ulint page_no,
333  que_thr_t* thr);
334 /*********************************************************************/
341 UNIV_INTERN
342 void
344 /*==========================*/
345  buf_block_t* block,
348  ulint space,
349  ulint page_no,
350  ulint zip_size,
352  ibool update_ibuf_bitmap);
357 /*********************************************************************/
362 UNIV_INTERN
363 void
365 /*============================*/
366  ulint space);
367 /*********************************************************************/
372 UNIV_INTERN
373 ulint
375 /*========================*/
376  table_id_t table_id,
379  ibool full);
384 #endif /* !UNIV_HOTBACKUP */
385 /*********************************************************************/
388 UNIV_INTERN
389 byte*
391 /*===================*/
392  byte* ptr,
393  byte* end_ptr,
394  buf_block_t* block,
395  mtr_t* mtr);
396 #ifndef UNIV_HOTBACKUP
397 #ifdef UNIV_IBUF_COUNT_DEBUG
398 /******************************************************************/
402 UNIV_INTERN
403 ulint
404 ibuf_count_get(
405 /*===========*/
406  ulint space,
407  ulint page_no);
408 #endif
409 /******************************************************************/
412 UNIV_INTERN
413 bool
414 ibuf_is_empty(void);
415 /*===============*/
416 /******************************************************************/
418 UNIV_INTERN
419 void
420 ibuf_print(
421 /*=======*/
422  FILE* file);
423 /********************************************************************
424 Read the first two bytes from a record's fourth field (counter field in new
425 records; something else in older records).
426 @return "counter" field, or ULINT_UNDEFINED if for some reason it can't be read */
427 UNIV_INTERN
428 ulint
430 /*=================*/
431  const rec_t* rec);
432 /******************************************************************/
434 UNIV_INTERN
435 void
436 ibuf_close(void);
437 /*============*/
438 
439 /******************************************************************/
442 UNIV_INTERN
443 dberr_t
445 /*========================*/
446  const trx_t* trx,
447  ulint space_id)
448  __attribute__((nonnull, warn_unused_result));
449 
450 #define IBUF_HEADER_PAGE_NO FSP_IBUF_HEADER_PAGE_NO
451 #define IBUF_TREE_ROOT_PAGE_NO FSP_IBUF_TREE_ROOT_PAGE_NO
452 
453 #endif /* !UNIV_HOTBACKUP */
454 
455 /* The ibuf header page currently contains only the file segment header
456 for the file segment from which the pages for the ibuf tree are allocated */
457 #define IBUF_HEADER PAGE_DATA
458 #define IBUF_TREE_SEG_HEADER 0 /* fseg header for ibuf tree */
459 
460 /* The insert buffer tree itself is always located in space 0. */
461 #define IBUF_SPACE_ID 0
462 
463 #ifndef UNIV_NONINL
464 #include "ibuf0ibuf.ic"
465 #endif
466 
467 #endif