MySQL 8.4.11
Source Code Documentation
server.h
Go to the documentation of this file.
1#pragma once
2/* Copyright (c) 2019, 2026, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
24
25#include <stdint.h>
26
27#include <set>
28
29#include "my_inttypes.h"
30#include "my_sys.h" // ErrorHandlerFunctionPointer
31#include "sql/dd/string_type.h"
32#include "sql/error_handler.h" // Internal_error_handler
33
34class THD;
35class Time_zone;
36
37struct CHARSET_INFO;
38
39using sql_mode_t = uint64_t;
40
41namespace dd {
42class Routine;
43class Schema;
44class Table;
45
46namespace upgrade {
47/**
48 Bootstrap thread executes SQL statements.
49 Any error in the execution of SQL statements causes call to my_error().
50 At this moment, error handler hook is set to my_message_stderr.
51 my_message_stderr() prints the error messages to standard error stream but
52 it does not follow the standard error format. Further, the error status is
53 not set in Diagnostics Area.
54
55 This class is to create RAII error handler hooks to be used when executing
56 statements from bootstrap thread.
57
58 It will print the error in the standard error format.
59 Diagnostics Area error status will be set to avoid asserts.
60 Error will be handler by caller function.
61*/
62
64 private:
66
67 // Set the error in DA. Optionally print error in log.
68 static void my_message_bootstrap(uint error, const char *str, myf MyFlags);
69
70 // Set abort on error flag and enable error logging for certain fatal error.
71 static void set_abort_on_error(uint error);
72
73 // Check if error should be logged.
74 static bool should_log_error(uint error);
75
76 public:
78
79 // Log all errors to the error log file too.
80 void set_log_error(bool log_error);
81
82 void set_allowlist_errors(std::set<uint> &error_codes);
84
86 static bool m_log_error;
87 static bool abort_on_error;
88 // Set of errors which are logged to error log file always.
89 static std::set<uint> m_allowlist_errors;
90};
91
92/**
93 Class to keep track of upgrade errors during upgrade after 8.0 GA.
94*/
96 private:
98 const int ERROR_LIMIT;
99
100 public:
102 bool has_errors();
103 bool has_too_many_errors();
106};
107
108/**
109 This class keeps a count of all the syntax errors that occurred while parsing
110 views, routines, events or triggers. This count is used along with
111 MAX_SERVER_CHECK_FAILS to exit upgrade.
112*/
114 public:
118 bool handle_condition(THD *, uint sql_errno, const char *,
120 const char *msg) override;
122
123 static bool has_too_many_errors();
124 static bool has_errors();
125 static const char *error_message();
126
127 static uint parse_error_count;
128 static bool is_parse_error;
129 static const uint MAX_SERVER_CHECK_FAILS;
132};
133
134/**
135 RAII for handling creation context of Events and
136 Stored routines.
137*/
138
145
146 public:
149};
150
151/**
152 Maintain a file named "mysql_upgrade_history" in the data directory.
153
154 The file will contain one entry for each upgrade. The format is structured
155 text on JSON format.
156
157 Errors will be written as warnings to the error log; if we e.g. fail to
158 open the upgrade history file, we will not abort the server since this file
159 is not considered a critical feature of the server.
160
161 @param initialize If this is the initialization of the data directory.
162*/
164
165/**
166 Performs validation on server metadata.
167
168 @param thd Thread context.
169
170 @return Upon failure, return true, otherwise false.
171 */
173
174/**
175 * @brief Validate the SQL string provided.
176 *
177 * @param thd Thread handle
178 * @param dbname The database used in the SQL string's context.
179 * @param sql The SQL string to be validated
180 * @return true
181 * @return false
182 */
183bool invalid_sql(THD *thd, const char *dbname, const dd::String_type &sql);
184
185/**
186 Validate all the triggers of the given table.
187
188 @param[in] thd Thread handle.
189 @param[in] schema_name Pointer for database name.
190 @param[in] table Triggers of the table to be checked.
191
192 @retval false ON SUCCESS
193 @retval true ON FAILURE
194*/
195bool invalid_triggers(THD *thd, const char *schema_name,
196 const dd::Table &table);
197
198/**
199 Validate a dd::Routine object.
200
201 @param[in] thd Thread handle.
202 @param[in] schema_name Schema in which the routine belongs.
203 @param[in] routine Routine to be validated.
204
205 @retval false ON SUCCESS
206 @retval true ON FAILURE
207*/
208bool invalid_routine(THD *thd, const dd::String_type &schema_name,
209 const dd::Routine &routine);
210
211/**
212 Helper function to create a stored procedure from an event body.
213
214 @param[in] thd Thread handle.
215 @param[in] name Name of the event.
216 @param[in] name_len Length of the name of the event.
217 @param[in] body Body of the event.
218 @param[in] body_len Length of the body of the event.
219 @param[out] sp_sql Stored procedure SQL string.
220
221 @retval false ON SUCCESS
222 @retval true ON FAILURE
223*/
224bool build_event_sp(const THD *thd, const char *name, size_t name_len,
225 const char *body, size_t body_len, dd::String_type *sp_sql);
226} // namespace upgrade
227} // namespace dd
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: table.h:47
Bootstrap thread executes SQL statements.
Definition: server.h:63
void clear_allowlist_errors()
Definition: server.cc:168
ErrorHandlerFunctionPointer m_old_error_handler_hook
Definition: server.h:65
Bootstrap_error_handler()
Definition: server.cc:146
static void set_abort_on_error(uint error)
Definition: server.cc:134
static bool should_log_error(uint error)
Definition: server.cc:157
static bool abort_on_error
Definition: server.h:87
static void my_message_bootstrap(uint error, const char *str, myf MyFlags)
Definition: server.cc:121
~Bootstrap_error_handler()
Definition: server.cc:172
static std::set< uint > m_allowlist_errors
Definition: server.h:89
void set_allowlist_errors(std::set< uint > &error_codes)
Definition: server.cc:163
void set_log_error(bool log_error)
Definition: server.cc:153
static bool m_log_error
Definition: server.h:86
RAII for handling creation context of Events and Stored routines.
Definition: server.h:139
THD * m_thd
Definition: server.h:140
::Time_zone * m_saved_time_zone
Definition: server.h:142
const CHARSET_INFO * m_client_cs
Definition: server.h:143
const CHARSET_INFO * m_connection_cl
Definition: server.h:144
~Routine_event_context_guard()
Definition: server.cc:195
Routine_event_context_guard(THD *thd)
Definition: server.cc:187
sql_mode_t m_sql_mode
Definition: server.h:141
This class keeps a count of all the syntax errors that occurred while parsing views,...
Definition: server.h:113
static bool is_parse_error
Definition: server.h:128
void reset_last_condition()
Definition: server.cc:226
Syntax_error_handler()
Definition: server.h:115
static bool has_too_many_errors()
Definition: server.cc:242
static const uint MAX_SERVER_CHECK_FAILS
Definition: server.h:129
Upgrade_error_counter * m_global_counter
Definition: server.h:131
static bool has_errors()
Definition: server.cc:246
static dd::String_type reason
Definition: server.h:130
static const char * error_message()
Definition: server.cc:248
Syntax_error_handler(Upgrade_error_counter *counter)
Definition: server.h:116
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:211
static uint parse_error_count
Definition: server.h:127
Class to keep track of upgrade errors during upgrade after 8.0 GA.
Definition: server.h:95
bool has_too_many_errors()
Definition: server.cc:255
int m_error_count
Definition: server.h:97
Upgrade_error_counter operator++(int)
Definition: server.cc:258
const int ERROR_LIMIT
Definition: server.h:98
Upgrade_error_counter()
Definition: server.h:101
bool has_errors()
Definition: server.cc:254
Upgrade_error_counter operator--(int)
Definition: server.cc:262
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:232
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:1087
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:1335
void update_upgrade_history_file(bool initialize)
Maintain a file named "mysql_upgrade_history" in the data directory.
Definition: server.cc:1063
bool do_server_upgrade_checks(THD *thd)
Performs validation on server metadata.
Definition: server.cc:1185
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:1367
bool invalid_triggers(THD *thd, const char *schema_name, const dd::Table &table)
Validate all the triggers of the given table.
Definition: server.cc:1309
bool invalid_routine(THD *thd, const dd::String_type &schema_name, const dd::Routine &routine)
Validate a dd::Routine object.
Definition: server.cc:1269
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