Drizzled Public API Documentation

trx0undo.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003 Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify it under
00006 the terms of the GNU General Public License as published by the Free Software
00007 Foundation; version 2 of the License.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with
00014 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
00015 St, Fifth Floor, Boston, MA 02110-1301 USA
00016 
00017 *****************************************************************************/
00018 
00019 /**************************************************/
00026 #pragma once
00027 #ifndef trx0undo_h
00028 #define trx0undo_h
00029 
00030 #include "univ.i"
00031 #include "trx0types.h"
00032 #include "mtr0mtr.h"
00033 #include "trx0sys.h"
00034 #include "page0types.h"
00035 #include "trx0xa.h"
00036 
00037 #ifndef UNIV_HOTBACKUP
00038 /***********************************************************************/
00041 UNIV_INLINE
00042 roll_ptr_t
00043 trx_undo_build_roll_ptr(
00044 /*====================*/
00045   ibool is_insert,  
00046   ulint rseg_id,  
00047   ulint page_no,  
00048   ulint offset);  
00049 /***********************************************************************/
00051 UNIV_INLINE
00052 void
00053 trx_undo_decode_roll_ptr(
00054 /*=====================*/
00055   roll_ptr_t  roll_ptr, 
00056   ibool*    is_insert,  
00057   ulint*    rseg_id,  
00058   ulint*    page_no,  
00059   ulint*    offset);  
00061 /***********************************************************************/
00064 UNIV_INLINE
00065 ibool
00066 trx_undo_roll_ptr_is_insert(
00067 /*========================*/
00068   roll_ptr_t  roll_ptr);  
00069 #endif /* !UNIV_HOTBACKUP */
00070 /*****************************************************************/
00074 UNIV_INLINE
00075 void
00076 trx_write_roll_ptr(
00077 /*===============*/
00078   byte*   ptr,    
00080   roll_ptr_t  roll_ptr);  
00081 /*****************************************************************/
00086 UNIV_INLINE
00087 roll_ptr_t
00088 trx_read_roll_ptr(
00089 /*==============*/
00090   const byte* ptr); 
00091 #ifndef UNIV_HOTBACKUP
00092 /******************************************************************/
00095 UNIV_INLINE
00096 page_t*
00097 trx_undo_page_get(
00098 /*==============*/
00099   ulint space,    
00100   ulint zip_size, 
00102   ulint page_no,  
00103   mtr_t*  mtr);   
00104 /******************************************************************/
00107 UNIV_INLINE
00108 page_t*
00109 trx_undo_page_get_s_latched(
00110 /*========================*/
00111   ulint space,    
00112   ulint zip_size, 
00114   ulint page_no,  
00115   mtr_t*  mtr);   
00116 /******************************************************************/
00120 UNIV_INLINE
00121 trx_undo_rec_t*
00122 trx_undo_page_get_prev_rec(
00123 /*=======================*/
00124   trx_undo_rec_t* rec,  
00125   ulint   page_no,
00126   ulint   offset);
00127 /******************************************************************/
00131 UNIV_INLINE
00132 trx_undo_rec_t*
00133 trx_undo_page_get_next_rec(
00134 /*=======================*/
00135   trx_undo_rec_t* rec,  
00136   ulint   page_no,
00137   ulint   offset);
00138 /******************************************************************/
00142 UNIV_INLINE
00143 trx_undo_rec_t*
00144 trx_undo_page_get_last_rec(
00145 /*=======================*/
00146   page_t* undo_page,
00147   ulint page_no,
00148   ulint offset);  
00149 /******************************************************************/
00153 UNIV_INLINE
00154 trx_undo_rec_t*
00155 trx_undo_page_get_first_rec(
00156 /*========================*/
00157   page_t* undo_page,
00158   ulint page_no,
00159   ulint offset);
00160 /***********************************************************************/
00163 UNIV_INTERN
00164 trx_undo_rec_t*
00165 trx_undo_get_prev_rec(
00166 /*==================*/
00167   trx_undo_rec_t* rec,  
00168   ulint   page_no,
00169   ulint   offset, 
00170   mtr_t*    mtr); 
00171 /***********************************************************************/
00174 UNIV_INTERN
00175 trx_undo_rec_t*
00176 trx_undo_get_next_rec(
00177 /*==================*/
00178   trx_undo_rec_t* rec,  
00179   ulint   page_no,
00180   ulint   offset, 
00181   mtr_t*    mtr); 
00182 /***********************************************************************/
00185 UNIV_INTERN
00186 trx_undo_rec_t*
00187 trx_undo_get_first_rec(
00188 /*===================*/
00189   ulint space,  
00190   ulint zip_size,
00192   ulint page_no,
00193   ulint offset, 
00194   ulint mode, 
00195   mtr_t*  mtr); 
00196 /********************************************************************/
00199 UNIV_INTERN
00200 ulint
00201 trx_undo_add_page(
00202 /*==============*/
00203   trx_t*    trx,  
00204   trx_undo_t* undo, 
00205   mtr_t*    mtr); 
00208 /***********************************************************************/
00211 UNIV_INTERN
00212 void
00213 trx_undo_truncate_end(
00214 /*==================*/
00215   trx_t*    trx,  
00216   trx_undo_t* undo, 
00217   undo_no_t limit); 
00219 /***********************************************************************/
00222 UNIV_INTERN
00223 void
00224 trx_undo_truncate_start(
00225 /*====================*/
00226   trx_rseg_t* rseg,   
00227   ulint   space,    
00228   ulint   hdr_page_no,  
00229   ulint   hdr_offset, 
00230   undo_no_t limit);   
00237 /********************************************************************/
00242 UNIV_INTERN
00243 ulint
00244 trx_undo_lists_init(
00245 /*================*/
00246   trx_rseg_t* rseg);  
00247 /**********************************************************************/
00253 UNIV_INTERN
00254 ulint
00255 trx_undo_assign_undo(
00256 /*=================*/
00257   trx_t*    trx,  
00258   ulint   type);  
00259 /******************************************************************/
00262 UNIV_INTERN
00263 page_t*
00264 trx_undo_set_state_at_finish(
00265 /*=========================*/
00266   trx_undo_t* undo, 
00267   mtr_t*    mtr); 
00268 /******************************************************************/
00271 UNIV_INTERN
00272 page_t*
00273 trx_undo_set_state_at_prepare(
00274 /*==========================*/
00275   trx_t*    trx,  
00276   trx_undo_t* undo, 
00277   mtr_t*    mtr); 
00279 /**********************************************************************/
00283 UNIV_INTERN
00284 void
00285 trx_undo_update_cleanup(
00286 /*====================*/
00287   trx_t*  trx,    
00288   page_t* undo_page,  
00290   mtr_t*  mtr);   
00291 /******************************************************************/
00295 UNIV_INTERN
00296 void
00297 trx_undo_insert_cleanup(
00298 /*====================*/
00299   trx_t*  trx); 
00300 #endif /* !UNIV_HOTBACKUP */
00301 /***********************************************************/
00304 UNIV_INTERN
00305 byte*
00306 trx_undo_parse_page_init(
00307 /*=====================*/
00308   byte* ptr,  
00309   byte* end_ptr,
00310   page_t* page, 
00311   mtr_t*  mtr); 
00312 /***********************************************************/
00315 UNIV_INTERN
00316 byte*
00317 trx_undo_parse_page_header(
00318 /*=======================*/
00319   ulint type, 
00320   byte* ptr,  
00321   byte* end_ptr,
00322   page_t* page, 
00323   mtr_t*  mtr); 
00324 /***********************************************************/
00327 UNIV_INTERN
00328 byte*
00329 trx_undo_parse_discard_latest(
00330 /*==========================*/
00331   byte* ptr,  
00332   byte* end_ptr,
00333   page_t* page, 
00334   mtr_t*  mtr); 
00335 /************************************************************************
00336 Frees an undo log memory copy. */
00337 UNIV_INTERN
00338 void
00339 trx_undo_mem_free(
00340 /*==============*/
00341   trx_undo_t* undo);    /* in: the undo object to be freed */
00342 
00343 /* Types of an undo log segment */
00344 #define TRX_UNDO_INSERT   1 /* contains undo entries for inserts */
00345 #define TRX_UNDO_UPDATE   2 /* contains undo entries for updates
00346           and delete markings: in short,
00347           modifys (the name 'UPDATE' is a
00348           historical relic) */
00349 /* States of an undo log segment */
00350 #define TRX_UNDO_ACTIVE   1 /* contains an undo log of an active
00351           transaction */
00352 #define TRX_UNDO_CACHED   2 /* cached for quick reuse */
00353 #define TRX_UNDO_TO_FREE  3 /* insert undo segment can be freed */
00354 #define TRX_UNDO_TO_PURGE 4 /* update undo segment will not be
00355           reused: it can be freed in purge when
00356           all undo data in it is removed */
00357 #define TRX_UNDO_PREPARED 5 /* contains an undo log of an
00358           prepared transaction */
00359 
00360 #ifndef UNIV_HOTBACKUP
00361 
00364 struct trx_undo_struct{
00365   /*-----------------------------*/
00366   ulint   id;   
00368   ulint   type;   
00370   ulint   state;    
00372   ibool   del_marks;  
00380   trx_id_t  trx_id;   
00382   XID   xid;    
00384   ibool   dict_operation; 
00385   table_id_t  table_id; 
00387   trx_rseg_t* rseg;   
00388   /*-----------------------------*/
00389   ulint   space;    
00391   ulint   zip_size; 
00393   ulint   hdr_page_no;  
00395   ulint   hdr_offset; 
00397   ulint   last_page_no; 
00400   ulint   size;   
00401   /*-----------------------------*/
00402   ulint   empty;    
00404   ulint   top_page_no;  
00408   ulint   top_offset; 
00411   undo_no_t top_undo_no;  
00412   buf_block_t*  guess_block;  
00414   /*-----------------------------*/
00415   UT_LIST_NODE_T(trx_undo_t) undo_list;
00418 };
00419 #endif /* !UNIV_HOTBACKUP */
00420 
00422 #define TRX_UNDO_PAGE_HDR FSEG_PAGE_DATA
00423 /*-------------------------------------------------------------*/
00425 /* @{ */
00426 #define TRX_UNDO_PAGE_TYPE  0 
00428 #define TRX_UNDO_PAGE_START 2 
00433 #define TRX_UNDO_PAGE_FREE  4 
00436 #define TRX_UNDO_PAGE_NODE  6 
00438 /*-------------------------------------------------------------*/
00439 #define TRX_UNDO_PAGE_HDR_SIZE  (6 + FLST_NODE_SIZE)
00440 
00442 /* @} */
00443 
00448 #define TRX_UNDO_PAGE_REUSE_LIMIT (3 * UNIV_PAGE_SIZE / 4)
00449 
00450 /* An update undo log segment may contain several undo logs on its first page
00451 if the undo logs took so little space that the segment could be cached and
00452 reused. All the undo log headers are then on the first page, and the last one
00453 owns the undo log records on subsequent pages if the segment is bigger than
00454 one page. If an undo log is stored in a segment, then on the first page it is
00455 allowed to have zero undo records, but if the segment extends to several
00456 pages, then all the rest of the pages must contain at least one undo log
00457 record. */
00458 
00462 #define TRX_UNDO_SEG_HDR  (TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE)
00463 
00464 /* @{ */
00465 /*-------------------------------------------------------------*/
00466 #define TRX_UNDO_STATE    0 
00467 #define TRX_UNDO_LAST_LOG 2 
00470 #define TRX_UNDO_FSEG_HEADER  4 
00472 #define TRX_UNDO_PAGE_LIST  (4 + FSEG_HEADER_SIZE)
00473 
00476 /*-------------------------------------------------------------*/
00478 #define TRX_UNDO_SEG_HDR_SIZE (4 + FSEG_HEADER_SIZE + FLST_BASE_NODE_SIZE)
00479 /* @} */
00480 
00481 
00484 /* @{ */
00485 /*-------------------------------------------------------------*/
00486 #define TRX_UNDO_TRX_ID   0 
00487 #define TRX_UNDO_TRX_NO   8 
00490 #define TRX_UNDO_DEL_MARKS  16  
00494 #define TRX_UNDO_LOG_START  18  
00500 #define TRX_UNDO_XID_EXISTS 20  
00503 #define TRX_UNDO_DICT_TRANS 21  
00510 #define TRX_UNDO_TABLE_ID 22  
00512 #define TRX_UNDO_NEXT_LOG 30  
00514 #define TRX_UNDO_PREV_LOG 32  
00516 #define TRX_UNDO_HISTORY_NODE 34  
00518 /*-------------------------------------------------------------*/
00519 
00520 #define TRX_UNDO_LOG_OLD_HDR_SIZE (34 + FLST_NODE_SIZE)
00521 
00522 /* Note: the writing of the undo log old header is coded by a log record
00523 MLOG_UNDO_HDR_CREATE or MLOG_UNDO_HDR_REUSE. The appending of an XID to the
00524 header is logged separately. In this sense, the XID is not really a member
00525 of the undo log header. TODO: do not append the XID to the log header if XA
00526 is not needed by the user. The XID wastes about 150 bytes of space in every
00527 undo log. In the history list we may have millions of undo logs, which means
00528 quite a large overhead. */
00529 
00531 /* @{ */
00533 #define TRX_UNDO_XA_FORMAT  (TRX_UNDO_LOG_OLD_HDR_SIZE)
00534 
00535 #define TRX_UNDO_XA_TRID_LEN  (TRX_UNDO_XA_FORMAT + 4)
00536 
00537 #define TRX_UNDO_XA_BQUAL_LEN (TRX_UNDO_XA_TRID_LEN + 4)
00538 
00539 #define TRX_UNDO_XA_XID   (TRX_UNDO_XA_BQUAL_LEN + 4)
00540 /*--------------------------------------------------------------*/
00541 #define TRX_UNDO_LOG_XA_HDR_SIZE (TRX_UNDO_XA_XID + XIDDATASIZE)
00542 
00544 /* @} */
00545 
00546 #ifndef UNIV_NONINL
00547 #include "trx0undo.ic"
00548 #endif
00549 
00550 #endif