MySQL 26.7.0
Source Code Documentation
Log_checkpointing Class Reference

#include <log0chkp.h>

Public Member Functions

Last known checkpoint lsn value
void set_checkpoint (lsn_t checkpoint_lsn)
 Updates the cached checkpoint_lsn. More...
 
lsn_t get_checkpoint ()
 
bool save_checkpoint_value (lsn_t checkpoint_lsn)
 Save the checkpoint lsn to the persistent store. More...
 
dberr_t load_checkpoint_value ()
 Fetch the checkpoint lsn from the persistent store. More...
 
The log_free_check() mechanism
void update_limits ()
 Calls ib::redo::handler->do_not_need_smaller_than(get_checkpoint_lsn()). More...
 

Static Public Member Functions

static void init ()
 Allocates and constructs the global log_checkpointing object. More...
 
static void deinit ()
 Destructs and deallocates the global log_checkpointing object. More...
 

Public Attributes

os_event_t m_event
 Event used by the log checkpointer thread to wait for requests. More...
 
os_event_t m_next_checkpoint_event
 Event signaled by log checkpointer when it advances m_checkpoint_lsn. More...
 
ib_mutex_t checkpoint_mutex
 Mutex which can be used to pause log checkpointer thread. More...
 
ib_mutex_t limits_mutex
 Mutex which protects fields: m_available_for_checkpoint_lsn, m_requested_checkpoint_lsn. More...
 

Private Member Functions

 Log_checkpointing ()
 
 ~Log_checkpointing ()
 
Making checkpoints
lsn_t determine_checkpoint_lsn ()
 Figures out m_available_for_checkpoint_lsn. More...
 
void consider_sync_flush ()
 Considers requesting page cleaners to execute sync flush. More...
 
bool should_checkpoint ()
 Checks if checkpoint should be written. More...
 
void consider_checkpoint ()
 Considers writing next checkpoint. More...
 
void create_checkpoint ()
 Makes a checkpoint. More...
 

Private Attributes

std::atomic_bool m_thread_should_stop {}
 
atomic_lsn_t m_checkpoint_lsn {}
 Latest checkpoint lsn. More...
 
Log_clock_point m_last_checkpoint_time {}
 Latest checkpoint wall time. More...
 
bool m_periodical_checkpoints_enabled {}
 If should perform checkpoints every innodb_log_checkpoint_every ms, or when doing so would help reclaim oldest redo log file. More...
 
THDm_checkpointer_thd
 THD used by the log_checkpointer thread. More...
 
Fields protected by the log_limits_mutex.

Related to free space in the redo log.

lsn_t m_available_for_checkpoint_lsn {}
 A new checkpoint could be written for this lsn value. More...
 
atomic_lsn_t m_requested_checkpoint_lsn {}
 When this is larger than the latest checkpoint, the log checkpointer thread will be forced to write a new checkpoint (unless the new latest checkpoint lsn would still be smaller than this value). More...
 

Friends

template<typename T >
void ut::aligned_delete (T *ptr) noexcept
 
template<typename T , typename... Args>
Tut::aligned_new_withkey (ut::PSI_memory_key_t key, std::size_t alignment, Args &&...args)
 

Coordination with buffer pool and oldest_lsn

lsn_t update_available_for_checkpoint_lsn ()
 Updates lsn available for checkpoint. More...
 
lsn_t get_available_for_checkpoint_lsn () const
 

Requests to make checkpoint

lsn_t get_requested_checkpoint_lsn ()
 Returns highest requested checkpoint lsn. More...
 
bool request_checkpoint (lsn_t requested_lsn)
 Requests a checkpoint written for lsn greater or equal to provided one. More...
 
void request_fuzzy_checkpoint (bool sync)
 Requests a fuzzy checkpoint write (for currently available lsn). More...
 
void request_sharp_checkpoint ()
 Make a checkpoint at the current lsn. More...
 

Periodical updates

bool are_periodical_checkpoints_enabled () const
 
std::chrono::steady_clock::duration time_since_checkpoint ()
 Calculates time that elapsed since last checkpoint. More...
 
void enable_periodical_checkpoints ()
 

The checkpointer thread

void do_work ()
 The actual non-static body of the static log_checkpointer() More...
 
void stop_thread_no_wait ()
 Informs the log checkpointer that it should stop, but does not wait for it to happen. More...
 
void stop_thread_and_wait ()
 Informs the log checkpointer that it should stop and waits for it to happen before returning to the caller. More...
 
void start_thread ()
 Starts the log checkpointer thread. More...
 
static void log_checkpointer ()
 The log checkpointer thread routine. More...
 

Dirty page flushing speed control

void get_limits (lsn_t &limit_for_free_check, lsn_t &limit_for_dirty_page_age)
 Retrieves limitations determined by the current state of log.m_capacity. More...
 
lsn_t get_sync_flush_lsn ()
 Computes lsn up to which sync flush of pages should be done or returns 0 if there is no need to execute sync flush of dirty pages now. More...
 
static lsn_t adaptive_flush_min_age ()
 Once checkpoint age exceeds this value, the flushing of pages starts to be adaptive. More...
 
static lsn_t adaptive_flush_max_age ()
 Once checkpoint age exceeds that value, the flushing of pages is the most aggressive possible since then. More...
 
static lsn_t aggressive_checkpoint_min_age ()
 Once checkpoint age exceeds that value, the log checkpointer thread keeps writing checkpoints aggressively (whatever the progress of last_checkpoint_lsn would it make). More...
 

Constructor & Destructor Documentation

◆ Log_checkpointing()

Log_checkpointing::Log_checkpointing ( )
private

◆ ~Log_checkpointing()

Log_checkpointing::~Log_checkpointing ( )
private

Member Function Documentation

◆ adaptive_flush_max_age()

lsn_t Log_checkpointing::adaptive_flush_max_age ( )
static

Once checkpoint age exceeds that value, the flushing of pages is the most aggressive possible since then.

For more details

See also
adaptive_flush_min_age.
Note
This value changes only during calls to
See also
update or
initialize.
Returns
limitation to start furious flushing

◆ adaptive_flush_min_age()

lsn_t Log_checkpointing::adaptive_flush_min_age ( )
static

Once checkpoint age exceeds this value, the flushing of pages starts to be adaptive.

The adaptive page flushing is becoming more and more aggressive in the following range: adaptive_flush_min_age()..adaptive_flush_max_age().

Note
This value changes only during calls to
See also
update or
initialize.
Note
Note that it must hold: adaptive_flush_min_age() < adaptive_flush_max_age() <= soft_logical_capacity().
Remarks
The diagram below shows how flushing / checkpointing becomes more aggressive when the age of the oldest modified page gets increased:

adaptive_flush_min_age adaptive_flush_max_age aggressive_checkpoint_min_age | | | ----—!---------------------—!------------------—!--------------—>age regular adaptive flushing aggressive flushing aggr. checkpoints

Returns
limitation to start adaptive flushing

◆ aggressive_checkpoint_min_age()

lsn_t Log_checkpointing::aggressive_checkpoint_min_age ( )
static

Once checkpoint age exceeds that value, the log checkpointer thread keeps writing checkpoints aggressively (whatever the progress of last_checkpoint_lsn would it make).

Before that happens, checkpoints could be written periodically (for more details

See also
adaptive_flush_min_age).
Note
This value changes only during calls to
See also
update or
initialize.
Note
It holds: adaptive_flush_max_age() < aggressive_checkpoint_min_age().
Returns
limitation to start aggressive checkpointing

◆ are_periodical_checkpoints_enabled()

bool Log_checkpointing::are_periodical_checkpoints_enabled ( ) const
inlineprivate

◆ consider_checkpoint()

void Log_checkpointing::consider_checkpoint ( )
private

Considers writing next checkpoint.

Checks if checkpoint should be written (using should_checkpoint()) and writes the checkpoint if that's the case.

◆ consider_sync_flush()

void Log_checkpointing::consider_sync_flush ( )
private

Considers requesting page cleaners to execute sync flush.

◆ create_checkpoint()

void Log_checkpointing::create_checkpoint ( )
private

Makes a checkpoint.

Note that this function does not flush dirty blocks from the buffer pool. It only checks what is lsn of the oldest modification in the buffer pool, and writes information about the lsn in log files.

◆ deinit()

void Log_checkpointing::deinit ( void  )
static

Destructs and deallocates the global log_checkpointing object.

◆ determine_checkpoint_lsn()

lsn_t Log_checkpointing::determine_checkpoint_lsn ( )
private

Figures out m_available_for_checkpoint_lsn.

◆ do_work()

void Log_checkpointing::do_work ( )
private

The actual non-static body of the static log_checkpointer()

◆ enable_periodical_checkpoints()

void Log_checkpointing::enable_periodical_checkpoints ( )
inline

◆ get_available_for_checkpoint_lsn()

lsn_t Log_checkpointing::get_available_for_checkpoint_lsn ( ) const
inline

◆ get_checkpoint()

lsn_t Log_checkpointing::get_checkpoint ( )
inline
Returns
Cached checkpoint_lsn

◆ get_limits()

void Log_checkpointing::get_limits ( lsn_t limit_for_free_check,
lsn_t limit_for_dirty_page_age 
)

Retrieves limitations determined by the current state of log.m_capacity.

These values are retrieved atomically (are consistent with each other).

Parameters
[out]limit_for_free_checksoft capacity of the redo decreased by the current free check margin; this is limit for size of redo until which the log_free_check calls do not force waits
[out]limit_for_dirty_page_agelimit for the oldest dirty page until which the async (adaptive) flushing is not forced to be started (it might be started if turned on explicitly by the innodb_adaptive_flushing); note that computation of this value include doing the subtraction of the current log free check margin

◆ get_requested_checkpoint_lsn()

lsn_t Log_checkpointing::get_requested_checkpoint_lsn ( )
inlineprivate

Returns highest requested checkpoint lsn.

◆ get_sync_flush_lsn()

lsn_t Log_checkpointing::get_sync_flush_lsn ( )

Computes lsn up to which sync flush of pages should be done or returns 0 if there is no need to execute sync flush of dirty pages now.

Returns
lsn for which we want to have oldest_lsn >= lsn in each BP, or 0 if there is no need for sync flush

◆ init()

void Log_checkpointing::init ( void  )
static

Allocates and constructs the global log_checkpointing object.

◆ load_checkpoint_value()

dberr_t Log_checkpointing::load_checkpoint_value ( )

Fetch the checkpoint lsn from the persistent store.

Returns
DB_SUCCESS or error

◆ log_checkpointer()

void Log_checkpointing::log_checkpointer ( )
static

The log checkpointer thread routine.

◆ request_checkpoint()

bool Log_checkpointing::request_checkpoint ( lsn_t  requested_lsn)

Requests a checkpoint written for lsn greater or equal to provided one.

Caller must hold log_limits_mutex

Parameters
[in]requested_lsncheckpoint should be not older than this
Returns
true iff checkpoints are enabled and request was made

◆ request_fuzzy_checkpoint()

void Log_checkpointing::request_fuzzy_checkpoint ( bool  sync)

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

Parameters
[in]syncwhether request is sync (function should wait)

◆ request_sharp_checkpoint()

void Log_checkpointing::request_sharp_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.

◆ save_checkpoint_value()

bool Log_checkpointing::save_checkpoint_value ( lsn_t  checkpoint_lsn)

Save the checkpoint lsn to the persistent store.

Parameters
[in]checkpoint_lsncheckpoint lsn to be persisted
Returns
true iff the lsn is persisted, false otherwise.

◆ set_checkpoint()

void Log_checkpointing::set_checkpoint ( lsn_t  checkpoint_lsn)
inline

Updates the cached checkpoint_lsn.

◆ should_checkpoint()

bool Log_checkpointing::should_checkpoint ( )
private

Checks if checkpoint should be written.

Checks time elapsed since the last checkpoint, age of the last checkpoint and if there was any extra request to write the checkpoint (e.g. coming from log_checkpointing->request_sharp_checkpoint()).

Returns
true if checkpoint should be written

◆ start_thread()

void Log_checkpointing::start_thread ( )

Starts the log checkpointer thread.

◆ stop_thread_and_wait()

void Log_checkpointing::stop_thread_and_wait ( )

Informs the log checkpointer that it should stop and waits for it to happen before returning to the caller.

◆ stop_thread_no_wait()

void Log_checkpointing::stop_thread_no_wait ( )

Informs the log checkpointer that it should stop, but does not wait for it to happen.

◆ time_since_checkpoint()

std::chrono::steady_clock::duration Log_checkpointing::time_since_checkpoint ( )
private

Calculates time that elapsed since last checkpoint.

Returns
Time duration elapsed since the last checkpoint

◆ update_available_for_checkpoint_lsn()

lsn_t Log_checkpointing::update_available_for_checkpoint_lsn ( )
private

Updates lsn available for checkpoint.

(Never decreases it)

Returns
the updated value of m_available_for_checkpoint

◆ update_limits()

void Log_checkpointing::update_limits ( )

Calls ib::redo::handler->do_not_need_smaller_than(get_checkpoint_lsn()).

We prefer to have Log_checkpointing be the only place which calls do_not_need_smaller_than() so that it is easier to reason about, and to ensure that the argument passed is the checkpoint. We know that ib::redo::Handler::do_not_need_smaller_than() will recompute log_sys->m_free_check_limit_lsn used in wait_for_space(), based on things like checkpoint_lsn, log.m_capacity etc, so we call update_limits() whenever any of them changes.

Friends And Related Function Documentation

◆ ut::aligned_delete

template<typename T >
void ut::aligned_delete ( T ptr)
friend

◆ ut::aligned_new_withkey

template<typename T , typename... Args>
T * ut::aligned_new_withkey ( ut::PSI_memory_key_t  key,
std::size_t  alignment,
Args &&...  args 
)
friend

Member Data Documentation

◆ checkpoint_mutex

ib_mutex_t Log_checkpointing::checkpoint_mutex
mutable

Mutex which can be used to pause log checkpointer thread.

This is used by log_position_lock() together with log_buffer_x_lock(), to pause any changes to current_lsn or last_checkpoint_lsn.

◆ limits_mutex

ib_mutex_t Log_checkpointing::limits_mutex
mutable

Mutex which protects fields: m_available_for_checkpoint_lsn, m_requested_checkpoint_lsn.

It also synchronizes updates of log_sys_t::m_free_check_limit_lsn. It protects reads and writes of log_sys_t::m_writer_inside_extra_margin. It also protects the srv_checkpoint_disabled (together with the checkpoint_mutex).

◆ m_available_for_checkpoint_lsn

lsn_t Log_checkpointing::m_available_for_checkpoint_lsn {}
private

A new checkpoint could be written for this lsn value.

Up to this lsn value, all dirty pages have been added to flush lists and flushed. Updated in the log checkpointer thread by taking minimum oldest_modification out of the last dirty pages from each flush list minus Buf_flush_list_added_lsns::order_lag(). However, it will not be bigger than the current value of Buf_flush_list_added_lsns::smallest_not_added_lsn(). Read by: user threads when requesting fuzzy checkpoint Read by: log_print() (printing status of redo) Updated by: log_checkpointer Protected by: limits_mutex.

◆ m_checkpoint_lsn

atomic_lsn_t Log_checkpointing::m_checkpoint_lsn {}
private

Latest checkpoint lsn.

Read by: user threads, log_print (no protection) Read by: log_writer (under writer_mutex) Updated by: log_checkpointer (under both mutexes) Protected by (updates only): checkpoint_mutex + writer_mutex.

◆ m_checkpointer_thd

THD* Log_checkpointing::m_checkpointer_thd
private

THD used by the log_checkpointer thread.

◆ m_event

os_event_t Log_checkpointing::m_event

Event used by the log checkpointer thread to wait for requests.

◆ m_last_checkpoint_time

Log_clock_point Log_checkpointing::m_last_checkpoint_time {}
private

Latest checkpoint wall time.

Used by (private): log_checkpointer. Protected by: checkpoint_mutex (although, its used only from one thread)

◆ m_next_checkpoint_event

os_event_t Log_checkpointing::m_next_checkpoint_event

Event signaled by log checkpointer when it advances m_checkpoint_lsn.

◆ m_periodical_checkpoints_enabled

bool Log_checkpointing::m_periodical_checkpoints_enabled {}
private

If should perform checkpoints every innodb_log_checkpoint_every ms, or when doing so would help reclaim oldest redo log file.

Disabled during startup. Enabled in srv_start_threads. Updated by: starting thread (srv_start_threads) Read by: log_checkpointer

◆ m_requested_checkpoint_lsn

atomic_lsn_t Log_checkpointing::m_requested_checkpoint_lsn {}
private

When this is larger than the latest checkpoint, the log checkpointer thread will be forced to write a new checkpoint (unless the new latest checkpoint lsn would still be smaller than this value).

Read by: log_checkpointer without and with limit_mutex Read by: buf_flush_page_coordinator_thread under limits_mutex Updated by: user threads (log_free_check() or for sharp checkpoint) Protected by: limits_mutex.

◆ m_thread_should_stop

std::atomic_bool Log_checkpointing::m_thread_should_stop {}
private

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