MySQL 8.0.39
Source Code Documentation
buf0flu.h File Reference

The database buffer pool flush algorithm. More...

#include "buf0types.h"
#include "univ.i"
#include "ut0byte.h"
#include "buf0flu.ic"

Go to the source code of this file.

Classes

class  Flush_observer
 We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load.cc).Since we disable redo logging during a index build, we need to make sure that all dirty pages modified by the index build are flushed to disk before any redo logged operations go to the index. More...
 

Functions

bool buf_flush_page_cleaner_is_active ()
 Checks if the page_cleaner is in active state. More...
 
void buf_flush_remove (buf_page_t *bpage)
 Remove a block from the flush list of modified blocks. More...
 
void buf_flush_relocate_on_flush_list (buf_page_t *bpage, buf_page_t *dpage)
 Relocates a buffer control block on the flush_list. More...
 
void buf_flush_write_complete (buf_page_t *bpage)
 Updates the flush system data structures when a write is completed. More...
 
bool page_is_uncompressed_type (const byte *page)
 Check if page type is uncompressed. More...
 
void buf_flush_init_for_writing (const buf_block_t *block, byte *page, void *page_zip_, lsn_t newest_lsn, bool skip_checksum, bool skip_lsn_check)
 Initialize a page for writing to the tablespace. More...
 
bool buf_flush_page_try (buf_pool_t *buf_pool, buf_block_t *block)
 Writes a flushable page asynchronously from the buffer pool to a file. More...
 
bool buf_flush_do_batch (buf_pool_t *buf_pool, buf_flush_t type, ulint min_n, lsn_t lsn_limit, ulint *n_processed)
 Do flushing batch of a given type. More...
 
bool buf_flush_lists (ulint min_n, lsn_t lsn_limit, ulint *n_processed)
 This utility flushes dirty blocks from the end of the flush list of all buffer pool instances. More...
 
bool buf_flush_single_page_from_LRU (buf_pool_t *buf_pool)
 This function picks up a single page from the tail of the LRU list, flushes it (if it is dirty), removes it from page_hash and LRU list and puts it on the free list. More...
 
void buf_flush_wait_batch_end (buf_pool_t *buf_pool, buf_flush_t flush_type)
 Waits until a flush batch of the given type ends. More...
 
void buf_flush_wait_batch_end_wait_only (buf_pool_t *buf_pool, buf_flush_t type)
 Waits until a flush batch of the given type ends. More...
 
static void buf_flush_note_modification (buf_block_t *block, lsn_t start_lsn, lsn_t end_lsn, Flush_observer *observer)
 This function should be called at a mini-transaction commit, if a page was modified in it. More...
 
static void buf_flush_recv_note_modification (buf_block_t *block, lsn_t start_lsn, lsn_t end_lsn)
 This function should be called when recovery has modified a buffer page. More...
 
bool buf_flush_ready_for_replace (buf_page_t *bpage)
 Returns true if the file page block is immediately suitable for replacement, i.e., the transition FILE_PAGE => NOT_USED allowed. More...
 
void buf_flush_page_cleaner_disabled_debug_update (THD *thd, SYS_VAR *var, void *var_ptr, const void *save)
 Disables page cleaner threads (coordinator and workers). More...
 
void buf_flush_page_cleaner_init ()
 Initialize page_cleaner. More...
 
void buf_flush_wait_LRU_batch_end ()
 Wait for any possible LRU flushes that are in progress to end. More...
 
bool buf_flush_validate (buf_pool_t *buf_pool)
 Validates the flush list. More...
 
void buf_flush_init_flush_rbt (void)
 Initialize the red-black tree to speed up insertions into the flush_list during recovery process. More...
 
void buf_flush_free_flush_rbt (void)
 Frees up the red-black tree. More...
 
bool buf_flush_page (buf_pool_t *buf_pool, buf_page_t *bpage, buf_flush_t flush_type, bool sync)
 Writes a flushable page asynchronously from the buffer pool to a file. More...
 
bool buf_flush_ready_for_flush (buf_page_t *bpage, buf_flush_t flush_type)
 Check if the block is modified and ready for flushing. More...
 
ulint buf_pool_get_dirty_pages_count (buf_pool_t *buf_pool, space_id_t id, Flush_observer *observer)
 Check if there are any dirty pages that belong to a space id in the flush list in a particular buffer pool. More...
 
void buf_flush_fsync ()
 Executes fsync for all tablespaces, to fsync all pages written to disk. More...
 
void buf_flush_sync_all_buf_pools ()
 Synchronously flush dirty blocks from the end of the flush list of all buffer pool instances. More...
 
bool buf_are_flush_lists_empty_validate ()
 Checks if all flush lists are empty. More...
 
lsn_t get_flush_sync_lsn () noexcept
 Get the lsn up to which data pages are to be synchronously flushed. More...
 

Variables

bool innodb_page_cleaner_disabled_debug
 Value of MySQL global variable used to disable page cleaner. More...
 
os_event_t buf_flush_event
 Event to synchronise with the flushing. More...
 
os_event_t buf_flush_tick_event
 Event to wait for one flushing step. More...
 

Detailed Description

The database buffer pool flush algorithm.

Created 11/5/1995 Heikki Tuuri

Function Documentation

◆ buf_are_flush_lists_empty_validate()

bool buf_are_flush_lists_empty_validate ( )

Checks if all flush lists are empty.

It is supposed to be used in single thread, during startup or shutdown. Hence it does not acquire lock and it is caller's responsibility to guarantee that flush lists are not changed in background.

Returns
true if all flush lists were empty.

◆ buf_flush_do_batch()

bool buf_flush_do_batch ( buf_pool_t buf_pool,
buf_flush_t  type,
ulint  min_n,
lsn_t  lsn_limit,
ulint n_processed 
)

Do flushing batch of a given type.

NOTE: The calling thread is not allowed to own any latches on pages!

Parameters
[in,out]buf_poolbuffer pool instance
[in]typeflush type
[in]min_nwished minimum number of blocks flushed (it is not guaranteed that the actual number is that big, though)
[in]lsn_limitin the case BUF_FLUSH_LIST all blocks whose oldest_modification is smaller than this should be flushed (if their number does not exceed min_n), otherwise ignored
[out]n_processedthe number of pages which were processed is passed back to caller. Ignored if NULL
Return values
trueif a batch was queued successfully.
falseif another batch of same type was already running.

◆ buf_flush_free_flush_rbt()

void buf_flush_free_flush_rbt ( void  )

Frees up the red-black tree.

◆ buf_flush_fsync()

void buf_flush_fsync ( )

Executes fsync for all tablespaces, to fsync all pages written to disk.

◆ buf_flush_init_flush_rbt()

void buf_flush_init_flush_rbt ( void  )

Initialize the red-black tree to speed up insertions into the flush_list during recovery process.

Should be called at the start of recovery process before any page has been read/written.

◆ buf_flush_init_for_writing()

void buf_flush_init_for_writing ( const buf_block_t block,
byte page,
void *  page_zip_,
lsn_t  newest_lsn,
bool  skip_checksum,
bool  skip_lsn_check 
)

Initialize a page for writing to the tablespace.

Parameters
[in]blockbuffer block; NULL if bypassing the buffer pool
[in,out]pagepage frame
[in,out]page_zip_compressed page, or NULL if uncompressed
[in]newest_lsnnewest modification LSN to the page
[in]skip_checksumwhether to disable the page checksum
[in]skip_lsn_checktrue to skip check for LSN (in DEBUG)

◆ buf_flush_lists()

bool buf_flush_lists ( ulint  min_n,
lsn_t  lsn_limit,
ulint n_processed 
)

This utility flushes dirty blocks from the end of the flush list of all buffer pool instances.

NOTE: The calling thread is not allowed to own any latches on pages!

Parameters
[in]min_nwished minimum number of blocks flushed (it is not guaranteed that the actual number is that big, though)
[in]lsn_limitin the case BUF_FLUSH_LIST all blocks whose oldest_modification is smaller than this should be flushed (if their number does not exceed min_n), otherwise ignored
[out]n_processedthe number of pages which were processed is passed back to caller. Ignored if NULL.
Returns
true if a batch was queued successfully for each buffer pool instance. false if another batch of same type was already running in at least one of the buffer pool instance

◆ buf_flush_note_modification()

static void buf_flush_note_modification ( buf_block_t block,
lsn_t  start_lsn,
lsn_t  end_lsn,
Flush_observer observer 
)
inlinestatic

This function should be called at a mini-transaction commit, if a page was modified in it.

Puts the block to the list of modified blocks, if it not already in it.

Parameters
[in]blockblock which is modified
[in]start_lsnstart lsn of the first mtr in a set of mtr's
[in]end_lsnend lsn of the last mtr in the set of mtr's
[in]observerflush observer

◆ buf_flush_page()

bool buf_flush_page ( buf_pool_t buf_pool,
buf_page_t bpage,
buf_flush_t  flush_type,
bool  sync 
)

Writes a flushable page asynchronously from the buffer pool to a file.

NOTE: 1. in simulated aio we must call os_aio_simulated_wake_handler_threads after we have posted a batch of writes! 2. buf_page_get_mutex(bpage) must be held upon entering this function. The LRU list mutex must be held if flush_type == BUF_FLUSH_SINGLE_PAGE. Both mutexes will be released by this function if it returns true.

Parameters
[in]buf_poolbuffer pool instance
[in]bpagebuffer control block
[in]flush_typetype of flush
[in]synctrue if sync IO request
Returns
true if page was flushed

◆ buf_flush_page_cleaner_disabled_debug_update()

void buf_flush_page_cleaner_disabled_debug_update ( THD thd,
SYS_VAR var,
void *  var_ptr,
const void *  save 
)

Disables page cleaner threads (coordinator and workers).

It's used by: SET GLOBAL innodb_page_cleaner_disabled_debug = 1 (0).

Parameters
[in]thdthread handle
[in]varpointer to system variable
[out]var_ptrwhere the formal string goes
[in]saveimmediate result from check function

◆ buf_flush_page_cleaner_init()

void buf_flush_page_cleaner_init ( )

Initialize page_cleaner.


◆ buf_flush_page_cleaner_is_active()

bool buf_flush_page_cleaner_is_active ( )

Checks if the page_cleaner is in active state.

Checks if the page_cleaner is in active state.

◆ buf_flush_page_try()

bool buf_flush_page_try ( buf_pool_t buf_pool,
buf_block_t block 
)

Writes a flushable page asynchronously from the buffer pool to a file.

NOTE: block and LRU list mutexes must be held upon entering this function, and they will be released by this function after flushing. This is loosely based on buf_flush_batch() and buf_flush_page().

Parameters
[in,out]buf_poolbuffer pool instance
[in,out]blockbuffer control block
Returns
true if the page was flushed and the mutex released

◆ buf_flush_ready_for_flush()

bool buf_flush_ready_for_flush ( buf_page_t bpage,
buf_flush_t  flush_type 
)

Check if the block is modified and ready for flushing.

Requires buf_page_get_mutex(bpage).

Parameters
[in]bpagebuffer control block, must be buf_page_in_file()
[in]flush_typetype of flush
Returns
true if can flush immediately

◆ buf_flush_ready_for_replace()

bool buf_flush_ready_for_replace ( buf_page_t bpage)

Returns true if the file page block is immediately suitable for replacement, i.e., the transition FILE_PAGE => NOT_USED allowed.

The caller must hold the LRU list and block mutexes.

Parameters
[in]bpagebuffer control block, must be buf_page_in_file() and in the LRU list
Returns
true if can replace immediately

◆ buf_flush_recv_note_modification()

static void buf_flush_recv_note_modification ( buf_block_t block,
lsn_t  start_lsn,
lsn_t  end_lsn 
)
inlinestatic

This function should be called when recovery has modified a buffer page.

Parameters
[in]blockblock which is modified
[in]start_lsnstart lsn of the first mtr in a set of mtr's
[in]end_lsnend lsn of the last mtr in the set of mtr's

◆ buf_flush_relocate_on_flush_list()

void buf_flush_relocate_on_flush_list ( buf_page_t bpage,
buf_page_t dpage 
)

Relocates a buffer control block on the flush_list.

Note that it is assumed that the contents of bpage has already been copied to dpage. in/out: destination block

Note that it is assumed that the contents of bpage have already been copied to dpage. IMPORTANT: When this function is called bpage and dpage are not exact copies of each other. For example, they both will have different "::state". Also the "::list" pointers in dpage may be stale. We need to use the current list node (bpage) to do the list manipulation because the list pointers could have changed between the time that we copied the contents of bpage to the dpage and the flush list manipulation below.

Parameters
bpagein/out: control block being moved
dpagein/out: destination block

◆ buf_flush_remove()

void buf_flush_remove ( buf_page_t bpage)

Remove a block from the flush list of modified blocks.

Parameters
[in]bpagepointer to the block in question

◆ buf_flush_single_page_from_LRU()

bool buf_flush_single_page_from_LRU ( buf_pool_t buf_pool)

This function picks up a single page from the tail of the LRU list, flushes it (if it is dirty), removes it from page_hash and LRU list and puts it on the free list.

It is called from user threads when they are unable to find a replaceable page at the tail of the LRU list i.e.: when the background LRU flushing in the page_cleaner thread is not fast enough to keep pace with the workload.

Parameters
[in,out]buf_poolbuffer pool instance
Returns
true if success.

◆ buf_flush_sync_all_buf_pools()

void buf_flush_sync_all_buf_pools ( )

Synchronously flush dirty blocks from the end of the flush list of all buffer pool instances.

NOTE: The calling thread is not allowed to own any latches on pages!

◆ buf_flush_validate()

bool buf_flush_validate ( buf_pool_t buf_pool)

Validates the flush list.

Returns
true if ok

◆ buf_flush_wait_batch_end()

void buf_flush_wait_batch_end ( buf_pool_t buf_pool,
buf_flush_t  flush_type 
)

Waits until a flush batch of the given type ends.

Parameters
[in]buf_poolBuffer pool instance.
[in]flush_typeFlush type.

◆ buf_flush_wait_batch_end_wait_only()

void buf_flush_wait_batch_end_wait_only ( buf_pool_t buf_pool,
buf_flush_t  type 
)

Waits until a flush batch of the given type ends.

This is called by a thread that only wants to wait for a flush to end but doesn't do any flushing itself.

Parameters
[in]buf_poolbuffer pool instance
[in]typeBUF_FLUSH_LRU or BUF_FLUSH_LIST

◆ buf_flush_wait_LRU_batch_end()

void buf_flush_wait_LRU_batch_end ( )

Wait for any possible LRU flushes that are in progress to end.

◆ buf_flush_write_complete()

void buf_flush_write_complete ( buf_page_t bpage)

Updates the flush system data structures when a write is completed.

Parameters
[in]bpagepointer to the block in question

◆ buf_pool_get_dirty_pages_count()

ulint buf_pool_get_dirty_pages_count ( buf_pool_t buf_pool,
space_id_t  id,
Flush_observer observer 
)

Check if there are any dirty pages that belong to a space id in the flush list in a particular buffer pool.

Returns
number of dirty pages present in a single buffer pool in: flush observer to check
number of dirty pages present in a single buffer pool
Parameters
buf_poolin: buffer pool
idin: space id to check
observerin: flush observer to check

◆ get_flush_sync_lsn()

lsn_t get_flush_sync_lsn ( )
noexcept

Get the lsn up to which data pages are to be synchronously flushed.

Returns
target lsn for the requested flush_sync

◆ page_is_uncompressed_type()

bool page_is_uncompressed_type ( const byte page)

Check if page type is uncompressed.

Parameters
[in]pagepage frame
Returns
true if uncompressed page type.

Variable Documentation

◆ buf_flush_event

os_event_t buf_flush_event
extern

Event to synchronise with the flushing.

◆ buf_flush_tick_event

os_event_t buf_flush_tick_event
extern

Event to wait for one flushing step.

◆ innodb_page_cleaner_disabled_debug

bool innodb_page_cleaner_disabled_debug
extern

Value of MySQL global variable used to disable page cleaner.