1 /***************************************************************************** 2 3 Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License along with 22 this program; if not, write to the Free Software Foundation, Inc., 23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA 24 25 *****************************************************************************/ 26 27 /**************************************************//** 28 @file include/buf0rea.h 29 The database buffer read 30 31 Created 11/5/1995 Heikki Tuuri 32 *******************************************************/ 33 34 #ifndef buf0rea_h 35 #define buf0rea_h 36 37 #include "univ.i" 38 #include "buf0buf.h" 39 #include "buf0types.h" 40 41 /** High-level function which reads a page asynchronously from a file to the 42 buffer buf_pool if it is not already there. Sets the io_fix flag and sets 43 an exclusive lock on the buffer frame. The flag is cleared and the x-lock 44 released by the i/o-handler thread. 45 @param[in] page_id page id 46 @param[in] page_size page size 47 @return TRUE if page has been read in, FALSE in case of failure */ 48 ibool 49 buf_read_page( 50 const page_id_t& page_id, 51 const page_size_t& page_size); 52 53 /** High-level function which reads a page asynchronously from a file to the 54 buffer buf_pool if it is not already there. Sets the io_fix flag and sets 55 an exclusive lock on the buffer frame. The flag is cleared and the x-lock 56 released by the i/o-handler thread. 57 @param[in] page_id page id 58 @param[in] page_size page size 59 @param[in] sync true if synchronous aio is desired 60 @return TRUE if page has been read in, FALSE in case of failure */ 61 ibool 62 buf_read_page_background( 63 const page_id_t& page_id, 64 const page_size_t& page_size, 65 bool sync); 66 67 /** Applies a random read-ahead in buf_pool if there are at least a threshold 68 value of accessed pages from the random read-ahead area. Does not read any 69 page, not even the one at the position (space, offset), if the read-ahead 70 mechanism is not activated. NOTE 1: the calling thread may own latches on 71 pages: to avoid deadlocks this function must be written such that it cannot 72 end up waiting for these latches! NOTE 2: the calling thread must want 73 access to the page given: this rule is set to prevent unintended read-aheads 74 performed by ibuf routines, a situation which could result in a deadlock if 75 the OS does not support asynchronous i/o. 76 @param[in] page_id page id of a page which the current thread 77 wants to access 78 @param[in] page_size page size 79 @param[in] inside_ibuf TRUE if we are inside ibuf routine 80 @return number of page read requests issued; NOTE that if we read ibuf 81 pages, it may happen that the page at the given page number does not 82 get read even if we return a positive value! */ 83 ulint 84 buf_read_ahead_random( 85 const page_id_t& page_id, 86 const page_size_t& page_size, 87 ibool inside_ibuf); 88 89 /** Applies linear read-ahead if in the buf_pool the page is a border page of 90 a linear read-ahead area and all the pages in the area have been accessed. 91 Does not read any page if the read-ahead mechanism is not activated. Note 92 that the algorithm looks at the 'natural' adjacent successor and 93 predecessor of the page, which on the leaf level of a B-tree are the next 94 and previous page in the chain of leaves. To know these, the page specified 95 in (space, offset) must already be present in the buf_pool. Thus, the 96 natural way to use this function is to call it when a page in the buf_pool 97 is accessed the first time, calling this function just after it has been 98 bufferfixed. 99 NOTE 1: as this function looks at the natural predecessor and successor 100 fields on the page, what happens, if these are not initialized to any 101 sensible value? No problem, before applying read-ahead we check that the 102 area to read is within the span of the space, if not, read-ahead is not 103 applied. An uninitialized value may result in a useless read operation, but 104 only very improbably. 105 NOTE 2: the calling thread may own latches on pages: to avoid deadlocks this 106 function must be written such that it cannot end up waiting for these 107 latches! 108 NOTE 3: the calling thread must want access to the page given: this rule is 109 set to prevent unintended read-aheads performed by ibuf routines, a situation 110 which could result in a deadlock if the OS does not support asynchronous io. 111 @param[in] page_id page id; see NOTE 3 above 112 @param[in] page_size page size 113 @param[in] inside_ibuf TRUE if we are inside ibuf routine 114 @return number of page read requests issued */ 115 ulint 116 buf_read_ahead_linear( 117 const page_id_t& page_id, 118 const page_size_t& page_size, 119 ibool inside_ibuf); 120 121 /********************************************************************//** 122 Issues read requests for pages which the ibuf module wants to read in, in 123 order to contract the insert buffer tree. Technically, this function is like 124 a read-ahead function. */ 125 void 126 buf_read_ibuf_merge_pages( 127 /*======================*/ 128 bool sync, /*!< in: true if the caller 129 wants this function to wait 130 for the highest address page 131 to get read in, before this 132 function returns */ 133 const ulint* space_ids, /*!< in: array of space ids */ 134 const ulint* page_nos, /*!< in: array of page numbers 135 to read, with the highest page 136 number the last in the 137 array */ 138 ulint n_stored); /*!< in: number of elements 139 in the arrays */ 140 141 /** Issues read requests for pages which recovery wants to read in. 142 @param[in] sync true if the caller wants this function to wait 143 for the highest address page to get read in, before this function returns 144 @param[in] space_id tablespace id 145 @param[in] page_nos array of page numbers to read, with the 146 highest page number the last in the array 147 @param[in] n_stored number of page numbers in the array */ 148 149 void 150 buf_read_recv_pages( 151 bool sync, 152 ulint space_id, 153 const ulint* page_nos, 154 ulint n_stored); 155 156 /** The size in pages of the area which the read-ahead algorithms read if 157 invoked */ 158 #define BUF_READ_AHEAD_AREA(b) ((b)->read_ahead_area) 159 160 /** @name Modes used in read-ahead @{ */ 161 /** read only pages belonging to the insert buffer tree */ 162 #define BUF_READ_IBUF_PAGES_ONLY 131 163 /** read any page */ 164 #define BUF_READ_ANY_PAGE 132 165 /* @} */ 166 167 #endif 168