MySQL 8.4.0
Source Code Documentation
binlog::Binlog_recovery Class Reference

Recovers from last crashed binlog at server start. More...

#include <recovery.h>

Inheritance diagram for binlog::Binlog_recovery:
[legend]

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_recoveryrecover ()
 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_keyget_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_readerm_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_xidm_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...
 

Detailed Description

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 internally coordinated transactions (normal) that are completely written to the binary log.
  • the list of externally coordinated transactions (XA) that appear in the binary log, along the state those transactions are in.

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.

Constructor & Destructor Documentation

◆ Binlog_recovery()

binlog::Binlog_recovery::Binlog_recovery ( Binlog_file_reader binlog_file_reader)

Class constructor.

Parameters
binlog_file_readerThe already instantiated and initialized file reader for the last available binary log file.

◆ ~Binlog_recovery()

binlog::Binlog_recovery::~Binlog_recovery ( )
overridedefault

Member Function Documentation

◆ get_failure_message()

std::string const & binlog::Binlog_recovery::get_failure_message ( ) const

Retrieves the textual representation of the encontered failure, if any.

Returns
the string containing the textual representation of the failure, an empty string otherwise.

◆ get_memory_key()

PSI_memory_key & binlog::Binlog_recovery::get_memory_key ( ) const
inlineoverrideprotectedvirtual

Function used to obtain memory key for derived classes.

Returns
Reference to a memory key

Implements binlog::Log_sanitizer.

◆ has_engine_recovery_failed()

bool binlog::Binlog_recovery::has_engine_recovery_failed ( ) const

Retrieves whether or not the storage engines XA recovery process completed successfully.

Returns
false if the storge engines completed the XA recovery process successfully, true otherwise.

◆ has_failures()

bool binlog::Binlog_recovery::has_failures ( ) const

Retrieves whether or not the recovery process ended successfully.

See also
Binlog_recovery::is_binlog_malformed()
Binlog_recovery::has_engine_recovery_failed()
Returns
true if the recovery process ended with errors, false otherwise.

◆ is_binlog_malformed()

bool binlog::Binlog_recovery::is_binlog_malformed ( ) const

Retrieves whether or not the binary log was correctly processed in full.

Returns
true if the binary log processing ended with errors, false otherwise.

◆ recover()

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 internally coordinated transactions (normal) that are completely written to the binary log.
  • the list of externally coordinated transactions (XA) that appear in the binary log, along the state those transactions are in.

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.

Returns
This instance's reference, for chaining purposes.

Member Data Documentation

◆ m_no_engine_recovery

bool binlog::Binlog_recovery::m_no_engine_recovery {false}
private

Whether or not the recovery in the storage engines failed.

◆ m_reader

Binlog_file_reader& binlog::Binlog_recovery::m_reader
private

File reader for the last available binary log file.


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