MySQL 26.7.0
Source Code Documentation
ib::fil::Tablespace_node_handle Class Referencefinal

#include <fil0innodb_tablespace_node_handle.h>

Inheritance diagram for ib::fil::Tablespace_node_handle:
[legend]

Public Member Functions

 Tablespace_node_handle (pfs_os_file_t handle, const std::string &file_name, space_id_t space_id, size_t page_size, size_t node_order)
 
 ~Tablespace_node_handle () override
 
bool needs_flushes_for_durability () const override
 Returns true if the node must be flushed in general to ensure data durability. More...
 
Status flush () override
 Ensures any data written so far to this tablespace node before this call will be made durable and will survive either software or hardware crash. More...
 
Status truncate (Page_number size) override
 Truncate the node storage to the given size. More...
 
Status fill_range_with_zeros (Page_number first_page, Page_number number_of_pages, bool optimize_writes) override
 Makes the number_of_pages pages, starting with page number first_page contain all zeros. More...
 
Status_IO read_page (IORequest req, byte *buffer, Page_number page_no) override
 Reads a requested page synchronously. More...
 
Status_IO read_page_async (IORequest req, byte *buffer, Page_number page_no, Callback callback) override
 Reads a requested page asynchronously. More...
 
Status_IO write_page (IORequest req, byte *buffer, size_t buffer_len, Page_number page_no) override
 Writes a requested page synchronously. More...
 
Status_IO write_page_async (IORequest req, byte *buffer, size_t buffer_len, Page_number page_no, Callback callback) override
 Writes a requested page asynchronously. More...
 
- Public Member Functions inherited from ib::fil::Tablespace_node_handle_interface
virtual ~Tablespace_node_handle_interface ()=default
 Closes the opened node handle. More...
 

Private Member Functions

void retry_read_a_few_times_if_page_id_seems_wrong (IORequest req, uint64_t offset, byte *buffer, page_no_t page_no, dberr_t &io_result)
 Checks if the page read by a successful asynchronous read contains the space and page IDs that were meant to be read and in case they are not, try a few times to read them synchronously from disk. More...
 

Static Private Member Functions

static Status_IO map_db_err_to_status_io (dberr_t err)
 Maps DB error code to Status_IO error code. More...
 

Private Attributes

const pfs_os_file_t m_handle
 Opened tablespace file handle. More...
 
const std::string m_file_name
 Tablespace file name. More...
 
const space_id_t m_space_id
 Tablespace ID. More...
 
const size_t m_physical_page_size
 Physical size of a page. More...
 
const size_t m_node_order
 Number of the node in the tablespace. More...
 

Additional Inherited Members

- Public Types inherited from ib::fil::Tablespace_node_handle_interface
enum class  Status { SUCCESS = 0 , IO_ERROR }
 
enum class  Status_IO {
  SUCCESS = 0 , IO_DECRYPT_FAIL , CORRUPTION , IO_OVERFLOW ,
  OUT_OF_MEMORY , IO_DECOMPRESS_FAIL , IO_NO_PUNCH_HOLE , UNSUPPORTED ,
  IO_ERROR
}
 
using byte = unsigned char
 
using Page_number = uint32_t
 Type used for numbering the pages in the node. More...
 
using Callback = std::function< void(dberr_t io_result)>
 

Constructor & Destructor Documentation

◆ Tablespace_node_handle()

ib::fil::Tablespace_node_handle::Tablespace_node_handle ( pfs_os_file_t  handle,
const std::string &  file_name,
space_id_t  space_id,
size_t  page_size,
size_t  node_order 
)

◆ ~Tablespace_node_handle()

ib::fil::Tablespace_node_handle::~Tablespace_node_handle ( )
override

Member Function Documentation

◆ fill_range_with_zeros()

Tablespace_node_handle::Status ib::fil::Tablespace_node_handle::fill_range_with_zeros ( Page_number  first_page,
Page_number  number_of_pages,
bool  optimize_writes 
)
overridevirtual

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

This can be use to efficiently extend the node size. It may be implemented more efficiently than actually writing buffers with zeros, but only if optimize_writes is set to true.

Parameters
[in]first_pageNumber of page in node from to be overwritten with zeros.
[in]number_of_pagesNumber of pages to overwrite with zeros.
[in]optimize_writesIf true the implementation can use faster and possibly less robust way to zero the range.
Returns
SUCCESS if zeroed successfully, error code otherwise.

Implements ib::fil::Tablespace_node_handle_interface.

◆ flush()

Tablespace_node_handle::Status ib::fil::Tablespace_node_handle::flush ( )
overridevirtual

Ensures any data written so far to this tablespace node before this call will be made durable and will survive either software or hardware crash.

Implements ib::fil::Tablespace_node_handle_interface.

◆ map_db_err_to_status_io()

Tablespace_node_handle::Status_IO ib::fil::Tablespace_node_handle::map_db_err_to_status_io ( dberr_t  err)
staticprivate

Maps DB error code to Status_IO error code.

◆ needs_flushes_for_durability()

bool ib::fil::Tablespace_node_handle::needs_flushes_for_durability ( ) const
overridevirtual

Returns true if the node must be flushed in general to ensure data durability.

Returns
true if flush is needed, false otherwise.

Implements ib::fil::Tablespace_node_handle_interface.

◆ read_page()

Tablespace_node_handle::Status_IO ib::fil::Tablespace_node_handle::read_page ( IORequest  req,
byte buffer,
Page_number  page_no 
)
overridevirtual

Reads a requested page synchronously.

Before the page is returned, the page will be decrypted and decompressed, depending on information present in the page header.

The size of the buffer in bytes should be at least the tablespace physical page size which was passed to tablespaces_nodes::open() or calculated from flags passed to tablespaces_nodes::create().

Parameters
[in]reqIO request type, compression and encryption information.
[out]bufferA buffer where to read the data in. It must be aligned in memory to physical page size. It must be able to store physical page size bytes. The memory pointed is managed by the caller and must remain valid until the call finishes. TODO : buffer to be replaced with std::span.
[in]page_noOffset from the first page in the node to read from.
Returns
Status_IO::SUCCESS on successful read, otherwise error code

Implements ib::fil::Tablespace_node_handle_interface.

◆ read_page_async()

Tablespace_node_handle::Status_IO ib::fil::Tablespace_node_handle::read_page_async ( IORequest  req,
byte buffer,
Page_number  page_no,
Callback  callback 
)
overridevirtual

Reads a requested page asynchronously.

After the operation is completed, successfully or not, the callback is called with the result error code, probably in a different thread. If the request is successful, it will always be called from a different thread in context that has no latches taken.

Before the page is returned, the page will be decrypted and decompressed, depending on information present in the page header.

The size of the buffer in bytes should be at least the tablespace physical page size which was passed to tablespaces_nodes::open() or calculated from flags passed to tablespaces_nodes::create().

Parameters
[in]reqIO request type, compression and encryption information.
[out]bufferA buffer where to read the data in. It must be aligned in memory to physical page size. It must be able to store physical page size bytes. The memory pointed is managed by the caller and must remain valid until the callback is being called. TODO : buffer to be replaced with std::span.
[in]page_noOffset from the first page in the node to read from.
[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 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
Status_IO::SUCCESS if IO was successfully posted, error code otherwise

Implements ib::fil::Tablespace_node_handle_interface.

◆ retry_read_a_few_times_if_page_id_seems_wrong()

void ib::fil::Tablespace_node_handle::retry_read_a_few_times_if_page_id_seems_wrong ( IORequest  req,
uint64_t  offset,
byte buffer,
page_no_t  page_no,
dberr_t io_result 
)
private

Checks if the page read by a successful asynchronous read contains the space and page IDs that were meant to be read and in case they are not, try a few times to read them synchronously from disk.

Parameters
[in]reqIO request.
[in]offsetAn offset in bytes in the tablespace the read was requested for.
[out]bufferA buffer where to read the data in.
[in]page_noOffset from the first page in the node to read from.
[in,out]io_resultReference to the error code of the IO operation, it will be have the value changed to result of last read IO operation executed.

◆ truncate()

Tablespace_node_handle::Status ib::fil::Tablespace_node_handle::truncate ( Page_number  size)
overridevirtual

Truncate the node storage to the given size.

Parameters
[in]sizeExpected size in pages of node after truncation. If the size provided is more than or equal to the current size of the node storage, return success.
Returns
SUCCESS if truncated successfully, error code otherwise.

Implements ib::fil::Tablespace_node_handle_interface.

◆ write_page()

Tablespace_node_handle::Status_IO ib::fil::Tablespace_node_handle::write_page ( IORequest  req,
byte buffer,
size_t  buffer_len,
Page_number  page_no 
)
overridevirtual

Writes a requested page synchronously.

The page will be encrypted and compressed, below this implementation depending on information present in the page header.

If punch hole is supported and requested, this API implementation punches the hole depending on input buffer compression metadata (check Punch Hole Optimization), the capability of Implementation and settings in IORequest.

If compression/encryption is to be done, the input buffer may be modified accordingly with post encryption/compression metadata (eg : Page type, compression info).

The size of the buffer in bytes should be at most the tablespaces physical page size which was passed to tablespaces_nodes::open() or calculated from flags passed to tablespaces_nodes::create(). In other words, buffer_len must not be greater than the tablespace physical page size. In case of punch hole, the buffer_len can be less than physical page size but it must be divisible by 512. And the buffer will be written out and rest of the page will be hole-punched.

Parameters
[in]reqIO request type, compression and encryption information.
[out]bufferA buffer containing the data to be written. Data from this buffer might be copied and the copy transformed before writing it. It must be aligned in memory to the OS block size (UNIV_SECTOR_SIZE). The memory pointed is managed by the caller and must remain valid until the call returns.
[in]buffer_lenSize of the buffer to be written. 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. TODO : buffer and buffer_len to be replaced with std::span.
[in]page_noOffset from the first page in the node to write to.
Returns
Status_IO::SUCCESS on successful write, otherwise error code

Implements ib::fil::Tablespace_node_handle_interface.

◆ write_page_async()

Tablespace_node_handle::Status_IO ib::fil::Tablespace_node_handle::write_page_async ( IORequest  req,
byte buffer,
size_t  buffer_len,
Page_number  page_no,
Callback  callback 
)
overridevirtual

Writes a requested page asynchronously.

After the operation is completed, successfully or not, the callback is called with the result error code, probably in a different thread. If the request is successful, it will always be called from a different thread in context that has no latches taken.

The page will be encrypted and compressed, below this implementation depending on information present in the page header.

If punch hole is supported and requested, this API implementation punches the hole depending on input buffer compression metadata (check Punch Hole Optimization), the capability of Implementation and settings in IORequest.

If compression/encryption is to be done, the input buffer may be modified accordingly with post encryption/compression metadata (eg : Page type, compression info).

The size of the buffer in bytes should be at most the tablespaces physical page size which was passed to tablespaces_nodes::open() or calculated from flags passed to tablespaces_nodes::create(). In other words, buffer_len must not be greater than the tablespace physical page size. In case of punch hole, the buffer_len can be less than physical page size but it must be divisible by 512. And the buffer will be written out and rest of the page will be hole-punched.

Parameters
[in]reqIO request type, compression and encryption information.
[out]bufferA buffer containing the data to be written. Data from this buffer might be copied and the copy transformed before writing it. It must be aligned in memory to the OS block size (UNIV_SECTOR_SIZE). The memory pointed is managed by the caller and must remain valid until the callback is being called.
[out]buffer_lenSize of the buffer to be written. It must be aligned to 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. TODO : buffer and buffer_len to be replaced with std::span.
[in]page_noOffset from the first page in the node to write to.
[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 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
Status_IO::SUCCESS if IO was successfully posted, error code otherwise

Implements ib::fil::Tablespace_node_handle_interface.

Member Data Documentation

◆ m_file_name

const std::string ib::fil::Tablespace_node_handle::m_file_name
private

Tablespace file name.

◆ m_handle

const pfs_os_file_t ib::fil::Tablespace_node_handle::m_handle
private

Opened tablespace file handle.

◆ m_node_order

const size_t ib::fil::Tablespace_node_handle::m_node_order
private

Number of the node in the tablespace.

◆ m_physical_page_size

const size_t ib::fil::Tablespace_node_handle::m_physical_page_size
private

Physical size of a page.

Needed to calculate the file offset for I/O.

◆ m_space_id

const space_id_t ib::fil::Tablespace_node_handle::m_space_id
private

Tablespace ID.


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