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