MySQL  8.0.17
Source Code Documentation
log_resource.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
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 /**
24  @addtogroup Backup
25  @{
26 
27  @file
28 
29  @brief Log resource definitions. This includes code for the server
30  resources that will take part on the results of the
31  performance_schema.log_status table.
32 */
33 
34 #ifndef LOG_RESOURCE_H
35 #define LOG_RESOURCE_H
36 
37 #include "sql/binlog.h"
38 #include "sql/handler.h"
39 #include "sql/rpl_gtid.h"
40 #include "sql/rpl_mi.h"
41 
42 class Json_dom;
43 
44 /**
45  @class Log_resource
46 
47  This is the base class that the logic of collecting a MySQL server instance
48  resources log will call.
49 
50  It basically contains lock, unlock and collect functions that shall be
51  overridden by more specialized classes to handle the specific cases of
52  resources participating in the process.
53 */
54 
55 class Log_resource {
56  /* JSON object to be filled by the do_collect_info function */
57  Json_dom *json = nullptr;
58 
59  public:
60  /**
61  There must be one function of this kind in order for the symbols in the
62  server's dynamic library to be visible to plugins.
63  */
64 
66 
67  /**
68  Log_resource constructor.
69 
70  @param[in] json_arg the pointer to the JSON object to be populated with the
71  resource log information.
72  */
73 
74  Log_resource(Json_dom *json_arg) : json(json_arg) {}
75 
76  /**
77  Destructor.
78 
79  This function will point the JSON object to nullptr.
80  */
81 
82  virtual ~Log_resource() { json = nullptr; }
83 
84  /**
85  Return the pointer to the JSON object that should be used to fill the
86  resource log information.
87 
88  @return the Json_object pointer to be filled with the log information.
89  */
90 
91  Json_dom *get_json() { return json; }
92 
93  /*
94  Next three virtual functions need to be overridden by any more specialized
95  class inheriting from this to support a specific resource participating in
96  the collection process.
97  */
98 
99  /**
100  Lock the resource avoiding updates.
101  */
102 
103  virtual void lock() = 0;
104 
105  /**
106  Unlock the resource allowing updates.
107  */
108 
109  virtual void unlock() = 0;
110 
111  /**
112  Collect resource log information.
113 
114  @return false on success.
115  true if there was an error collecting the information.
116  */
117 
118  virtual bool collect_info() = 0;
119 };
120 
121 /**
122  @class Log_resource_mi_wrapper
123 
124  This is the Log_resource to handle Master_info resources.
125 */
127  Master_info *mi = nullptr;
128 
129  public:
130  /**
131  Log_resource_mi_wrapper constructor.
132 
133  @param[in] mi_arg the pointer to the Master_info object resource.
134  @param[in] json_arg the pointer to the JSON object to be populated with the
135  resource log information.
136  */
137 
139  : Log_resource(json_arg), mi(mi_arg) {}
140 
141  void lock() override;
142  void unlock() override;
143  bool collect_info() override;
144 };
145 
146 /**
147  @class Log_resource_binlog_wrapper
148 
149  This is the Log_resource to handle MYSQL_BIN_LOG resources.
150 */
152  MYSQL_BIN_LOG *binlog = nullptr;
153 
154  public:
155  /**
156  Log_resource_binlog_wrapper constructor.
157 
158  @param[in] binlog_arg the pointer to the MYSQL_BIN_LOG object resource.
159  @param[in] json_arg the pointer to the JSON object to be populated with the
160  resource log information.
161  */
162 
164  : Log_resource(json_arg), binlog(binlog_arg) {}
165 
166  void lock() override;
167  void unlock() override;
168  bool collect_info() override;
169 };
170 
171 /**
172  @class Log_resource_gtid_state_wrapper
173 
174  This is the Log_resource to handle Gtid_state resources.
175 */
177  Gtid_state *gtid_state = nullptr;
178 
179  public:
180  /**
181  Log_resource_gtid_state_wrapper constructor.
182 
183  @param[in] gtid_state_arg the pointer to the Gtid_state object resource.
184  @param[in] json_arg the pointer to the JSON object to be populated with the
185  resource log information.
186  */
187 
189  Json_dom *json_arg)
190  : Log_resource(json_arg), gtid_state(gtid_state_arg) {}
191 
192  void lock() override;
193  void unlock() override;
194  bool collect_info() override;
195 };
196 
197 /**
198  @class Log_resource_hton_wrapper
199 
200  This is the Log_resource to handle handlerton resources.
201 */
203  handlerton *hton = nullptr;
204 
205  public:
206  /**
207  Log_resource_hton_wrapper constructor.
208 
209  @param[in] hton_arg the pointer to the hton resource.
210  @param[in] json_arg the pointer to the JSON object to be populated with the
211  resource log information.
212  */
213 
215  : Log_resource(json_arg), hton(hton_arg) {}
216 
217  void lock() override;
218  void unlock() override;
219  bool collect_info() override;
220 };
221 
222 /**
223  @class Log_resource_factory
224 
225  This is the Log_resource factory to create wrappers for supported
226  resources.
227 */
229  public:
230  /**
231  Creates a Log_resource wrapper based on a Master_info object.
232 
233  @param[in] mi the pointer to the Master_info object resource.
234  @param[in] json the pointer to the JSON object to be populated with the
235  resource log information.
236  @return the pointer to the new Log_resource.
237  */
238 
239  static Log_resource *get_wrapper(Master_info *mi, Json_dom *json);
240 
241  /**
242  Creates a Log_resource wrapper based on a Master_info object.
243 
244  @param[in] binlog the pointer to the MYSQL_BIN_LOG object resource.
245  @param[in] json the pointer to the JSON object to be populated with the
246  resource log information.
247  @return the pointer to the new Log_resource.
248  */
249 
250  static Log_resource *get_wrapper(MYSQL_BIN_LOG *binlog, Json_dom *json);
251 
252  /**
253  Creates a Log_resource wrapper based on a Gtid_state object.
254 
255  @param[in] gtid_state the pointer to the Gtid_state object resource.
256  @param[in] json the pointer to the JSON object to be populated with the
257  resource log information.
258  @return the pointer to the new Log_resource.
259  */
260 
262 
263  /**
264  Creates a Log_resource wrapper based on a handlerton.
265 
266  @param[in] hton the pointer to the handlerton resource.
267  @param[in] json the pointer to the JSON object to be populated with the
268  resource log information.
269  @return the pointer to the new Log_resource.
270  */
271 
272  static Log_resource *get_wrapper(handlerton *hton, Json_dom *json);
273 };
274 
275 /**
276  @} (End of group Backup)
277 */
278 
279 #endif /* LOG_RESOURCE_H */
Log_resource_binlog_wrapper(MYSQL_BIN_LOG *binlog_arg, Json_dom *json_arg)
Log_resource_binlog_wrapper constructor.
Definition: log_resource.h:163
void unlock() override
Unlock the resource allowing updates.
Definition: log_resource.cc:91
Definition: binlog.h:325
This is the Log_resource to handle Gtid_state resources.
Definition: log_resource.h:176
void lock() override
Lock the resource avoiding updates.
Definition: log_resource.cc:61
static Log_resource * get_wrapper(Master_info *mi, Json_dom *json)
Creates a Log_resource wrapper based on a Master_info object.
Definition: log_resource.cc:124
Log_resource_mi_wrapper(Master_info *mi_arg, Json_dom *json_arg)
Log_resource_mi_wrapper constructor.
Definition: log_resource.h:138
void unlock() override
Unlock the resource allowing updates.
Definition: log_resource.cc:65
This is the Log_resource factory to create wrappers for supported resources.
Definition: log_resource.h:228
bool collect_info() override
Collect resource log information.
Definition: log_resource.cc:35
Json_dom * get_json()
Return the pointer to the JSON object that should be used to fill the resource log information...
Definition: log_resource.h:91
void lock() override
Lock the resource avoiding updates.
Definition: log_resource.cc:31
virtual bool collect_info()=0
Collect resource log information.
virtual void lock()=0
Lock the resource avoiding updates.
Log_resource_gtid_state_wrapper(Gtid_state *gtid_state_arg, Json_dom *json_arg)
Log_resource_gtid_state_wrapper constructor.
Definition: log_resource.h:188
bool collect_info() override
Collect resource log information.
Definition: log_resource.cc:116
virtual ~Log_resource()
Destructor.
Definition: log_resource.h:82
Master_info * mi
Definition: log_resource.h:127
void unlock() override
Unlock the resource allowing updates.
Definition: log_resource.cc:112
Json_dom * json
Definition: log_resource.h:57
virtual void unlock()=0
Unlock the resource allowing updates.
static int dummy_function_to_ensure_we_are_linked_into_the_server()
There must be one function of this kind in order for the symbols in the server's dynamic library to b...
Definition: log_resource.cc:27
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2275
void unlock() override
Unlock the resource allowing updates.
Definition: log_resource.cc:33
Represents the server's GTID state: the set of committed GTIDs, the set of lost gtids, the set of owned gtids, the owner of each owned gtid, and a Mutex_cond_array that protects updates to gtids of each SIDNO.
Definition: rpl_gtid.h:2549
MYSQL_BIN_LOG * binlog
Definition: log_resource.h:152
void lock() override
Lock the resource avoiding updates.
Definition: log_resource.cc:89
Definition: rpl_mi.h:85
Log_resource_hton_wrapper(handlerton *hton_arg, Json_dom *json_arg)
Log_resource_hton_wrapper constructor.
Definition: log_resource.h:214
Gtid_state * gtid_state
Definition: log_resource.h:177
bool collect_info() override
Collect resource log information.
Definition: log_resource.cc:93
bool collect_info() override
Collect resource log information.
Definition: log_resource.cc:69
handlerton * hton
Definition: log_resource.h:203
This is the Log_resource to handle MYSQL_BIN_LOG resources.
Definition: log_resource.h:151
JSON DOM abstract base class.
Definition: json_dom.h:169
This is the Log_resource to handle Master_info resources.
Definition: log_resource.h:126
void lock() override
Lock the resource avoiding updates.
Definition: log_resource.cc:108
This is the Log_resource to handle handlerton resources.
Definition: log_resource.h:202
Gtid_state * gtid_state
Global state of GTIDs.
Definition: mysqld.cc:1585
This is the base class that the logic of collecting a MySQL server instance resources log will call...
Definition: log_resource.h:55
Log_resource(Json_dom *json_arg)
Log_resource constructor.
Definition: log_resource.h:74