InnoDB Plugin  1.0
trx0undo.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2013, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #ifndef trx0undo_h
27 #define trx0undo_h
28 
29 #include "univ.i"
30 #include "trx0types.h"
31 #include "mtr0mtr.h"
32 #include "trx0sys.h"
33 #include "page0types.h"
34 #include "trx0xa.h"
35 
36 #ifndef UNIV_HOTBACKUP
37 /***********************************************************************/
40 UNIV_INLINE
43 /*====================*/
44  ibool is_insert,
45  ulint rseg_id,
46  ulint page_no,
47  ulint offset);
48 /***********************************************************************/
50 UNIV_INLINE
51 void
53 /*=====================*/
54  roll_ptr_t roll_ptr,
55  ibool* is_insert,
56  ulint* rseg_id,
57  ulint* page_no,
58  ulint* offset);
60 /***********************************************************************/
63 UNIV_INLINE
64 ibool
66 /*========================*/
67  roll_ptr_t roll_ptr);
68 /***********************************************************************/
71 UNIV_INLINE
72 bool
74 /*======================*/
75  const byte* trx_id)
76  __attribute__((nonnull, pure, warn_unused_result));
77 #endif /* !UNIV_HOTBACKUP */
78 /*****************************************************************/
82 UNIV_INLINE
83 void
85 /*===============*/
86  byte* ptr,
88  roll_ptr_t roll_ptr);
89 /*****************************************************************/
94 UNIV_INLINE
97 /*==============*/
98  const byte* ptr);
99 #ifndef UNIV_HOTBACKUP
100 /******************************************************************/
103 UNIV_INLINE
104 page_t*
106 /*==============*/
107  ulint space,
108  ulint zip_size,
110  ulint page_no,
111  mtr_t* mtr);
112 /******************************************************************/
115 UNIV_INLINE
116 page_t*
118 /*========================*/
119  ulint space,
120  ulint zip_size,
122  ulint page_no,
123  mtr_t* mtr);
124 /******************************************************************/
128 UNIV_INLINE
131 /*=======================*/
132  trx_undo_rec_t* rec,
133  ulint page_no,
134  ulint offset);
135 /******************************************************************/
139 UNIV_INLINE
142 /*=======================*/
143  trx_undo_rec_t* rec,
144  ulint page_no,
145  ulint offset);
146 /******************************************************************/
150 UNIV_INLINE
153 /*=======================*/
154  page_t* undo_page,
155  ulint page_no,
156  ulint offset);
157 /******************************************************************/
161 UNIV_INLINE
164 /*========================*/
165  page_t* undo_page,
166  ulint page_no,
167  ulint offset);
168 /***********************************************************************/
171 UNIV_INTERN
174 /*==================*/
175  trx_undo_rec_t* rec,
176  ulint page_no,
177  ulint offset,
178  bool shared,
179  mtr_t* mtr);
180 /***********************************************************************/
183 UNIV_INTERN
186 /*==================*/
187  trx_undo_rec_t* rec,
188  ulint page_no,
189  ulint offset,
190  mtr_t* mtr);
191 /***********************************************************************/
194 UNIV_INTERN
197 /*===================*/
198  ulint space,
199  ulint zip_size,
201  ulint page_no,
202  ulint offset,
203  ulint mode,
204  mtr_t* mtr);
205 /********************************************************************/
208 UNIV_INTERN
211 /*==============*/
212  trx_t* trx,
213  trx_undo_t* undo,
214  mtr_t* mtr)
217  __attribute__((nonnull, warn_unused_result));
218 /********************************************************************/
221 UNIV_INTERN
222 void
224 /*==========================*/
225 #ifdef UNIV_DEBUG
226  const trx_t* trx,
227 #endif /* UNIV_DEBUG */
228  trx_undo_t* undo,
229  mtr_t* mtr)
232  __attribute__((nonnull));
233 #ifdef UNIV_DEBUG
234 # define trx_undo_free_last_page(trx,undo,mtr) \
235  trx_undo_free_last_page_func(trx,undo,mtr)
236 #else /* UNIV_DEBUG */
237 # define trx_undo_free_last_page(trx,undo,mtr) \
238  trx_undo_free_last_page_func(undo,mtr)
239 #endif /* UNIV_DEBUG */
240 
241 /***********************************************************************/
244 UNIV_INTERN
245 void
247 /*=======================*/
248 #ifdef UNIV_DEBUG
249  const trx_t* trx,
250 #endif /* UNIV_DEBUG */
251  trx_undo_t* undo,
252  undo_no_t limit)
254  __attribute__((nonnull));
255 #ifdef UNIV_DEBUG
256 # define trx_undo_truncate_end(trx,undo,limit) \
257  trx_undo_truncate_end_func(trx,undo,limit)
258 #else /* UNIV_DEBUG */
259 # define trx_undo_truncate_end(trx,undo,limit) \
260  trx_undo_truncate_end_func(undo,limit)
261 #endif /* UNIV_DEBUG */
262 
263 /***********************************************************************/
266 UNIV_INTERN
267 void
269 /*====================*/
270  trx_rseg_t* rseg,
271  ulint space,
272  ulint hdr_page_no,
273  ulint hdr_offset,
274  undo_no_t limit);
281 /********************************************************************/
286 UNIV_INTERN
287 ulint
289 /*================*/
290  trx_rseg_t* rseg);
291 /**********************************************************************/
297 UNIV_INTERN
298 dberr_t
300 /*=================*/
301  trx_t* trx,
302  ulint type)
303  __attribute__((nonnull, warn_unused_result));
304 /******************************************************************/
307 UNIV_INTERN
308 page_t*
310 /*=========================*/
311  trx_undo_t* undo,
312  mtr_t* mtr);
313 /******************************************************************/
316 UNIV_INTERN
317 page_t*
319 /*==========================*/
320  trx_t* trx,
321  trx_undo_t* undo,
322  mtr_t* mtr);
324 /**********************************************************************/
328 UNIV_INTERN
329 void
331 /*====================*/
332  trx_t* trx,
333  page_t* undo_page,
335  mtr_t* mtr);
336 /******************************************************************/
340 UNIV_INTERN
341 void
343 /*====================*/
344  trx_t* trx);
346 /********************************************************************/
348 UNIV_INTERN
349 void
351 /*===================*/
352  trx_t* trx)
353  UNIV_COLD __attribute__((nonnull));
354 #endif /* !UNIV_HOTBACKUP */
355 /***********************************************************/
358 UNIV_INTERN
359 byte*
361 /*=====================*/
362  byte* ptr,
363  byte* end_ptr,
364  page_t* page,
365  mtr_t* mtr);
366 /***********************************************************/
369 UNIV_INTERN
370 byte*
372 /*=======================*/
373  ulint type,
374  byte* ptr,
375  byte* end_ptr,
376  page_t* page,
377  mtr_t* mtr);
378 /***********************************************************/
381 UNIV_INTERN
382 byte*
384 /*==========================*/
385  byte* ptr,
386  byte* end_ptr,
387  page_t* page,
388  mtr_t* mtr);
389 /************************************************************************
390 Frees an undo log memory copy. */
391 UNIV_INTERN
392 void
393 trx_undo_mem_free(
394 /*==============*/
395  trx_undo_t* undo); /* in: the undo object to be freed */
396 
397 /* Types of an undo log segment */
398 #define TRX_UNDO_INSERT 1 /* contains undo entries for inserts */
399 #define TRX_UNDO_UPDATE 2 /* contains undo entries for updates
400  and delete markings: in short,
401  modifys (the name 'UPDATE' is a
402  historical relic) */
403 /* States of an undo log segment */
404 #define TRX_UNDO_ACTIVE 1 /* contains an undo log of an active
405  transaction */
406 #define TRX_UNDO_CACHED 2 /* cached for quick reuse */
407 #define TRX_UNDO_TO_FREE 3 /* insert undo segment can be freed */
408 #define TRX_UNDO_TO_PURGE 4 /* update undo segment will not be
409  reused: it can be freed in purge when
410  all undo data in it is removed */
411 #define TRX_UNDO_PREPARED 5 /* contains an undo log of an
412  prepared transaction */
414 #ifndef UNIV_HOTBACKUP
418 struct trx_undo_t{
419  /*-----------------------------*/
420  ulint id;
422  ulint type;
424  ulint state;
426  ibool del_marks;
439  table_id_t table_id;
441  trx_rseg_t* rseg;
442  /*-----------------------------*/
443  ulint space;
445  ulint zip_size;
447  ulint hdr_page_no;
449  ulint hdr_offset;
451  ulint last_page_no;
454  ulint size;
455  /*-----------------------------*/
456  ulint empty;
458  ulint top_page_no;
462  ulint top_offset;
468  /*-----------------------------*/
469  UT_LIST_NODE_T(trx_undo_t) undo_list;
472 };
473 #endif /* !UNIV_HOTBACKUP */
474 
476 #define TRX_UNDO_PAGE_HDR FSEG_PAGE_DATA
477 /*-------------------------------------------------------------*/
479 /* @{ */
480 #define TRX_UNDO_PAGE_TYPE 0
482 #define TRX_UNDO_PAGE_START 2
487 #define TRX_UNDO_PAGE_FREE 4
490 #define TRX_UNDO_PAGE_NODE 6
492 /*-------------------------------------------------------------*/
493 #define TRX_UNDO_PAGE_HDR_SIZE (6 + FLST_NODE_SIZE)
494 
496 /* @} */
497 
502 #define TRX_UNDO_PAGE_REUSE_LIMIT (3 * UNIV_PAGE_SIZE / 4)
503 
504 /* An update undo log segment may contain several undo logs on its first page
505 if the undo logs took so little space that the segment could be cached and
506 reused. All the undo log headers are then on the first page, and the last one
507 owns the undo log records on subsequent pages if the segment is bigger than
508 one page. If an undo log is stored in a segment, then on the first page it is
509 allowed to have zero undo records, but if the segment extends to several
510 pages, then all the rest of the pages must contain at least one undo log
511 record. */
512 
516 #define TRX_UNDO_SEG_HDR (TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE)
518 /* @{ */
519 /*-------------------------------------------------------------*/
520 #define TRX_UNDO_STATE 0
521 #define TRX_UNDO_LAST_LOG 2
524 #define TRX_UNDO_FSEG_HEADER 4
526 #define TRX_UNDO_PAGE_LIST (4 + FSEG_HEADER_SIZE)
527 
530 /*-------------------------------------------------------------*/
532 #define TRX_UNDO_SEG_HDR_SIZE (4 + FSEG_HEADER_SIZE + FLST_BASE_NODE_SIZE)
533 /* @} */
535 
538 /* @{ */
539 /*-------------------------------------------------------------*/
540 #define TRX_UNDO_TRX_ID 0
541 #define TRX_UNDO_TRX_NO 8
544 #define TRX_UNDO_DEL_MARKS 16
548 #define TRX_UNDO_LOG_START 18
554 #define TRX_UNDO_XID_EXISTS 20
557 #define TRX_UNDO_DICT_TRANS 21
564 #define TRX_UNDO_TABLE_ID 22
566 #define TRX_UNDO_NEXT_LOG 30
568 #define TRX_UNDO_PREV_LOG 32
570 #define TRX_UNDO_HISTORY_NODE 34
572 /*-------------------------------------------------------------*/
573 
574 #define TRX_UNDO_LOG_OLD_HDR_SIZE (34 + FLST_NODE_SIZE)
575 
576 /* Note: the writing of the undo log old header is coded by a log record
577 MLOG_UNDO_HDR_CREATE or MLOG_UNDO_HDR_REUSE. The appending of an XID to the
578 header is logged separately. In this sense, the XID is not really a member
579 of the undo log header. TODO: do not append the XID to the log header if XA
580 is not needed by the user. The XID wastes about 150 bytes of space in every
581 undo log. In the history list we may have millions of undo logs, which means
582 quite a large overhead. */
583 
585 /* @{ */
587 #define TRX_UNDO_XA_FORMAT (TRX_UNDO_LOG_OLD_HDR_SIZE)
589 #define TRX_UNDO_XA_TRID_LEN (TRX_UNDO_XA_FORMAT + 4)
590 
591 #define TRX_UNDO_XA_BQUAL_LEN (TRX_UNDO_XA_TRID_LEN + 4)
592 
593 #define TRX_UNDO_XA_XID (TRX_UNDO_XA_BQUAL_LEN + 4)
594 /*--------------------------------------------------------------*/
595 #define TRX_UNDO_LOG_XA_HDR_SIZE (TRX_UNDO_XA_XID + XIDDATASIZE)
596 
598 /* @} */
599 
600 #ifndef UNIV_NONINL
601 #include "trx0undo.ic"
602 #endif
603 
604 #endif