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

A job represents a single unit of work applied by worker pool threads. More...

#include <job.h>

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

Public Types

using Thread_id = unsigned int
 Type alias for thread identifier. More...
 

Public Member Functions

 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 unsigned int get_instance_id () const
 Obtains unique instance id to gather statistics separately for different "instances". More...
 
virtual bool is_trx () const
 Checks whether handled job is a transaction (supports two phases) More...
 
virtual bool restart ()
 Resets the job for retrying. More...
 
virtual bool run (Thread_id thread_id)=0
 Implements execution of the full job or a single job phase. 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_success ()
 Global job success callback. 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 void set_done ()
 Sets this job as done. 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...
 
virtual void skip ()
 Skip this job, considered complete and done without failure. More...
 

Protected Attributes

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

Static Protected Attributes

static std::atomic< std::size_t > next_id = 0
 Next job id. Used to generate ids for jobs. More...
 

Detailed Description

A job represents a single unit of work applied by worker pool threads.

Job defines execution path, the number of times the job runs, the number of retries, how job attaches to applier context and detaches from it. This is an abstract class for a job.

Member Typedef Documentation

◆ Thread_id

using mysql::csa::Job::Thread_id = unsigned int

Type alias for thread identifier.

Constructor & Destructor Documentation

◆ Job() [1/2]

mysql::csa::Job::Job ( const Job )
delete

Deleted copy constructor.

◆ Job() [2/2]

mysql::csa::Job::Job ( unsigned int  max_retries)

Constructor.

Parameters
max_retriesThe number of times a job can be retried.

◆ ~Job()

mysql::csa::Job::~Job ( )
virtual

Destructor.

Member Function Documentation

◆ attach()

virtual bool mysql::csa::Job::attach ( Thread_id  thread_id)
pure virtual

Attaches the job.

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

Implemented in mysql::csa::Job_applier.

◆ can_be_retried()

bool mysql::csa::Job::can_be_retried ( )
virtual

Checks whether this job can be retried.

Returns
True if the job can be retried. False otherwise.

Reimplemented in mysql::csa::Job_applier.

◆ detach()

virtual bool mysql::csa::Job::detach ( Thread_id  thread_id)
pure virtual

Detaches the job.

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

Implemented in mysql::csa::Job_applier.

◆ get_attach_id()

Job::Thread_id mysql::csa::Job::get_attach_id ( ) const

Returns an id based on which the job attaches to applier context.

Returns
Attach id

◆ get_id()

std::size_t mysql::csa::Job::get_id ( ) const
virtual

Gets the job identifier.

Returns
Job identifier - job sequence number.

◆ get_instance_id()

unsigned int mysql::csa::Job::get_instance_id ( ) const
virtual

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

Returns
Instance unique identifier

Reimplemented in mysql::csa::Job_binlog.

◆ get_retries()

unsigned int mysql::csa::Job::get_retries ( ) const
virtual

Gets the number of retries for this job.

Returns
The number of times this job was retried.

◆ inc_retries()

void mysql::csa::Job::inc_retries ( )
virtual

Increments the number of retries for the job.

◆ is_attached()

virtual bool mysql::csa::Job::is_attached ( ) const
pure virtual

Checks whether the job is currently attached.

Returns
True if attached, false if detached.

Implemented in mysql::csa::Job_applier.

◆ is_done()

bool mysql::csa::Job::is_done ( )
virtual

Checks whether the job is done.

Returns
True if the job is done, false otherwise.

◆ is_error()

bool mysql::csa::Job::is_error ( )
virtual

Checks whether this job is in error state.

Returns
True if the job errored out. False otherwise.

◆ is_fatal_error()

bool mysql::csa::Job::is_fatal_error ( )
virtual

Checks whether job has a fatal, non-recoverable error.

Returns
True when fatal error detected. False otherwise.

◆ is_stopped()

bool mysql::csa::Job::is_stopped ( ) const
virtual

Checks whether applier stop has been requested for this job.

Returns
True if stop was requested. False otherwise.

◆ is_trx()

bool mysql::csa::Job::is_trx ( ) const
virtual

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

Returns
True if handled job is a transaction

Reimplemented in mysql::csa::Job_binlog.

◆ operator=()

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

Deleted assignment operator.

◆ restart()

bool mysql::csa::Job::restart ( )
virtual

Resets the job for retrying.

This must be called before retrying, so that the internal pointers are reset to the proper place.

Returns
True on error. False on success.

Reimplemented in mysql::csa::Job_applier, and mysql::csa::Job_binlog.

◆ run()

virtual bool mysql::csa::Job::run ( Thread_id  thread_id)
pure virtual

Implements execution of the full job or a single job phase.

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

Implemented in mysql::csa::Job_binlog.

◆ set_applier_stop()

void mysql::csa::Job::set_applier_stop ( std::atomic< bool > &  applier_stop)
virtual

Injects the applier stop flag for this job.

Parameters
applier_stopStop flag reference.

◆ set_done()

void mysql::csa::Job::set_done ( )
virtual

Sets this job as done.

Reimplemented in mysql::csa::Job_binlog.

◆ set_error()

void mysql::csa::Job::set_error ( )
virtual

Sets job error.

◆ set_failure()

void mysql::csa::Job::set_failure ( )
virtual

Global job failure callback.

Reimplemented in mysql::csa::Job_applier.

◆ set_fatal_error()

void mysql::csa::Job::set_fatal_error ( )
virtual

Sets fatal job error.

◆ set_success()

void mysql::csa::Job::set_success ( )
virtual

Global job success callback.

Reimplemented in mysql::csa::Job_binlog.

◆ skip()

virtual void mysql::csa::Job::skip ( )
inlinevirtual

Skip this job, considered complete and done without failure.

Reimplemented in mysql::csa::Job_binlog.

◆ to_string()

std::string mysql::csa::Job::to_string ( )
virtual

Converts the job to a string representation.

Returns
String representation of the job.

Reimplemented in mysql::csa::Job_applier.

Member Data Documentation

◆ m_applier_stop

std::reference_wrapper<std::atomic<bool> > mysql::csa::Job::m_applier_stop
protected

Channel stop flag used to interrupt wait loops.

◆ m_id

std::size_t mysql::csa::Job::m_id {0}
protected

This job sequence id.

◆ m_is_done

bool mysql::csa::Job::m_is_done {false}
protected

When set to true, job is done (successfully or not)

◆ m_is_error

bool mysql::csa::Job::m_is_error {false}
protected

Error flag for job.

◆ m_is_fatal_error

bool mysql::csa::Job::m_is_fatal_error {false}
protected

Specifies if this job has a fatal error - we cannot retry it.

◆ m_max_retries

unsigned int mysql::csa::Job::m_max_retries
protected

Maximum number of retries for this job.

◆ m_thread_id

Thread_id mysql::csa::Job::m_thread_id {0}
protected

Worker pool thread id.

◆ m_trx_retries

std::size_t mysql::csa::Job::m_trx_retries {0}
protected

The number of times this job was retried.

◆ next_id

std::atomic< std::size_t > mysql::csa::Job::next_id = 0
staticprotected

Next job id. Used to generate ids for jobs.


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