MySQL 26.7.0
Source Code Documentation
log0chkp.cc File Reference
#include "log0chkp.h"
#include <chrono>
#include <cstring>
#include "arch0arch.h"
#include "buf0buf.h"
#include "buf0flu.h"
#include "fil0pages_persistence_interface.h"
#include "log0buf.h"
#include "log0encryption.h"
#include "log0files_io.h"
#include "log0log.h"
#include "log0recv.h"
#include "log0handler_interface.h"
#include "log0sys.h"
#include "log0test.h"
#include "log0types.h"
#include "log0write.h"
#include "mach0data.h"
#include "my_dbug.h"
#include "os0event.h"
#include "os0thread-create.h"
#include "sql_thd_internal_api.h"
#include "srv0mon.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "ut0byte.h"

Functions

static void log_wait_for_checkpoint (lsn_t lsn)
 Waits for checkpoint advanced to at least that lsn. More...
 
static void log_request_sync_flush ()
 Requests for urgent flush of dirty pages, to advance oldest_lsn in flush lists. More...
 
static lsn_t log_compute_available_for_checkpoint_lsn ()
 Calculates lsn at which we might write a next checkpoint. More...
 
dberr_t log_files_next_checkpoint (log_t &log, lsn_t next_checkpoint_lsn)
 Writes the next checkpoint to the log file, by writing a single checkpoint header with the checkpoint lsn. More...
 
Log_checkpoint_header_no log_next_checkpoint_header (Log_checkpoint_header_no checkpoint_header_no)
 Provides opposite checkpoint header number to the given checkpoint header number. More...
 
dberr_t log_files_write_checkpoint_low (log_t &log, Log_file_handle &checkpoint_file_handle, Log_checkpoint_header_no checkpoint_header_no, lsn_t checkpoint_lsn)
 Writes checkpoint to the file containing the written checkpoint_lsn. More...
 
dberr_t log_files_write_first_data_block_low (log_t &log, Log_file_handle &file_handle, lsn_t checkpoint_lsn, lsn_t file_start_lsn)
 Writes the first data block to the log file using the provided handle to the opened log file. More...
 
static bool log_request_checkpoint_validate ()
 Check if the checkpointing is enabled. More...
 
static lsn_t get_soft_logical_capacity ()
 
static lsn_t adaptive_flush_max_age (lsn_t soft_logical_capacity)
 
static lsn_t adaptive_flush_min_age (lsn_t soft_logical_capacity)
 
static lsn_t aggressive_checkpoint_min_age (lsn_t soft_logical_capacity)
 
void log_update_exported_lsns ()
 Updates: More...
 

Variables

Log_checkpointinglog_checkpointing
 Redo log checkpointing. More...
 

Function Documentation

◆ adaptive_flush_max_age()

static lsn_t adaptive_flush_max_age ( lsn_t  soft_logical_capacity)
static

◆ adaptive_flush_min_age()

static lsn_t adaptive_flush_min_age ( lsn_t  soft_logical_capacity)
static

◆ aggressive_checkpoint_min_age()

static lsn_t aggressive_checkpoint_min_age ( lsn_t  soft_logical_capacity)
static

◆ get_soft_logical_capacity()

static lsn_t get_soft_logical_capacity ( )
static

◆ log_compute_available_for_checkpoint_lsn()

static lsn_t log_compute_available_for_checkpoint_lsn ( )
static

Calculates lsn at which we might write a next checkpoint.

It does the best effort, but possibly the maximum allowed lsn, could be even bigger. That's because the order of dirty pages in flush lists has been relaxed, and we don't want to spend time on traversing the whole flush lists here.

Note that some flush lists could be empty, and some additions of dirty pages could be pending (threads have written data to the log buffer and became scheduled out just before adding the dirty pages). That's why the calculated value cannot be larger than the buf_flush_list_added->smallest_not_added_lsn() (only up to this lsn value we are sure, that all the dirty pages have been added).

It is guaranteed, that the returned value will not be smaller than the log_checkpointer.m_checkpoint_lsn.

Returns
lsn for which we might write the checkpoint

◆ log_files_next_checkpoint()

dberr_t log_files_next_checkpoint ( log_t log,
lsn_t  lsn 
)

Writes the next checkpoint to the log file, by writing a single checkpoint header with the checkpoint lsn.

Flushes the file after the write and updates the log.last_checkpoint_lsn.

Remarks
Note that two checkpoint headers are used alternately for consecutive checkpoints. If InnoDB crashed during the write, it would still have the previous checkpoint info and recovery would work.
Parameters
[in,out]logredo log
[in]lsnwrites checkpoint at this lsn
Returns
DB_SUCCESS or error

◆ log_files_write_checkpoint_low()

dberr_t log_files_write_checkpoint_low ( log_t log,
Log_file_handle checkpoint_file_handle,
Log_checkpoint_header_no  checkpoint_header_no,
lsn_t  next_checkpoint_lsn 
)

Writes checkpoint to the file containing the written checkpoint_lsn.

The checkpoint is written to the given checkpoint header. Unless InnoDB is starting: checkpointer, writer and files mutexes must be acquired before calling this function.

Parameters
[in,out]logredo log
[in]checkpoint_file_handlehandle to opened file
[in]checkpoint_header_nocheckpoint header to be written
[in]next_checkpoint_lsnthe checkpoint lsn to write
Returns
DB_SUCCESS or error

◆ log_files_write_first_data_block_low()

dberr_t log_files_write_first_data_block_low ( log_t log,
Log_file_handle file_handle,
lsn_t  checkpoint_lsn,
lsn_t  file_start_lsn 
)

Writes the first data block to the log file using the provided handle to the opened log file.

The block is addressed by the given checkpoint_lsn, filled with 0x00 and its data length points to checkpoint_lsn inside, making the block logically empty.

Remarks
This is used only during creation of new log files.
Parameters
[in,out]logredo log
[in]file_handlehandle to the opened log file
[in]checkpoint_lsnthe checkpoint lsn
[in]file_start_lsnstart_lsn of the file
Returns
DB_SUCCESS or error

◆ log_next_checkpoint_header()

Log_checkpoint_header_no log_next_checkpoint_header ( Log_checkpoint_header_no  checkpoint_header_no)

Provides opposite checkpoint header number to the given checkpoint header number.

Parameters
[in]checkpoint_header_nothe given checkpoint header number
Returns
the opposite checkpoint header number

◆ log_request_checkpoint_validate()

static bool log_request_checkpoint_validate ( )
static

Check if the checkpointing is enabled.

Return values
truecheckpointing is enabled
falsecheckpointing is disabled

◆ log_request_sync_flush()

static void log_request_sync_flush ( )
static

Requests for urgent flush of dirty pages, to advance oldest_lsn in flush lists.

This should force page cleaners to perform the sync-flush in which case the innodb_max_io_capacity is not respected. This should be called when we are close to running out of space in redo log (close to m_free_check_limit_lsn).

◆ log_update_exported_lsns()

void log_update_exported_lsns ( )

Updates:

  • Innodb_redo_log_checkpoint_lsn,
  • Innodb_redo_log_current_lsn,
  • Innodb_redo_log_flushed_to_disk_lsn. They should be updated "together", to present a consistent state to the user, that is one in which checkpoint_lsn <= flushed_to_disk_lsn <= current_lsn. Calls are protected by log_checkpointer->limits_mutex, which is to avoid torn writes to these exposed fields, but otherwise does not enforce above inequalities. Instead they follow from loading atomics in the order from the conceptually smallest to the largest - a load synchronizes with the store, which in turn should happen after the conceptually larger atomic already was at least equal to the stored value, so can be only larger now.

◆ log_wait_for_checkpoint()

static void log_wait_for_checkpoint ( lsn_t  lsn)
static

Waits for checkpoint advanced to at least that lsn.

Parameters
[in]lsnlsn up to which we are waiting

Variable Documentation

◆ log_checkpointing

Log_checkpointing* log_checkpointing

Redo log checkpointing.