MySQL 8.4.2
Source Code Documentation
server.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 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 DD_UPGRADE_IMPL__SERVER_H_INCLUDED
25#define DD_UPGRADE_IMPL__SERVER_H_INCLUDED
26
27#include <stdint.h>
28#include <stdio.h>
29
30#include <set>
31
32#include "my_inttypes.h"
33#include "my_sys.h" // ErrorHandlerFunctionPointer
34#include "sql/dd/string_type.h"
35#include "sql/error_handler.h" // Internal_error_handler
36
37class THD;
38class Time_zone;
39
40struct CHARSET_INFO;
41
42using sql_mode_t = uint64_t;
43
44namespace dd {
45class Routine;
46class Schema;
47class Table;
48
49namespace upgrade {
50/**
51 Bootstrap thread executes SQL statements.
52 Any error in the execution of SQL statements causes call to my_error().
53 At this moment, error handler hook is set to my_message_stderr.
54 my_message_stderr() prints the error messages to standard error stream but
55 it does not follow the standard error format. Further, the error status is
56 not set in Diagnostics Area.
57
58 This class is to create RAII error handler hooks to be used when executing
59 statements from bootstrap thread.
60
61 It will print the error in the standard error format.
62 Diagnostics Area error status will be set to avoid asserts.
63 Error will be handler by caller function.
64*/
65
67 private:
69
70 // Set the error in DA. Optionally print error in log.
71 static void my_message_bootstrap(uint error, const char *str, myf MyFlags);
72
73 // Set abort on error flag and enable error logging for certain fatal error.
74 static void set_abort_on_error(uint error);
75
76 // Check if error should be logged.
77 static bool should_log_error(uint error);
78
79 public:
81
82 // Log all errors to the error log file too.
83 void set_log_error(bool log_error);
84
85 void set_allowlist_errors(std::set<uint> &error_codes);
87
89 static bool m_log_error;
90 static bool abort_on_error;
91 // Set of errors which are logged to error log file always.
92 static std::set<uint> m_allowlist_errors;
93};
94
95/**
96 Class to keep track of upgrade errors during upgrade after 8.0 GA.
97*/
99 private:
101 const int ERROR_LIMIT;
102
103 public:
105 bool has_errors();
106 bool has_too_many_errors();
109};
110
111/**
112 This class keeps a count of all the syntax errors that occurred while parsing
113 views, routines, events or triggers. This count is used along with
114 MAX_SERVER_CHECK_FAILS to exit upgrade.
115*/
117 public:
121 bool handle_condition(THD *, uint sql_errno, const char *,
123 const char *msg) override;
125
126 static bool has_too_many_errors();
127 static bool has_errors();
128 static const char *error_message();
129
130 static uint parse_error_count;
131 static bool is_parse_error;
132 static const uint MAX_SERVER_CHECK_FAILS;
135};
136
137/**
138 RAII for handling creation context of Events and
139 Stored routines.
140*/
141
148
149 public:
152};
153
154/**
155 Maintain a file named "mysql_upgrade_history" in the data directory.
156
157 The file will contain one entry for each upgrade. The format is structured
158 text on JSON format.
159
160 Errors will be written as warnings to the error log; if we e.g. fail to
161 open the upgrade history file, we will not abort the server since this file
162 is not considered a critical feature of the server.
163
164 @param initialize If this is the initialization of the data directory.
165*/
167
168/**
169 Performs validation on server metadata.
170
171 @param thd Thread context.
172
173 @return Upon failure, return true, otherwise false.
174 */
176
177/**
178 * @brief Validate the SQL string provided.
179 *
180 * @param thd Thread handle
181 * @param dbname The database used in the SQL string's context.
182 * @param sql The SQL string to be validated
183 * @return true
184 * @return false
185 */
186bool invalid_sql(THD *thd, const char *dbname, const dd::String_type &sql);
187
188/**
189 Validate all the triggers of the given table.
190
191 @param[in] thd Thread handle.
192 @param[in] schema_name Pointer for database name.
193 @param[in] table Triggers of the table to be checked.
194
195 @retval false ON SUCCESS
196 @retval true ON FAILURE
197*/
198bool invalid_triggers(THD *thd, const char *schema_name,
199 const dd::Table &table);
200
201/**
202 Validate a dd::Routine object.
203
204 @param[in] thd Thread handle.
205 @param[in] schema Schema in which the routine belongs.
206 @param[in] routine Routine to be validated.
207
208 @retval false ON SUCCESS
209 @retval true ON FAILURE
210*/
211bool invalid_routine(THD *thd, const dd::Schema &schema,
212 const dd::Routine &routine);
213
214/**
215 Helper function to create a stored procedure from an event body.
216
217 @param[in] thd Thread handle.
218 @param[in] name Name of the event.
219 @param[in] name_len Length of the name of the event.
220 @param[in] body Body of the event.
221 @param[in] body_len Length of the body of the event.
222 @param[out] sp_sql Stored procedure SQL string.
223
224 @retval false ON SUCCESS
225 @retval true ON FAILURE
226*/
227bool build_event_sp(const THD *thd, const char *name, size_t name_len,
228 const char *body, size_t body_len, dd::String_type *sp_sql);
229} // namespace upgrade
230
231} // namespace dd
232#endif // DD_UPGRADE_IMPL__SERVER_H_INCLUDED
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
This class represents the interface for internal error handlers.
Definition: error_handler.h:47
enum_severity_level
Enumeration value describing the severity of the condition.
Definition: sql_error.h:63
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t co...
Definition: tztime.h:49
Abstract base class for functions and procedures.
Definition: routine.h:61
Definition: schema.h:63
Definition: table.h:47
Bootstrap thread executes SQL statements.
Definition: server.h:66
void clear_allowlist_errors()
Definition: server.cc:150
ErrorHandlerFunctionPointer m_old_error_handler_hook
Definition: server.h:68
Bootstrap_error_handler()
Definition: server.cc:128
static void set_abort_on_error(uint error)
Definition: server.cc:116
static bool should_log_error(uint error)
Definition: server.cc:139
static bool abort_on_error
Definition: server.h:90
static void my_message_bootstrap(uint error, const char *str, myf MyFlags)
Definition: server.cc:103
~Bootstrap_error_handler()
Definition: server.cc:154
static std::set< uint > m_allowlist_errors
Definition: server.h:92
void set_allowlist_errors(std::set< uint > &error_codes)
Definition: server.cc:145
void set_log_error(bool log_error)
Definition: server.cc:135
static bool m_log_error
Definition: server.h:89
RAII for handling creation context of Events and Stored routines.
Definition: server.h:142
THD * m_thd
Definition: server.h:143
::Time_zone * m_saved_time_zone
Definition: server.h:145
const CHARSET_INFO * m_client_cs
Definition: server.h:146
const CHARSET_INFO * m_connection_cl
Definition: server.h:147
~Routine_event_context_guard()
Definition: server.cc:177
Routine_event_context_guard(THD *thd)
Definition: server.cc:169
sql_mode_t m_sql_mode
Definition: server.h:144
This class keeps a count of all the syntax errors that occurred while parsing views,...
Definition: server.h:116
static bool is_parse_error
Definition: server.h:131
void reset_last_condition()
Definition: server.cc:208
Syntax_error_handler()
Definition: server.h:118
static bool has_too_many_errors()
Definition: server.cc:224
static const uint MAX_SERVER_CHECK_FAILS
Definition: server.h:132
Upgrade_error_counter * m_global_counter
Definition: server.h:134
static bool has_errors()
Definition: server.cc:228
static dd::String_type reason
Definition: server.h:133
static const char * error_message()
Definition: server.cc:230
Syntax_error_handler(Upgrade_error_counter *counter)
Definition: server.h:119
bool handle_condition(THD *, uint sql_errno, const char *, Sql_condition::enum_severity_level *, const char *msg) override
Handle a sql condition.
Definition: server.cc:193
static uint parse_error_count
Definition: server.h:130
Class to keep track of upgrade errors during upgrade after 8.0 GA.
Definition: server.h:98
bool has_too_many_errors()
Definition: server.cc:237
int m_error_count
Definition: server.h:100
Upgrade_error_counter operator++(int)
Definition: server.cc:240
const int ERROR_LIMIT
Definition: server.h:101
Upgrade_error_counter()
Definition: server.h:104
bool has_errors()
Definition: server.cc:236
Upgrade_error_counter operator--(int)
Definition: server.cc:244
uint64_t sql_mode_t
Definition: dd_event.h:39
#define log_error(...)
Definition: log_client.h:155
void(*)(uint, const char *, myf) ErrorHandlerFunctionPointer
Definition: my_sys.h:229
Some integer typedefs for easier portability.
int myf
Definition: my_inttypes.h:94
Common header for many mysys elements.
uint counter
Definition: mysqlimport.cc:58
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1081
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
borrowable::session_track::Schema< true > Schema
Definition: classic_protocol_session_track.h:288
bool invalid_sql(THD *thd, const char *dbname, const dd::String_type &sql)
Validate the SQL string provided.
Definition: server.cc:1128
void update_upgrade_history_file(bool initialize)
Maintain a file named "mysql_upgrade_history" in the data directory.
Definition: server.cc:883
bool do_server_upgrade_checks(THD *thd)
Performs validation on server metadata.
Definition: server.cc:1005
bool build_event_sp(const THD *thd, const char *name, size_t name_len, const char *body, size_t body_len, dd::String_type *sp_sql)
Helper function to create a stored procedure from an event body.
Definition: server.cc:1160
bool invalid_triggers(THD *thd, const char *schema_name, const dd::Table &table)
Validate all the triggers of the given table.
Definition: server.cc:1105
bool invalid_routine(THD *thd, const dd::Schema &schema, const dd::Routine &routine)
Validate a dd::Routine object.
Definition: server.cc:1065
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
MYSQL_STRINGS_EXPORT void initialize(const char *charset_dir=nullptr, MY_CHARSET_LOADER *loader=nullptr)
Initialize character set/collation library.
Definition: collations.cc:98
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:423