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