MySQL 9.0.0
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();
108};
109
110/**
111 This class keeps a count of all the syntax errors that occurred while parsing
112 views, routines, events or triggers. This count is used along with
113 MAX_SERVER_CHECK_FAILS to exit upgrade.
114*/
116 public:
120 bool handle_condition(THD *, uint sql_errno, const char *,
122 const char *msg) override;
123
124 static bool has_too_many_errors();
125 static bool has_errors();
126 static const char *error_message();
127
128 static uint parse_error_count;
129 static bool is_parse_error;
130 static const uint MAX_SERVER_CHECK_FAILS;
133};
134
135/**
136 RAII for handling creation context of Events and
137 Stored routines.
138*/
139
146
147 public:
150};
151
152/**
153 Maintain a file named "mysql_upgrade_history" in the data directory.
154
155 The file will contain one entry for each upgrade. The format is structured
156 text on JSON format.
157
158 Errors will be written as warnings to the error log; if we e.g. fail to
159 open the upgrade history file, we will not abort the server since this file
160 is not considered a critical feature of the server.
161
162 @param initialize If this is the initialization of the data directory.
163*/
165
166/**
167 Performs validation on server metadata.
168
169 @param thd Thread context.
170
171 @return Upon failure, return true, otherwise false.
172 */
174
175/**
176 * @brief Validate the SQL string provided.
177 *
178 * @param thd Thread handle
179 * @param dbname The database used in the SQL string's context.
180 * @param sql The SQL string to be validated
181 * @return true
182 * @return false
183 */
184bool invalid_sql(THD *thd, const char *dbname, const dd::String_type &sql);
185
186/**
187 Validate all the triggers of the given table.
188
189 @param[in] thd Thread handle.
190 @param[in] schema_name Pointer for database name.
191 @param[in] table Triggers of the table to be checked.
192
193 @retval false ON SUCCESS
194 @retval true ON FAILURE
195*/
196bool invalid_triggers(THD *thd, const char *schema_name,
197 const dd::Table &table);
198
199/**
200 Validate a dd::Routine object.
201
202 @param[in] thd Thread handle.
203 @param[in] schema Schema in which the routine belongs.
204 @param[in] routine Routine to be validated.
205
206 @retval false ON SUCCESS
207 @retval true ON FAILURE
208*/
209bool invalid_routine(THD *thd, const dd::Schema &schema,
210 const dd::Routine &routine);
211
212/**
213 Helper function to create a stored procedure from an event body.
214
215 @param[in] thd Thread handle.
216 @param[in] name Name of the event.
217 @param[in] name_len Length of the name of the event.
218 @param[in] body Body of the event.
219 @param[in] body_len Length of the body of the event.
220 @param[out] sp_sql Stored procedure SQL string.
221
222 @retval false ON SUCCESS
223 @retval true ON FAILURE
224*/
225bool build_event_sp(const THD *thd, const char *name, size_t name_len,
226 const char *body, size_t body_len, dd::String_type *sp_sql);
227} // namespace upgrade
228
229} // namespace dd
230#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:140
THD * m_thd
Definition: server.h:141
::Time_zone * m_saved_time_zone
Definition: server.h:143
const CHARSET_INFO * m_client_cs
Definition: server.h:144
const CHARSET_INFO * m_connection_cl
Definition: server.h:145
~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:142
This class keeps a count of all the syntax errors that occurred while parsing views,...
Definition: server.h:115
static bool is_parse_error
Definition: server.h:129
Syntax_error_handler()
Definition: server.h:117
static bool has_too_many_errors()
Definition: server.cc:208
static const uint MAX_SERVER_CHECK_FAILS
Definition: server.h:130
Upgrade_error_counter * m_global_counter
Definition: server.h:132
static bool has_errors()
Definition: server.cc:212
static dd::String_type reason
Definition: server.h:131
static const char * error_message()
Definition: server.cc:214
Syntax_error_handler(Upgrade_error_counter *counter)
Definition: server.h:118
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:128
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:221
int m_error_count
Definition: server.h:100
Upgrade_error_counter operator++(int)
Definition: server.cc:224
const int ERROR_LIMIT
Definition: server.h:101
Upgrade_error_counter()
Definition: server.h:104
bool has_errors()
Definition: server.cc:220
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:1093
void update_upgrade_history_file(bool initialize)
Maintain a file named "mysql_upgrade_history" in the data directory.
Definition: server.cc:848
bool do_server_upgrade_checks(THD *thd)
Performs validation on server metadata.
Definition: server.cc:970
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:1125
bool invalid_triggers(THD *thd, const char *schema_name, const dd::Table &table)
Validate all the triggers of the given table.
Definition: server.cc:1070
bool invalid_routine(THD *thd, const dd::Schema &schema, const dd::Routine &routine)
Validate a dd::Routine object.
Definition: server.cc:1030
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:421