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.

250 lines
8.9 KiB

  1. /*****************************************************************************
  2. Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  11. Place, Suite 330, Boston, MA 02111-1307 USA
  12. *****************************************************************************/
  13. /**************************************************//**
  14. @file include/mtr0log.h
  15. Mini-transaction logging routines
  16. Created 12/7/1995 Heikki Tuuri
  17. *******************************************************/
  18. #ifndef mtr0log_h
  19. #define mtr0log_h
  20. #include "univ.i"
  21. #include "mtr0mtr.h"
  22. #include "dict0types.h"
  23. #ifndef UNIV_HOTBACKUP
  24. /********************************************************//**
  25. Writes 1 - 4 bytes to a file page buffered in the buffer pool.
  26. Writes the corresponding log record to the mini-transaction log. */
  27. UNIV_INTERN
  28. void
  29. mlog_write_ulint(
  30. /*=============*/
  31. byte* ptr, /*!< in: pointer where to write */
  32. ulint val, /*!< in: value to write */
  33. byte type, /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
  34. mtr_t* mtr); /*!< in: mini-transaction handle */
  35. /********************************************************//**
  36. Writes 8 bytes to a file page buffered in the buffer pool.
  37. Writes the corresponding log record to the mini-transaction log. */
  38. UNIV_INTERN
  39. void
  40. mlog_write_dulint(
  41. /*==============*/
  42. byte* ptr, /*!< in: pointer where to write */
  43. dulint val, /*!< in: value to write */
  44. mtr_t* mtr); /*!< in: mini-transaction handle */
  45. /********************************************************//**
  46. Writes a string to a file page buffered in the buffer pool. Writes the
  47. corresponding log record to the mini-transaction log. */
  48. UNIV_INTERN
  49. void
  50. mlog_write_string(
  51. /*==============*/
  52. byte* ptr, /*!< in: pointer where to write */
  53. const byte* str, /*!< in: string to write */
  54. ulint len, /*!< in: string length */
  55. mtr_t* mtr); /*!< in: mini-transaction handle */
  56. /********************************************************//**
  57. Logs a write of a string to a file page buffered in the buffer pool.
  58. Writes the corresponding log record to the mini-transaction log. */
  59. UNIV_INTERN
  60. void
  61. mlog_log_string(
  62. /*============*/
  63. byte* ptr, /*!< in: pointer written to */
  64. ulint len, /*!< in: string length */
  65. mtr_t* mtr); /*!< in: mini-transaction handle */
  66. /********************************************************//**
  67. Writes initial part of a log record consisting of one-byte item
  68. type and four-byte space and page numbers. */
  69. UNIV_INTERN
  70. void
  71. mlog_write_initial_log_record(
  72. /*==========================*/
  73. const byte* ptr, /*!< in: pointer to (inside) a buffer
  74. frame holding the file page where
  75. modification is made */
  76. byte type, /*!< in: log item type: MLOG_1BYTE, ... */
  77. mtr_t* mtr); /*!< in: mini-transaction handle */
  78. /********************************************************//**
  79. Writes a log record about an .ibd file create/delete/rename.
  80. @return new value of log_ptr */
  81. UNIV_INLINE
  82. byte*
  83. mlog_write_initial_log_record_for_file_op(
  84. /*======================================*/
  85. ulint type, /*!< in: MLOG_FILE_CREATE, MLOG_FILE_DELETE, or
  86. MLOG_FILE_RENAME */
  87. ulint space_id,/*!< in: space id, if applicable */
  88. ulint page_no,/*!< in: page number (not relevant currently) */
  89. byte* log_ptr,/*!< in: pointer to mtr log which has been opened */
  90. mtr_t* mtr); /*!< in: mtr */
  91. /********************************************************//**
  92. Catenates 1 - 4 bytes to the mtr log. */
  93. UNIV_INLINE
  94. void
  95. mlog_catenate_ulint(
  96. /*================*/
  97. mtr_t* mtr, /*!< in: mtr */
  98. ulint val, /*!< in: value to write */
  99. ulint type); /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
  100. /********************************************************//**
  101. Catenates n bytes to the mtr log. */
  102. UNIV_INTERN
  103. void
  104. mlog_catenate_string(
  105. /*=================*/
  106. mtr_t* mtr, /*!< in: mtr */
  107. const byte* str, /*!< in: string to write */
  108. ulint len); /*!< in: string length */
  109. /********************************************************//**
  110. Catenates a compressed ulint to mlog. */
  111. UNIV_INLINE
  112. void
  113. mlog_catenate_ulint_compressed(
  114. /*===========================*/
  115. mtr_t* mtr, /*!< in: mtr */
  116. ulint val); /*!< in: value to write */
  117. /********************************************************//**
  118. Catenates a compressed dulint to mlog. */
  119. UNIV_INLINE
  120. void
  121. mlog_catenate_dulint_compressed(
  122. /*============================*/
  123. mtr_t* mtr, /*!< in: mtr */
  124. dulint val); /*!< in: value to write */
  125. /********************************************************//**
  126. Opens a buffer to mlog. It must be closed with mlog_close.
  127. @return buffer, NULL if log mode MTR_LOG_NONE */
  128. UNIV_INLINE
  129. byte*
  130. mlog_open(
  131. /*======*/
  132. mtr_t* mtr, /*!< in: mtr */
  133. ulint size); /*!< in: buffer size in bytes; MUST be
  134. smaller than DYN_ARRAY_DATA_SIZE! */
  135. /********************************************************//**
  136. Closes a buffer opened to mlog. */
  137. UNIV_INLINE
  138. void
  139. mlog_close(
  140. /*=======*/
  141. mtr_t* mtr, /*!< in: mtr */
  142. byte* ptr); /*!< in: buffer space from ptr up was not used */
  143. /********************************************************//**
  144. Writes the initial part of a log record (3..11 bytes).
  145. If the implementation of this function is changed, all
  146. size parameters to mlog_open() should be adjusted accordingly!
  147. @return new value of log_ptr */
  148. UNIV_INLINE
  149. byte*
  150. mlog_write_initial_log_record_fast(
  151. /*===============================*/
  152. const byte* ptr, /*!< in: pointer to (inside) a buffer
  153. frame holding the file page where
  154. modification is made */
  155. byte type, /*!< in: log item type: MLOG_1BYTE, ... */
  156. byte* log_ptr,/*!< in: pointer to mtr log which has
  157. been opened */
  158. mtr_t* mtr); /*!< in: mtr */
  159. #else /* !UNIV_HOTBACKUP */
  160. # define mlog_write_initial_log_record(ptr,type,mtr) ((void) 0)
  161. # define mlog_write_initial_log_record_fast(ptr,type,log_ptr,mtr) ((byte *) 0)
  162. #endif /* !UNIV_HOTBACKUP */
  163. /********************************************************//**
  164. Parses an initial log record written by mlog_write_initial_log_record.
  165. @return parsed record end, NULL if not a complete record */
  166. UNIV_INTERN
  167. byte*
  168. mlog_parse_initial_log_record(
  169. /*==========================*/
  170. byte* ptr, /*!< in: buffer */
  171. byte* end_ptr,/*!< in: buffer end */
  172. byte* type, /*!< out: log record type: MLOG_1BYTE, ... */
  173. ulint* space, /*!< out: space id */
  174. ulint* page_no);/*!< out: page number */
  175. /********************************************************//**
  176. Parses a log record written by mlog_write_ulint or mlog_write_dulint.
  177. @return parsed record end, NULL if not a complete record */
  178. UNIV_INTERN
  179. byte*
  180. mlog_parse_nbytes(
  181. /*==============*/
  182. ulint type, /*!< in: log record type: MLOG_1BYTE, ... */
  183. byte* ptr, /*!< in: buffer */
  184. byte* end_ptr,/*!< in: buffer end */
  185. byte* page, /*!< in: page where to apply the log record, or NULL */
  186. void* page_zip);/*!< in/out: compressed page, or NULL */
  187. /********************************************************//**
  188. Parses a log record written by mlog_write_string.
  189. @return parsed record end, NULL if not a complete record */
  190. UNIV_INTERN
  191. byte*
  192. mlog_parse_string(
  193. /*==============*/
  194. byte* ptr, /*!< in: buffer */
  195. byte* end_ptr,/*!< in: buffer end */
  196. byte* page, /*!< in: page where to apply the log record, or NULL */
  197. void* page_zip);/*!< in/out: compressed page, or NULL */
  198. #ifndef UNIV_HOTBACKUP
  199. /********************************************************//**
  200. Opens a buffer for mlog, writes the initial log record and,
  201. if needed, the field lengths of an index. Reserves space
  202. for further log entries. The log entry must be closed with
  203. mtr_close().
  204. @return buffer, NULL if log mode MTR_LOG_NONE */
  205. UNIV_INTERN
  206. byte*
  207. mlog_open_and_write_index(
  208. /*======================*/
  209. mtr_t* mtr, /*!< in: mtr */
  210. const byte* rec, /*!< in: index record or page */
  211. dict_index_t* index, /*!< in: record descriptor */
  212. byte type, /*!< in: log item type */
  213. ulint size); /*!< in: requested buffer size in bytes
  214. (if 0, calls mlog_close() and returns NULL) */
  215. #endif /* !UNIV_HOTBACKUP */
  216. /********************************************************//**
  217. Parses a log record written by mlog_open_and_write_index.
  218. @return parsed record end, NULL if not a complete record */
  219. UNIV_INTERN
  220. byte*
  221. mlog_parse_index(
  222. /*=============*/
  223. byte* ptr, /*!< in: buffer */
  224. const byte* end_ptr,/*!< in: buffer end */
  225. ibool comp, /*!< in: TRUE=compact record format */
  226. dict_index_t** index); /*!< out, own: dummy index */
  227. #ifndef UNIV_HOTBACKUP
  228. /* Insert, update, and maybe other functions may use this value to define an
  229. extra mlog buffer size for variable size data */
  230. #define MLOG_BUF_MARGIN 256
  231. #endif /* !UNIV_HOTBACKUP */
  232. #ifndef UNIV_NONINL
  233. #include "mtr0log.ic"
  234. #endif
  235. #endif