MySQL 8.3.0
Source Code Documentation
buf0rea.cc File Reference

The database buffer read. More...

#include <mysql/service_thd_wait.h>
#include <stddef.h>
#include "buf0buf.h"
#include "buf0dblwr.h"
#include "buf0flu.h"
#include "buf0lru.h"
#include "buf0rea.h"
#include "fil0fil.h"
#include "ha_prototypes.h"
#include "ibuf0ibuf.h"
#include "log0recv.h"
#include "mtr0mtr.h"
#include "my_dbug.h"
#include "os0file.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "trx0sys.h"
#include "ut0new.h"

Functions

page_no_t BUF_READ_AHEAD_RANDOM_THRESHOLD (const buf_pool_t *b)
 There must be at least this many pages in buf_pool in the area to start a random read-ahead. More...
 
ulint buf_read_page_low (dberr_t *err, bool sync, ulint type, ulint mode, const page_id_t &page_id, const page_size_t &page_size, bool unzip)
 Low-level function which reads a page asynchronously from a file to the buffer buf_pool if it is not already there, in which case does nothing. More...
 
ulint buf_read_ahead_random (const page_id_t &page_id, const page_size_t &page_size, bool inside_ibuf)
 Applies a random read-ahead in buf_pool if there are at least a threshold value of accessed pages from the random read-ahead area. More...
 
bool buf_read_page (const page_id_t &page_id, const page_size_t &page_size)
 High-level function which reads a page asynchronously from a file to the buffer buf_pool if it is not already there. More...
 
bool buf_read_page_background (const page_id_t &page_id, const page_size_t &page_size, bool sync)
 High-level function which reads a page asynchronously from a file to the buffer buf_pool if it is not already there. More...
 
ulint buf_read_ahead_linear (const page_id_t &page_id, const page_size_t &page_size, bool inside_ibuf)
 Applies linear read-ahead if in the buf_pool the page is a border page of a linear read-ahead area and all the pages in the area have been accessed. More...
 
void buf_read_ibuf_merge_pages (bool sync, const space_id_t *space_ids, const page_no_t *page_nos, ulint n_stored)
 Issues read requests for pages which the ibuf module wants to read in, in order to contract the insert buffer tree. More...
 
void buf_read_recv_pages (space_id_t space_id, const page_no_t *page_nos, ulint n_stored)
 Issues asynchronous read requests for pages which recovery wants to read in. More...
 

Variables

static constexpr uint32_t BUF_READ_AHEAD_PEND_LIMIT = 2
 If there are buf_pool->curr_size per the number below pending reads, then read-ahead is not done: this is to prevent flooding the buffer pool with i/o-fixed buffer blocks. More...
 

Detailed Description

The database buffer read.

Created 11/5/1995 Heikki Tuuri

Function Documentation

◆ buf_read_ahead_linear()

ulint buf_read_ahead_linear ( const page_id_t page_id,
const page_size_t page_size,
bool  inside_ibuf 
)

Applies linear read-ahead if in the buf_pool the page is a border page of a linear read-ahead area and all the pages in the area have been accessed.

Does not read any page if the read-ahead mechanism is not activated. Note that the algorithm looks at the 'natural' adjacent successor and predecessor of the page, which on the leaf level of a B-tree are the next and previous page in the chain of leaves. To know these, the page specified in (space, offset) must already be present in the buf_pool. Thus, the natural way to use this function is to call it when a page in the buf_pool is accessed the first time, calling this function just after it has been bufferfixed. NOTE 1: as this function looks at the natural predecessor and successor fields on the page, what happens, if these are not initialized to any sensible value? No problem, before applying read-ahead we check that the area to read is within the span of the space, if not, read-ahead is not applied. An uninitialized value may result in a useless read operation, but only very improbably. NOTE 2: the calling thread may own latches on pages: to avoid deadlocks this function must be written such that it cannot end up waiting for these latches! NOTE 3: the calling thread must want access to the page given: this rule is set to prevent unintended read-aheads performed by ibuf routines, a situation which could result in a deadlock if the OS does not support asynchronous io.

Parameters
[in]page_idpage id; see NOTE 3 above
[in]page_sizepage size
[in]inside_ibuftrue if we are inside ibuf routine
Returns
number of page read requests issued

◆ buf_read_ahead_random()

ulint buf_read_ahead_random ( const page_id_t page_id,
const page_size_t page_size,
bool  inside_ibuf 
)

Applies a random read-ahead in buf_pool if there are at least a threshold value of accessed pages from the random read-ahead area.

Does not read any page, not even the one at the position (space, offset), if the read-ahead mechanism is not activated. NOTE 1: the calling thread may own latches on pages: to avoid deadlocks this function must be written such that it cannot end up waiting for these latches! NOTE 2: the calling thread must want access to the page given: this rule is set to prevent unintended read-aheads performed by ibuf routines, a situation which could result in a deadlock if the OS does not support asynchronous i/o.

Parameters
[in]page_idpage id of a page which the current thread wants to access
[in]page_sizepage size
[in]inside_ibuftrue if we are inside ibuf routine
Returns
number of page read requests issued; NOTE that if we read ibuf pages, it may happen that the page at the given page number does not get read even if we return a positive value!

◆ BUF_READ_AHEAD_RANDOM_THRESHOLD()

page_no_t BUF_READ_AHEAD_RANDOM_THRESHOLD ( const buf_pool_t b)
inline

There must be at least this many pages in buf_pool in the area to start a random read-ahead.

◆ buf_read_ibuf_merge_pages()

void buf_read_ibuf_merge_pages ( bool  sync,
const space_id_t space_ids,
const page_no_t page_nos,
ulint  n_stored 
)

Issues read requests for pages which the ibuf module wants to read in, in order to contract the insert buffer tree.

Technically, this function is like a read-ahead function.

Parameters
[in]synctrue if the caller wants this function to wait for the highest address page to get read in, before this function returns.
[in]space_idsArray of space ids.
[in]page_nosArray of page numbers to read, with the highest page number the last in the array.
[in]n_storednumber of elements in the arrays.

◆ buf_read_page()

bool buf_read_page ( const page_id_t page_id,
const page_size_t page_size 
)

High-level function which reads a page asynchronously from a file to the buffer buf_pool if it is not already there.

Sets the io_fix flag and sets an exclusive lock on the buffer frame. The flag is cleared and the x-lock released by the i/o-handler thread.

Parameters
[in]page_idpage id
[in]page_sizepage size
Returns
true if page has been read in, false in case of failure

◆ buf_read_page_background()

bool buf_read_page_background ( const page_id_t page_id,
const page_size_t page_size,
bool  sync 
)

High-level function which reads a page asynchronously from a file to the buffer buf_pool if it is not already there.

Sets the io_fix flag and sets an exclusive lock on the buffer frame. The flag is cleared and the x-lock released by the i/o-handler thread.

Parameters
[in]page_idpage id
[in]page_sizepage size
[in]synctrue if synchronous aio is desired
Returns
true if page has been read in, false in case of failure

◆ buf_read_page_low()

ulint buf_read_page_low ( dberr_t err,
bool  sync,
ulint  type,
ulint  mode,
const page_id_t page_id,
const page_size_t page_size,
bool  unzip 
)

Low-level function which reads a page asynchronously from a file to the buffer buf_pool if it is not already there, in which case does nothing.

Sets the io_fix flag and sets an exclusive lock on the buffer frame. The flag is cleared and the x-lock released by an i/o-handler thread.

Parameters
[out]errDB_SUCCESS or DB_TABLESPACE_DELETED if we are trying to read from a non-existent tablespace or a tablespace which is just now being dropped
[in]syncwhether synchronous aio is desired
[in]typeRequest type
[in]modeBUF_READ_IBUF_PAGES_ONLY, ...
[in]page_idpage id
[in]page_sizepage size
[in]unziptrue=request uncompressed page
Returns
1 if a read request was queued, 0 if the page already resided in buf_pool, or if the page is in the doublewrite buffer blocks in which case it is never read into the pool, or if the tablespace does not exist or is being dropped

◆ buf_read_recv_pages()

void buf_read_recv_pages ( space_id_t  space_id,
const page_no_t page_nos,
ulint  n_stored 
)

Issues asynchronous read requests for pages which recovery wants to read in.

Parameters
[in]space_idtablespace id
[in]page_nosarray of page numbers to read, with the highest page number the last in the array
[in]n_storednumber of page numbers in the array

Variable Documentation

◆ BUF_READ_AHEAD_PEND_LIMIT

constexpr uint32_t BUF_READ_AHEAD_PEND_LIMIT = 2
staticconstexpr

If there are buf_pool->curr_size per the number below pending reads, then read-ahead is not done: this is to prevent flooding the buffer pool with i/o-fixed buffer blocks.