MySQL 26.7.0
Source Code Documentation
fil_node_t Class Reference

Node of a tablespace encapsulating handle required for any IO operations on this node. More...

#include <fil0fil.h>

Public Types

using modification_counter_t = int64_t
 
using List_node = UT_LIST_NODE_T(fil_node_t)
 

Public Member Functions

 fil_node_t (fil_space_t *space, const char *name, uint32_t node_order, bool is_raw, page_no_t size_in_pages, page_no_t max_pages, uint32_t block_size)
 
 fil_node_t (fil_node_t &&other)
 
 ~fil_node_t ()
 
bool can_be_closed () const
 Returns true if the node can be closed. More...
 
bool is_flushed () const
 Returns true if the node is fully flushed, that is it is flushed up to the modification_counter. More...
 
void pretend_is_flushed ()
 Sets node to flushed state without actually flushing it. More...
 
void increment_modification_counter ()
 Increment modification counter for this node. More...
 
bool is_flush_needed () const
 Determine if flush is needed for the node. More...
 
void wait_for_all_flushes_to_finish (class Fil_shard &shard)
 Waits for any pending flushes. More...
 
void flush (class Fil_shard &shard)
 Assures the node will be flushed at least to m_modification_counter. More...
 
bool needs_flushes_for_durability () const
 
dberr_t post_io_sync (IORequest &type, byte *buf, size_t buffer_len, page_no_t page_no) const
 Posts a synchronous READ or WRITE IO operation on the node. More...
 
dberr_t post_io_async (IORequest &type, byte *buf, size_t buffer_len, page_no_t page_no, std::function< void(dberr_t)> callback) const
 Posts an asynchronous READ or WRITE IO operation on the node. More...
 
bool is_open () const
 Returns true iff the node is currently opened and allows IO operations. More...
 
bool is_read_only () const
 Must the node be opened only for read only mode? Files can be opened for read and write, unless the srv_read_only_mode is used. More...
 
bool open ()
 Opens the node for incoming IO operations. More...
 
void close ()
 Closes the node, the IO operations will not be permitted. More...
 
bool truncate (page_no_t new_size_in_pages)
 Truncates the node. More...
 
dberr_t fill_range_with_zeros (page_no_t first_page, page_no_t number_of_pages)
 Makes the number_of_pages pages, starting with page number first_page contain all zeros. More...
 
size_t get_block_size () const
 
bool get_punch_hole () const
 Check if punch_hole is supported by storage. More...
 
void set_punch_hole (bool value)
 
page_no_t get_cached_size_in_pages () const
 
void set_cached_node_size (size_t new_pages_count_to_cache)
 In addition to updating. More...
 

Public Attributes

fil_space_t *const space
 tablespace containing this node More...
 
char * name
 file name; protected by Fil_shard::m_mutex and log_sys->mutex. More...
 
const size_t m_order
 Number of the file in the tablespace's nodes list. More...
 
const bool is_raw_disk
 whether the node actually is a raw device or disk partition More...
 
page_no_t flush_size
 Size of the node when last flushed, used to force the flush when node grows to keep the filesystem metadata synced when using O_DIRECT_NO_FSYNC. More...
 
page_no_t init_size
 initial size of the node in database pages; FIL_IBD_FILE_INITIAL_SIZE by default More...
 
const page_no_t m_max_size_in_pages
 maximum size of the node in database pages More...
 
size_t n_pending_ios {}
 count of pending I/O's; is_open must be true if nonzero More...
 
bool m_is_being_flushed {}
 Set to true when the node is being flushed. More...
 
bool is_being_extended {}
 Set to true when a node is being extended. More...
 
List_node LRU {}
 link to the fil_system->LRU list (keeping track of open files) More...
 
const size_t magic_n {FIL_NODE_MAGIC_N}
 FIL_NODE_MAGIC_N. More...
 

Private Member Functions

bool is_flush_needed (modification_counter_t flush_upto) const
 Determine if flush is needed. More...
 
void wait_for_current_flush_to_finish (class Fil_shard &shard, modification_counter_t flush_upto)
 Waits for the current flush (if any) to finish, unless the file is already flushed up to flush_upto. More...
 

Static Private Member Functions

static dberr_t map_status_io_to_db_err (ib::fil::Tablespace_node_handle_interface::Status_IO err)
 Map error code returned from read/write APIs to dberr_t code. More...
 

Private Attributes

ut::unique_ptr< ib::fil::Tablespace_node_handle_interfacem_handle {}
 file handle (not null iff is_open) More...
 
Os_event_t m_flush_finished_event {}
 event that groups and serializes calls to fsync More...
 
bool m_is_open {false}
 whether this node is open. More...
 
modification_counter_t m_modification_counter {}
 number of writes to the node since the system was started More...
 
modification_counter_t m_flush_counter {}
 the m_modification_counter of the latest flush to disk More...
 
size_t m_n_threads_waiting_for_flush {}
 number of threads waiting for chance to flush More...
 
const size_t m_block_size
 block size to use for punching holes More...
 
bool m_punch_hole {false}
 whether the file system of this node supports PUNCH HOLE More...
 
page_no_t m_cached_size_in_pages
 Size of the node in physical pages, excluding any partial last page. More...
 

Detailed Description

Node of a tablespace encapsulating handle required for any IO operations on this node.

Member Typedef Documentation

◆ List_node

◆ modification_counter_t

Constructor & Destructor Documentation

◆ fil_node_t() [1/2]

fil_node_t::fil_node_t ( fil_space_t space,
const char *  name,
uint32_t  node_order,
bool  is_raw,
page_no_t  size_in_pages,
page_no_t  max_pages,
uint32_t  block_size 
)
inline

◆ fil_node_t() [2/2]

fil_node_t::fil_node_t ( fil_node_t &&  other)
inline

◆ ~fil_node_t()

fil_node_t::~fil_node_t ( )
inline

Member Function Documentation

◆ can_be_closed()

bool fil_node_t::can_be_closed ( ) const

Returns true if the node can be closed.

◆ close()

void fil_node_t::close ( void  )

Closes the node, the IO operations will not be permitted.

It is up to the user to provide synchronization with open(), IO calls and wait for pending IO operations to finish first before calling the close.

◆ fill_range_with_zeros()

dberr_t fil_node_t::fill_range_with_zeros ( page_no_t  first_page,
page_no_t  number_of_pages 
)

Makes the number_of_pages pages, starting with page number first_page contain all zeros.

This can be used to efficiently extend the node size. It may be implemented more efficiently than actually writing buffers with zeros.

Parameters
[in]first_pageID of first page to be overwritten with zeros.
[in]number_of_pagesNumber of pages to overwrite with zeros.

◆ flush()

void fil_node_t::flush ( class Fil_shard shard)

Assures the node will be flushed at least to m_modification_counter.

Parameters
[in]shardReference to Fil_shard that will be used to release and re-acquire mutex while we are waiting for the pending flushes.

◆ get_block_size()

size_t fil_node_t::get_block_size ( ) const
inline

◆ get_cached_size_in_pages()

page_no_t fil_node_t::get_cached_size_in_pages ( ) const
inline
See also
m_cached_size_in_pages

◆ get_punch_hole()

bool fil_node_t::get_punch_hole ( ) const
inline

Check if punch_hole is supported by storage.

Returns
true if punch hole is supported, false otherwise.

◆ increment_modification_counter()

void fil_node_t::increment_modification_counter ( )

Increment modification counter for this node.

◆ is_flush_needed() [1/2]

bool fil_node_t::is_flush_needed ( ) const

Determine if flush is needed for the node.

Returns
true if flush is needed, false otherwise

◆ is_flush_needed() [2/2]

bool fil_node_t::is_flush_needed ( modification_counter_t  flush_upto) const
private

Determine if flush is needed.

Parameters
[in]flush_uptoexpectation up to which flush is to be done
Returns
true if flush is not done up to flush_upto, false otherwise

◆ is_flushed()

bool fil_node_t::is_flushed ( ) const

Returns true if the node is fully flushed, that is it is flushed up to the modification_counter.

◆ is_open()

bool fil_node_t::is_open ( ) const
inline

Returns true iff the node is currently opened and allows IO operations.

◆ is_read_only()

bool fil_node_t::is_read_only ( ) const

Must the node be opened only for read only mode? Files can be opened for read and write, unless the srv_read_only_mode is used.

With srv_read_only_mode all files are read-only, but the temporary tables, as they are not altering the physical database data, they do not generate UNDO etc, so can be used even in the read-only mode.

◆ map_status_io_to_db_err()

dberr_t fil_node_t::map_status_io_to_db_err ( ib::fil::Tablespace_node_handle_interface::Status_IO  err)
staticprivate

Map error code returned from read/write APIs to dberr_t code.

Parameters
[in]errerror code returned from read/write APIs
Returns
corresponding dberr_t error code

◆ needs_flushes_for_durability()

bool fil_node_t::needs_flushes_for_durability ( ) const
inline

◆ open()

bool fil_node_t::open ( )

Opens the node for incoming IO operations.

The node will be opened for read-only if is_read_only() returns true, and for read-write otherwise.

Returns
true if node is successfully opened

◆ post_io_async()

dberr_t fil_node_t::post_io_async ( IORequest type,
byte buf,
size_t  buffer_len,
page_no_t  page_no,
std::function< void(dberr_t)>  callback 
) const

Posts an asynchronous READ or WRITE IO operation on the node.

The operation may return error code immediately or DB_SUCCESS when the IO was submitted for asynchronous completion. After the asynchronous IO is complete, the os_aio_handler will return a reference to the current node, callback value supplied, the type and status code for the result of the IO operation.

Parameters
[in]typeIO request type, compression and encryption information.
[in,out]bufA buffer where to store read data or from where to write. Data from this buffer might be first transformed before writing it. It must be aligned in memory to OS block size (UNIV_SECTOR_SIZE). Additionally, for reads, it must be aligned to physical page size, too. The memory pointed is managed by the caller and must remain valid until the callback begins execution.
[in]buffer_lenSize of the buffer. It must not cross the node boundary; It always has to be a multiply of OS block size (UNIV_SECTOR_SIZE). In case of write of an already compressed data, it is a length of the compressed data buffer. Otherwise it should be physical page size. Actual number of bytes written can be smaller if the tablespace has compression enabled and data was not compressed already.
[in]page_noPage number where to read from or write into.
[in]callbackA callback to be called exactly once when the result of this IO operation is known. It may be a success if the read or write succeeded or a subset of dberr_t errors if the write or read could not be executed or if it failed. It can be called synchronously in this thread before returning from this method, or can be executed asynchronously from another thread, when sync is false, before or after this call returns.
Returns
DB_SUCCESS if IO was successfully posted, error code otherwise

◆ post_io_sync()

dberr_t fil_node_t::post_io_sync ( IORequest type,
byte buf,
size_t  buffer_len,
page_no_t  page_no 
) const

Posts a synchronous READ or WRITE IO operation on the node.

It is blocking call and returns the status code of the IO operation.

Parameters
[in]typeIO request type, compression and encryption information.
[in,out]bufA buffer where to store read data or from where to write. Data from this buffer might be first transformed before writing it. It must be aligned in memory to OS block size (UNIV_SECTOR_SIZE). Additionally, for reads, it must be aligned to physical page size, too. The memory pointed is managed by the caller and must remain valid until the call returns.
[in]buffer_lenSize of the buffer. It must not cross the node boundary; It always has to be a multiply of OS block size (UNIV_SECTOR_SIZE). In case of write of an already compressed data, it is a length of the compressed data buffer. Otherwise it should be physical page size. Actual number of bytes written can be smaller if the tablespace has compression enabled and data was not compressed already.
[in]page_noPage number where to read from or write into.
Returns
DB_SUCCESS on successful IO completion, otherwise error code

◆ pretend_is_flushed()

void fil_node_t::pretend_is_flushed ( )

Sets node to flushed state without actually flushing it.

◆ set_cached_node_size()

void fil_node_t::set_cached_node_size ( size_t  new_pages_count_to_cache)

In addition to updating.

See also
m_cached_size_in_pages it also updates the size of the fil_space_t it belongs to

◆ set_punch_hole()

void fil_node_t::set_punch_hole ( bool  value)
inline

◆ truncate()

bool fil_node_t::truncate ( page_no_t  new_size_in_pages)

Truncates the node.

Sets the truncated node to have size of size bytes, that are all zeroed.

Parameters
[in]new_size_in_pagesSize in pages to set the node size to after the truncation.

◆ wait_for_all_flushes_to_finish()

void fil_node_t::wait_for_all_flushes_to_finish ( class Fil_shard shard)

Waits for any pending flushes.

Parameters
[in]shardReference to Fil_shard that will be used to release and re-acquire mutex while we are waiting for the pending flushes.

◆ wait_for_current_flush_to_finish()

void fil_node_t::wait_for_current_flush_to_finish ( class Fil_shard shard,
modification_counter_t  flush_upto 
)
private

Waits for the current flush (if any) to finish, unless the file is already flushed up to flush_upto.

Parameters
[in]shardReference to Fil_shard that will be used to release and re-acquire mutex while we are waiting for the current flush to finish.
[in]flush_uptoWait until current flush finished or until m_flush_counter reached flush_upto

Member Data Documentation

◆ flush_size

page_no_t fil_node_t::flush_size

Size of the node when last flushed, used to force the flush when node grows to keep the filesystem metadata synced when using O_DIRECT_NO_FSYNC.

◆ init_size

page_no_t fil_node_t::init_size

initial size of the node in database pages; FIL_IBD_FILE_INITIAL_SIZE by default

◆ is_being_extended

bool fil_node_t::is_being_extended {}

Set to true when a node is being extended.

◆ is_raw_disk

const bool fil_node_t::is_raw_disk

whether the node actually is a raw device or disk partition

◆ LRU

List_node fil_node_t::LRU {}

link to the fil_system->LRU list (keeping track of open files)

◆ m_block_size

const size_t fil_node_t::m_block_size
private

block size to use for punching holes

◆ m_cached_size_in_pages

page_no_t fil_node_t::m_cached_size_in_pages
private

Size of the node in physical pages, excluding any partial last page.

The field is initialized with the fresh result of Tablespace_nodes_interface::get_node_info(), and updated by InnoDB whenever it is performing Fil_shard::space_truncate() or Fil_shard::space_extend(), to match the desired size. The size of the physical page is validated to flags in the tablespace header, i.e. it is impossible to continue if size of the page declared in the header doesn't match the expectation. However, the number of pages declared in the header, and cached in the m_fsp_cache.m_size_in_header, doesn't have to match m_cached_size_in_pages. In other words:

  1. m_fsp_cache.m_size_in_header matches what is in the header.
  2. m_cached_size_in_pages matches what Tablespace_nodes_interface last said, about the real length of the tablespace (until we extend the space, in which case we increase m_cached_size_in_pages to match the new size and an answer Tablespace_nodes_interface would give if we asked it).

◆ m_flush_counter

modification_counter_t fil_node_t::m_flush_counter {}
private

the m_modification_counter of the latest flush to disk

◆ m_flush_finished_event

Os_event_t fil_node_t::m_flush_finished_event {}
private

event that groups and serializes calls to fsync

◆ m_handle

file handle (not null iff is_open)

◆ m_is_being_flushed

bool fil_node_t::m_is_being_flushed {}

Set to true when the node is being flushed.

◆ m_is_open

bool fil_node_t::m_is_open {false}
private

whether this node is open.

◆ m_max_size_in_pages

const page_no_t fil_node_t::m_max_size_in_pages

maximum size of the node in database pages

◆ m_modification_counter

modification_counter_t fil_node_t::m_modification_counter {}
private

number of writes to the node since the system was started

◆ m_n_threads_waiting_for_flush

size_t fil_node_t::m_n_threads_waiting_for_flush {}
private

number of threads waiting for chance to flush

◆ m_order

const size_t fil_node_t::m_order

Number of the file in the tablespace's nodes list.

◆ m_punch_hole

bool fil_node_t::m_punch_hole {false}
private

whether the file system of this node supports PUNCH HOLE

◆ magic_n

const size_t fil_node_t::magic_n {FIL_NODE_MAGIC_N}

FIL_NODE_MAGIC_N.

◆ n_pending_ios

size_t fil_node_t::n_pending_ios {}

count of pending I/O's; is_open must be true if nonzero

◆ name

char* fil_node_t::name

file name; protected by Fil_shard::m_mutex and log_sys->mutex.

◆ space

fil_space_t* const fil_node_t::space

tablespace containing this node


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