MySQL 8.4.0
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 @retval false Success
112 @retval true Error
113 */
114 bool move_to_next_log();
115 /**
116 It reads the coordinates up to which the receiver thread has written and
117 check whether there is any event to be read.
118
119 @retval false The applier has read all events.
120 @retval true The applier is behind the receiver.
121 */
123 /**
124 In the case receiver thread says master skipped some events, it will
125 generate a Rotate_log_event for applier to advance executed master log
126 position.
127 */
129 /**
130 Purge relay log files prior to m_rli->group_relay_log_name.
131 It is used to be called MYSQL_BIN_LOG::purge_first_log
132
133 @retval false Success
134 @retval true Error
135 */
136 bool purge_applied_logs();
137
138 /**
139 Waits for new events coming. Returning successfully just means it gets a
140 signal. That doesn't guarantee that any new event came.
141
142 @retval false Success
143 @retval true Error. The thread is killed or flush failed while
144 executing mta_checkpoint_routine.
145
146 @note the The caller must hold m_rli->data_lock and
147 relaylog.lock_binlog_end_pos().
148 */
149 bool wait_for_new_event();
150
151 /**
152 It checks if the relaylog file reader should be reopened and then reopens
153 the reader if receiver thread truncated some data from active relay log.
154 The caller must hold m_rli->data_lock
155
156 @retval false Success
157 @retval true Error
158 */
160
161 /* reset seconds_behind_source when starting to wait for events coming */
163 /* relay_log_space_limit should be disabled temporarily in some cases. */
165#ifndef NDEBUG
167#endif
168};
169
170#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:289
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:272
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 move_to_next_log()
When reaching the end of current relay log file, close it and open next relay log.
Definition: rpl_applier_reader.cc:359
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:261
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:318
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 disable_relay_log_space_limit_if_needed()
Temporarily disables the receiver thread's check for log space, allowing it to queue more than log_sp...
Definition: rpl_applier_reader.cc:498
void debug_print_next_event_positions()
Definition: rpl_applier_reader.cc:528
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:566
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:421
~Rpl_applier_reader()
Definition: rpl_applier_reader.cc:94
ulonglong my_off_t
Definition: my_inttypes.h:72
bool relay_log_purge
Definition: mysqld.cc:1268
Definition: binlog.h:115