Drizzled Public API Documentation

ibuf0ibuf.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003 Copyright (C) 1997, 2009, Innobase Oy. All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify it under
00006 the terms of the GNU General Public License as published by the Free Software
00007 Foundation; version 2 of the License.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with
00014 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
00015 St, Fifth Floor, Boston, MA 02110-1301 USA
00016 
00017 *****************************************************************************/
00018 
00019 /**************************************************/
00026 #pragma once
00027 #ifndef ibuf0ibuf_h
00028 #define ibuf0ibuf_h
00029 
00030 #include "univ.i"
00031 
00032 #include "mtr0mtr.h"
00033 #include "dict0mem.h"
00034 #include "fsp0fsp.h"
00035 
00036 #ifndef UNIV_HOTBACKUP
00037 # include "ibuf0types.h"
00038 
00039 /* Possible operations buffered in the insert/whatever buffer. See
00040 ibuf_insert(). DO NOT CHANGE THE VALUES OF THESE, THEY ARE STORED ON DISK. */
00041 typedef enum {
00042   IBUF_OP_INSERT = 0,
00043   IBUF_OP_DELETE_MARK = 1,
00044   IBUF_OP_DELETE = 2,
00045 
00046   /* Number of different operation types. */
00047   IBUF_OP_COUNT = 3
00048 } ibuf_op_t;
00049 
00053 typedef enum {
00054   IBUF_USE_NONE = 0,
00055   IBUF_USE_INSERT,  /* insert */
00056   IBUF_USE_DELETE_MARK, /* delete */
00057   IBUF_USE_INSERT_DELETE_MARK,  /* insert+delete */
00058   IBUF_USE_DELETE,  /* delete+purge */
00059   IBUF_USE_ALL,   /* insert+delete+purge */
00060 
00061   IBUF_USE_COUNT    /* number of entries in ibuf_use_t */
00062 } ibuf_use_t;
00063 
00065 extern ibuf_use_t ibuf_use;
00066 
00067 #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
00068 
00069 extern uint   ibuf_debug;
00070 #endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
00071 
00073 extern ibuf_t*    ibuf;
00074 
00075 /* The purpose of the insert buffer is to reduce random disk access.
00076 When we wish to insert a record into a non-unique secondary index and
00077 the B-tree leaf page where the record belongs to is not in the buffer
00078 pool, we insert the record into the insert buffer B-tree, indexed by
00079 (space_id, page_no).  When the page is eventually read into the buffer
00080 pool, we look up the insert buffer B-tree for any modifications to the
00081 page, and apply these upon the completion of the read operation.  This
00082 is called the insert buffer merge. */
00083 
00084 /* The insert buffer merge must always succeed.  To guarantee this,
00085 the insert buffer subsystem keeps track of the free space in pages for
00086 which it can buffer operations.  Two bits per page in the insert
00087 buffer bitmap indicate the available space in coarse increments.  The
00088 free bits in the insert buffer bitmap must never exceed the free space
00089 on a page.  It is safe to decrement or reset the bits in the bitmap in
00090 a mini-transaction that is committed before the mini-transaction that
00091 affects the free space.  It is unsafe to increment the bits in a
00092 separately committed mini-transaction, because in crash recovery, the
00093 free bits could momentarily be set too high. */
00094 
00095 /******************************************************************/
00097 UNIV_INTERN
00098 void
00099 ibuf_init_at_db_start(void);
00100 /*=======================*/
00101 /*********************************************************************/
00104 UNIV_INTERN
00105 void
00106 ibuf_update_max_tablespace_id(void);
00107 /*===============================*/
00108 /*********************************************************************/
00110 UNIV_INTERN
00111 void
00112 ibuf_bitmap_page_init(
00113 /*==================*/
00114   buf_block_t*  block,  
00115   mtr_t*    mtr); 
00116 /************************************************************************/
00125 UNIV_INTERN
00126 void
00127 ibuf_reset_free_bits(
00128 /*=================*/
00129   buf_block_t*  block); 
00132 /************************************************************************/
00145 UNIV_INLINE
00146 void
00147 ibuf_update_free_bits_if_full(
00148 /*==========================*/
00149   buf_block_t*  block,  
00154   ulint   max_ins_size,
00157   ulint   increase);
00160 /**********************************************************************/
00168 UNIV_INTERN
00169 void
00170 ibuf_update_free_bits_low(
00171 /*======================*/
00172   const buf_block_t*  block,    
00173   ulint     max_ins_size, 
00178   mtr_t*      mtr);   
00179 /**********************************************************************/
00187 UNIV_INTERN
00188 void
00189 ibuf_update_free_bits_zip(
00190 /*======================*/
00191   buf_block_t*  block,  
00192   mtr_t*    mtr); 
00193 /**********************************************************************/
00200 UNIV_INTERN
00201 void
00202 ibuf_update_free_bits_for_two_pages_low(
00203 /*====================================*/
00204   ulint   zip_size,
00206   buf_block_t*  block1, 
00207   buf_block_t*  block2, 
00208   mtr_t*    mtr); 
00209 /**********************************************************************/
00212 UNIV_INLINE
00213 ibool
00214 ibuf_should_try(
00215 /*============*/
00216   dict_index_t* index,      
00217   ulint   ignore_sec_unique); 
00221 /******************************************************************/
00228 UNIV_INTERN
00229 ibool
00230 ibuf_inside(void);
00231 /*=============*/
00232 /***********************************************************************/
00235 UNIV_INLINE
00236 ibool
00237 ibuf_bitmap_page(
00238 /*=============*/
00239   ulint zip_size,
00241   ulint page_no);
00242 /***********************************************************************/
00246 UNIV_INTERN
00247 ibool
00248 ibuf_page(
00249 /*======*/
00250   ulint space,  
00251   ulint zip_size,
00252   ulint page_no,
00253   mtr_t*  mtr); 
00257 /***********************************************************************/
00261 UNIV_INTERN
00262 void
00263 ibuf_free_excess_pages(void);
00264 /*========================*/
00265 /*********************************************************************/
00270 UNIV_INTERN
00271 ibool
00272 ibuf_insert(
00273 /*========*/
00274   ibuf_op_t op, 
00275   const dtuple_t* entry,  
00276   dict_index_t* index,  
00277   ulint   space,  
00278   ulint   zip_size,
00279   ulint   page_no,
00280   que_thr_t*  thr); 
00281 /*********************************************************************/
00288 UNIV_INTERN
00289 void
00290 ibuf_merge_or_delete_for_page(
00291 /*==========================*/
00292   buf_block_t*  block,  
00295   ulint   space,  
00296   ulint   page_no,
00297   ulint   zip_size,
00299   ibool   update_ibuf_bitmap);
00304 /*********************************************************************/
00309 UNIV_INTERN
00310 void
00311 ibuf_delete_for_discarded_space(
00312 /*============================*/
00313   ulint space); 
00314 /*********************************************************************/
00319 UNIV_INTERN
00320 ulint
00321 ibuf_contract(
00322 /*==========*/
00323   ibool sync);  
00326 /*********************************************************************/
00331 UNIV_INTERN
00332 ulint
00333 ibuf_contract_for_n_pages(
00334 /*======================*/
00335   ibool sync, 
00338   ulint n_pages);
00341 #endif /* !UNIV_HOTBACKUP */
00342 /*********************************************************************/
00345 UNIV_INTERN
00346 byte*
00347 ibuf_parse_bitmap_init(
00348 /*===================*/
00349   byte*   ptr,  
00350   byte*   end_ptr,
00351   buf_block_t*  block,  
00352   mtr_t*    mtr); 
00353 #ifndef UNIV_HOTBACKUP
00354 #ifdef UNIV_IBUF_COUNT_DEBUG
00355 /******************************************************************/
00359 UNIV_INTERN
00360 ulint
00361 ibuf_count_get(
00362 /*===========*/
00363   ulint space,  
00364   ulint page_no);
00365 #endif
00366 /******************************************************************/
00369 UNIV_INTERN
00370 ibool
00371 ibuf_is_empty(void);
00372 /*===============*/
00373 /******************************************************************/
00375 UNIV_INTERN
00376 void
00377 ibuf_print(
00378 /*=======*/
00379   FILE* file);  
00380 /********************************************************************
00381 Read the first two bytes from a record's fourth field (counter field in new
00382 records; something else in older records).
00383 @return "counter" field, or ULINT_UNDEFINED if for some reason it can't be read */
00384 UNIV_INTERN
00385 ulint
00386 ibuf_rec_get_counter(
00387 /*=================*/
00388   const rec_t*  rec); 
00389 /******************************************************************/
00391 UNIV_INTERN
00392 void
00393 ibuf_close(void);
00394 /*============*/
00395 
00396 #define IBUF_HEADER_PAGE_NO FSP_IBUF_HEADER_PAGE_NO
00397 #define IBUF_TREE_ROOT_PAGE_NO  FSP_IBUF_TREE_ROOT_PAGE_NO
00398 
00399 #endif /* !UNIV_HOTBACKUP */
00400 
00401 /* The ibuf header page currently contains only the file segment header
00402 for the file segment from which the pages for the ibuf tree are allocated */
00403 #define IBUF_HEADER   PAGE_DATA
00404 #define IBUF_TREE_SEG_HEADER  0 /* fseg header for ibuf tree */
00405 
00406 /* The insert buffer tree itself is always located in space 0. */
00407 #define IBUF_SPACE_ID   0
00408 
00409 #ifndef UNIV_NONINL
00410 #include "ibuf0ibuf.ic"
00411 #endif
00412 
00413 #endif