MySQL 9.1.0
Source Code Documentation
mtr0log.cc File Reference

Mini-transaction log routines. More...

#include "mtr0log.h"
#include "buf0buf.h"
#include "buf0dblwr.h"
#include "dict0dict.h"
#include "log0recv.h"
#include "page0page.h"
#include "dict0boot.h"

Classes

struct  Field_instant_info
 

Typedefs

using instant_fields_list_t = std::vector< Field_instant_info >
 

Functions

static const bytemlog_parse_index_v1 (const byte *ptr, const byte *end_ptr, dict_index_t **index)
 Parses a log record written by mlog_open_and_write_index. More...
 
void mlog_catenate_string (mtr_t *mtr, const byte *str, ulint len)
 Catenates n bytes to the mtr log. More...
 
void mlog_write_initial_log_record (const byte *ptr, mlog_id_t type, mtr_t *mtr)
 Writes the initial part of a log record consisting of one-byte item type and four-byte space and page numbers. 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...
 
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...
 
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...
 
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...
 
static void log_index_get_size_needed (const dict_index_t *index, size_t size, uint16_t n, bool is_comp, bool is_versioned, bool is_instant, const bool *fields_with_changed_order, size_t &size_needed)
 Calculate total size needed to log index information. More...
 
static void log_index_log_version (uint8_t version, byte *&log_ptr)
 Log the index log version. More...
 
static void log_index_flag (uint8_t flag, byte *&log_ptr)
 Log the flag. More...
 
static void log_index_column_counts (const dict_index_t *index, uint16_t n, const byte *rec, bool is_comp, bool is_versioned, bool is_instant, byte *&log_ptr)
 Log the number of fields in index. More...
 
static bool close_and_reopen_log (byte *&log_ptr, const byte *&log_start, const byte *&log_end, mtr_t *&mtr, size_t &alloc, size_t &total)
 Close, allocate and reopen LOG pointer buffer. More...
 
template<typename F >
static bool log_index_fields (const dict_index_t *index, uint16_t n, bool is_versioned, std::vector< dict_field_t * > &f, bool *changed_order, byte *&log_ptr, F &func)
 Log index field len info. More...
 
template<typename F >
static bool log_index_versioned_fields (const std::vector< dict_field_t * > &f, byte *&log_ptr, F &func, const dict_index_t *index)
 Log fields with version. 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...
 
static const byteread_2_bytes (const byte *ptr, const byte *end_ptr, uint16_t &val)
 Read 2 bytes from log buffer. More...
 
static const byteread_1_bytes (const byte *ptr, const byte *end_ptr, uint8_t &val)
 Read 1 bytes from log buffer. More...
 
static const byteparse_index_column_counts (const byte *ptr, const byte *end_ptr, bool is_comp, bool is_versioned, bool is_instant, uint16_t &n, uint16_t &n_uniq, uint16_t &inst_cols)
 Read number of columns for index. More...
 
static const byteparse_index_fields (const byte *ptr, const byte *end_ptr, uint16_t n, uint16_t n_uniq, bool is_versioned, dict_index_t *&ind, dict_table_t *&table)
 Parse index fields. More...
 
static const byteparse_index_versioned_fields (const byte *ptr, const byte *end_ptr, instant_fields_list_t &f, uint16_t &crv, size_t &n_dropped)
 Parse the fields with versions. More...
 
static void update_instant_info (instant_fields_list_t f, dict_index_t *index)
 Update the version info for the columns. More...
 
static void populate_dummy_fields (dict_index_t *index, dict_table_t *table, size_t n, bool is_comp)
 To populate dummy fields. More...
 
static const byteparse_index_log_version (const byte *ptr, const byte *end_ptr, uint8_t &version)
 
static const byteparse_index_flag (const byte *ptr, const byte *end_ptr, uint8_t &flag)
 
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...
 

Variables

constexpr size_t inst_col_info_size = 6
 

Detailed Description

Mini-transaction log routines.

Created 12/7/1995 Heikki Tuuri

Typedef Documentation

◆ instant_fields_list_t

Function Documentation

◆ close_and_reopen_log()

static bool close_and_reopen_log ( byte *&  log_ptr,
const byte *&  log_start,
const byte *&  log_end,
mtr_t *&  mtr,
size_t &  alloc,
size_t &  total 
)
static

Close, allocate and reopen LOG pointer buffer.

Parameters
[in]log_ptrpointer to log buffer
[in,out]log_startstart of currently allocated buffer
[in,out]log_endend of currently allocated buffer
[in]mtrmini transaction
[in,out]allocsize allocated as of now on log
[in,out]totaltotal size needed on log

◆ log_index_column_counts()

static void log_index_column_counts ( const dict_index_t index,
uint16_t  n,
const byte rec,
bool  is_comp,
bool  is_versioned,
bool  is_instant,
byte *&  log_ptr 
)
static

Log the number of fields in index.

Parameters
[in]indexindex
[in]nnumber of fields
[in]recindex record
[in]is_comptrue if COMP
[in]is_versionedtrue if table has row versions
[in]is_instanttrue if table has INSTANT cols
[in,out]log_ptrREDO LOG buffer pointer

◆ log_index_fields()

template<typename F >
static bool log_index_fields ( const dict_index_t index,
uint16_t  n,
bool  is_versioned,
std::vector< dict_field_t * > &  f,
bool *  changed_order,
byte *&  log_ptr,
F &  func 
)
static

Log index field len info.

Parameters
[in]indexindex
[in]nnumber of fields
[in]is_versionedtrue if table has row versions
[in,out]fvector of fields with versions
[in]changed_orderarray indicating fields changed position
[in]log_ptrlog buffer pointer
[in]funccallback to check size reopen log buffer

◆ log_index_flag()

static void log_index_flag ( uint8_t  flag,
byte *&  log_ptr 
)
static

Log the flag.

Parameters
[in]flag1 byte flag to be logged
[in,out]log_ptrREDO LOG buffer pointer

◆ log_index_get_size_needed()

static void log_index_get_size_needed ( const dict_index_t index,
size_t  size,
uint16_t  n,
bool  is_comp,
bool  is_versioned,
bool  is_instant,
const bool *  fields_with_changed_order,
size_t &  size_needed 
)
static

Calculate total size needed to log index information.

Parameters
[in]indexindex
[in]sizesize passed from caller
[in]nnumber of fields in index
[in]is_comptrue if COMP
[in]is_versionedif table has row versions
[in]is_instanttrue if table has INSTANT cols
[in]fields_with_changed_orderbitmap to indicate fields with changed order
[out]size_neededtotal size needed on REDO LOG

◆ log_index_log_version()

static void log_index_log_version ( uint8_t  version,
byte *&  log_ptr 
)
static

Log the index log version.

Parameters
[in]version1 byte index log version
[in,out]log_ptrREDO LOG buffer pointer

◆ log_index_versioned_fields()

template<typename F >
static bool log_index_versioned_fields ( const std::vector< dict_field_t * > &  f,
byte *&  log_ptr,
F &  func,
const dict_index_t index 
)
static

Log fields with version.

Parameters
[in]fvector of fields with versions
[in]log_ptrlog buffer pointer
[in]funccallback to check size reopen log buffer
[in]indexindex to fetch field's logical position

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

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

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

static const byte * mlog_parse_index_v1 ( const byte ptr,
const byte end_ptr,
dict_index_t **  index 
)
static

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

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

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

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

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.

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

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

◆ parse_index_column_counts()

static const byte * parse_index_column_counts ( const byte ptr,
const byte end_ptr,
bool  is_comp,
bool  is_versioned,
bool  is_instant,
uint16_t &  n,
uint16_t &  n_uniq,
uint16_t &  inst_cols 
)
static

Read number of columns for index.

Parameters
[in]ptrpointer to buffer
[in]end_ptrpointer to end of buffer
[in]is_comptrue if COMP
[in]is_versionedtrue if table has row versions
[in]is_instanttrue if table has INSTANT cols
[out]nnumber of index fields
[out]n_uniqn_uniq for index
[out]inst_colsnumber of column before first instant add was done.
Returns
pointer to buffer.

◆ parse_index_fields()

static const byte * parse_index_fields ( const byte ptr,
const byte end_ptr,
uint16_t  n,
uint16_t  n_uniq,
bool  is_versioned,
dict_index_t *&  ind,
dict_table_t *&  table 
)
static

Parse index fields.

Parameters
[in]ptrpointer to buffer
[in]end_ptrpointer to end of buffer
[in]nnumber of fields
[in]n_uniqn_uniq
[in]is_versionedtrue if table has row versions
[in,out]inddummy index
[in,out]tabledummy table
Returns
pointer to log buffer

◆ parse_index_flag()

static const byte * parse_index_flag ( const byte ptr,
const byte end_ptr,
uint8_t &  flag 
)
static

◆ parse_index_log_version()

static const byte * parse_index_log_version ( const byte ptr,
const byte end_ptr,
uint8_t &  version 
)
static

◆ parse_index_versioned_fields()

static const byte * parse_index_versioned_fields ( const byte ptr,
const byte end_ptr,
instant_fields_list_t f,
uint16_t &  crv,
size_t &  n_dropped 
)
static

Parse the fields with versions.

Parameters
[in]ptrpointer to buffer
[in]end_ptrpointer to end of buffer
[out]fvector of fields with versions
[out]crvcurrent row version
[out]n_droppednumber of dropped columns

◆ populate_dummy_fields()

static void populate_dummy_fields ( dict_index_t index,
dict_table_t table,
size_t  n,
bool  is_comp 
)
static

To populate dummy fields.

Used only in case of REDUNDANT row format.

Parameters
[in,out]indexdummy index
[in,out]tabledummy table
[in]nnumber of fields
[in]is_comptrue if COMP

◆ read_1_bytes()

static const byte * read_1_bytes ( const byte ptr,
const byte end_ptr,
uint8_t &  val 
)
static

Read 1 bytes from log buffer.

Parameters
[in]ptrpointer to buffer
[in]end_ptrpointer to end of buffer
[out]valread 2 bytes value

◆ read_2_bytes()

static const byte * read_2_bytes ( const byte ptr,
const byte end_ptr,
uint16_t &  val 
)
static

Read 2 bytes from log buffer.

Parameters
[in]ptrpointer to buffer
[in]end_ptrpointer to end of buffer
[out]valread 2 bytes value

◆ update_instant_info()

static void update_instant_info ( instant_fields_list_t  f,
dict_index_t index 
)
static

Update the version info for the columns.

NOTE : fields are logged in their physical order so with the help of phy_pos, it's easy to locate them.

Parameters
[in]ffields with versions
[in,out]indexdummy index

Variable Documentation

◆ inst_col_info_size

constexpr size_t inst_col_info_size = 6
constexpr