MySQL  8.0.27
Source Code Documentation
Rpl_transaction_write_set_ctx Class Reference

Thread class responsible for the collection of write sets associated to a transaction. More...

#include <rpl_transaction_write_set_ctx.h>

Public Member Functions

 Rpl_transaction_write_set_ctx ()
 
virtual ~Rpl_transaction_write_set_ctx ()=default
 
bool add_write_set (uint64 hash)
 Function to add the write set of the hash of the PKE in the std::vector in the transaction_ctx object. More...
 
std::vector< uint64 > * get_write_set ()
 
void reset_state ()
 Reset the object so it can be used for a new transaction. More...
 
void set_has_missing_keys ()
 
bool get_has_missing_keys ()
 
void set_has_related_foreign_keys ()
 
bool get_has_related_foreign_keys ()
 
bool was_write_set_limit_reached ()
 Identifies situations where the limit for number of write set entries already exceeded the configure limit. More...
 
size_t write_set_memory_size ()
 
void add_savepoint (char *name)
 Function to add a new SAVEPOINT identifier in the savepoint map in the transaction_ctx object. More...
 
void del_savepoint (char *name)
 Function to delete a SAVEPOINT identifier in the savepoint map in the transaction_ctx object. More...
 
void rollback_to_savepoint (char *name)
 Function to delete all data added to write set and savepoint since SAVEPOINT identifier was added to savepoinbt in the transaction_ctx object. More...
 
void reset_savepoint_list ()
 Function to push savepoint data to a list and clear the savepoint map in order to create another identifier context, needed on functions ant trigger. More...
 
void restore_savepoint_list ()
 Restore previous savepoint map context, called after executed trigger or function. More...
 
void set_local_ignore_write_set_memory_limit (bool ignore_limit)
 Set if the thread shall ignore any configured memory limit for write set collection. More...
 
void set_local_allow_drop_write_set (bool allow_drop_write_set)
 Set if the thread shall if needed discard write sets. More...
 

Static Public Member Functions

static void set_global_write_set_memory_size_limit (uint64 limit)
 Adds a memory limit for write sets. More...
 
static void update_global_write_set_memory_size_limit (uint64 limit)
 Updates the memory limit for write sets. More...
 
static void set_global_require_full_write_set (bool requires_ws)
 Prevent or allow this class to discard writesets exceeding a size limit If true, a transaction will never discard its write sets. More...
 

Private Member Functions

void clear_write_set ()
 

Private Attributes

std::vector< uint64write_set
 
bool m_has_missing_keys
 
bool m_has_related_foreign_keys
 
std::map< std::string, size_t > savepoint
 Contains information related to SAVEPOINTs. More...
 
std::list< std::map< std::string, size_t > > savepoint_list
 Create a savepoint context hierarchy to support encapsulation of identifier name when function or trigger are executed. More...
 
bool m_ignore_write_set_memory_limit
 If the thread should or not ignore the set limit for write set collection. More...
 
bool m_local_allow_drop_write_set
 Even if a component says all transactions require write sets, this variable says this thread should discard them when they are bigger than m_opt_max_history_size. More...
 
bool m_local_has_reached_write_set_limit
 True if the write set size is over the configure limit. More...
 

Static Private Attributes

static std::atomic< bool > m_global_component_requires_write_sets
 There is a component requiring write sets on transactions. More...
 
static std::atomic< uint64m_global_write_set_memory_size_limit
 Memory size limit enforced for write set collection. More...
 

Detailed Description

Thread class responsible for the collection of write sets associated to a transaction.

It also includes suport for save points where information will be discarded on rollbacks to a savepoint.

Write set and flags are reset on Rpl_transaction_write_set_ctx::reset_state().

The write set collection by an executing transaction is capped to a limit. The limit can be "soft" or "hard":

  • when a writeset grows above a "soft" limit, the transaction is allowed to execute and commit, but the write set is discarded, and the transaction declared to not have a usable write set.
  • when a write set grows above a "hard" limit, the transaction is forced to abort and rollback.

We cannot use a soft limit for transactions that will be certified in GR, since a writeset is required for correct certification. But when GR is disabled, we can use a soft limit, because the writeset is only used to compute transaction dependencies, and we can pessimistically mark the transaction as conflicting with all other transcations when the writeset is discarded. A soft limit can also be used for transactions executed by the GR recovery channel, since they will not be certified, and the GR applier channel, since those transactions have already passed the certification stage.

For the soft limit, we use

  • binlog_transaction_dependency_history_size. Transactions bigger than that cannot be added to the writeset history since they do not fit, and therefore are marked as conflicting with all subsequent* transactions anyways. Therefore much of the parallelization for the transaction is already destroyed, and it is unlikely that also marking it as conflicting with previous* transactions makes a significant difference.

For the hard limit, when using Group Replication, we use

  • group_replication_transaction_size_limit. Since the writeset is a subset of the transaction, and the transaction is limited to this size anyways, a transaction whose writeset exceeds this limit will fail anyways. So failing it when generating the writeset is merely a fail-fast mechanism, and it is not a restriction to apply this limit to the writeset of all transactions for which the full transaction data is also subject to the limit. The transactions that are subject to this limit are exactly those executed when GR is enabled, except by the GR applier channel and GR recovery channel.

We expose the following interfaces so that components such as GR can control the limit. There is an interface to globally disable/enable the soft limit: static void set_global_require_full_write_set(bool requires_ws); set/alter/remove a hard limit: static void set_global_write_set_memory_size_limit(uint64 limit) static void update_global_write_set_memory_size_limit(uint64 limit);

There is another interface to override the global limits for a thread: void set_local_ignore_write_set_memory_limit(bool ignore_limit); void set_local_allow_drop_write_set(bool allow_drop_write_set);

The local methods are used for example for Group Replication applier and recovery threads as group_replication_transaction_size_limit only applies to client sessions and non group replication replica threads.

Constructor & Destructor Documentation

◆ Rpl_transaction_write_set_ctx()

Rpl_transaction_write_set_ctx::Rpl_transaction_write_set_ctx ( )

◆ ~Rpl_transaction_write_set_ctx()

virtual Rpl_transaction_write_set_ctx::~Rpl_transaction_write_set_ctx ( )
virtualdefault

Member Function Documentation

◆ add_savepoint()

void Rpl_transaction_write_set_ctx::add_savepoint ( char *  name)

Function to add a new SAVEPOINT identifier in the savepoint map in the transaction_ctx object.

Parameters
[in]name- the identifier name of the SAVEPOINT.

◆ add_write_set()

bool Rpl_transaction_write_set_ctx::add_write_set ( uint64  hash)

Function to add the write set of the hash of the PKE in the std::vector in the transaction_ctx object.

Parameters
[in]hash- the uint64 type hash value of the PKE.
Returns
true if it can't add the write set entry, false if successful

◆ clear_write_set()

void Rpl_transaction_write_set_ctx::clear_write_set ( )
private

◆ del_savepoint()

void Rpl_transaction_write_set_ctx::del_savepoint ( char *  name)

Function to delete a SAVEPOINT identifier in the savepoint map in the transaction_ctx object.

Parameters
[in]name- the identifier name of the SAVEPOINT.

◆ get_has_missing_keys()

bool Rpl_transaction_write_set_ctx::get_has_missing_keys ( )

◆ get_has_related_foreign_keys()

bool Rpl_transaction_write_set_ctx::get_has_related_foreign_keys ( )

◆ get_write_set()

std::vector< uint64 > * Rpl_transaction_write_set_ctx::get_write_set ( )

◆ reset_savepoint_list()

void Rpl_transaction_write_set_ctx::reset_savepoint_list ( )

Function to push savepoint data to a list and clear the savepoint map in order to create another identifier context, needed on functions ant trigger.

◆ reset_state()

void Rpl_transaction_write_set_ctx::reset_state ( )

Reset the object so it can be used for a new transaction.

◆ restore_savepoint_list()

void Rpl_transaction_write_set_ctx::restore_savepoint_list ( )

Restore previous savepoint map context, called after executed trigger or function.

◆ rollback_to_savepoint()

void Rpl_transaction_write_set_ctx::rollback_to_savepoint ( char *  name)

Function to delete all data added to write set and savepoint since SAVEPOINT identifier was added to savepoinbt in the transaction_ctx object.

Parameters
[in]name- the identifier name of the SAVEPOINT.

◆ set_global_require_full_write_set()

void Rpl_transaction_write_set_ctx::set_global_require_full_write_set ( bool  requires_ws)
static

Prevent or allow this class to discard writesets exceeding a size limit If true, a transaction will never discard its write sets.

Parameters
requires_wsif who invoked the method needs or not write sets

◆ set_global_write_set_memory_size_limit()

void Rpl_transaction_write_set_ctx::set_global_write_set_memory_size_limit ( uint64  limit)
static

Adds a memory limit for write sets.

Note
currently only one component can set this limit a time.
Parameters
limitthe limit to be added

◆ set_has_missing_keys()

void Rpl_transaction_write_set_ctx::set_has_missing_keys ( )

◆ set_has_related_foreign_keys()

void Rpl_transaction_write_set_ctx::set_has_related_foreign_keys ( )

◆ set_local_allow_drop_write_set()

void Rpl_transaction_write_set_ctx::set_local_allow_drop_write_set ( bool  allow_drop_write_set)

Set if the thread shall if needed discard write sets.

Parameters
allow_drop_write_setif full write sets are not critical

◆ set_local_ignore_write_set_memory_limit()

void Rpl_transaction_write_set_ctx::set_local_ignore_write_set_memory_limit ( bool  ignore_limit)

Set if the thread shall ignore any configured memory limit for write set collection.

Parameters
ignore_limitif the limit should be ignored

◆ update_global_write_set_memory_size_limit()

void Rpl_transaction_write_set_ctx::update_global_write_set_memory_size_limit ( uint64  limit)
static

Updates the memory limit for write sets.

Note
Using the value 0 disables the limit
Parameters
limitthe limit to be added

◆ was_write_set_limit_reached()

bool Rpl_transaction_write_set_ctx::was_write_set_limit_reached ( )

Identifies situations where the limit for number of write set entries already exceeded the configure limit.

Return values
trueif too many write set entries exist, false otherwise

◆ write_set_memory_size()

size_t Rpl_transaction_write_set_ctx::write_set_memory_size ( )
Returns
the size of the write_set field in bytes

Member Data Documentation

◆ m_global_component_requires_write_sets

std::atomic< bool > Rpl_transaction_write_set_ctx::m_global_component_requires_write_sets
staticprivate

There is a component requiring write sets on transactions.

◆ m_global_write_set_memory_size_limit

std::atomic< uint64 > Rpl_transaction_write_set_ctx::m_global_write_set_memory_size_limit
staticprivate

Memory size limit enforced for write set collection.

◆ m_has_missing_keys

bool Rpl_transaction_write_set_ctx::m_has_missing_keys
private

◆ m_has_related_foreign_keys

bool Rpl_transaction_write_set_ctx::m_has_related_foreign_keys
private

◆ m_ignore_write_set_memory_limit

bool Rpl_transaction_write_set_ctx::m_ignore_write_set_memory_limit
private

If the thread should or not ignore the set limit for write set collection.

◆ m_local_allow_drop_write_set

bool Rpl_transaction_write_set_ctx::m_local_allow_drop_write_set
private

Even if a component says all transactions require write sets, this variable says this thread should discard them when they are bigger than m_opt_max_history_size.

◆ m_local_has_reached_write_set_limit

bool Rpl_transaction_write_set_ctx::m_local_has_reached_write_set_limit
private

True if the write set size is over the configure limit.

◆ savepoint

std::map<std::string, size_t> Rpl_transaction_write_set_ctx::savepoint
private

Contains information related to SAVEPOINTs.

The key on map is the identifier and the value is the size of write set when command was executed.

◆ savepoint_list

std::list<std::map<std::string, size_t> > Rpl_transaction_write_set_ctx::savepoint_list
private

Create a savepoint context hierarchy to support encapsulation of identifier name when function or trigger are executed.

◆ write_set

std::vector<uint64> Rpl_transaction_write_set_ctx::write_set
private

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