Drizzled Public API Documentation

trx0sys.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003 Copyright (C) 1996, 2010, 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 trx0sys_h
00028 #define trx0sys_h
00029 
00030 #include "univ.i"
00031 
00032 #include "trx0types.h"
00033 #include "fsp0types.h"
00034 #include "fil0fil.h"
00035 #include "buf0buf.h"
00036 #ifndef UNIV_HOTBACKUP
00037 #include "mtr0mtr.h"
00038 #include "ut0byte.h"
00039 #include "mem0mem.h"
00040 #include "sync0sync.h"
00041 #include "ut0lst.h"
00042 #include "read0types.h"
00043 #include "page0types.h"
00044 
00045 #include <drizzled/atomics.h>
00046 
00048 extern drizzled::atomic<uint64_t> trx_sys_commit_id; 
00049 
00051 extern trx_sys_t* trx_sys;
00052 
00054 extern trx_doublewrite_t* trx_doublewrite;
00057 extern ibool      trx_doublewrite_must_reset_space_ids;
00059 extern ibool      trx_doublewrite_buf_is_being_created;
00063 extern ibool      trx_sys_multiple_tablespace_format;
00064 
00065 /****************************************************************/
00068 UNIV_INTERN
00069 void
00070 trx_sys_create_doublewrite_buf(void);
00071 /*================================*/
00072 /****************************************************************/
00079 UNIV_INTERN
00080 void
00081 trx_sys_doublewrite_init_or_restore_pages(
00082 /*======================================*/
00083   ibool restore_corrupt_pages); 
00084 /****************************************************************/
00087 UNIV_INTERN
00088 void
00089 trx_sys_mark_upgraded_to_multiple_tablespaces(void);
00090 /*===============================================*/
00091 /****************************************************************/
00095 UNIV_INTERN
00096 ibool
00097 trx_doublewrite_page_inside(
00098 /*========================*/
00099   ulint page_no); 
00100 /***************************************************************/
00103 UNIV_INLINE
00104 ibool
00105 trx_sys_hdr_page(
00106 /*=============*/
00107   ulint space,  
00108   ulint page_no);
00109 /*****************************************************************/
00112 UNIV_INTERN
00113 void
00114 trx_sys_init_at_db_start(void);
00115 /*==========================*/
00116 /*****************************************************************/
00118 UNIV_INTERN
00119 void
00120 trx_sys_create(void);
00121 /*================*/
00122 /****************************************************************/
00125 UNIV_INTERN
00126 ulint
00127 trx_sysf_rseg_find_free(
00128 /*====================*/
00129   mtr_t*    mtr);   
00130 /***************************************************************/
00133 UNIV_INLINE
00134 trx_rseg_t*
00135 trx_sys_get_nth_rseg(
00136 /*=================*/
00137   trx_sys_t*  sys,  
00138   ulint   n); 
00139 /***************************************************************/
00141 UNIV_INLINE
00142 void
00143 trx_sys_set_nth_rseg(
00144 /*=================*/
00145   trx_sys_t*  sys,  
00146   ulint   n,  
00147   trx_rseg_t* rseg);  
00149 /**********************************************************************/
00152 UNIV_INLINE
00153 trx_sysf_t*
00154 trx_sysf_get(
00155 /*=========*/
00156   mtr_t*  mtr); 
00157 /*****************************************************************/
00161 UNIV_INLINE
00162 ulint
00163 trx_sysf_rseg_get_space(
00164 /*====================*/
00165   trx_sysf_t* sys_header, 
00166   ulint   i,    
00167   mtr_t*    mtr);   
00168 /*****************************************************************/
00172 UNIV_INLINE
00173 ulint
00174 trx_sysf_rseg_get_page_no(
00175 /*======================*/
00176   trx_sysf_t* sys_header, 
00177   ulint   i,    
00178   mtr_t*    mtr);   
00179 /*****************************************************************/
00182 UNIV_INLINE
00183 void
00184 trx_sysf_rseg_set_space(
00185 /*====================*/
00186   trx_sysf_t* sys_header, 
00187   ulint   i,    
00188   ulint   space,    
00189   mtr_t*    mtr);   
00190 /*****************************************************************/
00193 UNIV_INLINE
00194 void
00195 trx_sysf_rseg_set_page_no(
00196 /*======================*/
00197   trx_sysf_t* sys_header, 
00198   ulint   i,    
00199   ulint   page_no,  
00201   mtr_t*    mtr);   
00202 /*****************************************************************/
00205 UNIV_INLINE
00206 trx_id_t
00207 trx_sys_get_new_trx_id(void);
00208 /*========================*/
00209 /*****************************************************************/
00212 UNIV_INLINE
00213 trx_id_t
00214 trx_sys_get_new_trx_no(void);
00215 /*========================*/
00216 #endif /* !UNIV_HOTBACKUP */
00217 /*****************************************************************/
00221 UNIV_INLINE
00222 void
00223 trx_write_trx_id(
00224 /*=============*/
00225   byte*   ptr,  
00226   trx_id_t  id);  
00227 #ifndef UNIV_HOTBACKUP
00228 /*****************************************************************/
00233 UNIV_INLINE
00234 trx_id_t
00235 trx_read_trx_id(
00236 /*============*/
00237   const byte* ptr); 
00238 /****************************************************************/
00241 UNIV_INLINE
00242 trx_t*
00243 trx_get_on_id(
00244 /*==========*/
00245   trx_id_t  trx_id);
00246 /****************************************************************/
00252 UNIV_INLINE
00253 trx_id_t
00254 trx_list_get_min_trx_id(void);
00255 /*=========================*/
00256 /****************************************************************/
00259 UNIV_INLINE
00260 ibool
00261 trx_is_active(
00262 /*==========*/
00263   trx_id_t  trx_id);
00264 /****************************************************************/
00267 UNIV_INTERN
00268 ibool
00269 trx_in_trx_list(
00270 /*============*/
00271   trx_t*  in_trx);
00272 /*****************************************************************/
00274 UNIV_INTERN
00275 void
00276 trx_sys_flush_commit_id(uint64_t commit_id, ulint field, mtr_t* mtr);
00277 /*****************************************************************/
00279 UNIV_INTERN
00280 void
00281 trx_sys_read_commit_id(void);
00282 /*****************************************************************/
00285 UNIV_INTERN
00286 void
00287 trx_sys_print_mysql_master_log_pos(void);
00288 /*====================================*/
00289 /*****************************************************************/
00291 UNIV_INTERN
00292 void
00293 trx_sys_file_format_init(void);
00294 /*==========================*/
00295 /*****************************************************************/
00297 UNIV_INTERN
00298 void
00299 trx_sys_file_format_close(void);
00300 /*===========================*/
00301 /********************************************************************/
00306 UNIV_INTERN
00307 void
00308 trx_sys_file_format_tag_init(void);
00309 /*==============================*/
00310 #ifndef UNIV_HOTBACKUP
00311 /*****************************************************************/
00313 UNIV_INTERN
00314 void
00315 trx_sys_close(void);
00316 /*===============*/
00317 #endif /* !UNIV_HOTBACKUP */
00318 /*****************************************************************/
00321 UNIV_INTERN
00322 const char*
00323 trx_sys_file_format_id_to_name(
00324 /*===========================*/
00325   const ulint id);    
00326 /*****************************************************************/
00330 UNIV_INTERN
00331 ibool
00332 trx_sys_file_format_max_set(
00333 /*========================*/
00334   ulint   format_id,  
00335   const char**  name);    
00337 /*****************************************************************/
00340 UNIV_INTERN
00341 const char*
00342 trx_sys_file_format_max_get(void);
00343 /*=============================*/
00344 /*****************************************************************/
00347 UNIV_INTERN
00348 ulint
00349 trx_sys_file_format_max_check(
00350 /*==========================*/
00351   ulint   max_format_id); 
00352 /********************************************************************/
00356 UNIV_INTERN
00357 ibool
00358 trx_sys_file_format_max_upgrade(
00359 /*============================*/
00360   const char**  name,   
00361   ulint   format_id); 
00362 #else /* !UNIV_HOTBACKUP */
00363 /*****************************************************************/
00369 UNIV_INTERN
00370 ibool
00371 trx_sys_read_file_format_id(
00372 /*========================*/
00373   const char *pathname, 
00375   ulint *format_id);  
00377 /*****************************************************************/
00380 UNIV_INTERN
00381 ibool
00382 trx_sys_read_pertable_file_format_id(
00383 /*=================================*/
00384   const char *pathname, 
00386   ulint *format_id);  
00388 /*****************************************************************/
00391 UNIV_INTERN
00392 const char*
00393 trx_sys_file_format_id_to_name(
00394 /*===========================*/
00395   const ulint id);  
00397 #endif /* !UNIV_HOTBACKUP */
00398 /*********************************************************************
00399 Creates the rollback segments */
00400 UNIV_INTERN
00401 void
00402 trx_sys_create_rsegs(
00403 /*=================*/
00404   ulint n_rsegs); 
00406 /* The automatically created system rollback segment has this id */
00407 #define TRX_SYS_SYSTEM_RSEG_ID  0
00408 
00409 /* Space id and page no where the trx system file copy resides */
00410 #define TRX_SYS_SPACE 0 /* the SYSTEM tablespace */
00411 #include "fsp0fsp.h"
00412 #define TRX_SYS_PAGE_NO FSP_TRX_SYS_PAGE_NO
00413 
00414 /* The offset of the transaction system header on the page */
00415 #define TRX_SYS   FSEG_PAGE_DATA
00416 
00418 /*------------------------------------------------------------- @{ */
00419 #define TRX_SYS_TRX_ID_STORE  0 
00431 #define TRX_SYS_FSEG_HEADER 8 
00434 #define TRX_SYS_RSEGS   (8 + FSEG_HEADER_SIZE)
00435 
00438 /*------------------------------------------------------------- @} */
00439 
00440 /* Max number of rollback segments: the number of segment specification slots
00441 in the transaction system array; rollback segment id must fit in one (signed)
00442 byte, therefore 128; each slot is currently 8 bytes in size. If you want
00443 to raise the level to 256 then you will need to fix some assertions that
00444 impose the 7 bit restriction. e.g., mach_write_to_3() */
00445 #define TRX_SYS_N_RSEGS     128
00446 /* Originally, InnoDB defined TRX_SYS_N_RSEGS as 256 but created only one
00447 rollback segment.  It initialized some arrays with this number of entries.
00448 We must remember this limit in order to keep file compatibility. */
00449 #define TRX_SYS_OLD_N_RSEGS   256
00450 
00454 #define TRX_SYS_MYSQL_LOG_NAME_LEN  512
00455 
00456 #define TRX_SYS_MYSQL_LOG_MAGIC_N 873422344
00457 
00458 #if UNIV_PAGE_SIZE < 4096
00459 # error "UNIV_PAGE_SIZE < 4096"
00460 #endif
00461 
00463 #define TRX_SYS_MYSQL_MASTER_LOG_INFO (UNIV_PAGE_SIZE - 2000)
00464 
00466 #define TRX_SYS_DRIZZLE_LOG_INFO  (UNIV_PAGE_SIZE - 1000)
00467 #define TRX_SYS_DRIZZLE_MAX_COMMIT_ID 8       
00469 #define TRX_SYS_DRIZZLE_LOG_NAME  12  
00472 /* @{ */
00473 
00474 #define TRX_SYS_DOUBLEWRITE   (UNIV_PAGE_SIZE - 200)
00475 /*-------------------------------------------------------------*/
00476 #define TRX_SYS_DOUBLEWRITE_FSEG  0 
00479 #define TRX_SYS_DOUBLEWRITE_MAGIC FSEG_HEADER_SIZE
00480 
00484 #define TRX_SYS_DOUBLEWRITE_BLOCK1  (4 + FSEG_HEADER_SIZE)
00485 
00491 #define TRX_SYS_DOUBLEWRITE_BLOCK2  (8 + FSEG_HEADER_SIZE)
00492 
00497 #define TRX_SYS_DOUBLEWRITE_REPEAT  12  
00510 #define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED (24 + FSEG_HEADER_SIZE)
00511 
00512 /*-------------------------------------------------------------*/
00514 #define TRX_SYS_DOUBLEWRITE_MAGIC_N 536853855
00515 
00516 #define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N 1783657386
00517 
00519 #define TRX_SYS_DOUBLEWRITE_BLOCK_SIZE  FSP_EXTENT_SIZE
00520 /* @} */
00521 
00522 #ifndef UNIV_HOTBACKUP
00523 
00524 /* @{ */
00527 #define TRX_SYS_FILE_FORMAT_TAG   (UNIV_PAGE_SIZE - 16)
00528 
00531 #define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW 3645922177UL
00532 
00533 #define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH  2745987765UL
00534 
00536 #define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N         \
00537   ((ib_uint64_t) TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH << 32 \
00538    | TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW)
00539 /* @} */
00540 
00542 struct trx_doublewrite_struct{
00543   mutex_t mutex;    
00545   ulint block1;   
00547   ulint block2;   
00548   ulint first_free; 
00550   byte* write_buf;  
00554   byte* write_buf_unaligned;
00556   buf_page_t**
00557     buf_block_arr;  
00559 };
00560 
00563 struct trx_sys_struct{
00564   trx_id_t  max_trx_id; 
00568   UT_LIST_BASE_NODE_T(trx_t) trx_list;
00572   UT_LIST_BASE_NODE_T(trx_t) mysql_trx_list;
00575   UT_LIST_BASE_NODE_T(trx_rseg_t) rseg_list;
00578   trx_rseg_t* latest_rseg;  
00581   trx_rseg_t* rseg_array[TRX_SYS_N_RSEGS];
00584   ulint   rseg_history_len;
00588   UT_LIST_BASE_NODE_T(read_view_t) view_list;
00591 };
00592 
00596 #define TRX_SYS_TRX_ID_WRITE_MARGIN 256
00597 #endif /* !UNIV_HOTBACKUP */
00598 
00599 #ifndef UNIV_NONINL
00600 #include "trx0sys.ic"
00601 #endif
00602 
00603 #endif