MySQL  8.0.19
Source Code Documentation
trx0sys.cc File Reference
#include <sys/types.h>
#include <new>
#include "current_thd.h"
#include "ha_prototypes.h"
#include "sql_error.h"
#include "trx0sys.h"
#include "fsp0fsp.h"
#include "fsp0sysspace.h"
#include "log0log.h"
#include "log0recv.h"
#include "mtr0log.h"
#include "os0file.h"
#include "read0read.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "trx0purge.h"
#include "trx0rseg.h"
#include "trx0trx.h"
#include "trx0undo.h"

Functions

void trx_sys_flush_max_trx_id (void)
 Writes the value of max_trx_id to the file based trx system header. More...
 
void trx_sys_persist_gtid_num (trx_id_t gtid_trx_no)
 Persist transaction number limit below which all transaction GTIDs are persisted to disk table. More...
 
trx_id_t trx_sys_oldest_trx_no ()
 
void trx_sys_get_binlog_prepared (std::vector< trx_id_t > &trx_ids)
 Get a list of all binlog prepared transactions. More...
 
static bool read_binlog_position (const byte *binlog_buf, const char *&file_name, uint32_t &high, uint32_t &low)
 Read binary log positions from buffer passed. More...
 
static void write_binlog_position (const char *file_name, uint64_t offset, byte *binlog_buf, mtr_t *mtr)
 Write binary log position into passed buffer. More...
 
void trx_sys_read_binlog_position (char *file, uint64_t &offset)
 Get current binary log positions stored. More...
 
static bool binlog_position_changed (const char *file_name, uint64_t offset, byte *binlog_buf)
 Check if binary log position is changed. More...
 
bool trx_sys_write_binlog_position (const char *last_file, uint64_t last_offset, const char *file, uint64_t offset)
 Update binary log position if not already updated. More...
 
void trx_sys_update_mysql_binlog_offset (trx_t *trx, mtr_t *mtr)
 Updates the offset information about the end of the MySQL binlog entry which corresponds to the transaction being committed, external XA transaction being prepared or rolled back. More...
 
page_no_t trx_sysf_rseg_find_page_no (ulint rseg_id)
 Find the page number in the TRX_SYS page for a given slot/rseg_id. More...
 
ulint trx_sysf_rseg_find_free (mtr_t *mtr)
 Look for a free slot for a rollback segment in the trx system file copy. More...
 
static void trx_sysf_create (mtr_t *mtr)
 Creates the file page for the transaction system. More...
 
purge_pq_ttrx_sys_init_at_db_start (void)
 Creates and initializes the central memory structures for the transaction system. More...
 
void trx_sys_create (void)
 Creates the trx_sys instance and initializes purge_queue and mutex. More...
 
void trx_sys_create_sys_pages (void)
 Creates and initializes the transaction system at the database creation. More...
 
void trx_sys_close (void)
 Shutdown/Close the transaction system. More...
 
static void trx_undo_fake_prepared (const trx_t *trx, trx_undo_t *undo)
 Convert an undo log to TRX_UNDO_PREPARED state on shutdown. More...
 
ulint trx_sys_any_active_transactions (void)
 
static bool trx_sys_validate_trx_list_low (trx_ut_list_t *trx_list)
 Validate the trx_ut_list_t. More...
 
bool trx_sys_validate_trx_list ()
 Validate the trx_sys_t::rw_trx_list. More...
 
void trx_sys_undo_spaces_init ()
 Initialize trx_sys_undo_spaces, called once during srv_start(). More...
 
void trx_sys_undo_spaces_deinit ()
 Free the resources occupied by trx_sys_undo_spaces, called once during thread de-initialization. More...
 

Variables

trx_sys_ttrx_sys = NULL
 The transaction system. More...
 
uint trx_rseg_n_slots_debug = 0
 
Space_Idstrx_sys_undo_spaces
 A list of undo tablespace IDs found in the TRX_SYS page. More...
 

Detailed Description

Transaction system

Created 3/26/1996 Heikki Tuuri

Function Documentation

◆ binlog_position_changed()

static bool binlog_position_changed ( const char *  file_name,
uint64_t  offset,
byte binlog_buf 
)
static

Check if binary log position is changed.

Parameters
[in]file_nameprevious binary log file name
[in]offsetprevious binary log file offset
[out]binlog_bufbuffer from trx sys page to write to
Returns
true, iff binary log position is modified from previous position.

◆ read_binlog_position()

static bool read_binlog_position ( const byte binlog_buf,
const char *&  file_name,
uint32_t &  high,
uint32_t &  low 
)
static

Read binary log positions from buffer passed.

Parameters
[in]binlog_bufbinary log buffer from trx sys page
[out]file_namebinary log file name
[out]highoffset part high order bytes
[out]lowoffset part low order bytes
Returns
true, if buffer has valid binary log position.

◆ trx_sys_any_active_transactions()

ulint trx_sys_any_active_transactions ( void  )

◆ trx_sys_close()

void trx_sys_close ( void  )

Shutdown/Close the transaction system.

◆ trx_sys_create()

void trx_sys_create ( void  )

Creates the trx_sys instance and initializes purge_queue and mutex.

◆ trx_sys_create_sys_pages()

void trx_sys_create_sys_pages ( void  )

Creates and initializes the transaction system at the database creation.

◆ trx_sys_flush_max_trx_id()

void trx_sys_flush_max_trx_id ( void  )

Writes the value of max_trx_id to the file based trx system header.

◆ trx_sys_get_binlog_prepared()

void trx_sys_get_binlog_prepared ( std::vector< trx_id_t > &  trx_ids)

Get a list of all binlog prepared transactions.

Parameters
[out]trx_idsall prepared transaction IDs.

◆ trx_sys_init_at_db_start()

purge_pq_t* trx_sys_init_at_db_start ( void  )

Creates and initializes the central memory structures for the transaction system.

This is called when the database is started.

Returns
min binary heap of rsegs to purge

◆ trx_sys_oldest_trx_no()

trx_id_t trx_sys_oldest_trx_no ( )
Returns
oldest transaction number yet to be committed.

◆ trx_sys_persist_gtid_num()

void trx_sys_persist_gtid_num ( trx_id_t  gtid_trx_no)

Persist transaction number limit below which all transaction GTIDs are persisted to disk table.

Parameters
[in]gtid_trx_notransaction number

◆ trx_sys_read_binlog_position()

void trx_sys_read_binlog_position ( char *  file,
uint64_t &  offset 
)

Get current binary log positions stored.

Parameters
[out]filebinary log file name
[out]offsetbinary log file offset

◆ trx_sys_undo_spaces_deinit()

void trx_sys_undo_spaces_deinit ( )

Free the resources occupied by trx_sys_undo_spaces, called once during thread de-initialization.

◆ trx_sys_undo_spaces_init()

void trx_sys_undo_spaces_init ( )

Initialize trx_sys_undo_spaces, called once during srv_start().

◆ trx_sys_update_mysql_binlog_offset()

void trx_sys_update_mysql_binlog_offset ( trx_t trx,
mtr_t mtr 
)

Updates the offset information about the end of the MySQL binlog entry which corresponds to the transaction being committed, external XA transaction being prepared or rolled back.

In a MySQL replication slave updates the latest master binlog position up to which replication has proceeded.

Parameters
[in]trxcurrent transaction
[in,out]mtrmini transaction for update

◆ trx_sys_validate_trx_list()

bool trx_sys_validate_trx_list ( )

Validate the trx_sys_t::rw_trx_list.

Returns
true if the list is valid.

◆ trx_sys_validate_trx_list_low()

static bool trx_sys_validate_trx_list_low ( trx_ut_list_t *  trx_list)
static

Validate the trx_ut_list_t.

Returns
true if valid.
Parameters
trx_listin: &trx_sys->rw_trx_list

◆ trx_sys_write_binlog_position()

bool trx_sys_write_binlog_position ( const char *  last_file,
uint64_t  last_offset,
const char *  file,
uint64_t  offset 
)

Update binary log position if not already updated.

This is called by clone to update any stale binary log position if any transaction is yet to update the binary log position in SE.

Parameters
[in]last_filelast noted binary log file name
[in]last_offsetlast noted binary log offset
[in]filecurrent binary log file name
[in]offsetcurrent binary log file offset
Returns
true, if binary log position is updated with current.

◆ trx_sysf_create()

static void trx_sysf_create ( mtr_t mtr)
static

Creates the file page for the transaction system.

This function is called only at the database creation, before trx_sys_init.

Parameters
mtrin: mtr

◆ trx_sysf_rseg_find_free()

ulint trx_sysf_rseg_find_free ( mtr_t mtr)

Look for a free slot for a rollback segment in the trx system file copy.

Parameters
[in,out]mtrmtr
Returns
slot index or ULINT_UNDEFINED if not found

◆ trx_sysf_rseg_find_page_no()

page_no_t trx_sysf_rseg_find_page_no ( ulint  rseg_id)

Find the page number in the TRX_SYS page for a given slot/rseg_id.

Parameters
[in]rseg_idslot number in the TRX_SYS page rseg array
Returns
page number from the TRX_SYS page rseg array

◆ trx_undo_fake_prepared()

static void trx_undo_fake_prepared ( const trx_t trx,
trx_undo_t undo 
)
static

Convert an undo log to TRX_UNDO_PREPARED state on shutdown.

If any prepared ACTIVE transactions exist, and their rollback was prevented by innodb_force_recovery, we convert these transactions to XA PREPARE state in the main-memory data structures, so that shutdown will proceed normally. These transactions will again recover as ACTIVE on the next restart, and they will be rolled back unless innodb_force_recovery prevents it again.

Parameters
[in]trxtransaction
[in,out]undoundo log to convert to TRX_UNDO_PREPARED

◆ write_binlog_position()

static void write_binlog_position ( const char *  file_name,
uint64_t  offset,
byte binlog_buf,
mtr_t mtr 
)
static

Write binary log position into passed buffer.

Parameters
[in]file_namebinary log file name
[in]offsetbinary log offset
[out]binlog_bufbuffer from trx sys page to write to
[in,out]mtrmini transaction

Variable Documentation

◆ trx_rseg_n_slots_debug

uint trx_rseg_n_slots_debug = 0

◆ trx_sys

trx_sys_t* trx_sys = NULL

The transaction system.

◆ trx_sys_undo_spaces

Space_Ids* trx_sys_undo_spaces

A list of undo tablespace IDs found in the TRX_SYS page.

These are the old type of undo tablespaces that do not have space_IDs in the reserved range nor contain an RSEG_ARRAY page. This cannot be part of the trx_sys_t object because it must be built before that is initialized.