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.

220 lines
8.1 KiB

  1. /*****************************************************************************
  2. Copyright (c) 1996, 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/trx0rseg.h
  15. Rollback segment
  16. Created 3/26/1996 Heikki Tuuri
  17. *******************************************************/
  18. #ifndef trx0rseg_h
  19. #define trx0rseg_h
  20. #include "univ.i"
  21. #include "trx0types.h"
  22. #include "trx0sys.h"
  23. /******************************************************************//**
  24. Gets a rollback segment header.
  25. @return rollback segment header, page x-latched */
  26. UNIV_INLINE
  27. trx_rsegf_t*
  28. trx_rsegf_get(
  29. /*==========*/
  30. ulint space, /*!< in: space where placed */
  31. ulint zip_size, /*!< in: compressed page size in bytes
  32. or 0 for uncompressed pages */
  33. ulint page_no, /*!< in: page number of the header */
  34. mtr_t* mtr); /*!< in: mtr */
  35. /******************************************************************//**
  36. Gets a newly created rollback segment header.
  37. @return rollback segment header, page x-latched */
  38. UNIV_INLINE
  39. trx_rsegf_t*
  40. trx_rsegf_get_new(
  41. /*==============*/
  42. ulint space, /*!< in: space where placed */
  43. ulint zip_size, /*!< in: compressed page size in bytes
  44. or 0 for uncompressed pages */
  45. ulint page_no, /*!< in: page number of the header */
  46. mtr_t* mtr); /*!< in: mtr */
  47. /***************************************************************//**
  48. Gets the file page number of the nth undo log slot.
  49. @return page number of the undo log segment */
  50. UNIV_INLINE
  51. ulint
  52. trx_rsegf_get_nth_undo(
  53. /*===================*/
  54. trx_rsegf_t* rsegf, /*!< in: rollback segment header */
  55. ulint n, /*!< in: index of slot */
  56. mtr_t* mtr); /*!< in: mtr */
  57. /***************************************************************//**
  58. Sets the file page number of the nth undo log slot. */
  59. UNIV_INLINE
  60. void
  61. trx_rsegf_set_nth_undo(
  62. /*===================*/
  63. trx_rsegf_t* rsegf, /*!< in: rollback segment header */
  64. ulint n, /*!< in: index of slot */
  65. ulint page_no,/*!< in: page number of the undo log segment */
  66. mtr_t* mtr); /*!< in: mtr */
  67. /****************************************************************//**
  68. Looks for a free slot for an undo log segment.
  69. @return slot index or ULINT_UNDEFINED if not found */
  70. UNIV_INLINE
  71. ulint
  72. trx_rsegf_undo_find_free(
  73. /*=====================*/
  74. trx_rsegf_t* rsegf, /*!< in: rollback segment header */
  75. mtr_t* mtr); /*!< in: mtr */
  76. /******************************************************************//**
  77. Looks for a rollback segment, based on the rollback segment id.
  78. @return rollback segment */
  79. UNIV_INTERN
  80. trx_rseg_t*
  81. trx_rseg_get_on_id(
  82. /*===============*/
  83. ulint id); /*!< in: rollback segment id */
  84. /****************************************************************//**
  85. Creates a rollback segment header. This function is called only when
  86. a new rollback segment is created in the database.
  87. @return page number of the created segment, FIL_NULL if fail */
  88. UNIV_INTERN
  89. ulint
  90. trx_rseg_header_create(
  91. /*===================*/
  92. ulint space, /*!< in: space id */
  93. ulint zip_size, /*!< in: compressed page size in bytes
  94. or 0 for uncompressed pages */
  95. ulint max_size, /*!< in: max size in pages */
  96. ulint* slot_no, /*!< out: rseg id == slot number in trx sys */
  97. mtr_t* mtr); /*!< in: mtr */
  98. /*********************************************************************//**
  99. Creates the memory copies for rollback segments and initializes the
  100. rseg list and array in trx_sys at a database startup. */
  101. UNIV_INTERN
  102. void
  103. trx_rseg_list_and_array_init(
  104. /*=========================*/
  105. trx_sysf_t* sys_header, /*!< in: trx system header */
  106. mtr_t* mtr); /*!< in: mtr */
  107. /****************************************************************//**
  108. Creates a new rollback segment to the database.
  109. @return the created segment object, NULL if fail */
  110. UNIV_INTERN
  111. trx_rseg_t*
  112. trx_rseg_create(
  113. /*============*/
  114. ulint space, /*!< in: space id */
  115. ulint max_size, /*!< in: max size in pages */
  116. ulint* id, /*!< out: rseg id */
  117. mtr_t* mtr); /*!< in: mtr */
  118. /***************************************************************************
  119. Free's an instance of the rollback segment in memory. */
  120. UNIV_INTERN
  121. void
  122. trx_rseg_mem_free(
  123. /*==============*/
  124. trx_rseg_t* rseg); /* in, own: instance to free */
  125. /* Number of undo log slots in a rollback segment file copy */
  126. #define TRX_RSEG_N_SLOTS (UNIV_PAGE_SIZE / 16)
  127. /* Maximum number of transactions supported by a single rollback segment */
  128. #define TRX_RSEG_MAX_N_TRXS (TRX_RSEG_N_SLOTS / 2)
  129. /* The rollback segment memory object */
  130. struct trx_rseg_struct{
  131. /*--------------------------------------------------------*/
  132. ulint id; /*!< rollback segment id == the index of
  133. its slot in the trx system file copy */
  134. mutex_t mutex; /*!< mutex protecting the fields in this
  135. struct except id; NOTE that the latching
  136. order must always be kernel mutex ->
  137. rseg mutex */
  138. ulint space; /*!< space where the rollback segment is
  139. header is placed */
  140. ulint zip_size;/* compressed page size of space
  141. in bytes, or 0 for uncompressed spaces */
  142. ulint page_no;/* page number of the rollback segment
  143. header */
  144. ulint max_size;/* maximum allowed size in pages */
  145. ulint curr_size;/* current size in pages */
  146. /*--------------------------------------------------------*/
  147. /* Fields for update undo logs */
  148. UT_LIST_BASE_NODE_T(trx_undo_t) update_undo_list;
  149. /* List of update undo logs */
  150. UT_LIST_BASE_NODE_T(trx_undo_t) update_undo_cached;
  151. /* List of update undo log segments
  152. cached for fast reuse */
  153. /*--------------------------------------------------------*/
  154. /* Fields for insert undo logs */
  155. UT_LIST_BASE_NODE_T(trx_undo_t) insert_undo_list;
  156. /* List of insert undo logs */
  157. UT_LIST_BASE_NODE_T(trx_undo_t) insert_undo_cached;
  158. /* List of insert undo log segments
  159. cached for fast reuse */
  160. /*--------------------------------------------------------*/
  161. ulint last_page_no; /*!< Page number of the last not yet
  162. purged log header in the history list;
  163. FIL_NULL if all list purged */
  164. ulint last_offset; /*!< Byte offset of the last not yet
  165. purged log header */
  166. trx_id_t last_trx_no; /*!< Transaction number of the last not
  167. yet purged log */
  168. ibool last_del_marks; /*!< TRUE if the last not yet purged log
  169. needs purging */
  170. /*--------------------------------------------------------*/
  171. UT_LIST_NODE_T(trx_rseg_t) rseg_list;
  172. /* the list of the rollback segment
  173. memory objects */
  174. };
  175. /* Undo log segment slot in a rollback segment header */
  176. /*-------------------------------------------------------------*/
  177. #define TRX_RSEG_SLOT_PAGE_NO 0 /* Page number of the header page of
  178. an undo log segment */
  179. /*-------------------------------------------------------------*/
  180. /* Slot size */
  181. #define TRX_RSEG_SLOT_SIZE 4
  182. /* The offset of the rollback segment header on its page */
  183. #define TRX_RSEG FSEG_PAGE_DATA
  184. /* Transaction rollback segment header */
  185. /*-------------------------------------------------------------*/
  186. #define TRX_RSEG_MAX_SIZE 0 /* Maximum allowed size for rollback
  187. segment in pages */
  188. #define TRX_RSEG_HISTORY_SIZE 4 /* Number of file pages occupied
  189. by the logs in the history list */
  190. #define TRX_RSEG_HISTORY 8 /* The update undo logs for committed
  191. transactions */
  192. #define TRX_RSEG_FSEG_HEADER (8 + FLST_BASE_NODE_SIZE)
  193. /* Header for the file segment where
  194. this page is placed */
  195. #define TRX_RSEG_UNDO_SLOTS (8 + FLST_BASE_NODE_SIZE + FSEG_HEADER_SIZE)
  196. /* Undo log segment slots */
  197. /*-------------------------------------------------------------*/
  198. #ifndef UNIV_NONINL
  199. #include "trx0rseg.ic"
  200. #endif
  201. #endif