MySQL 26.7.0
Source Code Documentation
cs::apply::Csa_worker_context Class Reference

Class representing the interface for parallel worker context. More...

#include <csa_worker_context.h>

Inheritance diagram for cs::apply::Csa_worker_context:
[legend]

Public Types

using Trx_id = Parallel_worker_context::Trx_id
 
using Worker_id = Parallel_worker_context::Worker_id
 
- Public Types inherited from cs::apply::Parallel_worker_context
using Trx_id = int64_t
 
using Worker_id = uint64_t
 
using Channel_id = std::string
 

Public Member Functions

 Csa_worker_context (Trx_id trx_seq_num, Worker_id worker_id, const std::string &channel_id, THD *trx_ctx, int current_retry, int retries_num)
 
void report_commit_order_deadlock (bool for_self=false) override
 Indicates that commit order deadlock has been found. More...
 
bool found_commit_order_deadlock () const override
 Checks if commit order deadlock has been found. More...
 
void reset_commit_order_deadlock () override
 Resets commit order deadlock. More...
 
bool is_same_channel (const Parallel_worker_context *arg) const override
 Checks if arg parallel worker executes transaction coming from the same channel. More...
 
THDget_transaction_ctx () override
 Returns transaction id (we use sequence number) More...
 
Worker_id get_worker_id () const override
 Returns worker id. More...
 
instruments::Worker_metricsget_worker_metrics () override
 Obtains worker metrics. More...
 
MDL_contextget_mdl_context () override
 MDL context accessor. More...
 
const std::string & get_channel_id () const
 Channel identifier accessor. More...
 
Trx_id get_trx_id () override
 Obtain transaction id (sequence number) More...
 
const char * get_for_channel_id (bool upper_case) const override
 Get "for channel" id. More...
 
void update (Trx_id trx_seq_num, Worker_id worker_id, THD *trx_ctx, int current_retry)
 Updates internal data for a new transaction. More...
 
void update (Worker_id worker_id, int current_retry)
 Updates internal data for ongoing transaction. More...
 
void update (Trx_id trx_seq_num, Worker_id worker_id, const std::string &channel_id, THD *trx_ctx, int current_retry, int retries_num)
 Updates all internal data for new transaction and channel. More...
 
bool can_be_retried (THD *thd) override
 Returns information on whether THD transaction can be retried. More...
 
bool has_temporary_error (THD *thd, int error)
 Checks whether this transaction error is temporary. More...
 
void set_applied ()
 Mark transaction as prepared and externally rollbackable. More...
 
void set_committing ()
 Move transaction from prepared into committing state. More...
 
bool is_rollback_requested () const
 Check if external rollback is on-going. More...
 
void handle_commit_order_deadlock ()
 Handle commit order deadlock - one of the callers will request transaction rollback due to rpco deadlock. More...
 
bool wait_for_rollback ()
 Waits for external rollback to finish. More...
 
bool is_csa () const override
 Checks whether this worker is CSA worker. More...
 
- Public Member Functions inherited from cs::apply::Parallel_worker_context
 Parallel_worker_context ()=default
 
virtual ~Parallel_worker_context ()=default
 

Static Public Attributes

static instruments::Dummy_worker_metrics m_disabled_worker_metrics {}
 Worker metrics. More...
 

Private Types

enum class  Rpco_state : std::uint8_t { preparing , prepared , commit }
 RPCO lifecycle visible to deadlock reporting: More...
 

Private Attributes

std::atomic< bool > m_is_commit_order_deadlock {false}
 Sticky indicator that this transaction was reported as an RPCO victim. More...
 
std::atomic< bool > m_rollback {false}
 Set once an external rollback request has been enqueued. More...
 
std::atomic< Rpco_statem_rpco_state {Rpco_state::preparing}
 Current RPCO lifecycle state used to decide how to handle reports. More...
 
std::promise< bool > m_rollback_promise
 Completes when the external rollback worker finishes rescue handling. More...
 
Trx_id m_trx_id {0}
 Transaction identifier reused by commit-order logic. More...
 
Worker_id m_worker_id {0}
 Current worker slot owning this transaction context. More...
 
std::string m_channel_id {""}
 Replication channel this transaction belongs to. More...
 
THDm_trx_ctx {nullptr}
 THD currently bound to this transaction context. More...
 
int m_current_retry {0}
 Retry number of the current attempt. More...
 
int m_retries_num {0}
 Maximum number of retries allowed for this transaction. More...
 
std::string m_for_channel_id {""}
 Cached "for channel" suffix, built lazily for diagnostics. More...
 

Detailed Description

Class representing the interface for parallel worker context.

It accesses basic information like worker id, transaction id, channel id and other functionatlities needed by the commit order manager.

Note
This context is needed to disconnect Slave_worker class from execution path, Slave_worker implements Parallel_worker_context interface

Member Typedef Documentation

◆ Trx_id

◆ Worker_id

Member Enumeration Documentation

◆ Rpco_state

enum class cs::apply::Csa_worker_context::Rpco_state : std::uint8_t
strongprivate

RPCO lifecycle visible to deadlock reporting:

  • preparing: transaction is still in apply/prepare work
  • prepared: transaction left apply and may be rescued externally
  • commit: transaction entered commit ownership and must resolve there
Enumerator
preparing 
prepared 
commit 

Constructor & Destructor Documentation

◆ Csa_worker_context()

cs::apply::Csa_worker_context::Csa_worker_context ( Trx_id  trx_seq_num,
Worker_id  worker_id,
const std::string &  channel_id,
THD trx_ctx,
int  current_retry,
int  retries_num 
)

Member Function Documentation

◆ can_be_retried()

bool cs::apply::Csa_worker_context::can_be_retried ( THD thd)
overridevirtual

Returns information on whether THD transaction can be retried.

Returns
true if transaction can be retried

Implements cs::apply::Parallel_worker_context.

◆ found_commit_order_deadlock()

bool cs::apply::Csa_worker_context::found_commit_order_deadlock ( ) const
overridevirtual

Checks if commit order deadlock has been found.

Returns
True if commit order deadlock has been found, false otherwise

Implements cs::apply::Parallel_worker_context.

◆ get_channel_id()

const std::string & cs::apply::Csa_worker_context::get_channel_id ( ) const

Channel identifier accessor.

Returns
channel identifier

◆ get_for_channel_id()

const char * cs::apply::Csa_worker_context::get_for_channel_id ( bool  upper_case) const
overridevirtual

Get "for channel" id.

Builds string in flight when needed

Parameters
upper_casePass true if upper case is needed
Returns
"for channel" string

Reimplemented from cs::apply::Parallel_worker_context.

◆ get_mdl_context()

MDL_context * cs::apply::Csa_worker_context::get_mdl_context ( )
overridevirtual

MDL context accessor.

Returns
MDL context obj pointer

Implements cs::apply::Parallel_worker_context.

◆ get_transaction_ctx()

THD * cs::apply::Csa_worker_context::get_transaction_ctx ( )
overridevirtual

Returns transaction id (we use sequence number)

Returns
transaction id

Implements cs::apply::Parallel_worker_context.

◆ get_trx_id()

Csa_worker_context::Trx_id cs::apply::Csa_worker_context::get_trx_id ( )
overridevirtual

Obtain transaction id (sequence number)

Returns
Transaction sequence number

Implements cs::apply::Parallel_worker_context.

◆ get_worker_id()

Csa_worker_context::Worker_id cs::apply::Csa_worker_context::get_worker_id ( ) const
overridevirtual

Returns worker id.

Returns
Worker identifier

Implements cs::apply::Parallel_worker_context.

◆ get_worker_metrics()

instruments::Worker_metrics & cs::apply::Csa_worker_context::get_worker_metrics ( )
overridevirtual

Obtains worker metrics.

Returns
Reference to worker metrics object

Implements cs::apply::Parallel_worker_context.

◆ handle_commit_order_deadlock()

void cs::apply::Csa_worker_context::handle_commit_order_deadlock ( )

Handle commit order deadlock - one of the callers will request transaction rollback due to rpco deadlock.

◆ has_temporary_error()

bool cs::apply::Csa_worker_context::has_temporary_error ( THD thd,
int  error 
)

Checks whether this transaction error is temporary.

Parameters
thdTHD handle
errorAdditional error information

◆ is_csa()

bool cs::apply::Csa_worker_context::is_csa ( ) const
overridevirtual

Checks whether this worker is CSA worker.

Returns
true for CSA parallel worker context. False otherwise

Reimplemented from cs::apply::Parallel_worker_context.

◆ is_rollback_requested()

bool cs::apply::Csa_worker_context::is_rollback_requested ( ) const
inline

Check if external rollback is on-going.

Returns
True when external rollback was already requested.

◆ is_same_channel()

bool cs::apply::Csa_worker_context::is_same_channel ( const Parallel_worker_context arg) const
overridevirtual

Checks if arg parallel worker executes transaction coming from the same channel.

Parameters
argContext to compare against

Implements cs::apply::Parallel_worker_context.

◆ report_commit_order_deadlock()

void cs::apply::Csa_worker_context::report_commit_order_deadlock ( bool  for_self = false)
overridevirtual

Indicates that commit order deadlock has been found.

Parameters
for_selfWhen true, a thread reports for its own

Implements cs::apply::Parallel_worker_context.

◆ reset_commit_order_deadlock()

void cs::apply::Csa_worker_context::reset_commit_order_deadlock ( )
overridevirtual

Resets commit order deadlock.

Implements cs::apply::Parallel_worker_context.

◆ set_applied()

void cs::apply::Csa_worker_context::set_applied ( )

Mark transaction as prepared and externally rollbackable.

◆ set_committing()

void cs::apply::Csa_worker_context::set_committing ( )

Move transaction from prepared into committing state.

◆ update() [1/3]

void cs::apply::Csa_worker_context::update ( Trx_id  trx_seq_num,
Worker_id  worker_id,
const std::string &  channel_id,
THD trx_ctx,
int  current_retry,
int  retries_num 
)

Updates all internal data for new transaction and channel.

Parameters
trx_seq_numTransaction sequence number
worker_idWorker identifier
channel_idChannel identifier
trx_ctxTransaction THD
current_retryCurrent retry number
retries_numNumber of possible retries for this transaction

◆ update() [2/3]

void cs::apply::Csa_worker_context::update ( Trx_id  trx_seq_num,
Worker_id  worker_id,
THD trx_ctx,
int  current_retry 
)

Updates internal data for a new transaction.

Parameters
trx_seq_numTransaction sequence number
worker_idWorker identifier
trx_ctxTransaction THD
current_retryCurrent retry number

◆ update() [3/3]

void cs::apply::Csa_worker_context::update ( Worker_id  worker_id,
int  current_retry 
)

Updates internal data for ongoing transaction.

Parameters
worker_idWorker identifier
current_retryCurrent retry number

◆ wait_for_rollback()

bool cs::apply::Csa_worker_context::wait_for_rollback ( )

Waits for external rollback to finish.

Member Data Documentation

◆ m_channel_id

std::string cs::apply::Csa_worker_context::m_channel_id {""}
private

Replication channel this transaction belongs to.

◆ m_current_retry

int cs::apply::Csa_worker_context::m_current_retry {0}
private

Retry number of the current attempt.

◆ m_disabled_worker_metrics

instruments::Dummy_worker_metrics cs::apply::Csa_worker_context::m_disabled_worker_metrics {}
static

Worker metrics.

◆ m_for_channel_id

std::string cs::apply::Csa_worker_context::m_for_channel_id {""}
mutableprivate

Cached "for channel" suffix, built lazily for diagnostics.

◆ m_is_commit_order_deadlock

std::atomic<bool> cs::apply::Csa_worker_context::m_is_commit_order_deadlock {false}
private

Sticky indicator that this transaction was reported as an RPCO victim.

◆ m_retries_num

int cs::apply::Csa_worker_context::m_retries_num {0}
private

Maximum number of retries allowed for this transaction.

◆ m_rollback

std::atomic<bool> cs::apply::Csa_worker_context::m_rollback {false}
private

Set once an external rollback request has been enqueued.

◆ m_rollback_promise

std::promise<bool> cs::apply::Csa_worker_context::m_rollback_promise
private

Completes when the external rollback worker finishes rescue handling.

◆ m_rpco_state

std::atomic<Rpco_state> cs::apply::Csa_worker_context::m_rpco_state {Rpco_state::preparing}
private

Current RPCO lifecycle state used to decide how to handle reports.

◆ m_trx_ctx

THD* cs::apply::Csa_worker_context::m_trx_ctx {nullptr}
private

THD currently bound to this transaction context.

◆ m_trx_id

Trx_id cs::apply::Csa_worker_context::m_trx_id {0}
private

Transaction identifier reused by commit-order logic.

◆ m_worker_id

Worker_id cs::apply::Csa_worker_context::m_worker_id {0}
private

Current worker slot owning this transaction context.


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