MySQL 8.3.0
Source Code Documentation
Log_file_handle Class Reference

Handle which allows to do reads / writes for the opened file. More...

#include <log0types.h>

Static Public Member Functions

static uint64_t fsyncs_in_progress ()
 
static uint64_t total_fsyncs ()
 

Private Member Functions

 Log_file_handle (const Log_file_handle &other)=delete
 
Log_file_handleoperator= (const Log_file_handle &rhs)=delete
 

Private Attributes

Log_file_id m_file_id
 Id of the redo log file (part of its file name) More...
 
Log_file_access_mode m_access_mode
 Access mode allowed for this handle (if not yet closed). More...
 
Encryption_metadatam_encryption_metadata
 Encryption metadata to be used for all IO operations on this file except those related to the first LOG_FILE_HDR_SIZE bytes. More...
 
Log_file_type m_file_type
 Type of redo log file. More...
 
bool m_is_open
 Whether file is opened. More...
 
bool m_is_modified
 Whether file has been modified using this handle since it was opened. More...
 
std::string m_file_path
 File name. More...
 
pfs_os_file_t m_raw_handle
 OS handle for file (if opened) More...
 
os_offset_t m_block_size
 Size of single physical block (if opened) More...
 
os_offset_t m_file_size
 Size of file in bytes (if opened) More...
 

Friends

struct Log_file
 

Log_file_handle implementation

static Log_file_io_callback s_on_before_read
 Callback called on each read operation. More...
 
static Log_file_io_callback s_on_before_write
 Callback called on each write operation. More...
 
static bool s_skip_fsyncs = false
 True iff all fsyncs should be no-op. More...
 
static std::atomic< size_t > s_n_open {0}
 Number of all opened Log_file_handle existing currently. More...
 
static std::atomic< uint64_t > s_fsyncs_in_progress {0}
 Number of fsyncs in-progress. More...
 
static std::atomic< uint64_t > s_total_fsyncs {0}
 Total number of fsyncs that have been started since the server has started. More...
 
 Log_file_handle (Encryption_metadata &encryption_metadata)
 
 Log_file_handle (Log_file_handle &&other)
 
Log_file_handleoperator= (Log_file_handle &&rhs)
 
 ~Log_file_handle ()
 Closes handle if was opened (calling fsync if was modified). More...
 
bool is_open () const
 
void close ()
 Closes file represented by this handle (must be opened). More...
 
Log_file_id file_id () const
 
const std::string & file_path () const
 
os_offset_t file_size () const
 
dberr_t read (os_offset_t read_offset, os_offset_t read_size, byte *buf)
 Reads from the log file at the given offset (to the provided buffer). More...
 
dberr_t write (os_offset_t write_offset, os_offset_t write_size, const byte *buf)
 Writes the provided buffer to the log file at the given offset. More...
 
void fsync ()
 Executes fsync operation for this redo log file. More...
 
 Log_file_handle (const Log_files_context &files_ctx, Log_file_id id, Log_file_access_mode access_mode, Encryption_metadata &encryption_metadata, Log_file_type file_type)
 Tries to open a given redo log file with with a given access mode. More...
 
dberr_t open ()
 Open the log file with the configured access mode. More...
 
IORequest prepare_io_request (int req_type, os_offset_t offset, os_offset_t size, bool can_use_encryption)
 Creates and configures an io request object according to currently configured encryption metadata (m_encryption_*) and m_block_size. More...
 

Detailed Description

Handle which allows to do reads / writes for the opened file.

For particular kind of reads or writes (for checkpoint headers, data blocks, main file header or encryption header) there are helper functions defined outside this class. Unless you wanted to transfer the whole file as-is, you should rather use those functions for read/write operations.

Constructor & Destructor Documentation

◆ Log_file_handle() [1/4]

Log_file_handle::Log_file_handle ( Encryption_metadata encryption_metadata)
explicit

◆ Log_file_handle() [2/4]

Log_file_handle::Log_file_handle ( Log_file_handle &&  other)

◆ ~Log_file_handle()

Log_file_handle::~Log_file_handle ( )

Closes handle if was opened (calling fsync if was modified).

Destructs the handle object.

◆ Log_file_handle() [3/4]

Log_file_handle::Log_file_handle ( const Log_files_context files_ctx,
Log_file_id  id,
Log_file_access_mode  access_mode,
Encryption_metadata encryption_metadata,
Log_file_type  file_type 
)
private

Tries to open a given redo log file with with a given access mode.

If succeeded then this handle represents the opened file and allows to performs reads and/or writes (depends on the requested access mode). If encountered error during the attempt to open, error message is emitted to the error log, in which case this handle remains closed.

Parameters
[in]files_ctxcontext within which files exist
[in]idid of the log file
[in]access_modeaccess mode for the opened file
[in]encryption_metadataencryption metadata
[in]file_typetype of redo file

◆ Log_file_handle() [4/4]

Log_file_handle::Log_file_handle ( const Log_file_handle other)
privatedelete

Member Function Documentation

◆ close()

void Log_file_handle::close ( void  )

Closes file represented by this handle (must be opened).

◆ file_id()

Log_file_id Log_file_handle::file_id ( ) const
Returns
id of the log file

◆ file_path()

const std::string & Log_file_handle::file_path ( ) const
Returns
path to the log file (including the file name)

◆ file_size()

os_offset_t Log_file_handle::file_size ( ) const
Returns
file size in bytes

◆ fsync()

void Log_file_handle::fsync ( )

Executes fsync operation for this redo log file.

◆ fsyncs_in_progress()

static uint64_t Log_file_handle::fsyncs_in_progress ( )
inlinestatic
Returns
number of fsyncs in-progress

◆ is_open()

bool Log_file_handle::is_open ( ) const
Returns
true iff file is opened (by this handle)

◆ open()

dberr_t Log_file_handle::open ( )
private

Open the log file with the configured access mode.

Returns
DB_SUCCESS or error

◆ operator=() [1/2]

Log_file_handle & Log_file_handle::operator= ( const Log_file_handle rhs)
privatedelete

◆ operator=() [2/2]

Log_file_handle & Log_file_handle::operator= ( Log_file_handle &&  rhs)

◆ prepare_io_request()

IORequest Log_file_handle::prepare_io_request ( int  req_type,
os_offset_t  offset,
os_offset_t  size,
bool  can_use_encryption 
)
private

Creates and configures an io request object according to currently configured encryption metadata (m_encryption_*) and m_block_size.

Parameters
[in]req_typedefines type of IO operation (read or write)
[in]offsetoffset in bytes from the beginning of the file
[in]sizenumber of bytes to write or read
[in]can_use_encryptione.g. whether newly blocks should be encrypted
Returns
IORequest instance

◆ read()

dberr_t Log_file_handle::read ( os_offset_t  read_offset,
os_offset_t  read_size,
byte buf 
)

Reads from the log file at the given offset (to the provided buffer).

Parameters
[in]read_offsetoffset in bytes from the beginning of the file
[in]read_sizenumber of bytes to read
[out]bufallocated buffer to fill when reading
Returns
DB_SUCCESS or error

◆ total_fsyncs()

static uint64_t Log_file_handle::total_fsyncs ( )
inlinestatic
Returns
total number of fsyncs that have been started since the server has started

◆ write()

dberr_t Log_file_handle::write ( os_offset_t  write_offset,
os_offset_t  write_size,
const byte buf 
)

Writes the provided buffer to the log file at the given offset.

Parameters
[in]write_offsetoffset in bytes from the beginning of the file
[in]write_sizenumber of bytes to write
[in]bufbuffer to write
Returns
DB_SUCCESS or error

Friends And Related Function Documentation

◆ Log_file

friend struct Log_file
friend

Member Data Documentation

◆ m_access_mode

Log_file_access_mode Log_file_handle::m_access_mode
private

Access mode allowed for this handle (if not yet closed).

◆ m_block_size

os_offset_t Log_file_handle::m_block_size
private

Size of single physical block (if opened)

◆ m_encryption_metadata

Encryption_metadata& Log_file_handle::m_encryption_metadata
private

Encryption metadata to be used for all IO operations on this file except those related to the first LOG_FILE_HDR_SIZE bytes.

Remarks
If Encryption::set_key() and Encryption::set_initial_vector() started to accept their arguments as const pointers, this could become a const pointer too). In such case, all usages of Encryption_metadata* inside redo log code, could also become changed to usages of the const pointer.

◆ m_file_id

Log_file_id Log_file_handle::m_file_id
private

Id of the redo log file (part of its file name)

◆ m_file_path

std::string Log_file_handle::m_file_path
private

File name.

◆ m_file_size

os_offset_t Log_file_handle::m_file_size
private

Size of file in bytes (if opened)

◆ m_file_type

Log_file_type Log_file_handle::m_file_type
private

Type of redo log file.

◆ m_is_modified

bool Log_file_handle::m_is_modified
private

Whether file has been modified using this handle since it was opened.

◆ m_is_open

bool Log_file_handle::m_is_open
private

Whether file is opened.

◆ m_raw_handle

pfs_os_file_t Log_file_handle::m_raw_handle
private

OS handle for file (if opened)

◆ s_fsyncs_in_progress

std::atomic< uint64_t > Log_file_handle::s_fsyncs_in_progress {0}
staticprivate

Number of fsyncs in-progress.

◆ s_n_open

std::atomic< size_t > Log_file_handle::s_n_open {0}
staticprivate

Number of all opened Log_file_handle existing currently.

◆ s_on_before_read

Log_file_io_callback Log_file_handle::s_on_before_read
static

Callback called on each read operation.

◆ s_on_before_write

Log_file_io_callback Log_file_handle::s_on_before_write
static

Callback called on each write operation.

◆ s_skip_fsyncs

bool Log_file_handle::s_skip_fsyncs = false
static

True iff all fsyncs should be no-op.

◆ s_total_fsyncs

std::atomic< uint64_t > Log_file_handle::s_total_fsyncs {0}
staticprivate

Total number of fsyncs that have been started since the server has started.


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