MySQL 8.4.3
Source Code Documentation
rpl_applier_reader.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 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 RPL_APPLIER_READER_INCLUDED
25#define RPL_APPLIER_READER_INCLUDED
26
27#include "mysqld.h"
28#include "sql/binlog.h"
29#include "sql/binlog_reader.h"
30
31class Relay_log_info;
32
33/**
34 This class provides the feature to read events from relay log files.
35
36 - Open() function just opens the first relay log file
37 (rli->get_group_relay_log_name()) which need to be applied by slave.
38
39 - read_next_event() just returns the events one by one. It will close()
40 current relay log and open next relay log file automatically when reaching
41 the end of current relay log. Internally each relay log file is opened and
42 read by using a Relaylog_file_reader.
43
44 - It will purge the applied relay logs accordingly when moving to next relay
45 log.
46
47 - When reaching the end of active relay log file, it will wait for new events
48 coming and make MTS checkpoints accordingly while waiting for events.
49*/
51 public:
52 /**
53 @param[in] rli relay log info is used in the function. So rli should be
54 initialized before initializing Rpl_applier_reader object.
55 */
60
61 /**
62 Open the first relay log file which will be read by applier and
63 seek to correct position. The file name and position are read from
64 rli->get_group_master_log_name() and rli->get_group_relay_log_pos().
65
66 @param[out] errmsg Set the error message to it if any error happens.
67
68 @retval false Success
69 @retval true Error
70 */
71 bool open(const char **errmsg);
72 void close();
73
74 /**
75 Read next event from relay log.
76 - It will wait until the receiver writes some events to relay log in case
77 where there are no more events left to read from the active relay log.
78 - The caller must hold m_rli->data_lock. The lock will be released
79 temporarily while waiting and required after waking up.
80 - The wait is protected by relay_log.lock_binlog_end_pos().
81
82 @retval Log_event* A valid Log_event object.
83 @retval nullptr Error happened or sql thread was killed.
84 */
86
87 private:
90 /** Stores the error message which is used internally */
91 const char *m_errmsg = nullptr;
92
94 /**
95 Stores active log's end position. Thus avoids to call
96 relay_log.get_binlog_log_pos() for each event.
97 */
99 /*
100 It stores offset of relay log index to speed up finding next relay log
101 files.
102 */
105
106 class Stage_controller;
107 /**
108 When reaching the end of current relay log file, close it and open next
109 relay log. purge old relay logs if necessary.
110
111 @param force_purge This function rarely purges the current log before
112 moving to the next. Sometimes, we need to enforce this purge, e.g. when
113 receiver is waiting for available relay log space. The 'force_purge'
114 will enable an aggressive relay log purge.
115 Beware that 'move_to_next_log' with force_purge enabled, will ignore that
116 current group position is lower than required and will reset it. Therefore,
117 make sure that workers finished executing ALL scheduled jobs.
118
119 @retval false Success
120 @retval true Error
121 */
122 bool move_to_next_log(bool force_purge);
123 /**
124 It reads the coordinates up to which the receiver thread has written and
125 check whether there is any event to be read.
126
127 @retval false The applier has read all events.
128 @retval true The applier is behind the receiver.
129 */
131 /**
132 In the case receiver thread says master skipped some events, it will
133 generate a Rotate_log_event for applier to advance executed master log
134 position.
135 */
137 /**
138 Purge relay log files prior to m_rli->group_relay_log_name.
139 It is used to be called MYSQL_BIN_LOG::purge_first_log
140
141 @retval false Success
142 @retval true Error
143 */
144 bool purge_applied_logs();
145
146 /**
147 Waits for new events coming. Returning successfully just means it gets a
148 signal. That doesn't guarantee that any new event came.
149
150 @retval false Success
151 @retval true Error. The thread is killed or flush failed while
152 executing mta_checkpoint_routine.
153
154 @note the The caller must hold m_rli->data_lock and
155 relaylog.lock_binlog_end_pos().
156 */
157 bool wait_for_new_event();
158
159 /**
160 It checks if the relaylog file reader should be reopened and then reopens
161 the reader if receiver thread truncated some data from active relay log.
162 The caller must hold m_rli->data_lock
163
164 @retval false Success
165 @retval true Error
166 */
168
169 /* reset seconds_behind_source when starting to wait for events coming */
171#ifndef NDEBUG
173#endif
174};
175
176#endif // RPL_APPLIER_READER_INCLUDED
This is the abstract base class for binary log events.
Definition: log_event.h:538
Definition: rpl_rli.h:203
This will be deprecated when we move to using sequence ids.
Definition: log_event.h:2027
It manages a stage and the related mutex and makes the process of locking and entering stage/unlock a...
Definition: rpl_applier_reader.cc:46
This class provides the feature to read events from relay log files.
Definition: rpl_applier_reader.h:50
bool m_relay_log_purge
Definition: rpl_applier_reader.h:104
Relay_log_info * m_rli
Definition: rpl_applier_reader.h:89
LOG_INFO m_linfo
Definition: rpl_applier_reader.h:103
bool wait_for_new_event()
Waits for new events coming.
Definition: rpl_applier_reader.cc:306
Rotate_log_event * generate_rotate_event()
In the case receiver thread says master skipped some events, it will generate a Rotate_log_event for ...
Definition: rpl_applier_reader.cc:289
const char * m_errmsg
Stores the error message which is used internally.
Definition: rpl_applier_reader.h:91
Relaylog_file_reader m_relaylog_file_reader
Definition: rpl_applier_reader.h:88
bool m_reading_active_log
Definition: rpl_applier_reader.h:93
bool read_active_log_end_pos()
It reads the coordinates up to which the receiver thread has written and check whether there is any e...
Definition: rpl_applier_reader.cc:278
bool reopen_log_reader_if_needed()
It checks if the relaylog file reader should be reopened and then reopens the reader if receiver thre...
Definition: rpl_applier_reader.cc:333
Rpl_applier_reader(const Rpl_applier_reader &)=delete
Rpl_applier_reader(Relay_log_info *rli)
Definition: rpl_applier_reader.cc:87
void close()
Definition: rpl_applier_reader.cc:148
void debug_print_next_event_positions()
Definition: rpl_applier_reader.cc:495
bool open(const char **errmsg)
Open the first relay log file which will be read by applier and seek to correct position.
Definition: rpl_applier_reader.cc:96
Rpl_applier_reader & operator=(const Rpl_applier_reader &)=delete
my_off_t m_log_end_pos
Stores active log's end position.
Definition: rpl_applier_reader.h:98
void reset_seconds_behind_master()
Definition: rpl_applier_reader.cc:533
Log_event * read_next_event()
Read next event from relay log.
Definition: rpl_applier_reader.cc:155
bool purge_applied_logs()
Purge relay log files prior to m_rli->group_relay_log_name.
Definition: rpl_applier_reader.cc:437
~Rpl_applier_reader()
Definition: rpl_applier_reader.cc:94
bool move_to_next_log(bool force_purge)
When reaching the end of current relay log file, close it and open next relay log.
Definition: rpl_applier_reader.cc:374
ulonglong my_off_t
Definition: my_inttypes.h:72
bool relay_log_purge
Definition: mysqld.cc:1268
Definition: binlog.h:115