MySQL 8.0.40
Source Code Documentation
|
Transaction system. More...
#include "univ.i"
#include "buf0buf.h"
#include "fil0fil.h"
#include "trx0types.h"
#include "mem0mem.h"
#include "mtr0mtr.h"
#include "page0types.h"
#include "ut0byte.h"
#include "ut0class_life_cycle.h"
#include "ut0guarded.h"
#include "ut0lst.h"
#include "ut0mutex.h"
#include <atomic>
#include <unordered_map>
#include <vector>
#include "trx0trx.h"
#include "trx0sys.ic"
Go to the source code of this file.
Classes | |
class | Space_Ids |
List of undo tablespace IDs. More... | |
class | Trx_by_id_with_min |
struct | Trx_by_id_with_min::Trx_track_hash |
struct | Trx_shard |
Shard for subset of transactions. More... | |
struct | trx_sys_t |
The transaction system central memory data structure. More... | |
Macros | |
#define | TRX_SYS_MYSQL_LOG_INFO (UNIV_PAGE_SIZE - 1000) |
The offset of the MySQL binlog offset info in the trx system header. More... | |
#define | TRX_SYS_TRX_NUM_GTID (TRX_SYS_MYSQL_LOG_INFO + TRX_SYS_MYSQL_LOG_NAME + TRX_SYS_MYSQL_LOG_NAME_LEN) |
Reserve next 8 bytes for transaction number up to which GTIDs are persisted to table. More... | |
#define | TRX_SYS_TRX_NUM_END (TRX_SYS_TRX_NUM_GTID + 8) |
Functions | |
static bool | trx_sys_hdr_page (const page_id_t &page_id) |
Checks if a page address is the trx sys header page. More... | |
purge_pq_t * | trx_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... | |
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 trx_sysf_t * | trx_sysf_get (mtr_t *mtr) |
Gets a pointer to the transaction system file copy and x-locks its page. More... | |
static space_id_t | trx_sysf_rseg_get_space (trx_sysf_t *sys_header, ulint i, mtr_t *mtr) |
Gets the space of the nth rollback segment slot in the trx system file copy. More... | |
static page_no_t | trx_sysf_rseg_get_page_no (trx_sysf_t *sys_header, ulint i, mtr_t *mtr) |
Gets the page number of the nth rollback segment slot in the trx system file copy. More... | |
static void | trx_sysf_rseg_set_space (trx_sysf_t *sys_header, ulint i, space_id_t space, mtr_t *mtr) |
Sets the space id of the nth rollback segment slot in the trx system file copy. More... | |
static void | trx_sysf_rseg_set_page_no (trx_sysf_t *sys_header, ulint i, page_no_t page_no, mtr_t *mtr) |
Set the page number of the nth rollback segment slot in the trx system file copy. More... | |
trx_id_t | trx_sys_allocate_trx_id () |
Allocates a new transaction id (for trx->id). More... | |
trx_id_t | trx_sys_allocate_trx_no () |
Allocates a new transaction number (for trx->no). More... | |
trx_id_t | trx_sys_get_next_trx_id_or_no () |
Retrieves a next value that will be allocated if trx_sys_allocate_trx_id() or trx_sys_allocate_trx_id_trx_no() was called. More... | |
static void | trx_write_trx_id (byte *ptr, trx_id_t id) |
Writes a trx id to an index page. More... | |
static trx_id_t | trx_read_trx_id (const byte *ptr) |
Reads a trx id from an index page. More... | |
static trx_t * | trx_rw_is_active (trx_id_t trx_id, bool do_ref_count) |
Checks if a rw transaction with the given id is active. 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... | |
void | trx_sys_read_binlog_position (char *file, uint64_t &offset) |
Get current binary log positions stored. 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... | |
void | trx_sys_close (void) |
Shutdown/Close the transaction system. More... | |
static bool | trx_sys_need_rollback () |
Determine if there are incomplete transactions in the system. 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... | |
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... | |
static void | trx_sys_rw_trx_add (trx_t *trx) |
Add the transaction to the RW transaction set. 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... | |
size_t | trx_get_shard_no (trx_id_t trx_id) |
Computes shard number for a given trx_id. More... | |
static void | trx_sys_mutex_enter () |
Acquire the trx_sys->mutex. More... | |
static void | trx_sys_mutex_exit () |
Release the trx_sys->mutex. More... | |
static bool | trx_sys_mutex_own () |
Test if trx_sys->mutex is owned. More... | |
static bool | trx_sys_serialisation_mutex_own () |
Test if trx_sys->serialisation_mutex is owned. More... | |
static void | trx_sys_serialisation_mutex_enter () |
Acquire the trx_sys->serialisation_mutex. More... | |
static void | trx_sys_serialisation_mutex_exit () |
Release the trx_sys->serialisation_mutex. More... | |
Variables | |
trx_sys_t * | trx_sys |
The transaction system. More... | |
uint | trx_rseg_n_slots_debug |
constexpr uint32_t | TRX_SYS_SYSTEM_RSEG_ID = 0 |
The automatically created system rollback segment has this id. More... | |
constexpr uint32_t | TRX_SYS = FSEG_PAGE_DATA |
The offset of the transaction system header on the page. More... | |
constexpr uint32_t | TRX_SYS_TRX_ID_STORE = 0 |
Transaction system header. More... | |
constexpr uint32_t | TRX_SYS_FSEG_HEADER = 8 |
segment header for the tablespace segment the trx system is created into More... | |
constexpr uint32_t | TRX_SYS_RSEGS = 8 + FSEG_HEADER_SIZE |
the start of the array of rollback segment specification slots More... | |
constexpr size_t | TRX_SYS_OLD_N_RSEGS = 256 |
constexpr size_t | TRX_SYS_OLD_TMP_RSEGS = 32 |
constexpr uint32_t | TRX_SYS_MYSQL_LOG_NAME_LEN = 512 |
Maximum length of MySQL binlog file name, in bytes. More... | |
constexpr uint32_t | TRX_SYS_MYSQL_LOG_MAGIC_N = 873422344 |
Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD. More... | |
constexpr uint32_t | TRX_SYS_MYSQL_LOG_MAGIC_N_FLD = 0 |
magic number which is TRX_SYS_MYSQL_LOG_MAGIC_N if we have valid data in the MySQL binlog info More... | |
constexpr uint32_t | TRX_SYS_MYSQL_LOG_OFFSET_HIGH = 4 |
high 4 bytes of the offset within that file More... | |
constexpr uint32_t | TRX_SYS_MYSQL_LOG_OFFSET_LOW = 8 |
low 4 bytes of the offset within that file More... | |
constexpr uint32_t | TRX_SYS_MYSQL_LOG_NAME = 12 |
MySQL log file name. More... | |
constexpr size_t | TRX_SHARDS_N = 256 |
Number of shards created for transactions. More... | |
Space_Ids * | trx_sys_undo_spaces |
A list of undo tablespace IDs found in the TRX_SYS page. More... | |
constexpr trx_id_t | TRX_SYS_TRX_ID_WRITE_MARGIN = 256 |
When a trx id which is zero modulo this number (which must be a power of two) is assigned, the field TRX_SYS_TRX_ID_STORE on the transaction system page is updated. More... | |
#define | TRX_SYS_DOUBLEWRITE (UNIV_PAGE_SIZE - 200) |
Doublewrite buffer. More... | |
#define | TRX_SYS_DOUBLEWRITE_BLOCK_SIZE FSP_EXTENT_SIZE |
Size of the doublewrite block in pages. More... | |
constexpr uint32_t | TRX_SYS_DOUBLEWRITE_FSEG = 0 |
fseg header of the fseg containing the doublewrite buffer More... | |
constexpr uint32_t | TRX_SYS_DOUBLEWRITE_MAGIC = FSEG_HEADER_SIZE |
4-byte magic number which shows if we already have created the doublewrite buffer More... | |
constexpr uint32_t | TRX_SYS_DOUBLEWRITE_BLOCK1 = 4 + FSEG_HEADER_SIZE |
page number of the first page in the first sequence of 64 (= FSP_EXTENT_SIZE) consecutive pages in the doublewrite buffer More... | |
constexpr uint32_t | TRX_SYS_DOUBLEWRITE_BLOCK2 = 8 + FSEG_HEADER_SIZE |
page number of the first page in the second sequence of 64 consecutive pages in the doublewrite buffer More... | |
constexpr uint32_t | TRX_SYS_DOUBLEWRITE_REPEAT = 12 |
we repeat TRX_SYS_DOUBLEWRITE_MAGIC, TRX_SYS_DOUBLEWRITE_BLOCK1, TRX_SYS_DOUBLEWRITE_BLOCK2 so that if the trx sys header is half-written to disk, we still may be able to recover the information More... | |
constexpr uint32_t | TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED = 24 + FSEG_HEADER_SIZE |
If this is not yet set to TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N, we must reset the doublewrite buffer, because starting from 4.1.x the space id of a data page is stored into FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID. More... | |
constexpr uint32_t | TRX_SYS_DOUBLEWRITE_MAGIC_N = 536853855 |
Contents of TRX_SYS_DOUBLEWRITE_MAGIC. More... | |
constexpr uint32_t | TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N = 1783657386 |
Contents of TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED. More... | |
Transaction system.
Created 3/26/1996 Heikki Tuuri
#define TRX_SYS_DOUBLEWRITE (UNIV_PAGE_SIZE - 200) |
Doublewrite buffer.
The offset of the doublewrite buffer header on the trx system header page
#define TRX_SYS_DOUBLEWRITE_BLOCK_SIZE FSP_EXTENT_SIZE |
Size of the doublewrite block in pages.
#define TRX_SYS_MYSQL_LOG_INFO (UNIV_PAGE_SIZE - 1000) |
The offset of the MySQL binlog offset info in the trx system header.
#define TRX_SYS_TRX_NUM_END (TRX_SYS_TRX_NUM_GTID + 8) |
#define TRX_SYS_TRX_NUM_GTID (TRX_SYS_MYSQL_LOG_INFO + TRX_SYS_MYSQL_LOG_NAME + TRX_SYS_MYSQL_LOG_NAME_LEN) |
Reserve next 8 bytes for transaction number up to which GTIDs are persisted to table.
|
inline |
Computes shard number for a given trx_id.
[in] | trx_id | trx_id for which shard_no should be computed |
Reads a trx id from an index page.
In case that the id size changes in some future version, this function should be used instead of mach_read_...
Checks if a rw transaction with the given id is active.
Please note, that positive result means only that the trx was active at some moment during the call, but it might have already become TRX_STATE_COMMITTED_IN_MEMORY before the call returns to the caller, as this transition is protected by trx->mutex and Trx_shard's mutex, but it is impossible for the caller to hold any of these mutexes when calling this function as the function itself internally acquires Trx_shard's mutex which would cause recurrent mutex acquisition if caller already had the same mutex, or latching order violation in case of holding trx->mutex.
[in] | trx_id | trx id of the transaction |
[in] | do_ref_count | if true then increment the trx_t::n_ref_count |
void trx_sys_after_background_threads_shutdown_validate | ( | ) |
Validates lists of transactions after all background threads of InnoDB exited during shutdown of MySQL.
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
|
inline |
Allocates a new transaction id (for trx->id).
Before calling, the trx_sys_mutex must be acquired.
|
inline |
Allocates a new transaction number (for trx->no).
Before calling, the trx_sys_serialisation_mutex must be acquired.
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
void trx_sys_close | ( | void | ) |
Shutdown/Close the transaction system.
void trx_sys_create | ( | void | ) |
Creates the trx_sys instance and initializes purge_queue and mutex.
void trx_sys_create_sys_pages | ( | void | ) |
Creates and initializes the transaction system at the database creation.
void trx_sys_get_binlog_prepared | ( | std::vector< trx_id_t > & | trx_ids | ) |
Get a list of all binlog prepared transactions.
[out] | trx_ids | all prepared transaction IDs. |
|
inline |
Retrieves a next value that will be allocated if trx_sys_allocate_trx_id() or trx_sys_allocate_trx_id_trx_no() was called.
|
inlinestatic |
Checks if a page address is the trx sys header page.
[in] | page_id | page id |
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.
|
inlinestatic |
Acquire the trx_sys->mutex.
|
inlinestatic |
Release the trx_sys->mutex.
|
inlinestatic |
Test if trx_sys->mutex is owned.
|
inlinestatic |
Determine if there are incomplete transactions in the system.
trx_id_t trx_sys_oldest_trx_no | ( | ) |
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.
[in] | gtid_trx_no | transaction number |
void trx_sys_read_binlog_position | ( | char * | file, |
uint64_t & | offset | ||
) |
Get current binary log positions stored.
[out] | file | binary log file name |
[out] | offset | binary log file offset |
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).
|
inlinestatic |
Add the transaction to the RW transaction set.
trx | transaction instance to add |
|
inlinestatic |
Acquire the trx_sys->serialisation_mutex.
|
inlinestatic |
Release the trx_sys->serialisation_mutex.
|
inlinestatic |
Test if trx_sys->serialisation_mutex is owned.
void trx_sys_undo_spaces_deinit | ( | ) |
Free the resources occupied by trx_sys_undo_spaces, called once during thread de-initialization.
void trx_sys_undo_spaces_init | ( | ) |
Initialize trx_sys_undo_spaces, called once during srv_start().
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.
[in] | trx | Current transaction |
[in,out] | mtr | Mini-transaction for update |
bool trx_sys_validate_trx_list | ( | ) |
Validate the trx_sys_t::rw_trx_list.
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.
[in] | last_file | last noted binary log file name |
[in] | last_offset | last noted binary log offset |
[in] | file | current binary log file name |
[in] | offset | current binary log file offset |
|
inlinestatic |
Gets a pointer to the transaction system file copy and x-locks its page.
Look for a free slot for a rollback segment in the trx system file copy.
[in,out] | mtr | mtr |
Find the page number in the TRX_SYS page for a given slot/rseg_id.
[in] | rseg_id | slot number in the TRX_SYS page rseg array |
|
inlinestatic |
Gets the page number of the nth rollback segment slot in the trx system file copy.
[in] | sys_header | trx sys file copy |
[in] | i | slot index == rseg id |
[in] | mtr | mtr |
|
inlinestatic |
Gets the space of the nth rollback segment slot in the trx system file copy.
[in] | sys_header | trx sys file copy |
[in] | i | slot index == rseg id |
[in] | mtr | mtr |
|
inlinestatic |
Set the page number of the nth rollback segment slot in the trx system file copy.
[in] | sys_header | trx sys file copy |
[in] | i | slot index == rseg id |
[in] | page_no | page number, FIL_NULL if the slot is reset to unused |
[in] | mtr | mtr |
|
inlinestatic |
Sets the space id of the nth rollback segment slot in the trx system file copy.
[in] | sys_header | trx sys file copy |
[in] | i | slot index == rseg id |
[in] | space | space id |
[in] | mtr | mtr |
Writes a trx id to an index page.
In case that the id size changes in some future version, this function should be used instead of mach_write_...
[in] | ptr | pointer to memory where written |
[in] | id | id |
|
extern |
|
constexpr |
Number of shards created for transactions.
|
extern |
The transaction system.
|
constexpr |
The offset of the transaction system header on the page.
|
constexpr |
page number of the first page in the first sequence of 64 (= FSP_EXTENT_SIZE) consecutive pages in the doublewrite buffer
|
constexpr |
page number of the first page in the second sequence of 64 consecutive pages in the doublewrite buffer
|
constexpr |
fseg header of the fseg containing the doublewrite buffer
|
constexpr |
4-byte magic number which shows if we already have created the doublewrite buffer
|
constexpr |
Contents of TRX_SYS_DOUBLEWRITE_MAGIC.
|
constexpr |
we repeat TRX_SYS_DOUBLEWRITE_MAGIC, TRX_SYS_DOUBLEWRITE_BLOCK1, TRX_SYS_DOUBLEWRITE_BLOCK2 so that if the trx sys header is half-written to disk, we still may be able to recover the information
|
constexpr |
If this is not yet set to TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N, we must reset the doublewrite buffer, because starting from 4.1.x the space id of a data page is stored into FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID.
|
constexpr |
Contents of TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED.
|
constexpr |
segment header for the tablespace segment the trx system is created into
|
constexpr |
Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD.
|
constexpr |
magic number which is TRX_SYS_MYSQL_LOG_MAGIC_N if we have valid data in the MySQL binlog info
|
constexpr |
MySQL log file name.
|
constexpr |
Maximum length of MySQL binlog file name, in bytes.
|
constexpr |
high 4 bytes of the offset within that file
|
constexpr |
low 4 bytes of the offset within that file
|
constexpr |
|
constexpr |
|
constexpr |
the start of the array of rollback segment specification slots
|
constexpr |
The automatically created system rollback segment has this id.
|
constexpr |
Transaction system header.
the maximum trx id or trx number modulo TRX_SYS_TRX_ID_UPDATE_MARGIN written to a file page by any transaction; the assignment of transaction ids continues from this number rounded up by TRX_SYS_TRX_ID_UPDATE_MARGIN plus TRX_SYS_TRX_ID_UPDATE_MARGIN when the database is started
|
constexpr |
When a trx id which is zero modulo this number (which must be a power of two) is assigned, the field TRX_SYS_TRX_ID_STORE on the transaction system page is updated.
|
extern |
A list of undo tablespace IDs found in the TRX_SYS page.
This cannot be part of the trx_sys_t object because it is initialized before that object is created. These are the old type of undo tablespaces that do not have space_IDs in the reserved range nor contain an RSEG_ARRAY 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.