1
/******************************************************
2
The database buffer read
6
Created 11/5/1995 Heikki Tuuri
7
*******************************************************/
13
#include "buf0types.h"
15
/************************************************************************
16
High-level function which reads a page asynchronously from a file to the
17
buffer buf_pool if it is not already there. Sets the io_fix flag and sets
18
an exclusive lock on the buffer frame. The flag is cleared and the x-lock
19
released by the i/o-handler thread. Does a random read-ahead if it seems
25
/* out: number of page read requests issued: this can
26
be > 1 if read-ahead occurred */
27
ulint space, /* in: space id */
28
ulint zip_size,/* in: compressed page size in bytes, or 0 */
29
ulint offset);/* in: page number */
30
/************************************************************************
31
Applies linear read-ahead if in the buf_pool the page is a border page of
32
a linear read-ahead area and all the pages in the area have been accessed.
33
Does not read any page if the read-ahead mechanism is not activated. Note
34
that the the algorithm looks at the 'natural' adjacent successor and
35
predecessor of the page, which on the leaf level of a B-tree are the next
36
and previous page in the chain of leaves. To know these, the page specified
37
in (space, offset) must already be present in the buf_pool. Thus, the
38
natural way to use this function is to call it when a page in the buf_pool
39
is accessed the first time, calling this function just after it has been
41
NOTE 1: as this function looks at the natural predecessor and successor
42
fields on the page, what happens, if these are not initialized to any
43
sensible value? No problem, before applying read-ahead we check that the
44
area to read is within the span of the space, if not, read-ahead is not
45
applied. An uninitialized value may result in a useless read operation, but
47
NOTE 2: the calling thread may own latches on pages: to avoid deadlocks this
48
function must be written such that it cannot end up waiting for these
50
NOTE 3: the calling thread must want access to the page given: this rule is
51
set to prevent unintended read-aheads performed by ibuf routines, a situation
52
which could result in a deadlock if the OS does not support asynchronous io. */
55
buf_read_ahead_linear(
56
/*==================*/
57
/* out: number of page read requests issued */
58
ulint space, /* in: space id */
59
ulint zip_size,/* in: compressed page size in bytes, or 0 */
60
ulint offset);/* in: page number of a page; NOTE: the current thread
61
must want access to this page (see NOTE 3 above) */
62
/************************************************************************
63
Issues read requests for pages which the ibuf module wants to read in, in
64
order to contract the insert buffer tree. Technically, this function is like
65
a read-ahead function. */
68
buf_read_ibuf_merge_pages(
69
/*======================*/
70
ibool sync, /* in: TRUE if the caller
71
wants this function to wait
72
for the highest address page
73
to get read in, before this
75
const ulint* space_ids, /* in: array of space ids */
76
const ib_int64_t* space_versions,/* in: the spaces must have
78
(timestamp), otherwise we
79
discard the read; we use this
80
to cancel reads if DISCARD +
81
IMPORT may have changed the
83
const ulint* page_nos, /* in: array of page numbers
84
to read, with the highest page
85
number the last in the
87
ulint n_stored); /* in: number of elements
89
/************************************************************************
90
Issues read requests for pages which recovery wants to read in. */
95
ibool sync, /* in: TRUE if the caller
96
wants this function to wait
97
for the highest address page
98
to get read in, before this
100
ulint space, /* in: space id */
101
ulint zip_size, /* in: compressed page size in
103
const ulint* page_nos, /* in: array of page numbers
104
to read, with the highest page
105
number the last in the
107
ulint n_stored); /* in: number of page numbers
110
/* The size in pages of the area which the read-ahead algorithms read if
113
#define BUF_READ_AHEAD_AREA \
114
ut_min(64, ut_2_power_up(buf_pool->curr_size / 32))
116
/* Modes used in read-ahead */
117
#define BUF_READ_IBUF_PAGES_ONLY 131
118
#define BUF_READ_ANY_PAGE 132