MySQL 9.1.0
Source Code Documentation
mtr0log.h File Reference

Mini-transaction logging routines. More...

#include "dyn0buf.h"
#include "mtr0mtr.h"
#include "univ.i"
#include "mtr0log.ic"

Go to the source code of this file.

Macros

#define COMPACT_FLAG   0x01
 
#define VERSION_FLAG   0x02
 
#define INSTANT_FLAG   0x04
 
#define IS_INSTANT(flags)   (flags & INSTANT_FLAG)
 
#define IS_VERSIONED(flags)   (flags & VERSION_FLAG)
 
#define IS_COMPACT(flags)   (flags & COMPACT_FLAG)
 
#define SET_INSTANT(flags)   (flag |= INSTANT_FLAG)
 
#define SET_VERSIONED(flags)   (flag |= VERSION_FLAG)
 
#define SET_COMPACT(flags)   (flag |= COMPACT_FLAG)
 

Functions

void mlog_write_ulint (byte *ptr, ulint val, mlog_id_t type, mtr_t *mtr)
 Writes 1, 2 or 4 bytes to a file page. More...
 
void mlog_write_ull (byte *ptr, uint64_t val, mtr_t *mtr)
 Writes 8 bytes to a file page. More...
 
void mlog_write_string (byte *ptr, const byte *str, ulint len, mtr_t *mtr)
 Writes a string to a file page buffered in the buffer pool. More...
 
void mlog_log_string (byte *ptr, ulint len, mtr_t *mtr)
 Logs a write of a string to a file page buffered in the buffer pool. More...
 
void mlog_write_initial_log_record (const byte *ptr, mlog_id_t type, mtr_t *mtr)
 Writes initial part of a log record consisting of one-byte item type and four-byte space and page numbers. More...
 
static void mlog_catenate_ulint (mtr_buf_t *dyn_buf, ulint val, mlog_id_t type)
 Catenates 1 - 4 bytes to the mtr log. More...
 
static void mlog_catenate_ulint (mtr_t *mtr, ulint val, mlog_id_t type)
 Catenates 1 - 4 bytes to the mtr log. More...
 
void mlog_catenate_string (mtr_t *mtr, const byte *str, ulint len)
 Catenates n bytes to the mtr log. More...
 
static void mlog_catenate_ulint_compressed (mtr_t *mtr, ulint val)
 Catenates a compressed ulint to mlog. More...
 
static void mlog_catenate_ull_compressed (mtr_t *mtr, uint64_t val)
 Catenates a compressed 64-bit integer to mlog. More...
 
static bool mlog_open (mtr_t *mtr, ulint size, byte *&buffer)
 Opens a buffer to mlog. More...
 
static bool mlog_open_metadata (mtr_t *mtr, ulint size, byte *&buffer)
 Opens a buffer to mlog. More...
 
static void mlog_close (mtr_t *mtr, byte *ptr)
 Closes a buffer opened to mlog. More...
 
static bytemlog_write_initial_dict_log_record (mlog_id_t type, table_id_t id, uint64_t version, byte *log_ptr, mtr_t *mtr)
 Writes a log record about a dictionary operation, which would cost at most 23 bytes. More...
 
static bytemlog_write_initial_log_record_low (mlog_id_t type, space_id_t space_id, page_no_t page_no, byte *log_ptr, mtr_t *mtr)
 Writes a log record about an operation. More...
 
static bytemlog_write_initial_log_record_fast (const byte *ptr, mlog_id_t type, byte *log_ptr, mtr_t *mtr)
 Writes the initial part of a log record (3..11 bytes). More...
 
const bytemlog_parse_initial_dict_log_record (const byte *ptr, const byte *end_ptr, mlog_id_t *type, table_id_t *id, uint64_t *version)
 Parses an initial log record written by mlog_write_initial_dict_log_record. More...
 
const bytemlog_parse_initial_log_record (const byte *ptr, const byte *end_ptr, mlog_id_t *type, space_id_t *space, page_no_t *page_no)
 Parses an initial log record written by mlog_write_initial_log_record. More...
 
const bytemlog_parse_nbytes (mlog_id_t type, const byte *ptr, const byte *end_ptr, byte *page, void *page_zip)
 Parses a log record written by mlog_write_ulint or mlog_write_ull. More...
 
const bytemlog_parse_string (const byte *ptr, const byte *end_ptr, byte *page, void *page_zip)
 Parses a log record written by mlog_write_string. More...
 
bool mlog_open_and_write_index (mtr_t *mtr, const byte *rec, const dict_index_t *index, mlog_id_t type, size_t size, byte *&log_ptr)
 Opens a buffer for mlog, writes the initial log record and, if needed, the field lengths of an index. More...
 
const bytemlog_parse_index (const byte *ptr, const byte *end_ptr, dict_index_t **index)
 Parses a log record written by mlog_open_and_write_index. More...
 
const bytemlog_parse_index_8027 (const byte *ptr, const byte *end_ptr, bool comp, dict_index_t **index)
 Parses a log record written by mlog_open_and_write_index in version <= 8027. More...
 

Variables

constexpr uint8_t INDEX_LOG_VERSION_0 = 0
 
constexpr uint8_t INDEX_LOG_VERSION_CURRENT = 1
 
constexpr uint8_t INDEX_LOG_VERSION_MAX = INDEX_LOG_VERSION_CURRENT
 
constexpr size_t REDO_LOG_INITIAL_INFO_SIZE = 11
 
constexpr auto MLOG_BUF_MARGIN = 256
 Insert, update, and maybe other functions may use this value to define an extra mlog buffer size for variable size data. More...
 

Detailed Description

Mini-transaction logging routines.

Created 12/7/1995 Heikki Tuuri

Macro Definition Documentation

◆ COMPACT_FLAG

#define COMPACT_FLAG   0x01

◆ INSTANT_FLAG

#define INSTANT_FLAG   0x04

◆ IS_COMPACT

#define IS_COMPACT (   flags)    (flags & COMPACT_FLAG)

◆ IS_INSTANT

#define IS_INSTANT (   flags)    (flags & INSTANT_FLAG)

◆ IS_VERSIONED

#define IS_VERSIONED (   flags)    (flags & VERSION_FLAG)

◆ SET_COMPACT

#define SET_COMPACT (   flags)    (flag |= COMPACT_FLAG)

◆ SET_INSTANT

#define SET_INSTANT (   flags)    (flag |= INSTANT_FLAG)

◆ SET_VERSIONED

#define SET_VERSIONED (   flags)    (flag |= VERSION_FLAG)

◆ VERSION_FLAG

#define VERSION_FLAG   0x02

Function Documentation

◆ mlog_catenate_string()

void mlog_catenate_string ( mtr_t mtr,
const byte str,
ulint  len 
)

Catenates n bytes to the mtr log.

Parameters
[in]mtrMini-transaction
[in]strString to write
[in]lenString length

◆ mlog_catenate_ulint() [1/2]

static void mlog_catenate_ulint ( mtr_buf_t dyn_buf,
ulint  val,
mlog_id_t  type 
)
inlinestatic

Catenates 1 - 4 bytes to the mtr log.

The value is not compressed.

Parameters
[in,out]dyn_bufbuffer to write
[in]valvalue to write
[in]typetype of value to write

◆ mlog_catenate_ulint() [2/2]

static void mlog_catenate_ulint ( mtr_t mtr,
ulint  val,
mlog_id_t  type 
)
inlinestatic

Catenates 1 - 4 bytes to the mtr log.

Parameters
[in]mtrmtr
[in]valvalue to write
[in]typeMLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES

◆ mlog_catenate_ulint_compressed()

static void mlog_catenate_ulint_compressed ( mtr_t mtr,
ulint  val 
)
inlinestatic

Catenates a compressed ulint to mlog.

Parameters
[in]mtrmtr
[in]valvalue to write

◆ mlog_catenate_ull_compressed()

static void mlog_catenate_ull_compressed ( mtr_t mtr,
uint64_t  val 
)
inlinestatic

Catenates a compressed 64-bit integer to mlog.

Parameters
[in]mtrmtr
[in]valvalue to write

◆ mlog_close()

static void mlog_close ( mtr_t mtr,
byte ptr 
)
inlinestatic

Closes a buffer opened to mlog.

Parameters
[in]mtrmtr
[in]ptrbuffer space from ptr up was not used

◆ mlog_log_string()

void mlog_log_string ( byte ptr,
ulint  len,
mtr_t mtr 
)

Logs a write of a string to a file page buffered in the buffer pool.

Writes the corresponding log record to the mini-transaction log. in: mini-transaction handle

Writes the corresponding log record to the mini-transaction log.

Parameters
ptrin: pointer written to
lenin: string length
mtrin: mini-transaction handle

◆ mlog_open()

static bool mlog_open ( mtr_t mtr,
ulint  size,
byte *&  buffer 
)
inlinestatic

Opens a buffer to mlog.

It must be closed with mlog_close.

Parameters
[in,out]mtrmtr
[in]sizebuffer size in bytes; MUST be smaller than DYN_ARRAY_DATA_SIZE!
[out]buffermlog buffer pointer if opened successfully
Return values
trueif opened successfully.
falseif not opened. One case is when redo is disabled for mtr.

◆ mlog_open_and_write_index()

bool mlog_open_and_write_index ( mtr_t mtr,
const byte rec,
const dict_index_t index,
mlog_id_t  type,
size_t  size,
byte *&  log_ptr 
)

Opens a buffer for mlog, writes the initial log record and, if needed, the field lengths of an index.

Reserves space for further log entries. The log entry must be closed with mtr_close().

Parameters
[in,out]mtrMini-transaction
[in]recIndex record or page
[in]indexRecord descriptor
[in]typeLog item type
[in]sizeRequested buffer size in bytes. if 0, calls mlog_close() and returns false.
[out]log_ptrLog buffer pointer
Return values
trueif opened successfully.
falseif not opened. One case is when redo is disabled for mtr.

◆ mlog_open_metadata()

static bool mlog_open_metadata ( mtr_t mtr,
ulint  size,
byte *&  buffer 
)
inlinestatic

Opens a buffer to mlog.

It must be closed with mlog_close. This is used for writing log for metadata changes

Parameters
[in,out]mtrmtr
[in]sizebuffer size in bytes; MUST be smaller than DYN_ARRAY_DATA_SIZE!
[out]buffermlog buffer pointer if opened successfully
Return values
trueif opened successfully.
falseif not opened. One case is when redo is disabled for mtr.

◆ mlog_parse_index()

const byte * mlog_parse_index ( const byte ptr,
const byte end_ptr,
dict_index_t **  index 
)

Parses a log record written by mlog_open_and_write_index.

Parameters
[in]ptrbuffer
[in]end_ptrbuffer end
[out]indexown: dummy index
Returns
parsed record end, NULL if not a complete record

◆ mlog_parse_index_8027()

const byte * mlog_parse_index_8027 ( const byte ptr,
const byte end_ptr,
bool  comp,
dict_index_t **  index 
)

Parses a log record written by mlog_open_and_write_index in version <= 8027.

This function should never be changed and should be removed once recovery from mysql-8.0.27 is not needed anymore.

Parameters
[in]ptrbuffer
[in]end_ptrbuffer end
[in]comptrue=compact row format
[out]indexown: dummy index
Returns
parsed record end, NULL if not a complete record

◆ mlog_parse_initial_dict_log_record()

const byte * mlog_parse_initial_dict_log_record ( const byte ptr,
const byte end_ptr,
mlog_id_t type,
table_id_t id,
uint64_t *  version 
)

Parses an initial log record written by mlog_write_initial_dict_log_record.

Parameters
[in]ptrbuffer
[in]end_ptrbuffer end
[out]typelog record type, should be MLOG_TABLE_DYNAMIC_META
[out]idtable id
[out]versiontable dynamic metadata version
Returns
parsed record end, NULL if not a complete record

◆ mlog_parse_initial_log_record()

const byte * mlog_parse_initial_log_record ( const byte ptr,
const byte end_ptr,
mlog_id_t type,
space_id_t space,
page_no_t page_no 
)

Parses an initial log record written by mlog_write_initial_log_record.

Returns
parsed record end, NULL if not a complete record out: page number
parsed record end, NULL if not a complete record
Parameters
ptrin: buffer
end_ptrin: buffer end
typeout: log record type: MLOG_1BYTE, ...
spaceout: space id
page_noout: page number

◆ mlog_parse_nbytes()

const byte * mlog_parse_nbytes ( mlog_id_t  type,
const byte ptr,
const byte end_ptr,
byte page,
void *  page_zip 
)

Parses a log record written by mlog_write_ulint or mlog_write_ull.

Returns
parsed record end, NULL if not a complete record in/out: compressed page, or NULL
parsed record end, NULL if not a complete record or a corrupt record
Parameters
typein: log record type: MLOG_1BYTE, ...
ptrin: buffer
end_ptrin: buffer end
pagein: page where to apply the log record, or NULL
page_zipin/out: compressed page, or NULL

◆ mlog_parse_string()

const byte * mlog_parse_string ( const byte ptr,
const byte end_ptr,
byte page,
void *  page_zip 
)

Parses a log record written by mlog_write_string.

Returns
parsed record end, NULL if not a complete record in/out: compressed page, or NULL
parsed record end, NULL if not a complete record
Parameters
ptrin: buffer
end_ptrin: buffer end
pagein: page where to apply the log record, or NULL
page_zipin/out: compressed page, or NULL

◆ mlog_write_initial_dict_log_record()

static byte * mlog_write_initial_dict_log_record ( mlog_id_t  type,
table_id_t  id,
uint64_t  version,
byte log_ptr,
mtr_t mtr 
)
inlinestatic

Writes a log record about a dictionary operation, which would cost at most 23 bytes.

Parameters
[in]typeRedo log record type
[in]idTable id
[in]versionTable dynamic metadata version
[in,out]log_ptrCurrent end of mini-transaction log
[in,out]mtrMini-transaction
Returns
end of mini-transaction log

◆ mlog_write_initial_log_record()

void mlog_write_initial_log_record ( const byte ptr,
mlog_id_t  type,
mtr_t mtr 
)

Writes initial part of a log record consisting of one-byte item type and four-byte space and page numbers.

in: mini-transaction handle

Writes initial part of a log record consisting of one-byte item type and four-byte space and page numbers.

Also pushes info to the mtr memo that a buffer page has been modified.

Parameters
ptrin: pointer to (inside) a buffer frame holding the file page where modification is made
typein: log item type: MLOG_1BYTE, ...
mtrin: mini-transaction handle

◆ mlog_write_initial_log_record_fast()

static byte * mlog_write_initial_log_record_fast ( const byte ptr,
mlog_id_t  type,
byte log_ptr,
mtr_t mtr 
)
inlinestatic

Writes the initial part of a log record (3..11 bytes).

If the implementation of this function is changed, all size parameters to mlog_open() should be adjusted accordingly!

Parameters
[in]ptrpointer to (inside) a buffer frame holding the file page where modification is made
[in]typelog item type: MLOG_1BYTE, ...
[in]log_ptrpointer to mtr log which has been opened
[in]mtrmtr
Returns
new value of log_ptr

◆ mlog_write_initial_log_record_low()

static byte * mlog_write_initial_log_record_low ( mlog_id_t  type,
space_id_t  space_id,
page_no_t  page_no,
byte log_ptr,
mtr_t mtr 
)
inlinestatic

Writes a log record about an operation.

Parameters
[in]typeRedo log record type
[in]space_idTablespace identifier
[in]page_noPage number
[in,out]log_ptrCurrent end of mini-transaction log
[in,out]mtrMini-transaction
Returns
end of mini-transaction log

◆ mlog_write_string()

void mlog_write_string ( byte ptr,
const byte str,
ulint  len,
mtr_t mtr 
)

Writes a string to a file page buffered in the buffer pool.

Writes the corresponding log record to the mini-transaction log. in: mini-transaction handle

Writes the corresponding log record to the mini-transaction log.

Parameters
ptrin: pointer where to write
strin: string to write
lenin: string length
mtrin: mini-transaction handle

◆ mlog_write_ulint()

void mlog_write_ulint ( byte ptr,
ulint  val,
mlog_id_t  type,
mtr_t mtr 
)

Writes 1, 2 or 4 bytes to a file page.

Writes the corresponding log record to the mini-transaction log if mtr is not NULL. in: mini-transaction handle

Writes the corresponding log record to the mini-transaction log if mtr is not NULL.

Parameters
ptrin: pointer where to write
valin: value to write
typein: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES
mtrin: mini-transaction handle

◆ mlog_write_ull()

void mlog_write_ull ( byte ptr,
uint64_t  val,
mtr_t mtr 
)

Writes 8 bytes to a file page.

Writes the corresponding log record to the mini-transaction log, only if mtr is not NULL in: mini-transaction handle

Writes the corresponding log record to the mini-transaction log, only if mtr is not NULL

Parameters
ptrin: pointer where to write
valin: value to write
mtrin: mini-transaction handle

Variable Documentation

◆ INDEX_LOG_VERSION_0

constexpr uint8_t INDEX_LOG_VERSION_0 = 0
constexpr

◆ INDEX_LOG_VERSION_CURRENT

constexpr uint8_t INDEX_LOG_VERSION_CURRENT = 1
constexpr

◆ INDEX_LOG_VERSION_MAX

constexpr uint8_t INDEX_LOG_VERSION_MAX = INDEX_LOG_VERSION_CURRENT
constexpr

◆ MLOG_BUF_MARGIN

constexpr auto MLOG_BUF_MARGIN = 256
constexpr

Insert, update, and maybe other functions may use this value to define an extra mlog buffer size for variable size data.

◆ REDO_LOG_INITIAL_INFO_SIZE

constexpr size_t REDO_LOG_INITIAL_INFO_SIZE = 11
constexpr