MySQL 8.3.0
Source Code Documentation
buf_page_t Class Reference

#include <buf0buf.h>

Classes

class  io_responsibility_t
 
class  Latching_rules_helpers
 The purpose of this class is to hide the knowledge that Buf_io_fix_latching_rules even exists from users of buf_page_t class, while also avoiding having to tediously repeat yourself in each place where buf_page_t's implementation needs to pass typical arguments to Buf_io_fix_latching_rules such as owned_latches or current state, which require access to private fields of buf_page_t. More...
 

Public Member Functions

 buf_page_t (const buf_page_t &other)
 Copy constructor. More...
 
bool is_memory () const noexcept
 Check if the state of this page is BUF_BLOCK_MEMORY. More...
 
void set_dblwr_batch_id (uint16_t batch_id)
 Set the doublewrite buffer ID. More...
 
uint16_t get_dblwr_batch_id () const
 
space_id_t space () const noexcept
 Retrieve the tablespace id. More...
 
page_no_t page_no () const noexcept
 Retrieve the page number. More...
 
bool is_stale () const
 Checks if this space reference saved during last page ID initialization was deleted or truncated since. More...
 
bool was_stale () const
 Checks if this space reference saved during last page ID initialization was deleted or truncated since. More...
 
fil_space_tget_space () const
 Retrieve the tablespace object if one was available during page ID initialization. More...
 
void set_page_id (const page_id_t page_id)
 Set the stored page id to a new value. More...
 
void set_page_size (const page_size_t &page_size)
 Set the page size to a new value. More...
 
void reset_page_id (page_id_t new_page_id)
 Sets stored page ID to the new value. More...
 
void reset_page_id ()
 Sets stored value to invalid/empty value. More...
 
Flush_observerget_flush_observer () noexcept
 
void set_flush_observer (Flush_observer *flush_observer) noexcept
 Set the flush observer for the page. More...
 
void reset_flush_observer () noexcept
 Remove the flush observer. More...
 
lsn_t get_newest_lsn () const noexcept
 
lsn_t get_oldest_lsn () const noexcept
 
bool is_dirty () const noexcept
 
void set_newest_lsn (lsn_t lsn) noexcept
 Set the latest modification LSN. More...
 
void set_oldest_lsn (lsn_t lsn) noexcept
 Set the LSN when the page is modified for the first time. More...
 
void set_clean () noexcept
 Set page to clean state. More...
 

Static Public Member Functions

static bool is_memory (const page_t *const ptr) noexcept
 Check if the given ptr lies in a memory block of type BUF_BLOCK_MEMORY. More...
 
static bool is_zeroes (const page_t *const ptr, const size_t len) noexcept
 Check if the given buffer is full of zeroes. More...
 

Public Attributes

buf_page_thash
 Node used in chaining to buf_pool->page_hash or buf_pool->zip_hash. More...
 
uint32_t m_version {}
 Version of fil_space_t when the page was updated. More...
 
std::chrono::steady_clock::time_point access_time
 Time of first access, or 0 if the block was never accessed in the buffer pool. More...
 
bool old
 true if the block is in the old blocks in buf_pool->LRU_old More...
 
bool file_page_was_freed
 This is set to true when fsp frees a page in buffer pool; protected by buf_pool->zip_mutex or buf_block_t::mutex. More...
 
bool in_flush_list
 true if in buf_pool->flush_list; when buf_pool->flush_list_mutex is free, the following should hold: in_flush_list == (state == BUF_BLOCK_FILE_PAGE || state == BUF_BLOCK_ZIP_DIRTY) Writes to this field must be covered by both buf_pool->flush_list_mutex and block->mutex. More...
 
bool in_free_list
 true if in buf_pool->free; when buf_pool->free_list_mutex is free, the following should hold: in_free_list == (state == BUF_BLOCK_NOT_USED) More...
 
bool in_LRU_list
 true if the page is in the LRU list; used in debugging More...
 
bool in_page_hash
 true if in buf_pool->page_hash More...
 
bool in_zip_hash
 true if in buf_pool->zip_hash More...
 

Private Member Functions

void space_id_changed ()
 Updates new space reference and acquires "reference count latch" and the current version of the space object. More...
 

Private Attributes

uint16_t m_dblwr_id {}
 Double write instance ordinal value during writes. More...
 

General fields

None of these bit-fields must be modified without holding buf_page_get_mutex() [buf_block_t::mutex or buf_pool->zip_mutex], since they can be stored in the same machine word.


page_id_t id
 Page id. More...
 
page_size_t size
 Page size. More...
 
buf_fix_count_atomic_t buf_fix_count
 Count of how many fold this block is currently bufferfixed. More...
 
buf_page_state state
 Block state. More...
 
buf_flush_t flush_type
 If this block is currently being flushed to disk, this tells the flush_type. More...
 
uint8_t buf_pool_index
 Index number of the buffer pool that this block belongs to. More...
 
copyable_atomic_t< buf_io_fixio_fix
 Type of pending I/O operation. More...
 
io_responsibility_t io_responsibility
 Tracks which thread is responsible for I/O on this page. More...
 
class Latching_rules_helpers
 
bool someone_has_io_responsibility () const
 Checks if there is any thread responsible for I/O on this page now. More...
 
bool current_thread_has_io_responsibility () const
 Checks if the current thread is responsible for I/O on this page now. More...
 
void release_io_responsibility ()
 Called by the thread responsible for I/O on this page to release its responsibility. More...
 
void take_io_responsibility ()
 Called by the thread which becomes responsible for I/O on this page to indicate that it takes the responsibility. More...
 
void init_io_fix ()
 This is called only when having full ownership of the page object and no other thread can reach it. More...
 
void reinit_io_fix ()
 This is called only when having full ownership of the page object and no other thread can reach it. More...
 
void set_io_fix (buf_io_fix io_fix)
 Sets io_fix to specified value. More...
 
buf_io_fix get_io_fix () const
 Retrieves the current value of io_fix. More...
 
bool is_io_fix_write () const
 Checks if the current value of io_fix is BUF_IO_WRITE. More...
 
bool is_io_fix_read () const
 Checks if the current value of io_fix is BUF_IO_READ. More...
 
bool is_io_fix_read_as_opposed_to_write () const
 Assuming that io_fix is either BUF_IO_READ or BUF_IO_WRITE determines which of the two it is. More...
 
bool was_io_fix_read () const
 Checks if io_fix is BUF_IO_READ without requiring or acquiring any latches. More...
 
bool was_io_fixed () const
 Checks if io_fix is BUF_IO_FIX or BUF_IO_READ or BUF_IO_WRITE without requiring or acquiring any latches. More...
 
bool was_io_fix_none () const
 Checks if io_fix is BUF_IO_NONE without requiring or acquiring any latches. More...
 
static bool is_correct_io_fix_value (buf_io_fix io_fix)
 Checks if io_fix has any of the known enum values. More...
 
bool has_correct_io_fix_value () const
 Checks if io_fix has any of the known enum values. More...
 
buf_io_fix get_io_fix_snapshot () const
 Retrieves a value of io_fix without requiring or acquiring any latches. More...
 

LRU replacement algorithm fields

log sequence number of the START of the log entry written of the oldest modification to this block which has not yet been flushed on disk; zero if all modifications are on disk.

Writes to this field must be covered by both block->mutex and buf_pool->flush_list_mutex. Hence reads can happen while holding any one of the two mutexes

These fields are protected by both buf_pool->LRU_list_mutex and the block mutex.

page_zip_des_t zip
 compressed page; zip.data (but not the data it points to) is protected by buf_pool->zip_mutex; state == BUF_BLOCK_ZIP_PAGE and zip.data == NULL means an active buf_pool->watch More...
 
Flush_observerm_flush_observer {}
 Flush observer instance. More...
 
fil_space_tm_space {}
 Tablespace instance that this page belongs to. More...
 
uint32_t freed_page_clock
 The value of buf_pool->freed_page_clock when this block was the last time put to the head of the LRU list; a thread is allowed to read this for heuristic purposes without holding any mutex or latch. More...
 
 UT_LIST_NODE_T (buf_page_t) LRU
 node of the LRU list More...
 

Page flushing fields

All these are protected by buf_pool->mutex.

lsn_t newest_modification
 The flush LSN, LSN when this page was written to the redo log. More...
 
lsn_t oldest_modification
 log sequence number of the youngest modification to this block, zero if not modified. More...
 
 UT_LIST_NODE_T (buf_page_t) list
 Based on state, this is a list node, protected by the corresponding list mutex, in one of the following lists in buf_pool: More...
 

Constructor & Destructor Documentation

◆ buf_page_t()

buf_page_t::buf_page_t ( const buf_page_t other)
inline

Copy constructor.

Parameters
[in]otherInstance to copy from.

Member Function Documentation

◆ current_thread_has_io_responsibility()

bool buf_page_t::current_thread_has_io_responsibility ( ) const
inline

Checks if the current thread is responsible for I/O on this page now.

Returns
true iff the current thread is responsible for I/O on this page.

◆ get_dblwr_batch_id()

uint16_t buf_page_t::get_dblwr_batch_id ( ) const
inline
Returns
the double write batch id, or uint16_t max if undefined.

◆ get_flush_observer()

Flush_observer * buf_page_t::get_flush_observer ( )
inlinenoexcept
Returns
the flush observer instance.

◆ get_io_fix()

buf_io_fix buf_page_t::get_io_fix ( ) const
inline

Retrieves the current value of io_fix.

Assumes the caller holds buf_page_get_mutex(this).

Returns
the current value of io_fix

◆ get_io_fix_snapshot()

buf_io_fix buf_page_t::get_io_fix_snapshot ( ) const
inlineprivate

Retrieves a value of io_fix without requiring or acquiring any latches.

Note that this implies that the value might be stale unless caller establishes happens-before relation in some other way. This is a low-level function which shouldn't be used directly, but rather via wrapper methods which check if proper latches are taken or via one of the many was_io_fix_something() methods with name explicitly warning the developer about the uncertainty involved.

Returns
the value of io_fix at some moment "during" the call

◆ get_newest_lsn()

lsn_t buf_page_t::get_newest_lsn ( ) const
inlinenoexcept
Returns
the LSN of the latest modification.

◆ get_oldest_lsn()

lsn_t buf_page_t::get_oldest_lsn ( ) const
inlinenoexcept
Returns
the LSN of the first modification since the last time it was clean.

◆ get_space()

fil_space_t * buf_page_t::get_space ( ) const
inline

Retrieve the tablespace object if one was available during page ID initialization.

The returned object is safe to use as long as this buf_page_t object is not changed. Caller should have a IO fix, buffer fix, mutex or any other mean to assure the page will not be freed. After that is released the space object may be freed.

Returns
tablespace object

◆ has_correct_io_fix_value()

bool buf_page_t::has_correct_io_fix_value ( ) const
inlineprivate

Checks if io_fix has any of the known enum values.

Returns
true iff io_fix has any of the known enum values

◆ init_io_fix()

void buf_page_t::init_io_fix ( )
inline

This is called only when having full ownership of the page object and no other thread can reach it.

This currently happens during buf_pool_create(), buf_pool_resize() (which latch quite a lot) or from fil_tablespace_iterate() which creates a fake, private block which is not really a part of the buffer pool. Therefore we allow this function to set io_fix without checking for any latches. Please use set_io_fix(BUF_IO_NONE) to change state in a regular situation.

◆ is_correct_io_fix_value()

static bool buf_page_t::is_correct_io_fix_value ( buf_io_fix  io_fix)
inlinestatic

Checks if io_fix has any of the known enum values.

Parameters
[in]io_fixthe value to test
Returns
true iff io_fix has any of the known enum values

◆ is_dirty()

bool buf_page_t::is_dirty ( ) const
inlinenoexcept
Returns
true if the page is dirty.

◆ is_io_fix_read()

bool buf_page_t::is_io_fix_read ( ) const

Checks if the current value of io_fix is BUF_IO_READ.

Assumes the caller holds buf_page_get_mutex(this) or some other latches which prevent state transition from/to BUF_IO_READ.

See also
Buf_io_fix_latching_rules for specific rules.
Returns
true iff the current value of io_fix == BUF_IO_READ

◆ is_io_fix_read_as_opposed_to_write()

bool buf_page_t::is_io_fix_read_as_opposed_to_write ( ) const

Assuming that io_fix is either BUF_IO_READ or BUF_IO_WRITE determines which of the two it is.

Additionally it assumes the caller holds buf_page_get_mutex(this) or some other latches which prevent state transition from BUF_IO_READ or from BUF_IO_WRITE to another state.

See also
Buf_io_fix_latching_rules for specific rules.
Returns
true iff the current value of io_fix == BUF_IO_READ

◆ is_io_fix_write()

bool buf_page_t::is_io_fix_write ( ) const

Checks if the current value of io_fix is BUF_IO_WRITE.

Assumes the caller holds buf_page_get_mutex(this) or some other latches which prevent state transition from/to BUF_IO_WRITE.

See also
Buf_io_fix_latching_rules for specific rules.
Returns
true iff the current value of io_fix == BUF_IO_WRITE

◆ is_memory() [1/2]

bool buf_page_t::is_memory ( ) const
inlinenoexcept

Check if the state of this page is BUF_BLOCK_MEMORY.

Returns
true if the state is BUF_BLOCK_MEMORY, or false.

◆ is_memory() [2/2]

bool buf_page_t::is_memory ( const page_t *const  ptr)
staticnoexcept

Check if the given ptr lies in a memory block of type BUF_BLOCK_MEMORY.

This is checked by looking at the FIL_PAGE_LSN. If the FIL_PAGE_LSN is zero, then the block state is assumed to be BUF_BLOCK_MEMORY.

Returns
true if the FIL_PAGE_LSN is zero, false otherwise.

◆ is_stale()

bool buf_page_t::is_stale ( ) const
inline

Checks if this space reference saved during last page ID initialization was deleted or truncated since.

Returns
true when space reference stored leads was deleted or truncated and this page should be discarded. Result is up to date until the fil_shard mutex is released.

◆ is_zeroes()

bool buf_page_t::is_zeroes ( const page_t *const  ptr,
const size_t  len 
)
staticnoexcept

Check if the given buffer is full of zeroes.

◆ page_no()

page_no_t buf_page_t::page_no ( ) const
inlinenoexcept

Retrieve the page number.

Returns
page number

◆ reinit_io_fix()

void buf_page_t::reinit_io_fix ( )
inline

This is called only when having full ownership of the page object and no other thread can reach it.

This currently happens during buf_page_init_low() under buf_page_get_mutex(this), on a previously initialized page for reuse, yet should be treated as initialization of the field, not a state transition. Please use set_io_fix(BUF_IO_NONE) to change state in a regular situation.

◆ release_io_responsibility()

void buf_page_t::release_io_responsibility ( )
inline

Called by the thread responsible for I/O on this page to release its responsibility.

◆ reset_flush_observer()

void buf_page_t::reset_flush_observer ( )
inlinenoexcept

Remove the flush observer.

◆ reset_page_id() [1/2]

void buf_page_t::reset_page_id ( )
inline

Sets stored value to invalid/empty value.

Handles space object reference count.

◆ reset_page_id() [2/2]

void buf_page_t::reset_page_id ( page_id_t  new_page_id)
inline

Sets stored page ID to the new value.

Handles space object reference count.

Parameters
[in]new_page_idnew page ID to be set.

◆ set_clean()

void buf_page_t::set_clean ( )
inlinenoexcept

Set page to clean state.

◆ set_dblwr_batch_id()

void buf_page_t::set_dblwr_batch_id ( uint16_t  batch_id)
inline

Set the doublewrite buffer ID.

Parameters
[in]batch_idDouble write batch ID that flushed the page.

◆ set_flush_observer()

void buf_page_t::set_flush_observer ( Flush_observer flush_observer)
inlinenoexcept

Set the flush observer for the page.

Parameters
[in]flush_observerThe flush observer to set.

◆ set_io_fix()

void buf_page_t::set_io_fix ( buf_io_fix  io_fix)

Sets io_fix to specified value.

Assumes the caller holds buf_page_get_mutex(this). Might require additional latches depending on particular state transition. Calls take_io_responsibility() or release_io_responsibility() as needed.

See also
Buf_io_fix_latching_rules for specific rules.

◆ set_newest_lsn()

void buf_page_t::set_newest_lsn ( lsn_t  lsn)
inlinenoexcept

Set the latest modification LSN.

Parameters
[in]lsnLatest modification lSN.

◆ set_oldest_lsn()

void buf_page_t::set_oldest_lsn ( lsn_t  lsn)
inlinenoexcept

Set the LSN when the page is modified for the first time.

Parameters
[in]lsnFirst modification LSN.

◆ set_page_id()

void buf_page_t::set_page_id ( const page_id_t  page_id)
inline

Set the stored page id to a new value.

This is used only on a buffer block with BUF_BLOCK_MEMORY state.

Parameters
[in]page_idthe new value of the page id.

◆ set_page_size()

void buf_page_t::set_page_size ( const page_size_t page_size)
inline

Set the page size to a new value.

This can be used during initialization of a newly allocated buffer page.

Parameters
[in]page_sizethe new value of the page size.

◆ someone_has_io_responsibility()

bool buf_page_t::someone_has_io_responsibility ( ) const
inline

Checks if there is any thread responsible for I/O on this page now.

Returns
true iff there is a thread responsible for I/O on this page.

◆ space()

space_id_t buf_page_t::space ( ) const
inlinenoexcept

Retrieve the tablespace id.

Returns
tablespace id

◆ space_id_changed()

void buf_page_t::space_id_changed ( )
inlineprivate

Updates new space reference and acquires "reference count latch" and the current version of the space object.

◆ take_io_responsibility()

void buf_page_t::take_io_responsibility ( )
inline

Called by the thread which becomes responsible for I/O on this page to indicate that it takes the responsibility.

◆ UT_LIST_NODE_T() [1/2]

buf_page_t::UT_LIST_NODE_T ( buf_page_t  )

Based on state, this is a list node, protected by the corresponding list mutex, in one of the following lists in buf_pool:

  • BUF_BLOCK_NOT_USED: free, withdraw
  • BUF_BLOCK_FILE_PAGE: flush_list
  • BUF_BLOCK_ZIP_DIRTY: flush_list
  • BUF_BLOCK_ZIP_PAGE: zip_clean

The node pointers are protected by the corresponding list mutex.

The contents of the list node is undefined if !in_flush_list && state == BUF_BLOCK_FILE_PAGE, or if state is one of BUF_BLOCK_MEMORY, BUF_BLOCK_REMOVE_HASH or BUF_BLOCK_READY_IN_USE.

◆ UT_LIST_NODE_T() [2/2]

buf_page_t::UT_LIST_NODE_T ( buf_page_t  )

node of the LRU list

◆ was_io_fix_none()

bool buf_page_t::was_io_fix_none ( ) const
inline

Checks if io_fix is BUF_IO_NONE without requiring or acquiring any latches.

Note that this implies calling this function twice in a row could produce different results. Please, prefer this function over !was_io_fixed() to avoid the misleading interpretation as "not(Exists time such that io_fix(time))", while in fact we want and get "Exists time such that !io_fix(time)".

Returns
true iff io_fix equal to BUF_IO_NONE was noticed

◆ was_io_fix_read()

bool buf_page_t::was_io_fix_read ( ) const
inline

Checks if io_fix is BUF_IO_READ without requiring or acquiring any latches.

Note that this implies calling this function twice in a row could produce different results.

Returns
true iff io_fix equal to BUF_IO_READ was noticed

◆ was_io_fixed()

bool buf_page_t::was_io_fixed ( ) const
inline

Checks if io_fix is BUF_IO_FIX or BUF_IO_READ or BUF_IO_WRITE without requiring or acquiring any latches.

Note that this implies calling this function twice in a row could produce different results.

Returns
true iff io_fix not equal to BUF_IO_NONE was noticed

◆ was_stale()

bool buf_page_t::was_stale ( ) const
inline

Checks if this space reference saved during last page ID initialization was deleted or truncated since.

Returns
true when space reference stored leads was deleted or truncated and this page should be discarded. When false is returned, the status of stale is checked to be guaranteed.

Friends And Related Function Documentation

◆ Latching_rules_helpers

friend class Latching_rules_helpers
friend

Member Data Documentation

◆ access_time

std::chrono::steady_clock::time_point buf_page_t::access_time

Time of first access, or 0 if the block was never accessed in the buffer pool.

Protected by block mutex

◆ buf_fix_count

buf_fix_count_atomic_t buf_page_t::buf_fix_count

Count of how many fold this block is currently bufferfixed.

◆ buf_pool_index

uint8_t buf_page_t::buf_pool_index

Index number of the buffer pool that this block belongs to.

◆ file_page_was_freed

bool buf_page_t::file_page_was_freed

This is set to true when fsp frees a page in buffer pool; protected by buf_pool->zip_mutex or buf_block_t::mutex.

◆ flush_type

buf_flush_t buf_page_t::flush_type

If this block is currently being flushed to disk, this tells the flush_type.

See also
buf_flush_t

◆ freed_page_clock

uint32_t buf_page_t::freed_page_clock

The value of buf_pool->freed_page_clock when this block was the last time put to the head of the LRU list; a thread is allowed to read this for heuristic purposes without holding any mutex or latch.

◆ hash

buf_page_t* buf_page_t::hash

Node used in chaining to buf_pool->page_hash or buf_pool->zip_hash.

◆ id

page_id_t buf_page_t::id

Page id.

◆ in_flush_list

bool buf_page_t::in_flush_list

true if in buf_pool->flush_list; when buf_pool->flush_list_mutex is free, the following should hold: in_flush_list == (state == BUF_BLOCK_FILE_PAGE || state == BUF_BLOCK_ZIP_DIRTY) Writes to this field must be covered by both buf_pool->flush_list_mutex and block->mutex.

Hence reads can happen while holding any one of the two mutexes

◆ in_free_list

bool buf_page_t::in_free_list

true if in buf_pool->free; when buf_pool->free_list_mutex is free, the following should hold: in_free_list == (state == BUF_BLOCK_NOT_USED)

◆ in_LRU_list

bool buf_page_t::in_LRU_list

true if the page is in the LRU list; used in debugging

◆ in_page_hash

bool buf_page_t::in_page_hash

true if in buf_pool->page_hash

◆ in_zip_hash

bool buf_page_t::in_zip_hash

true if in buf_pool->zip_hash

◆ io_fix

copyable_atomic_t<buf_io_fix> buf_page_t::io_fix
private

Type of pending I/O operation.

Modified under protection of buf_page_get_mutex(this). Read under protection of rules described in

See also
Buf_io_fix_latching_rules

◆ io_responsibility

io_responsibility_t buf_page_t::io_responsibility
private

Tracks which thread is responsible for I/O on this page.

◆ m_dblwr_id

uint16_t buf_page_t::m_dblwr_id {}
private

Double write instance ordinal value during writes.

This is used by IO completion (writes) to select the double write instance.

◆ m_flush_observer

Flush_observer* buf_page_t::m_flush_observer {}

Flush observer instance.

◆ m_space

fil_space_t* buf_page_t::m_space {}

Tablespace instance that this page belongs to.

◆ m_version

uint32_t buf_page_t::m_version {}

Version of fil_space_t when the page was updated.

It can also be viewed as the truncation number.

◆ newest_modification

lsn_t buf_page_t::newest_modification
private

The flush LSN, LSN when this page was written to the redo log.

For non redo logged pages this is set using: buf_flush_borrow_lsn()

◆ old

bool buf_page_t::old

true if the block is in the old blocks in buf_pool->LRU_old

◆ oldest_modification

lsn_t buf_page_t::oldest_modification
private

log sequence number of the youngest modification to this block, zero if not modified.

Protected by block mutex

◆ size

page_size_t buf_page_t::size

Page size.

◆ state

buf_page_state buf_page_t::state

Block state.

See also
buf_page_in_file

◆ zip

page_zip_des_t buf_page_t::zip

compressed page; zip.data (but not the data it points to) is protected by buf_pool->zip_mutex; state == BUF_BLOCK_ZIP_PAGE and zip.data == NULL means an active buf_pool->watch


The documentation for this class was generated from the following files: