24#ifndef APPLIER_INCLUDE
25#define APPLIER_INCLUDE
47#define ACTION_PACKET_TYPE 2
48#define SINGLE_PRIMARY_PACKET_TYPE 4
49#define SYNC_BEFORE_EXECUTION_PACKET_TYPE 5
50#define TRANSACTION_PREPARED_PACKET_TYPE 6
51#define LEAVING_MEMBERS_PACKET_TYPE 7
52#define RECOVERY_METADATA_PROCESSING_PACKET_TYPE 8
53#define ERROR_PACKET_TYPE 9
56#define APPLIER_GTID_CHECK_TIMEOUT_ERROR -1
57#define APPLIER_RELAY_LOG_NOT_INITED -2
58#define APPLIER_THREAD_ABORTED -3
145 std::shared_ptr<Continuation> checkpoint_condition_arg)
240 const std::vector<Gcs_member_identifier> &leaving_members)
281 bool *abort_flag,
bool wait_for_execution =
true) = 0;
285 double timeout,
bool check_and_purge_partial_transactions) = 0;
287 std::shared_ptr<Continuation> checkpoint_condition,
bool *abort_flag,
288 bool update_THD_status =
true) = 0;
291 std::string &retrieved_set,
double timeout,
292 bool update_THD_status =
true) = 0;
310 std::list<Gcs_member_identifier> *online_members,
317 std::shared_ptr<Continuation> checkpoint_condition) = 0;
384 ulong stop_timeout,
rpl_sidno group_sidno,
433 std::list<Gcs_member_identifier> *online_members,
436 new Data_packet(data, len,
key, consistency_level, online_members));
631 bool *abort_flag,
bool wait_for_execution =
true)
override;
670 double timeout,
bool check_and_purge_partial_transactions)
override;
695 std::shared_ptr<Continuation> checkpoint_condition,
bool *abort_flag,
696 bool update_THD_status =
true)
override;
725 bool update_THD_status =
true)
override;
769 std::shared_ptr<Continuation> checkpoint_condition)
override;
894 struct timespec abstime;
#define ERROR_PACKET_TYPE
Make the applier fail.
Definition: applier.h:53
#define RECOVERY_METADATA_PROCESSING_PACKET_TYPE
Definition: applier.h:52
#define ACTION_PACKET_TYPE
Definition: applier.h:47
char applier_module_channel_name[]
Definition: applier.cc:49
#define LEAVING_MEMBERS_PACKET_TYPE
Definition: applier.h:51
enum_applier_state
Definition: applier.h:270
@ APPLIER_STATE_ON
Definition: applier.h:271
@ APPLIER_STATE_OFF
Definition: applier.h:272
@ APPLIER_ERROR
Definition: applier.h:273
#define TRANSACTION_PREPARED_PACKET_TYPE
Definition: applier.h:50
enum enum_applier_state Member_applier_state
#define SINGLE_PRIMARY_PACKET_TYPE
Definition: applier.h:48
#define SYNC_BEFORE_EXECUTION_PACKET_TYPE
Definition: applier.h:49
enum_packet_action
Definition: applier.h:63
@ TERMINATION_PACKET
Definition: applier.h:64
@ ACTION_NUMBER
Definition: applier.h:67
@ SUSPENSION_PACKET
Definition: applier.h:65
@ CHECKPOINT_PACKET
Definition: applier.h:66
A packet to control the applier in a event oriented way.
Definition: applier.h:74
Action_packet(enum_packet_action action)
Create a new action packet.
Definition: applier.h:80
enum_packet_action packet_action
Definition: applier.h:85
~Action_packet() override=default
Definition: applier_channel_state_observer.h:30
Definition: applier.h:276
virtual Pipeline_stats_member_collector * get_pipeline_stats_member_collector()=0
virtual bool get_retrieved_gtid_set(std::string &retrieved_set)=0
virtual ~Applier_module_interface()=default
virtual int wait_for_applier_complete_suspension(bool *abort_flag, bool wait_for_execution=true)=0
virtual void add_packet(Packet *packet)=0
virtual size_t get_message_queue_size()=0
virtual Certification_handler * get_certification_handler()=0
virtual Flow_control_module * get_flow_control_module()=0
virtual int wait_for_applier_event_execution(double timeout, bool check_and_purge_partial_transactions)=0
virtual int wait_for_applier_event_execution(std::string &retrieved_set, double timeout, bool update_THD_status=true)=0
virtual void add_sync_before_execution_action_packet(Sync_before_execution_action_packet *packet)=0
virtual void add_leaving_members_action_packet(Leaving_members_action_packet *packet)=0
virtual void awake_applier_module()=0
virtual int purge_applier_queue_and_restart_applier_module()=0
virtual Member_applier_state get_applier_status()=0
virtual int handle(const uchar *data, ulong len, enum_group_replication_consistency_level consistency_level, std::list< Gcs_member_identifier > *online_members, PSI_memory_key key)=0
virtual void add_transaction_prepared_action_packet(Transaction_prepared_action_packet *packet)=0
virtual void add_suspension_packet()=0
virtual bool wait_for_current_events_execution(std::shared_ptr< Continuation > checkpoint_condition, bool *abort_flag, bool update_THD_status=true)=0
virtual void add_metadata_processing_packet(Recovery_metadata_processing_packets *packet)=0
virtual void run_flow_control_step()=0
virtual void add_view_change_packet(View_change_packet *packet)=0
virtual bool queue_and_wait_on_queue_checkpoint(std::shared_ptr< Continuation > checkpoint_condition)=0
virtual void add_single_primary_action_packet(Single_primary_action_packet *packet)=0
virtual int handle_pipeline_action(Pipeline_action *action)=0
virtual void interrupt_applier_suspension_wait()=0
Definition: applier.h:322
~Applier_module() override
Definition: applier.cc:77
int apply_data_packet(Data_packet *data_packet, Format_description_log_event *fde_evt, Continuation *cont)
Apply a Data packet received by the applier.
Definition: applier.cc:345
Certification_handler * get_certification_handler() override
Returns the handler instance in the applier module responsible for certification.
Definition: applier.cc:989
bool is_applier_thread_aborted()
Is the applier marked for shutdown?
Definition: applier.h:357
void add_termination_packet()
Queues a packet that will make the applier module terminate it's handling process.
Definition: applier.h:528
Plugin_stage_monitor_handler stage_handler
Definition: applier.h:979
int applier_error
Definition: applier.h:948
void clean_applier_thread_context()
Cleans the thread context for the applier thread This includes such tasks as removing the thread from...
Definition: applier.cc:230
bool apply_action_packet(Action_packet *action_packet)
Apply an action packet received by the applier.
Definition: applier.cc:247
int wait_for_applier_complete_suspension(bool *abort_flag, bool wait_for_execution=true) override
Waits for the applier to suspend and apply all the transactions previous to the suspend request.
Definition: applier.cc:845
int applier_thread_handle()
Runs the applier thread process, reading events and processing them.
Definition: applier.cc:444
Member_applier_state get_applier_status() override
Definition: applier.h:746
bool wait_for_current_events_execution(std::shared_ptr< Continuation > checkpoint_condition, bool *abort_flag, bool update_THD_status=true) override
Waits for the execution of all current events by part of the current SQL applier.
Definition: applier.cc:967
int setup_pipeline_handlers()
Configure the applier pipeline handlers.
Definition: applier.cc:164
bool applier_killed_status
Definition: applier.h:950
void set_stop_wait_timeout(ulong timeout)
Sets the applier shutdown timeout.
Definition: applier.h:481
bool m_ignore_applier_errors_during_stop
Definition: applier.h:952
my_thread_handle applier_pthd
Definition: applier.h:932
int apply_single_primary_action_packet(Single_primary_action_packet *packet)
Apply an single primary action packet received by the applier.
Definition: applier.cc:403
void ignore_errors_during_stop(bool ignore_errors)
Check whether to ignore applier errors during stop or not.
Definition: applier.h:505
int purge_applier_queue_and_restart_applier_module() override
Purges the relay logs and restarts the applier thread.
Definition: applier.cc:121
mysql_mutex_t run_lock
Definition: applier.h:941
int apply_transaction_prepared_action_packet(Transaction_prepared_action_packet *packet)
Apply a transaction prepared action packet received by the applier.
Definition: applier.cc:422
bool suspended
Definition: applier.h:960
int setup_applier_module(Handler_pipeline_type pipeline_type, bool reset_logs, ulong stop_timeout, rpl_sidno group_sidno, ulonglong gtid_assignment_block_size)
Configure the applier pipeline according to the given configuration.
Definition: applier.cc:95
void add_suspension_packet() override
Queues a packet that will eventually make the applier module suspend.
Definition: applier.h:517
mysql_cond_t suspension_waiting_condition
Definition: applier.h:963
rpl_sidno group_replication_sidno
Definition: applier.h:937
int intersect_group_executed_sets(std::vector< std::string > >id_sets, Gtid_set *output_set)
This method calculates the intersection of the given sets passed as a list of strings.
Definition: applier.cc:997
bool is_running()
Is the applier running?
Definition: applier.h:368
void add_packet(Packet *packet) override
Generic add packet method.
Definition: applier.h:534
void add_single_primary_action_packet(Single_primary_action_packet *packet) override
Queues a single primary action packet into the applier.
Definition: applier.h:561
int apply_leaving_members_action_packet(Leaving_members_action_packet *packet)
Apply a leaving members action packet received by the applier.
Definition: applier.cc:437
void suspend_applier_module()
Suspends the applier module, being transactions still queued in the incoming queue.
Definition: applier.h:883
void set_applier_thread_context()
Set the thread context for the applier thread.
Definition: applier.cc:190
int initialize_applier_thread()
Initializes and launches the applier thread.
Definition: applier.cc:687
int terminate_applier_thread()
Terminates the applier thread.
Definition: applier.cc:739
size_t get_message_queue_size() override
Returns the applier module's queue size.
Definition: applier.h:744
bool reset_applier_logs
Definition: applier.h:936
void inform_of_applier_stop(char *channel_name, bool aborted)
This method informs the applier module that an applying thread stopped.
Definition: applier.cc:817
bool is_applier_thread_waiting()
Checks if the applier, and its workers when parallel applier is enabled, has already consumed all rel...
Definition: applier.cc:900
Flow_control_module flow_control_module
Definition: applier.h:978
void add_metadata_processing_packet(Recovery_metadata_processing_packets *packet) override
Definition: applier.h:549
int wait_for_applier_event_execution(double timeout, bool check_and_purge_partial_transactions) override
Waits for the execution of all events by part of the current SQL applier.
Definition: applier.cc:912
int terminate_applier_pipeline()
Terminates the pipeline, shutting down the handlers and deleting them.
Definition: applier.cc:724
Event_handler * pipeline
Definition: applier.h:969
bool get_retrieved_gtid_set(std::string &retrieved_set) override
Returns the retrieved gtid set for the applier channel.
Definition: applier.cc:938
int handle(const uchar *data, ulong len, enum_group_replication_consistency_level consistency_level, std::list< Gcs_member_identifier > *online_members, PSI_memory_key key) override
Queues the packet coming from the reader for future application.
Definition: applier.h:431
bool applier_aborted
Definition: applier.h:946
Pipeline_stats_member_collector * get_pipeline_stats_member_collector() override
Definition: applier.h:755
mysql_mutex_t suspend_lock
Definition: applier.h:956
int apply_view_change_packet(View_change_packet *view_change_packet, Format_description_log_event *fde_evt, Continuation *cont)
Apply a View Change packet received by the applier.
Definition: applier.cc:269
void awake_applier_module() override
Awakes the applier module.
Definition: applier.h:610
Pipeline_member_stats * get_local_pipeline_stats()
Return the local applier stats.
Definition: applier.cc:1062
bool queue_and_wait_on_queue_checkpoint(std::shared_ptr< Continuation > checkpoint_condition) override
Definition: applier.cc:1056
int inject_event_into_pipeline(Pipeline_event *pevent, Continuation *cont)
Injects an event into the pipeline and waits for its handling.
Definition: applier.cc:236
thread_state applier_thd_state
Definition: applier.h:944
ulonglong gtid_assignment_block_size
Definition: applier.h:938
int apply_sync_before_execution_action_packet(Sync_before_execution_action_packet *packet)
Apply a synchronization before execution action packet received by the applier.
Definition: applier.cc:430
void add_view_change_packet(View_change_packet *packet) override
Queues a view change packet into the applier.
Definition: applier.h:545
void add_sync_before_execution_action_packet(Sync_before_execution_action_packet *packet) override
Queues a synchronization before execution action packet into the applier.
Definition: applier.h:585
THD * applier_thd
Definition: applier.h:933
mysql_cond_t suspend_cond
Definition: applier.h:958
int handle_pipeline_action(Pipeline_action *action) override
Gives the pipeline an action for execution.
Definition: applier.h:449
Pipeline_stats_member_collector pipeline_stats_member_collector
Definition: applier.h:977
void run_flow_control_step() override
Definition: applier.h:764
mysql_cond_t run_cond
Definition: applier.h:942
virtual void queue_certification_enabling_packet()
Queues a single a packet that will enable certification on this member.
Definition: applier.cc:1051
ulong stop_wait_timeout
Definition: applier.h:972
Applier_module()
Definition: applier.cc:58
int apply_metadata_processing_packet(Recovery_metadata_processing_packets *metadata_processing_packet)
Apply a Recovery metadata processing information received from the GCS.
Definition: applier.cc:331
void interrupt_applier_suspension_wait() override
Interrupts the current applier waiting process either for it's suspension or it's wait for the consum...
Definition: applier.cc:894
Flow_control_module * get_flow_control_module() override
Definition: applier.h:760
Applier_channel_state_observer * applier_channel_observer
Definition: applier.h:975
void add_leaving_members_action_packet(Leaving_members_action_packet *packet) override
Queues a leaving members action packet into the applier.
Definition: applier.h:597
Synchronized_queue< Packet * > * incoming
Definition: applier.h:966
void add_transaction_prepared_action_packet(Transaction_prepared_action_packet *packet) override
Queues a transaction prepared action packet into the applier.
Definition: applier.h:573
Definition: certification_handler.h:32
Class used to wait on the execution of some action.
Definition: pipeline_interfaces.h:536
A wrapper for raw network packets.
Definition: pipeline_interfaces.h:76
A packet to inform the applier it should fail.
Definition: applier.h:252
const char * m_error_message
The error message for the failure process.
Definition: applier.h:267
~Error_action_packet() override=default
Error_action_packet(const char *error_message)
Create a new error packet.
Definition: applier.h:256
const char * get_error_message()
Returns the error message for the failure.
Definition: applier.h:263
Interface for the application of events, them being packets or log events.
Definition: pipeline_interfaces.h:663
virtual int handle_action(Pipeline_action *action)=0
Handling of an action as defined in the handler implementation.
The pipeline stats aggregator of all group members stats and flow control module.
Definition: pipeline_stats.h:608
void flow_control_step(Pipeline_stats_member_collector *)
Evaluate the information received in the last flow control period and adjust the system parameters ac...
Definition: pipeline_stats.cc:749
It represents the identity of a group member within a certain group.
Definition: gcs_member_identifier.h:40
Represents a set of GTIDs.
Definition: rpl_gtid.h:1557
Action to configure existing applier handlers.
Definition: pipeline_handlers.h:105
A packet to inform pipeline listeners of leaving members, this packet will be handled on the global m...
Definition: applier.h:232
const std::vector< Gcs_member_identifier > m_leaving_members
Definition: applier.h:246
~Leaving_members_action_packet() override=default
Leaving_members_action_packet(const std::vector< Gcs_member_identifier > &leaving_members)
Create a new leaving members packet.
Definition: applier.h:239
A generic interface for different kinds of packets.
Definition: pipeline_interfaces.h:51
A wrapper for pipeline actions.
Definition: pipeline_interfaces.h:633
A wrapper for log events/packets.
Definition: pipeline_interfaces.h:167
Computed statistics per member.
Definition: pipeline_stats.h:433
The pipeline collector for the local member stats.
Definition: pipeline_stats.h:284
Definition: stage_monitor_handler.h:30
int set_stage(PSI_stage_key key, const char *file, int line, ulonglong estimated_work, ulonglong work_completed)
Set that a new stage is now in progress.
Definition: stage_monitor_handler.cc:79
A packet to wait for queue consumption.
Definition: applier.h:139
std::shared_ptr< Continuation > checkpoint_condition
If we discard a packet.
Definition: applier.h:153
void signal_checkpoint_reached()
Definition: applier.h:149
Queue_checkpoint_packet(std::shared_ptr< Continuation > checkpoint_condition_arg)
Create a new Queue_checkpoint_packet packet.
Definition: applier.h:144
A packet to send new primary election related info to the applier.
Definition: applier.h:118
enum_action
Definition: applier.h:120
@ NEW_PRIMARY
Definition: applier.h:120
@ QUEUE_APPLIED
Definition: applier.h:120
Single_primary_action_packet(enum enum_action action_arg)
Create a new single primary action packet with associated data.
Definition: applier.h:127
~Single_primary_action_packet() override=default
enum enum_action action
Definition: applier.h:132
A packet to request a synchronization point on the global message order on a given member before tran...
Definition: applier.h:206
const Gcs_member_identifier m_gcs_member_id
Definition: applier.h:223
Sync_before_execution_action_packet(my_thread_id thread_id, const Gcs_member_identifier &gcs_member_id)
Create a new synchronization point request.
Definition: applier.h:214
const my_thread_id m_thread_id
Definition: applier.h:222
~Sync_before_execution_action_packet() override=default
Definition: plugin_utils.h:182
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
std::atomic< killed_state > killed
Definition: sql_class.h:2745
A packet to inform that a given member did prepare a given transaction.
Definition: applier.h:160
const gr::Gtid_tsid & get_tsid() const
tsid accessor
Definition: applier.h:191
const Gcs_member_identifier m_gcs_member_id
Definition: applier.h:187
const rpl_gno m_gno
Definition: applier.h:186
~Transaction_prepared_action_packet() override=default
gr::Gtid_tsid m_tsid
Definition: applier.h:198
Transaction_prepared_action_packet(const gr::Gtid_tsid &tsid, bool is_tsid_specified, rpl_gno gno, const Gcs_member_identifier &gcs_member_id)
Create a new transaction prepared action.
Definition: applier.h:171
bool is_tsid_specified() const
returns information on whether TSID is specified for this trx
Definition: applier.h:195
const bool m_tsid_specified
Definition: applier.h:185
A packet to send view change related info to the applier.
Definition: pipeline_interfaces.h:116
Represents Transaction Source Identifier which is composed of source UUID and transaction tag.
Definition: tsid.h:44
#define mysql_cond_timedwait(C, M, T)
Definition: mysql_cond.h:51
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
void set_timespec(struct timespec *abstime, Timeout_type sec)
Set the value of a timespec object to the current time plus a number of seconds using seconds.
Definition: my_systime.cc:84
static my_thread_id thread_id
Definition: my_thr_init.cc:63
uint32 my_thread_id
Definition: my_thread_local.h:34
int(* mysql_cond_broadcast)(mysql_cond_t *that, const char *src_file, unsigned int src_line)
Definition: mysql_cond_service.h:52
static bool ignore_errors
Definition: mysqlcheck.cc:62
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
Handler_pipeline_type
Definition: pipeline_factory.h:45
API for Group Replication plugin.
enum_group_replication_consistency_level
Definition: plugin_group_replication.h:35
PSI_stage_info info_GR_STAGE_module_suspending
Definition: plugin_psi.h:230
PSI_stage_info info_GR_STAGE_module_executing
Definition: plugin_psi.h:229
required string key
Definition: replication_asynchronous_connection_failover.proto:60
repeated Action action
Definition: replication_group_member_actions.proto:43
mysql::gtid::gno_t rpl_gno
GNO, the second (numeric) component of a GTID, is an alias of mysql::gtid::gno_t.
Definition: rpl_gtid.h:113
cs::index::rpl_sidno rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:109
PSI_stage_key m_key
The registered stage key.
Definition: psi_stage_bits.h:76
Definition: my_thread_bits.h:58
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: plugin_utils.h:48
bool is_running() const
Definition: plugin_utils.h:85