MySQL 8.4.3
Source Code Documentation
|
#include <fcntl.h>
#include <unistd.h>
#include <algorithm>
#include <cstring>
#include <limits>
#include <sstream>
#include "log0files_io.h"
#include "log0pre_8_0_30.h"
#include "log0types.h"
#include "mach0data.h"
#include "my_dbug.h"
#include "os0file.h"
#include "ut0new.h"
#include "ut0rnd.h"
#include "srv0srv.h"
Classes | |
struct | Log_file_block |
Used for reads/writes to redo files within this module. More... | |
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. | |
static void | log_file_header_validate (const Log_file_header &header) |
Asserts that the provided file header seems correct. More... | |
static Log_flags | log_file_header_flag_bit (uint32_t bit) |
Converts flag number to the mask with this flag turned on. More... | |
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 - checkpoint header read/write. | |
static os_offset_t | log_checkpoint_header_offset (Log_checkpoint_header_no checkpoint_header_no) |
Computes offset from the beginning of the redo file to the checkpoint header for provided checkpoint header number. More... | |
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 data blocks | |
static void | log_data_blocks_validate (os_offset_t offset, os_offset_t size) |
Asserts that the provided <offset, size> defines one or more redo data blocks within a log file. More... | |
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 - file creation / deletion | |
static dberr_t | log_rename_file_low (const Log_files_context &context, const std::string &old_file_path, const std::string &new_file_path, int err_msg_id) |
Renames the log file. More... | |
static dberr_t | log_remove_file_low (const Log_files_context &context, const std::string &file_path, int err_msg_id) |
Delete the log file at the provided file path. More... | |
static dberr_t | log_resize_file_low (const std::string &file_path, os_offset_t size_in_bytes, int err_msg_id) |
Resizes the log file at the provided file path. More... | |
static dberr_t | log_check_file (const Log_files_context &ctx, Log_file_id file_id, bool read_only, os_offset_t &size_in_bytes) |
Checks if a log file exists and can be opened with srv_read_only_mode mode. 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 - 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 - file names and paths. | |
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... | |
static bool | log_extract_id_from_file_name (const Log_files_context &ctx, const char *file_name, const char *expected_suffix, Log_file_id &extracted_id) |
Extracts identifier of the redo log file from its file name. More... | |
static dberr_t | log_list_existing_files_low (const Log_files_context &ctx, const char *suffix, ut::vector< Log_file_id > &ret) |
Lists existing redo files in the configured redo log directory, selecting redo log files which have a given suffix in their name. 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_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... | |
Variables | |
Log_checksum_algorithm_atomic_ptr | log_checksum_algorithm_ptr |
Atomic pointer to the log checksum calculation function. More... | |
|
static |
Checks if a log file exists and can be opened with srv_read_only_mode mode.
If that is successful, reads the size of the file and provides it.
[in] | ctx | redo log files context |
[in] | file_id | id of the file to check and open |
[in] | read_only | true: check file permissions only for reading false: check for both reading and writing |
[out] | size_in_bytes | size of the file, in bytes |
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 |
|
static |
Computes offset from the beginning of the redo file to the checkpoint header for provided checkpoint header number.
[in] | checkpoint_header_no | checkpoint header for which offset to compute |
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 |
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 |
|
static |
Asserts that the provided <offset, size> defines one or more redo data blocks within a log file.
[in] | offset | expected offset to the beginning of data block(s) |
[in] | size | size in bytes of data blocks starting from the offset |
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 |
|
static |
Extracts identifier of the redo log file from its file name.
Function might be called for non-redo log files in which case it should return false instead of extracting the identifier.
[in] | ctx | redo log files context |
[in] | file_name | file name (can be wrong) |
[in] | expected_suffix | suffix that should exist after id |
[out] | extracted_id | extracted redo file identifier |
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 |
|
static |
Converts flag number to the mask with this flag turned on.
[in] | bit | flag bit number (but > 0) |
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) |
|
static |
Asserts that the provided file header seems correct.
[in] | header | file header data to validate |
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 |
|
static |
Lists existing redo files in the configured redo log directory, selecting redo log files which have a given suffix in their name.
Produces list of identifiers of the listed and selected files. If a system error occurs when listing the redo directory, error is emitted to the error log and DB_ERROR is returned.
[in] | ctx | redo log files context |
[in] | suffix | suffix used for the selection of files (could be "") |
[out] | ret | identifiers of the listed and selected 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 |
|
static |
Delete the log file at the provided file path.
Asserts that the file has been deleted or does not exist.
[in] | context | redo log files context |
[in] | file_path | path to the log file that should be removed |
[in] | err_msg_id | id of the error message to print (if needed) |
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 |
|
static |
Renames the log file.
[in] | context | redo log files context |
[in] | old_file_path | path to the existing log file to rename |
[in] | new_file_path | path to the renamed file |
[in] | err_msg_id | id of the error message to print (if needed) |
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 |
|
static |
Resizes the log file at the provided file path.
[in] | file_path | path to the log file that should be resized |
[in] | size_in_bytes | size to which resize, in bytes |
[in] | err_msg_id | id of the error message to print (if needed) |
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 |
Log_checksum_algorithm_atomic_ptr log_checksum_algorithm_ptr |
Atomic pointer to the log checksum calculation function.
This is actually the only remaining "state" of the library. Hopefully can become removed.