1 /* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #ifndef SQL_THREAD_APPLIER_INCLUDE
24 #define SQL_THREAD_APPLIER_INCLUDE
25 
26 #include <mysql/group_replication_priv.h>
27 
28 #include "my_inttypes.h"
29 #include "plugin/group_replication/include/handlers/pipeline_handlers.h"
30 #include "plugin/group_replication/include/replication_threads_api.h"
31 
32 class Applier_handler : public Event_handler {
33  public:
34   Applier_handler();
35   int handle_event(Pipeline_event *ev, Continuation *cont);
36   int handle_action(Pipeline_action *action);
37   int initialize();
38   int terminate();
39   bool is_unique();
40   int get_role();
41 
42   /**
43     Initializes the SQL thread when receiving a configuration package
44 
45     @param reset_logs                if a reset was executed in the server
46     @param plugin_shutdown_timeout   the plugin's timeout for component shutdown
47 
48     @return the operation status
49       @retval 0      OK
50       @retval !=0    Error
51   */
52   int initialize_repositories(bool reset_logs, ulong plugin_shutdown_timeout);
53 
54   /**
55     Starts the SQL thread when receiving a action package
56 
57     @return the operation status
58       @retval 0      OK
59       @retval !=0    Error
60   */
61   int start_applier_thread();
62 
63   /**
64     Stops the SQL thread when receiving a action package
65 
66     @return the operation status
67       @retval 0      OK
68       @retval !=0    Error
69   */
70   int stop_applier_thread();
71 
72   /**
73     Checks if the applier, and its workers when parallel applier is
74     enabled, has already consumed all relay log, that is, applier is
75     waiting for transactions to be queued.
76 
77     @return the applier status
78       @retval true      the applier is waiting
79       @retval false     otherwise
80   */
81   bool is_applier_thread_waiting();
82 
83   /**
84     Checks if all the queued transactions were executed.
85 
86     @param timeout  the time (seconds) after which the method returns if the
87                     above condition was not satisfied
88 
89     @return the operation status
90       @retval 0      All transactions were executed
91       @retval -1     A timeout occurred
92       @retval -2     An error occurred
93   */
94   int wait_for_gtid_execution(double timeout);
95 
96   /**
97     Checks if all the given transactions were executed.
98 
99     @param retrieved_set the set in string format of transaction to wait for
100     @param timeout  the time (seconds) after which the method returns if the
101                   above condition was not satisfied
102     @param update_THD_status     Shall the method update the THD stage
103 
104     @return the operation status
105       @retval 0      All transactions were executed
106       @retval -1     A timeout occurred
107       @retval -2     An error occurred
108 */
109   int wait_for_gtid_execution(std::string &retrieved_set, double timeout,
110                               bool update_THD_status = true);
111 
112   /**
113     Checks if the channel's relay log contains partial transaction.
114 
115     @retval true  If relaylog contains partial transaction.
116     @retval false If relaylog does not contain partial transaction.
117   */
118   int is_partial_transaction_on_relay_log();
119 
120  private:
121   Replication_thread_api channel_interface;
122 };
123 
124 #endif /* SQL_THREAD_APPLIER_INCLUDE */
125