MySQL 9.1.0
Source Code Documentation
|
Recovers from last crashed binlog at server start. More...
#include <recovery.h>
Public Member Functions | |
Binlog_recovery (Binlog_file_reader &binlog_file_reader) | |
Class constructor. More... | |
~Binlog_recovery () override=default | |
bool | has_failures () const |
Retrieves whether or not the recovery process ended successfully. More... | |
bool | is_binlog_malformed () const |
Retrieves whether or not the binary log was correctly processed in full. More... | |
bool | has_engine_recovery_failed () const |
Retrieves whether or not the storage engines XA recovery process completed successfully. More... | |
std::string const & | get_failure_message () const |
Retrieves the textual representation of the encontered failure, if any. More... | |
Binlog_recovery & | recover () |
Uses the provided binary log file reader to inspect the binary log and extract transaction information. More... | |
Public Member Functions inherited from binlog::Log_sanitizer | |
Log_sanitizer () | |
Ctor. More... | |
virtual | ~Log_sanitizer ()=default |
Dtor. More... | |
my_off_t | get_valid_pos () const |
Retrieves the position of the last binlog/relay log event that ended a transaction or position after the RLE/FDE/SE that comes from the source. More... | |
std::pair< my_off_t, bool > | get_valid_source_pos () const |
Retrieves the last valid source position of an event in read from the binary log / relay log file, which may be: More... | |
std::pair< std::string, bool > | get_valid_source_file () const |
Retrieves the updated name of the binlog source file. More... | |
bool | is_log_malformed () const |
Retrieves whether or not the log was correctly processed in full. More... | |
std::string const & | get_failure_message () const |
Retrieves the textual representation of the encontered failure, if any. More... | |
std::string | get_valid_file () const |
bool | is_log_truncation_needed () const |
Checks whether a valid sanitized log file needs truncation of the last, partially written transaction or events that cannot be safely read. More... | |
bool | is_fatal_error () const |
Checks whether the fatal error occurred during log sanitization (OOM / decompression error which we cannot handle) More... | |
Protected Member Functions | |
PSI_memory_key & | get_memory_key () const override |
Function used to obtain memory key for derived classes. More... | |
Protected Member Functions inherited from binlog::Log_sanitizer | |
template<class Type_reader > | |
void | process_logs (Type_reader &reader) |
This function goes through the opened file and searches for a valid position in a binary log file. More... | |
template<class Type_reader > | |
void | process_logs (Type_reader &reader, const std::list< std::string > &list_of_files, MYSQL_BIN_LOG &log) |
This function goes iterates over the relay log files in the 'list_of_files' container, starting from the most recent one. More... | |
template<class Type_reader > | |
void | process_logs (Type_reader &reader, MYSQL_BIN_LOG &log) |
This function will obtain the list of relay log files using the object of MYSQL_BIN_LOG class and iterate over them to find the last valid position within a relay log file. More... | |
template<class Type_reader > | |
bool | process_one_log (Type_reader &reader, const std::string &filename) |
Reads and validates one log file. More... | |
void | process_query_event (Query_log_event const &ev) |
Invoked when a Query_log_event is read from the binary log file reader. More... | |
void | process_xid_event (Xid_log_event const &ev) |
Invoked when a Xid_log_event is read from the binary log file reader. More... | |
void | process_xa_prepare_event (XA_prepare_log_event const &ev) |
Invoked when a XA_prepare_log_event is read from the binary log file reader. More... | |
void | process_start () |
Invoked when a BEGIN or an ‘XA START’ is found in a Query_log_event . More... | |
void | process_commit () |
Invoked when a COMMIT is found in a Query_log_event . More... | |
void | process_rollback () |
Invoked when a ROLLBACK is found in a Query_log_event . More... | |
void | process_atomic_ddl (Query_log_event const &ev) |
Invoked when a DDL is found in a Query_log_event . More... | |
void | process_xa_commit (std::string const &query) |
Invoked when an XA COMMIT is found in a Query_log_event . More... | |
void | process_xa_rollback (std::string const &query) |
Invoked when an XA ROLLBACK is found in a Query_log_event . More... | |
void | add_external_xid (std::string const &query, enum_ha_recover_xa_state state) |
Parses the provided string for an XID and adds it to the externally coordinated transactions map, along side the provided state. More... | |
Private Attributes | |
Binlog_file_reader & | m_reader |
File reader for the last available binary log file. More... | |
bool | m_no_engine_recovery {false} |
Whether or not the recovery in the storage engines failed. More... | |
Additional Inherited Members | |
Protected Attributes inherited from binlog::Log_sanitizer | |
bool | m_validation_started {true} |
Indicates whether validation has started. More... | |
my_off_t | m_valid_pos {0} |
Position of the last binlog/relay log event that ended a transaction. More... | |
my_off_t | m_valid_source_pos {0} |
Position of the last binlog event that ended a transaction (source position which corresponds to m_valid_pos) More... | |
std::string | m_valid_source_file {""} |
Currently processed binlog file set in case source rotation event is encountered. More... | |
std::string | m_valid_file {""} |
Last log file containing finished transaction. More... | |
bool | m_in_transaction {false} |
Whether or not the event being processed is within a transaction. More... | |
bool | m_is_malformed {false} |
Whether or not the binary log is malformed/corrupted or error occurred. More... | |
bool | m_fatal_error {false} |
Whether or not the binary log has a fatal error. More... | |
std::string | m_failure_message {""} |
Textual representation of the encountered failure. More... | |
MEM_ROOT | m_mem_root |
Memory pool to use for the XID lists. More... | |
Mem_root_allocator< my_xid > | m_set_alloc |
Memory pool allocator to use with the normal transaction list. More... | |
Mem_root_allocator< std::pair< const XID, XID_STATE::xa_states > > | m_map_alloc |
Memory pool allocator to use with the XA transaction list. More... | |
Xid_commit_list | m_internal_xids |
List of normal transactions fully written to the binary log. More... | |
Xa_state_list::list | m_external_xids |
List of XA transactions and states that appear in the binary log. More... | |
bool | m_is_log_truncation_needed {false} |
Information on whether log needs to be truncated, i.e. More... | |
bool | m_has_valid_pos {false} |
Indicator on whether a valid position has been found in the log file. More... | |
bool | m_has_valid_source_pos {false} |
Indicator on whether a valid source position has been found in the log file. More... | |
my_off_t | m_last_file_size {0} |
Last opened file size. More... | |
Recovers from last crashed binlog at server start.
After a crash, storage engines may contain transactions that are prepared but not committed (in theory any engine, in practice InnoDB). This classe's methods use the binary log as the source of truth to determine which of these transactions should be committed and which should be rolled back.
The Binlog::recovery()
method collects the following from the last available binary log:
The list of XIDs of all internally coordinated transactions that are completely written to the binary log is passed to the storage engines through the ha_recover function in the handler interface. This tells the storage engines to commit all prepared transactions that are in the set, and to roll back all prepared transactions that are not in the set.
The list of XIDs of all externally coordinated transactions that appear in the binary log, along with the state they are in, is passed to the storage engines through the ha_recover function in the handler interface. The storage engine will determine if the transaction is to be kept at PREPARE, is to be COMMITTED or ROLLED BACK, in accordance with: the state that is provided in the list; the internal storage engine state for the transaction.
binlog::Binlog_recovery::Binlog_recovery | ( | Binlog_file_reader & | binlog_file_reader | ) |
Class constructor.
binlog_file_reader | The already instantiated and initialized file reader for the last available binary log file. |
|
overridedefault |
std::string const & binlog::Binlog_recovery::get_failure_message | ( | ) | const |
Retrieves the textual representation of the encontered failure, if any.
|
inlineoverrideprotectedvirtual |
Function used to obtain memory key for derived classes.
Implements binlog::Log_sanitizer.
bool binlog::Binlog_recovery::has_engine_recovery_failed | ( | ) | const |
Retrieves whether or not the storage engines XA recovery process completed successfully.
bool binlog::Binlog_recovery::has_failures | ( | ) | const |
Retrieves whether or not the recovery process ended successfully.
bool binlog::Binlog_recovery::is_binlog_malformed | ( | ) | const |
Retrieves whether or not the binary log was correctly processed in full.
binlog::Binlog_recovery & binlog::Binlog_recovery::recover | ( | ) |
Uses the provided binary log file reader to inspect the binary log and extract transaction information.
The following is collected from the provided binlog file reader:
The list of XIDs of all internally coordinated transactions that are completely written to the binary log is passed to the storage engines through the ha_recover function in the handler interface. This tells the storage engines to commit all prepared transactions that are in the set, and to roll back all prepared transactions that are not in the set.
The list of XIDs of all externally coordinated transactions that appear in the binary log, along with the state they are in, is passed to the storage engines through the ha_recover function in the handler interface. The storage engine will determine if the transaction is to be kept at PREPARE, is to be COMMITTED or ROLLED BACK, in accordance with: the state that is provided in the list; the internal storage engine state for the transaction.
After recover()
returns, has_failures()
should be invoked to determine if the recover process ended successfully. Additionally, is_binlog_malformed()
and has_engine_recovery_failed()
can be invoked to determine the type of error that occurred.
|
private |
Whether or not the recovery in the storage engines failed.
|
private |
File reader for the last available binary log file.