MySQL 26.7.0
Source Code Documentation
mysql::csa::Job_binlog Class Referenceabstract

The Job_binlog class is a container that holds a buffer of fetchable events and context for the transaction to be applied in change streams. More...

#include <job_binlog.h>

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

Public Types

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_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...
 
virtual bool prepare (Thread_id thread_id)=0
 Run prepare phase of this transaction. More...
 
virtual bool commit (Thread_id thread_id)=0
 Run commit phase of this transaction. More...
 
virtual bool commit_register (Thread_id thread_id)=0
 Register the transaction for commit phase. 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...
 
virtual bool attach (Thread_id thread_id)=0
 Attaches the job. More...
 
Thread_id get_attach_id () const
 Returns an id based on which the job attaches to applier context. More...
 
virtual bool detach (Thread_id thread_id)=0
 Detaches the job. 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 bool can_be_retried ()
 Checks whether this job can be retried. 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_failure ()
 Global job failure callback. 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...
 
virtual bool is_attached () const =0
 Checks whether the job is currently attached. More...
 
virtual std::string to_string ()
 Converts the job to a string representation. More...
 

Protected Member Functions

bool restart_internal (bool all)
 Restarts job with fetch metadata. More...
 

Protected Attributes

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

The Job_binlog class is a container that holds a buffer of fetchable events and context for the transaction to be applied in change streams.

The context includes the originating channel and parallelization window information.

Member Typedef Documentation

◆ Stat_monitor_ref

Alias to Statistics_instance_monitor_ref contained in the scheduler library.

Constructor & Destructor Documentation

◆ Job_binlog() [1/2]

mysql::csa::Job_binlog::Job_binlog ( const Job_binlog )
delete

Deleted copy constructor.

◆ Job_binlog() [2/2]

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

Constructor for Job_binlog.

Parameters
channelThe channel this job is coming from.
max_retriesThe maximum number of retries for this job.
fetch_objectThe object to fetch job data from.
stat_monitorObject for monitoring statistics

◆ ~Job_binlog()

mysql::csa::Job_binlog::~Job_binlog ( )
overridevirtual

Destructor for Job_binlog.

Member Function Documentation

◆ commit()

virtual bool mysql::csa::Job_binlog::commit ( Thread_id  thread_id)
pure virtual

Run commit phase of this transaction.

Parameters
thread_idThread pool worker identifier
Returns
False on success. True on failure

Implemented in mysql::csa::Job_applier.

◆ commit_register()

virtual bool mysql::csa::Job_binlog::commit_register ( Thread_id  thread_id)
pure virtual

Register the transaction for commit phase.

Parameters
thread_idThread pool worker identifier
Returns
False on success. True on failure

Implemented in mysql::csa::Job_applier.

◆ get_channel()

Channel * mysql::csa::Job_binlog::get_channel ( ) const

Gets the channel this job comes from.

Returns
Pointer to the channel this job comes from.

◆ get_channel_id()

const std::string & mysql::csa::Job_binlog::get_channel_id ( ) const

Gets the transaction identifier as a string.

Returns
The transaction identifier as a string.

◆ get_instance_id()

unsigned int mysql::csa::Job_binlog::get_instance_id ( ) const
overridevirtual

Obtains unique instance id to gather statistics separately for different "instances".

Since we want to gather statistics separately for different. channels, this is set to channel id. The instance ID is used as a key to aggregate statistics for each channel.

Returns
int Unique identifier for the instance (channel ID).

Reimplemented from mysql::csa::Job.

◆ get_last_committed()

unsigned long long mysql::csa::Job_binlog::get_last_committed ( ) const

Gets the last committed value to determine when this transaction can run.

Returns
The transaction's last committed value.

◆ get_sequence_number()

unsigned long long mysql::csa::Job_binlog::get_sequence_number ( ) const

Gets the sequence number of this transaction to determine when it can run and commit.

Returns
The transaction's sequence number.

◆ get_trx_gtid()

const mysql::gtid::Gtid & mysql::csa::Job_binlog::get_trx_gtid ( ) const
inline

Gets the transaction GTID.

Returns
The transaction GTID.

◆ get_trx_id()

std::string mysql::csa::Job_binlog::get_trx_id ( ) const

Get transaction GTID.

Returns
Transaction GTID

◆ get_trx_length()

unsigned long long mysql::csa::Job_binlog::get_trx_length ( ) const

Gets the transaction length.

Returns
The transaction length.

◆ is_complete()

bool mysql::csa::Job_binlog::is_complete ( )
virtual

Checks if this transaction has finished fetching.

Returns
True if complete, false otherwise.

◆ is_trx()

bool mysql::csa::Job_binlog::is_trx ( ) const
overridevirtual

Checks whether handled job is a transaction (supports two phases)

Returns
True if handled job is a transaction

Reimplemented from mysql::csa::Job.

◆ operator=()

Job_binlog & mysql::csa::Job_binlog::operator= ( const Job_binlog )
delete

Deleted assignment operator.

◆ prepare()

virtual bool mysql::csa::Job_binlog::prepare ( Thread_id  thread_id)
pure virtual

Run prepare phase of this transaction.

Parameters
thread_idThread pool worker identifier
Returns
False on success. True on failure

Implemented in mysql::csa::Job_applier.

◆ restart()

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

Restarts the job and prepares for retry.

Returns
False on success, true on failure.

Reimplemented from mysql::csa::Job.

◆ restart_internal()

bool mysql::csa::Job_binlog::restart_internal ( bool  all)
protected

Restarts job with fetch metadata.

Parameters
allWhen true, this is a retry and all object states must be restarted

◆ run()

bool mysql::csa::Job_binlog::run ( Thread_id  thread_id)
overridevirtual

Binlog job needs to be called twice to apply transaction:

  • 1st run - prepare
  • 2nd run - commit Applier job may run up to slave_trans_retries times. If we retry "prepare" phase, nothing changes. If we retry "commit", we run both phases, prepare + commit.
    Parameters
    thread_idThread pool worker identifier

Implements mysql::csa::Job.

◆ set_done()

void mysql::csa::Job_binlog::set_done ( )
overridevirtual

Mark the transaction as done (done with failure or done successfully.

Reimplemented from mysql::csa::Job.

◆ set_success()

void mysql::csa::Job_binlog::set_success ( )
overridevirtual

success callback

Reimplemented from mysql::csa::Job.

◆ skip()

void mysql::csa::Job_binlog::skip ( )
overridevirtual

Skip this job, considered complete and done without failure.

Reimplemented from mysql::csa::Job.

Member Data Documentation

◆ m_channel

Channel* mysql::csa::Job_binlog::m_channel
protected

The channel this transaction is coming from.

◆ m_fetch_metadata

std::shared_ptr<Fetchable_transaction> mysql::csa::Job_binlog::m_fetch_metadata
protected

Information on how to fetch transaction data.

◆ m_first_event

mysql::csa::Managed_event mysql::csa::Job_binlog::m_first_event
protected

The first event fetched to obtain GTID information.

◆ m_next_event

uint32_t mysql::csa::Job_binlog::m_next_event {0}
protected

The cursor for the events to process.

◆ m_phase

Transaction_phase mysql::csa::Job_binlog::m_phase {Transaction_phase::prepare}
protected

Transaction phase indicator:

  • prepare - this state means that transaction needs to be prepared
  • commit - this state means that transaction needs to be committed
  • done - transaction is committed
  • retry_commit - transaction prepare phase succeeded, but commit did not and we need to retry full transaction in one run.

◆ m_stat_monitor

Stat_monitor_ref mysql::csa::Job_binlog::m_stat_monitor
protected

Statistics monitoring object for the current instance.

◆ m_trx_gtid

mysql::gtid::Gtid mysql::csa::Job_binlog::m_trx_gtid
protected

The GTID of the transaction. "<unknown>" if not available.


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