MySQL 8.0.40
Source Code Documentation
trx0sys.cc File Reference

Transaction system. More...

#include <sys/types.h>
#include <new>
#include "current_thd.h"
#include "ha_prototypes.h"
#include "mysql/plugin.h"
#include "sql_error.h"
#include "trx0sys.h"
#include "fsp0fsp.h"
#include "fsp0sysspace.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_write_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...
 
void trx_sys_before_pre_dd_shutdown_validate ()
 Validates lists of transactions at the very beginning of the pre-dd-shutdown phase. More...
 
void trx_sys_after_pre_dd_shutdown_validate ()
 Validates lists of transactions at the very end of the pre-dd-shutdown phase. More...
 
void trx_sys_after_background_threads_shutdown_validate ()
 Validates lists of transactions after all background threads of InnoDB exited during shutdown of MySQL. More...
 
size_t trx_sys_recovered_active_trxs_count ()
 Reads number of recovered transactions which have state equal to TRX_STATE_ACTIVE (so are not prepared transactions). 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 = nullptr
 The transaction system. More...
 
uint trx_rseg_n_slots_debug = 0
 
const uint32_t max_rseg_init_threads = 4
 
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_after_background_threads_shutdown_validate()

void trx_sys_after_background_threads_shutdown_validate ( )

Validates lists of transactions after all background threads of InnoDB exited during shutdown of MySQL.

◆ trx_sys_after_pre_dd_shutdown_validate()

void trx_sys_after_pre_dd_shutdown_validate ( )

Validates lists of transactions at the very end of the pre-dd-shutdown phase.

At this point we check the mysql_trx_list again, now we don't expect purge thread transactions in the list

◆ trx_sys_before_pre_dd_shutdown_validate()

void trx_sys_before_pre_dd_shutdown_validate ( )

Validates lists of transactions at the very beginning of the pre-dd-shutdown phase.

All connections are closed and close_connection unregisters associated trx from mysql_trx_list. We still might have some non started transactions in mysql_trx_list. Purge threads are an exception, they create their own trx_t objects which are not real transactions but are needed for the purge sys to use the query threads framework. Purge sys shutdown happens at a later point in the shutdown sequence so we need to skip its transactions here. IMPORTANT: If allocating transactions for background threads, please use trx_allocate_for_background. This function does not add the trx to the mysql_trx_list so we don't have to add logic to skip these at shutdown.

Skip purge thread trx, it will be cleared after purge sys shutdown

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

size_t trx_sys_recovered_active_trxs_count ( )

Reads number of recovered transactions which have state equal to TRX_STATE_ACTIVE (so are not prepared transactions).

Returns
number of active recovered transactions

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

void trx_sys_write_max_trx_id ( void  )

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

◆ 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

◆ 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

◆ max_rseg_init_threads

const uint32_t max_rseg_init_threads = 4

◆ trx_rseg_n_slots_debug

uint trx_rseg_n_slots_debug = 0

◆ trx_sys

trx_sys_t* trx_sys = nullptr

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.