MySQL 9.1.0
Source Code Documentation
|
The log0files_io. More...
#include <string>
#include "log0types.h"
#include "mach0data.h"
#include "ut0crc32.h"
#include "ut0new.h"
Go to the source code of this file.
Functions | |
bool | log_header_checksum_is_ok (const byte *buf) |
Computes checksum of the given header and verifies if the checksum is the same as the one stored in that header. More... | |
Log - file header read/write. | |
void | log_file_header_serialize (const Log_file_header &header, byte *buf) |
Serializes the log file header to the buffer. More... | |
bool | log_file_header_deserialize (const byte *buf, Log_file_header &header) |
Deserializes the log file header stored in the buffer. More... | |
dberr_t | log_file_header_write (Log_file_handle &file_handle, const Log_file_header &header) |
Serializes and writes the log file header to the log file. More... | |
dberr_t | log_file_header_write (Log_file_handle &file_handle, const byte *buf) |
Writes the serialized log file header to the log file. More... | |
dberr_t | log_file_header_read (Log_file_handle &file_handle, byte *buf) |
Reads the serialized log file header to the buffer. More... | |
dberr_t | log_file_header_read (Log_file_handle &file_handle, Log_file_header &header) |
Reads and deserializes the log file header. More... | |
void | log_file_header_set_flag (Log_flags &log_flags, uint32_t bit) |
Sets a specific flag in the mask built of redo log flags. More... | |
void | log_file_header_reset_flag (Log_flags &log_flags, uint32_t bit) |
Resets a specific flag in the mask built of redo log flags. More... | |
bool | log_file_header_check_flag (Log_flags log_flags, uint32_t bit) |
Checks if a specific flag is set in the mask built of redo log flags. More... | |
Log - encryption header read/write. | |
dberr_t | log_encryption_header_write (Log_file_handle &file_handle, const byte *buf) |
Writes the serialized encryption meta data to the log file. More... | |
dberr_t | log_encryption_header_read (Log_file_handle &file_handle, byte *buf) |
Reads the serialized encryption meta data from the log file. More... | |
Log - checkpoint header read/write. | |
void | log_checkpoint_header_serialize (const Log_checkpoint_header &header, byte *buf) |
Serializes the log checkpoint header to the buffer. More... | |
bool | log_checkpoint_header_deserialize (const byte *buf, Log_checkpoint_header &header) |
Deserializes the log checkpoint header stored in the buffer. More... | |
dberr_t | log_checkpoint_header_write (Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no, const Log_checkpoint_header &header) |
Serializes and writes the log checkpoint header to the log file. More... | |
dberr_t | log_checkpoint_header_write (Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no, const byte *buf) |
Writes the serialized checkpoint header to the log file. More... | |
dberr_t | log_checkpoint_header_read (Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no, byte *buf) |
Reads the serialized log checkpoint header to the buffer. More... | |
dberr_t | log_checkpoint_header_read (Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no, Log_checkpoint_header &header) |
Reads and deserializes the log checkpoint header. More... | |
Log functions - data blocks read/write. | |
dberr_t | log_data_blocks_write (Log_file_handle &file_handle, os_offset_t write_offset, size_t write_size, const byte *buf) |
Writes the formatted log blocks with redo records to the log file. More... | |
dberr_t | log_data_blocks_read (Log_file_handle &file_handle, os_offset_t read_offset, size_t read_size, byte *buf) |
Reads log blocks with redo records from the log file, starting at the given offset. More... | |
Log - files creation/deletion, path computation. | |
std::string | log_directory_path (const Log_files_context &ctx) |
Provides path to directory with redo log files. More... | |
std::string | log_file_name (const Log_files_context &ctx, Log_file_id file_id) |
Provides name of the log file with the given file id, e.g. More... | |
std::string | log_file_path (const Log_files_context &ctx, Log_file_id file_id) |
Provides full path to the log file, e.g. More... | |
std::string | log_file_path_for_unused_file (const Log_files_context &ctx, Log_file_id file_id) |
Provides full path to the temporary log file, e.g. More... | |
dberr_t | log_list_existing_files (const Log_files_context &ctx, ut::vector< Log_file_id > &ret) |
List existing log files in the directory (does not include unused files). More... | |
dberr_t | log_list_existing_unused_files (const Log_files_context &ctx, ut::vector< Log_file_id > &ret) |
List existing unused log files in the directory. More... | |
dberr_t | log_rename_unused_file (const Log_files_context &ctx, Log_file_id old_unused_file_id, Log_file_id new_unused_file_id) |
Renames the unused file to another unused file. More... | |
dberr_t | log_mark_file_as_in_use (const Log_files_context &ctx, Log_file_id file_id) |
Renames a temporary log file to the non-temporary log file. More... | |
dberr_t | log_mark_file_as_unused (const Log_files_context &ctx, Log_file_id file_id) |
Renames a non-temporary log file to the temporary log file. More... | |
dberr_t | log_remove_unused_file (const Log_files_context &ctx, Log_file_id file_id) |
Removes a temporary log file, if it existed. More... | |
std::pair< dberr_t, ut::vector< Log_file_id > > | log_remove_unused_files (const Log_files_context &ctx) |
Removes all temporary log files in the directory. More... | |
dberr_t | log_remove_file (const Log_files_context &ctx, Log_file_id file_id) |
Removes a log file, if it existed. More... | |
std::pair< dberr_t, Log_file_id > | log_remove_file (const Log_files_context &ctx) |
Removes a single existing log file (if it existed). More... | |
std::pair< dberr_t, ut::vector< Log_file_id > > | log_remove_files (const Log_files_context &ctx) |
Removes existing log files. More... | |
dberr_t | log_create_unused_file (const Log_files_context &ctx, Log_file_id file_id, os_offset_t size_in_bytes) |
Creates a new temporary log file and resizes the file to the given size. More... | |
dberr_t | log_resize_unused_file (const Log_files_context &ctx, Log_file_id file_id, os_offset_t size_in_bytes) |
Resizes an existing temporary log file to the given size. More... | |
dberr_t | log_resize_file (const Log_files_context &ctx, Log_file_id file_id, os_offset_t size_in_bytes) |
Resizes an existing log file to the given size. More... | |
dberr_t | log_collect_existing_files (const Log_files_context &ctx, bool read_only, ut::vector< Log_file_id_and_size > &found) |
Searches for all possible log files existing on disk in the log directory. More... | |
Log_uuid | log_generate_uuid () |
Generate unique identifier for the redo log files. More... | |
Log - log blocks format. | |
uint32_t | log_block_get_hdr_no (const byte *log_block) |
Gets a log block number stored in the header. More... | |
void | log_block_set_hdr_no (byte *log_block, uint32_t n) |
Sets the log block number stored in the header. More... | |
uint32_t | log_block_get_data_len (const byte *log_block) |
Gets a log block data length. More... | |
void | log_block_set_data_len (byte *log_block, uint32_t len) |
Sets the log block data length. More... | |
uint32_t | log_block_get_first_rec_group (const byte *log_block) |
Gets an offset to the beginning of the first group of log records in a given log block. More... | |
void | log_block_set_first_rec_group (byte *log_block, uint32_t offset) |
Sets an offset to the beginning of the first group of log records in a given log block. More... | |
uint32_t | log_block_get_epoch_no (const byte *log_block) |
Gets a log block epoch_no. More... | |
void | log_block_set_epoch_no (byte *log_block, uint32_t no) |
Sets a log block epoch_no. More... | |
uint32_t | log_block_convert_lsn_to_epoch_no (lsn_t lsn) |
Converts a lsn to a log block epoch number. More... | |
uint32_t | log_block_convert_lsn_to_hdr_no (lsn_t lsn) |
Converts a lsn to a log block number. More... | |
uint32_t | log_block_calc_checksum (const byte *log_block) |
Calculates the checksum for a log block. More... | |
uint32_t | log_block_calc_checksum_crc32 (const byte *log_block) |
Calculates the checksum for a log block using the MySQL 5.7 algorithm. More... | |
uint32_t | log_block_calc_checksum_none (const byte *) |
Calculates the checksum for a log block using the "no-op" algorithm. More... | |
uint32_t | log_block_get_checksum (const byte *log_block) |
Gets value of a log block checksum field. More... | |
void | log_block_set_checksum (byte *log_block, uint32_t checksum) |
Sets value of a log block checksum field. More... | |
void | log_block_store_checksum (byte *log_block) |
Stores a 4-byte checksum to the trailer checksum field of a log block. More... | |
bool | log_block_get_encrypt_bit (const byte *log_block) |
Gets value of a log block encrypt bit (true or false). More... | |
void | log_block_set_encrypt_bit (byte *log_block, bool val) |
Sets value of a log block encrypt bit (true or false). More... | |
void | log_data_block_header_serialize (const Log_data_block_header &header, byte *buf) |
Serializes the log data block header to the redo log block buffer which already contains redo log data (must have the redo data before this call). More... | |
bool | log_data_block_header_deserialize (const byte *buf, Log_data_block_header &header) |
Deserializes the log data block header stored in the buffer. More... | |
Variables | |
Log_checksum_algorithm_atomic_ptr | log_checksum_algorithm_ptr |
Atomic pointer to the log checksum calculation function. More... | |
The log0files_io.
{cc,h} is a low-level independent library for IO operations performed directly on redo log files.
The library provides functions which allow to:
NOTE: Parsing of individual redo records is NOT in scope of this library.
Main goal for this library is to make IO operations simpler, no matter what is the motivation behind reading or writing fragments of redo log files.
That's why:
Functions that operate on set of redo files are also part of this library. This includes functions to:
|
inline |
Calculates the checksum for a log block.
[in] | log_block | log block |
|
inline |
Calculates the checksum for a log block using the MySQL 5.7 algorithm.
[in] | log_block | log block |
|
inline |
Calculates the checksum for a log block using the "no-op" algorithm.
|
inline |
Converts a lsn to a log block epoch number.
For details
[in] | lsn | lsn of a byte within the block |
|
inline |
Converts a lsn to a log block number.
Consecutive log blocks have consecutive numbers (unless the sequence wraps). It is guaranteed that the calculated number is greater than zero.
[in] | lsn | lsn of a byte within the block |
|
inline |
Gets value of a log block checksum field.
[in] | log_block | log block |
|
inline |
Gets a log block data length.
[in] | log_block | log block |
|
inline |
Gets value of a log block encrypt bit (true or false).
[in] | log_block | log block |
|
inline |
Gets a log block epoch_no.
For details:
[in] | log_block | log block |
|
inline |
Gets an offset to the beginning of the first group of log records in a given log block.
[in] | log_block | log block |
|
inline |
Gets a log block number stored in the header.
The number corresponds to lsn range for data stored in the block.
During recovery, when a next block is being parsed, a next range of lsn values is expected to be read. This corresponds to a log block number increased by one (modulo LOG_BLOCK_MAX_NO). However, if an unexpected number is read from the header, it is then considered the end of the redo log and recovery is finished. In such case, the next block is most likely an empty block or a block from the past, because the redo log files might be reused.
[in] | log_block | log block (may be invalid or empty block) |
|
inline |
Sets value of a log block checksum field.
[in,out] | log_block | log block |
[in] | checksum | checksum |
|
inline |
Sets the log block data length.
[in,out] | log_block | log block |
[in] | len | data length ( |
|
inline |
Sets value of a log block encrypt bit (true or false).
[in] | log_block | log block to modify |
[in] | val | the value to set (true or false) |
|
inline |
Sets a log block epoch_no.
For details:
[in,out] | log_block | log block |
[in] | no | epoch number |
|
inline |
Sets an offset to the beginning of the first group of log records in a given log block.
[in,out] | log_block | log block |
[in] | offset | offset, 0 if none |
|
inline |
Sets the log block number stored in the header.
NOTE that this must be set before the flush bit!
[in,out] | log_block | log block |
[in] | n | log block number: must be in (0, 1G] |
|
inline |
Stores a 4-byte checksum to the trailer checksum field of a log block.
This is used before writing the log block to disk. The checksum in a log block is used in recovery to check the consistency of the log block.
[in] | log_block | log block (completely filled in!) |
bool log_checkpoint_header_deserialize | ( | const byte * | buf, |
Log_checkpoint_header & | header | ||
) |
Deserializes the log checkpoint header stored in the buffer.
[in] | buf | the buffer to deserialize |
[out] | header | the deserialized header |
dberr_t log_checkpoint_header_read | ( | Log_file_handle & | file_handle, |
Log_checkpoint_header_no | checkpoint_header_no, | ||
byte * | buf | ||
) |
Reads the serialized log checkpoint header to the buffer.
[in] | file_handle | handle for the opened log file |
[in] | checkpoint_header_no | checkpoint header to read |
[out] | buf | the allocated buffer for read |
dberr_t log_checkpoint_header_read | ( | Log_file_handle & | file_handle, |
Log_checkpoint_header_no | checkpoint_header_no, | ||
Log_checkpoint_header & | header | ||
) |
Reads and deserializes the log checkpoint header.
[in] | file_handle | handle for the opened log file |
[in] | checkpoint_header_no | checkpoint header to read |
[out] | header | the checkpoint header read |
void log_checkpoint_header_serialize | ( | const Log_checkpoint_header & | header, |
byte * | buf | ||
) |
Serializes the log checkpoint header to the buffer.
[in] | header | the header to serialize |
[out] | buf | the allocated buffer |
dberr_t log_checkpoint_header_write | ( | Log_file_handle & | file_handle, |
Log_checkpoint_header_no | checkpoint_header_no, | ||
const byte * | buf | ||
) |
Writes the serialized checkpoint header to the log file.
[in] | file_handle | handle for the opened log file |
[in] | checkpoint_header_no | checkpoint header to be written |
[in] | buf | buffer containing the serialized checkpoint header to write |
dberr_t log_checkpoint_header_write | ( | Log_file_handle & | file_handle, |
Log_checkpoint_header_no | checkpoint_header_no, | ||
const Log_checkpoint_header & | header | ||
) |
Serializes and writes the log checkpoint header to the log file.
[in] | file_handle | handle for the opened log file |
[in] | checkpoint_header_no | checkpoint header to be written |
[in] | header | the checkpoint header |
dberr_t log_collect_existing_files | ( | const Log_files_context & | ctx, |
bool | read_only, | ||
ut::vector< Log_file_id_and_size > & | found | ||
) |
Searches for all possible log files existing on disk in the log directory.
Performs only very minimal validation of the files, checking if files could be opened and have valid file size.
[in] | ctx | context within which files exist |
[in] | read_only | true: check file permissions only for reading, false: check for both reading and writing |
[out] | found | list of <file_id, size of file> for each file found |
dberr_t log_create_unused_file | ( | const Log_files_context & | ctx, |
Log_file_id | file_id, | ||
os_offset_t | size_in_bytes | ||
) |
Creates a new temporary log file and resizes the file to the given size.
[in] | ctx | context within which files exist |
[in] | file_id | id of the file to create |
[in] | size_in_bytes | size of the file, in bytes |
|
inline |
Deserializes the log data block header stored in the buffer.
[in] | buf | the buffer to deserialize |
[out] | header | the deserialized header |
|
inline |
Serializes the log data block header to the redo log block buffer which already contains redo log data (must have the redo data before this call).
[in] | header | the header to serialize |
[out] | buf | the buffer containing the redo log block with the data |
dberr_t log_data_blocks_read | ( | Log_file_handle & | file_handle, |
os_offset_t | read_offset, | ||
size_t | read_size, | ||
byte * | buf | ||
) |
Reads log blocks with redo records from the log file, starting at the given offset.
The log blocks must exist within single log file.
[in] | file_handle | handle for the opened log file |
[in] | read_offset | offset from the beginning of the given file |
[in] | read_size | size of the data to read (must be divisible by OS_FILE_LOG_BLOCK_SIZE) |
[out] | buf | allocated buffer to fill by the read |
dberr_t log_data_blocks_write | ( | Log_file_handle & | file_handle, |
os_offset_t | write_offset, | ||
size_t | write_size, | ||
const byte * | buf | ||
) |
Writes the formatted log blocks with redo records to the log file.
The given log blocks must fit within the same single log file.
[in] | file_handle | handle for the opened log file |
[in] | write_offset | offset from the beginning of the given file |
[in] | write_size | size of the data to write (must be divisible by OS_FILE_LOG_BLOCK_SIZE) |
[in] | buf | formatted log blocks with the data to write |
std::string log_directory_path | ( | const Log_files_context & | ctx | ) |
Provides path to directory with redo log files.
[in] | ctx | context within which files exist |
dberr_t log_encryption_header_read | ( | Log_file_handle & | file_handle, |
byte * | buf | ||
) |
Reads the serialized encryption meta data from the log file.
[in] | file_handle | handle for the opened log file |
[out] | buf | the allocated buffer for read |
dberr_t log_encryption_header_write | ( | Log_file_handle & | file_handle, |
const byte * | buf | ||
) |
Writes the serialized encryption meta data to the log file.
[in] | file_handle | handle for the opened log file |
[in] | buf | the filled encryption buffer to write |
bool log_file_header_check_flag | ( | Log_flags | log_flags, |
uint32_t | bit | ||
) |
Checks if a specific flag is set in the mask built of redo log flags.
[in] | log_flags | mask of log flags |
[in] | bit | bit number to check (flag) |
bool log_file_header_deserialize | ( | const byte * | buf, |
Log_file_header & | header | ||
) |
Deserializes the log file header stored in the buffer.
[in] | buf | the buffer to deserialize |
[out] | header | the deserialized header |
dberr_t log_file_header_read | ( | Log_file_handle & | file_handle, |
byte * | buf | ||
) |
Reads the serialized log file header to the buffer.
[in] | file_handle | handle for the opened log file |
[out] | buf | the allocated buffer for read |
dberr_t log_file_header_read | ( | Log_file_handle & | file_handle, |
Log_file_header & | header | ||
) |
Reads and deserializes the log file header.
[in] | file_handle | handle for the opened log file |
[out] | header | the file header read |
void log_file_header_reset_flag | ( | Log_flags & | log_flags, |
uint32_t | bit | ||
) |
Resets a specific flag in the mask built of redo log flags.
[in] | log_flags | mask of log flags |
[in] | bit | bit number to set (flag) |
void log_file_header_serialize | ( | const Log_file_header & | header, |
byte * | buf | ||
) |
Serializes the log file header to the buffer.
[in] | header | the header to serialize |
[out] | buf | the allocated buffer |
void log_file_header_set_flag | ( | Log_flags & | log_flags, |
uint32_t | bit | ||
) |
Sets a specific flag in the mask built of redo log flags.
[in] | log_flags | mask of log flags |
[in] | bit | bit number to set (flag) |
dberr_t log_file_header_write | ( | Log_file_handle & | file_handle, |
const byte * | buf | ||
) |
Writes the serialized log file header to the log file.
[in] | file_handle | handle for the opened log file |
[in] | buf | the serialized file header |
dberr_t log_file_header_write | ( | Log_file_handle & | file_handle, |
const Log_file_header & | header | ||
) |
Serializes and writes the log file header to the log file.
[in] | file_handle | handle for the opened log file |
[in] | header | the file header |
std::string log_file_name | ( | const Log_files_context & | ctx, |
Log_file_id | file_id | ||
) |
Provides name of the log file with the given file id, e.g.
'ib_redo0'.
[in] | ctx | context within which files exist |
[in] | file_id | id of the log file |
std::string log_file_path | ( | const Log_files_context & | ctx, |
Log_file_id | file_id | ||
) |
Provides full path to the log file, e.g.
'/data/innodb_redo/ib_redo2'.
[in] | ctx | context within which files exist |
[in] | file_id | id of the log file |
std::string log_file_path_for_unused_file | ( | const Log_files_context & | ctx, |
Log_file_id | file_id | ||
) |
Provides full path to the temporary log file, e.g.
'/data/innodb_redo/ib_redo2_tmp'.
[in] | ctx | context within which files exist |
[in] | file_id | id of the file |
Log_uuid log_generate_uuid | ( | ) |
Generate unique identifier for the redo log files.
bool log_header_checksum_is_ok | ( | const byte * | buf | ) |
Computes checksum of the given header and verifies if the checksum is the same as the one stored in that header.
[in] | buf | header to verify |
dberr_t log_list_existing_files | ( | const Log_files_context & | ctx, |
ut::vector< Log_file_id > & | ret | ||
) |
List existing log files in the directory (does not include unused files).
[in] | ctx | context within which files exist |
[out] | ret | identifiers of existing log files |
dberr_t log_list_existing_unused_files | ( | const Log_files_context & | ctx, |
ut::vector< Log_file_id > & | ret | ||
) |
List existing unused log files in the directory.
[in] | ctx | context within which files exist |
[out] | ret | identifiers of existing unused log files |
dberr_t log_mark_file_as_in_use | ( | const Log_files_context & | ctx, |
Log_file_id | file_id | ||
) |
Renames a temporary log file to the non-temporary log file.
[in] | ctx | context within which files exist |
[in] | file_id | id of the file to rename |
dberr_t log_mark_file_as_unused | ( | const Log_files_context & | ctx, |
Log_file_id | file_id | ||
) |
Renames a non-temporary log file to the temporary log file.
[in] | ctx | context within which files exist |
[in] | file_id | id of the file to rename |
std::pair< dberr_t, Log_file_id > log_remove_file | ( | const Log_files_context & | ctx | ) |
Removes a single existing log file (if it existed).
[in] | ctx | context within which files exist |
dberr_t log_remove_file | ( | const Log_files_context & | ctx, |
Log_file_id | file_id | ||
) |
Removes a log file, if it existed.
[in] | ctx | context within which files exist |
[in] | file_id | id of the file to remove |
std::pair< dberr_t, ut::vector< Log_file_id > > log_remove_files | ( | const Log_files_context & | ctx | ) |
Removes existing log files.
When failed to remove a file, stops and returns error. In such case the last element of the returned identifiers of files, represents the file for which error has been encountered when trying to remove it.
[in] | ctx | context within which files exist |
dberr_t log_remove_unused_file | ( | const Log_files_context & | ctx, |
Log_file_id | file_id | ||
) |
Removes a temporary log file, if it existed.
[in] | ctx | context within which files exist |
[in] | file_id | id of the file to remove |
std::pair< dberr_t, ut::vector< Log_file_id > > log_remove_unused_files | ( | const Log_files_context & | ctx | ) |
Removes all temporary log files in the directory.
When failed to remove a file, stops and returns error. In such case the last element of the returned identifiers of files, represents the file for which error has been encountered when trying to remove it.
[in] | ctx | context within which files exist |
dberr_t log_rename_unused_file | ( | const Log_files_context & | ctx, |
Log_file_id | old_unused_file_id, | ||
Log_file_id | new_unused_file_id | ||
) |
Renames the unused file to another unused file.
[in] | ctx | context within which files exist |
[in] | old_unused_file_id | id of file to rename |
[in] | new_unused_file_id | new file id |
dberr_t log_resize_file | ( | const Log_files_context & | ctx, |
Log_file_id | file_id, | ||
os_offset_t | size_in_bytes | ||
) |
Resizes an existing log file to the given size.
[in] | ctx | context within which files exist |
[in] | file_id | id of the file to resize |
[in] | size_in_bytes | requested size of the file, in bytes |
dberr_t log_resize_unused_file | ( | const Log_files_context & | ctx, |
Log_file_id | file_id, | ||
os_offset_t | size_in_bytes | ||
) |
Resizes an existing temporary log file to the given size.
[in] | ctx | context within which files exist |
[in] | file_id | id of the file to resize |
[in] | size_in_bytes | requested size of the file, in bytes |
|
extern |
Atomic pointer to the log checksum calculation function.
This is actually the only remaining "state" of the library. Hopefully can become removed.