MySQL 8.4.2
Source Code Documentation
log0log.h File Reference

Redo log - the main header. More...

#include "log0files_capacity.h"
#include "log0files_dict.h"
#include "log0files_finder.h"
#include "log0files_governor.h"
#include "log0files_io.h"
#include "log0sys.h"
#include "log0types.h"

Go to the source code of this file.

Functions

Log - LSN computations.
constexpr lsn_t log_translate_sn_to_lsn (sn_t sn)
 Calculates lsn value for given sn value. More...
 
sn_t log_translate_lsn_to_sn (lsn_t lsn)
 Calculates sn value for given lsn value. More...
 
bool log_is_data_lsn (lsn_t lsn)
 Validates a given lsn value. More...
 
Log - general functions.
static sn_t log_get_sn (const log_t &log)
 
lsn_t log_get_lsn (const log_t &log)
 Gets the current lsn value. 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...
 
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_update_exported_variables (const log_t &log)
 
Log - initialization of the redo log system.
dberr_t log_sys_init (bool expect_no_files, lsn_t flushed_lsn, lsn_t &new_files_lsn)
 Initializes log_sys and finds existing redo log files, or creates a new set of redo log files. More...
 
dberr_t log_start (log_t &log, lsn_t checkpoint_lsn, lsn_t start_lsn, bool allow_checkpoints=true)
 Starts the initialized redo log system using a provided checkpoint_lsn and current lsn. More...
 
void log_sys_close ()
 Close the log system and free all the related memory. More...
 
void log_write_ahead_resize (log_t &log, size_t new_size)
 Resizes the write ahead buffer in the redo log. More...
 
Log - the log position locking.
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...
 
Log - persisting the flags.
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...
 
void log_persist_initialized (log_t &log)
 Marks the redo log files as belonging to the initialized data directory with initialized set of redo log files. More...
 
void log_crash_safe_validate (log_t &log)
 Asserts that the log is not marked as crash-unsafe. More...
 

Log - the log threads and mutexes

#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)
 
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 ()
 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_make_empty_and_stop_background_threads (log_t &log)
 Function similar to. More...
 
void log_wake_threads (log_t &log)
 Wakes up all log threads which are alive. More...
 

Detailed Description

Redo log - the main header.

Basic types are defined inside log0types.h.

Constant values are defined inside log0constants.h, but that file should only be included by log0types.h.

The log_sys is defined in log0sys.h.

Functions related to the log buffer are declared in log0buf.h.

Functions related to the checkpoints are declared in log0chkp.h.

Functions related to the writer/flusher are declared in log0write.h.

Functions computing capacity of redo and related margins are declared in log0files_capacity.h.

Functions doing IO to log files and formatting log blocks are declared in log0files_io.h.

Macro Definition Documentation

◆ 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)

Function Documentation

◆ 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 ( )

Validates that all the log background threads are inactive.

Used only to assert, that the state is correct.

◆ log_crash_safe_validate()

void log_crash_safe_validate ( log_t log)

Asserts that the log is not marked as crash-unsafe.

Parameters
[in,out]logredo log

◆ 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
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_sn()

static sn_t log_get_sn ( const log_t log)
inlinestatic
Returns
consistent sn value for locked state

◆ log_is_data_lsn()

bool log_is_data_lsn ( 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_empty_and_stop_background_threads()

void log_make_empty_and_stop_background_threads ( log_t log)

Function similar to.

See also
log_stop_background_threads() except that it stops all the log threads in such a way, that the redo log will be logically empty after the threads are stopped.
Note
It is caller responsibility to ensure that all threads other than the log_files_governor cannot produce new redo log records when this function is being called.

◆ 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_persist_initialized()

void log_persist_initialized ( log_t log)

Marks the redo log files as belonging to the initialized data directory with initialized set of redo log files.

Flushes the log_flags without the flag LOG_HEADER_FLAG_NOT_INITIALIZED to the newest redo log file.

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_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_start()

dberr_t log_start ( log_t log,
lsn_t  checkpoint_lsn,
lsn_t  start_lsn,
bool  allow_checkpoints = true 
)

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_lsncheckpoint lsn
[in]start_lsncurrent lsn to start at
[in]allow_checkpointstrue iff allows writing newer checkpoints
Returns
DB_SUCCESS or error

◆ 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.

Parameters
[in,out]logredo log

◆ log_sys_close()

void log_sys_close ( )

Close the log system and free all the related memory.

◆ log_sys_init()

dberr_t log_sys_init ( bool  expect_no_files,
lsn_t  flushed_lsn,
lsn_t new_files_lsn 
)

Initializes log_sys and finds existing redo log files, or creates a new set of redo log files.

New redo log files are created in following cases:

  • there are no existing redo log files in the log directory,
  • existing set of redo log files is not marked as fully initialized (flag LOG_HEADER_FLAG_NOT_INITIALIZED exists in the newest file).

After this call, the log_sys global variable is allocated and initialized. InnoDB might start recovery then.

Remarks
The redo log files are not resized in this function, because before resizing log files, InnoDB must run recovery and ensure log files are logically empty. The redo resize is currently the only scenario in which the initialized log_sys might become closed by log_sys_close() and then re-initialized by another call to log_sys_init().
Note
Note that the redo log system is NOT ready for user writes after this call is finished. The proper order of calls looks like this:
  • log_sys_init(),
  • log_start(),
  • log_start_background_threads() and this sequence is executed inside srv_start() in srv0start.cc (interleaved with remaining logic of the srv_start())
Note this function also verifies that REDO logs are in known format.
Parameters
[in]expect_no_filestrue means we should return DB_ERROR if log files are present in the directory before proceeding any further
[in]flushed_lsnlsn at which new redo log files might be started if they had to be created during this call; this should be lsn stored in the system tablespace header at offset FIL_PAGE_FILE_FLUSH_LSN if the data directory has been initialized;
[out]new_files_lsnupdated to the lsn of the first checkpoint created in the new log files if new log files are created; else: 0
Returns
DB_SUCCESS or error

◆ log_translate_lsn_to_sn()

sn_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 ( sn_t  sn)
inlineconstexpr

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_exported_variables()

void log_update_exported_variables ( const log_t 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_wake_threads()

void log_wake_threads ( log_t log)

Wakes up all log threads which are alive.

Parameters
[in,out]logredo log

◆ 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)