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