![]() |
MySQL 26.7.0
Source Code Documentation
|
Recovery. More...
#include "ha_prototypes.h"#include <my_aes.h>#include <sys/types.h>#include <ostream>#include <array>#include <iomanip>#include <map>#include <new>#include <optional>#include <span>#include <string>#include <vector>#include "arch0arch.h"#include "btr0btr.h"#include "btr0cur.h"#include "buf0buf.h"#include "buf0flu.h"#include "clone0api.h"#include "dict0dd.h"#include "fil0fil.h"#include "fil0pages_persistence_interface.h"#include "ibuf0ibuf.h"#include "log0chkp.h"#include "log0encryption.h"#include "log0files_io.h"#include "log0log.h"#include "log0pre_8_0_30.h"#include "log0recv.h"#include "log0test.h"#include "mem0mem.h"#include "mtr0log.h"#include "mtr0mtr.h"#include "os0thread-create.h"#include "page0cur.h"#include "page0zip.h"#include "trx0rec.h"#include "trx0undo.h"#include "ut0new.h"#include "my_dbug.h"#include "buf0rea.h"#include "ddl0ddl.h"#include "log0handler.h"#include "srv0srv.h"#include "srv0start.h"#include "trx0purge.h"Macros | |
| #define | RECV_DATA_BLOCK_SIZE (MEM_MAX_ALLOC_IN_BUF - sizeof(recv_data_t)) |
| Log records are stored in the hash table in chunks at most of this size; this must be less than UNIV_PAGE_SIZE as it is stored in the buffer pool. More... | |
Functions | |
| static bool | recv_writer_is_active () |
| static void | recv_init_crash_recovery () |
| Initialize crash recovery environment. More... | |
| lsn_t | recv_calc_lsn_on_data_add (lsn_t lsn, os_offset_t len) |
| Calculates the new value for lsn when more data is added to the log. More... | |
| void | recv_sys_create () |
| Creates the recovery system. More... | |
| bool | recv_sys_resize_buf () |
| Resize the recovery parsing buffer up to log_buffer_size. More... | |
| static void | recv_sys_finish () |
| Free up recovery data structures. More... | |
| void | recv_sys_close () |
| Release recovery system mutexes. More... | |
| void | recv_sys_var_init () |
| Reset the state of the recovery system variables. More... | |
| static size_t | recv_heap_used () |
| Get the number of bytes used by all the heaps. More... | |
| static void | recv_report_corrupt_log (std::span< const byte > buffer, size_t pos, lsn_t lsn) |
| Prints diagnostic info of corrupt log. More... | |
| void | recv_sys_init () |
| Inits the recovery system for a recovery operation. More... | |
| static void | recv_sys_empty_hash () |
| Empties the hash table when it has been fully processed. More... | |
| static recv_sys_t::Space * | recv_get_page_map (space_id_t space_id, bool create) |
| Get the page map for a tablespace. More... | |
| static recv_addr_t * | recv_get_rec (const page_id_t &page_id) |
| Gets the list of log records for a <space, page>. More... | |
| static void | recv_writer_thread () |
| recv_writer thread tasked with flushing dirty pages from the buffer pools. More... | |
| void | recv_sys_free () |
| Frees the recovery system. More... | |
| static void | one_less_page_to_recover () |
| static void | recv_read_in_area (const page_id_t &requested_page_id, const page_size_t &page_size) |
| Reads in pages which have hashed log records, from an area around a given page number. More... | |
| static void | recv_apply_log_rec (recv_addr_t *recv_addr) |
| Apply the log records to a page. More... | |
| static void | recv_apply_hashed_log_recs () |
| Empties the hash table of stored log records, applying them to appropriate pages. More... | |
| static void | recv_add_to_hash_table (mlog_id_t type, space_id_t space_id, page_no_t page_no, std::span< const byte > body, lsn_t start_lsn, lsn_t end_lsn) |
| Adds a new log record to the hash table of log records. More... | |
| static void | recv_data_copy_to_buf (byte *buf, recv_t *recv) |
| Copies the log record body from recv to buf. More... | |
| bool | recv_page_is_brand_new (buf_block_t *block) |
| Returns true if the page is brand new (the next log record is init_file_page or no records to apply). More... | |
| static void | apply_tablespace_side_effects (const ib::redo::Record_handle &record_handle, const ib::redo::Page_handle &page_handle) |
| Apply tablespace metadata side-effects after page record application. More... | |
| void | recv_recover_page_func (bool just_read_in, buf_block_t *block) |
| Applies the hashed log records to the page, if the page lsn is less than the lsn of a log record. More... | |
| void | recv_track_changes_of_recovered_lsn () |
| static bool | recv_process_space_record (const ib::redo::Record_view &rec, lsn_t start_lsn) |
| Process a table space record. More... | |
| static bool | recv_process_page_record (const ib::redo::Record_view &rec, lsn_t start_lsn, lsn_t end_lsn) |
| Process a page record. More... | |
| static bool | process_mtr (const ib::redo::Mtr_view &mtr, lsn_t start_lsn, lsn_t end_lsn) |
| Process an mtr. More... | |
| static std::optional< ib::redo::Mtr_view > | parse_buffer (std::span< const byte > buffer) |
| Parses the buffer starting from the beginning. More... | |
| static bool | process_mtr_and_possibly_apply_records (ib::redo::Mtr_view mtr) |
| mtr buffer is processed if the start_lsn is more than checkpoint_lsn. More... | |
| dberr_t | recv_parse_and_apply_log_recs (size_t mem_limit) |
| Parse log records from a buffer and stores them to a hash table. More... | |
| static void | recv_reset_buffer () |
| Moves the parsing buffer data left to the buffer start. More... | |
| dberr_t | recv_recovery_begin (lsn_t checkpoint_lsn) |
| Scans log from a stream and stores new log data to the parsing buffer. More... | |
| dberr_t | recv_recovery_from_checkpoint_start (lsn_t flush_lsn) |
| Recovers all tablespaces from the redo log. More... | |
| MetadataRecover * | recv_recovery_from_checkpoint_finish (bool aborting) |
| Complete the recovery from the latest checkpoint. More... | |
| const char * | get_mlog_string (mlog_id_t type) |
| Return string name of the redo log record type. More... | |
Variables | |
| static const size_t | RECV_READ_AHEAD_AREA = 32 |
| Read-ahead area in applying log records to file pages. More... | |
| recv_sys_t * | recv_sys = nullptr |
| The recovery system. More... | |
| volatile bool | recv_recovery_on |
| true when applying redo log records during crash recovery; false otherwise. More... | |
| static const size_t | PARSING_BUF_MINIMUM_SIZE = 2048 |
| PSI_memory_key | mem_log_recv_space_hash_key |
| bool | recv_needed_recovery |
| true when recv_init_crash_recovery() has been called. More... | |
| bool | recv_lsn_checks_on |
| true if buf_page_is_corrupted() should check if the log sequence number (FIL_PAGE_LSN) is in the future. More... | |
| static ulint | recv_scan_print_counter |
| The following counter is used to decide when to print info on log scan. More... | |
| size_t | recv_n_frames_for_pages_per_pool_instance |
| This many blocks must be left in each Buffer Pool instance to be managed by the LRU when we scan the log and store the scanned log records in a hashmap allocated in the Buffer Pool in frames of non-LRU managed blocks. More... | |
| static lsn_t | recv_max_page_lsn |
| The maximum lsn we see for a page during the recovery process. More... | |
Recovery.
Created 9/20/1997 Heikki Tuuri
| #define RECV_DATA_BLOCK_SIZE (MEM_MAX_ALLOC_IN_BUF - sizeof(recv_data_t)) |
Log records are stored in the hash table in chunks at most of this size; this must be less than UNIV_PAGE_SIZE as it is stored in the buffer pool.
|
static |
Apply tablespace metadata side-effects after page record application.
This function handles tablespace-level side-effects that occur when applying certain redo log records.
| record_handle | Handle containing the redo log record type and body |
| page_handle | Handle containing the page buffer and metadata after the page modifications have been applied. |
| const char * get_mlog_string | ( | mlog_id_t | type | ) |
Return string name of the redo log record type.
| [in] | type | record log record enum |
|
static |
|
static |
Parses the buffer starting from the beginning.
If the buffer content causes parse error, it sets the found_corrupt_log flag to true. The function assumes recovered_lsn is the start_lsn of the mtr.
| [in] | buffer | The buffer to parse |
|
static |
Process an mtr.
| [in] | mtr | mtr to process |
| [in] | start_lsn | mtr start lsn |
| [in] | end_lsn | mtr end lsn |
|
static |
mtr buffer is processed if the start_lsn is more than checkpoint_lsn.
The function assumes recovered_lsn is the start_lsn of the mtr. Processing involves the following two steps :
| [in] | mtr | mtr to process |
|
static |
Adds a new log record to the hash table of log records.
| [in] | type | log record type |
| [in] | space_id | Tablespace id |
| [in] | page_no | page number |
| [in] | body | log record body |
| [in] | start_lsn | start lsn of the mtr |
| [in] | end_lsn | end lsn of the mtr |
|
static |
Empties the hash table of stored log records, applying them to appropriate pages.
|
static |
Apply the log records to a page.
| [in,out] | recv_addr | Redo log records to apply |
| lsn_t recv_calc_lsn_on_data_add | ( | lsn_t | lsn, |
| os_offset_t | len | ||
| ) |
Calculates the new value for lsn when more data is added to the log.
| [in] | lsn | Old LSN |
| [in] | len | This many bytes of data is added, log block headers not included |
Copies the log record body from recv to buf.
| [in] | buf | Buffer of length at least recv->len |
| [in] | recv | Log record |
|
static |
Get the page map for a tablespace.
It will create one if one isn't found.
| [in] | space_id | Tablespace ID for which page map required. |
| [in] | create | false if lookup only |
|
static |
Gets the list of log records for a <space, page>.
| [in] | page_id | The <Tablespace ID,Page number> pair |
|
static |
Get the number of bytes used by all the heaps.
|
static |
Initialize crash recovery environment.
Can be called iff recv_needed_recovery == false.
| bool recv_page_is_brand_new | ( | buf_block_t * | block | ) |
Returns true if the page is brand new (the next log record is init_file_page or no records to apply).
| [in] | block | buffer block |
| dberr_t recv_parse_and_apply_log_recs | ( | size_t | mem_limit | ) |
Parse log records from a buffer and stores them to a hash table.
Some (, none or all) of the oldest redo log records from the hash table may be applied as a side effect, when the hash table overflows or an mtr requires strict ordering.
| mem_limit | hash table threshold. max() value would skip applying the log records |
|
static |
Process a page record.
| [in] | rec | record to process |
| [in] | start_lsn | start lsn of mtr containing the record |
| [in] | end_lsn | end lsn of mtr containing the record |
|
static |
Process a table space record.
| [in] | rec | record to process |
| [in] | start_lsn | start lsn of mtr containing the record |
|
static |
Reads in pages which have hashed log records, from an area around a given page number.
| [in] | requested_page_id | The page which has to be read in anyway, so we have an opportunity to read pages nearby. |
| [in] | page_size | Size of pages in this page's space |
| void recv_recover_page_func | ( | bool | just_read_in, |
| buf_block_t * | block | ||
| ) |
Applies the hashed log records to the page, if the page lsn is less than the lsn of a log record.
This can be called when a buffer page has just been read in, or also for a page already in the buffer pool.
| [in] | just_read_in | true if the IO handler calls this for a freshly read page |
| [in,out] | block | buffer block |
Scans log from a stream and stores new log data to the parsing buffer.
Parses and hashes the log records if new data found. Each time the hash table gets full (see max_mem), it will apply all the records from the hashmap to the pages ("a batch"), clearing the hashmap, and continuing this way till the end of stream.
| [in] | checkpoint_lsn | log sequence number found in checkpoint header. May be inexact (in a middle of an mtr which we can ignore, as it is already applied to tablespace files) until which all redo log has been scanned |
| MetadataRecover * recv_recovery_from_checkpoint_finish | ( | bool | aborting | ) |
Complete the recovery from the latest checkpoint.
| [in] | aborting | true if the server has to abort due to an error |
Recovers all tablespaces from the redo log.
| [in] | flush_lsn | lsn stored at offset FIL_PAGE_FILE_FLUSH_LSN in the system tablespace header |
|
static |
Prints diagnostic info of corrupt log.
| [in] | buffer | buffer containing corrupted data |
| [in] | pos | position in buffer where the error occurred |
| [in] | lsn | last processed lsn before the error occurred |
|
static |
Moves the parsing buffer data left to the buffer start.
| void recv_sys_close | ( | ) |
Release recovery system mutexes.
| void recv_sys_create | ( | ) |
Creates the recovery system.
|
static |
Empties the hash table when it has been fully processed.
|
static |
Free up recovery data structures.
| void recv_sys_free | ( | ) |
Frees the recovery system.
| void recv_sys_init | ( | ) |
Inits the recovery system for a recovery operation.
| bool recv_sys_resize_buf | ( | ) |
Resize the recovery parsing buffer up to log_buffer_size.
| void recv_sys_var_init | ( | ) |
Reset the state of the recovery system variables.
| void recv_track_changes_of_recovered_lsn | ( | ) |
|
static |
|
static |
recv_writer thread tasked with flushing dirty pages from the buffer pools.
| PSI_memory_key mem_log_recv_space_hash_key |
|
static |
| bool recv_lsn_checks_on |
true if buf_page_is_corrupted() should check if the log sequence number (FIL_PAGE_LSN) is in the future.
Initially false, and set by recv_recovery_from_checkpoint_start().
|
static |
The maximum lsn we see for a page during the recovery process.
If this is bigger than the lsn we are able to scan up to, that is an indication that the recovery failed and the database may be corrupt.
| size_t recv_n_frames_for_pages_per_pool_instance |
This many blocks must be left in each Buffer Pool instance to be managed by the LRU when we scan the log and store the scanned log records in a hashmap allocated in the Buffer Pool in frames of non-LRU managed blocks.
We will use these free blocks to read in pages when we start applying the log records to the database.
| bool recv_needed_recovery |
true when recv_init_crash_recovery() has been called.
|
static |
Read-ahead area in applying log records to file pages.
| volatile bool recv_recovery_on |
true when applying redo log records during crash recovery; false otherwise.
Note that this is false while a background thread is rolling back incomplete transactions.
|
static |
The following counter is used to decide when to print info on log scan.
| recv_sys_t* recv_sys = nullptr |
The recovery system.