MySQL 8.3.0
Source Code Documentation
log0types.h File Reference

Redo log basic types. More...

#include <atomic>
#include <chrono>
#include <string>
#include "univ.i"
#include "os0file.h"
#include "ut0cpu_cache.h"
#include "log0constants.h"

Go to the source code of this file.

Classes

struct  Log_files_context
 Configures path to the root directory, where redo subdirectory might be located (or redo log files if the ruleset is older). More...
 
struct  Log_file_header
 Meta data stored in log file header. More...
 
struct  Log_checkpoint_header
 Meta data stored in one of two checkpoint headers. More...
 
struct  Log_data_block_header
 Meta data stored in header of a log data block. More...
 
struct  Log_file_id_and_size
 Pair of: log file id and log file size (expressed in bytes). More...
 
struct  Log_file_id_and_header
 Pair of: log file id and log file header. More...
 
class  Log_file_handle
 Handle which allows to do reads / writes for the opened file. More...
 
struct  Log_file
 Meta information about single log file. More...
 
struct  Log_files_stats
 Runtime statistics related to redo log files management. More...
 

Macros

#define LSN_PF   UINT64PF
 Print format for lsn_t values, used in functions like printf. More...
 

Typedefs

typedef uint64_t lsn_t
 Type used for all log sequence number storage and arithmetic. More...
 
typedef size_t Log_file_id
 Log file id (0 for ib_redo0) More...
 
typedef uint32_t Log_flags
 Log flags (stored in file header of log file). More...
 
typedef uint32_t Log_uuid
 Number which tries to uniquely identify a created set of redo log files. More...
 
using atomic_lsn_t = std::atomic< lsn_t >
 Alias for atomic based on lsn_t. More...
 
typedef uint64_t sn_t
 Type used for sn values, which enumerate bytes of data stored in the log. More...
 
using atomic_sn_t = std::atomic< sn_t >
 Alias for atomic based on sn_t. More...
 
typedef std::atomic< int64_t > log_flushes_t
 Type used for counters in log_t: flushes_requested and flushes_expected. More...
 
typedef std::function< void(Log_file_id file_id, Log_file_type file_type, os_offset_t offset, os_offset_t size)> Log_file_io_callback
 Callback called on each read or write operation on a redo log file. More...
 
typedef std::atomic< uint32_t(*)(const byte *log_block)> Log_checksum_algorithm_atomic_ptr
 Function used to calculate checksums of log blocks. More...
 
using Log_clock = std::chrono::high_resolution_clock
 Clock used to measure time spent in redo log (e.g. More...
 
using Log_clock_point = std::chrono::time_point< Log_clock >
 Time point defined by the Log_clock. More...
 

Enumerations

enum class  Log_checkpoint_header_no : uint32_t { HEADER_1 , HEADER_2 }
 Enumerates checkpoint headers in the redo log file. More...
 
enum class  Log_file_type { NORMAL , UNUSED }
 Type of redo log file. More...
 
enum class  Log_format : uint32_t {
  LEGACY = 0 , VERSION_5_7_9 = 1 , VERSION_8_0_1 = 2 , VERSION_8_0_3 = 3 ,
  VERSION_8_0_19 = 4 , VERSION_8_0_28 = 5 , VERSION_8_0_30 = 6 , CURRENT = VERSION_8_0_30
}
 Supported redo log formats. More...
 
enum class  Log_files_ruleset { PRE_8_0_30 , CURRENT }
 Ruleset defining how redo log files are named, where they are stored, when they are created and what sizes could they have. More...
 
enum class  Log_resize_mode { NONE , RESIZING_DOWN }
 Direction of resize operation. More...
 
enum class  Log_file_access_mode { READ_WRITE , READ_ONLY , WRITE_ONLY }
 Type of access allowed for the opened redo log file. More...
 

Detailed Description

Redo log basic types.

Macro Definition Documentation

◆ LSN_PF

#define LSN_PF   UINT64PF

Print format for lsn_t values, used in functions like printf.

Typedef Documentation

◆ atomic_lsn_t

using atomic_lsn_t = std::atomic<lsn_t>

Alias for atomic based on lsn_t.

◆ atomic_sn_t

using atomic_sn_t = std::atomic<sn_t>

Alias for atomic based on sn_t.

◆ Log_checksum_algorithm_atomic_ptr

typedef std::atomic<uint32_t (*)(const byte *log_block)> Log_checksum_algorithm_atomic_ptr

Function used to calculate checksums of log blocks.

◆ Log_clock

using Log_clock = std::chrono::high_resolution_clock

Clock used to measure time spent in redo log (e.g.

when flushing).

◆ Log_clock_point

using Log_clock_point = std::chrono::time_point<Log_clock>

Time point defined by the Log_clock.

◆ Log_file_id

typedef size_t Log_file_id

Log file id (0 for ib_redo0)

◆ Log_file_io_callback

typedef std::function<void(Log_file_id file_id, Log_file_type file_type, os_offset_t offset, os_offset_t size)> Log_file_io_callback

Callback called on each read or write operation on a redo log file.

Parameters
[in]file_idid of the redo log file (target of the IO operation)
[in]file_typetype of the redo log file
[in]offsetoffset in the file, at which read or write operation is going to start (expressed in bytes and computed from the beginning of the file)
[in]sizesize of data that is going to be read or written in the IO operation

◆ Log_flags

typedef uint32_t Log_flags

Log flags (stored in file header of log file).

◆ log_flushes_t

typedef std::atomic<int64_t> log_flushes_t

Type used for counters in log_t: flushes_requested and flushes_expected.

They represent number of requests to flush the redo log to disk.

◆ Log_uuid

typedef uint32_t Log_uuid

Number which tries to uniquely identify a created set of redo log files.

Redo log files, which have different values of Log_uuid, most likely have been created for different directories and cannot be mixed. This way foreign redo files might be easily recognized. When that is the case, most likely something went wrong when copying files.

◆ lsn_t

typedef uint64_t lsn_t

Type used for all log sequence number storage and arithmetic.

◆ sn_t

typedef uint64_t sn_t

Type used for sn values, which enumerate bytes of data stored in the log.

Note that these values skip bytes of headers and footers of log blocks.

Enumeration Type Documentation

◆ Log_checkpoint_header_no

enum class Log_checkpoint_header_no : uint32_t
strong

Enumerates checkpoint headers in the redo log file.

Enumerator
HEADER_1 

The first checkpoint header.

HEADER_2 

The second checkpoint header.

◆ Log_file_access_mode

enum class Log_file_access_mode
strong

Type of access allowed for the opened redo log file.

Enumerator
READ_WRITE 

The opened file can be both read and written.

READ_ONLY 

The opened file can be only read.

WRITE_ONLY 

The opened file can be only written.

◆ Log_file_type

enum class Log_file_type
strong

Type of redo log file.

Enumerator
NORMAL 

Usual redo log file, most likely with important redo data.

UNUSED 

Unused redo log file, might always be removed.

◆ Log_files_ruleset

enum class Log_files_ruleset
strong

Ruleset defining how redo log files are named, where they are stored, when they are created and what sizes could they have.

Enumerator
PRE_8_0_30 

Redo log files were named ib_logfile0, ib_logfile1, ... ib_logfile99.

Redo log files were pre-created during startup and re-used after wrapping. Redo log files had the same file size and supported formats < VERSION_8_0_30. The non-initialized set of redo log files was denoted by existence of the ib_logfile101. The log files were located directly in the root directory (innodb_log_group_home_dir if specified; else: datadir).

CURRENT 

Redo log files are named ib_redo0, ib_redo1, ... and no longer wrapped.

Redo log files are created on-demand during runtime and might have different sizes. Formats >= VERSION_8_0_30 are supported. The redo log files are located in innodb_redo subdirectory in the root directory - for example:

  • if innodb_log_group_home_dir = '/srv/my_db/logs', then redo files are in '/srv/my_db/logs/innodb_redo/',
  • if innodb_log_group_home_dir is not specified and datadir='/srv/my_db', then redo files are in '/srv/my_db/innodb_redo'.

◆ Log_format

enum class Log_format : uint32_t
strong

Supported redo log formats.

Stored in LOG_HEADER_FORMAT.

Enumerator
LEGACY 

Unknown format of redo file.

VERSION_5_7_9 

The MySQL 5.7.9 redo log format identifier.

We can support recovery from this format if the redo log is clean (logically empty).

VERSION_8_0_1 

Remove MLOG_FILE_NAME and MLOG_CHECKPOINT, introduce MLOG_FILE_OPEN redo log record.

VERSION_8_0_3 

Allow checkpoint_lsn to point any data byte within redo log (before it had to point the beginning of a group of log records).

VERSION_8_0_19 

Expand ulint compressed form.

VERSION_8_0_28 

Row versioning header.

VERSION_8_0_30 

Introduced with innodb_redo_log_capacity:

  • write LSN does not re-enter file with checkpoint_lsn,
  • epoch_no is checked strictly during recovery.
CURRENT 

The redo log format identifier corresponding to the current format version.

◆ Log_resize_mode

enum class Log_resize_mode
strong

Direction of resize operation.

Enumerator
NONE 

No pending resize.

RESIZING_DOWN 

Resizing down.