MySQL 26.7.0
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();
105};
106
107/**
108 This class keeps a count of all the syntax errors that occurred while parsing
109 views, routines, events or triggers. This count is used along with
110 MAX_SERVER_CHECK_FAILS to exit upgrade.
111*/
113 public:
117 bool handle_condition(THD *, uint sql_errno, const char *,
119 const char *msg) override;
120
121 static bool has_too_many_errors();
122 static bool has_errors();
123 static const char *error_message();
124
125 static uint parse_error_count;
126 static bool is_parse_error;
127 static const uint MAX_SERVER_CHECK_FAILS;
130};
131
132/**
133 RAII for handling creation context of Events and
134 Stored routines.
135*/
136
143
144 public:
147};
148
149/**
150 Maintain a file named "mysql_upgrade_history" in the data directory.
151
152 The file will contain one entry for each upgrade. The format is structured
153 text on JSON format.
154
155 Errors will be written as warnings to the error log; if we e.g. fail to
156 open the upgrade history file, we will not abort the server since this file
157 is not considered a critical feature of the server.
158
159 @param initialize If this is the initialization of the data directory.
160*/
162
163/**
164 Performs validation on server metadata.
165
166 @param thd Thread context.
167
168 @return Upon failure, return true, otherwise false.
169 */
171
172/**
173 * @brief Validate the SQL string provided.
174 *
175 * @param thd Thread handle
176 * @param dbname The database used in the SQL string's context.
177 * @param sql The SQL string to be validated
178 * @return true
179 * @return false
180 */
181bool invalid_sql(THD *thd, const char *dbname, const dd::String_type &sql);
182
183/**
184 Validate all the triggers of the given table.
185
186 @param[in] thd Thread handle.
187 @param[in] schema_name Pointer for database name.
188 @param[in] table Triggers of the table to be checked.
189
190 @retval false ON SUCCESS
191 @retval true ON FAILURE
192*/
193bool invalid_triggers(THD *thd, const char *schema_name,
194 const dd::Table &table);
195
196/**
197 Validate a dd::Routine object.
198
199 @param[in] thd Thread handle.
200 @param[in] schema_name Schema in which the routine belongs.
201 @param[in] routine Routine to be validated.
202
203 @retval false ON SUCCESS
204 @retval true ON FAILURE
205*/
206bool invalid_routine(THD *thd, const dd::String_type &schema_name,
207 const dd::Routine &routine);
208
209/**
210 Helper function to create a stored procedure from an event body.
211
212 @param[in] thd Thread handle.
213 @param[in] name Name of the event.
214 @param[in] name_len Length of the name of the event.
215 @param[in] body Body of the event.
216 @param[in] body_len Length of the body of the event.
217 @param[out] sp_sql Stored procedure SQL string.
218
219 @retval false ON SUCCESS
220 @retval true ON FAILURE
221*/
222bool build_event_sp(const THD *thd, const char *name, size_t name_len,
223 const char *body, size_t body_len, dd::String_type *sp_sql);
224} // namespace upgrade
225} // namespace dd
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
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:66
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:167
ErrorHandlerFunctionPointer m_old_error_handler_hook
Definition: server.h:65
Bootstrap_error_handler()
Definition: server.cc:145
static void set_abort_on_error(uint error)
Definition: server.cc:133
static bool should_log_error(uint error)
Definition: server.cc:156
static bool abort_on_error
Definition: server.h:87
static void my_message_bootstrap(uint error, const char *str, myf MyFlags)
Definition: server.cc:120
~Bootstrap_error_handler()
Definition: server.cc:171
static std::set< uint > m_allowlist_errors
Definition: server.h:89
void set_allowlist_errors(std::set< uint > &error_codes)
Definition: server.cc:162
void set_log_error(bool log_error)
Definition: server.cc:152
static bool m_log_error
Definition: server.h:86
RAII for handling creation context of Events and Stored routines.
Definition: server.h:137
THD * m_thd
Definition: server.h:138
::Time_zone * m_saved_time_zone
Definition: server.h:140
const CHARSET_INFO * m_client_cs
Definition: server.h:141
const CHARSET_INFO * m_connection_cl
Definition: server.h:142
~Routine_event_context_guard()
Definition: server.cc:194
Routine_event_context_guard(THD *thd)
Definition: server.cc:186
sql_mode_t m_sql_mode
Definition: server.h:139
This class keeps a count of all the syntax errors that occurred while parsing views,...
Definition: server.h:112
static bool is_parse_error
Definition: server.h:126
Syntax_error_handler()
Definition: server.h:114
static bool has_too_many_errors()
Definition: server.cc:225
static const uint MAX_SERVER_CHECK_FAILS
Definition: server.h:127
Upgrade_error_counter * m_global_counter
Definition: server.h:129
static bool has_errors()
Definition: server.cc:229
static dd::String_type reason
Definition: server.h:128
static const char * error_message()
Definition: server.cc:231
Syntax_error_handler(Upgrade_error_counter *counter)
Definition: server.h:115
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:210
static uint parse_error_count
Definition: server.h:125
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:238
int m_error_count
Definition: server.h:97
Upgrade_error_counter operator++(int)
Definition: server.cc:241
const int ERROR_LIMIT
Definition: server.h:98
Upgrade_error_counter()
Definition: server.h:101
bool has_errors()
Definition: server.cc:237
uint64_t sql_mode_t
Definition: dd_event.h:39
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:1077
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:1312
void update_upgrade_history_file(bool initialize)
Maintain a file named "mysql_upgrade_history" in the data directory.
Definition: server.cc:1040
bool do_server_upgrade_checks(THD *thd)
Performs validation on server metadata.
Definition: server.cc:1162
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:1344
bool invalid_triggers(THD *thd, const char *schema_name, const dd::Table &table)
Validate all the triggers of the given table.
Definition: server.cc:1286
bool invalid_routine(THD *thd, const dd::String_type &schema_name, const dd::Routine &routine)
Validate a dd::Routine object.
Definition: server.cc:1246
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:44
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
entry::Table Table
Definition: select.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:60
Definition: m_ctype.h:421
#define log_error(msg,...)
Definition: tm_log.h:87