MySQL 26.7.0
Source Code Documentation
mysql::csa::Job_applier Class Reference

Concrete class representing job applied by the applier. More...

#include <job_applier.h>

Inheritance diagram for mysql::csa::Job_applier:
[legend]

Public Types

using Resource_monitor_ref = Resource_instance_monitor_ref
 
- Public Types inherited from mysql::csa::Job_binlog
using Stat_monitor_ref = scheduler::Statistics_instance_monitor_ref
 Alias to Statistics_instance_monitor_ref contained in the scheduler library. More...
 
- Public Types inherited from mysql::csa::Job
using Thread_id = unsigned int
 Type alias for thread identifier. More...
 

Public Member Functions

 Job_applier (Channel *channel, unsigned int max_retries, std::shared_ptr< Fetchable_transaction > fetch_object, Stat_monitor_ref stat_monitor, Resource_monitor_ref res_monitor)
 Constructor. More...
 
virtual ~Job_applier () override
 Destructor. More...
 
bool attach (Thread_id thread_id) override
 Attaches to relay context. More...
 
bool detach (Thread_id thread_id) override
 Detaches from relay context. More...
 
bool is_attached () const override
 Checks whether this job is attached to relay log context. More...
 
bool restart () override
 Restarts internal state. More...
 
std::string to_string () override
 Presents job identifier. More...
 
void set_failure () override
 Sets job failure. More...
 
void prepare_for_apply (Session_service_ptr ss)
 Prepares this job to be applied. More...
 
bool wait_for_rollback_and_restart ()
 Internal function to wait for rollback and restart transaction in case deadlock has been found. More...
 
- Public Member Functions inherited from mysql::csa::Job_binlog
 Job_binlog (const Job_binlog &)=delete
 Deleted copy constructor. More...
 
Job_binlogoperator= (const Job_binlog &)=delete
 Deleted assignment operator. More...
 
 Job_binlog (Channel *channel, unsigned int max_retries, std::shared_ptr< Fetchable_transaction > fetch_object, Stat_monitor_ref stat_monitor)
 Constructor for Job_binlog. More...
 
virtual ~Job_binlog () override
 Destructor for Job_binlog. More...
 
Channelget_channel () const
 Gets the channel this job comes from. More...
 
const std::string & get_channel_id () const
 Gets the transaction identifier as a string. More...
 
std::string get_trx_id () const
 Get transaction GTID. More...
 
const mysql::gtid::Gtidget_trx_gtid () const
 Gets the transaction GTID. More...
 
unsigned long long get_last_committed () const
 Gets the last committed value to determine when this transaction can run. More...
 
unsigned long long get_sequence_number () const
 Gets the sequence number of this transaction to determine when it can run and commit. More...
 
unsigned long long get_trx_length () const
 Gets the transaction length. More...
 
void set_done () override
 Mark the transaction as done (done with failure or done successfully. More...
 
unsigned int get_instance_id () const override
 Obtains unique instance id to gather statistics separately for different "instances". More...
 
virtual bool is_complete ()
 Checks if this transaction has finished fetching. More...
 
bool restart () override
 Restarts the job and prepares for retry. More...
 
bool run (Thread_id thread_id) override
 Binlog job needs to be called twice to apply transaction: More...
 
bool is_trx () const override
 Checks whether handled job is a transaction (supports two phases) More...
 
void set_success () override
 success callback More...
 
void skip () override
 Skip this job, considered complete and done without failure. More...
 
- Public Member Functions inherited from mysql::csa::Job
 Job (const Job &)=delete
 Deleted copy constructor. More...
 
Joboperator= (const Job &)=delete
 Deleted assignment operator. More...
 
 Job (unsigned int max_retries)
 Constructor. More...
 
virtual ~Job ()
 Destructor. More...
 
Thread_id get_attach_id () const
 Returns an id based on which the job attaches to applier context. More...
 
virtual std::size_t get_id () const
 Gets the job identifier. More...
 
virtual void inc_retries ()
 Increments the number of retries for the job. More...
 
virtual unsigned int get_retries () const
 Gets the number of retries for this job. More...
 
virtual bool is_error ()
 Checks whether this job is in error state. More...
 
virtual bool is_stopped () const
 Checks whether applier stop has been requested for this job. More...
 
virtual bool is_fatal_error ()
 Checks whether job has a fatal, non-recoverable error. More...
 
virtual void set_applier_stop (std::atomic< bool > &applier_stop)
 Injects the applier stop flag for this job. More...
 
virtual void set_fatal_error ()
 Sets fatal job error. More...
 
virtual void set_error ()
 Sets job error. More...
 
virtual bool is_done ()
 Checks whether the job is done. More...
 

Protected Types

using Log_event_ptr = Managed_event::Log_event_ptr
 Type alias for log event pointer. More...
 

Protected Member Functions

bool prepare (Thread_id thread_id) override
 Transaction prepare phase, control events execute fully in prepare phase. More...
 
bool commit (Thread_id thread_id) override
 Transaction commit phase, noop for control events. More...
 
bool commit_register (Thread_id thread_id) override
 Transaction "register for commit" phase, noop for control events. More...
 
bool apply_event (const Log_event_ptr &ev, THD *thd)
 Applies a single event (internal helper) More...
 
bool run_phase (Thread_id thread_id)
 Apply events from phase until phase ends or transaction ends. More...
 
bool check_rpco_conflict (Thread_id thread_id)
 Checks and handles RPCO conflict if designated. More...
 
void ensure_session (uint thread_id)
 Acquires session if not already obtained. More...
 
void finish_before_commit ()
 Called to clean up when a transaction is skipped (skipping commit phase): More...
 
bool can_be_retried () override
 Check if transaction can be retried. More...
 
void start_telemetry ()
 Internal function that starts the transaction telemetry tracking. More...
 
void finish_telemetry ()
 Internal function that finishes the transaction telemetry tracking. More...
 
void sync_rows_query_event_retention ()
 Keeps ROWS_QUERY event memory alive until Relay_log_info cleanup clears the query pointers that reference it. More...
 
- Protected Member Functions inherited from mysql::csa::Job_binlog
bool restart_internal (bool all)
 Restarts job with fetch metadata. More...
 

Protected Attributes

mysql::csa::Relay_context_ptr m_relay_context
 Relay context used to apply transaction. More...
 
Session_service_ptr m_session_service
 The session service to secure a THD and RLI objects when applying the job. More...
 
bool m_is_attached {false}
 Attach flag. Set to true when job is attached to the relay context. More...
 
Log_event_ptr m_commit_event
 Commit event, saved here for the commit phase in case of retry. More...
 
Log_event_ptr m_rows_query_event
 The currently active ROWS_QUERY event for statement-level processlist visibility. More...
 
Resource_monitor_ref m_resource_monitor
 Resource monitoring object for the current channel instance. More...
 
bool m_skip {false}
 Internal flag for skipping transaction used to check if we need to wait for unregistering from COM queue in commit phase. More...
 
bool m_skip_rollback {false}
 Internal flag to skip transaction rollback, used by the restart. More...
 
bool m_co_registered {false}
 Flag indicating that trx registered in the COM queue. More...
 
- Protected Attributes inherited from mysql::csa::Job_binlog
mysql::gtid::Gtid m_trx_gtid
 The GTID of the transaction. "<unknown>" if not available. More...
 
Channelm_channel
 The channel this transaction is coming from. More...
 
mysql::csa::Managed_event m_first_event
 The first event fetched to obtain GTID information. More...
 
uint32_t m_next_event {0}
 The cursor for the events to process. More...
 
Stat_monitor_ref m_stat_monitor
 Statistics monitoring object for the current instance. More...
 
std::shared_ptr< Fetchable_transactionm_fetch_metadata
 Information on how to fetch transaction data. More...
 
Transaction_phase m_phase {Transaction_phase::prepare}
 Transaction phase indicator: More...
 
- Protected Attributes inherited from mysql::csa::Job
bool m_is_error {false}
 Error flag for job. More...
 
bool m_is_fatal_error {false}
 Specifies if this job has a fatal error - we cannot retry it. More...
 
bool m_is_done {false}
 When set to true, job is done (successfully or not) More...
 
unsigned int m_max_retries
 Maximum number of retries for this job. More...
 
std::size_t m_id {0}
 This job sequence id. More...
 
Thread_id m_thread_id {0}
 Worker pool thread id. More...
 
std::size_t m_trx_retries {0}
 The number of times this job was retried. More...
 
std::reference_wrapper< std::atomic< bool > > m_applier_stop
 Channel stop flag used to interrupt wait loops. More...
 

Additional Inherited Members

- Static Protected Attributes inherited from mysql::csa::Job
static std::atomic< std::size_t > next_id = 0
 Next job id. Used to generate ids for jobs. More...
 

Detailed Description

Concrete class representing job applied by the applier.

Contains logic to execute (prepare, commit, retry) transaction.

Member Typedef Documentation

◆ Log_event_ptr

Type alias for log event pointer.

◆ Resource_monitor_ref

Constructor & Destructor Documentation

◆ Job_applier()

mysql::csa::Job_applier::Job_applier ( Channel channel,
unsigned int  max_retries,
std::shared_ptr< Fetchable_transaction fetch_object,
Stat_monitor_ref  stat_monitor,
Resource_monitor_ref  res_monitor 
)

Constructor.

Parameters
channelChannel this job comes from.
max_retriesMaximum number of retries for this job.
fetch_objectObject to fetch job data.
stat_monitorObject for monitoring statistics.
res_monitorObject for monitoring resources.

◆ ~Job_applier()

mysql::csa::Job_applier::~Job_applier ( )
overridevirtual

Destructor.

Member Function Documentation

◆ apply_event()

bool mysql::csa::Job_applier::apply_event ( const Log_event_ptr ev,
THD thd 
)
protected

Applies a single event (internal helper)

Parameters
evEvent to apply
thdTHD session to apply an event
Returns
False on success, true on error

◆ attach()

bool mysql::csa::Job_applier::attach ( Thread_id  thread_id)
overridevirtual

Attaches to relay context.

Parameters
thread_idThread pool worker identifier
Returns
False on success, true otherwise.

Implements mysql::csa::Job.

◆ can_be_retried()

bool mysql::csa::Job_applier::can_be_retried ( )
overrideprotectedvirtual

Check if transaction can be retried.

Returns
True if transaction can be retried, false otherwise

Reimplemented from mysql::csa::Job.

◆ check_rpco_conflict()

bool mysql::csa::Job_applier::check_rpco_conflict ( Thread_id  thread_id)
protected

Checks and handles RPCO conflict if designated.

Parameters
thread_idThread pool worker identifier
Return values
TrueRPCO conflict detected
FalseNo RPCO conflict

◆ commit()

bool mysql::csa::Job_applier::commit ( Thread_id  thread_id)
overrideprotectedvirtual

Transaction commit phase, noop for control events.

Parameters
thread_idThread pool worker identifier

Implements mysql::csa::Job_binlog.

◆ commit_register()

bool mysql::csa::Job_applier::commit_register ( Thread_id  thread_id)
overrideprotectedvirtual

Transaction "register for commit" phase, noop for control events.

Parameters
thread_idThread pool worker identifier
Returns
False on success, true on error

Implements mysql::csa::Job_binlog.

◆ detach()

bool mysql::csa::Job_applier::detach ( Thread_id  thread_id)
overridevirtual

Detaches from relay context.

Parameters
thread_idThread pool worker identifier
Returns
False on success, true otherwise.

Implements mysql::csa::Job.

◆ ensure_session()

void mysql::csa::Job_applier::ensure_session ( uint  thread_id)
protected

Acquires session if not already obtained.

Prepares parallel worker context

Parameters
thread_idThread pool worker identifier

◆ finish_before_commit()

void mysql::csa::Job_applier::finish_before_commit ( )
protected

Called to clean up when a transaction is skipped (skipping commit phase):

  • unregister from commit order manager

◆ finish_telemetry()

void mysql::csa::Job_applier::finish_telemetry ( )
protected

Internal function that finishes the transaction telemetry tracking.

◆ is_attached()

bool mysql::csa::Job_applier::is_attached ( ) const
overridevirtual

Checks whether this job is attached to relay log context.

Returns
True if attached. False otherwise.

Implements mysql::csa::Job.

◆ prepare()

bool mysql::csa::Job_applier::prepare ( Thread_id  thread_id)
overrideprotectedvirtual

Transaction prepare phase, control events execute fully in prepare phase.

Parameters
thread_idThread pool worker identifier

Implements mysql::csa::Job_binlog.

◆ prepare_for_apply()

void mysql::csa::Job_applier::prepare_for_apply ( Session_service_ptr  ss)

Prepares this job to be applied.

Parameters
ssPointer to session service.

◆ restart()

bool mysql::csa::Job_applier::restart ( )
overridevirtual

Restarts internal state.

Prepares for retry.

Returns
False on success, true otherwise.

Reimplemented from mysql::csa::Job.

◆ run_phase()

bool mysql::csa::Job_applier::run_phase ( Thread_id  thread_id)
protected

Apply events from phase until phase ends or transaction ends.

Parameters
thread_idThread pool worker identifier
Returns
False on success, true otherwise

◆ set_failure()

void mysql::csa::Job_applier::set_failure ( )
overridevirtual

Sets job failure.

Reimplemented from mysql::csa::Job.

◆ start_telemetry()

void mysql::csa::Job_applier::start_telemetry ( )
protected

Internal function that starts the transaction telemetry tracking.

◆ sync_rows_query_event_retention()

void mysql::csa::Job_applier::sync_rows_query_event_retention ( )
protected

Keeps ROWS_QUERY event memory alive until Relay_log_info cleanup clears the query pointers that reference it.

◆ to_string()

std::string mysql::csa::Job_applier::to_string ( )
overridevirtual

Presents job identifier.

Returns
String with job identifier.

Reimplemented from mysql::csa::Job.

◆ wait_for_rollback_and_restart()

bool mysql::csa::Job_applier::wait_for_rollback_and_restart ( )

Internal function to wait for rollback and restart transaction in case deadlock has been found.

Returns
True if transaction cannot be rolled back or retried. False otherwise

Member Data Documentation

◆ m_co_registered

bool mysql::csa::Job_applier::m_co_registered {false}
protected

Flag indicating that trx registered in the COM queue.

◆ m_commit_event

Log_event_ptr mysql::csa::Job_applier::m_commit_event
protected

Commit event, saved here for the commit phase in case of retry.

◆ m_is_attached

bool mysql::csa::Job_applier::m_is_attached {false}
protected

Attach flag. Set to true when job is attached to the relay context.

◆ m_relay_context

mysql::csa::Relay_context_ptr mysql::csa::Job_applier::m_relay_context
protected

Relay context used to apply transaction.

◆ m_resource_monitor

Resource_monitor_ref mysql::csa::Job_applier::m_resource_monitor
protected

Resource monitoring object for the current channel instance.

◆ m_rows_query_event

Log_event_ptr mysql::csa::Job_applier::m_rows_query_event
protected

The currently active ROWS_QUERY event for statement-level processlist visibility.

◆ m_session_service

Session_service_ptr mysql::csa::Job_applier::m_session_service
protected

The session service to secure a THD and RLI objects when applying the job.

◆ m_skip

bool mysql::csa::Job_applier::m_skip {false}
protected

Internal flag for skipping transaction used to check if we need to wait for unregistering from COM queue in commit phase.

◆ m_skip_rollback

bool mysql::csa::Job_applier::m_skip_rollback {false}
protected

Internal flag to skip transaction rollback, used by the restart.


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