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.

416 lines
14 KiB

Applying InnoDB Plugin 1.0.5 snapshot, part 6 From revision r5748 to r5783 Detailed revision comments: r5748 | marko | 2009-09-03 06:05:44 -0500 (Thu, 03 Sep 2009) | 1 line branches/zip: MLOG_MULTI_REC_END: Correct the comment. r5751 | marko | 2009-09-03 09:36:15 -0500 (Thu, 03 Sep 2009) | 7 lines branches/zip: row_merge(): Remove a bogus debug assertion that was triggered when creating an index on an empty table. row_merge_sort(): Add debug assertions and comments that justify the loop termination condition. The bogus assertion ut_ad(ihalf > 0) was reported by Michael. r5752 | marko | 2009-09-03 09:55:51 -0500 (Thu, 03 Sep 2009) | 10 lines branches/zip: recv_recover_page_func(): Write the log sequence number to the compressed page, if there is one. Previously, the function only wrote the LSN to the uncompressed page. It is not clear why recv_recover_page_func() is updating FIL_PAGE_LSN in the buffer pool. The log sequence number will be stamped on the page when it is flushed to disk, in buf_flush_init_for_writing(). I noticed this inconsistency when analyzing Issue #313, but this patch does not fix it. That is no surprise, since FIL_PAGE_LSN should only matter on disk files, not in the buffer pool. r5775 | calvin | 2009-09-07 16:15:05 -0500 (Mon, 07 Sep 2009) | 13 lines branches/zip: Build InnoDB on Windows with UNIV_HOTBACKUP The changes are non-functional changes for normal InnoDB, but needed for building the Hot Backup on Windows (with UNIV_HOTBACKUP defined). - Define os_aio_use_native_aio for HB. - Do not acquire seek mutexes for backup since HB is single threaded. - Do not use srv_flush_log_at_trx_commit for HB build rb://155 Approved by: Marko r5777 | marko | 2009-09-08 10:50:25 -0500 (Tue, 08 Sep 2009) | 2 lines branches/zip: Remove BUF_LRU_INITIAL_RATIO, which should have been removed together with buf_LRU_get_recent_limit(). r5779 | marko | 2009-09-09 01:17:19 -0500 (Wed, 09 Sep 2009) | 2 lines branches/zip: buf_page_peek_if_too_old(): Make the bitmasking work when buf_pool->freed_page_clock is wider than 32 bits. r5780 | marko | 2009-09-09 01:50:50 -0500 (Wed, 09 Sep 2009) | 1 line branches/zip: ut_time_ms(): Return ulint, not uint. r5782 | marko | 2009-09-09 02:00:59 -0500 (Wed, 09 Sep 2009) | 2 lines branches/zip: buf_page_peek_if_too_old(): Silence a compiler warning that was introduced in r5779 on 32-bit systems. r5783 | marko | 2009-09-09 02:25:00 -0500 (Wed, 09 Sep 2009) | 1 line branches/zip: buf_page_is_accessed(): Correct the function comment.
16 years ago
  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/mtr0mtr.h
  15. Mini-transaction buffer
  16. Created 11/26/1995 Heikki Tuuri
  17. *******************************************************/
  18. #ifndef mtr0mtr_h
  19. #define mtr0mtr_h
  20. #include "univ.i"
  21. #include "mem0mem.h"
  22. #include "dyn0dyn.h"
  23. #include "buf0types.h"
  24. #include "sync0rw.h"
  25. #include "ut0byte.h"
  26. #include "mtr0types.h"
  27. #include "page0types.h"
  28. /* Logging modes for a mini-transaction */
  29. #define MTR_LOG_ALL 21 /* default mode: log all operations
  30. modifying disk-based data */
  31. #define MTR_LOG_NONE 22 /* log no operations */
  32. /*#define MTR_LOG_SPACE 23 */ /* log only operations modifying
  33. file space page allocation data
  34. (operations in fsp0fsp.* ) */
  35. #define MTR_LOG_SHORT_INSERTS 24 /* inserts are logged in a shorter
  36. form */
  37. /* Types for the mlock objects to store in the mtr memo; NOTE that the
  38. first 3 values must be RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
  39. #define MTR_MEMO_PAGE_S_FIX RW_S_LATCH
  40. #define MTR_MEMO_PAGE_X_FIX RW_X_LATCH
  41. #define MTR_MEMO_BUF_FIX RW_NO_LATCH
  42. #define MTR_MEMO_MODIFY 54
  43. #define MTR_MEMO_S_LOCK 55
  44. #define MTR_MEMO_X_LOCK 56
  45. /** @name Log item types
  46. The log items are declared 'byte' so that the compiler can warn if val
  47. and type parameters are switched in a call to mlog_write_ulint. NOTE!
  48. For 1 - 8 bytes, the flag value must give the length also! @{ */
  49. #define MLOG_SINGLE_REC_FLAG 128 /*!< if the mtr contains only
  50. one log record for one page,
  51. i.e., write_initial_log_record
  52. has been called only once,
  53. this flag is ORed to the type
  54. of that first log record */
  55. #define MLOG_1BYTE (1) /*!< one byte is written */
  56. #define MLOG_2BYTES (2) /*!< 2 bytes ... */
  57. #define MLOG_4BYTES (4) /*!< 4 bytes ... */
  58. #define MLOG_8BYTES (8) /*!< 8 bytes ... */
  59. #define MLOG_REC_INSERT ((byte)9) /*!< record insert */
  60. #define MLOG_REC_CLUST_DELETE_MARK ((byte)10) /*!< mark clustered index record
  61. deleted */
  62. #define MLOG_REC_SEC_DELETE_MARK ((byte)11) /*!< mark secondary index record
  63. deleted */
  64. #define MLOG_REC_UPDATE_IN_PLACE ((byte)13) /*!< update of a record,
  65. preserves record field sizes */
  66. #define MLOG_REC_DELETE ((byte)14) /*!< delete a record from a
  67. page */
  68. #define MLOG_LIST_END_DELETE ((byte)15) /*!< delete record list end on
  69. index page */
  70. #define MLOG_LIST_START_DELETE ((byte)16) /*!< delete record list start on
  71. index page */
  72. #define MLOG_LIST_END_COPY_CREATED ((byte)17) /*!< copy record list end to a
  73. new created index page */
  74. #define MLOG_PAGE_REORGANIZE ((byte)18) /*!< reorganize an
  75. index page in
  76. ROW_FORMAT=REDUNDANT */
  77. #define MLOG_PAGE_CREATE ((byte)19) /*!< create an index page */
  78. #define MLOG_UNDO_INSERT ((byte)20) /*!< insert entry in an undo
  79. log */
  80. #define MLOG_UNDO_ERASE_END ((byte)21) /*!< erase an undo log
  81. page end */
  82. #define MLOG_UNDO_INIT ((byte)22) /*!< initialize a page in an
  83. undo log */
  84. #define MLOG_UNDO_HDR_DISCARD ((byte)23) /*!< discard an update undo log
  85. header */
  86. #define MLOG_UNDO_HDR_REUSE ((byte)24) /*!< reuse an insert undo log
  87. header */
  88. #define MLOG_UNDO_HDR_CREATE ((byte)25) /*!< create an undo
  89. log header */
  90. #define MLOG_REC_MIN_MARK ((byte)26) /*!< mark an index
  91. record as the
  92. predefined minimum
  93. record */
  94. #define MLOG_IBUF_BITMAP_INIT ((byte)27) /*!< initialize an
  95. ibuf bitmap page */
  96. /*#define MLOG_FULL_PAGE ((byte)28) full contents of a page */
  97. #define MLOG_INIT_FILE_PAGE ((byte)29) /*!< this means that a
  98. file page is taken
  99. into use and the prior
  100. contents of the page
  101. should be ignored: in
  102. recovery we must not
  103. trust the lsn values
  104. stored to the file
  105. page */
  106. #define MLOG_WRITE_STRING ((byte)30) /*!< write a string to
  107. a page */
  108. #define MLOG_MULTI_REC_END ((byte)31) /*!< if a single mtr writes
  109. several log records,
  110. this log record ends the
  111. sequence of these records */
  112. #define MLOG_DUMMY_RECORD ((byte)32) /*!< dummy log record used to
  113. pad a log block full */
  114. #define MLOG_FILE_CREATE ((byte)33) /*!< log record about an .ibd
  115. file creation */
  116. #define MLOG_FILE_RENAME ((byte)34) /*!< log record about an .ibd
  117. file rename */
  118. #define MLOG_FILE_DELETE ((byte)35) /*!< log record about an .ibd
  119. file deletion */
  120. #define MLOG_COMP_REC_MIN_MARK ((byte)36) /*!< mark a compact
  121. index record as the
  122. predefined minimum
  123. record */
  124. #define MLOG_COMP_PAGE_CREATE ((byte)37) /*!< create a compact
  125. index page */
  126. #define MLOG_COMP_REC_INSERT ((byte)38) /*!< compact record insert */
  127. #define MLOG_COMP_REC_CLUST_DELETE_MARK ((byte)39)
  128. /*!< mark compact
  129. clustered index record
  130. deleted */
  131. #define MLOG_COMP_REC_SEC_DELETE_MARK ((byte)40)/*!< mark compact
  132. secondary index record
  133. deleted; this log
  134. record type is
  135. redundant, as
  136. MLOG_REC_SEC_DELETE_MARK
  137. is independent of the
  138. record format. */
  139. #define MLOG_COMP_REC_UPDATE_IN_PLACE ((byte)41)/*!< update of a
  140. compact record,
  141. preserves record field
  142. sizes */
  143. #define MLOG_COMP_REC_DELETE ((byte)42) /*!< delete a compact record
  144. from a page */
  145. #define MLOG_COMP_LIST_END_DELETE ((byte)43) /*!< delete compact record list
  146. end on index page */
  147. #define MLOG_COMP_LIST_START_DELETE ((byte)44) /*!< delete compact record list
  148. start on index page */
  149. #define MLOG_COMP_LIST_END_COPY_CREATED ((byte)45)
  150. /*!< copy compact
  151. record list end to a
  152. new created index
  153. page */
  154. #define MLOG_COMP_PAGE_REORGANIZE ((byte)46) /*!< reorganize an index page */
  155. #define MLOG_FILE_CREATE2 ((byte)47) /*!< log record about creating
  156. an .ibd file, with format */
  157. #define MLOG_ZIP_WRITE_NODE_PTR ((byte)48) /*!< write the node pointer of
  158. a record on a compressed
  159. non-leaf B-tree page */
  160. #define MLOG_ZIP_WRITE_BLOB_PTR ((byte)49) /*!< write the BLOB pointer
  161. of an externally stored column
  162. on a compressed page */
  163. #define MLOG_ZIP_WRITE_HEADER ((byte)50) /*!< write to compressed page
  164. header */
  165. #define MLOG_ZIP_PAGE_COMPRESS ((byte)51) /*!< compress an index page */
  166. #define MLOG_BIGGEST_TYPE ((byte)51) /*!< biggest value (used in
  167. assertions) */
  168. /* @} */
  169. /** @name Flags for MLOG_FILE operations
  170. (stored in the page number parameter, called log_flags in the
  171. functions). The page number parameter was originally written as 0. @{ */
  172. #define MLOG_FILE_FLAG_TEMP 1 /*!< identifies TEMPORARY TABLE in
  173. MLOG_FILE_CREATE, MLOG_FILE_CREATE2 */
  174. /* @} */
  175. /***************************************************************//**
  176. Starts a mini-transaction and creates a mini-transaction handle
  177. and buffer in the memory buffer given by the caller.
  178. @return mtr buffer which also acts as the mtr handle */
  179. UNIV_INLINE
  180. mtr_t*
  181. mtr_start(
  182. /*======*/
  183. mtr_t* mtr); /*!< in: memory buffer for the mtr buffer */
  184. /***************************************************************//**
  185. Commits a mini-transaction. */
  186. UNIV_INTERN
  187. void
  188. mtr_commit(
  189. /*=======*/
  190. mtr_t* mtr); /*!< in: mini-transaction */
  191. /**********************************************************//**
  192. Sets and returns a savepoint in mtr.
  193. @return savepoint */
  194. UNIV_INLINE
  195. ulint
  196. mtr_set_savepoint(
  197. /*==============*/
  198. mtr_t* mtr); /*!< in: mtr */
  199. /**********************************************************//**
  200. Releases the latches stored in an mtr memo down to a savepoint.
  201. NOTE! The mtr must not have made changes to buffer pages after the
  202. savepoint, as these can be handled only by mtr_commit. */
  203. UNIV_INTERN
  204. void
  205. mtr_rollback_to_savepoint(
  206. /*======================*/
  207. mtr_t* mtr, /*!< in: mtr */
  208. ulint savepoint); /*!< in: savepoint */
  209. #ifndef UNIV_HOTBACKUP
  210. /**********************************************************//**
  211. Releases the (index tree) s-latch stored in an mtr memo after a
  212. savepoint. */
  213. UNIV_INLINE
  214. void
  215. mtr_release_s_latch_at_savepoint(
  216. /*=============================*/
  217. mtr_t* mtr, /*!< in: mtr */
  218. ulint savepoint, /*!< in: savepoint */
  219. rw_lock_t* lock); /*!< in: latch to release */
  220. #else /* !UNIV_HOTBACKUP */
  221. # define mtr_release_s_latch_at_savepoint(mtr,savepoint,lock) ((void) 0)
  222. #endif /* !UNIV_HOTBACKUP */
  223. /***************************************************************//**
  224. Gets the logging mode of a mini-transaction.
  225. @return logging mode: MTR_LOG_NONE, ... */
  226. UNIV_INLINE
  227. ulint
  228. mtr_get_log_mode(
  229. /*=============*/
  230. mtr_t* mtr); /*!< in: mtr */
  231. /***************************************************************//**
  232. Changes the logging mode of a mini-transaction.
  233. @return old mode */
  234. UNIV_INLINE
  235. ulint
  236. mtr_set_log_mode(
  237. /*=============*/
  238. mtr_t* mtr, /*!< in: mtr */
  239. ulint mode); /*!< in: logging mode: MTR_LOG_NONE, ... */
  240. /********************************************************//**
  241. Reads 1 - 4 bytes from a file page buffered in the buffer pool.
  242. @return value read */
  243. UNIV_INTERN
  244. ulint
  245. mtr_read_ulint(
  246. /*===========*/
  247. const byte* ptr, /*!< in: pointer from where to read */
  248. ulint type, /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
  249. mtr_t* mtr); /*!< in: mini-transaction handle */
  250. /********************************************************//**
  251. Reads 8 bytes from a file page buffered in the buffer pool.
  252. @return value read */
  253. UNIV_INTERN
  254. dulint
  255. mtr_read_dulint(
  256. /*============*/
  257. const byte* ptr, /*!< in: pointer from where to read */
  258. mtr_t* mtr); /*!< in: mini-transaction handle */
  259. #ifndef UNIV_HOTBACKUP
  260. /*********************************************************************//**
  261. This macro locks an rw-lock in s-mode. */
  262. #define mtr_s_lock(B, MTR) mtr_s_lock_func((B), __FILE__, __LINE__,\
  263. (MTR))
  264. /*********************************************************************//**
  265. This macro locks an rw-lock in x-mode. */
  266. #define mtr_x_lock(B, MTR) mtr_x_lock_func((B), __FILE__, __LINE__,\
  267. (MTR))
  268. /*********************************************************************//**
  269. NOTE! Use the macro above!
  270. Locks a lock in s-mode. */
  271. UNIV_INLINE
  272. void
  273. mtr_s_lock_func(
  274. /*============*/
  275. rw_lock_t* lock, /*!< in: rw-lock */
  276. const char* file, /*!< in: file name */
  277. ulint line, /*!< in: line number */
  278. mtr_t* mtr); /*!< in: mtr */
  279. /*********************************************************************//**
  280. NOTE! Use the macro above!
  281. Locks a lock in x-mode. */
  282. UNIV_INLINE
  283. void
  284. mtr_x_lock_func(
  285. /*============*/
  286. rw_lock_t* lock, /*!< in: rw-lock */
  287. const char* file, /*!< in: file name */
  288. ulint line, /*!< in: line number */
  289. mtr_t* mtr); /*!< in: mtr */
  290. #endif /* !UNIV_HOTBACKUP */
  291. /***************************************************//**
  292. Releases an object in the memo stack. */
  293. UNIV_INTERN
  294. void
  295. mtr_memo_release(
  296. /*=============*/
  297. mtr_t* mtr, /*!< in: mtr */
  298. void* object, /*!< in: object */
  299. ulint type); /*!< in: object type: MTR_MEMO_S_LOCK, ... */
  300. #ifdef UNIV_DEBUG
  301. # ifndef UNIV_HOTBACKUP
  302. /**********************************************************//**
  303. Checks if memo contains the given item.
  304. @return TRUE if contains */
  305. UNIV_INLINE
  306. ibool
  307. mtr_memo_contains(
  308. /*==============*/
  309. mtr_t* mtr, /*!< in: mtr */
  310. const void* object, /*!< in: object to search */
  311. ulint type); /*!< in: type of object */
  312. /**********************************************************//**
  313. Checks if memo contains the given page.
  314. @return TRUE if contains */
  315. UNIV_INTERN
  316. ibool
  317. mtr_memo_contains_page(
  318. /*===================*/
  319. mtr_t* mtr, /*!< in: mtr */
  320. const byte* ptr, /*!< in: pointer to buffer frame */
  321. ulint type); /*!< in: type of object */
  322. /*********************************************************//**
  323. Prints info of an mtr handle. */
  324. UNIV_INTERN
  325. void
  326. mtr_print(
  327. /*======*/
  328. mtr_t* mtr); /*!< in: mtr */
  329. # else /* !UNIV_HOTBACKUP */
  330. # define mtr_memo_contains(mtr, object, type) TRUE
  331. # define mtr_memo_contains_page(mtr, ptr, type) TRUE
  332. # endif /* !UNIV_HOTBACKUP */
  333. #endif /* UNIV_DEBUG */
  334. /*######################################################################*/
  335. #define MTR_BUF_MEMO_SIZE 200 /* number of slots in memo */
  336. /***************************************************************//**
  337. Returns the log object of a mini-transaction buffer.
  338. @return log */
  339. UNIV_INLINE
  340. dyn_array_t*
  341. mtr_get_log(
  342. /*========*/
  343. mtr_t* mtr); /*!< in: mini-transaction */
  344. /***************************************************//**
  345. Pushes an object to an mtr memo stack. */
  346. UNIV_INLINE
  347. void
  348. mtr_memo_push(
  349. /*==========*/
  350. mtr_t* mtr, /*!< in: mtr */
  351. void* object, /*!< in: object */
  352. ulint type); /*!< in: object type: MTR_MEMO_S_LOCK, ... */
  353. /* Type definition of a mini-transaction memo stack slot. */
  354. typedef struct mtr_memo_slot_struct mtr_memo_slot_t;
  355. struct mtr_memo_slot_struct{
  356. ulint type; /*!< type of the stored object (MTR_MEMO_S_LOCK, ...) */
  357. void* object; /*!< pointer to the object */
  358. };
  359. /* Mini-transaction handle and buffer */
  360. struct mtr_struct{
  361. #ifdef UNIV_DEBUG
  362. ulint state; /*!< MTR_ACTIVE, MTR_COMMITTING, MTR_COMMITTED */
  363. #endif
  364. dyn_array_t memo; /*!< memo stack for locks etc. */
  365. dyn_array_t log; /*!< mini-transaction log */
  366. ibool modifications;
  367. /* TRUE if the mtr made modifications to
  368. buffer pool pages */
  369. ulint n_log_recs;
  370. /* count of how many page initial log records
  371. have been written to the mtr log */
  372. ulint log_mode; /* specifies which operations should be
  373. logged; default value MTR_LOG_ALL */
  374. ib_uint64_t start_lsn;/* start lsn of the possible log entry for
  375. this mtr */
  376. ib_uint64_t end_lsn;/* end lsn of the possible log entry for
  377. this mtr */
  378. #ifdef UNIV_DEBUG
  379. ulint magic_n;
  380. #endif /* UNIV_DEBUG */
  381. };
  382. #ifdef UNIV_DEBUG
  383. # define MTR_MAGIC_N 54551
  384. #endif /* UNIV_DEBUG */
  385. #define MTR_ACTIVE 12231
  386. #define MTR_COMMITTING 56456
  387. #define MTR_COMMITTED 34676
  388. #ifndef UNIV_NONINL
  389. #include "mtr0mtr.ic"
  390. #endif
  391. #endif