MySQL 8.4.13
Source Code Documentation
xa::Transaction_cache Class Reference

Class responsible for managing a cache of Transaction_ctx objects associated with XA transactions. More...

#include <transaction_cache.h>

Classes

class  Cache_entry
 Cached transaction context and its visibility through SQL XA RECOVER. More...
 

Public Types

using transaction_ptr = std::shared_ptr< Transaction_ctx >
 
using filter_predicate_t = std::function< bool(transaction_ptr const &)>
 

Public Member Functions

virtual ~Transaction_cache ()=default
 
 Transaction_cache (Transaction_cache const &)=delete
 
 Transaction_cache (Transaction_cache &&)=delete
 
Transaction_cache & operator= (Transaction_cache const &)=delete
 
Transaction_cache & operator= (Transaction_cache &&)=delete
 

Static Public Member Functions

static bool detach (Transaction_ctx *transaction)
 Transaction is marked in the cache as if it's recovered. More...
 
static void remove (Transaction_ctx *transaction)
 Remove information about transaction from a cache. More...
 
static void mark_prepared_visible_for_xa_recover (Transaction_ctx *transaction)
 Mark a transaction visible through SQL XA RECOVER without changing its SQL XA state. More...
 
static void mark_finalized_for_recover (Transaction_ctx *transaction)
 Mark a transaction finalized for SQL XA RECOVER without releasing its XID reservation from the cache. More...
 
static bool insert (XID *xid, Transaction_ctx *transaction)
 Inserts a transaction context identified by a given XID. More...
 
static bool insert (XID *xid)
 Creates a new transaction context for the recovering transaction identified by a given XID. More...
 
static transaction_ptr find (XID *xid, filter_predicate_t filter=nullptr)
 Searches the cache for the transaction context identified by the given XID. More...
 
static std::vector< XID > get_xids_visible_to_xa_recover ()
 Retrieves XID snapshots visible through SQL XA RECOVER. More...
 
static void initialize ()
 Initializes the transaction cache underlying resources. More...
 
static void dispose ()
 Disposes of the transaction cache allocated resources. More...
 

Private Types

enum class  Xa_recover_visibility { Visible , Hidden }
 
using unordered_map = malloc_unordered_map< std::string, Cache_entry >
 

Private Member Functions

 Transaction_cache ()
 Class constructor. More...
 

Static Private Member Functions

static Transaction_cache & instance ()
 Initialize a cache to store Transaction_ctx and a mutex to protect access to the cache. More...
 
static bool create_and_insert_new_transaction (XID *xid, bool is_binlogged_arg, const Transaction_ctx *src)
 Creates a new transaction context for the transaction with the given XID and adds it to the cache. More...
 

Private Attributes

mysql_mutex_t m_LOCK_transaction_cache
 A lock to serialize the access to m_transaction_cache More...
 
PSI_mutex_key m_key_LOCK_transaction_cache
 The PSI key for the above lock. More...
 
PSI_mutex_info m_transaction_cache_mutexes [1]
 The PSI configuration of the above lock and key. More...
 
unordered_map m_transaction_cache
 A map holding the cached transaction context, indexed by XID. More...
 

Detailed Description

Class responsible for managing a cache of Transaction_ctx objects associated with XA transactions.

The cache is used during the recovery stage of an XA transaction.

Note
this class is a singleton class.

Member Typedef Documentation

◆ filter_predicate_t

using xa::Transaction_cache::filter_predicate_t = std::function<bool(transaction_ptr const &)>

◆ transaction_ptr

◆ unordered_map

Member Enumeration Documentation

◆ Xa_recover_visibility

Enumerator
Visible 
Hidden 

Constructor & Destructor Documentation

◆ ~Transaction_cache()

virtual xa::Transaction_cache::~Transaction_cache ( )
virtualdefault

◆ Transaction_cache() [1/3]

xa::Transaction_cache::Transaction_cache ( Transaction_cache const &  )
delete

◆ Transaction_cache() [2/3]

xa::Transaction_cache::Transaction_cache ( Transaction_cache &&  )
delete

◆ Transaction_cache() [3/3]

xa::Transaction_cache::Transaction_cache ( )
private

Class constructor.

It's declared private since this class is a singleton class.

Member Function Documentation

◆ create_and_insert_new_transaction()

bool xa::Transaction_cache::create_and_insert_new_transaction ( XID *  xid,
bool  is_binlogged_arg,
const Transaction_ctx *  src 
)
staticprivate

Creates a new transaction context for the transaction with the given XID and adds it to the cache.

Parameters
xidThe XID of the transaction to create and add.
is_binlogged_argWhether or not the transaction has already been binlogged.
srcThe transaction context and info to be added to the newly created cache item.
Returns
false if the pair was successfully inserted, true otherwise.

◆ detach()

bool xa::Transaction_cache::detach ( Transaction_ctx *  transaction)
static

Transaction is marked in the cache as if it's recovered.

The method allows to sustain prepared transaction disconnection.

Parameters
transactionPointer to Transaction object that is replaced.
Returns
operation result
Return values
falsesuccess or a cache already contains XID_STATE for this XID value
truefailure

◆ dispose()

void xa::Transaction_cache::dispose ( )
static

Disposes of the transaction cache allocated resources.

◆ find()

std::shared_ptr< Transaction_ctx > xa::Transaction_cache::find ( XID *  xid,
filter_predicate_t  filter = nullptr 
)
static

Searches the cache for the transaction context identified by the given XID.

An additional filtering predicate can be provided, to allow for further validations on values for mathching XID. The predicate is evaluated while holding the necessary locks to ensure the validaty of the Transaction_ctx shared pointer.

A non-null value is returned if and only if:

  1. The value is found in the underlying map
  2. The found value underlying XID (Transaction_ctx::xid_state()get_xid()) equals to the parameter xid. This validation is necessary since the XID representation for the key used in the underlying map isn't an exact match for the full XID representation.
  3. If a predicate parameter is provided, the evaluation of passing the value as a predicate parameter must be true.
Parameters
xidThe XID of the transaction to search the context for.
filterA predicate to be evaluated when an value for xid is found. If predicate returns false, the found element is filtered out.
Returns
The transaction context if found and valid, nullptr otherwise.

◆ get_xids_visible_to_xa_recover()

std::vector< XID > xa::Transaction_cache::get_xids_visible_to_xa_recover ( )
static

Retrieves XID snapshots visible through SQL XA RECOVER.

Entries finalized for recover are skipped here, but remain in the cache as XID reservations until final cleanup removes them.

Returns
XID value snapshots for transactions visible through SQL XA RECOVER.

◆ initialize()

void xa::Transaction_cache::initialize ( )
static

Initializes the transaction cache underlying resources.

◆ insert() [1/2]

bool xa::Transaction_cache::insert ( XID *  xid)
static

Creates a new transaction context for the recovering transaction identified by a given XID.

Parameters
xidThe XID of the transaction being recovered.
Returns
false if the pair was successfully inserted, true otherwise.

◆ insert() [2/2]

bool xa::Transaction_cache::insert ( XID *  xid,
Transaction_ctx *  transaction 
)
static

Inserts a transaction context identified by a given XID.

Parameters
xidThe XID of the transaction.
transactionThe object containing the context of the transaction.
Returns
false if the pair was successfully inserted, true otherwise.

◆ instance()

xa::Transaction_cache & xa::Transaction_cache::instance ( )
staticprivate

Initialize a cache to store Transaction_ctx and a mutex to protect access to the cache.

Returns
The initialized class instance.

◆ mark_finalized_for_recover()

void xa::Transaction_cache::mark_finalized_for_recover ( Transaction_ctx *  transaction)
static

Mark a transaction finalized for SQL XA RECOVER without releasing its XID reservation from the cache.

This is used after XA COMMIT/XA ROLLBACK has completed in engines, but before the statement GTID is made visible. The cache entry must remain present for two reasons:

  1. To keep the XID reserved until per-XID cleanup, such as MDL context backup deletion, is done.
  2. To keep the cached detached transaction identity available for concurrent same-XID second-phase checks until final cleanup removes the entry.
Parameters
transactionTransaction context to hide from SQL XA RECOVER.

◆ mark_prepared_visible_for_xa_recover()

void xa::Transaction_cache::mark_prepared_visible_for_xa_recover ( Transaction_ctx *  transaction)
static

Mark a transaction visible through SQL XA RECOVER without changing its SQL XA state.

This is used by XA PREPARE before the prepare GTID is made visible, and again when SQL state changes to XA_PREPARED. The second call is idempotent and preserves the ordinary prepared-implies-recover-visible contract for paths without GTID externalization.

Parameters
transactionTransaction context to show in SQL XA RECOVER.

◆ operator=() [1/2]

Transaction_cache & xa::Transaction_cache::operator= ( Transaction_cache &&  )
delete

◆ operator=() [2/2]

Transaction_cache & xa::Transaction_cache::operator= ( Transaction_cache const &  )
delete

◆ remove()

void xa::Transaction_cache::remove ( Transaction_ctx *  transaction)
static

Remove information about transaction from a cache.

Parameters
transactionPointer to a Transaction_ctx that has to be removed from a cache.

Member Data Documentation

◆ m_key_LOCK_transaction_cache

PSI_mutex_key xa::Transaction_cache::m_key_LOCK_transaction_cache
private

The PSI key for the above lock.

◆ m_LOCK_transaction_cache

mysql_mutex_t xa::Transaction_cache::m_LOCK_transaction_cache
private

A lock to serialize the access to m_transaction_cache

◆ m_transaction_cache

unordered_map xa::Transaction_cache::m_transaction_cache
private

A map holding the cached transaction context, indexed by XID.

◆ m_transaction_cache_mutexes

PSI_mutex_info xa::Transaction_cache::m_transaction_cache_mutexes[1]
private
Initial value:
= {
{&m_key_LOCK_transaction_cache, "LOCK_transaction_cache",
PSI_mutex_key m_key_LOCK_transaction_cache
The PSI key for the above lock.
Definition: transaction_cache.h:225
#define PSI_DOCUMENT_ME
Definition: component_common.h:29
#define PSI_FLAG_SINGLETON
Singleton flag.
Definition: component_common.h:35

The PSI configuration of the above lock and key.


The documentation for this class was generated from the following files: