MySQL 9.1.0
Source Code Documentation
|
Recovery. More...
#include "ha_prototypes.h"
#include <my_aes.h>
#include <sys/types.h>
#include <array>
#include <iomanip>
#include <map>
#include <new>
#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 "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 "srv0srv.h"
#include "srv0start.h"
#include "trx0purge.h"
Classes | |
struct | Log_checkpoint_location |
Describes location of a single checkpoint. More... | |
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 lsn_t | recv_read_log_seg (log_t &log, byte *buf, lsn_t start_lsn, lsn_t end_lsn) |
Reads a specified log segment to a buffer. More... | |
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... | |
static 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 bool | recv_report_corrupt_log (const byte *ptr, int type, space_id_t space, page_no_t page_no) |
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 bool | log_block_checksum_is_ok (const byte *block) |
Check the 4-byte checksum to the trailer checksum field of a log block. 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 bool | log_block_epoch_no_is_valid (uint32_t log_block_epoch_no, uint32_t last_epoch_no) |
Checks if a given log data block could be considered a next valid block, with regards to the epoch_no it has stored in its header, during the recovery. 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 () |
dberr_t | recv_verify_log_is_clean_pre_8_0_30 (log_t &log) |
Determine if a redo log from a version before MySQL 8.0.30 is clean. More... | |
static bool | recv_find_max_checkpoint (log_t &, Log_file_handle &file_handle, Log_checkpoint_location &checkpoint) |
Find the latest checkpoint in the given log file. More... | |
static bool | recv_find_max_checkpoint (log_t &log, Log_checkpoint_location &checkpoint) |
Find the latest checkpoint (check all existing redo log files). More... | |
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... | |
void | recv_apply_hashed_log_recs (log_t &log, bool allow_ibuf) |
Empties the hash table of stored log records, applying them to appropriate pages. More... | |
static bool | check_encryption (page_no_t page_no, space_id_t space_id, const byte *start, const byte *end) |
Check if redo log is for encryption information. More... | |
static const byte * | recv_parse_or_apply_log_rec_body (mlog_id_t type, const byte *ptr, const byte *end_ptr, space_id_t space_id, page_no_t page_no, buf_block_t *block, mtr_t *mtr, ulint parsed_bytes, lsn_t start_lsn) |
Try to parse a single log record body and also applies it if specified. More... | |
static void | recv_add_to_hash_table (mlog_id_t type, space_id_t space_id, page_no_t page_no, const byte *body, const byte *rec_end, 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... | |
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... | |
static ulint | recv_parse_log_rec (mlog_id_t *type, const byte *ptr, const byte *end_ptr, space_id_t *space_id, page_no_t *page_no, const byte **body) |
Tries to parse a single log record. More... | |
static bool | recv_update_bytes_to_ignore_before_checkpoint (size_t next_parsed_bytes) |
Subtracts next number of bytes to ignore before we reach the checkpoint or returns information that there was nothing more to skip. More... | |
static void | recv_track_changes_of_recovered_lsn () |
Tracks changes of recovered_lsn and tracks proper values for what first_rec_group should be for consecutive blocks. More... | |
static bool | recv_single_rec (const byte *ptr, const byte *end_ptr) |
Parse and store a single log record entry. More... | |
static bool | recv_multi_rec (const byte *ptr, const byte *end_ptr) |
Parse and store a multiple record log entry. More... | |
static void | recv_parse_log_recs () |
Parse log records from a buffer and optionally store them to a hash table to wait merging to file pages. More... | |
static bool | recv_sys_add_to_parsing_buf (const byte *log_block, lsn_t scanned_lsn) |
Adds data from a new log block to the parsing buffer of recv_sys if recv_sys->parse_start_lsn is non-zero. More... | |
static void | recv_reset_buffer () |
Moves the parsing buffer data left to the buffer start. More... | |
static bool | recv_scan_log_recs (log_t &log, size_t max_memory, const byte *buf, size_t len, lsn_t start_lsn, lsn_t *read_upto_lsn) |
Scans log from a buffer and stores new log data to the parsing buffer. More... | |
static dberr_t | recv_recovery_begin (log_t &log, const lsn_t checkpoint_lsn) |
Scans log from a buffer and stores new log data to the parsing buffer. More... | |
dberr_t | recv_recovery_from_checkpoint_start (log_t &log, lsn_t flush_lsn) |
Start recovering from a redo log checkpoint. More... | |
static void | verify_page_type (page_id_t page_id, page_type_t type) |
Check the page type, if there is a mismatch then throw fatal error. 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... | |
PSI_memory_key | mem_log_recv_page_hash_key |
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... | |
bool | recv_no_ibuf_operations |
If the following is true, the buffer pool file pages must be invalidated after recovery and no ibuf operations are allowed; this becomes true if the log record hash table becomes too full, and log records must be merged to file pages already before the recovery is finished: in this case no ibuf operations are allowed, as they could modify the pages read in the buffer pool before the pages have been recovered to the up-to-date state. More... | |
bool | recv_is_making_a_backup = false |
true When the redo log is being backed up More... | |
bool | recv_is_from_backup = false |
true when recovering from a backed up redo log file More... | |
static ulint | recv_scan_print_counter |
The following counter is used to decide when to print info on log scan. More... | |
static mlog_id_t | recv_previous_parsed_rec_type |
The type of the previous parsed redo log record. More... | |
static ulint | recv_previous_parsed_rec_offset |
The offset of the previous parsed redo log record. More... | |
static ulint | recv_previous_parsed_rec_is_multi |
The 'multi' flag of the previous parsed redo log record. 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.
|
inlinestatic |
Check if redo log is for encryption information.
[in] | page_no | Page number |
[in] | space_id | Tablespace identifier |
[in] | start | Redo log record body |
[in] | end | End of buffer |
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 |
Check the 4-byte checksum to the trailer checksum field of a log block.
[in] | block | pointer to a log block |
|
static |
Checks if a given log data block could be considered a next valid block, with regards to the epoch_no it has stored in its header, during the recovery.
[in] | log_block_epoch_no | epoch_no of the log data block to check |
[in] | last_epoch_no | epoch_no of the last data block scanned |
|
static |
|
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] | rec_end | log record end |
[in] | start_lsn | start lsn of the mtr |
[in] | end_lsn | end lsn of the mtr |
void recv_apply_hashed_log_recs | ( | log_t & | log, |
bool | allow_ibuf | ||
) |
Empties the hash table of stored log records, applying them to appropriate pages.
[in,out] | log | redo log |
[in] | allow_ibuf | if true, ibuf operations are allowed during the application; if false, no ibuf operations are allowed, and after the application all file pages are flushed to disk and invalidated in buffer pool: this alternative means that no new log records can be generated during the application; the caller must in this case own the log mutex |
|
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 |
Find the latest checkpoint in the given log file.
[in] | file_handle | handle for the opened redo log file |
[out] | checkpoint | the latest checkpoint found (if any) |
|
static |
Find the latest checkpoint (check all existing redo log files).
[in,out] | log | redo log |
[out] | checkpoint | the latest checkpoint found (if any) |
|
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.
Parse and store a multiple record log entry.
[in] | ptr | start of buffer |
[in] | end_ptr | end of buffer |
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 |
|
static |
Tries to parse a single log record.
[out] | type | log record type |
[in] | ptr | pointer to a buffer |
[in] | end_ptr | end of the buffer |
[out] | space_id | tablespace identifier |
[out] | page_no | page number |
[out] | body | start of log record body |
|
static |
Parse log records from a buffer and optionally store them to a hash table to wait merging to file pages.
|
static |
Try to parse a single log record body and also applies it if specified.
[in] | type | Redo log entry type |
[in] | ptr | Redo log record body |
[in] | end_ptr | End of buffer |
[in] | space_id | Tablespace identifier |
[in] | page_no | Page number |
[in,out] | block | Buffer block, or nullptr if a page log record should not be applied or if it is a MLOG_FILE_ operation |
[in,out] | mtr | Mini-transaction, or nullptr if a page log record should not be applied |
[in] | parsed_bytes | Number of bytes parsed so far |
[in] | start_lsn | lsn for REDO 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 |
Reads a specified log segment to a buffer.
[in,out] | log | redo log |
[in,out] | buf | buffer where to read |
[in] | start_lsn | read area start |
[in] | end_lsn | read area end |
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 buffer and stores new log data to the parsing buffer.
Parses and hashes the log records if new data found.
[in,out] | log | redo log |
[in,out] | 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 |
Start recovering from a redo log checkpoint.
[in,out] | log | 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] | ptr | pointer to corrupt log record |
[in] | type | type of the log record (could be garbage) |
[in] | space | tablespace ID (could be garbage) |
[in] | page_no | page number (could be garbage) |
|
static |
Moves the parsing buffer data left to the buffer start.
|
static |
Scans log from a buffer and stores new log data to the parsing buffer.
Parses and hashes the log records if new data found. Unless UNIV_HOTBACKUP is defined, this function will apply log records automatically when the hash table becomes full.
[in,out] | log | redo log |
[in] | max_memory | we let the hash table of recs to grow to this size, at the maximum |
[in] | buf | buffer containing a log segment or garbage |
[in] | len | buffer length |
[in] | start_lsn | buffer start lsn |
[out] | read_upto_lsn | scanning succeeded up to this lsn |
Parse and store a single log record entry.
[in] | ptr | start of buffer |
[in] | end_ptr | end of buffer |
Adds data from a new log block to the parsing buffer of recv_sys if recv_sys->parse_start_lsn is non-zero.
[in] | log_block | log block |
[in] | scanned_lsn | lsn of how far we were able to find data in this log block |
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.
|
static |
Resize the recovery parsing buffer up to log_buffer_size.
void recv_sys_var_init | ( | ) |
Reset the state of the recovery system variables.
|
static |
Tracks changes of recovered_lsn and tracks proper values for what first_rec_group should be for consecutive blocks.
Must be called when recv_sys->recovered_lsn is changed to next lsn pointing at boundary between consecutive parsed mini-transactions.
|
static |
Subtracts next number of bytes to ignore before we reach the checkpoint or returns information that there was nothing more to skip.
[in] | next_parsed_bytes | number of next bytes that were parsed, which are supposed to be subtracted from bytes to ignore before checkpoint |
true | there were still bytes to ignore |
false | there was already 0 bytes to ignore, nothing changed. |
Determine if a redo log from a version before MySQL 8.0.30 is clean.
[in,out] | log | redo log |
DB_SUCCESS | if the redo log is clean |
DB_ERROR | if the redo log is corrupted or dirty |
|
static |
|
static |
recv_writer thread tasked with flushing dirty pages from the buffer pools.
|
static |
Check the page type, if there is a mismatch then throw fatal error.
It may so happen that data file before 5.7 GA version may contain uninitialized bytes in the FIL_PAGE_TYPE field.
[in] | page_id | Page id to verify |
[in] | type | Expected page type |
PSI_memory_key mem_log_recv_page_hash_key |
PSI_memory_key mem_log_recv_space_hash_key |
bool recv_is_from_backup = false |
true when recovering from a backed up redo log file
bool recv_is_making_a_backup = false |
true When the redo log is being backed up
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.
bool recv_no_ibuf_operations |
If the following is true, the buffer pool file pages must be invalidated after recovery and no ibuf operations are allowed; this becomes true if the log record hash table becomes too full, and log records must be merged to file pages already before the recovery is finished: in this case no ibuf operations are allowed, as they could modify the pages read in the buffer pool before the pages have been recovered to the up-to-date state.
true means that recovery is running and no operations on the log files are allowed yet: the variable name is misleading.
|
static |
The 'multi' flag of the previous parsed redo log record.
|
static |
The offset of the previous parsed redo log record.
|
static |
The type of the previous parsed redo log record.
|
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.