MySQL  8.0.27
Source Code Documentation
rpl_replica_until_options.h
Go to the documentation of this file.
1 /* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
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 DEFINED_RPL_REPLICA_UNTIL_OPTIONS_H
24 #define DEFINED_RPL_REPLICA_UNTIL_OPTIONS_H
25 
26 #include <sys/types.h>
27 #include <string>
28 
29 #include "my_dbug.h"
30 #include "my_inttypes.h"
31 #include "my_io.h"
32 #include "sql/rpl_gtid.h"
33 
34 class Log_event;
35 class Relay_log_info;
36 
37 /**
38  @class Until_option
39 
40  This is the abstract base class for slave start until options. It defines
41  the public interfaces called by slave coordinator.
42 
43  This class publics three interfaces:
44  - is_satisfied_at_start_slave
45  It is called just when starting slave coordinator to check if the until
46  condition is already satisfied.
47  - is_satisfied_before_dispatching_event
48  It is called just after coordinator reads a events from relay log but
49  before it is applied or dispatched.
50  - is_satisfied_after_dispatching_event
51  It is called just after a event is applied or dispatched by the coordinator.
52 
53  These three interfaces cover all until options's check requirements.
54 */
55 class Until_option {
56  public:
57  virtual ~Until_option() = default;
58 
59  /**
60  Check if the until option is already satisfied at coordinator starting.
61 
62  @return bool
63  @retval true if it is satisfied.
64  @retval false if it is not satisfied.
65  */
67  DBUG_TRACE;
68  bool ret = check_at_start_slave();
69  return ret;
70  }
71 
72  /**
73  check if the until option is satisfied before applying or dispatching
74  a event.
75 
76  @param[in] ev point to the event which will be applied or dispatched.
77 
78  @return bool
79  @retval true if it is satisfied.
80  @retval false if it is not satisfied.
81  */
83  DBUG_TRACE;
84  bool ret = check_before_dispatching_event(ev);
85  return ret;
86  }
87 
88  /**
89  check if the until option is satisfied after applied or dispatched
90  a event.
91 
92  @return bool
93  @retval true if it is satisfied.
94  @retval false if it is not satisfied.
95  */
97  DBUG_TRACE;
98  bool ret = check_after_dispatching_event();
99  return ret;
100  }
101 
102  protected:
104 
106 
107  private:
108  /*
109  The virtual functions called by the interface functions.
110  They are implemented in sub-classes.
111  */
112  virtual bool check_at_start_slave() = 0;
113  virtual bool check_before_dispatching_event(const Log_event *ev) = 0;
114  virtual bool check_after_dispatching_event() = 0;
115 };
116 
117 /**
118  @class Until_position
119 
120  It is an abstract class for until master position and until relay log
121  position. It ecapsulates the variables and functions shared by the two
122  sort of until options.
123 
124  To avoid comparing log name in every call of interface functions. An
125  optimized comparing logic is implemented.
126  - Log name is just compared once for each master log and relay log.
127  - coodinator should notify Until_option object if master log or relay
128  log is switched by calling notify_log_name_change() function.
129 */
130 class Until_position : public Until_option {
131  public:
132  ~Until_position() override = default;
133 
134  /**
135  Initialize the until position when starting the slave.
136 
137  @param[in] log_name the log name in START SLAVE UNTIL option.
138  @param[in] log_pos the log position in START SLAVE UNTIL option.
139 
140  @return int
141  @retval 0 if succeeds.
142  @retval a defined mysql error number if error happens.
143  */
144  int init(const char *log_name, my_off_t log_pos);
145 
146  /**
147  Coordinator calls this function to notify that master
148  log switch or relay log switch.
149  */
151  DBUG_TRACE;
153  return;
154  }
155 
156  const char *get_until_log_name() { return (const char *)m_until_log_name; }
158 
159  protected:
160  /**
161  Log name is compared only once for each master log or relay log. And
162  the comparison result is stored in m_log_names_cmp_result.
163  */
164  enum {
170 
172 
173  /**
174  Check if until position is satisfied.
175 
176  - If m_log_names_cmp_result is LOG_NAMES_CMP_UNKNOWN, then it first
177  compares log_name to m_until_log_name.
178  - If the comparison result is LOG_NAMES_CMP_LESS, it will return
179  false directly. If it is LOG_NAMES_CMP_EQUAL, it then compares
180  log_pos to m_until_log_pos.
181  - If the comparison result is LOG_NAMES_CMP_GREATER, it will
182  return true directly.
183  */
184  bool check_position(const char *log_name, my_off_t log_pos);
185 
186  private:
187  /* They store the log name and log position in START SLAVE UNTIL option */
190 
191  /*
192  It stores the suffix number of m_until_log_name. Suffix number is compared
193  as a number but not a string. Othwerwise it will cause trouble for the below
194  log names. master-bin.999999 and master-bin.1234567.
195  */
197 };
198 
199 /**
200  @class Until_master_position
201 
202  It is for UNTIL master_log_file and master_log_pos
203 */
205  public:
207 
208  private:
209  /*
210  Current event's master log name and position. They are set in
211  is_satisfied_before_dispatching_event and checked in
212  is_satisfied_after_dispatching_event.
213  */
216 
217  bool check_at_start_slave() override;
218  bool check_before_dispatching_event(const Log_event *ev) override;
219  bool check_after_dispatching_event() override;
220 };
221 
222 /**
223  @class Until_relay_position
224 
225  It is for UNTIL relay_log_file and relay_log_pos
226 */
228  public:
230 
231  private:
232  bool check_at_start_slave() override;
233  bool check_before_dispatching_event(const Log_event *ev) override;
234  bool check_after_dispatching_event() override;
235 };
236 
237 /**
238  @class Until_gtids
239 
240  It is an abstract class for UNTIL SQL_BEFORE_GTIDS and SQL_AFTER_GTIDS.
241  It encapsulates the variables and functions shared between the two options.
242  */
243 class Until_gtids : public Until_option {
244  public:
245  ~Until_gtids() override = default;
246 
247  /**
248  Initialize the until gtids when starting the slave.
249 
250  @param[in] gtid_set_str the gtid set in START SLAVE UNTIL option.
251 
252  @return int
253  @retval 0 if succeeds.
254  @retval a defined mysql error number if error happens.
255  */
256  int init(const char *gtid_set_str);
257 
258  protected:
259  /**
260  Stores the gtids of START SLAVE UNTIL SQL_*_GTIDS.
261  Each time a gtid is about to be processed, we check if it is in the
262  set. Depending on until_condition, SQL thread is stopped before or
263  after applying the gtid.
264  */
266 
269 };
270 
271 /**
272  @class Until_before_gtids
273 
274  It implementes the logic of UNTIL SQL_BEFORE_GTIDS
275 */
277  public:
279 
280  private:
281  bool check_at_start_slave() override;
282  bool check_before_dispatching_event(const Log_event *ev) override;
283  bool check_after_dispatching_event() override;
284 };
285 
286 /**
287  @class Until_after_gtids
288 
289  It implementes the logic of UNTIL SQL_AFTER_GTIDS
290 */
292  public:
294 
295  private:
296  bool check_at_start_slave() override;
297  bool check_before_dispatching_event(const Log_event *ev) override;
298  bool check_after_dispatching_event() override;
299 };
300 
301 /**
302  @class Until_view_id
303 
304  It implementes the logic for UNTIL VIEW_ID.
305 */
306 class Until_view_id : public Until_option {
307  public:
309  : Until_option(rli),
310  until_view_id_found(false),
312 
313  /**
314  Initialize the view_id when starting the slave.
315 
316  @param[in] view_id the view_id in START SLAVE UNTIO option.
317 
318  @return int
319  @retval 0 if succeeds.
320  @retval a defined mysql error number if error happens.
321  */
322  int init(const char *view_id);
323 
324  private:
325  std::string m_view_id;
326  /*
327  Flag used to indicate that view_id identified by 'until_view_id'
328  was found on the current UNTIL_SQL_VIEW_ID condition.
329  It is set to false on the beginning of the UNTIL_SQL_VIEW_ID
330  condition, and set to true when view_id is found.
331  */
333  /*
334  Flag used to indicate that commit event after view_id identified
335  by 'until_view_id' was found on the current UNTIL_SQL_VIEW_ID condition.
336  It is set to false on the beginning of the UNTIL_SQL_VIEW_ID
337  condition, and set to true when commit event after view_id is found.
338  */
340 
341  bool check_at_start_slave() override;
342  bool check_before_dispatching_event(const Log_event *ev) override;
343  bool check_after_dispatching_event() override;
344 };
345 
346 /**
347  @class Until_mts_gap
348 
349  It implementes the logic of UNTIL SQL_AFTER_MTS_GAP
350 */
351 class Until_mts_gap : public Until_option {
352  public:
354 
355  /**
356  Intialize it when starting the slave.
357  */
358  void init();
359 
360  private:
361  bool check_at_start_slave() override;
362  bool check_before_dispatching_event(const Log_event *ev) override;
363  bool check_after_dispatching_event() override;
364 };
365 
366 #endif // DEFINED_RPL_REPLICA_UNTIL_OPTIONS_H
Represents a set of GTIDs.
Definition: rpl_gtid.h:1435
This is the abstract base class for binary log events.
Definition: log_event.h:659
Definition: rpl_rli.h:200
It implementes the logic of UNTIL SQL_AFTER_GTIDS.
Definition: rpl_replica_until_options.h:291
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:218
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:233
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:237
Until_after_gtids(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:293
It implementes the logic of UNTIL SQL_BEFORE_GTIDS.
Definition: rpl_replica_until_options.h:276
Until_before_gtids(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:278
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:179
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:196
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:216
It is an abstract class for UNTIL SQL_BEFORE_GTIDS and SQL_AFTER_GTIDS.
Definition: rpl_replica_until_options.h:243
int init(const char *gtid_set_str)
Initialize the until gtids when starting the slave.
Definition: rpl_replica_until_options.cc:168
Gtid_set m_gtids
Stores the gtids of START SLAVE UNTIL SQL_*_GTIDS.
Definition: rpl_replica_until_options.h:265
~Until_gtids() override=default
Until_gtids(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:267
It is for UNTIL master_log_file and master_log_pos.
Definition: rpl_replica_until_options.h:204
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:112
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:121
Until_master_position(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:206
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:147
char m_current_log_name[FN_REFLEN]
Definition: rpl_replica_until_options.h:214
my_off_t m_current_log_pos
Definition: rpl_replica_until_options.h:215
It implementes the logic of UNTIL SQL_AFTER_MTS_GAP.
Definition: rpl_replica_until_options.h:351
void init()
Intialize it when starting the slave.
Definition: rpl_replica_until_options.cc:279
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:285
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:283
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:294
Until_mts_gap(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:353
This is the abstract base class for slave start until options.
Definition: rpl_replica_until_options.h:55
bool is_satisfied_after_dispatching_event()
check if the until option is satisfied after applied or dispatched a event.
Definition: rpl_replica_until_options.h:96
Until_option(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:105
virtual bool check_before_dispatching_event(const Log_event *ev)=0
Relay_log_info * m_rli
Definition: rpl_replica_until_options.h:103
bool is_satisfied_before_dispatching_event(const Log_event *ev)
check if the until option is satisfied before applying or dispatching a event.
Definition: rpl_replica_until_options.h:82
virtual bool check_at_start_slave()=0
bool is_satisfied_at_start_slave()
Check if the until option is already satisfied at coordinator starting.
Definition: rpl_replica_until_options.h:66
virtual bool check_after_dispatching_event()=0
virtual ~Until_option()=default
It is an abstract class for until master position and until relay log position.
Definition: rpl_replica_until_options.h:130
my_off_t get_until_log_pos()
Definition: rpl_replica_until_options.h:157
int init(const char *log_name, my_off_t log_pos)
Initialize the until position when starting the slave.
Definition: rpl_replica_until_options.cc:40
~Until_position() override=default
@ LOG_NAMES_CMP_LESS
Definition: rpl_replica_until_options.h:166
@ LOG_NAMES_CMP_GREATER
Definition: rpl_replica_until_options.h:168
@ LOG_NAMES_CMP_EQUAL
Definition: rpl_replica_until_options.h:167
@ LOG_NAMES_CMP_UNKNOWN
Definition: rpl_replica_until_options.h:165
Until_position(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:171
const char * get_until_log_name()
Definition: rpl_replica_until_options.h:156
ulong m_until_log_name_extension
Definition: rpl_replica_until_options.h:196
bool check_position(const char *log_name, my_off_t log_pos)
Check if until position is satisfied.
Definition: rpl_replica_until_options.cc:63
void notify_log_name_change()
Coordinator calls this function to notify that master log switch or relay log switch.
Definition: rpl_replica_until_options.h:150
char m_until_log_name[FN_REFLEN]
Definition: rpl_replica_until_options.h:188
ulonglong m_until_log_pos
Definition: rpl_replica_until_options.h:189
enum Until_position::@137 m_log_names_cmp_result
Log name is compared only once for each master log or relay log.
It is for UNTIL relay_log_file and relay_log_pos.
Definition: rpl_replica_until_options.h:227
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:159
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:154
Until_relay_position(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:229
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:163
It implementes the logic for UNTIL VIEW_ID.
Definition: rpl_replica_until_options.h:306
bool until_view_id_found
Definition: rpl_replica_until_options.h:332
std::string m_view_id
Definition: rpl_replica_until_options.h:325
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:255
Until_view_id(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:308
int init(const char *view_id)
Initialize the view_id when starting the slave.
Definition: rpl_replica_until_options.cc:241
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:253
bool until_view_id_commit_found
Definition: rpl_replica_until_options.h:339
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:275
DBUG_TRACE
Definition: do_ctype.cc:46
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
ulonglong my_off_t
Definition: my_inttypes.h:71
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:82
Sid_map * global_sid_map
Definition: mysqld.cc:1789