MySQL 8.0.39
Source Code Documentation
rpl_info.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 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_INFO_H
25#define RPL_INFO_H
26
27#include <sys/types.h>
28#include <atomic>
29
30#include "my_inttypes.h"
31#include "my_psi_config.h"
35#include "mysql_com.h" // NAME_LEN
36#include "sql/rpl_info_handler.h" // Rpl_info_handler
37#include "sql/rpl_reporting.h" // Slave_reporting_capability
38
39class THD;
40
41#define CHANNEL_NAME_LENGTH NAME_LEN
42
44 public:
45 ~Rpl_info() override;
46
47 /*
48 standard lock acquisition order to avoid deadlocks:
49 run_lock, data_lock, relay_log.LOCK_log, relay_log.LOCK_index
50 run_lock, sleep_lock
51 run_lock, info_thd_lock
52
53 info_thd_lock is to protect operations on info_thd:
54 - before *reading* info_thd we must hold *either* info_thd_lock or
55 run_lock;
56 - before *writing* we must hold *both* run_lock and info_thd_lock.
57 */
59 /*
60 start_cond is broadcast when SQL thread is started
61 stop_cond - when stopped
62 data_cond - when data protected by data_lock changes
63 sleep_cond - when killed
64
65 'data_cond' is only being used in class Relay_log_info and not in the
66 class Master_info. So 'data_cond' could be moved to Relay_log_info.
67 */
69
70#ifdef HAVE_PSI_INTERFACE
73
76#endif
77
79
80 bool inited;
81 std::atomic<bool> abort_slave;
82 std::atomic<uint> slave_running;
83 std::atomic<ulong> slave_run_id;
84
85#ifndef NDEBUG
87#endif
88
89 /**
90 Sets the persistency component/handler.
91
92 @param[in] param_handler Pointer to the handler.
93 */
95 handler = param_handler;
96 }
97
98 /**
99 Gets the persistency component/handler.
100
101 @return the handler if there is one.
102 */
104
105 enum_return_check check_info() const { return (handler->check_info()); }
106
107 int remove_info() { return (handler->remove_info()); }
108
109 int clean_info() { return (handler->clean_info()); }
110
111 bool is_transactional() const { return (handler->is_transactional()); }
112
114 return (handler->update_is_transactional());
115 }
116
117 char *get_description_info() const {
118 return (handler->get_description_info());
119 }
120
122 if (read_info(from) || write_info(to)) return (true);
123
124 return (false);
125 }
126
127 uint get_internal_id() const { return internal_id; }
128
129 char *get_channel() const { return const_cast<char *>(channel); }
130
131 /**
132 To search in the slave repositories, each slave info object
133 (mi, rli or worker) should use a primary key. This function
134 sets the field values of the slave info objects with
135 the search information, which is nothing but PK in mysql slave
136 info tables.
137 Ex: field_value[23]="channel_name" in the master info
138 object.
139
140 Currently, used only for TABLE repository.
141 */
142
144
145 protected:
146 /**
147 Pointer to the repository's handler.
148 */
150
151 /**
152 Uniquely and internally identifies an info entry (.e.g. a row or
153 file). This information is completely transparent to users and
154 is used only during startup to retrieve information from the
155 repositories.
156
157 @todo, This is not required any longer for Master_info and
158 Relay_log_info, since Channel can be used to uniquely
159 identify this. To preserve backward compatibility,
160 we keep this for Master_info and Relay_log_info.
161 However, {id, channel} is still required for a worker info.
162 */
164
165 /**
166 Every slave info object acts on a particular channel in Multisource
167 Replication.
168 */
170
171 Rpl_info(const char *type,
173 PSI_mutex_key *param_key_info_run_lock,
174 PSI_mutex_key *param_key_info_data_lock,
175 PSI_mutex_key *param_key_info_sleep_lock,
176 PSI_mutex_key *param_key_info_thd_lock,
177 PSI_mutex_key *param_key_info_data_cond,
178 PSI_mutex_key *param_key_info_start_cond,
179 PSI_mutex_key *param_key_info_stop_cond,
180 PSI_mutex_key *param_key_info_sleep_cond,
181#endif
182 uint param_id, const char *param_channel);
183
184 private:
185 virtual bool read_info(Rpl_info_handler *from) = 0;
186 virtual bool write_info(Rpl_info_handler *to) = 0;
187
190
191 public:
192 /* True when the thread is still running, but started the stop procedure */
193 std::atomic<bool> atomic_is_stopping{false};
194};
195#endif /* RPL_INFO_H */
Definition: rpl_info_handler.h:58
Definition: rpl_info.h:43
PSI_mutex_key * key_info_sleep_cond
Definition: rpl_info.h:75
virtual bool set_info_search_keys(Rpl_info_handler *to)=0
To search in the slave repositories, each slave info object (mi, rli or worker) should use a primary ...
char * get_description_info() const
Definition: rpl_info.h:117
Rpl_info_handler * handler
Pointer to the repository's handler.
Definition: rpl_info.h:149
Rpl_info(const char *type, PSI_mutex_key *param_key_info_run_lock, PSI_mutex_key *param_key_info_data_lock, PSI_mutex_key *param_key_info_sleep_lock, PSI_mutex_key *param_key_info_thd_lock, PSI_mutex_key *param_key_info_data_cond, PSI_mutex_key *param_key_info_start_cond, PSI_mutex_key *param_key_info_stop_cond, PSI_mutex_key *param_key_info_sleep_cond, uint param_id, const char *param_channel)
Definition: rpl_info.cc:31
~Rpl_info() override
Definition: rpl_info.cc:88
Rpl_info & operator=(const Rpl_info &info)
std::atomic< bool > abort_slave
Definition: rpl_info.h:81
void set_rpl_info_handler(Rpl_info_handler *param_handler)
Sets the persistency component/handler.
Definition: rpl_info.h:94
PSI_mutex_key * key_info_sleep_lock
Definition: rpl_info.h:71
uint internal_id
Uniquely and internally identifies an info entry (.e.g.
Definition: rpl_info.h:163
virtual bool read_info(Rpl_info_handler *from)=0
bool inited
Definition: rpl_info.h:80
mysql_cond_t sleep_cond
Definition: rpl_info.h:68
mysql_mutex_t info_thd_lock
Definition: rpl_info.h:58
char * get_channel() const
Definition: rpl_info.h:129
bool copy_info(Rpl_info_handler *from, Rpl_info_handler *to)
Definition: rpl_info.h:121
mysql_cond_t start_cond
Definition: rpl_info.h:68
std::atomic< bool > atomic_is_stopping
Definition: rpl_info.h:193
int remove_info()
Definition: rpl_info.h:107
PSI_mutex_key * key_info_run_lock
Definition: rpl_info.h:71
std::atomic< ulong > slave_run_id
Definition: rpl_info.h:83
Rpl_info(const Rpl_info &info)
PSI_mutex_key * key_info_stop_cond
Definition: rpl_info.h:74
Rpl_info_handler * get_rpl_info_handler()
Gets the persistency component/handler.
Definition: rpl_info.h:103
mysql_mutex_t sleep_lock
Definition: rpl_info.h:58
bool update_is_transactional()
Definition: rpl_info.h:113
mysql_cond_t data_cond
Definition: rpl_info.h:68
PSI_mutex_key * key_info_start_cond
Definition: rpl_info.h:74
mysql_mutex_t run_lock
Definition: rpl_info.h:58
uint get_internal_id() const
Definition: rpl_info.h:127
mysql_mutex_t data_lock
Definition: rpl_info.h:58
bool is_transactional() const
Definition: rpl_info.h:111
mysql_cond_t stop_cond
Definition: rpl_info.h:68
PSI_mutex_key * key_info_data_lock
Definition: rpl_info.h:71
PSI_mutex_key * key_info_thd_lock
Definition: rpl_info.h:72
char channel[CHANNEL_NAME_LENGTH+1]
Every slave info object acts on a particular channel in Multisource Replication.
Definition: rpl_info.h:169
PSI_mutex_key * key_info_data_cond
Definition: rpl_info.h:74
std::atomic< uint > slave_running
Definition: rpl_info.h:82
int events_until_exit
Definition: rpl_info.h:86
THD * info_thd
Definition: rpl_info.h:78
int clean_info()
Definition: rpl_info.h:109
enum_return_check check_info() const
Definition: rpl_info.h:105
virtual bool write_info(Rpl_info_handler *to)=0
Mix-in to handle the message logging and reporting for relay log info and master log info structures.
Definition: rpl_reporting.h:53
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4414
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:52
Some integer typedefs for easier portability.
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
#define HAVE_PSI_INTERFACE
Definition: my_psi_config.h:39
Common definition between mysql server & client.
Instrumentation helpers for conditions.
ABI for instrumented mutexes.
Log info(cout, "NOTE")
Instrumentation helpers for mutexes.
required string type
Definition: replication_group_member_actions.proto:34
#define CHANNEL_NAME_LENGTH
Definition: rpl_info.h:41
enum_return_check
Definition: rpl_info_handler.h:51
Definition: task.h:427
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
unsigned int uint
Definition: uca9-dump.cc:75