You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

306 lines
11 KiB

20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
  1. /******************************************************
  2. Insert buffer
  3. (c) 1997 Innobase Oy
  4. Created 7/19/1997 Heikki Tuuri
  5. *******************************************************/
  6. #ifndef ibuf0ibuf_h
  7. #define ibuf0ibuf_h
  8. #include "univ.i"
  9. #include "dict0mem.h"
  10. #include "dict0dict.h"
  11. #include "mtr0mtr.h"
  12. #include "que0types.h"
  13. #include "ibuf0types.h"
  14. #include "fsp0fsp.h"
  15. extern ibuf_t* ibuf;
  16. /**********************************************************************
  17. Creates the insert buffer data struct for a single tablespace. Reads the
  18. root page of the insert buffer tree in the tablespace. This function can
  19. be called only after the dictionary system has been initialized, as this
  20. creates also the insert buffer table and index for this tablespace. */
  21. ibuf_data_t*
  22. ibuf_data_init_for_space(
  23. /*=====================*/
  24. /* out, own: ibuf data struct, linked to the list
  25. in ibuf control structure. */
  26. ulint space); /* in: space id */
  27. /**********************************************************************
  28. Creates the insert buffer data structure at a database startup and
  29. initializes the data structures for the insert buffer of each tablespace. */
  30. void
  31. ibuf_init_at_db_start(void);
  32. /*=======================*/
  33. /*************************************************************************
  34. Reads the biggest tablespace id from the high end of the insert buffer
  35. tree and updates the counter in fil_system. */
  36. void
  37. ibuf_update_max_tablespace_id(void);
  38. /*===============================*/
  39. /*************************************************************************
  40. Initializes an ibuf bitmap page. */
  41. void
  42. ibuf_bitmap_page_init(
  43. /*==================*/
  44. buf_block_t* block, /* in: bitmap page */
  45. mtr_t* mtr); /* in: mtr */
  46. /****************************************************************************
  47. Resets the free bits of the page in the ibuf bitmap. This is done in a
  48. separate mini-transaction, hence this operation does not restrict further
  49. work to only ibuf bitmap operations, which would result if the latch to the
  50. bitmap page were kept. */
  51. void
  52. ibuf_reset_free_bits_with_type(
  53. /*===========================*/
  54. ulint type, /* in: index type */
  55. buf_block_t* block); /* in: index page; free bits are set to 0
  56. if the index is a non-clustered
  57. non-unique, and page level is 0 */
  58. /****************************************************************************
  59. Updates the free bits of the page in the ibuf bitmap if there is not enough
  60. free on the page any more. This is done in a separate mini-transaction, hence
  61. this operation does not restrict further work to only ibuf bitmap operations,
  62. which would result if the latch to the bitmap page were kept. */
  63. UNIV_INLINE
  64. void
  65. ibuf_update_free_bits_if_full(
  66. /*==========================*/
  67. dict_index_t* index, /* in: index */
  68. buf_block_t* block, /* in: index page to which we have added new
  69. records; the free bits are updated if the
  70. index is non-clustered and non-unique and
  71. the page level is 0, and the page becomes
  72. fuller */
  73. ulint max_ins_size,/* in: value of maximum insert size with
  74. reorganize before the latest operation
  75. performed to the page */
  76. ulint increase);/* in: upper limit for the additional space
  77. used in the latest operation, if known, or
  78. ULINT_UNDEFINED */
  79. /**************************************************************************
  80. Updates the free bits for the page to reflect the present state. Does this
  81. in the mtr given, which means that the latching order rules virtually
  82. prevent any further operations for this OS thread until mtr is committed. */
  83. void
  84. ibuf_update_free_bits_low(
  85. /*======================*/
  86. dict_index_t* index, /* in: index */
  87. buf_block_t* block, /* in: index page */
  88. ulint max_ins_size, /* in: value of maximum insert size
  89. with reorganize before the latest
  90. operation performed to the page */
  91. mtr_t* mtr); /* in: mtr */
  92. /**************************************************************************
  93. Updates the free bits for the two pages to reflect the present state. Does
  94. this in the mtr given, which means that the latching order rules virtually
  95. prevent any further operations until mtr is committed. */
  96. void
  97. ibuf_update_free_bits_for_two_pages_low(
  98. /*====================================*/
  99. dict_index_t* index, /* in: index */
  100. buf_block_t* block1, /* in: index page */
  101. buf_block_t* block2, /* in: index page */
  102. mtr_t* mtr); /* in: mtr */
  103. /**************************************************************************
  104. A basic partial test if an insert to the insert buffer could be possible and
  105. recommended. */
  106. UNIV_INLINE
  107. ibool
  108. ibuf_should_try(
  109. /*============*/
  110. dict_index_t* index, /* in: index where to insert */
  111. ulint ignore_sec_unique); /* in: if != 0, we should
  112. ignore UNIQUE constraint on
  113. a secondary index when we
  114. decide */
  115. /**********************************************************************
  116. Returns TRUE if the current OS thread is performing an insert buffer
  117. routine. */
  118. ibool
  119. ibuf_inside(void);
  120. /*=============*/
  121. /* out: TRUE if inside an insert buffer routine: for instance,
  122. a read-ahead of non-ibuf pages is then forbidden */
  123. /***************************************************************************
  124. Checks if a page address is an ibuf bitmap page (level 3 page) address. */
  125. UNIV_INLINE
  126. ibool
  127. ibuf_bitmap_page(
  128. /*=============*/
  129. /* out: TRUE if a bitmap page */
  130. ulint zip_size,/* in: compressed page size in bytes;
  131. 0 for uncompressed pages */
  132. ulint page_no);/* in: page number */
  133. /***************************************************************************
  134. Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */
  135. ibool
  136. ibuf_page(
  137. /*======*/
  138. /* out: TRUE if level 2 or level 3 page */
  139. ulint space, /* in: space id */
  140. ulint zip_size,/* in: compressed page size in bytes, or 0 */
  141. ulint page_no);/* in: page number */
  142. /***************************************************************************
  143. Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */
  144. ibool
  145. ibuf_page_low(
  146. /*==========*/
  147. /* out: TRUE if level 2 or level 3 page */
  148. ulint space, /* in: space id */
  149. ulint zip_size,/* in: compressed page size in bytes, or 0 */
  150. ulint page_no,/* in: page number */
  151. mtr_t* mtr); /* in: mtr which will contain an x-latch to the
  152. bitmap page if the page is not one of the fixed
  153. address ibuf pages */
  154. /***************************************************************************
  155. Frees excess pages from the ibuf free list. This function is called when an OS
  156. thread calls fsp services to allocate a new file segment, or a new page to a
  157. file segment, and the thread did not own the fsp latch before this call. */
  158. void
  159. ibuf_free_excess_pages(
  160. /*===================*/
  161. ulint space, /* in: space id */
  162. ulint zip_size); /* in: compressed page size in bytes, or 0 */
  163. /*************************************************************************
  164. Makes an index insert to the insert buffer, instead of directly to the disk
  165. page, if this is possible. Does not do insert if the index is clustered
  166. or unique. */
  167. ibool
  168. ibuf_insert(
  169. /*========*/
  170. /* out: TRUE if success */
  171. const dtuple_t* entry, /* in: index entry to insert */
  172. dict_index_t* index, /* in: index where to insert */
  173. ulint space, /* in: space id where to insert */
  174. ulint zip_size,/* in: compressed page size in bytes, or 0 */
  175. ulint page_no,/* in: page number where to insert */
  176. que_thr_t* thr); /* in: query thread */
  177. /*************************************************************************
  178. When an index page is read from a disk to the buffer pool, this function
  179. inserts to the page the possible index entries buffered in the insert buffer.
  180. The entries are deleted from the insert buffer. If the page is not read, but
  181. created in the buffer pool, this function deletes its buffered entries from
  182. the insert buffer; there can exist entries for such a page if the page
  183. belonged to an index which subsequently was dropped. */
  184. void
  185. ibuf_merge_or_delete_for_page(
  186. /*==========================*/
  187. buf_block_t* block, /* in: if page has been read from
  188. disk, pointer to the page x-latched,
  189. else NULL */
  190. ulint space, /* in: space id of the index page */
  191. ulint page_no,/* in: page number of the index page */
  192. ulint zip_size,/* in: compressed page size in bytes,
  193. or 0 */
  194. ibool update_ibuf_bitmap);/* in: normally this is set
  195. to TRUE, but if we have deleted or are
  196. deleting the tablespace, then we
  197. naturally do not want to update a
  198. non-existent bitmap page */
  199. /*************************************************************************
  200. Deletes all entries in the insert buffer for a given space id. This is used
  201. in DISCARD TABLESPACE and IMPORT TABLESPACE.
  202. NOTE: this does not update the page free bitmaps in the space. The space will
  203. become CORRUPT when you call this function! */
  204. void
  205. ibuf_delete_for_discarded_space(
  206. /*============================*/
  207. ulint space); /* in: space id */
  208. /*************************************************************************
  209. Contracts insert buffer trees by reading pages to the buffer pool. */
  210. ulint
  211. ibuf_contract(
  212. /*==========*/
  213. /* out: a lower limit for the combined size in bytes
  214. of entries which will be merged from ibuf trees to the
  215. pages read, 0 if ibuf is empty */
  216. ibool sync); /* in: TRUE if the caller wants to wait for the
  217. issued read with the highest tablespace address
  218. to complete */
  219. /*************************************************************************
  220. Contracts insert buffer trees by reading pages to the buffer pool. */
  221. ulint
  222. ibuf_contract_for_n_pages(
  223. /*======================*/
  224. /* out: a lower limit for the combined size in bytes
  225. of entries which will be merged from ibuf trees to the
  226. pages read, 0 if ibuf is empty */
  227. ibool sync, /* in: TRUE if the caller wants to wait for the
  228. issued read with the highest tablespace address
  229. to complete */
  230. ulint n_pages);/* in: try to read at least this many pages to
  231. the buffer pool and merge the ibuf contents to
  232. them */
  233. /*************************************************************************
  234. Parses a redo log record of an ibuf bitmap page init. */
  235. byte*
  236. ibuf_parse_bitmap_init(
  237. /*===================*/
  238. /* out: end of log record or NULL */
  239. byte* ptr, /* in: buffer */
  240. byte* end_ptr,/* in: buffer end */
  241. buf_block_t* block, /* in: block or NULL */
  242. mtr_t* mtr); /* in: mtr or NULL */
  243. #ifdef UNIV_IBUF_DEBUG
  244. /**********************************************************************
  245. Gets the ibuf count for a given page. */
  246. ulint
  247. ibuf_count_get(
  248. /*===========*/
  249. /* out: number of entries in the insert buffer
  250. currently buffered for this page */
  251. ulint space, /* in: space id */
  252. ulint page_no);/* in: page number */
  253. #endif
  254. /**********************************************************************
  255. Looks if the insert buffer is empty. */
  256. ibool
  257. ibuf_is_empty(void);
  258. /*===============*/
  259. /* out: TRUE if empty */
  260. /**********************************************************************
  261. Prints info of ibuf. */
  262. void
  263. ibuf_print(
  264. /*=======*/
  265. FILE* file); /* in: file where to print */
  266. #define IBUF_HEADER_PAGE_NO FSP_IBUF_HEADER_PAGE_NO
  267. #define IBUF_TREE_ROOT_PAGE_NO FSP_IBUF_TREE_ROOT_PAGE_NO
  268. /* The ibuf header page currently contains only the file segment header
  269. for the file segment from which the pages for the ibuf tree are allocated */
  270. #define IBUF_HEADER PAGE_DATA
  271. #define IBUF_TREE_SEG_HEADER 0 /* fseg header for ibuf tree */
  272. #ifndef UNIV_NONINL
  273. #include "ibuf0ibuf.ic"
  274. #endif
  275. #endif