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