MySQL 8.4.2
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>

Public Types

using transaction_ptr = std::shared_ptr< Transaction_ctx >
 
using unordered_map = malloc_unordered_map< std::string, transaction_ptr >
 
using list = std::vector< transaction_ptr >
 
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_cacheoperator= (Transaction_cache const &)=delete
 
Transaction_cacheoperator= (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 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 list get_cached_transactions ()
 Retrieves the list of transaction contexts cached. More...
 
static void initialize ()
 Initializes the transaction cache underlying resources. More...
 
static void dispose ()
 Disposes of the transaction cache allocated resources. More...
 

Private Member Functions

 Transaction_cache ()
 Class constructor. More...
 

Static Private Member Functions

static Transaction_cacheinstance ()
 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 &)>

◆ list

◆ transaction_ptr

◆ unordered_map

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_cached_transactions()

xa::Transaction_cache::list xa::Transaction_cache::get_cached_transactions ( )
static

Retrieves the list of transaction contexts cached.

Returns
A vector with all transaction contexts cached so far.

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

◆ 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:156
#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: