00001 /****************************************************** 00002 Insert buffer 00003 00004 (c) 1997 Innobase Oy 00005 00006 Created 7/19/1997 Heikki Tuuri 00007 *******************************************************/ 00008 00009 #ifndef ibuf0ibuf_h 00010 #define ibuf0ibuf_h 00011 00012 #include "univ.i" 00013 00014 #include "dict0mem.h" 00015 #include "dict0dict.h" 00016 #include "mtr0mtr.h" 00017 #include "que0types.h" 00018 #include "ibuf0types.h" 00019 #include "fsp0fsp.h" 00020 00021 extern ibuf_t* ibuf; 00022 00023 /********************************************************************** 00024 Creates the insert buffer data struct for a single tablespace. Reads the 00025 root page of the insert buffer tree in the tablespace. This function can 00026 be called only after the dictionary system has been initialized, as this 00027 creates also the insert buffer table and index for this tablespace. */ 00028 00029 ibuf_data_t* 00030 ibuf_data_init_for_space( 00031 /*=====================*/ 00032 /* out, own: ibuf data struct, linked to the list 00033 in ibuf control structure. */ 00034 ulint space); /* in: space id */ 00035 /********************************************************************** 00036 Creates the insert buffer data structure at a database startup and 00037 initializes the data structures for the insert buffer of each tablespace. */ 00038 00039 void 00040 ibuf_init_at_db_start(void); 00041 /*=======================*/ 00042 /************************************************************************* 00043 Reads the biggest tablespace id from the high end of the insert buffer 00044 tree and updates the counter in fil_system. */ 00045 00046 void 00047 ibuf_update_max_tablespace_id(void); 00048 /*===============================*/ 00049 /************************************************************************* 00050 Initializes an ibuf bitmap page. */ 00051 00052 void 00053 ibuf_bitmap_page_init( 00054 /*==================*/ 00055 page_t* page, /* in: bitmap page */ 00056 mtr_t* mtr); /* in: mtr */ 00057 /**************************************************************************** 00058 Resets the free bits of the page in the ibuf bitmap. This is done in a 00059 separate mini-transaction, hence this operation does not restrict further 00060 work to only ibuf bitmap operations, which would result if the latch to the 00061 bitmap page were kept. */ 00062 00063 void 00064 ibuf_reset_free_bits_with_type( 00065 /*===========================*/ 00066 ulint type, /* in: index type */ 00067 page_t* page); /* in: index page; free bits are set to 0 if the index 00068 is non-clustered and non-unique and the page level is 00069 0 */ 00070 /**************************************************************************** 00071 Resets the free bits of the page in the ibuf bitmap. This is done in a 00072 separate mini-transaction, hence this operation does not restrict further 00073 work to solely ibuf bitmap operations, which would result if the latch to 00074 the bitmap page were kept. */ 00075 00076 void 00077 ibuf_reset_free_bits( 00078 /*=================*/ 00079 dict_index_t* index, /* in: index */ 00080 page_t* page); /* in: index page; free bits are set to 0 if 00081 the index is non-clustered and non-unique and 00082 the page level is 0 */ 00083 /**************************************************************************** 00084 Updates the free bits of the page in the ibuf bitmap if there is not enough 00085 free on the page any more. This is done in a separate mini-transaction, hence 00086 this operation does not restrict further work to only ibuf bitmap operations, 00087 which would result if the latch to the bitmap page were kept. */ 00088 UNIV_INLINE 00089 void 00090 ibuf_update_free_bits_if_full( 00091 /*==========================*/ 00092 dict_index_t* index, /* in: index */ 00093 page_t* page, /* in: index page to which we have added new 00094 records; the free bits are updated if the 00095 index is non-clustered and non-unique and 00096 the page level is 0, and the page becomes 00097 fuller */ 00098 ulint max_ins_size,/* in: value of maximum insert size with 00099 reorganize before the latest operation 00100 performed to the page */ 00101 ulint increase);/* in: upper limit for the additional space 00102 used in the latest operation, if known, or 00103 ULINT_UNDEFINED */ 00104 /************************************************************************** 00105 Updates the free bits for the page to reflect the present state. Does this 00106 in the mtr given, which means that the latching order rules virtually 00107 prevent any further operations for this OS thread until mtr is committed. */ 00108 00109 void 00110 ibuf_update_free_bits_low( 00111 /*======================*/ 00112 dict_index_t* index, /* in: index */ 00113 page_t* page, /* in: index page */ 00114 ulint max_ins_size, /* in: value of maximum insert size 00115 with reorganize before the latest 00116 operation performed to the page */ 00117 mtr_t* mtr); /* in: mtr */ 00118 /************************************************************************** 00119 Updates the free bits for the two pages to reflect the present state. Does 00120 this in the mtr given, which means that the latching order rules virtually 00121 prevent any further operations until mtr is committed. */ 00122 00123 void 00124 ibuf_update_free_bits_for_two_pages_low( 00125 /*====================================*/ 00126 dict_index_t* index, /* in: index */ 00127 page_t* page1, /* in: index page */ 00128 page_t* page2, /* in: index page */ 00129 mtr_t* mtr); /* in: mtr */ 00130 /************************************************************************** 00131 A basic partial test if an insert to the insert buffer could be possible and 00132 recommended. */ 00133 UNIV_INLINE 00134 ibool 00135 ibuf_should_try( 00136 /*============*/ 00137 dict_index_t* index, /* in: index where to insert */ 00138 ulint ignore_sec_unique); /* in: if != 0, we should 00139 ignore UNIQUE constraint on 00140 a secondary index when we 00141 decide */ 00142 /********************************************************************** 00143 Returns TRUE if the current OS thread is performing an insert buffer 00144 routine. */ 00145 00146 ibool 00147 ibuf_inside(void); 00148 /*=============*/ 00149 /* out: TRUE if inside an insert buffer routine: for instance, 00150 a read-ahead of non-ibuf pages is then forbidden */ 00151 /*************************************************************************** 00152 Checks if a page address is an ibuf bitmap page (level 3 page) address. */ 00153 UNIV_INLINE 00154 ibool 00155 ibuf_bitmap_page( 00156 /*=============*/ 00157 /* out: TRUE if a bitmap page */ 00158 ulint page_no);/* in: page number */ 00159 /*************************************************************************** 00160 Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */ 00161 00162 ibool 00163 ibuf_page( 00164 /*======*/ 00165 /* out: TRUE if level 2 or level 3 page */ 00166 ulint space, /* in: space id */ 00167 ulint page_no);/* in: page number */ 00168 /*************************************************************************** 00169 Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */ 00170 00171 ibool 00172 ibuf_page_low( 00173 /*==========*/ 00174 /* out: TRUE if level 2 or level 3 page */ 00175 ulint space, /* in: space id */ 00176 ulint page_no,/* in: page number */ 00177 mtr_t* mtr); /* in: mtr which will contain an x-latch to the 00178 bitmap page if the page is not one of the fixed 00179 address ibuf pages */ 00180 /*************************************************************************** 00181 Frees excess pages from the ibuf free list. This function is called when an OS 00182 thread calls fsp services to allocate a new file segment, or a new page to a 00183 file segment, and the thread did not own the fsp latch before this call. */ 00184 00185 void 00186 ibuf_free_excess_pages( 00187 /*===================*/ 00188 ulint space); /* in: space id */ 00189 /************************************************************************* 00190 Makes an index insert to the insert buffer, instead of directly to the disk 00191 page, if this is possible. Does not do insert if the index is clustered 00192 or unique. */ 00193 00194 ibool 00195 ibuf_insert( 00196 /*========*/ 00197 /* out: TRUE if success */ 00198 dtuple_t* entry, /* in: index entry to insert */ 00199 dict_index_t* index, /* in: index where to insert */ 00200 ulint space, /* in: space id where to insert */ 00201 ulint page_no,/* in: page number where to insert */ 00202 que_thr_t* thr); /* in: query thread */ 00203 /************************************************************************* 00204 When an index page is read from a disk to the buffer pool, this function 00205 inserts to the page the possible index entries buffered in the insert buffer. 00206 The entries are deleted from the insert buffer. If the page is not read, but 00207 created in the buffer pool, this function deletes its buffered entries from 00208 the insert buffer; there can exist entries for such a page if the page 00209 belonged to an index which subsequently was dropped. */ 00210 00211 void 00212 ibuf_merge_or_delete_for_page( 00213 /*==========================*/ 00214 page_t* page, /* in: if page has been read from disk, pointer to 00215 the page x-latched, else NULL */ 00216 ulint space, /* in: space id of the index page */ 00217 ulint page_no,/* in: page number of the index page */ 00218 ibool update_ibuf_bitmap);/* in: normally this is set to TRUE, but if 00219 we have deleted or are deleting the tablespace, then we 00220 naturally do not want to update a non-existent bitmap 00221 page */ 00222 /************************************************************************* 00223 Deletes all entries in the insert buffer for a given space id. This is used 00224 in DISCARD TABLESPACE and IMPORT TABLESPACE. 00225 NOTE: this does not update the page free bitmaps in the space. The space will 00226 become CORRUPT when you call this function! */ 00227 00228 void 00229 ibuf_delete_for_discarded_space( 00230 /*============================*/ 00231 ulint space); /* in: space id */ 00232 /************************************************************************* 00233 Contracts insert buffer trees by reading pages to the buffer pool. */ 00234 00235 ulint 00236 ibuf_contract( 00237 /*==========*/ 00238 /* out: a lower limit for the combined size in bytes 00239 of entries which will be merged from ibuf trees to the 00240 pages read, 0 if ibuf is empty */ 00241 ibool sync); /* in: TRUE if the caller wants to wait for the 00242 issued read with the highest tablespace address 00243 to complete */ 00244 /************************************************************************* 00245 Contracts insert buffer trees by reading pages to the buffer pool. */ 00246 00247 ulint 00248 ibuf_contract_for_n_pages( 00249 /*======================*/ 00250 /* out: a lower limit for the combined size in bytes 00251 of entries which will be merged from ibuf trees to the 00252 pages read, 0 if ibuf is empty */ 00253 ibool sync, /* in: TRUE if the caller wants to wait for the 00254 issued read with the highest tablespace address 00255 to complete */ 00256 ulint n_pages);/* in: try to read at least this many pages to 00257 the buffer pool and merge the ibuf contents to 00258 them */ 00259 /************************************************************************* 00260 Parses a redo log record of an ibuf bitmap page init. */ 00261 00262 byte* 00263 ibuf_parse_bitmap_init( 00264 /*===================*/ 00265 /* out: end of log record or NULL */ 00266 byte* ptr, /* in: buffer */ 00267 byte* end_ptr,/* in: buffer end */ 00268 page_t* page, /* in: page or NULL */ 00269 mtr_t* mtr); /* in: mtr or NULL */ 00270 #ifdef UNIV_IBUF_DEBUG 00271 /********************************************************************** 00272 Gets the ibuf count for a given page. */ 00273 00274 ulint 00275 ibuf_count_get( 00276 /*===========*/ 00277 /* out: number of entries in the insert buffer 00278 currently buffered for this page */ 00279 ulint space, /* in: space id */ 00280 ulint page_no);/* in: page number */ 00281 #endif 00282 /********************************************************************** 00283 Looks if the insert buffer is empty. */ 00284 00285 ibool 00286 ibuf_is_empty(void); 00287 /*===============*/ 00288 /* out: TRUE if empty */ 00289 /********************************************************************** 00290 Prints info of ibuf. */ 00291 00292 void 00293 ibuf_print( 00294 /*=======*/ 00295 FILE* file); /* in: file where to print */ 00296 00297 #define IBUF_HEADER_PAGE_NO FSP_IBUF_HEADER_PAGE_NO 00298 #define IBUF_TREE_ROOT_PAGE_NO FSP_IBUF_TREE_ROOT_PAGE_NO 00299 00300 /* The ibuf header page currently contains only the file segment header 00301 for the file segment from which the pages for the ibuf tree are allocated */ 00302 #define IBUF_HEADER PAGE_DATA 00303 #define IBUF_TREE_SEG_HEADER 0 /* fseg header for ibuf tree */ 00304 00305 #ifndef UNIV_NONINL 00306 #include "ibuf0ibuf.ic" 00307 #endif 00308 00309 #endif
1.4.7

