MySQL 8.0.39
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... | |
virtual | ~Binlog_recovery ()=default |
my_off_t | get_valid_pos () const |
Retrieves the position of the last binlog event that ended a transaction. More... | |
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... | |
Private Member Functions | |
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... | |
my_off_t | m_valid_pos {0} |
Position of the last binlog event that ended a 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. More... | |
bool | m_no_engine_recovery {false} |
Whether or not the recovery in the storage engines failed. 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... | |
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. |
|
virtualdefault |
|
private |
Parses the provided string for an XID and adds it to the externally coordinated transactions map, along side the provided state.
query | The query to search and retrieve the XID from |
state | The state to add to the map, along side the XID |
std::string const & binlog::Binlog_recovery::get_failure_message | ( | ) | const |
Retrieves the textual representation of the encontered failure, if any.
my_off_t binlog::Binlog_recovery::get_valid_pos | ( | ) | const |
Retrieves the position of the last binlog event that ended a transaction.
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.
|
private |
Invoked when a DDL is found in a Query_log_event
.
Actions taken to process the statement:
m_in_transaction
flag is set to true, m_is_malformed
is set to true, indicating that the binary log is malformed.m_internal_xids
.m_is_malformed
is set to true, indicating that the binary log is malformed.ev | The Query_log_event to process |
|
private |
Invoked when a COMMIT
is found in a Query_log_event
.
Actions taken to process the statement:
m_in_transaction
flag is set to false, m_is_malformed
is set to true, indicating that the binary log is malformed.m_in_transaction
flag is set to false, indicating that the event starts a transaction.
|
private |
Invoked when a Query_log_event
is read from the binary log file reader.
The underlying query string is inspected to determine if the SQL command starts or ends a transaction. The following commands are searched for:
Check below for the description of the action that is taken for each.
ev | The Query_log_event to process |
|
private |
Invoked when a ROLLBACK
is found in a Query_log_event
.
Actions taken to process the statement:
m_in_transaction
flag is set to false, m_is_malformed
is set to true, indicating that the binary log is malformed.m_in_transaction
flag is set to false, indicating that the event starts a transaction.
|
private |
Invoked when a BEGIN
or an ‘XA START’ is found in a Query_log_event
.
Actions taken to process the statement:
m_in_transaction
flag is set to true, m_is_malformed
is set to true, indicating that the binary log is malformed.m_in_transaction
flag is set to true, indicating that the event starts a transaction.
|
private |
Invoked when an XA COMMIT
is found in a Query_log_event
.
Actions taken to process the statement:
m_in_transaction
flag is set to true, m_is_malformed
is set to true, indicating that the binary log is malformed.m_in_transaction
flag is set to false, indicating that the event ends a transaction.m_external_xids
, alongside the state COMMITTED.PREPARED
, m_is_malformed
is set to true, indicating that the binary log is malformed.query | The query string to process |
|
private |
Invoked when a XA_prepare_log_event
is read from the binary log file reader.
Actions taken to process the event:
m_in_transaction
flag is set to false, m_is_malformed
is set to true, indicating that the binary log is malformed.m_in_transaction
flag is set to false, indicating that the event ends a transaction.m_external_xids
, along side the state COMMITTED if the event represents an XA COMMIT ONE_PHASE
or PREPARED if not.COMMITTED
or ROLLEDBACK
, m_is_malformed
is set to true, indicating that the binary log is malformed.ev | The XA_prepare_log_event to process |
|
private |
Invoked when an XA ROLLBACK
is found in a Query_log_event
.
Actions taken to process the statement:
m_in_transaction
flag is set to true, m_is_malformed
is set to true, indicating that the binary log is malformed.m_in_transaction
flag is set to false, indicating that the event ends a transaction.m_external_xids
, along side the state ROLLEDBACK.PREPARED
, m_is_malformed
is set to true, indicating that the binary log is malformed.query | The query string to process |
|
private |
Invoked when a Xid_log_event
is read from the binary log file reader.
Actions taken to process the event:
m_in_transaction
flag is set to false, m_is_malformed
is set to true, indicating that the binary log is malformed.m_in_transaction
flag is set to false, indicating that the event ends a transaction.m_internal_xids
.m_is_malformed
is set to true, indicating that the binary log is malformed.ev | The Xid_log_event to process |
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 |
List of XA transactions and states that appear in the binary log.
|
private |
Textual representation of the encountered failure.
|
private |
Whether or not the event being processed is within a transaction.
|
private |
List of normal transactions fully written to the binary log.
|
private |
Whether or not the binary log is malformed/corrupted.
|
private |
Memory pool allocator to use with the XA transaction list.
|
private |
Memory pool to use for the XID lists.
|
private |
Whether or not the recovery in the storage engines failed.
|
private |
File reader for the last available binary log file.
|
private |
Memory pool allocator to use with the normal transaction list.
|
private |
Position of the last binlog event that ended a transaction.