MySQL  8.0.22
Source Code Documentation
log0log.h File Reference

Redo log constants and functions. More...

#include "dyn0buf.h"
#include "univ.i"
#include "sync0rw.h"
#include "log0test.h"
#include "log0types.h"
#include "my_compiler.h"
#include "log0log.ic"

Go to the source code of this file.

Macros

#define LOG_HEADER_CREATOR_CURRENT   "MySQL " INNODB_VERSION_STR
 Contents of the LOG_HEADER_CREATOR field. More...
 
#define LOG_HEADER_CREATOR_CLONE   "MySQL Clone"
 Header is created during DB clone. More...
 
#define log_checkpointer_mutex_enter(log)   mutex_enter(&((log).checkpointer_mutex))
 
#define log_checkpointer_mutex_exit(log)   mutex_exit(&((log).checkpointer_mutex))
 
#define log_checkpointer_mutex_own(log)   (mutex_own(&((log).checkpointer_mutex)) || !log_checkpointer_is_active())
 
#define log_closer_mutex_enter(log)   mutex_enter(&((log).closer_mutex))
 
#define log_closer_mutex_enter_nowait(log)   mutex_enter_nowait(&((log).closer_mutex))
 
#define log_closer_mutex_exit(log)   mutex_exit(&((log).closer_mutex))
 
#define log_flusher_mutex_enter(log)   mutex_enter(&((log).flusher_mutex))
 
#define log_flusher_mutex_enter_nowait(log)   mutex_enter_nowait(&((log).flusher_mutex))
 
#define log_flusher_mutex_exit(log)   mutex_exit(&((log).flusher_mutex))
 
#define log_flusher_mutex_own(log)   (mutex_own(&((log).flusher_mutex)) || !log_flusher_is_active())
 
#define log_flush_notifier_mutex_enter(log)   mutex_enter(&((log).flush_notifier_mutex))
 
#define log_flush_notifier_mutex_exit(log)   mutex_exit(&((log).flush_notifier_mutex))
 
#define log_flush_notifier_mutex_own(log)   (mutex_own(&((log).flush_notifier_mutex)) || !log_flush_notifier_is_active())
 
#define log_writer_mutex_enter(log)   mutex_enter(&((log).writer_mutex))
 
#define log_writer_mutex_enter_nowait(log)   mutex_enter_nowait(&((log).writer_mutex))
 
#define log_writer_mutex_exit(log)   mutex_exit(&((log).writer_mutex))
 
#define log_writer_mutex_own(log)   (mutex_own(&((log).writer_mutex)) || !log_writer_is_active())
 
#define log_write_notifier_mutex_enter(log)   mutex_enter(&((log).write_notifier_mutex))
 
#define log_write_notifier_mutex_exit(log)   mutex_exit(&((log).write_notifier_mutex))
 
#define log_write_notifier_mutex_own(log)   (mutex_own(&((log).write_notifier_mutex)) || !log_write_notifier_is_active())
 
#define log_limits_mutex_enter(log)   mutex_enter(&((log).limits_mutex))
 
#define log_limits_mutex_exit(log)   mutex_exit(&((log).limits_mutex))
 
#define log_limits_mutex_own(log)   mutex_own(&(log).limits_mutex)
 
#define LOG_SYNC_POINT(a)
 

Functions

void LOG_HEADER_SET_FLAG (uint32_t &flag, uint32_t bit)
 Set a specific bit in flag. More...
 
bool LOG_HEADER_CHECK_FLAG (uint32_t flag, uint32_t bit)
 Check a specific bit in flag. More...
 
bool log_block_get_flush_bit (const byte *log_block)
 Gets a log block flush bit. More...
 
void log_block_set_flush_bit (byte *log_block, bool value)
 Sets the log block flush bit. More...
 
uint32_t log_block_get_hdr_no (const byte *log_block)
 Gets a log block number stored in the header. More...
 
void log_block_set_hdr_no (byte *log_block, uint32_t n)
 Sets the log block number stored in the header. More...
 
uint32_t log_block_get_data_len (const byte *log_block)
 Gets a log block data length. More...
 
void log_block_set_data_len (byte *log_block, ulint len)
 Sets the log block data length. More...
 
uint32_t log_block_get_first_rec_group (const byte *log_block)
 Gets an offset to the beginning of the first group of log records in a given log block. More...
 
void log_block_set_first_rec_group (byte *log_block, uint32_t offset)
 Sets an offset to the beginning of the first group of log records in a given log block. More...
 
uint32_t log_block_get_checkpoint_no (const byte *log_block)
 Gets a log block checkpoint number field (4 lowest bytes). More...
 
void log_block_set_checkpoint_no (byte *log_block, uint64_t no)
 Sets a log block checkpoint number field (4 lowest bytes). More...
 
uint32_t log_block_convert_lsn_to_no (lsn_t lsn)
 Converts a lsn to a log block number. More...
 
uint32_t log_block_calc_checksum (const byte *log_block)
 Calculates the checksum for a log block. More...
 
uint32_t log_block_calc_checksum_crc32 (const byte *log_block)
 Calculates the checksum for a log block using the MySQL 5.7 algorithm. More...
 
uint32_t log_block_calc_checksum_none (const byte *log_block)
 Calculates the checksum for a log block using the "no-op" algorithm. More...
 
uint32_t log_block_get_checksum (const byte *log_block)
 Gets value of a log block checksum field. More...
 
void log_block_set_checksum (byte *log_block, uint32_t checksum)
 Sets value of a log block checksum field. More...
 
void log_block_store_checksum (byte *log_block)
 Stores a 4-byte checksum to the trailer checksum field of a log block. More...
 
lsn_t log_get_lsn (const log_t &log)
 Gets the current lsn value. More...
 
lsn_t log_get_checkpoint_lsn (const log_t &log)
 Gets the last checkpoint lsn stored and flushed to disk. More...
 
bool log_needs_free_check ()
 
void log_free_check ()
 Any database operation should call this when it has modified more than about 4 pages. More...
 
constexpr lsn_t log_translate_sn_to_lsn (lsn_t sn)
 Calculates lsn value for given sn value. More...
 
lsn_t log_translate_lsn_to_sn (lsn_t lsn)
 Calculates sn value for given lsn value. More...
 
bool log_lsn_validate (lsn_t lsn)
 Validates a given lsn value. More...
 
lsn_t log_get_checkpoint_age (const log_t &log)
 Calculates age of current checkpoint as number of bytes since last checkpoint. More...
 
Log_handle log_buffer_reserve (log_t &log, size_t len)
 Reserves space in the redo log for following write operations. More...
 
lsn_t log_buffer_write (log_t &log, const Log_handle &handle, const byte *str, size_t str_len, lsn_t start_lsn)
 Writes data to the log buffer. More...
 
void log_buffer_write_completed (log_t &log, const Log_handle &handle, lsn_t start_lsn, lsn_t end_lsn)
 Adds a link start_lsn -> end_lsn to the log recent written buffer. More...
 
void log_buffer_set_first_record_group (log_t &log, const Log_handle &handle, lsn_t rec_group_end_lsn)
 Modifies header of log block in the log buffer, which contains a given lsn value, and sets offset to the first group of log records within the block. More...
 
void log_buffer_close (log_t &log, const Log_handle &handle)
 Adds a link start_lsn -> end_lsn to the log recent closed buffer. More...
 
void log_buffer_flush_to_disk (log_t &log, bool sync=true)
 Write to the log file up to the last log entry. More...
 
void log_buffer_sync_in_background ()
 Writes the log buffer to the log file. More...
 
void log_buffer_flush_to_disk (bool sync=true)
 Requests flush of the log buffer. More...
 
lsn_t log_buffer_ready_for_write_lsn (const log_t &log)
 
lsn_t log_buffer_dirty_pages_added_up_to_lsn (const log_t &log)
 
lsn_t log_buffer_flush_order_lag (const log_t &log)
 
void log_buffer_get_last_block (log_t &log, lsn_t &last_lsn, byte *last_block, uint32_t &block_len)
 Get last redo block from redo buffer and end LSN. More...
 
bool log_advance_ready_for_write_lsn (log_t &log)
 Advances log.buf_ready_for_write_lsn using links in the recent written buffer. More...
 
void log_recent_written_empty_validate (const log_t &log, lsn_t begin, lsn_t end)
 Validates that all slots in log recent written buffer for lsn values in range between begin and end, are empty. More...
 
void log_recent_closed_empty_validate (const log_t &log, lsn_t begin, lsn_t end)
 Validates that all slots in log recent closed buffer for lsn values in range between begin and end, are empty. More...
 
void log_wait_for_space_in_log_recent_closed (log_t &log, lsn_t lsn)
 Waits until there is free space in the log recent closed buffer for any links start_lsn -> end_lsn, which start at provided start_lsn. More...
 
void log_wait_for_space_in_log_buf (log_t &log, sn_t end_sn)
 Waits until there is free space in the log buffer. More...
 
void log_wait_for_space (log_t &log, sn_t end_sn)
 Waits until there is free space for range of sn values ending at the provided sn, in both the log buffer and in the log files. More...
 
lsn_t log_get_free_check_capacity (const log_t &log)
 Computes capacity of redo log available until log_free_check() reaches point where it needs to wait. More...
 
lsn_t log_get_max_modified_age_async (const log_t &log)
 When the oldest dirty page age exceeds this value, we start an asynchronous preflush of dirty pages. More...
 
void log_free_check_wait (log_t &log)
 Waits until there is free space in log files which includes concurrency margin required for all threads. More...
 
void log_update_limits (log_t &log)
 Updates limits related to free space in redo log files: log.available_for_checkpoint_lsn and log.free_check_limit_sn. More...
 
void log_update_buf_limit (log_t &log)
 Updates limit used when writing to log buffer. More...
 
void log_update_buf_limit (log_t &log, lsn_t write_lsn)
 Updates limit used when writing to log buffer, according to provided write_lsn. More...
 
Wait_stats log_write_up_to (log_t &log, lsn_t lsn, bool flush_to_disk)
 Waits until the redo log is written up to a provided lsn. More...
 
bool log_read_encryption ()
 
bool log_write_encryption (byte *key, byte *iv, bool is_boot)
 Write the encryption info into the log file header(the 3rd block). More...
 
bool log_rotate_encryption ()
 Rotate the redo log encryption It will re-encrypt the redo log encryption metadata and write it to redo log file header. More...
 
void redo_rotate_default_master_key ()
 Rotate default master key for redo log encryption. More...
 
void log_request_checkpoint (log_t &log, bool sync, lsn_t lsn)
 Requests a sharp checkpoint write for provided or greater lsn. More...
 
void log_request_checkpoint (log_t &log, bool sync)
 Requests a fuzzy checkpoint write (for lsn currently available for checkpointing). More...
 
bool log_make_latest_checkpoint (log_t &log)
 Make a checkpoint at the current lsn. More...
 
bool log_make_latest_checkpoint ()
 Make a checkpoint at the current lsn. More...
 
void log_files_header_read (log_t &log, uint32_t header)
 Reads a log file header page to log.checkpoint_buf. More...
 
void log_files_header_fill (byte *buf, lsn_t start_lsn, const char *creator, bool no_logging, bool crash_unsafe)
 Fill redo log header. More...
 
void log_files_header_flush (log_t &log, uint32_t nth_file, lsn_t start_lsn)
 Writes a log file header to the log file space. More...
 
void log_files_downgrade (log_t &log)
 Changes format of redo files to previous format version. More...
 
void log_files_write_checkpoint (log_t &log, lsn_t next_checkpoint_lsn)
 Writes the next checkpoint info to header of the first log file. More...
 
void log_files_update_offsets (log_t &log, lsn_t lsn)
 Updates current_file_lsn and current_file_real_offset to correspond to a given lsn. More...
 
void log_buffer_x_lock_enter (log_t &log)
 Acquires the log buffer x-lock. More...
 
void log_buffer_x_lock_exit (log_t &log)
 Releases the log buffer x-lock. More...
 
uint64_t log_files_size_offset (const log_t &log, uint64_t offset)
 Calculates offset within log files, excluding headers of log files. More...
 
uint64_t log_files_real_offset (const log_t &log, uint64_t offset)
 Calculates offset within log files, including headers of log files. More...
 
uint64_t log_files_real_offset_for_lsn (const log_t &log, lsn_t lsn)
 Calculates offset within log files, including headers of log files, for the provided lsn value. More...
 
bool log_buffer_resize (log_t &log, size_t new_size)
 Changes size of the log buffer. More...
 
bool log_buffer_resize_low (log_t &log, size_t new_size, lsn_t end_lsn)
 Changes size of the log buffer. More...
 
void log_write_ahead_resize (log_t &log, size_t new_size)
 Resizes the write ahead buffer in the redo log. More...
 
void log_set_dict_max_allowed_checkpoint_lsn (log_t &log, lsn_t max_lsn)
 Updates the field log.dict_max_allowed_checkpoint_lsn. More...
 
void log_set_dict_persist_margin (log_t &log, sn_t margin)
 Updates log.dict_persist_margin and recompute free check limit. More...
 
void log_increase_concurrency_margin (log_t &log)
 Increase concurrency_margin used inside log_free_check() calls. More...
 
void log_print (const log_t &log, FILE *file)
 Prints information about important lsn values used in the redo log, and some statistics about speed of writing and flushing of data. More...
 
void log_refresh_stats (log_t &log)
 Refreshes the statistics used to print per-second averages in log_print(). More...
 
void log_create_first_checkpoint (log_t &log, lsn_t lsn)
 Creates the first checkpoint ever in the log files. More...
 
void log_calc_max_ages (log_t &log)
 Calculates limits for maximum age of checkpoint and maximum age of the oldest page. More...
 
bool log_calc_concurrency_margin (log_t &log)
 Updates concurrency margin. More...
 
bool log_sys_init (uint32_t n_files, uint64_t file_size, space_id_t space_id)
 Initializes the log system. More...
 
void log_start (log_t &log, checkpoint_no_t checkpoint_no, lsn_t checkpoint_lsn, lsn_t start_lsn)
 Starts the initialized redo log system using a provided checkpoint_lsn and current lsn. More...
 
void log_writer_thread_active_validate (const log_t &log)
 Validates that the log writer thread is active. More...
 
void log_background_write_threads_active_validate (const log_t &log)
 Validates that the log writer, flusher threads are active. More...
 
void log_background_threads_active_validate (const log_t &log)
 Validates that all the log background threads are active. More...
 
void log_background_threads_inactive_validate (const log_t &log)
 Validates that all the log background threads are inactive. More...
 
void log_start_background_threads (log_t &log)
 Starts all the log background threads. More...
 
void log_stop_background_threads (log_t &log)
 Stops all the log background threads. More...
 
void log_stop_background_threads_nowait (log_t &log)
 Marks the flag which tells log threads to stop and wakes them. More...
 
void log_wake_threads (log_t &log)
 Wakes up all log threads which are alive. More...
 
void log_control_writer_threads (log_t &log)
 Pause/Resume the log writer threads based on innodb_log_writer_threads value. More...
 
void log_sys_close ()
 Free the log system data structures. More...
 
void log_writer (log_t *log_ptr)
 The log writer thread co-routine. More...
 
void log_flusher (log_t *log_ptr)
 The log flusher thread co-routine. More...
 
void log_flush_notifier (log_t *log_ptr)
 The log flush notifier thread co-routine. More...
 
void log_write_notifier (log_t *log_ptr)
 The log write notifier thread co-routine. More...
 
void log_checkpointer (log_t *log_ptr)
 The log checkpointer thread co-routine. More...
 
void log_position_lock (log_t &log)
 Lock redo log. More...
 
void log_position_unlock (log_t &log)
 Unlock the locked redo log. More...
 
void log_position_collect_lsn_info (const log_t &log, lsn_t *current_lsn, lsn_t *checkpoint_lsn)
 Collect coordinates in the locked redo log. More...
 
bool log_writer_is_active ()
 Checks if log writer thread is active. More...
 
bool log_write_notifier_is_active ()
 Checks if log write notifier thread is active. More...
 
bool log_flusher_is_active ()
 Checks if log flusher thread is active. More...
 
bool log_flush_notifier_is_active ()
 Checks if log flush notifier thread is active. More...
 
bool log_checkpointer_is_active ()
 Checks if log checkpointer thread is active. More...
 
bool log_file_header_fill_encryption (byte *buf, byte *key, byte *iv, bool is_boot, bool encrypt_key)
 Writes encryption information to log header. More...
 
void log_persist_disable (log_t &log)
 Disable redo logging and persist the information. More...
 
void log_persist_enable (log_t &log)
 Enable redo logging and persist the information. More...
 
void log_persist_crash_safe (log_t &log)
 Persist the information that it is safe to restart server. More...
 

Variables

constexpr const char *const ib_logfile_basename = "ib_logfile"
 Prefix for name of log file, e.g. More...
 
constexpr uint32_t MAX_LOG_FILE_NAME = 32
 
constexpr uint32_t LOG_NO_CHECKSUM_MAGIC = 0xDEADBEEFUL
 Magic value to use instead of log checksums when they are disabled. More...
 
constexpr uint32_t LOG_CHECKPOINT_EXTRA_FREE = 8
 Absolute margin for the free space in the log, before a new query step which modifies the database, is started. More...
 
constexpr uint32_t LOG_CHECKPOINT_FREE_PER_THREAD = 4
 Per thread margin for the free space in the log, before a new query step which modifies the database, is started. More...
 
constexpr uint32_t LOG_POOL_CHECKPOINT_RATIO_ASYNC = 32
 Controls asynchronous making of a new checkpoint. More...
 
constexpr uint32_t LOG_POOL_PREFLUSH_RATIO_SYNC = 16
 Controls synchronous preflushing of modified buffer pages. More...
 
constexpr uint32_t LOG_POOL_PREFLUSH_RATIO_ASYNC = 8
 Controls asynchronous preflushing of modified buffer pages. More...
 
constexpr lsn_t LOG_START_LSN = 16 * OS_FILE_LOG_BLOCK_SIZE
 The counting of lsn's starts from this value: this must be non-zero. More...
 
constexpr uint32_t LOG_BLOCK_HDR_NO = 0
 Block number which must be > 0 and is allowed to wrap around at 1G. More...
 
constexpr uint32_t LOG_BLOCK_FLUSH_BIT_MASK = 0x80000000UL
 Mask used to get the highest bit in the hdr_no field. More...
 
constexpr uint32_t LOG_BLOCK_MAX_NO = 0x3FFFFFFFUL + 1
 Maximum allowed block's number (stored in hdr_no). More...
 
constexpr uint32_t LOG_BLOCK_HDR_DATA_LEN = 4
 Number of bytes written to this block (also header bytes). More...
 
constexpr uint32_t LOG_BLOCK_ENCRYPT_BIT_MASK = 0x8000UL
 Mask used to get the highest bit in the data len field, this bit is to indicate if this block is encrypted or not. More...
 
constexpr uint32_t LOG_BLOCK_FIRST_REC_GROUP = 6
 Offset of the first start of mtr log record group in this log block. More...
 
constexpr uint32_t LOG_BLOCK_CHECKPOINT_NO = 8
 4 lower bytes of the value of log_sys->next_checkpoint_no when the log block was last written to: if the block has not yet been written full, this value is only updated before a log buffer flush. More...
 
constexpr uint32_t LOG_BLOCK_HDR_SIZE = 12
 Size of the log block's header in bytes. More...
 
constexpr uint32_t LOG_BLOCK_CHECKSUM = 4
 4 byte checksum of the log block contents. More...
 
constexpr uint32_t LOG_BLOCK_TRL_SIZE = 4
 Size of the log block footer (trailer) in bytes. More...
 
constexpr uint32_t LOG_BLOCK_DATA_SIZE
 Size of log block's data fragment (where actual data is stored). More...
 
constexpr sn_t SN_MAX = (1ULL << 62) - 1
 Ensure, that 64 bits are enough to represent lsn values, when 63 bits are used to represent sn values. More...
 
constexpr sn_t SN_LOCKED = 1ULL << 63
 The sn bit to express locked state. More...
 
constexpr lsn_t LSN_MAX = (1ULL << 63) - 1
 Maximum possible lsn value is slightly higher than the maximum sn value, because lsn sequence enumerates also bytes used for headers and footers of all log blocks. More...
 
constexpr uint32_t LOG_CHECKPOINT_NO = 0
 Checkpoint number. More...
 
constexpr uint32_t LOG_CHECKPOINT_LSN = 8
 Checkpoint lsn. More...
 
constexpr uint32_t LOG_CHECKPOINT_OFFSET = 16
 Offset within the log files, which corresponds to checkpoint lsn. More...
 
constexpr uint32_t LOG_CHECKPOINT_LOG_BUF_SIZE = 24
 Size of the log buffer, when the checkpoint write was started. More...
 
constexpr uint32_t LOG_HEADER_FORMAT = 0
 Offsets used in a log file header. More...
 
constexpr uint32_t LOG_HEADER_PAD1 = 4
 4 unused (zero-initialized) bytes. More...
 
constexpr uint32_t LOG_HEADER_START_LSN = 8
 LSN of the start of data in this log file (with format version 1 and 2). More...
 
constexpr uint32_t LOG_HEADER_CREATOR = 16
 A null-terminated string which will contain either the string 'MEB' and the MySQL version if the log file was created by mysqlbackup, or 'MySQL' and the MySQL version that created the redo log file. More...
 
constexpr uint32_t LOG_HEADER_CREATOR_END = LOG_HEADER_CREATOR + 32
 End of the log file creator field. More...
 
constexpr uint32_t LOG_HEADER_FLAGS = LOG_HEADER_CREATOR_END
 32 BITs flag More...
 
constexpr uint32_t LOG_HEADER_FLAG_NO_LOGGING = 1
 Flag at BIT-1 to indicate if redo logging is disabled or not. More...
 
constexpr uint32_t LOG_HEADER_FLAG_CRASH_UNSAFE = 2
 Flag at BIT-2 to indicate if server is not recoverable on crash. More...
 
constexpr uint32_t LOG_HEADER_FLAG_MAX = LOG_HEADER_FLAG_CRASH_UNSAFE
 Maximum BIT position number. More...
 
constexpr uint32_t LOG_HEADER_SIZE = LOG_HEADER_FLAGS + 4
 Current total size of LOG header. More...
 
constexpr uint32_t LOG_CHECKPOINT_1 = OS_FILE_LOG_BLOCK_SIZE
 First checkpoint field in the log header. More...
 
constexpr uint32_t LOG_ENCRYPTION = 2 * OS_FILE_LOG_BLOCK_SIZE
 Log Encryption information in redo log header. More...
 
constexpr uint32_t LOG_CHECKPOINT_2 = 3 * OS_FILE_LOG_BLOCK_SIZE
 Second checkpoint field in the header of the first log file. More...
 
constexpr uint32_t LOG_FILE_HDR_SIZE = 4 * OS_FILE_LOG_BLOCK_SIZE
 Size of log file's header. More...
 
constexpr ulint INNODB_LOG_WRITE_MAX_SIZE_DEFAULT = 4096
 Constants related to server variables (default, min and max values). More...
 
constexpr ulong INNODB_LOG_CHECKPOINT_EVERY_DEFAULT = 1000
 Default value of innodb_log_checkpointer_every (in milliseconds). More...
 
constexpr ulong INNODB_LOG_WRITER_SPIN_DELAY_DEFAULT = 250000
 Default value of innodb_log_writer_spin_delay (in spin rounds). More...
 
constexpr ulong INNODB_LOG_WRITER_TIMEOUT_DEFAULT = 10
 Default value of innodb_log_writer_timeout (in microseconds). More...
 
constexpr ulong INNODB_LOG_SPIN_CPU_ABS_LWM_DEFAULT = 80
 Default value of innodb_log_spin_cpu_abs_lwm. More...
 
constexpr uint INNODB_LOG_SPIN_CPU_PCT_HWM_DEFAULT = 50
 Default value of innodb_log_spin_cpu_pct_hwm. More...
 
constexpr ulong INNODB_LOG_WAIT_FOR_WRITE_SPIN_DELAY_DEFAULT = 25000
 Default value of innodb_log_wait_for_write_spin_delay (in spin rounds). More...
 
constexpr ulong INNODB_LOG_WAIT_FOR_WRITE_TIMEOUT_DEFAULT = 1000
 Default value of innodb_log_wait_for_write_timeout (in microseconds). More...
 
constexpr ulong INNODB_LOG_WAIT_FOR_FLUSH_SPIN_DELAY_DEFAULT = 25000
 Default value of innodb_log_wait_for_flush_spin_delay (in spin rounds). More...
 
constexpr ulong INNODB_LOG_WAIT_FOR_FLUSH_SPIN_HWM_DEFAULT = 400
 Default value of innodb_log_wait_for_flush_spin_hwm (in microseconds). More...
 
constexpr ulong INNODB_LOG_WAIT_FOR_FLUSH_TIMEOUT_DEFAULT = 1000
 Default value of innodb_log_wait_for_flush_timeout (in microseconds). More...
 
constexpr ulong INNODB_LOG_FLUSHER_SPIN_DELAY_DEFAULT = 250000
 Default value of innodb_log_flusher_spin_delay (in spin rounds). More...
 
constexpr ulong INNODB_LOG_FLUSHER_TIMEOUT_DEFAULT = 10
 Default value of innodb_log_flusher_timeout (in microseconds). More...
 
constexpr ulong INNODB_LOG_WRITE_NOTIFIER_SPIN_DELAY_DEFAULT = 0
 Default value of innodb_log_write_notifier_spin_delay (in spin rounds). More...
 
constexpr ulong INNODB_LOG_WRITE_NOTIFIER_TIMEOUT_DEFAULT = 10
 Default value of innodb_log_write_notifier_timeout (in microseconds). More...
 
constexpr ulong INNODB_LOG_FLUSH_NOTIFIER_SPIN_DELAY_DEFAULT = 0
 Default value of innodb_log_flush_notifier_spin_delay (in spin rounds). More...
 
constexpr ulong INNODB_LOG_FLUSH_NOTIFIER_TIMEOUT_DEFAULT = 10
 Default value of innodb_log_flush_notifier_timeout (in microseconds). More...
 
constexpr ulong INNODB_LOG_BUFFER_SIZE_DEFAULT = 16 * 1024 * 1024UL
 Default value of innodb_log_buffer_size (in bytes). More...
 
constexpr ulong INNODB_LOG_BUFFER_SIZE_MIN = 256 * 1024UL
 Minimum allowed value of innodb_log_buffer_size. More...
 
constexpr ulong INNODB_LOG_BUFFER_SIZE_MAX = ULONG_MAX
 Maximum allowed value of innodb_log_buffer_size. More...
 
constexpr ulong INNODB_LOG_RECENT_WRITTEN_SIZE_DEFAULT = 1024 * 1024
 Default value of innodb_log_recent_written_size (in bytes). More...
 
constexpr ulong INNODB_LOG_RECENT_WRITTEN_SIZE_MIN = OS_FILE_LOG_BLOCK_SIZE
 Minimum allowed value of innodb_log_recent_written_size. More...
 
constexpr ulong INNODB_LOG_RECENT_WRITTEN_SIZE_MAX = 1024 * 1024 * 1024UL
 Maximum allowed value of innodb_log_recent_written_size. More...
 
constexpr ulong INNODB_LOG_RECENT_CLOSED_SIZE_DEFAULT = 2 * 1024 * 1024
 Default value of innodb_log_recent_closed_size (in bytes). More...
 
constexpr ulong INNODB_LOG_RECENT_CLOSED_SIZE_MIN = OS_FILE_LOG_BLOCK_SIZE
 Minimum allowed value of innodb_log_recent_closed_size. More...
 
constexpr ulong INNODB_LOG_RECENT_CLOSED_SIZE_MAX = 1024 * 1024 * 1024UL
 Maximum allowed value of innodb_log_recent_closed_size. More...
 
constexpr ulong INNODB_LOG_EVENTS_DEFAULT = 2048
 Default value of innodb_log_events (number of events). More...
 
constexpr ulong INNODB_LOG_EVENTS_MIN = 1
 Minimum allowed value of innodb_log_events. More...
 
constexpr ulong INNODB_LOG_EVENTS_MAX = 1024 * 1024 * 1024UL
 Maximum allowed value of innodb_log_events. More...
 
constexpr ulong INNODB_LOG_WRITE_AHEAD_SIZE_DEFAULT = 8192
 Default value of innodb_log_write_ahead_size (in bytes). More...
 
constexpr ulong INNODB_LOG_WRITE_AHEAD_SIZE_MIN = OS_FILE_LOG_BLOCK_SIZE
 Minimum allowed value of innodb_log_write_ahead_size. More...
 
constexpr ulint INNODB_LOG_WRITE_AHEAD_SIZE_MAX
 Maximum allowed value of innodb_log_write_ahead_size. More...
 
constexpr int64_t MLOG_TEST_VALUE = 10000
 Value to which MLOG_TEST records should sum up within a group. More...
 
constexpr uint32_t MLOG_TEST_MAX_REC_LEN = 100
 Maximum size of single MLOG_TEST record (in bytes). More...
 
constexpr uint32_t MLOG_TEST_GROUP_MAX_REC_N = 100
 Maximum number of MLOG_TEST records in single group of log records. More...
 
constexpr uint32_t MLOG_TEST_REC_OVERHEAD = 37
 Bytes consumed by MLOG_TEST record with an empty payload. More...
 
log_tlog_sys
 Redo log system (singleton). More...
 
log_checksum_func_t log_checksum_algorithm_ptr
 Pointer to the log checksum calculation function. More...
 
std::unique_ptr< Log_testlog_test
 Represents currently running test of redo log, nullptr otherwise. More...
 

Detailed Description

Redo log constants and functions.

Types are defined inside log0types.h.

Created 12/9/1995 Heikki Tuuri

Macro Definition Documentation

◆ log_checkpointer_mutex_enter

#define log_checkpointer_mutex_enter (   log)    mutex_enter(&((log).checkpointer_mutex))

◆ log_checkpointer_mutex_exit

#define log_checkpointer_mutex_exit (   log)    mutex_exit(&((log).checkpointer_mutex))

◆ log_checkpointer_mutex_own

#define log_checkpointer_mutex_own (   log)    (mutex_own(&((log).checkpointer_mutex)) || !log_checkpointer_is_active())

◆ log_closer_mutex_enter

#define log_closer_mutex_enter (   log)    mutex_enter(&((log).closer_mutex))

◆ log_closer_mutex_enter_nowait

#define log_closer_mutex_enter_nowait (   log)    mutex_enter_nowait(&((log).closer_mutex))

◆ log_closer_mutex_exit

#define log_closer_mutex_exit (   log)    mutex_exit(&((log).closer_mutex))

◆ log_flush_notifier_mutex_enter

#define log_flush_notifier_mutex_enter (   log)    mutex_enter(&((log).flush_notifier_mutex))

◆ log_flush_notifier_mutex_exit

#define log_flush_notifier_mutex_exit (   log)    mutex_exit(&((log).flush_notifier_mutex))

◆ log_flush_notifier_mutex_own

#define log_flush_notifier_mutex_own (   log)    (mutex_own(&((log).flush_notifier_mutex)) || !log_flush_notifier_is_active())

◆ log_flusher_mutex_enter

#define log_flusher_mutex_enter (   log)    mutex_enter(&((log).flusher_mutex))

◆ log_flusher_mutex_enter_nowait

#define log_flusher_mutex_enter_nowait (   log)    mutex_enter_nowait(&((log).flusher_mutex))

◆ log_flusher_mutex_exit

#define log_flusher_mutex_exit (   log)    mutex_exit(&((log).flusher_mutex))

◆ log_flusher_mutex_own

#define log_flusher_mutex_own (   log)    (mutex_own(&((log).flusher_mutex)) || !log_flusher_is_active())

◆ LOG_HEADER_CREATOR_CLONE

#define LOG_HEADER_CREATOR_CLONE   "MySQL Clone"

Header is created during DB clone.

◆ LOG_HEADER_CREATOR_CURRENT

#define LOG_HEADER_CREATOR_CURRENT   "MySQL " INNODB_VERSION_STR

Contents of the LOG_HEADER_CREATOR field.

◆ log_limits_mutex_enter

#define log_limits_mutex_enter (   log)    mutex_enter(&((log).limits_mutex))

◆ log_limits_mutex_exit

#define log_limits_mutex_exit (   log)    mutex_exit(&((log).limits_mutex))

◆ log_limits_mutex_own

#define log_limits_mutex_own (   log)    mutex_own(&(log).limits_mutex)

◆ LOG_SYNC_POINT

#define LOG_SYNC_POINT (   a)
Value:
do { \
DEBUG_SYNC_C(a); \
DBUG_EXECUTE_IF(a, DBUG_SUICIDE();); \
if (log_test != nullptr) { \
log_test->sync_point(a); \
} \
} while (0)
std::unique_ptr< Log_test > log_test
Represents currently running test of redo log, nullptr otherwise.
Definition: log0test.cc:52
#define DBUG_SUICIDE()
Definition: my_dbug.h:229

◆ log_write_notifier_mutex_enter

#define log_write_notifier_mutex_enter (   log)    mutex_enter(&((log).write_notifier_mutex))

◆ log_write_notifier_mutex_exit

#define log_write_notifier_mutex_exit (   log)    mutex_exit(&((log).write_notifier_mutex))

◆ log_write_notifier_mutex_own

#define log_write_notifier_mutex_own (   log)    (mutex_own(&((log).write_notifier_mutex)) || !log_write_notifier_is_active())

◆ log_writer_mutex_enter

#define log_writer_mutex_enter (   log)    mutex_enter(&((log).writer_mutex))

◆ log_writer_mutex_enter_nowait

#define log_writer_mutex_enter_nowait (   log)    mutex_enter_nowait(&((log).writer_mutex))

◆ log_writer_mutex_exit

#define log_writer_mutex_exit (   log)    mutex_exit(&((log).writer_mutex))

◆ log_writer_mutex_own

#define log_writer_mutex_own (   log)    (mutex_own(&((log).writer_mutex)) || !log_writer_is_active())

Function Documentation

◆ log_advance_ready_for_write_lsn()

bool log_advance_ready_for_write_lsn ( log_t log)

Advances log.buf_ready_for_write_lsn using links in the recent written buffer.

It's used by the log writer thread only.

Parameters
[in]logredo log
Returns
true if and only if the lsn has been advanced

◆ log_background_threads_active_validate()

void log_background_threads_active_validate ( const log_t log)

Validates that all the log background threads are active.

Used only to assert, that the state is correct.

Parameters
[in]logredo log

◆ log_background_threads_inactive_validate()

void log_background_threads_inactive_validate ( const log_t log)

Validates that all the log background threads are inactive.

Used only to assert, that the state is correct.

Parameters
[in]logredo log

◆ log_background_write_threads_active_validate()

void log_background_write_threads_active_validate ( const log_t log)

Validates that the log writer, flusher threads are active.

Used only to assert, that the state is correct.

Parameters
[in]logredo log

◆ log_block_calc_checksum()

uint32_t log_block_calc_checksum ( const byte log_block)
inline

Calculates the checksum for a log block.

Parameters
[in]log_blocklog block
Returns
checksum

◆ log_block_calc_checksum_crc32()

uint32_t log_block_calc_checksum_crc32 ( const byte log_block)
inline

Calculates the checksum for a log block using the MySQL 5.7 algorithm.

Parameters
[in]log_blocklog block
Returns
checksum

◆ log_block_calc_checksum_none()

uint32_t log_block_calc_checksum_none ( const byte log_block)
inline

Calculates the checksum for a log block using the "no-op" algorithm.

Parameters
[in]log_blocklog block
Returns
checksum

◆ log_block_convert_lsn_to_no()

uint32_t log_block_convert_lsn_to_no ( lsn_t  lsn)
inline

Converts a lsn to a log block number.

Consecutive log blocks have consecutive numbers (unless the sequence wraps). It is guaranteed that the calculated number is greater than zero.

Parameters
[in]lsnlsn of a byte within the block
Returns
log block number, it is > 0 and <= 1G

◆ log_block_get_checkpoint_no()

uint32_t log_block_get_checkpoint_no ( const byte log_block)
inline

Gets a log block checkpoint number field (4 lowest bytes).

Parameters
[in]log_blocklog block
Returns
checkpoint no (4 lowest bytes)

◆ log_block_get_checksum()

uint32_t log_block_get_checksum ( const byte log_block)
inline

Gets value of a log block checksum field.

Parameters
[in]log_blocklog block
Returns
checksum

◆ log_block_get_data_len()

uint32_t log_block_get_data_len ( const byte log_block)
inline

Gets a log block data length.

Parameters
[in]log_blocklog block
Returns
log block data length measured as a byte offset from the block start

◆ log_block_get_first_rec_group()

uint32_t log_block_get_first_rec_group ( const byte log_block)
inline

Gets an offset to the beginning of the first group of log records in a given log block.

Parameters
[in]log_blocklog block
Returns
first mtr log record group byte offset from the block start, 0 if none.

◆ log_block_get_flush_bit()

bool log_block_get_flush_bit ( const byte log_block)
inline

Gets a log block flush bit.

The flush bit is set, if and only if, the block was the first block written in a call to fil_io().

During recovery, when encountered the flush bit, recovery code can be pretty sure, that all previous blocks belong to a completed fil_io(), because the block with flush bit belongs to the next call to fil_io(), which could only be started after the previous one has been finished.

Parameters
[in]log_blocklog block
Returns
true if this block was the first to be written in fil_io().

◆ log_block_get_hdr_no()

uint32_t log_block_get_hdr_no ( const byte log_block)
inline

Gets a log block number stored in the header.

The number corresponds to lsn range for data stored in the block.

During recovery, when a next block is being parsed, a next range of lsn values is expected to be read. This corresponds to a log block number increased by one. However, if a smaller number is read from the header, it is then considered the end of the redo log and recovery is finished. In such case, the next block is most likely an empty block or a block from the past, because the redo log is written in circular manner.

Parameters
[in]log_blocklog block (may be invalid or empty block)
Returns
log block number stored in the block header

◆ log_block_set_checkpoint_no()

void log_block_set_checkpoint_no ( byte log_block,
uint64_t  no 
)
inline

Sets a log block checkpoint number field (4 lowest bytes).

Parameters
[in,out]log_blocklog block
[in]nocheckpoint no

◆ log_block_set_checksum()

void log_block_set_checksum ( byte log_block,
uint32_t  checksum 
)
inline

Sets value of a log block checksum field.

Parameters
[in,out]log_blocklog block
[in]checksumchecksum

◆ log_block_set_data_len()

void log_block_set_data_len ( byte log_block,
ulint  len 
)
inline

Sets the log block data length.

Parameters
[in,out]log_blocklog block
[in]lendata length (
See also
log_block_get_data_len)

◆ log_block_set_first_rec_group()

void log_block_set_first_rec_group ( byte log_block,
uint32_t  offset 
)
inline

Sets an offset to the beginning of the first group of log records in a given log block.

Parameters
[in,out]log_blocklog block
[in]offsetoffset, 0 if none

◆ log_block_set_flush_bit()

void log_block_set_flush_bit ( byte log_block,
bool  value 
)
inline

Sets the log block flush bit.

Parameters
[in,out]log_blocklog block (must have hdr_no != 0)
[in]valuevalue to set

◆ log_block_set_hdr_no()

void log_block_set_hdr_no ( byte log_block,
uint32_t  n 
)
inline

Sets the log block number stored in the header.

NOTE that this must be set before the flush bit!

Parameters
[in,out]log_blocklog block
[in]nlog block number: must be in (0, 1G]

◆ log_block_store_checksum()

void log_block_store_checksum ( byte log_block)
inline

Stores a 4-byte checksum to the trailer checksum field of a log block.

This is used before writing the log block to disk. The checksum in a log block is used in recovery to check the consistency of the log block.

Parameters
[in]log_blocklog block (completely filled in!)

◆ log_buffer_close()

void log_buffer_close ( log_t log,
const Log_handle handle 
)

Adds a link start_lsn -> end_lsn to the log recent closed buffer.

This is called after all dirty pages related to [start_lsn, end_lsn) have been added to corresponding flush lists. For detailed explanation -

See also
log0write.cc.
Adding link to the log recent
Parameters
[in,out]logredo log
[in]handlehandle for the reservation of space

◆ log_buffer_dirty_pages_added_up_to_lsn()

lsn_t log_buffer_dirty_pages_added_up_to_lsn ( const log_t log)
inline
Returns
lsn up to which all dirty pages have been added to flush list

◆ log_buffer_flush_order_lag()

lsn_t log_buffer_flush_order_lag ( const log_t log)
inline
Returns
capacity of the recent_closed, or 0 if !log_use_threads()

◆ log_buffer_flush_to_disk() [1/2]

void log_buffer_flush_to_disk ( log_t log,
bool  sync = true 
)

Write to the log file up to the last log entry.

Parameters
[in,out]logredo log
[in]syncwhether we want the written log also to be flushed to disk.

◆ log_buffer_flush_to_disk() [2/2]

void log_buffer_flush_to_disk ( bool  sync = true)
inline

Requests flush of the log buffer.

Parameters
[in]synctrue: wait until the flush is done

◆ log_buffer_get_last_block()

void log_buffer_get_last_block ( log_t log,
lsn_t last_lsn,
byte last_block,
uint32_t &  block_len 
)

Get last redo block from redo buffer and end LSN.

Note that it takes x-lock on the log buffer for a short period. Out values are always set, even when provided last_block is nullptr.

Parameters
[in,out]logredo log
[out]last_lsnend lsn of last mtr
[out]last_blocklast redo block
[in,out]block_lenlength in bytes

◆ log_buffer_ready_for_write_lsn()

lsn_t log_buffer_ready_for_write_lsn ( const log_t log)
inline
Returns
lsn up to which all writes to log buffer have been finished

◆ log_buffer_reserve()

Log_handle log_buffer_reserve ( log_t log,
size_t  len 
)

Reserves space in the redo log for following write operations.

Space is reserved for a given number of data bytes. Additionally bytes for required headers and footers of log blocks are reserved.

After the space is reserved, range of lsn values from a start_lsn to an end_lsn is assigned. The log writer thread cannot proceed further than to the start_lsn, until a link start_lsn -> end_lsn has been added to the log recent written buffer.

NOTE that the link is added after data is written to the reserved space in the log buffer. It is very critical to do all these steps as fast as possible, because very likely the log writer thread is waiting for the link.

See also
Reservation of space in the redo
Parameters
[in,out]logredo log
[in]lennumber of data bytes to reserve for write
Returns
handle that represents the reservation

◆ log_buffer_resize()

bool log_buffer_resize ( log_t log,
size_t  new_size 
)

Changes size of the log buffer.

This is a thread-safe version. It is used by SET GLOBAL innodb_log_buffer_size = X.

Parameters
[in,out]logredo log
[in]new_sizerequested new size
Returns
true iff succeeded in resize

◆ log_buffer_resize_low()

bool log_buffer_resize_low ( log_t log,
size_t  new_size,
lsn_t  end_lsn 
)

Changes size of the log buffer.

This is a non-thread-safe version which might be invoked only when there are no concurrent possible writes to the log buffer. It is used in log_buffer_reserve() when a requested size to reserve is larger than size of the log buffer.

Parameters
[in,out]logredo log
[in]new_sizerequested new size
[in]end_lsnmaximum lsn written to log buffer
Returns
true iff succeeded in resize

◆ log_buffer_set_first_record_group()

void log_buffer_set_first_record_group ( log_t log,
const Log_handle handle,
lsn_t  rec_group_end_lsn 
)

Modifies header of log block in the log buffer, which contains a given lsn value, and sets offset to the first group of log records within the block.

This is used by mtr after writing a log record group which ends at lsn belonging to different log block than lsn at which the group was started. When write was finished at the last data byte of log block, it is considered ended in the next log block, because the next data byte belongs to that block.

During recovery, when recovery is started in the middle of some group of log records, it first looks for the beginning of the next group.

Parameters
[in,out]logredo log
[in]handlehandle for the reservation of space
[in]rec_group_end_lsnlsn at which the first log record group starts within the block containing this lsn value

◆ log_buffer_sync_in_background()

void log_buffer_sync_in_background ( )

Writes the log buffer to the log file.

It is intended to be called from background master thread periodically. If the log writer threads are active, this function writes nothing.

◆ log_buffer_write()

lsn_t log_buffer_write ( log_t log,
const Log_handle handle,
const byte str,
size_t  str_len,
lsn_t  start_lsn 
)

Writes data to the log buffer.

The space in the redo log has to be reserved before calling to this function and lsn pointing to inside the reserved range of lsn values has to be provided.

The write does not have to cover the whole reserved space, but may not overflow it. If it does not cover, then returned value should be used to start the next write operation. Note that finally we must use exactly all the reserved space.

See also
Copying data to the reserved space
Parameters
[in,out]logredo log
[in]handlehandle for the reservation of space
[in]strmemory to write data from
[in]str_lennumber of bytes to write
[in]start_lsnlsn to start writing at (the reserved space)
Returns
end_lsn after writing the data (in the reserved space), could be used to start the next write operation if there is still free space in the reserved space

◆ log_buffer_write_completed()

void log_buffer_write_completed ( log_t log,
const Log_handle handle,
lsn_t  start_lsn,
lsn_t  end_lsn 
)

Adds a link start_lsn -> end_lsn to the log recent written buffer.

This function must be called after the data has been written to the fragment of log buffer represented by range [start_lsn, end_lsn). After the link is added, the log writer may write the data to disk.

NOTE that still dirty pages for the [start_lsn, end_lsn) are not added to flush lists when this function is called.

See also
Adding links to the
Parameters
[in,out]logredo log
[in]handlehandle for the reservation of space
[in]start_lsnstart_lsn of the link to add
[in]end_lsnend_lsn of the link to add

◆ log_buffer_x_lock_enter()

void log_buffer_x_lock_enter ( log_t log)

Acquires the log buffer x-lock.

Parameters
[in,out]logredo log

◆ log_buffer_x_lock_exit()

void log_buffer_x_lock_exit ( log_t log)

Releases the log buffer x-lock.

Parameters
[in,out]logredo log

◆ log_calc_concurrency_margin()

bool log_calc_concurrency_margin ( log_t log)

Updates concurrency margin.

Uses current value of srv_thread_concurrency.

Parameters
[in,out]logredo log
Return values
trueif success
falseif the redo log is too small to accommodate the number of OS threads in the database server

◆ log_calc_max_ages()

void log_calc_max_ages ( log_t log)

Calculates limits for maximum age of checkpoint and maximum age of the oldest page.

Parameters
[in,out]logredo log

◆ log_checkpointer()

void log_checkpointer ( log_t log_ptr)

The log checkpointer thread co-routine.

See also
Thread: log checkpointer
Parameters
[in,out]log_ptrpointer to redo log

◆ log_checkpointer_is_active()

bool log_checkpointer_is_active ( )
inline

Checks if log checkpointer thread is active.

Returns
true if and only if the log checkpointer thread is active

◆ log_control_writer_threads()

void log_control_writer_threads ( log_t log)

Pause/Resume the log writer threads based on innodb_log_writer_threads value.

NOTE: These pause/resume functions should be protected by mutex while serving. The caller innodb_log_writer_threads_update() is protected by LOCK_global_system_variables in mysqld.

◆ log_create_first_checkpoint()

void log_create_first_checkpoint ( log_t log,
lsn_t  lsn 
)

Creates the first checkpoint ever in the log files.

Used during initialization of new log files. Flushes:

  • header of the first log file (including checkpoint headers),
  • log block with data addressed by the checkpoint lsn.
    Parameters
    [in,out]logredo log
    [in]lsnthe first checkpoint lsn

◆ log_file_header_fill_encryption()

bool log_file_header_fill_encryption ( byte buf,
byte key,
byte iv,
bool  is_boot,
bool  encrypt_key 
)

Writes encryption information to log header.

Parameters
[in,out]buflog file header
[in]keyencryption key
[in]ivencryption iv
[in]is_bootif it's for bootstrap
[in]encrypt_keyencrypt with master key

◆ log_files_downgrade()

void log_files_downgrade ( log_t log)

Changes format of redo files to previous format version.

Note
Note this will work between the two formats 5_7_9 & current because the only change is the version number

◆ log_files_header_fill()

void log_files_header_fill ( byte buf,
lsn_t  start_lsn,
const char *  creator,
bool  no_logging,
bool  crash_unsafe 
)

Fill redo log header.

Parameters
[out]buffilled buffer
[in]start_lsnlog start LSN
[in]creatorcreator of the header
[in]no_loggingredo logging is disabled
[in]crash_unsafeit is not safe to crash

◆ log_files_header_flush()

void log_files_header_flush ( log_t log,
uint32_t  nth_file,
lsn_t  start_lsn 
)

Writes a log file header to the log file space.

Parameters
[in]logredo log
[in]nth_fileheader for the nth file in the log files
[in]start_lsnlog file data starts at this lsn

◆ log_files_header_read()

void log_files_header_read ( log_t log,
uint32_t  header 
)

Reads a log file header page to log.checkpoint_buf.

Parameters
[in,out]logredo log
[in]header0 or LOG_CHECKPOINT_1 or LOG_CHECKPOINT2

◆ log_files_real_offset()

uint64_t log_files_real_offset ( const log_t log,
uint64_t  offset 
)

Calculates offset within log files, including headers of log files.

Parameters
[in]logredo log
[in]offsetsize offset (excluding log file headers)
Returns
real offset including log file headers (>= offset)

◆ log_files_real_offset_for_lsn()

uint64_t log_files_real_offset_for_lsn ( const log_t log,
lsn_t  lsn 
)

Calculates offset within log files, including headers of log files, for the provided lsn value.

Parameters
[in]logredo log
[in]lsnlog sequence number
Returns
real offset within the log files

◆ log_files_size_offset()

uint64_t log_files_size_offset ( const log_t log,
uint64_t  offset 
)

Calculates offset within log files, excluding headers of log files.

Parameters
[in]logredo log
[in]offsetreal offset (including log file headers)
Returns
size offset excluding log file headers (<= offset)

◆ log_files_update_offsets()

void log_files_update_offsets ( log_t log,
lsn_t  lsn 
)

Updates current_file_lsn and current_file_real_offset to correspond to a given lsn.

For this function to work, the values must already be initialized to correspond to some lsn, for instance, a checkpoint lsn.

Parameters
[in,out]logredo log
[in]lsnlog sequence number to set files_start_lsn at

◆ log_files_write_checkpoint()

void log_files_write_checkpoint ( log_t log,
lsn_t  next_checkpoint_lsn 
)

Writes the next checkpoint info to header of the first log file.

Note that two pages of the header are used alternately for consecutive checkpoints. If we crashed during the write, we would still have the previous checkpoint info and recovery would work.

Parameters
[in,out]logredo log
[in]next_checkpoint_lsnwrites checkpoint at this lsn

◆ log_flush_notifier()

void log_flush_notifier ( log_t log_ptr)

The log flush notifier thread co-routine.

See also
Thread: log flush_notifier
Parameters
[in,out]log_ptrpointer to redo log

◆ log_flush_notifier_is_active()

bool log_flush_notifier_is_active ( )
inline

Checks if log flush notifier thread is active.

Returns
true if and only if the log flush notifier thread is active

◆ log_flusher()

void log_flusher ( log_t log_ptr)

The log flusher thread co-routine.

See also
Thread: log flusher
Parameters
[in,out]log_ptrpointer to redo log

◆ log_flusher_is_active()

bool log_flusher_is_active ( )
inline

Checks if log flusher thread is active.

Returns
true if and only if the log flusher thread is active

◆ log_free_check()

void log_free_check ( )
inline

Any database operation should call this when it has modified more than about 4 pages.

NOTE that this function may only be called when the thread owns no synchronization objects except the dictionary mutex.

Checks if current log.sn exceeds log.free_check_limit_sn, in which case waits. This is supposed to guarantee that we would not run out of space in the log files when holding latches of some dirty pages (which could end up in a deadlock, because flush of the latched dirty pages could be required to reclaim the space and it is impossible to flush latched pages).

◆ log_free_check_wait()

void log_free_check_wait ( log_t log)

Waits until there is free space in log files which includes concurrency margin required for all threads.

You should rather use log_free_check().

See also
Reclaiming space in redo log
Parameters
[in]logredo log

◆ log_get_checkpoint_age()

lsn_t log_get_checkpoint_age ( const log_t log)
inline

Calculates age of current checkpoint as number of bytes since last checkpoint.

This includes bytes for headers and footers of all log blocks. The calculation is based on the latest written checkpoint lsn, and the current lsn, which points to the first non reserved data byte. Note that the current lsn could not fit the free space in the log files. This means that the checkpoint age could potentially be larger than capacity of the log files. However we do the best effort to avoid such situations, and if they happen, user threads wait until the space is reclaimed.

Parameters
[in]logredo log
Returns
checkpoint age as number of bytes

◆ log_get_checkpoint_lsn()

lsn_t log_get_checkpoint_lsn ( const log_t log)
inline

Gets the last checkpoint lsn stored and flushed to disk.

Returns
last checkpoint lsn

◆ log_get_free_check_capacity()

lsn_t log_get_free_check_capacity ( const log_t log)

Computes capacity of redo log available until log_free_check() reaches point where it needs to wait.

Parameters
[in]logredo log
Returns
lsn capacity up to free_check_wait happens

◆ log_get_lsn()

lsn_t log_get_lsn ( const log_t log)
inline

Gets the current lsn value.

This value points to the first non reserved data byte in the redo log. When next user thread reserves space in the redo log, it starts at this lsn.

If the last reservation finished exactly before footer of log block, this value points to the first byte after header of the next block.

NOTE that it is possible that the current lsn value does not fit free space in the log files or in the log buffer. In such case, user threads need to wait until the space becomes available.

Returns
current lsn

◆ log_get_max_modified_age_async()

lsn_t log_get_max_modified_age_async ( const log_t log)

When the oldest dirty page age exceeds this value, we start an asynchronous preflush of dirty pages.

Parameters
[in]logredo log
Returns
age of dirty page at which async preflush is started

◆ LOG_HEADER_CHECK_FLAG()

bool LOG_HEADER_CHECK_FLAG ( uint32_t  flag,
uint32_t  bit 
)
inline

Check a specific bit in flag.

Parameters
[in]flagbit flag
[in]bitcheck bit
Returns
true, iff bit is set in flag.

◆ LOG_HEADER_SET_FLAG()

void LOG_HEADER_SET_FLAG ( uint32_t &  flag,
uint32_t  bit 
)
inline

Set a specific bit in flag.

Parameters
[in]flagbit flag
[in]bitset bit

◆ log_increase_concurrency_margin()

void log_increase_concurrency_margin ( log_t log)

Increase concurrency_margin used inside log_free_check() calls.

◆ log_lsn_validate()

bool log_lsn_validate ( lsn_t  lsn)
inline

Validates a given lsn value.

Checks if the lsn value points to data bytes inside log block (not to some bytes in header/footer). It is used by assertions.

Returns
true if lsn points to data bytes within log block

◆ log_make_latest_checkpoint() [1/2]

bool log_make_latest_checkpoint ( log_t log)

Make a checkpoint at the current lsn.

Reads current lsn and waits until all dirty pages have been flushed up to that lsn. Afterwards requests a checkpoint write and waits until it is finished.

Parameters
[in,out]logredo log
Returns
true iff current lsn was greater than last checkpoint lsn

◆ log_make_latest_checkpoint() [2/2]

bool log_make_latest_checkpoint ( )

Make a checkpoint at the current lsn.

Reads current lsn and waits until all dirty pages have been flushed up to that lsn. Afterwards requests a checkpoint write and waits until it is finished.

Returns
true iff current lsn was greater than last checkpoint lsn

◆ log_needs_free_check()

bool log_needs_free_check ( )
inline
Returns
true iff log_free_check should be executed.

◆ log_persist_crash_safe()

void log_persist_crash_safe ( log_t log)

Persist the information that it is safe to restart server.

Parameters
[in,out]logredo log

◆ log_persist_disable()

void log_persist_disable ( log_t log)

Disable redo logging and persist the information.

Parameters
[in,out]logredo log

◆ log_persist_enable()

void log_persist_enable ( log_t log)

Enable redo logging and persist the information.

Parameters
[in,out]logredo log

◆ log_position_collect_lsn_info()

void log_position_collect_lsn_info ( const log_t log,
lsn_t current_lsn,
lsn_t checkpoint_lsn 
)

Collect coordinates in the locked redo log.

Parameters
[in]loglocked redo log
[out]current_lsnstores current lsn there
[out]checkpoint_lsnstores checkpoint lsn there

◆ log_position_lock()

void log_position_lock ( log_t log)

Lock redo log.

Both current lsn and checkpoint lsn will not change until the redo log is unlocked.

Parameters
[in,out]logredo log to lock

◆ log_position_unlock()

void log_position_unlock ( log_t log)

Unlock the locked redo log.

Parameters
[in,out]logredo log to unlock

◆ log_print()

void log_print ( const log_t log,
FILE *  file 
)

Prints information about important lsn values used in the redo log, and some statistics about speed of writing and flushing of data.

Parameters
[in]logredo log for which print information
[out]filefile where to print

◆ log_read_encryption()

bool log_read_encryption ( )

◆ log_recent_closed_empty_validate()

void log_recent_closed_empty_validate ( const log_t log,
lsn_t  begin,
lsn_t  end 
)

Validates that all slots in log recent closed buffer for lsn values in range between begin and end, are empty.

Used during tests, crashes the program if validation does not pass.

Parameters
[in]logredo log which buffer is validated
[in]beginvalidation start (inclusive)
[in]endvalidation end (exclusive)

◆ log_recent_written_empty_validate()

void log_recent_written_empty_validate ( const log_t log,
lsn_t  begin,
lsn_t  end 
)

Validates that all slots in log recent written buffer for lsn values in range between begin and end, are empty.

Used during tests, crashes the program if validation does not pass.

Parameters
[in]logredo log which buffer is validated
[in]beginvalidation start (inclusive)
[in]endvalidation end (exclusive)

◆ log_refresh_stats()

void log_refresh_stats ( log_t log)

Refreshes the statistics used to print per-second averages in log_print().

Parameters
[in,out]logredo log

◆ log_request_checkpoint() [1/2]

void log_request_checkpoint ( log_t log,
bool  sync,
lsn_t  lsn 
)

Requests a sharp checkpoint write for provided or greater lsn.

Parameters
[in,out]logredo log
[in]synctrue -> wait until it is finished
[in]lsnlsn for which we need checkpoint (or greater chkp)

◆ log_request_checkpoint() [2/2]

void log_request_checkpoint ( log_t log,
bool  sync 
)

Requests a fuzzy checkpoint write (for lsn currently available for checkpointing).

Parameters
[in,out]logredo log
[in]synctrue -> wait until it is finished

◆ log_rotate_encryption()

bool log_rotate_encryption ( )

Rotate the redo log encryption It will re-encrypt the redo log encryption metadata and write it to redo log file header.

Returns
true if success.

◆ log_set_dict_max_allowed_checkpoint_lsn()

void log_set_dict_max_allowed_checkpoint_lsn ( log_t log,
lsn_t  max_lsn 
)

Updates the field log.dict_max_allowed_checkpoint_lsn.

Parameters
[in,out]logredo log
[in]max_lsnnew value for the field

◆ log_set_dict_persist_margin()

void log_set_dict_persist_margin ( log_t log,
sn_t  margin 
)

Updates log.dict_persist_margin and recompute free check limit.

Parameters
[in,out]logredo log
[in]marginnew value for log.dict_persist_margin

◆ log_start()

void log_start ( log_t log,
checkpoint_no_t  checkpoint_no,
lsn_t  checkpoint_lsn,
lsn_t  start_lsn 
)

Starts the initialized redo log system using a provided checkpoint_lsn and current lsn.

Block for current_lsn must be properly initialized in the log buffer prior to calling this function. Therefore a proper value of first_rec_group must be set for that block before log_start is called.

Parameters
[in,out]logredo log
[in]checkpoint_nocheckpoint no (sequential number)
[in]checkpoint_lsncheckpoint lsn
[in]start_lsncurrent lsn to start at

◆ log_start_background_threads()

void log_start_background_threads ( log_t log)

Starts all the log background threads.

This can be called only, when the threads are inactive. This should never be called concurrently. This may not be called during read-only mode.

Parameters
[in,out]logredo log

◆ log_stop_background_threads()

void log_stop_background_threads ( log_t log)

Stops all the log background threads.

This can be called only, when the threads are active. This should never be called concurrently. This may not be called in read-only mode. Note that is is impossible to start log background threads in such case.

Parameters
[in,out]logredo log

◆ log_stop_background_threads_nowait()

void log_stop_background_threads_nowait ( log_t log)

Marks the flag which tells log threads to stop and wakes them.

Does not wait until they are stopped.

◆ log_sys_close()

void log_sys_close ( )

Free the log system data structures.

Deallocate all the related memory.

◆ log_sys_init()

bool log_sys_init ( uint32_t  n_files,
uint64_t  file_size,
space_id_t  space_id 
)

Initializes the log system.

Note that the log system is not ready for user writes after this call is finished. It should be followed by a call to log_start. Also, log background threads need to be started manually using log_start_background_threads afterwards.

Hence the proper order of calls looks like this:

  • log_sys_init(),
  • log_start(),
  • log_start_background_threads().
Parameters
[in]n_filesnumber of log files
[in]file_sizesize of each log file in bytes
[in]space_idspace id of the file space with log files

◆ log_translate_lsn_to_sn()

lsn_t log_translate_lsn_to_sn ( lsn_t  lsn)
inline

Calculates sn value for given lsn value.

See also
log_translate_sn_to_lsn
Parameters
[in]lsnlsn value
Returns
sn value for the provided lsn value

◆ log_translate_sn_to_lsn()

constexpr lsn_t log_translate_sn_to_lsn ( lsn_t  sn)
inline

Calculates lsn value for given sn value.

Sequence of sn values enumerate all data bytes in the redo log. Sequence of lsn values enumerate all data bytes and bytes used for headers and footers of all log blocks in the redo log. For every LOG_BLOCK_DATA_SIZE bytes of data we have OS_FILE_LOG_BLOCK_SIZE bytes in the redo log. NOTE that LOG_BLOCK_DATA_SIZE + LOG_BLOCK_HDR_SIZE + LOG_BLOCK_TRL_SIZE == OS_FILE_LOG_BLOCK_SIZE. The calculated lsn value will always point to some data byte (will be % OS_FILE_LOG_BLOCK_SIZE >= LOG_BLOCK_HDR_SIZE, and < OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_TRL_SIZE).

Parameters
[in]snsn value
Returns
lsn value for the provided sn value

◆ log_update_buf_limit() [1/2]

void log_update_buf_limit ( log_t log)

Updates limit used when writing to log buffer.

Note that the log buffer may have space for log records for which we still do not have space in log files (for larger lsn values).

Parameters
[in,out]logredo log

◆ log_update_buf_limit() [2/2]

void log_update_buf_limit ( log_t log,
lsn_t  write_lsn 
)

Updates limit used when writing to log buffer, according to provided write_lsn.

It must be <= log.write_lsn.load() to protect from log buffer overwrites.

Parameters
[in,out]logredo log
[in]write_lsnvalue <= log.write_lsn.load()

◆ log_update_limits()

void log_update_limits ( log_t log)

Updates limits related to free space in redo log files: log.available_for_checkpoint_lsn and log.free_check_limit_sn.

Parameters
[in,out]logredo log

◆ log_wait_for_space()

void log_wait_for_space ( log_t log,
sn_t  end_sn 
)

Waits until there is free space for range of sn values ending at the provided sn, in both the log buffer and in the log files.

Parameters
[in]logredo log
[in]end_snend of the range of sn values

◆ log_wait_for_space_in_log_buf()

void log_wait_for_space_in_log_buf ( log_t log,
sn_t  end_sn 
)

Waits until there is free space in the log buffer.

The free space has to be available for range of sn values ending at the provided sn.

See also
Waiting until log has been written to
Parameters
[in]logredo log
[in]end_snend of the range of sn values

◆ log_wait_for_space_in_log_recent_closed()

void log_wait_for_space_in_log_recent_closed ( log_t log,
lsn_t  lsn 
)

Waits until there is free space in the log recent closed buffer for any links start_lsn -> end_lsn, which start at provided start_lsn.

It does not add any link.

This is called just before dirty pages for [start_lsn, end_lsn) are added to flush lists. That's because we need to guarantee, that the delay until dirty page is added to flush list is limited. For detailed explanation -

See also
log0write.cc.
Adding dirty pages to flush lists
Parameters
[in,out]logredo log
[in]lsnlsn on which we wait (for any link: lsn -> x)

◆ log_wake_threads()

void log_wake_threads ( log_t log)

Wakes up all log threads which are alive.

◆ log_write_ahead_resize()

void log_write_ahead_resize ( log_t log,
size_t  new_size 
)

Resizes the write ahead buffer in the redo log.

Parameters
[in,out]logredo log
[in]new_sizenew size (in bytes)

◆ log_write_encryption()

bool log_write_encryption ( byte key,
byte iv,
bool  is_boot 
)

Write the encryption info into the log file header(the 3rd block).

It just need to flush the file header block with current master key.

Parameters
[in]keyencryption key
[in]ivencryption iv
[in]is_bootif it is for bootstrap
Returns
true if success.

◆ log_write_notifier()

void log_write_notifier ( log_t log_ptr)

The log write notifier thread co-routine.

See also
Thread: log write_notifier
Parameters
[in,out]log_ptrpointer to redo log

◆ log_write_notifier_is_active()

bool log_write_notifier_is_active ( )
inline

Checks if log write notifier thread is active.

Returns
true if and only if the log write notifier thread is active

◆ log_write_up_to()

Wait_stats log_write_up_to ( log_t log,
lsn_t  lsn,
bool  flush_to_disk 
)

Waits until the redo log is written up to a provided lsn.

Parameters
[in]logredo log
[in]lsnlsn to wait for
[in]flush_to_disktrue: wait until it is flushed
Returns
statistics about waiting inside

◆ log_writer()

void log_writer ( log_t log_ptr)

The log writer thread co-routine.

See also
Thread: log writer
Parameters
[in,out]log_ptrpointer to redo log

◆ log_writer_is_active()

bool log_writer_is_active ( )
inline

Checks if log writer thread is active.

Returns
true if and only if the log writer thread is active

◆ log_writer_thread_active_validate()

void log_writer_thread_active_validate ( const log_t log)

Validates that the log writer thread is active.

Used only to assert, that the state is correct.

Parameters
[in]logredo log

◆ redo_rotate_default_master_key()

void redo_rotate_default_master_key ( )

Rotate default master key for redo log encryption.

Variable Documentation

◆ ib_logfile_basename

constexpr const char* const ib_logfile_basename = "ib_logfile"

Prefix for name of log file, e.g.

"ib_logfile"

◆ INNODB_LOG_BUFFER_SIZE_DEFAULT

constexpr ulong INNODB_LOG_BUFFER_SIZE_DEFAULT = 16 * 1024 * 1024UL

Default value of innodb_log_buffer_size (in bytes).

◆ INNODB_LOG_BUFFER_SIZE_MAX

constexpr ulong INNODB_LOG_BUFFER_SIZE_MAX = ULONG_MAX

Maximum allowed value of innodb_log_buffer_size.

◆ INNODB_LOG_BUFFER_SIZE_MIN

constexpr ulong INNODB_LOG_BUFFER_SIZE_MIN = 256 * 1024UL

Minimum allowed value of innodb_log_buffer_size.

◆ INNODB_LOG_CHECKPOINT_EVERY_DEFAULT

constexpr ulong INNODB_LOG_CHECKPOINT_EVERY_DEFAULT = 1000

Default value of innodb_log_checkpointer_every (in milliseconds).

◆ INNODB_LOG_EVENTS_DEFAULT

constexpr ulong INNODB_LOG_EVENTS_DEFAULT = 2048

Default value of innodb_log_events (number of events).

◆ INNODB_LOG_EVENTS_MAX

constexpr ulong INNODB_LOG_EVENTS_MAX = 1024 * 1024 * 1024UL

Maximum allowed value of innodb_log_events.

◆ INNODB_LOG_EVENTS_MIN

constexpr ulong INNODB_LOG_EVENTS_MIN = 1

Minimum allowed value of innodb_log_events.

◆ INNODB_LOG_FLUSH_NOTIFIER_SPIN_DELAY_DEFAULT

constexpr ulong INNODB_LOG_FLUSH_NOTIFIER_SPIN_DELAY_DEFAULT = 0

Default value of innodb_log_flush_notifier_spin_delay (in spin rounds).

◆ INNODB_LOG_FLUSH_NOTIFIER_TIMEOUT_DEFAULT

constexpr ulong INNODB_LOG_FLUSH_NOTIFIER_TIMEOUT_DEFAULT = 10

Default value of innodb_log_flush_notifier_timeout (in microseconds).

◆ INNODB_LOG_FLUSHER_SPIN_DELAY_DEFAULT

constexpr ulong INNODB_LOG_FLUSHER_SPIN_DELAY_DEFAULT = 250000

Default value of innodb_log_flusher_spin_delay (in spin rounds).

Read about INNODB_LOG_WRITER_SPIN_DELAY_DEFAULT.

◆ INNODB_LOG_FLUSHER_TIMEOUT_DEFAULT

constexpr ulong INNODB_LOG_FLUSHER_TIMEOUT_DEFAULT = 10

Default value of innodb_log_flusher_timeout (in microseconds).

Note that it will anyway take at least 50us.

◆ INNODB_LOG_RECENT_CLOSED_SIZE_DEFAULT

constexpr ulong INNODB_LOG_RECENT_CLOSED_SIZE_DEFAULT = 2 * 1024 * 1024

Default value of innodb_log_recent_closed_size (in bytes).

◆ INNODB_LOG_RECENT_CLOSED_SIZE_MAX

constexpr ulong INNODB_LOG_RECENT_CLOSED_SIZE_MAX = 1024 * 1024 * 1024UL

Maximum allowed value of innodb_log_recent_closed_size.

◆ INNODB_LOG_RECENT_CLOSED_SIZE_MIN

constexpr ulong INNODB_LOG_RECENT_CLOSED_SIZE_MIN = OS_FILE_LOG_BLOCK_SIZE

Minimum allowed value of innodb_log_recent_closed_size.

◆ INNODB_LOG_RECENT_WRITTEN_SIZE_DEFAULT

constexpr ulong INNODB_LOG_RECENT_WRITTEN_SIZE_DEFAULT = 1024 * 1024

Default value of innodb_log_recent_written_size (in bytes).

◆ INNODB_LOG_RECENT_WRITTEN_SIZE_MAX

constexpr ulong INNODB_LOG_RECENT_WRITTEN_SIZE_MAX = 1024 * 1024 * 1024UL

Maximum allowed value of innodb_log_recent_written_size.

◆ INNODB_LOG_RECENT_WRITTEN_SIZE_MIN

constexpr ulong INNODB_LOG_RECENT_WRITTEN_SIZE_MIN = OS_FILE_LOG_BLOCK_SIZE

Minimum allowed value of innodb_log_recent_written_size.

◆ INNODB_LOG_SPIN_CPU_ABS_LWM_DEFAULT

constexpr ulong INNODB_LOG_SPIN_CPU_ABS_LWM_DEFAULT = 80

Default value of innodb_log_spin_cpu_abs_lwm.

Expressed in percent (80 stands for 80%) of a single CPU core.

◆ INNODB_LOG_SPIN_CPU_PCT_HWM_DEFAULT

constexpr uint INNODB_LOG_SPIN_CPU_PCT_HWM_DEFAULT = 50

Default value of innodb_log_spin_cpu_pct_hwm.

Expressed in percent (50 stands for 50%) of all CPU cores.

◆ INNODB_LOG_WAIT_FOR_FLUSH_SPIN_DELAY_DEFAULT

constexpr ulong INNODB_LOG_WAIT_FOR_FLUSH_SPIN_DELAY_DEFAULT = 25000

Default value of innodb_log_wait_for_flush_spin_delay (in spin rounds).

Read about INNODB_LOG_WAIT_FOR_WRITE_SPIN_DELAY_DEFAULT. The same mechanism applies here (to compute max rounds).

◆ INNODB_LOG_WAIT_FOR_FLUSH_SPIN_HWM_DEFAULT

constexpr ulong INNODB_LOG_WAIT_FOR_FLUSH_SPIN_HWM_DEFAULT = 400

Default value of innodb_log_wait_for_flush_spin_hwm (in microseconds).

◆ INNODB_LOG_WAIT_FOR_FLUSH_TIMEOUT_DEFAULT

constexpr ulong INNODB_LOG_WAIT_FOR_FLUSH_TIMEOUT_DEFAULT = 1000

Default value of innodb_log_wait_for_flush_timeout (in microseconds).

◆ INNODB_LOG_WAIT_FOR_WRITE_SPIN_DELAY_DEFAULT

constexpr ulong INNODB_LOG_WAIT_FOR_WRITE_SPIN_DELAY_DEFAULT = 25000

Default value of innodb_log_wait_for_write_spin_delay (in spin rounds).

Read about INNODB_LOG_WRITER_SPIN_DELAY_DEFAULT. Number of spin rounds is calculated according to current usage of CPU cores. If the usage is smaller than lwm percents of single core, then max rounds = 0. If the usage is smaller than 50% of hwm percents of all cores, then max rounds is decreasing linearly from 10x innodb_log_writer_spin_delay to 1x (for 50%). Then in range from 50% of hwm to 100% of hwm, the max rounds stays equal to the innodb_log_writer_spin_delay, because it doesn't make sense to use too short waits. Hence this is minimum value for the max rounds when non-zero value is being used.

◆ INNODB_LOG_WAIT_FOR_WRITE_TIMEOUT_DEFAULT

constexpr ulong INNODB_LOG_WAIT_FOR_WRITE_TIMEOUT_DEFAULT = 1000

Default value of innodb_log_wait_for_write_timeout (in microseconds).

◆ INNODB_LOG_WRITE_AHEAD_SIZE_DEFAULT

constexpr ulong INNODB_LOG_WRITE_AHEAD_SIZE_DEFAULT = 8192

Default value of innodb_log_write_ahead_size (in bytes).

◆ INNODB_LOG_WRITE_AHEAD_SIZE_MAX

constexpr ulint INNODB_LOG_WRITE_AHEAD_SIZE_MAX
Initial value:
=
UNIV_PAGE_SIZE_DEF

Maximum allowed value of innodb_log_write_ahead_size.

◆ INNODB_LOG_WRITE_AHEAD_SIZE_MIN

constexpr ulong INNODB_LOG_WRITE_AHEAD_SIZE_MIN = OS_FILE_LOG_BLOCK_SIZE

Minimum allowed value of innodb_log_write_ahead_size.

◆ INNODB_LOG_WRITE_MAX_SIZE_DEFAULT

constexpr ulint INNODB_LOG_WRITE_MAX_SIZE_DEFAULT = 4096

Constants related to server variables (default, min and max values).

Default value of innodb_log_write_max_size (in bytes).

◆ INNODB_LOG_WRITE_NOTIFIER_SPIN_DELAY_DEFAULT

constexpr ulong INNODB_LOG_WRITE_NOTIFIER_SPIN_DELAY_DEFAULT = 0

Default value of innodb_log_write_notifier_spin_delay (in spin rounds).

◆ INNODB_LOG_WRITE_NOTIFIER_TIMEOUT_DEFAULT

constexpr ulong INNODB_LOG_WRITE_NOTIFIER_TIMEOUT_DEFAULT = 10

Default value of innodb_log_write_notifier_timeout (in microseconds).

◆ INNODB_LOG_WRITER_SPIN_DELAY_DEFAULT

constexpr ulong INNODB_LOG_WRITER_SPIN_DELAY_DEFAULT = 250000

Default value of innodb_log_writer_spin_delay (in spin rounds).

We measured that 1000 spin round takes 4us. We decided to select 1ms as the maximum time for busy waiting. Therefore it corresponds to 250k spin rounds. Note that first wait on event takes 50us-100us (even if 10us is passed), so it is 5%-10% of the total time that we have already spent on busy waiting, when we fall back to wait on event.

◆ INNODB_LOG_WRITER_TIMEOUT_DEFAULT

constexpr ulong INNODB_LOG_WRITER_TIMEOUT_DEFAULT = 10

Default value of innodb_log_writer_timeout (in microseconds).

Note that it will anyway take at least 50us.

◆ LOG_BLOCK_CHECKPOINT_NO

constexpr uint32_t LOG_BLOCK_CHECKPOINT_NO = 8

4 lower bytes of the value of log_sys->next_checkpoint_no when the log block was last written to: if the block has not yet been written full, this value is only updated before a log buffer flush.

◆ LOG_BLOCK_CHECKSUM

constexpr uint32_t LOG_BLOCK_CHECKSUM = 4

4 byte checksum of the log block contents.

In InnoDB versions < 3.23.52 this did not contain the checksum, but the same value as .._HDR_NO.

◆ LOG_BLOCK_DATA_SIZE

constexpr uint32_t LOG_BLOCK_DATA_SIZE
Initial value:
=
#define OS_FILE_LOG_BLOCK_SIZE
The next value should be smaller or equal to the smallest sector size used on any disk...
Definition: os0file.h:174
constexpr uint32_t LOG_BLOCK_TRL_SIZE
Size of the log block footer (trailer) in bytes.
Definition: log0log.h:134
constexpr uint32_t LOG_BLOCK_HDR_SIZE
Size of the log block&#39;s header in bytes.
Definition: log0log.h:125

Size of log block's data fragment (where actual data is stored).

◆ LOG_BLOCK_ENCRYPT_BIT_MASK

constexpr uint32_t LOG_BLOCK_ENCRYPT_BIT_MASK = 0x8000UL

Mask used to get the highest bit in the data len field, this bit is to indicate if this block is encrypted or not.

◆ LOG_BLOCK_FIRST_REC_GROUP

constexpr uint32_t LOG_BLOCK_FIRST_REC_GROUP = 6

Offset of the first start of mtr log record group in this log block.

0 if none. If the value is the same as LOG_BLOCK_HDR_DATA_LEN, it means that the first rec group has not yet been concatenated to this log block, but if it will, it will start at this offset.

An archive recovery can start parsing the log records starting from this offset in this log block, if value is not 0.

◆ LOG_BLOCK_FLUSH_BIT_MASK

constexpr uint32_t LOG_BLOCK_FLUSH_BIT_MASK = 0x80000000UL

Mask used to get the highest bit in the hdr_no field.

◆ LOG_BLOCK_HDR_DATA_LEN

constexpr uint32_t LOG_BLOCK_HDR_DATA_LEN = 4

Number of bytes written to this block (also header bytes).

◆ LOG_BLOCK_HDR_NO

constexpr uint32_t LOG_BLOCK_HDR_NO = 0

Block number which must be > 0 and is allowed to wrap around at 1G.

The highest bit is set to 1, if this is the first block in a call to fil_io (for possibly many consecutive blocks).

◆ LOG_BLOCK_HDR_SIZE

constexpr uint32_t LOG_BLOCK_HDR_SIZE = 12

Size of the log block's header in bytes.

◆ LOG_BLOCK_MAX_NO

constexpr uint32_t LOG_BLOCK_MAX_NO = 0x3FFFFFFFUL + 1

Maximum allowed block's number (stored in hdr_no).

◆ LOG_BLOCK_TRL_SIZE

constexpr uint32_t LOG_BLOCK_TRL_SIZE = 4

Size of the log block footer (trailer) in bytes.

◆ LOG_CHECKPOINT_1

constexpr uint32_t LOG_CHECKPOINT_1 = OS_FILE_LOG_BLOCK_SIZE

First checkpoint field in the log header.

We write alternately to the checkpoint fields when we make new checkpoints. This field is only defined in the first log file.

◆ LOG_CHECKPOINT_2

constexpr uint32_t LOG_CHECKPOINT_2 = 3 * OS_FILE_LOG_BLOCK_SIZE

Second checkpoint field in the header of the first log file.

◆ LOG_CHECKPOINT_EXTRA_FREE

constexpr uint32_t LOG_CHECKPOINT_EXTRA_FREE = 8

Absolute margin for the free space in the log, before a new query step which modifies the database, is started.

Expressed in number of pages.

◆ LOG_CHECKPOINT_FREE_PER_THREAD

constexpr uint32_t LOG_CHECKPOINT_FREE_PER_THREAD = 4

Per thread margin for the free space in the log, before a new query step which modifies the database, is started.

It's multiplied by maximum number of threads, that can concurrently enter mini-transactions. Expressed in number of pages.

◆ LOG_CHECKPOINT_LOG_BUF_SIZE

constexpr uint32_t LOG_CHECKPOINT_LOG_BUF_SIZE = 24

Size of the log buffer, when the checkpoint write was started.

It seems to be write-only field in InnoDB. Not used by recovery.

Note
Note that when the log buffer is being resized, all the log background threads are stopped, so there no is concurrent checkpoint write (the log_checkpointer thread is stopped).

◆ LOG_CHECKPOINT_LSN

constexpr uint32_t LOG_CHECKPOINT_LSN = 8

Checkpoint lsn.

Recovery starts from this lsn and searches for the first log record group that starts since then. In InnoDB < 8.0, it was exact value at which the first log record group started. Because of the relaxed order in flush lists, checkpoint lsn values are not precise anymore (the maximum delay related to the relaxed order in flush lists, is subtracted from oldest_lsn, when writing a checkpoint).

◆ LOG_CHECKPOINT_NO

constexpr uint32_t LOG_CHECKPOINT_NO = 0

Checkpoint number.

It's incremented by one for each consecutive checkpoint. During recovery, all headers are scanned, and one with the maximum checkpoint number is used for the recovery (checkpoint_lsn from the header is used).

◆ LOG_CHECKPOINT_OFFSET

constexpr uint32_t LOG_CHECKPOINT_OFFSET = 16

Offset within the log files, which corresponds to checkpoint lsn.

Used for calibration of lsn and offset calculations.

◆ log_checksum_algorithm_ptr

log_checksum_func_t log_checksum_algorithm_ptr

Pointer to the log checksum calculation function.

Changes are protected by log_mutex_enter_all, which also stops the log background threads.

◆ LOG_ENCRYPTION

constexpr uint32_t LOG_ENCRYPTION = 2 * OS_FILE_LOG_BLOCK_SIZE

Log Encryption information in redo log header.

◆ LOG_FILE_HDR_SIZE

constexpr uint32_t LOG_FILE_HDR_SIZE = 4 * OS_FILE_LOG_BLOCK_SIZE

Size of log file's header.

◆ LOG_HEADER_CREATOR

constexpr uint32_t LOG_HEADER_CREATOR = 16

A null-terminated string which will contain either the string 'MEB' and the MySQL version if the log file was created by mysqlbackup, or 'MySQL' and the MySQL version that created the redo log file.

◆ LOG_HEADER_CREATOR_END

constexpr uint32_t LOG_HEADER_CREATOR_END = LOG_HEADER_CREATOR + 32

End of the log file creator field.

◆ LOG_HEADER_FLAG_CRASH_UNSAFE

constexpr uint32_t LOG_HEADER_FLAG_CRASH_UNSAFE = 2

Flag at BIT-2 to indicate if server is not recoverable on crash.

This is set only when redo logging is disabled and unset on slow shutdown after all pages are flushed to disk.

◆ LOG_HEADER_FLAG_MAX

constexpr uint32_t LOG_HEADER_FLAG_MAX = LOG_HEADER_FLAG_CRASH_UNSAFE

Maximum BIT position number.

Should be set to the latest added.

◆ LOG_HEADER_FLAG_NO_LOGGING

constexpr uint32_t LOG_HEADER_FLAG_NO_LOGGING = 1

Flag at BIT-1 to indicate if redo logging is disabled or not.

◆ LOG_HEADER_FLAGS

constexpr uint32_t LOG_HEADER_FLAGS = LOG_HEADER_CREATOR_END

32 BITs flag

◆ LOG_HEADER_FORMAT

constexpr uint32_t LOG_HEADER_FORMAT = 0

Offsets used in a log file header.

Log file header format identifier (32-bit unsigned big-endian integer). This used to be called LOG_GROUP_ID and always written as 0, because InnoDB never supported more than one copy of the redo log.

◆ LOG_HEADER_PAD1

constexpr uint32_t LOG_HEADER_PAD1 = 4

4 unused (zero-initialized) bytes.

◆ LOG_HEADER_SIZE

constexpr uint32_t LOG_HEADER_SIZE = LOG_HEADER_FLAGS + 4

Current total size of LOG header.

◆ LOG_HEADER_START_LSN

constexpr uint32_t LOG_HEADER_START_LSN = 8

LSN of the start of data in this log file (with format version 1 and 2).

◆ LOG_NO_CHECKSUM_MAGIC

constexpr uint32_t LOG_NO_CHECKSUM_MAGIC = 0xDEADBEEFUL

Magic value to use instead of log checksums when they are disabled.

◆ LOG_POOL_CHECKPOINT_RATIO_ASYNC

constexpr uint32_t LOG_POOL_CHECKPOINT_RATIO_ASYNC = 32

Controls asynchronous making of a new checkpoint.

Should be bigger than LOG_POOL_PREFLUSH_RATIO_SYNC.

◆ LOG_POOL_PREFLUSH_RATIO_ASYNC

constexpr uint32_t LOG_POOL_PREFLUSH_RATIO_ASYNC = 8

Controls asynchronous preflushing of modified buffer pages.

Should be less than the LOG_POOL_PREFLUSH_RATIO_SYNC.

◆ LOG_POOL_PREFLUSH_RATIO_SYNC

constexpr uint32_t LOG_POOL_PREFLUSH_RATIO_SYNC = 16

Controls synchronous preflushing of modified buffer pages.

◆ LOG_START_LSN

constexpr lsn_t LOG_START_LSN = 16 * OS_FILE_LOG_BLOCK_SIZE

The counting of lsn's starts from this value: this must be non-zero.

◆ log_sys

log_t* log_sys

Redo log system (singleton).

◆ log_test

std::unique_ptr<Log_test> log_test

Represents currently running test of redo log, nullptr otherwise.

◆ LSN_MAX

constexpr lsn_t LSN_MAX = (1ULL << 63) - 1

Maximum possible lsn value is slightly higher than the maximum sn value, because lsn sequence enumerates also bytes used for headers and footers of all log blocks.

However, still 64-bits are enough to represent the maximum lsn value, because only 63 bits are used to represent sn value.

◆ MAX_LOG_FILE_NAME

constexpr uint32_t MAX_LOG_FILE_NAME = 32

◆ MLOG_TEST_GROUP_MAX_REC_N

constexpr uint32_t MLOG_TEST_GROUP_MAX_REC_N = 100

Maximum number of MLOG_TEST records in single group of log records.

◆ MLOG_TEST_MAX_REC_LEN

constexpr uint32_t MLOG_TEST_MAX_REC_LEN = 100

Maximum size of single MLOG_TEST record (in bytes).

◆ MLOG_TEST_REC_OVERHEAD

constexpr uint32_t MLOG_TEST_REC_OVERHEAD = 37

Bytes consumed by MLOG_TEST record with an empty payload.

◆ MLOG_TEST_VALUE

constexpr int64_t MLOG_TEST_VALUE = 10000

Value to which MLOG_TEST records should sum up within a group.

◆ SN_LOCKED

constexpr sn_t SN_LOCKED = 1ULL << 63

The sn bit to express locked state.

◆ SN_MAX

constexpr sn_t SN_MAX = (1ULL << 62) - 1

Ensure, that 64 bits are enough to represent lsn values, when 63 bits are used to represent sn values.

It is enough to ensure that lsn < 2*sn, and that is guaranteed if the overhead enumerated in lsn sequence is not bigger than number of actual data bytes. Maximum possible sn value.