1
/*****************************************************************************
3
Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/buf0rea.h
21
The database buffer read
23
Created 11/5/1995 Heikki Tuuri
24
*******************************************************/
31
#include "buf0types.h"
32
#include "trx0types.h"
34
/********************************************************************//**
35
Low-level function which reads a page asynchronously from a file to the
36
buffer buf_pool if it is not already there, in which case does nothing.
37
Sets the io_fix flag and sets an exclusive lock on the buffer frame. The
38
flag is cleared and the x-lock released by an i/o-handler thread.
39
@return 1 if a read request was queued, 0 if the page already resided
40
in buf_pool, or if the page is in the doublewrite buffer blocks in
41
which case it is never read into the pool, or if the tablespace does
42
not exist or is being dropped TODO update
43
@return 1 if read request is issued. 0 if it is not */
48
ulint* err, /*!< out: DB_SUCCESS or DB_TABLESPACE_DELETED if we are
49
trying to read from a non-existent tablespace, or a
50
tablespace which is just now being dropped */
51
ibool sync, /*!< in: true if synchronous aio is desired */
52
ulint mode, /*!< in: BUF_READ_IBUF_PAGES_ONLY, ...,
53
ORed to OS_AIO_SIMULATED_WAKE_LATER (see below
54
at read-ahead functions) */
55
ulint space, /*!< in: space id */
56
ulint zip_size,/*!< in: compressed page size, or 0 */
57
ibool unzip, /*!< in: true=request uncompressed page */
58
ib_int64_t tablespace_version, /*!< in: if the space memory object has
59
this timestamp different from what we are giving here,
60
treat the tablespace as dropped; this is a timestamp we
61
use to stop dangling page reads from a tablespace
62
which we have DISCARDed + IMPORTed back */
63
ulint offset);/*!< in: page number */
65
/********************************************************************//**
66
High-level function which reads a page asynchronously from a file to the
67
buffer buf_pool if it is not already there. Sets the io_fix flag and sets
68
an exclusive lock on the buffer frame. The flag is cleared and the x-lock
69
released by the i/o-handler thread.
70
@return TRUE if page has been read in, FALSE in case of failure */
75
ulint space, /*!< in: space id */
76
ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
77
ulint offset);/*!< in: page number */
78
/********************************************************************//**
79
Applies linear read-ahead if in the buf_pool the page is a border page of
80
a linear read-ahead area and all the pages in the area have been accessed.
81
Does not read any page if the read-ahead mechanism is not activated. Note
82
that the the algorithm looks at the 'natural' adjacent successor and
83
predecessor of the page, which on the leaf level of a B-tree are the next
84
and previous page in the chain of leaves. To know these, the page specified
85
in (space, offset) must already be present in the buf_pool. Thus, the
86
natural way to use this function is to call it when a page in the buf_pool
87
is accessed the first time, calling this function just after it has been
89
NOTE 1: as this function looks at the natural predecessor and successor
90
fields on the page, what happens, if these are not initialized to any
91
sensible value? No problem, before applying read-ahead we check that the
92
area to read is within the span of the space, if not, read-ahead is not
93
applied. An uninitialized value may result in a useless read operation, but
95
NOTE 2: the calling thread may own latches on pages: to avoid deadlocks this
96
function must be written such that it cannot end up waiting for these
98
NOTE 3: the calling thread must want access to the page given: this rule is
99
set to prevent unintended read-aheads performed by ibuf routines, a situation
100
which could result in a deadlock if the OS does not support asynchronous io.
101
@return number of page read requests issued */
104
buf_read_ahead_linear(
105
/*==================*/
106
ulint space, /*!< in: space id */
107
ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
108
ulint offset);/*!< in: page number of a page; NOTE: the current thread
109
must want access to this page (see NOTE 3 above) */
110
/********************************************************************//**
111
Issues read requests for pages which the ibuf module wants to read in, in
112
order to contract the insert buffer tree. Technically, this function is like
113
a read-ahead function. */
116
buf_read_ibuf_merge_pages(
117
/*======================*/
118
ibool sync, /*!< in: TRUE if the caller
119
wants this function to wait
120
for the highest address page
121
to get read in, before this
123
const ulint* space_ids, /*!< in: array of space ids */
124
const ib_int64_t* space_versions,/*!< in: the spaces must have
126
(timestamp), otherwise we
127
discard the read; we use this
128
to cancel reads if DISCARD +
129
IMPORT may have changed the
131
const ulint* page_nos, /*!< in: array of page numbers
132
to read, with the highest page
133
number the last in the
135
ulint n_stored); /*!< in: number of elements
137
/********************************************************************//**
138
Issues read requests for pages which recovery wants to read in. */
143
ibool sync, /*!< in: TRUE if the caller
144
wants this function to wait
145
for the highest address page
146
to get read in, before this
148
ulint space, /*!< in: space id */
149
ulint zip_size, /*!< in: compressed page size in
151
const ulint* page_nos, /*!< in: array of page numbers
152
to read, with the highest page
153
number the last in the
155
ulint n_stored); /*!< in: number of page numbers
158
/** The size in pages of the area which the read-ahead algorithms read if
160
#define BUF_READ_AHEAD_AREA(b) 64
162
/** @name Modes used in read-ahead @{ */
163
/** read only pages belonging to the insert buffer tree */
164
#define BUF_READ_IBUF_PAGES_ONLY 131
166
#define BUF_READ_ANY_PAGE 132