Drizzled Public API Documentation

buf0buf.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003 Copyright (C) 1995, 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 buf0buf_h
00028 #define buf0buf_h
00029 
00030 #include "univ.i"
00031 #include "fil0fil.h"
00032 #include "mtr0types.h"
00033 #include "buf0types.h"
00034 #include "hash0hash.h"
00035 #include "ut0byte.h"
00036 #include "page0types.h"
00037 #ifndef UNIV_HOTBACKUP
00038 #include "ut0rbt.h"
00039 #include "os0proc.h"
00040 
00042 /* @{ */
00043 #define BUF_GET     10  
00044 #define BUF_GET_IF_IN_POOL  11  
00045 #define BUF_GET_NO_LATCH  14  
00051 #define BUF_GET_IF_IN_POOL_OR_WATCH 15
00052 
00055 /* @} */
00057 /* @{ */
00058 #define BUF_MAKE_YOUNG  51    
00063 #define BUF_KEEP_OLD  52    
00065 /* @} */
00066 
00067 #define MAX_BUFFER_POOLS 64   
00070 #define BUF_POOL_WATCH_SIZE 1   
00073 extern  buf_pool_t* buf_pool_ptr; 
00075 #ifdef UNIV_DEBUG
00076 extern ibool    buf_debug_prints;
00079 #endif /* UNIV_DEBUG */
00080 #else /* !UNIV_HOTBACKUP */
00081 extern buf_block_t* back_block1;  
00082 extern buf_block_t* back_block2;  
00083 #endif /* !UNIV_HOTBACKUP */
00084 
00086 #define BUF_NO_CHECKSUM_MAGIC 0xDEADBEEFUL
00087 
00092 enum buf_page_state {
00093   BUF_BLOCK_ZIP_FREE = 0,   
00095   BUF_BLOCK_POOL_WATCH = 0, 
00097   BUF_BLOCK_ZIP_PAGE,   
00099   BUF_BLOCK_ZIP_DIRTY,    
00103   BUF_BLOCK_NOT_USED,   
00107   BUF_BLOCK_READY_FOR_USE,  
00109   BUF_BLOCK_FILE_PAGE,    
00110   BUF_BLOCK_MEMORY,   
00112   BUF_BLOCK_REMOVE_HASH   
00114 };
00115 
00116 #ifndef UNIV_HOTBACKUP
00117 /********************************************************************/
00119 UNIV_INLINE
00120 void
00121 buf_pool_mutex_enter_all(void);
00122 /*===========================*/
00123 
00124 /********************************************************************/
00126 UNIV_INLINE
00127 void
00128 buf_pool_mutex_exit_all(void);
00129 /*==========================*/
00130 
00131 /********************************************************************/
00134 UNIV_INTERN
00135 ulint
00136 buf_pool_init(
00137 /*=========*/
00138   ulint size,   
00139   ulint n_instances); 
00140 /********************************************************************/
00143 UNIV_INTERN
00144 void
00145 buf_pool_free(
00146 /*==========*/
00147   ulint n_instances); 
00149 /********************************************************************/
00153 UNIV_INTERN
00154 void
00155 buf_pool_drop_hash_index(void);
00156 /*==========================*/
00157 
00158 /********************************************************************/
00162 UNIV_INTERN
00163 void
00164 buf_relocate(
00165 /*=========*/
00166   buf_page_t* bpage,  
00169   buf_page_t* dpage)  
00170   __attribute__((nonnull));
00171 /********************************************************************/
00173 UNIV_INTERN
00174 void
00175 buf_pool_resize(void);
00176 /*=================*/
00177 /*********************************************************************/
00180 UNIV_INLINE
00181 ulint
00182 buf_pool_get_curr_size(void);
00183 /*========================*/
00184 /*********************************************************************/
00187 UNIV_INLINE
00188 ulint
00189 buf_pool_get_n_pages(void);
00190 /*=======================*/
00191 /********************************************************************/
00195 UNIV_INTERN
00196 ib_uint64_t
00197 buf_pool_get_oldest_modification(void);
00198 /*==================================*/
00199 /********************************************************************/
00202 UNIV_INTERN
00203 buf_block_t*
00204 buf_block_alloc(
00205 /*============*/
00206   buf_pool_t* buf_pool, 
00207   ulint   zip_size);  
00209 /********************************************************************/
00211 UNIV_INLINE
00212 void
00213 buf_block_free(
00214 /*===========*/
00215   buf_block_t*  block); 
00216 #endif /* !UNIV_HOTBACKUP */
00217 /*********************************************************************/
00220 UNIV_INLINE
00221 byte*
00222 buf_frame_copy(
00223 /*===========*/
00224   byte*     buf,  
00225   const buf_frame_t*  frame); 
00226 #ifndef UNIV_HOTBACKUP
00227 /**************************************************************/
00231 #define buf_page_get(SP, ZS, OF, LA, MTR)  buf_page_get_gen(\
00232         SP, ZS, OF, LA, NULL,\
00233         BUF_GET, __FILE__, __LINE__, MTR)
00234 /**************************************************************/
00240 #define buf_page_get_with_no_latch(SP, ZS, OF, MTR)    buf_page_get_gen(\
00241         SP, ZS, OF, RW_NO_LATCH, NULL,\
00242         BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
00243 /********************************************************************/
00247 UNIV_INTERN
00248 ibool
00249 buf_page_optimistic_get(
00250 /*====================*/
00251   ulint   rw_latch,
00252   buf_block_t*  block,  
00253   ib_uint64_t modify_clock,
00255   const char* file, 
00256   ulint   line, 
00257   mtr_t*    mtr); 
00258 /********************************************************************/
00262 UNIV_INTERN
00263 ibool
00264 buf_page_get_known_nowait(
00265 /*======================*/
00266   ulint   rw_latch,
00267   buf_block_t*  block,  
00268   ulint   mode, 
00269   const char* file, 
00270   ulint   line, 
00271   mtr_t*    mtr); 
00273 /*******************************************************************/
00277 UNIV_INTERN
00278 const buf_block_t*
00279 buf_page_try_get_func(
00280 /*==================*/
00281   ulint   space_id,
00282   ulint   page_no,
00283   const char* file, 
00284   ulint   line, 
00285   mtr_t*    mtr); 
00293 #define buf_page_try_get(space_id, page_no, mtr)  \
00294   buf_page_try_get_func(space_id, page_no, __FILE__, __LINE__, mtr);
00295 
00296 /********************************************************************/
00305 UNIV_INTERN
00306 buf_page_t*
00307 buf_page_get_zip(
00308 /*=============*/
00309   ulint   space,  
00310   ulint   zip_size,
00311   ulint   offset);
00312 /********************************************************************/
00315 UNIV_INTERN
00316 buf_block_t*
00317 buf_page_get_gen(
00318 /*=============*/
00319   ulint   space,  
00320   ulint   zip_size,
00322   ulint   offset, 
00323   ulint   rw_latch,
00324   buf_block_t*  guess,  
00325   ulint   mode, 
00328   const char* file, 
00329   ulint   line, 
00330   mtr_t*    mtr); 
00331 /********************************************************************/
00337 UNIV_INTERN
00338 buf_block_t*
00339 buf_page_create(
00340 /*============*/
00341   ulint space,  
00342   ulint offset, 
00344   ulint zip_size,
00345   mtr_t*  mtr); 
00346 #else /* !UNIV_HOTBACKUP */
00347 /********************************************************************/
00349 UNIV_INTERN
00350 void
00351 buf_page_init_for_backup_restore(
00352 /*=============================*/
00353   ulint   space,  
00354   ulint   offset, 
00356   ulint   zip_size,
00358   buf_block_t*  block); 
00359 #endif /* !UNIV_HOTBACKUP */
00360 
00361 #ifndef UNIV_HOTBACKUP
00362 /********************************************************************/
00364 UNIV_INLINE
00365 void
00366 buf_page_release_zip(
00367 /*=================*/
00368   buf_page_t* bpage);   
00369 /********************************************************************/
00372 UNIV_INLINE
00373 void
00374 buf_page_release(
00375 /*=============*/
00376   buf_block_t*  block,    
00377   ulint   rw_latch);  
00379 /********************************************************************/
00383 UNIV_INTERN
00384 void
00385 buf_page_make_young(
00386 /*================*/
00387   buf_page_t* bpage); 
00388 /********************************************************************/
00395 UNIV_INLINE
00396 ibool
00397 buf_page_peek(
00398 /*==========*/
00399   ulint space,  
00400   ulint offset);
00401 /********************************************************************/
00404 UNIV_INTERN
00405 void
00406 buf_reset_check_index_page_at_flush(
00407 /*================================*/
00408   ulint space,  
00409   ulint offset);
00410 #ifdef UNIV_DEBUG_FILE_ACCESSES
00411 /********************************************************************/
00417 UNIV_INTERN
00418 buf_page_t*
00419 buf_page_set_file_page_was_freed(
00420 /*=============================*/
00421   ulint space,  
00422   ulint offset);
00423 /********************************************************************/
00429 UNIV_INTERN
00430 buf_page_t*
00431 buf_page_reset_file_page_was_freed(
00432 /*===============================*/
00433   ulint space,  
00434   ulint offset);  
00435 #endif /* UNIV_DEBUG_FILE_ACCESSES */
00436 /********************************************************************/
00439 UNIV_INLINE
00440 ulint
00441 buf_page_get_freed_page_clock(
00442 /*==========================*/
00443   const buf_page_t* bpage)  
00444   __attribute__((pure));
00445 /********************************************************************/
00448 UNIV_INLINE
00449 ulint
00450 buf_block_get_freed_page_clock(
00451 /*===========================*/
00452   const buf_block_t*  block)  
00453   __attribute__((pure));
00454 
00455 /********************************************************************/
00460 UNIV_INLINE
00461 ibool
00462 buf_page_peek_if_too_old(
00463 /*=====================*/
00464   const buf_page_t* bpage); 
00465 /********************************************************************/
00470 UNIV_INTERN
00471 ibool
00472 buf_page_peek_if_search_hashed(
00473 /*===========================*/
00474   ulint space,  
00475   ulint offset);
00476 /********************************************************************/
00480 UNIV_INLINE
00481 ib_uint64_t
00482 buf_page_get_newest_modification(
00483 /*=============================*/
00484   const buf_page_t* bpage); 
00486 /********************************************************************/
00490 UNIV_INLINE
00491 void
00492 buf_block_modify_clock_inc(
00493 /*=======================*/
00494   buf_block_t*  block); 
00495 /********************************************************************/
00499 UNIV_INLINE
00500 ib_uint64_t
00501 buf_block_get_modify_clock(
00502 /*=======================*/
00503   buf_block_t*  block); 
00504 #else /* !UNIV_HOTBACKUP */
00505 # define buf_block_modify_clock_inc(block) ((void) 0)
00506 #endif /* !UNIV_HOTBACKUP */
00507 /********************************************************************/
00512 UNIV_INTERN
00513 ulint
00514 buf_calc_page_new_checksum(
00515 /*=======================*/
00516   const byte* page);  
00517 /********************************************************************/
00525 UNIV_INTERN
00526 ulint
00527 buf_calc_page_old_checksum(
00528 /*=======================*/
00529   const byte*  page); 
00530 /********************************************************************/
00533 UNIV_INTERN
00534 ibool
00535 buf_page_is_corrupted(
00536 /*==================*/
00537   const byte* read_buf, 
00538   ulint   zip_size);  
00540 #ifndef UNIV_HOTBACKUP
00541 /**********************************************************************/
00544 UNIV_INLINE
00545 void
00546 buf_ptr_get_fsp_addr(
00547 /*=================*/
00548   const void* ptr,  
00549   ulint*    space,  
00550   fil_addr_t* addr);  
00551 /**********************************************************************/
00555 UNIV_INLINE
00556 ulint
00557 buf_block_get_lock_hash_val(
00558 /*========================*/
00559   const buf_block_t*  block)  
00560   __attribute__((pure));
00561 #ifdef UNIV_DEBUG
00562 /*********************************************************************/
00566 UNIV_INTERN
00567 buf_block_t*
00568 buf_pool_contains_zip(
00569 /*==================*/
00570   buf_pool_t* buf_pool, 
00571   const void* data);    
00572 #endif /* UNIV_DEBUG */
00573 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
00574 /*********************************************************************/
00577 UNIV_INTERN
00578 ibool
00579 buf_validate(void);
00580 /*==============*/
00581 #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
00582 #if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
00583 /*********************************************************************/
00585 UNIV_INTERN
00586 void
00587 buf_print(void);
00588 /*============*/
00589 #endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
00590 #endif /* !UNIV_HOTBACKUP */
00591 /********************************************************************/
00593 UNIV_INTERN
00594 void
00595 buf_page_print(
00596 /*===========*/
00597   const byte* read_buf, 
00598   ulint   zip_size);  
00600 /********************************************************************/
00603 UNIV_INTERN
00604 ibool
00605 buf_zip_decompress(
00606 /*===============*/
00607   buf_block_t*  block,  
00608   ibool   check); 
00609 #ifndef UNIV_HOTBACKUP
00610 #ifdef UNIV_DEBUG
00611 /*********************************************************************/
00614 UNIV_INTERN
00615 ulint
00616 buf_get_latched_pages_number(void);
00617 /*==============================*/
00618 #endif /* UNIV_DEBUG */
00619 /*********************************************************************/
00622 UNIV_INTERN
00623 ulint
00624 buf_get_n_pending_ios(void);
00625 /*=======================*/
00626 /*********************************************************************/
00628 UNIV_INTERN
00629 void
00630 buf_print_io(
00631 /*=========*/
00632   FILE* file);  
00633 /*********************************************************************/
00637 UNIV_INTERN
00638 ulint
00639 buf_get_modified_ratio_pct(void);
00640 /*============================*/
00641 /**********************************************************************/
00643 UNIV_INTERN
00644 void
00645 buf_refresh_io_stats(
00646 /*=================*/
00647   buf_pool_t* buf_pool);  
00648 /**********************************************************************/
00650 UNIV_INTERN
00651 void
00652 buf_refresh_io_stats_all(void);
00653 /*=================*/
00654 /*********************************************************************/
00657 UNIV_INTERN
00658 ibool
00659 buf_all_freed(void);
00660 /*===============*/
00661 /*********************************************************************/
00665 UNIV_INTERN
00666 ibool
00667 buf_pool_check_no_pending_io(void);
00668 /*==============================*/
00669 /*********************************************************************/
00673 UNIV_INTERN
00674 void
00675 buf_pool_invalidate(void);
00676 /*=====================*/
00677 #endif /* !UNIV_HOTBACKUP */
00678 
00679 /*========================================================================
00680 --------------------------- LOWER LEVEL ROUTINES -------------------------
00681 =========================================================================*/
00682 
00683 #ifdef UNIV_SYNC_DEBUG
00684 /*********************************************************************/
00688 UNIV_INLINE
00689 void
00690 buf_block_dbg_add_level(
00691 /*====================*/
00692   buf_block_t*  block,  
00694   ulint   level); 
00695 #else /* UNIV_SYNC_DEBUG */
00696 # define buf_block_dbg_add_level(block, level) /* nothing */
00697 #endif /* UNIV_SYNC_DEBUG */
00698 /*********************************************************************/
00701 UNIV_INLINE
00702 enum buf_page_state
00703 buf_page_get_state(
00704 /*===============*/
00705   const buf_page_t* bpage); 
00706 /*********************************************************************/
00709 UNIV_INLINE
00710 enum buf_page_state
00711 buf_block_get_state(
00712 /*================*/
00713   const buf_block_t*  block)  
00714   __attribute__((pure));
00715 /*********************************************************************/
00717 UNIV_INLINE
00718 void
00719 buf_page_set_state(
00720 /*===============*/
00721   buf_page_t*   bpage,  
00722   enum buf_page_state state); 
00723 /*********************************************************************/
00725 UNIV_INLINE
00726 void
00727 buf_block_set_state(
00728 /*================*/
00729   buf_block_t*    block,  
00730   enum buf_page_state state); 
00731 /*********************************************************************/
00734 UNIV_INLINE
00735 ibool
00736 buf_page_in_file(
00737 /*=============*/
00738   const buf_page_t* bpage)  
00739   __attribute__((pure));
00740 #ifndef UNIV_HOTBACKUP
00741 /*********************************************************************/
00744 UNIV_INLINE
00745 ibool
00746 buf_page_belongs_to_unzip_LRU(
00747 /*==========================*/
00748   const buf_page_t* bpage)  
00749   __attribute__((pure));
00750 
00751 /*********************************************************************/
00754 UNIV_INLINE
00755 mutex_t*
00756 buf_page_get_mutex(
00757 /*===============*/
00758   const buf_page_t* bpage)  
00759   __attribute__((pure));
00760 
00761 /*********************************************************************/
00764 UNIV_INLINE
00765 enum buf_flush
00766 buf_page_get_flush_type(
00767 /*====================*/
00768   const buf_page_t* bpage)  
00769   __attribute__((pure));
00770 /*********************************************************************/
00772 UNIV_INLINE
00773 void
00774 buf_page_set_flush_type(
00775 /*====================*/
00776   buf_page_t* bpage,    
00777   enum buf_flush  flush_type);  
00778 /*********************************************************************/
00780 UNIV_INLINE
00781 void
00782 buf_block_set_file_page(
00783 /*====================*/
00784   buf_block_t*    block,  
00785   ulint     space,  
00786   ulint     page_no);
00787 /*********************************************************************/
00790 UNIV_INLINE
00791 enum buf_io_fix
00792 buf_page_get_io_fix(
00793 /*================*/
00794   const buf_page_t* bpage)  
00795   __attribute__((pure));
00796 /*********************************************************************/
00799 UNIV_INLINE
00800 enum buf_io_fix
00801 buf_block_get_io_fix(
00802 /*================*/
00803   const buf_block_t*  block)  
00804   __attribute__((pure));
00805 /*********************************************************************/
00807 UNIV_INLINE
00808 void
00809 buf_page_set_io_fix(
00810 /*================*/
00811   buf_page_t* bpage,  
00812   enum buf_io_fix io_fix);
00813 /*********************************************************************/
00815 UNIV_INLINE
00816 void
00817 buf_block_set_io_fix(
00818 /*=================*/
00819   buf_block_t*  block,  
00820   enum buf_io_fix io_fix);
00822 /********************************************************************/
00825 UNIV_INLINE
00826 ibool
00827 buf_page_can_relocate(
00828 /*==================*/
00829   const buf_page_t* bpage)  
00830   __attribute__((pure));
00831 
00832 /*********************************************************************/
00835 UNIV_INLINE
00836 ibool
00837 buf_page_is_old(
00838 /*============*/
00839   const buf_page_t* bpage)  
00840   __attribute__((pure));
00841 /*********************************************************************/
00843 UNIV_INLINE
00844 void
00845 buf_page_set_old(
00846 /*=============*/
00847   buf_page_t* bpage,  
00848   ibool   old); 
00849 /*********************************************************************/
00852 UNIV_INLINE
00853 unsigned
00854 buf_page_is_accessed(
00855 /*=================*/
00856   const buf_page_t* bpage)  
00857   __attribute__((nonnull, pure));
00858 /*********************************************************************/
00860 UNIV_INLINE
00861 void
00862 buf_page_set_accessed(
00863 /*==================*/
00864   buf_page_t* bpage,    
00865   ulint   time_ms)  
00866   __attribute__((nonnull));
00867 /*********************************************************************/
00872 UNIV_INLINE
00873 buf_block_t*
00874 buf_page_get_block(
00875 /*===============*/
00876   buf_page_t* bpage)  
00877   __attribute__((pure));
00878 #endif /* !UNIV_HOTBACKUP */
00879 #ifdef UNIV_DEBUG
00880 /*********************************************************************/
00883 UNIV_INLINE
00884 buf_frame_t*
00885 buf_block_get_frame(
00886 /*================*/
00887   const buf_block_t*  block)  
00888   __attribute__((pure));
00889 #else /* UNIV_DEBUG */
00890 # define buf_block_get_frame(block) (block)->frame
00891 #endif /* UNIV_DEBUG */
00892 /*********************************************************************/
00895 UNIV_INLINE
00896 ulint
00897 buf_page_get_space(
00898 /*===============*/
00899   const buf_page_t* bpage)  
00900   __attribute__((pure));
00901 /*********************************************************************/
00904 UNIV_INLINE
00905 ulint
00906 buf_block_get_space(
00907 /*================*/
00908   const buf_block_t*  block)  
00909   __attribute__((pure));
00910 /*********************************************************************/
00913 UNIV_INLINE
00914 ulint
00915 buf_page_get_page_no(
00916 /*=================*/
00917   const buf_page_t* bpage)  
00918   __attribute__((pure));
00919 /*********************************************************************/
00922 UNIV_INLINE
00923 ulint
00924 buf_block_get_page_no(
00925 /*==================*/
00926   const buf_block_t*  block)  
00927   __attribute__((pure));
00928 /*********************************************************************/
00931 UNIV_INLINE
00932 ulint
00933 buf_page_get_zip_size(
00934 /*==================*/
00935   const buf_page_t* bpage)  
00936   __attribute__((pure));
00937 /*********************************************************************/
00940 UNIV_INLINE
00941 ulint
00942 buf_block_get_zip_size(
00943 /*===================*/
00944   const buf_block_t*  block)  
00945   __attribute__((pure));
00946 /*********************************************************************/
00949 #define buf_block_get_page_zip(block) \
00950   (UNIV_LIKELY_NULL((block)->page.zip.data) ? &(block)->page.zip : NULL)
00951 #ifndef UNIV_HOTBACKUP
00952 /*******************************************************************/
00955 UNIV_INTERN
00956 buf_block_t*
00957 buf_block_align(
00958 /*============*/
00959   const byte* ptr); 
00960 /********************************************************************/
00964 UNIV_INTERN
00965 ibool
00966 buf_pointer_is_block_field(
00967 /*=======================*/
00968   const void*   ptr); 
00973 #define buf_pool_is_block_mutex(m)      \
00974   buf_pointer_is_block_field((const void*)(m))
00975 
00978 #define buf_pool_is_block_lock(l)     \
00979   buf_pointer_is_block_field((const void*)(l))
00980 
00981 #if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
00982 /*********************************************************************/
00986 UNIV_INLINE
00987 const page_zip_des_t*
00988 buf_frame_get_page_zip(
00989 /*===================*/
00990   const byte* ptr); 
00991 #endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
00992 /********************************************************************/
01002 UNIV_INTERN
01003 buf_page_t*
01004 buf_page_init_for_read(
01005 /*===================*/
01006   ulint*    err,  
01007   ulint   mode, 
01008   ulint   space,  
01009   ulint   zip_size,
01010   ibool   unzip,  
01011   ib_int64_t  tablespace_version,
01014   ulint   offset);
01015 /********************************************************************/
01018 UNIV_INTERN
01019 void
01020 buf_page_io_complete(
01021 /*=================*/
01022   buf_page_t* bpage); 
01023 /********************************************************************/
01027 UNIV_INLINE
01028 ulint
01029 buf_page_address_fold(
01030 /*==================*/
01031   ulint space,  
01032   ulint offset) 
01033   __attribute__((const));
01034 /********************************************************************/
01037 UNIV_INLINE
01038 ulint
01039 buf_pool_index(
01040 /*===========*/
01041   const buf_pool_t* buf_pool) 
01042   __attribute__((nonnull, const));
01043 /******************************************************************/
01046 UNIV_INLINE
01047 buf_pool_t*
01048 buf_pool_from_bpage(
01049 /*================*/
01050   const buf_page_t* bpage); 
01051 /******************************************************************/
01054 UNIV_INLINE
01055 buf_pool_t*
01056 buf_pool_from_block(
01057 /*================*/
01058   const buf_block_t*  block); 
01059 /******************************************************************/
01062 UNIV_INLINE
01063 buf_pool_t*
01064 buf_pool_get(
01065 /*==========*/
01066   ulint space,  
01067   ulint offset);
01068 /******************************************************************/
01071 UNIV_INLINE
01072 buf_pool_t*
01073 buf_pool_from_array(
01074 /*================*/
01075   ulint index);   
01077 /******************************************************************/
01080 UNIV_INLINE
01081 buf_page_t*
01082 buf_page_hash_get_low(
01083 /*==================*/
01084   buf_pool_t* buf_pool, 
01085   ulint   space,    
01086   ulint   offset,   
01088   ulint   fold);    
01090 /******************************************************************/
01093 UNIV_INLINE
01094 buf_page_t*
01095 buf_page_hash_get(
01096 /*==============*/
01097   buf_pool_t* buf_pool, 
01098   ulint   space,    
01099   ulint   offset);  
01101 /******************************************************************/
01105 UNIV_INLINE
01106 buf_block_t*
01107 buf_block_hash_get(
01108 /*===============*/
01109   buf_pool_t* buf_pool, 
01110   ulint   space,    
01111   ulint   offset);  
01113 /*********************************************************************/
01116 UNIV_INTERN
01117 ulint
01118 buf_get_free_list_len(void);
01119 /*=======================*/
01120 
01121 /********************************************************************
01122 Determine if a block is a sentinel for a buffer pool watch.
01123 @return TRUE if a sentinel for a buffer pool watch, FALSE if not */
01124 UNIV_INTERN
01125 ibool
01126 buf_pool_watch_is_sentinel(
01127 /*=======================*/
01128   buf_pool_t*   buf_pool, 
01129   const buf_page_t* bpage)    
01130   UNIV_WARN_UNUSED_RESULT;
01131 /****************************************************************/
01134 UNIV_INTERN
01135 buf_page_t*
01136 buf_pool_watch_set(
01137 /*===============*/
01138   ulint space,  
01139   ulint offset, 
01140   ulint fold) 
01141   UNIV_WARN_UNUSED_RESULT;
01142 /****************************************************************/
01145 UNIV_INTERN
01146 void
01147 buf_pool_watch_unset(
01148 /*=================*/
01149   ulint space,  
01150   ulint offset);
01151 /****************************************************************/
01156 UNIV_INTERN
01157 ibool
01158 buf_pool_watch_occurred(
01159 /*====================*/
01160   ulint space,  
01161   ulint offset) 
01162   UNIV_WARN_UNUSED_RESULT;
01163 /********************************************************************/
01165 UNIV_INTERN
01166 void
01167 buf_get_total_list_len(
01168 /*===================*/
01169   ulint*    LRU_len,  
01170   ulint*    free_len, 
01171   ulint*    flush_list_len);
01172 /********************************************************************/
01174 UNIV_INTERN
01175 void
01176 buf_get_total_stat(
01177 /*===============*/
01178   buf_pool_stat_t*tot_stat);  
01180 #endif /* !UNIV_HOTBACKUP */
01181 
01185 struct buf_page_struct{
01192   /* @{ */
01193 
01194   unsigned  space:32; 
01196   unsigned  offset:32;  
01199   unsigned  state:3;  
01206 #ifndef UNIV_HOTBACKUP
01207   unsigned  flush_type:2; 
01211   unsigned  io_fix:2; 
01214   unsigned  buf_fix_count:19;
01216   unsigned  buf_pool_index:6;
01218 # if MAX_BUFFER_POOLS > 64
01219 #  error "MAX_BUFFER_POOLS > 64; redefine buf_pool_index:6"
01220 # endif
01221   /* @} */
01222 #endif /* !UNIV_HOTBACKUP */
01223   page_zip_des_t  zip;    
01229 #ifndef UNIV_HOTBACKUP
01230   buf_page_t* hash;   
01233 #ifdef UNIV_DEBUG
01234   ibool   in_page_hash; 
01235   ibool   in_zip_hash;  
01236 #endif /* UNIV_DEBUG */
01237 
01240   /* @{ */
01241 
01242   UT_LIST_NODE_T(buf_page_t) list;
01270 #ifdef UNIV_DEBUG
01271   ibool   in_flush_list;  
01282   ibool   in_free_list; 
01286 #endif /* UNIV_DEBUG */
01287   ib_uint64_t newest_modification;
01293   ib_uint64_t oldest_modification;
01306   /* @} */
01310   /* @{ */
01311 
01312   UT_LIST_NODE_T(buf_page_t) LRU;
01314 #ifdef UNIV_DEBUG
01315   ibool   in_LRU_list;  
01318 #endif /* UNIV_DEBUG */
01319   unsigned  old:1;    
01321   unsigned  freed_page_clock:31;
01329   unsigned  access_time:32; 
01332   /* @} */
01333 # ifdef UNIV_DEBUG_FILE_ACCESSES
01334   ibool   file_page_was_freed;
01337 # endif /* UNIV_DEBUG_FILE_ACCESSES */
01338 #endif /* !UNIV_HOTBACKUP */
01339 };
01340 
01343 struct buf_block_struct{
01344 
01346   /* @{ */
01347 
01348   buf_page_t  page;   
01352   byte*   frame;    
01356 #ifndef UNIV_HOTBACKUP
01357   UT_LIST_NODE_T(buf_block_t) unzip_LRU;
01362 #ifdef UNIV_DEBUG
01363   ibool   in_unzip_LRU_list;
01366 #endif /* UNIV_DEBUG */
01367   mutex_t   mutex;    
01373   rw_lock_t lock;   
01375   unsigned  lock_hash_val:32;
01382   ibool   check_index_page_at_flush;
01391   /* @} */
01393   /* @{ */
01394 
01395   ib_uint64_t modify_clock; 
01406   /* @} */
01409   /* @{ */
01410 
01411   ulint   n_hash_helps; 
01413   ulint   n_fields; 
01415   ulint   n_bytes;  
01417   ibool   left_side;  
01421   /* @} */
01422 
01432   /* @{ */
01433 
01434 #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
01435   ulint   n_pointers; 
01438 #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
01439   unsigned  is_hashed:1;  
01446   unsigned  curr_n_fields:10;
01448   unsigned  curr_n_bytes:15;
01450   unsigned  curr_left_side:1;
01451   dict_index_t* index;    
01453   /* @} */
01454 # ifdef UNIV_SYNC_DEBUG
01455 
01456   /* @{ */
01457   rw_lock_t debug_latch;  
01461   /* @} */
01462 # endif
01463 #endif /* !UNIV_HOTBACKUP */
01464 };
01465 
01469 #define buf_block_state_valid(block)        \
01470 (buf_block_get_state(block) >= BUF_BLOCK_NOT_USED   \
01471  && (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
01472 
01473 #ifndef UNIV_HOTBACKUP
01474 /**********************************************************************/
01476 /* @{ */
01477 #define BUF_POOL_ZIP_FOLD_PTR(ptr) ((ulint) (ptr) / UNIV_PAGE_SIZE)
01478 #define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
01479 #define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
01480 /* @} */
01481 
01483 struct buf_pool_stat_struct{
01484   ulint n_page_gets;  
01490   ulint n_pages_read; 
01491   ulint n_pages_written;
01492   ulint n_pages_created;
01494   ulint n_ra_pages_read;
01496   ulint n_ra_pages_evicted;
01499   ulint n_pages_made_young; 
01501   ulint n_pages_not_made_young; 
01505 };
01506 
01508 struct buf_buddy_stat_struct {
01510   ulint   used;
01512   ib_uint64_t relocated;
01514   ib_uint64_t relocated_usec;
01515 };
01516 
01522 struct buf_pool_struct{
01523 
01525   /* @{ */
01526   mutex_t   mutex;    
01528   mutex_t   zip_mutex;  
01532   ulint   instance_no;  
01534   ulint   old_pool_size;  
01535   ulint   curr_pool_size; 
01536   ulint   LRU_old_ratio;  
01538 #ifdef UNIV_DEBUG
01539   ulint   buddy_n_frames; 
01541 #endif
01542 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
01543   ulint   mutex_exit_forbidden; 
01544 #endif
01545   ulint   n_chunks; 
01546   buf_chunk_t*  chunks;   
01547   ulint   curr_size;  
01548   hash_table_t* page_hash;  
01552   hash_table_t* zip_hash; 
01556   ulint   n_pend_reads; 
01558   ulint   n_pend_unzip; 
01560   time_t    last_printout_time;
01563   buf_buddy_stat_t buddy_stat[BUF_BUDDY_SIZES + 1];
01566   buf_pool_stat_t stat;   
01567   buf_pool_stat_t old_stat; 
01569   /* @} */
01570 
01573   /* @{ */
01574 
01575   mutex_t   flush_list_mutex;
01582   UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
01585   ibool   init_flush[BUF_FLUSH_N_TYPES];
01588   ulint   n_flush[BUF_FLUSH_N_TYPES];
01591   os_event_t  no_flush[BUF_FLUSH_N_TYPES];
01595   ib_rbt_t* flush_rbt;  
01609   ulint   freed_page_clock;
01618   ulint   LRU_flush_ended;
01622   /* @} */
01623 
01625   /* @{ */
01626 
01627   UT_LIST_BASE_NODE_T(buf_page_t) free;
01630   UT_LIST_BASE_NODE_T(buf_page_t) LRU;
01632   buf_page_t* LRU_old;  
01639   ulint   LRU_old_len;  
01647   UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU;
01651   /* @} */
01656   /* @{ */
01657   UT_LIST_BASE_NODE_T(buf_page_t) zip_clean;
01659   UT_LIST_BASE_NODE_T(buf_page_t) zip_free[BUF_BUDDY_SIZES];
01662   buf_page_t      watch[BUF_POOL_WATCH_SIZE];
01667 #if BUF_BUDDY_HIGH != UNIV_PAGE_SIZE
01668 # error "BUF_BUDDY_HIGH != UNIV_PAGE_SIZE"
01669 #endif
01670 #if BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE
01671 # error "BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE"
01672 #endif
01673   /* @} */
01674 };
01675 
01678 /* @{ */
01679 
01681 #define buf_pool_mutex_own(b) mutex_own(&b->mutex)
01682 
01683 #define buf_pool_mutex_enter(b) do {    \
01684   ut_ad(!mutex_own(&b->zip_mutex)); \
01685   mutex_enter(&b->mutex);   \
01686 } while (0)
01687 
01689 #define buf_flush_list_mutex_own(b) mutex_own(&b->flush_list_mutex)
01690 
01692 #define buf_flush_list_mutex_enter(b) do {  \
01693   mutex_enter(&b->flush_list_mutex);  \
01694 } while (0)
01695 
01696 # define buf_flush_list_mutex_exit(b) do {  \
01697   mutex_exit(&b->flush_list_mutex); \
01698 } while (0)
01699 
01700 
01701 
01702 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
01703 
01704 # define buf_pool_mutex_exit_forbid(b) do { \
01705   ut_ad(buf_pool_mutex_own(b));   \
01706   b->mutex_exit_forbidden++;    \
01707 } while (0)
01708 
01709 # define buf_pool_mutex_exit_allow(b) do {  \
01710   ut_ad(buf_pool_mutex_own(b));   \
01711   ut_a(b->mutex_exit_forbidden);  \
01712   b->mutex_exit_forbidden--;    \
01713 } while (0)
01714 
01715 # define buf_pool_mutex_exit(b) do {    \
01716   ut_a(!b->mutex_exit_forbidden);   \
01717   mutex_exit(&b->mutex);      \
01718 } while (0)
01719 #else
01720 
01721 # define buf_pool_mutex_exit_forbid(b) ((void) 0)
01722 
01723 # define buf_pool_mutex_exit_allow(b) ((void) 0)
01724 
01725 # define buf_pool_mutex_exit(b) mutex_exit(&b->mutex)
01726 #endif
01727 #endif /* !UNIV_HOTBACKUP */
01728 /* @} */
01729 
01730 /**********************************************************************
01731 Let us list the consistency conditions for different control block states.
01732 
01733 NOT_USED: is in free list, not in LRU list, not in flush list, nor
01734     page hash table
01735 READY_FOR_USE:  is not in free list, LRU list, or flush list, nor page
01736     hash table
01737 MEMORY:   is not in free list, LRU list, or flush list, nor page
01738     hash table
01739 FILE_PAGE:  space and offset are defined, is in page hash table
01740     if io_fix == BUF_IO_WRITE,
01741       pool: no_flush[flush_type] is in reset state,
01742       pool: n_flush[flush_type] > 0
01743 
01744     (1) if buf_fix_count == 0, then
01745       is in LRU list, not in free list
01746       is in flush list,
01747         if and only if oldest_modification > 0
01748       is x-locked,
01749         if and only if io_fix == BUF_IO_READ
01750       is s-locked,
01751         if and only if io_fix == BUF_IO_WRITE
01752 
01753     (2) if buf_fix_count > 0, then
01754       is not in LRU list, not in free list
01755       is in flush list,
01756         if and only if oldest_modification > 0
01757       if io_fix == BUF_IO_READ,
01758         is x-locked
01759       if io_fix == BUF_IO_WRITE,
01760         is s-locked
01761 
01762 State transitions:
01763 
01764 NOT_USED => READY_FOR_USE
01765 READY_FOR_USE => MEMORY
01766 READY_FOR_USE => FILE_PAGE
01767 MEMORY => NOT_USED
01768 FILE_PAGE => NOT_USED NOTE: This transition is allowed if and only if
01769         (1) buf_fix_count == 0,
01770         (2) oldest_modification == 0, and
01771         (3) io_fix == 0.
01772 */
01773 
01774 #ifndef UNIV_NONINL
01775 #include "buf0buf.ic"
01776 #endif
01777 
01778 #endif