MySQL 9.1.0
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 /**
104 check if the until option is waiting for more transactions to be read from
105 the relay log.
106
107 @return bool
108 @retval true all log events where read.
109 @retval false waiting for more log events to be read.
110 */
114 }
115
116 protected:
118
120
121 private:
122 /*
123 The virtual functions called by the interface functions.
124 They are implemented in sub-classes.
125 */
126 virtual bool check_at_start_slave() = 0;
127 virtual bool check_before_dispatching_event(const Log_event *ev) = 0;
130};
131
132/**
133 @class Until_position
134
135 It is an abstract class for until master position and until relay log
136 position. It ecapsulates the variables and functions shared by the two
137 sort of until options.
138
139 To avoid comparing log name in every call of interface functions. An
140 optimized comparing logic is implemented.
141 - Log name is just compared once for each master log and relay log.
142 - coodinator should notify Until_option object if master log or relay
143 log is switched by calling notify_log_name_change() function.
144*/
146 public:
147 ~Until_position() override = default;
148
149 /**
150 Initialize the until position when starting the slave.
151
152 @param[in] log_name the log name in START REPLICA UNTIL option.
153 @param[in] log_pos the log position in START REPLICA UNTIL option.
154
155 @return int
156 @retval 0 if succeeds.
157 @retval a defined mysql error number if error happens.
158 */
159 int init(const char *log_name, my_off_t log_pos);
160
161 /**
162 Coordinator calls this function to notify that master
163 log switch or relay log switch.
164 */
168 return;
169 }
170
171 const char *get_until_log_name() { return (const char *)m_until_log_name; }
173
174 protected:
175 /**
176 Log name is compared only once for each master log or relay log. And
177 the comparison result is stored in m_log_names_cmp_result.
178 */
179 enum {
185
187
188 /**
189 Check if until position is satisfied.
190
191 - If m_log_names_cmp_result is LOG_NAMES_CMP_UNKNOWN, then it first
192 compares log_name to m_until_log_name.
193 - If the comparison result is LOG_NAMES_CMP_LESS, it will return
194 false directly. If it is LOG_NAMES_CMP_EQUAL, it then compares
195 log_pos to m_until_log_pos.
196 - If the comparison result is LOG_NAMES_CMP_GREATER, it will
197 return true directly.
198 */
199 bool check_position(const char *log_name, my_off_t log_pos);
200
201 private:
202 /* They store the log name and log position in START REPLICA UNTIL option */
205
206 /*
207 It stores the suffix number of m_until_log_name. Suffix number is compared
208 as a number but not a string. Otherwise it will cause trouble for the below
209 log names. master-bin.999999 and master-bin.1234567.
210 */
212};
213
214/**
215 @class Until_master_position
216
217 It is for UNTIL SOURCE_LOG_FILE and SOURCE_LOG_POS
218*/
220 public:
222
223 private:
224 /*
225 Current event's master log name and position. They are set in
226 is_satisfied_before_dispatching_event and checked in
227 is_satisfied_after_dispatching_event.
228 */
231
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;
236};
237
238/**
239 @class Until_relay_position
240
241 It is for UNTIL relay_log_file and relay_log_pos
242*/
244 public:
246
247 private:
248 bool check_at_start_slave() override;
249 bool check_before_dispatching_event(const Log_event *ev) override;
250 bool check_after_dispatching_event() override;
252};
253
254/**
255 @class Until_gtids
256
257 It is an abstract class for UNTIL SQL_BEFORE_GTIDS and SQL_AFTER_GTIDS.
258 It encapsulates the variables and functions shared between the two options.
259 */
260class Until_gtids : public Until_option {
261 public:
262 ~Until_gtids() override = default;
263
264 /**
265 Initialize the until gtids when starting the slave.
266
267 @param[in] gtid_set_str the gtid set in START REPLICA UNTIL option.
268
269 @return int
270 @retval 0 if succeeds.
271 @retval a defined mysql error number if error happens.
272 */
273 int init(const char *gtid_set_str);
274
275 protected:
276 /**
277 Stores the gtids of START REPLICA UNTIL SQL_*_GTIDS.
278 Each time a gtid is about to be processed, we check if it is in the
279 set. Depending on until_condition, SQL thread is stopped before or
280 after applying the gtid.
281 */
283
286};
287
288/**
289 @class Until_before_gtids
290
291 It implements the logic of UNTIL SQL_BEFORE_GTIDS
292*/
294 public:
296
297 private:
298 bool check_at_start_slave() override;
299 bool check_before_dispatching_event(const Log_event *ev) override;
300 bool check_after_dispatching_event() override;
302};
303
304/**
305 @class Until_after_gtids
306
307 It implements the logic of UNTIL SQL_AFTER_GTIDS
308*/
310 public:
312 ~Until_after_gtids() override;
313
314 private:
315 bool check_at_start_slave() override;
316 bool check_before_dispatching_event(const Log_event *ev) override;
317 bool check_after_dispatching_event() override;
319
320 /**
321 Checks if all the customer specified transactions have been executed or not.
322
323 @return bool
324 @retval true all customer specified transactions have been executed
325 @retval false customer specified all transactions have not been executed
326 yet
327 */
329
330 /**
331 If last transaction has ben completely received wait for the worker thread
332 to finish executing the transactions.
333 @return bool
334 @retval true error happened in wait like worker error out, shutdown etc.
335 @retval false all specified transactions have been executed
336 */
337 bool wait_for_gtid_set();
338
339 /**
340 Print message to the error log for the last message.
341 Caller of the function should hold a read or write lock on
342 global_tsid_lock.
343 */
345
346 /*
347 Gtid_set of transactions read from the Relay Log for application in this
348 channel and known exectuted GTID in the server, transactions may still be in
349 execution in worker threads.
350 */
351 std::unique_ptr<Gtid_set> m_gtids_known_to_channel{nullptr};
352
353 /*
354 Last transaction has been received and dispatched to worker.
355 */
357};
358
359/**
360 @class Until_view_id
361
362 It implements the logic for UNTIL VIEW_ID.
363*/
365 public:
367 : Until_option(rli),
368 until_view_id_found(false),
370
371 /**
372 Initialize the view_id when starting the slave.
373
374 @param[in] view_id the view_id in START REPLICA UNTIO option.
375
376 @return int
377 @retval 0 if succeeds.
378 @retval a defined mysql error number if error happens.
379 */
380 int init(const char *view_id);
381
382 private:
383 std::string m_view_id;
384 /*
385 Flag used to indicate that view_id identified by 'until_view_id'
386 was found on the current UNTIL_SQL_VIEW_ID condition.
387 It is set to false on the beginning of the UNTIL_SQL_VIEW_ID
388 condition, and set to true when view_id is found.
389 */
391 /*
392 Flag used to indicate that commit event after view_id identified
393 by 'until_view_id' was found on the current UNTIL_SQL_VIEW_ID condition.
394 It is set to false on the beginning of the UNTIL_SQL_VIEW_ID
395 condition, and set to true when commit event after view_id is found.
396 */
398
399 bool check_at_start_slave() override;
400 bool check_before_dispatching_event(const Log_event *ev) override;
401 bool check_after_dispatching_event() override;
403};
404
405/**
406 @class Until_mts_gap
407
408 It implements the logic of UNTIL SQL_AFTER_MTS_GAP
409*/
411 public:
413
414 /**
415 Initialize it when starting the slave.
416 */
417 void init();
418
419 private:
420 bool check_at_start_slave() override;
421 bool check_before_dispatching_event(const Log_event *ev) override;
422 bool check_after_dispatching_event() override;
424};
425
426#endif // DEFINED_RPL_REPLICA_UNTIL_OPTIONS_H
Represents a set of GTIDs.
Definition: rpl_gtid.h:1557
This is the abstract base class for binary log events.
Definition: log_event.h:538
Definition: rpl_rli.h:206
It implements the logic of UNTIL SQL_AFTER_GTIDS.
Definition: rpl_replica_until_options.h:309
void last_transaction_executed_message()
Print message to the error log for the last message.
Definition: rpl_replica_until_options.cc:236
bool check_all_transactions_read_from_relay_log() override
Definition: rpl_replica_until_options.cc:346
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:254
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:264
~Until_after_gtids() override
Definition: rpl_replica_until_options.cc:234
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:311
bool m_last_transaction_in_execution
Definition: rpl_replica_until_options.h:356
bool check_all_transactions_executed()
Checks if all the customer specified transactions have been executed or not.
Definition: rpl_replica_until_options.cc:244
Until_after_gtids(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:311
bool wait_for_gtid_set()
If last transaction has ben completely received wait for the worker thread to finish executing the tr...
Definition: rpl_replica_until_options.cc:323
std::unique_ptr< Gtid_set > m_gtids_known_to_channel
Definition: rpl_replica_until_options.h:351
It implements the logic of UNTIL SQL_BEFORE_GTIDS.
Definition: rpl_replica_until_options.h:293
Until_before_gtids(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:295
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:190
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:207
bool check_all_transactions_read_from_relay_log() override
Definition: rpl_replica_until_options.cc:230
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:228
It is an abstract class for UNTIL SQL_BEFORE_GTIDS and SQL_AFTER_GTIDS.
Definition: rpl_replica_until_options.h:260
int init(const char *gtid_set_str)
Initialize the until gtids when starting the slave.
Definition: rpl_replica_until_options.cc:179
Gtid_set m_gtids
Stores the gtids of START REPLICA UNTIL SQL_*_GTIDS.
Definition: rpl_replica_until_options.h:282
~Until_gtids() override=default
Until_gtids(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:284
It is for UNTIL SOURCE_LOG_FILE and SOURCE_LOG_POS.
Definition: rpl_replica_until_options.h:219
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:115
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:124
bool check_all_transactions_read_from_relay_log() override
Definition: rpl_replica_until_options.cc:157
Until_master_position(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:221
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:150
char m_current_log_name[FN_REFLEN]
Definition: rpl_replica_until_options.h:229
my_off_t m_current_log_pos
Definition: rpl_replica_until_options.h:230
It implements the logic of UNTIL SQL_AFTER_MTS_GAP.
Definition: rpl_replica_until_options.h:410
void init()
Initialize it when starting the slave.
Definition: rpl_replica_until_options.cc:393
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:399
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:397
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:408
Until_mts_gap(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:412
bool check_all_transactions_read_from_relay_log() override
Definition: rpl_replica_until_options.cc:410
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:119
virtual bool check_before_dispatching_event(const Log_event *ev)=0
Relay_log_info * m_rli
Definition: rpl_replica_until_options.h:117
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
virtual bool check_all_transactions_read_from_relay_log()=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
bool is_satisfied_all_transactions_read_from_relay_log()
check if the until option is waiting for more transactions to be read from the relay log.
Definition: rpl_replica_until_options.h:111
virtual ~Until_option()=default
It is an abstract class for until master position and until relay log position.
Definition: rpl_replica_until_options.h:145
my_off_t get_until_log_pos()
Definition: rpl_replica_until_options.h:172
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:43
~Until_position() override=default
const char * get_until_log_name()
Definition: rpl_replica_until_options.h:171
Until_position(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:186
enum Until_position::@158 m_log_names_cmp_result
Log name is compared only once for each master log or relay log.
ulong m_until_log_name_extension
Definition: rpl_replica_until_options.h:211
bool check_position(const char *log_name, my_off_t log_pos)
Check if until position is satisfied.
Definition: rpl_replica_until_options.cc:66
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:165
char m_until_log_name[FN_REFLEN]
Definition: rpl_replica_until_options.h:203
ulonglong m_until_log_pos
Definition: rpl_replica_until_options.h:204
@ LOG_NAMES_CMP_LESS
Definition: rpl_replica_until_options.h:181
@ LOG_NAMES_CMP_GREATER
Definition: rpl_replica_until_options.h:183
@ LOG_NAMES_CMP_EQUAL
Definition: rpl_replica_until_options.h:182
@ LOG_NAMES_CMP_UNKNOWN
Definition: rpl_replica_until_options.h:180
It is for UNTIL relay_log_file and relay_log_pos.
Definition: rpl_replica_until_options.h:243
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:166
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:161
bool check_all_transactions_read_from_relay_log() override
Definition: rpl_replica_until_options.cc:175
Until_relay_position(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:245
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:170
It implements the logic for UNTIL VIEW_ID.
Definition: rpl_replica_until_options.h:364
bool until_view_id_found
Definition: rpl_replica_until_options.h:390
std::string m_view_id
Definition: rpl_replica_until_options.h:383
bool check_before_dispatching_event(const Log_event *ev) override
Definition: rpl_replica_until_options.cc:365
bool check_all_transactions_read_from_relay_log() override
Definition: rpl_replica_until_options.cc:389
Until_view_id(Relay_log_info *rli)
Definition: rpl_replica_until_options.h:366
int init(const char *view_id)
Initialize the view_id when starting the slave.
Definition: rpl_replica_until_options.cc:351
bool check_at_start_slave() override
Definition: rpl_replica_until_options.cc:363
bool until_view_id_commit_found
Definition: rpl_replica_until_options.h:397
bool check_after_dispatching_event() override
Definition: rpl_replica_until_options.cc:385
#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
Tsid_map * global_tsid_map
Definition: mysqld.cc:1838