MySQL 8.0.32
Source Code Documentation
log0files_governor.cc File Reference

Redo log files - governor. More...

#include <algorithm>
#include "log0buf.h"
#include "log0chkp.h"
#include "log0encryption.h"
#include "log0files_capacity.h"
#include "log0files_io.h"
#include "log0files_governor.h"
#include "log0log.h"
#include "log0sys.h"
#include "log0test.h"
#include "log0types.h"
#include "log0write.h"
#include "os0file.h"
#include "sql/current_thd.h"
#include "sql/debug_sync.h"
#include "sql/sql_thd_internal_api.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "ut0byte.h"
#include "ut0new.h"

Namespaces

namespace  log_files
 

Functions

static os_offset_t log_files::physical_size (const log_t &log, os_offset_t unused_file_size)
 
static bool log_files::physical_capacity_allows_to_recycle (const log_t &log, os_offset_t removed_file_size, os_offset_t unused_file_size)
 
static bool log_files::physical_capacity_allows_to_create (const log_t &log, os_offset_t unused_file_size)
 
static size_t log_files::number_of_files (const log_t &log)
 
static bool log_files::is_newest_lsn_nearby_the_end (const log_t &log)
 
static bool log_files::number_of_files_enforced_to_allow (const log_t &log)
 
static bool log_files::number_of_files_allows_to_recycle (const log_t &log)
 Checks if current number of redo files allows to recycle the oldest one. More...
 
static bool log_files::number_of_files_allows_to_create (const log_t &log)
 Checks if current number of redo files allows to create a new unused file. More...
 
static bool log_files::might_recycle_file (const log_t &log, os_offset_t removed_file_size, os_offset_t unused_file_size)
 
static bool log_files::might_create_unused_file (const log_t &log, os_offset_t unused_file_size)
 
bool log_files::is_consumption_needed (const log_t &log)
 Checks if consumption of the oldest redo log files needs to be done or might be postponed. More...
 
Log - files initialization and handling sysvar updates
static void log_files_initialize (log_t &log, lsn_t current_logical_size, lsn_t current_checkpoint_age)
 Computes initial capacity limits and size suggested for the next log file. More...
 
void log_files_initialize_on_empty_redo (log_t &log)
 Computes initial capacity limits and size suggested for the next log file. More...
 
void log_files_initialize_on_existing_redo (log_t &log)
 Computes initial capacity limits and size suggested for the next log file. More...
 
static void log_files_wait_until_next_governor_iteration (log_t &log)
 Waits until the log_files_governor performs a next iteration of its loop. More...
 
void log_files_resize_requested (log_t &log)
 Updates capacity limitations after srv_redo_log_capacity_used has been changed. More...
 
void log_files_thread_concurrency_updated (log_t &log)
 Updates capacity limitations after srv_thread_concurrency has been changed. More...
 

Log - files management.

enum class  Log_files_governor_iteration_result { RETRY_WITH_WRITER_MUTEX , COMPLETED_BUT_NEED_MORE_INTAKE , COMPLETED }
 Result of execution of log_files_governor_iteration_low(). More...
 
typedef std::function< void(Log_file_id file_id, Log_file_header &file_header)> Log_file_header_callback
 Callback type for callbacks called for a provided log file header. More...
 
static void log_files_create_allowed_validate ()
 Validates that new log files might be created. More...
 
static void log_files_access_allowed_validate (const log_t &log)
 Validates that log.m_files might be accessed from the current thread. More...
 
static void log_files_write_allowed_validate (const log_t &log)
 Validates that log.m_files might be accessed from the current thread and the current thread is allowed to perform write IO for redo log files, or create / remove / rename the existing redo log files. More...
 
static Log_file_header log_files_prepare_header (const log_t &log, lsn_t file_start_lsn)
 Prepares a log file header according to: More...
 
static Log_file_header log_files_prepare_header (const log_t &log, const Log_file &file)
 Prepares a log file header according to: More...
 
static void log_files_validate_not_consumed (const log_t &log)
 Asserts that all log files with id greater or equal to id of the file containing the oldest lsn, have not been consumed / marked for consumption. More...
 
static void log_files_validate_current_file (const log_t &log)
 Asserts that the current file exists and contains the log_files_newest_needed_lsn(log). More...
 
static dberr_t log_files_create_file (log_t &log, Log_file_id file_id, lsn_t start_lsn, lsn_t checkpoint_lsn, bool create_first_data_block)
 Creates a new redo log file and resizes the file to the size returned by log.m_capacity.next_file_size(). More...
 
static dberr_t log_files_rewrite_old_headers (log_t &log, Log_file_header_callback before_write, Log_file_header_callback after_write)
 Rewrites header of each of log files except the header of the newest file. More...
 
static dberr_t log_files_rewrite_newest_header (log_t &log, Log_file_header_callback cbk)
 Rewrites header of the newest log file, preparing it accordingly to the current metadata of the file, which is stored in memory (in log.m_files). More...
 
static dberr_t log_files_mark_current_file_as_incomplete (log_t &log)
 Rewrites header of the current log file (log.m_current_file) marking the file as not full in log_flags stored in the header. More...
 
static dberr_t log_files_mark_current_file_as_full (log_t &log)
 Rewrites header of the current log file (log.m_current_file) marking the file as full in log_flags stored in the header. More...
 
static void log_files_update_current_file_low (log_t &log)
 Updates log.m_current_file and (re-)opens that file (therefore also the log.m_current_file_handle becomes updated). More...
 
static lsn_t log_files_oldest_needed_lsn (const log_t &log)
 Finds the oldest LSN required by some of currently registered log consumers. More...
 
static lsn_t log_files_newest_needed_lsn (const log_t &log)
 Finds the newest LSN which potentially might be interesting for currently registered log consumers. More...
 
static dberr_t log_files_remove_from_future (log_t &log)
 Removes redo log files for LSN ranges (from future) with m_start_lsn larger than log_files_newest_needed_lsn(log). More...
 
static dberr_t log_files_remove_file (log_t &log, Log_file_id file_id)
 Removes the file from disk and after that from log.m_files. More...
 
static std::pair< lsn_t, lsn_tlog_files_logical_size_and_checkpoint_age (const log_t &log)
 Computes current logical size of the redo log and the minimum suggested soft (excluding extra_margin) logical capacity for the current redo log data. More...
 
static os_offset_t log_files_next_file_size (const log_t &log)
 Provides size for the next redo log file that will be created, unless there is not enough free space in current physical capacity, in which case it returns zero. More...
 
static void log_files_update_capacity_limits (log_t &log)
 Updates capacity limitations (log.m_capacity. More...
 
static void log_files_generate_dummy_records (log_t &log, lsn_t min_size)
 Generates at least a given bytes of intake to the redo log. More...
 
static bool log_files_is_truncate_allowed (const log_t &log)
 Checks if redo log file truncation is allowed. More...
 
static void log_files_truncate (log_t &log)
 Truncates the redo log file. More...
 
static void log_files_mark_consumed_file (log_t &log, Log_file_id file_id)
 Marks the given file as consumed by the registered redo log consumers. More...
 
static void log_files_mark_consumed_files (log_t &log)
 Marks each redo log file which became consumed by all registered redo log consumers, as consumed. More...
 
static bool log_files_remove_consumed_file (log_t &log, Log_file_id file_id)
 Removes the given consumed redo log file. More...
 
static bool log_files_recycle_file (log_t &log, Log_file_id file_id, os_offset_t unused_file_size)
 Recycles the given consumed redo log file. More...
 
static bool log_files_process_consumed_file (log_t &log, Log_file_id file_id)
 Process the given consumed redo log file (recycle or remove the file). More...
 
static void log_files_process_consumed_files (log_t &log)
 Process all redo log files marked as consumed (recycling or removing each). More...
 
static void log_files_create_next_as_unused_if_needed (log_t &log)
 Create a spare unused redo log file if there was no such file. More...
 
static bool log_files_consuming_oldest_file_takes_too_long (const log_t &log)
 Checks if the redo log consumption, according to the measured average speed of consumption, is too slow to consume the oldest file in reasonable time (10 seconds). More...
 
static bool log_files_filling_oldest_file_takes_too_long (const log_t &log)
 Checks if the redo log, according to the measured average speed, is not being filled fast enough to fill the oldest redo log file in reasonable time (10 seconds). More...
 
static bool log_files_should_rush_oldest_file_consumption (const log_t &log)
 Checks if there are any reasons to rush consumption of the oldest redo log file, that is if either: More...
 
static void log_files_adjust_unused_files_sizes (log_t &log)
 Ensures that unused redo log files have log.m_capacity.next_file_size(). More...
 
static Log_files_governor_iteration_result log_files_governor_iteration_low (log_t &log, bool has_writer_mutex)
 Tries to perform a single iteration of the log_files_governor thread. More...
 
static void log_files_governor_iteration (log_t &log)
 Performs a single iteration of the log_files_governor thread. More...
 
static dberr_t log_files_prepare_unused_file (log_t &log, Log_file_id file_id, lsn_t start_lsn, lsn_t checkpoint_lsn, bool create_first_data_block, os_offset_t &file_size)
 
static Log_file_id log_files_next_unused_id (log_t &log)
 
dberr_t log_files_produce_file (log_t &log)
 Creates a next log file, ready for writes. More...
 
void log_files_governor (log_t *log_ptr)
 The log files governor thread routine. More...
 
void log_files_wait_for_next_file_available (log_t &log)
 Waits until a next log file is available and can be produced. More...
 
dberr_t log_files_create (log_t &log, lsn_t flushed_lsn, lsn_t &checkpoint_lsn)
 Creates a new set of redo log files. More...
 
void log_files_remove (log_t &log)
 Removes all log files. More...
 
dberr_t log_files_start (log_t &log)
 Starts the log file management. More...
 
dberr_t log_files_persist_flags (log_t &log, Log_flags log_flags)
 Persists log flags to the newest log file. More...
 
dberr_t log_files_reset_creator_and_set_full (log_t &log)
 Resets creator name to the current creator and marks all files as full in their headers by setting LOG_HEADER_FLAG_FILE_FULL bit in the log_flags field. More...
 
void log_files_update_encryption (log_t &log, const Encryption_metadata &encryption_metadata)
 Updates the encryption metadata stored in-memory for all redo log files. More...
 
void log_files_dummy_records_request_disable (log_t &log)
 Disallows to generate dummy redo records but does not wait until the log_files_governor promised not to generate them anymore. More...
 
void log_files_dummy_records_disable (log_t &log)
 Disallows to generate dummy redo records and waits until the log_files_governor thread promised not to generate them. More...
 

Detailed Description

Redo log files - governor.

This module contains functions, which are useful during startup, for:

  1. redo log files creation / deletion,
  2. initialization on existing set of redo log files.

However, the major part of this module is the log_files_governor's implementation. This thread is fully responsible for:

  1. cooperation with the set of redo log consumers, including:
    1. finding out the oldest redo log consumer
    2. determining the oldest needed lsn (files ending at smaller lsn might be consumed),
    3. rushing the oldest redo log consumer when it's lagging too much,
  2. consumption of the oldest redo log files, including:
    1. finding the files that might be consumed,
    2. deciding if consumption is really needed or might be postponed,
    3. deciding if consumed redo log files should be recycled or removed,
    4. removing or renaming the redo log files,
  3. all updates of log.m_capacity object (
    See also
    Log_files_capacity),
  4. supervising pending redo resizes, helping to finish them when needed, by:
    1. truncating the newest redo log file if its end is too far away,
    2. writing dummy redo records to complete the file if intake is too slow,
  5. managing the set of unused redo log files, including:
    1. resizing them if needed,
    2. creating a spare file ahead,
    3. recycling the consumed files,
    4. deleting the consumed files if needed.

This module is responsible for managing redo log files on disk and keeping them in-sync with in-memory data structures: log.m_files, log.m_encryption_metadata.

Typedef Documentation

◆ Log_file_header_callback

typedef std::function<void(Log_file_id file_id, Log_file_header &file_header)> Log_file_header_callback

Callback type for callbacks called for a provided log file header.

Parameters
[in]file_idid of the log file which owns the header
[in,out]file_headerinitially filled header of redo file, accordingly to its currently known meta data; should be updated by callback if needed

Enumeration Type Documentation

◆ Log_files_governor_iteration_result

Result of execution of log_files_governor_iteration_low().

Enumerator
RETRY_WITH_WRITER_MUTEX 

Execution needs to be repeated, but this time when having the log.writer_mutex acquired.

COMPLETED_BUT_NEED_MORE_INTAKE 

Execution completed successfully, the governor should produce extra intake to help the pending redo resize to be finished.

COMPLETED 

Execution completed successfully, nothing to be done more.

Function Documentation

◆ log_files_access_allowed_validate()

static void log_files_access_allowed_validate ( const log_t log)
static

Validates that log.m_files might be accessed from the current thread.

Validates that log.m_files_mutex is acquired unless srv_is_being_stated is true.

Parameters
[in]logredo log

◆ log_files_adjust_unused_files_sizes()

static void log_files_adjust_unused_files_sizes ( log_t log)
static

Ensures that unused redo log files have log.m_capacity.next_file_size().

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log

◆ log_files_consuming_oldest_file_takes_too_long()

static bool log_files_consuming_oldest_file_takes_too_long ( const log_t log)
static

Checks if the redo log consumption, according to the measured average speed of consumption, is too slow to consume the oldest file in reasonable time (10 seconds).

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log
Returns
true iff the redo log consumption is not going to consume the oldest redo log file soon

Maximum time it might take to consume the oldest redo log file since now. If the average lsn consumption speed shows that most likely this time will not be enough for the oldest file to become consumed, then the oldest redo log consumer must be requested to proceed faster.

◆ log_files_create()

dberr_t log_files_create ( log_t log,
lsn_t  flushed_lsn,
lsn_t checkpoint_lsn 
)

Creates a new set of redo log files.

Remarks
Before creating the new log files, function asserts that there are no existing log files in the directory specified for the redo log. The new set of log files starts at the beginning of the first log block after the given lsn (block which start_lsn is greater than the given flushed_lsn). Checkpoint is written LOG_BLOCK_HDR_SIZE bytes after the beginning of that block. The set is marked as initialized if this call succeeded and information about the initial LSN is emitted to the error log. In such case, a new value is generated and assigned to the log.m_log_uuid (identifying the new log files).
Parameters
[in,out]logredo log
[in]flushed_lsnthe new set of log files should start with log block which first data byte is addressed by lsn greater or equal to this value
[out]checkpoint_lsnlsn of the first created checkpoint
Returns
DB_SUCCESS or error code

◆ log_files_create_allowed_validate()

static void log_files_create_allowed_validate ( )
static

Validates that new log files might be created.

◆ log_files_create_file()

static dberr_t log_files_create_file ( log_t log,
Log_file_id  file_id,
lsn_t  start_lsn,
lsn_t  checkpoint_lsn,
bool  create_first_data_block 
)
static

Creates a new redo log file and resizes the file to the size returned by log.m_capacity.next_file_size().

If checkpoint_lsn != 0, it also must hold: checkpoint_lsn >= start_lsn. The checkpoint information is stored to both checkpoint headers of the new file. When create_first_data_block is true, the first data block is modified also in the log buffer and written to disk

  • that can only be used when there are no concurrent writes to the log buffer.

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log
[in]file_idid of the log file to create
[in]start_lsnstart_lsn for the log file
[in]checkpoint_lsnlsn of the current checkpoint if it is located in the file, or zero
[in]create_first_data_blocktrue iff should format the first data block in log.buf and write to the file
Returns
DB_SUCCESS or error code

◆ log_files_create_next_as_unused_if_needed()

static void log_files_create_next_as_unused_if_needed ( log_t log)
static

Create a spare unused redo log file if there was no such file.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log

◆ log_files_dummy_records_disable()

void log_files_dummy_records_disable ( log_t log)

Disallows to generate dummy redo records and waits until the log_files_governor thread promised not to generate them.

Parameters
[in,out]logredo log

◆ log_files_dummy_records_request_disable()

void log_files_dummy_records_request_disable ( log_t log)

Disallows to generate dummy redo records but does not wait until the log_files_governor promised not to generate them anymore.

Parameters
[in,out]logredo log

◆ log_files_filling_oldest_file_takes_too_long()

static bool log_files_filling_oldest_file_takes_too_long ( const log_t log)
static

Checks if the redo log, according to the measured average speed, is not being filled fast enough to fill the oldest redo log file in reasonable time (10 seconds).

Note, that if there are multiple redo log files, then the oldest file has already been filled, in which case this function would return false.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log
Returns
true iff the redo log is not being filled with new data fast enough to fill the oldest redo log file soon

◆ log_files_generate_dummy_records()

static void log_files_generate_dummy_records ( log_t log,
lsn_t  min_size 
)
static

Generates at least a given bytes of intake to the redo log.

Requirement: none of log.m_files_mutex, log.writer_mutex, log.flusher_mutex, log.checkpointer_mutex is acquired when the function is called.

Requirement: the log_files_governor thread still hasn't promised not to generate dummy redo records (!log.m_no_more_dummy_records_promised).

Parameters
[in,out]logredo log
[in]min_sizemin number of bytes to write to the log buffer

◆ log_files_governor()

void log_files_governor ( log_t log_ptr)

The log files governor thread routine.

Parameters
[in,out]log_ptrpointer to redo log

◆ log_files_governor_iteration()

static void log_files_governor_iteration ( log_t log)
static

Performs a single iteration of the log_files_governor thread.

It first tries to perform the iteration without the log.writer_mutex. However, if that failed then this function would retry the attempt, after acquiring the log.writer_mutex.

Requirement: none of log.m_files_mutex, log.writer_mutex acquired before calling this function.

Parameters
[in,out]logredo log

◆ log_files_governor_iteration_low()

static Log_files_governor_iteration_result log_files_governor_iteration_low ( log_t log,
bool  has_writer_mutex 
)
static

Tries to perform a single iteration of the log_files_governor thread.

However, it might turn out, that the log.writer_mutex is required to perform required actions. In such case (happens only when has_writer_mutex is false) this function returns earlier, without completing all the steps and returns the Log_files_governor_iteration_result::RETRY_WITH_WRITER_MUTEX value. Then caller is responsible for repeating the call, after acquiring the log.writer_mutex.

Requirement: log.m_files_mutex not acquired before calling this function and log.writer_mutex acquired iff has_writer_mutex is true.

Parameters
[in,out]logredo log
[in]has_writer_mutextrue iff this thread has log.writer_mutex acquired
Returns
See also
Log_files_governor_iteration_result

◆ log_files_initialize()

static void log_files_initialize ( log_t log,
lsn_t  current_logical_size,
lsn_t  current_checkpoint_age 
)
static

Computes initial capacity limits and size suggested for the next log file.

Called after existing redo log files have been discovered (log.m_files), or when logically empty redo log is being initialized.

Requirement: srv_is_being_started is true.

Parameters
[in,out]logredo log
[in]current_logical_sizecurrent logical size of the redo log
[in]current_checkpoint_agecurrent checkpoint age

◆ log_files_initialize_on_empty_redo()

void log_files_initialize_on_empty_redo ( log_t log)

Computes initial capacity limits and size suggested for the next log file.

Called when logically empty redo log is being initialized.

Parameters
[in,out]logredo log

◆ log_files_initialize_on_existing_redo()

void log_files_initialize_on_existing_redo ( log_t log)

Computes initial capacity limits and size suggested for the next log file.

Called after existing redo log files have been discovered (log.m_files).

Parameters
[in,out]logredo log

◆ log_files_is_truncate_allowed()

static bool log_files_is_truncate_allowed ( const log_t log)
static

Checks if redo log file truncation is allowed.

It is guaranteed that the conditions checked by this function are based on properties guarded by log.m_files_mutex. Note that this function checks only for allowance. It does not check if truncate is recommended to be done.

Remarks
This function currently checks if there is just a single redo log consumer (and log_checkpointer is expected to be that one) in which case (and only then) the truncation is allowed.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log
Returns
true iff redo log file truncation is allowed

◆ log_files_logical_size_and_checkpoint_age()

static std::pair< lsn_t, lsn_t > log_files_logical_size_and_checkpoint_age ( const log_t log)
static

Computes current logical size of the redo log and the minimum suggested soft (excluding extra_margin) logical capacity for the current redo log data.

Note that this two values could be based on different redo log consumers, because different redo log consumers might be related to different margins preserved between size and capacity.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log
Returns
pair of logical redo log size and suggesed logical soft capacity

◆ log_files_mark_consumed_file()

static void log_files_mark_consumed_file ( log_t log,
Log_file_id  file_id 
)
static

Marks the given file as consumed by the registered redo log consumers.

It allows to recycle or remove the file later, when log_files_process_consumed_files() is called.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log
[in]file_idid of the file which should be marked as consumed

◆ log_files_mark_consumed_files()

static void log_files_mark_consumed_files ( log_t log)
static

Marks each redo log file which became consumed by all registered redo log consumers, as consumed.

It allows to recycle or remove those files later, when log_files_process_consumed_files() is called.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log

◆ log_files_mark_current_file_as_full()

static dberr_t log_files_mark_current_file_as_full ( log_t log)
static

Rewrites header of the current log file (log.m_current_file) marking the file as full in log_flags stored in the header.

Updates metadata stored in log.m_files and log.m_current_file for that file.

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log
Returns
DB_SUCCESS or error (if writing to disk failed)

◆ log_files_mark_current_file_as_incomplete()

static dberr_t log_files_mark_current_file_as_incomplete ( log_t log)
static

Rewrites header of the current log file (log.m_current_file) marking the file as not full in log_flags stored in the header.

Updates metadata stored in log.m_files and log.m_current_file for that file.

Remarks
This is required to be called just before InnoDB can remove log files from future (which it does when recovery didn't advance up to the last file).

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log
Returns
DB_SUCCESS or error (if writing to disk failed)

◆ log_files_newest_needed_lsn()

static lsn_t log_files_newest_needed_lsn ( const log_t log)
static

Finds the newest LSN which potentially might be interesting for currently registered log consumers.

Remarks
This is currently simply returning the log.write_lsn, but to preserve the design clean this function exists as a complementary to the
See also
log_files_oldest_needed_lsn().

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log
Returns
the newest LSN (log.write_lsn)

◆ log_files_next_file_size()

static os_offset_t log_files_next_file_size ( const log_t log)
static

Provides size for the next redo log file that will be created, unless there is not enough free space in current physical capacity, in which case it returns zero.

If the zero was returned, then it's guaranteed that either:

  • some consumed log files might be removed or recycled,
  • or some log files might become consumed and then removed or recycled. These actions are executed by the log_files_governor thread, and that will certainly lead to state in which log_files_next_file_size() returns non-zero, because that's the property guaranteed by the strategy in Log_files_capacity. Therefore for other threads, which are waiting on this function to return non zero value, it's enough to wait. However, while waiting for that, these threads must not hold m_files_mutex. This function cannot wait itself, because it needs m_files_mutex prior to be called and guarantees not to release the mutex itself.
Remarks
This function should be used only in scenarios in which it is important if there is free space to create the next redo log file. In scenarios which do not care about that, the log.m_capacity.next_file_size() should be used instead.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log
Returns
size of next redo log file or 0 if it cannot be created

◆ log_files_next_unused_id()

static Log_file_id log_files_next_unused_id ( log_t log)
static

◆ log_files_oldest_needed_lsn()

static lsn_t log_files_oldest_needed_lsn ( const log_t log)
static

Finds the oldest LSN required by some of currently registered log consumers.

This is based on log_consumer_get_oldest().

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log
Returns
maximum lsn up to which all log consumers have consumed the redo log

◆ log_files_persist_flags()

dberr_t log_files_persist_flags ( log_t log,
Log_flags  log_flags 
)

Persists log flags to the newest log file.

Flushes header of the log file and updates log.m_log_flags if succeeded.

Parameters
[in,out]logredo log
[in]log_flagslog_flags to persist
Returns
DB_SUCCESS or error

◆ log_files_prepare_header() [1/2]

static Log_file_header log_files_prepare_header ( const log_t log,
const Log_file file 
)
static

Prepares a log file header according to:

  • meta data currently stored for the given log file in log.m_files,
  • and fields: log.m_format, log.m_creator_name, log.m_log_flags, log.m_log_uuid.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log
[in]filelog file for which header is prepared
Returns
the prepared log file header

◆ log_files_prepare_header() [2/2]

static Log_file_header log_files_prepare_header ( const log_t log,
lsn_t  file_start_lsn 
)
static

Prepares a log file header according to:

  • meta data provided by parameters (file_start_lsn),
  • and fields: log.m_format, log.m_creator_name, log.m_log_flags, log.m_log_uuid.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log
[in]file_start_lsnstart lsn of the file
Returns
the prepared log file header

◆ log_files_prepare_unused_file()

static dberr_t log_files_prepare_unused_file ( log_t log,
Log_file_id  file_id,
lsn_t  start_lsn,
lsn_t  checkpoint_lsn,
bool  create_first_data_block,
os_offset_t file_size 
)
static

◆ log_files_process_consumed_file()

static bool log_files_process_consumed_file ( log_t log,
Log_file_id  file_id 
)
static

Process the given consumed redo log file (recycle or remove the file).

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started) and the given file must have been marked as consumed before calling this function.

Parameters
[in,out]logredo log
[in]file_idid of the file which should be processed
Return values
trueprocessed (recycled or removed) successfully
falsefailed to process (disk error)

◆ log_files_process_consumed_files()

static void log_files_process_consumed_files ( log_t log)
static

Process all redo log files marked as consumed (recycling or removing each).

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log

◆ log_files_produce_file()

dberr_t log_files_produce_file ( log_t log)

Creates a next log file, ready for writes.

Updates log.m_current_file.

Parameters
[in,out]logredo log
Return values
DB_SUCCESSif created successfully
DB_OUT_OF_DISK_SPACEif there was no free space to create next file, according to limitations we have for redo files, or according to space physically available on the disk
othererrors are possible

◆ log_files_recycle_file()

static bool log_files_recycle_file ( log_t log,
Log_file_id  file_id,
os_offset_t  unused_file_size 
)
static

Recycles the given consumed redo log file.

This is called when the redo log files marked as consumed are being processed (recycled or removed). The file becomes renamed and joins the set of unused (spare) redo log files.

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started) and the given file must have been marked as consumed before calling this function.

Parameters
[in,out]logredo log
[in]file_idid of the file which should be recycled
[in]unused_file_sizesize to which the file should be resized
Return values
truerecycled (including rename) successfully
falsefailed to rename (disk error)

◆ log_files_remove()

void log_files_remove ( log_t log)

Removes all log files.

Parameters
[in,out]logredo log

◆ log_files_remove_consumed_file()

static bool log_files_remove_consumed_file ( log_t log,
Log_file_id  file_id 
)
static

Removes the given consumed redo log file.

This is called when the redo log files marked as consumed are being processed (recycled or removed).

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started) and the given file must have been marked as consumed before calling this function.

Parameters
[in,out]logredo log
[in]file_idid of the file which should be removed
Return values
trueremoved successfully
falsefailed to remove (disk error)

◆ log_files_remove_file()

static dberr_t log_files_remove_file ( log_t log,
Log_file_id  file_id 
)
static

Removes the file from disk and after that from log.m_files.

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log
[in]file_idid of the log file to remove
Returns
DB_SUCCESS or error

◆ log_files_remove_from_future()

static dberr_t log_files_remove_from_future ( log_t log)
static

Removes redo log files for LSN ranges (from future) with m_start_lsn larger than log_files_newest_needed_lsn(log).

The files are removed from disk and from the log.m_files.

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log
Returns
DB_SUCCESS or error (if rewriting header of the current file failed)

◆ log_files_reset_creator_and_set_full()

dberr_t log_files_reset_creator_and_set_full ( log_t log)

Resets creator name to the current creator and marks all files as full in their headers by setting LOG_HEADER_FLAG_FILE_FULL bit in the log_flags field.

Flushes headers of all log files and updates log.m_creator_name and log.m_files accordingly if succeeded (if fails, then some files might remain updated and some not; metadata stored in log.m_files should reflect that).

Parameters
[in,out]logredo log
Returns
DB_SUCCESS or error

◆ log_files_resize_requested()

void log_files_resize_requested ( log_t log)

Updates capacity limitations after srv_redo_log_capacity_used has been changed.

It is called when user requests to change innodb_redo_log_capacity in runtime.

Parameters
[in,out]logredo log

◆ log_files_rewrite_newest_header()

static dberr_t log_files_rewrite_newest_header ( log_t log,
Log_file_header_callback  cbk 
)
static

Rewrites header of the newest log file, preparing it accordingly to the current metadata of the file, which is stored in memory (in log.m_files).

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log
[in]cbkcallback which can modify the prepared log file header, before the write to disk
Returns
DB_SUCCESS or error (if writing to disk failed)

◆ log_files_rewrite_old_headers()

static dberr_t log_files_rewrite_old_headers ( log_t log,
Log_file_header_callback  before_write,
Log_file_header_callback  after_write 
)
static

Rewrites header of each of log files except the header of the newest file.

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log
[in]before_writecallback which can modify the prepared header, before the write
[in]after_writecallback called after the successful write
Returns
DB_SUCCESS or error (if writing to disk failed)

◆ log_files_should_rush_oldest_file_consumption()

static bool log_files_should_rush_oldest_file_consumption ( const log_t log)
static

Checks if there are any reasons to rush consumption of the oldest redo log file, that is if either:

  • rushing consumption has been requested explicitly (by the log_writer which is waiting for a next available file),
  • or the redo log is being resized down.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log
Returns
true iff consumption of the oldest redo log files should be rushed

◆ log_files_start()

dberr_t log_files_start ( log_t log)

Starts the log file management.

Parameters
[in]logredo log
Returns
DB_SUCCESS or error

Existing log files are marked as not consumed.

◆ log_files_thread_concurrency_updated()

void log_files_thread_concurrency_updated ( log_t log)

Updates capacity limitations after srv_thread_concurrency has been changed.

It is called when user requests to change innodb_thread_concurrency in runtime.

Parameters
[in,out]logredo log

◆ log_files_truncate()

static void log_files_truncate ( log_t log)
static

Truncates the redo log file.

It must be called when there is exactly one redo log file.

Requirement: log.m_files_mutex and log.writer_mutex acquired before calling this function (unless srv_is_being_started) and log_files_is_truncate_allowed() must be allowing to do the truncation and there must exist exactly one redo log file.

Parameters
[in,out]logredo log

◆ log_files_update_capacity_limits()

static void log_files_update_capacity_limits ( log_t log)
static

Updates capacity limitations (log.m_capacity.

  • and log.free_check_sn). If redo resize was in progress, and conditions to consider it finished became satisfied, this call would result in marking the resize as done.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log

◆ log_files_update_current_file_low()

static void log_files_update_current_file_low ( log_t log)
static

Updates log.m_current_file and (re-)opens that file (therefore also the log.m_current_file_handle becomes updated).

Requirement: log.m_files_mutex, log.writer_mutex and log.flusher_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in,out]logredo log

◆ log_files_update_encryption()

void log_files_update_encryption ( log_t log,
const Encryption_metadata encryption_metadata 
)

Updates the encryption metadata stored in-memory for all redo log files.

Caller needs to have the log.m_files_mutex acquired before calling this.

Parameters
[in,out]logredo log
[in]encryption_metadataencryption metadata

◆ log_files_validate_current_file()

static void log_files_validate_current_file ( const log_t log)
static

Asserts that the current file exists and contains the log_files_newest_needed_lsn(log).

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log

◆ log_files_validate_not_consumed()

static void log_files_validate_not_consumed ( const log_t log)
static

Asserts that all log files with id greater or equal to id of the file containing the oldest lsn, have not been consumed / marked for consumption.

Requirement: log.m_files_mutex acquired before calling this function (unless srv_is_being_started).

Parameters
[in]logredo log

◆ log_files_wait_for_next_file_available()

void log_files_wait_for_next_file_available ( log_t log)

Waits until a next log file is available and can be produced.

Parameters
[in]logredo log

◆ log_files_wait_until_next_governor_iteration()

static void log_files_wait_until_next_governor_iteration ( log_t log)
static

Waits until the log_files_governor performs a next iteration of its loop.

Notifies the log_files_governor thread (to ensure it is soon).

Parameters
[in,out]logredo log

◆ log_files_write_allowed_validate()

static void log_files_write_allowed_validate ( const log_t log)
static

Validates that log.m_files might be accessed from the current thread and the current thread is allowed to perform write IO for redo log files, or create / remove / rename the existing redo log files.

Validates that both log.m_files_mutex and log.writer_mutex are acquired unless srv_is_being_stated is true.

Parameters
[in]logredo log