MySQL 8.0.40
Source Code Documentation
Log_files_capacity Class Reference

Responsible for the redo log capacity computations. More...

#include <log0files_capacity.h>

Classes

struct  Exposed
 

Private Attributes

Exposed m_exposed {}
 Cache for values returned by getters in this object, which otherwise would need to be computed on-demand. More...
 
os_offset_t m_current_physical_capacity {0}
 This is limitation for space on disk we are never allowed to exceed. More...
 
os_offset_t m_target_physical_capacity {0}
 Goal we are trying to achieve for m_current_physical_capacity when resize operation is in progress, else: equal to m_current_physical_capacity. More...
 
Log_resize_mode m_resize_mode {Log_resize_mode::NONE}
 Current resize direction. More...
 

Log_files_capacity implementation

void initialize (const Log_files_dict &files, lsn_t current_logical_size, lsn_t current_checkpoint_age)
 Initialize on discovered set of redo log files (empty set if new redo is being created). More...
 
void update (const Log_files_dict &files, lsn_t current_logical_size, lsn_t current_checkpoint_age)
 Updates all internal limits according to the provided parameters. More...
 
bool is_resizing_down () const
 
os_offset_t current_physical_capacity () const
 Provides maximum limitation for space occupied on disk. More...
 
os_offset_t target_physical_capacity () const
 If a redo downsize is in progress, it is the targeted value for the current_physical_capacity() (is equal if there is no resize in progress). More...
 
lsn_t soft_logical_capacity () const
 Soft limit for logical capacity of the redo log. More...
 
lsn_t hard_logical_capacity () const
 Hard limit for logical capacity of the redo log. More...
 
lsn_t adaptive_flush_min_age () const
 Once checkpoint age exceeds this value, the flushing of pages starts to be adaptive. More...
 
lsn_t adaptive_flush_max_age () const
 Once checkpoint age exceeds that value, the flushing of pages is the most aggressive possible since then. More...
 
lsn_t aggressive_checkpoint_min_age () const
 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...
 
os_offset_t next_file_size () const
 Provides size of the next redo log file that will be created. More...
 
lsn_t next_file_earlier_margin () const
 Provides margin which might be used ahead of the newest lsn to create a next file earlier if needed (it will be created as unused redo file). More...
 
static os_offset_t next_file_size (os_offset_t physical_capacity)
 Computes size of a next redo log file that would be chosen for a given physical capacity. More...
 
static lsn_t next_file_earlier_margin (os_offset_t physical_capacity)
 Computes margin which might be used ahead of the newest lsn to create a next file earlier if needed (it will be created as unused redo file). More...
 
static lsn_t guess_hard_logical_capacity_for_soft (lsn_t soft_logical_capacity)
 Computes hard logical capacity, that corresponds to the provided soft logical capacity of the redo log (. More...
 
static lsn_t soft_logical_capacity_for_hard (lsn_t hard_logical_capacity)
 Computes soft logical capacity, that corresponds to the provided hard logical capacity of the redo log (. More...
 
static lsn_t hard_logical_capacity_for_physical (os_offset_t physical_capacity)
 Computes hard logical capacity, that corresponds to the provided physical capacity of the redo log (. More...
 
static lsn_t sync_flush_logical_capacity_for_soft (lsn_t soft_logical_capacity)
 Computes maximum age of dirty pages up to which there is no sync flush enforced on page cleaners. More...
 
static lsn_t guess_soft_logical_capacity_for_sync_flush (lsn_t adaptive_flush_max_age)
 Computes soft logical capacity, that corresponds to the provided maximum age of dirty pages up to which there is no sync flush enforced on page cleaners. More...
 
void cancel_resize ()
 Cancels current resize operation immediately. More...
 
void update_target ()
 Updates m_target_physical_capacity (reading srv_redo_log_capacity_used) and possibly starts a new downsize operation. More...
 
bool is_target_reached_for_logical_size (lsn_t current_logical_size) const
 Checks if target of the resize is reached, with regards to the criteria based on the current logical size of the redo. More...
 
bool is_target_reached_for_physical_size (os_offset_t current_physical_size) const
 Checks if target of the resize is reached, with regards to the criteria based on the current physical size of existing log files (excludes unused). More...
 
bool is_target_reached_for_max_file_size (const Log_files_dict &files) const
 Checks if target of the resize is reached, with regards to the criteria based on the largest existing redo file. More...
 
bool is_target_reached_for_resizing_down (const Log_files_dict &files, lsn_t current_logical_size) const
 Checks if target of the resize is reached. More...
 
void update_if_target_reached (const Log_files_dict &files, lsn_t current_logical_size)
 Checks if target of the resize is reached with regards to all criteria and updates the m_resize_mode, m_current_physical_capacity when that happens (marking the resize operation as finished). More...
 
void update_resize_status_variable ()
 Updates value of server status variable: innodb_redo_log_resize_status. More...
 
void update_status_variables (const Log_files_dict &files, lsn_t current_logical_size)
 Updates values of server status variables: innodb_redo_log_capacity_resized, innodb_redo_log_logical_size, innodb_redo_log_physical_size, innodb_redo_log_resize_status. More...
 
void update_exposed (lsn_t current_logical_size)
 Updates cached and exposed values related to the logical redo capacity: More...
 
lsn_t get_suggested_hard_logical_capacity (lsn_t current_checkpoint_age) const
 Computes suggested value for the current hard logical capacity. More...
 

Detailed Description

Responsible for the redo log capacity computations.

Computes size for the next log file that will be created. Tracks the redo resize operation when the innodb_redo_log_capacity gets changed. Computes maximum ages for dirty pages, which are then used by page cleaner coordinator.

Remarks
When downsize is started, the limits for ages are decreased, forcing page cleaners to flush more dirty pages then. File sizes for new redo files are adjusted accordingly, so they could always be effectively used to hold the whole existing redo log data (for the given current logical size).

Member Function Documentation

◆ adaptive_flush_max_age()

lsn_t Log_files_capacity::adaptive_flush_max_age ( ) const

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_files_capacity::adaptive_flush_min_age ( ) const

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_files_capacity::aggressive_checkpoint_min_age ( ) const

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

◆ cancel_resize()

void Log_files_capacity::cancel_resize ( )
private

Cancels current resize operation immediately.

Remarks
If the innodb_redo_log_capacity is changed when there is a previous redo resize in progress, the previous resize is first cancelled.

◆ current_physical_capacity()

os_offset_t Log_files_capacity::current_physical_capacity ( ) const

Provides maximum limitation for space occupied on disk.

Note
This value changes only during calls to
See also
update or
initialize.
Returns
maximum allowed size on disk, in bytes

◆ get_suggested_hard_logical_capacity()

lsn_t Log_files_capacity::get_suggested_hard_logical_capacity ( lsn_t  current_checkpoint_age) const
private

Computes suggested value for the current hard logical capacity.

Remarks
This becomes non-trivial when the redo log is being resized down, because this method is supposed to follow the checkpoint age then. On the other hand, when the redo log is not being resized down, this method computes the hard logical capacity by using simple math based on the current physical capacity only (ie. ignoring the current checkpoint age).
Parameters
[in]current_checkpoint_agecurrent checkpoint age, used only when resizing down
Returns
suggested value for current hard logical capacity

◆ guess_hard_logical_capacity_for_soft()

lsn_t Log_files_capacity::guess_hard_logical_capacity_for_soft ( lsn_t  soft_logical_capacity)
static

Computes hard logical capacity, that corresponds to the provided soft logical capacity of the redo log (.

See also
soft_logical_capacity()).
Parameters
[in]soft_logical_capacitylogical capacity for user threads, used in log_free_check() calls
Returns
hard logical capacity

◆ guess_soft_logical_capacity_for_sync_flush()

lsn_t Log_files_capacity::guess_soft_logical_capacity_for_sync_flush ( lsn_t  adaptive_flush_max_age)
static

Computes soft logical capacity, that corresponds to the provided maximum age of dirty pages up to which there is no sync flush enforced on page cleaners.

This is a larger value than the provided maximum age, because sync flush must be started earlier than log_free_check() calls begin to stop user threads.

Parameters
[in]adaptive_flush_max_agemaximum age of dirty page without sync flush started
Returns
soft logical capacity

◆ hard_logical_capacity()

lsn_t Log_files_capacity::hard_logical_capacity ( ) const

Hard limit for logical capacity of the redo log.

This limitation includes "extra_writer_margin" that belongs to the log writer thread. The log writer does not to exceed this limit. If space isn't reclaimed after 1 sec wait, it writes only as much as possible or crashes the InnoDB.

Note
This value changes only during calls to
See also
update or
initialize.
Returns
limitation for free space in the redo log for the log writer thread

◆ hard_logical_capacity_for_physical()

lsn_t Log_files_capacity::hard_logical_capacity_for_physical ( os_offset_t  physical_capacity)
static

Computes hard logical capacity, that corresponds to the provided physical capacity of the redo log (.

See also
hard_logical_capacity()).
Parameters
[in]physical_capacityphysical capacity for the redo log
Returns
hard logical capacity

◆ initialize()

void Log_files_capacity::initialize ( const Log_files_dict files,
lsn_t  current_logical_size,
lsn_t  current_checkpoint_age 
)

Initialize on discovered set of redo log files (empty set if new redo is being created).

Parameters
[in]filesin-memory dictionary of existing files
[in]current_logical_sizecurrent logical size of data in redo, or 0 if new redo is being created
[in]current_checkpoint_agecurrent checkpoint age

◆ is_resizing_down()

bool Log_files_capacity::is_resizing_down ( ) const
Returns
true iff resize-down is pending

◆ is_target_reached_for_logical_size()

bool Log_files_capacity::is_target_reached_for_logical_size ( lsn_t  current_logical_size) const
private

Checks if target of the resize is reached, with regards to the criteria based on the current logical size of the redo.

Parameters
[in]current_logical_sizecurrent logical size of the redo log
Returns
true iff the target is reached

◆ is_target_reached_for_max_file_size()

bool Log_files_capacity::is_target_reached_for_max_file_size ( const Log_files_dict files) const
private

Checks if target of the resize is reached, with regards to the criteria based on the largest existing redo file.

Parameters
[in]filesin-memory dictionary of existing files
Returns
true iff the target is reached

◆ is_target_reached_for_physical_size()

bool Log_files_capacity::is_target_reached_for_physical_size ( os_offset_t  current_physical_size) const
private

Checks if target of the resize is reached, with regards to the criteria based on the current physical size of existing log files (excludes unused).

Parameters
[in]current_physical_sizetotal size of existing redo log files, excluding unused (spare) files
Returns
true iff the target is reached

◆ is_target_reached_for_resizing_down()

bool Log_files_capacity::is_target_reached_for_resizing_down ( const Log_files_dict files,
lsn_t  current_logical_size 
) const
private

Checks if target of the resize is reached.

Parameters
[in]filesin-memory dictionary of existing files
[in]current_logical_sizecurrent logical size of the redo log
Returns
true iff the target is reached

◆ next_file_earlier_margin() [1/2]

lsn_t Log_files_capacity::next_file_earlier_margin ( ) const

Provides margin which might be used ahead of the newest lsn to create a next file earlier if needed (it will be created as unused redo file).

Note
This value changes only during calls to
See also
update or
initialize.
Returns
the maximum allowed margin ahead of the newest lsn to be reserved

◆ next_file_earlier_margin() [2/2]

lsn_t Log_files_capacity::next_file_earlier_margin ( os_offset_t  physical_capacity)
static

Computes margin which might be used ahead of the newest lsn to create a next file earlier if needed (it will be created as unused redo file).

The computation is done for a given physical capacity.

Parameters
[in]physical_capacityphysical capacity assumed for computation
Returns
the maximum allowed margin ahead of the newest lsn to be reserved

◆ next_file_size() [1/2]

os_offset_t Log_files_capacity::next_file_size ( ) const

Provides size of the next redo log file that will be created.

The initial value becomes set during a call to

See also
initialize. Since then, it changes only when innodb_redo_log_capacity is changed, during a call to
update.
Note
Does not depend on whether the file actually might be created or not. It is log_files_governor's responsibility not to exceed the physical capacity.
Remarks
The strategy used by the Log_files_capacity, guarantees that next redo log file should always be possible to be created. That's because:
  1. The next file size is always chosen as: innodb_redo_log_capacity / LOG_N_FILES.
  1. The logical capacity of the redo log is limited to: (LOG_N_FILES - 2) / LOG_N_FILES * m_current_physical_capacity.
  2. The m_current_physical_capacity is changed only after resize is finished, and the resize is considered finished only when:
    • all redo log files have size <= innodb_redo_log_capacity / LOG_N_FILES,
    • and the logical size of the redo log can fit physical size of LOG_N_FILES - 2 redo files, which guarantees that at most LOG_N_FILES - 1 redo files will ever need to exist (consider scenario in which oldest_lsn is at the very end of the oldest redo files and newest_lsn is at the very beginning of the newest redo file if you are curious why -2 is there instead of -1).
Returns
file size suggested for next log file to create

◆ next_file_size() [2/2]

os_offset_t Log_files_capacity::next_file_size ( os_offset_t  physical_capacity)
static

Computes size of a next redo log file that would be chosen for a given physical capacity.

Parameters
[in]physical_capacityphysical capacity assumed for computation
Returns
file size suggested for next log file to create

◆ soft_logical_capacity()

lsn_t Log_files_capacity::soft_logical_capacity ( ) const

Soft limit for logical capacity of the redo log.

When the log writer exceeds this limitation, all user threads are paused during log_free_check() calls and message is emitted to the error log. The log writer can still continue to write until it reaches the hard limit for logical capacity (value returned by hard_logical_capacity()).

Note
This value changes only during calls to
See also
update or
initialize.
Returns
limitation for free space in the redo log for user threads

◆ soft_logical_capacity_for_hard()

lsn_t Log_files_capacity::soft_logical_capacity_for_hard ( lsn_t  hard_logical_capacity)
static

Computes soft logical capacity, that corresponds to the provided hard logical capacity of the redo log (.

See also
hard_logical_capacity()).
Parameters
[in]hard_logical_capacitylogical capacity for the log writer
Returns
soft logical capacity

◆ sync_flush_logical_capacity_for_soft()

lsn_t Log_files_capacity::sync_flush_logical_capacity_for_soft ( lsn_t  soft_logical_capacity)
static

Computes maximum age of dirty pages up to which there is no sync flush enforced on page cleaners.

This is a smaller value than soft logical capacity, because sync flush must be started earlier than log_free_check() calls begin to stop user threads.

Parameters
[in]soft_logical_capacitylogical capacity for user threads, used in log_free_check() calls
Returns
maximum age of dirty pages before the sync flush is started

◆ target_physical_capacity()

os_offset_t Log_files_capacity::target_physical_capacity ( ) const

If a redo downsize is in progress, it is the targeted value for the current_physical_capacity() (is equal if there is no resize in progress).

It is set to srv_redo_log_capacity_used when

See also
update is called.
Note
This value changes only during calls to
See also
update or
initialize.
Returns
targeted physical capacity, in bytes

◆ update()

void Log_files_capacity::update ( const Log_files_dict files,
lsn_t  current_logical_size,
lsn_t  current_checkpoint_age 
)

Updates all internal limits according to the provided parameters.

If there are any values outside this class, on which computations of limits depend on, they should be explicitly provided here, except the server variables (srv_thread_concurrency, srv_redo_log_capacity_used).

Parameters
[in]filesin-memory dictionary of files
[in]current_logical_sizecurrent logical size of data in the redo log; it depends directly on the oldest redo log consumer
[in]current_checkpoint_agecurrent checkpoint age

◆ update_exposed()

void Log_files_capacity::update_exposed ( lsn_t  current_logical_size)
private

Updates cached and exposed values related to the logical redo capacity:

  • See also
    m_soft_logical_capacity
  • See also
    m_hard_logical_capacity
  • See also
    m_agressive_checkpoint_min_age
  • See also
    m_adaptive_flush_min_age
  • See also
    m_adaptive_flush_max_age
    Parameters
    [in]current_logical_sizecurrent logical size of the redo log

◆ update_if_target_reached()

void Log_files_capacity::update_if_target_reached ( const Log_files_dict files,
lsn_t  current_logical_size 
)
private

Checks if target of the resize is reached with regards to all criteria and updates the m_resize_mode, m_current_physical_capacity when that happens (marking the resize operation as finished).

Parameters
[in]filesin-memory dictionary of existing files
[in]current_logical_sizecurrent logical size of the redo log

◆ update_resize_status_variable()

void Log_files_capacity::update_resize_status_variable ( )
private

Updates value of server status variable: innodb_redo_log_resize_status.

◆ update_status_variables()

void Log_files_capacity::update_status_variables ( const Log_files_dict files,
lsn_t  current_logical_size 
)
private

Updates values of server status variables: innodb_redo_log_capacity_resized, innodb_redo_log_logical_size, innodb_redo_log_physical_size, innodb_redo_log_resize_status.

Parameters
[in]filesin-memory dictionary of existing files
[in]current_logical_sizecurrent logical size of the redo log

◆ update_target()

void Log_files_capacity::update_target ( )
private

Updates m_target_physical_capacity (reading srv_redo_log_capacity_used) and possibly starts a new downsize operation.

Might also update: m_resize_mode, m_current_physical_capacity.

Member Data Documentation

◆ m_current_physical_capacity

os_offset_t Log_files_capacity::m_current_physical_capacity {0}
private

This is limitation for space on disk we are never allowed to exceed.

This is the guard of disk space - current size of all log files on disk is always not greater than this value.

Note
Updated only during calls to
See also
initialize and
update.

◆ m_exposed

Exposed Log_files_capacity::m_exposed {}
private

Cache for values returned by getters in this object, which otherwise would need to be computed on-demand.

These values do not have impact on state updates of this object.

Note
Updated only during calls to
See also
initialize and
update.

◆ m_resize_mode

Log_resize_mode Log_files_capacity::m_resize_mode {Log_resize_mode::NONE}
private

Current resize direction.

When user decides to resize down the redo log, it becomes Log_resize_mode::RESIZING_DOWN until the resize is finished or user decides to stop it (providing other capacity). Note, that resize is not started during startup (when srv_is_being_started is true).

Note
Updated only during calls to
See also
initialize and
update.

◆ m_target_physical_capacity

os_offset_t Log_files_capacity::m_target_physical_capacity {0}
private

Goal we are trying to achieve for m_current_physical_capacity when resize operation is in progress, else: equal to m_current_physical_capacity.

During startup (when srv_is_being_started is true) it stays equal to the m_current_physical_capacity (which is then computed for discovered log files). After startup, it's set to srv_redo_log_capacity_used by calls to

See also
update.

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