MySQL 8.0.37
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 <stdio.h>
28
29#include <set>
30
31#include "my_sys.h" // ErrorHandlerFunctionPointer
32#include "sql/dd/string_type.h"
33#include "sql/error_handler.h" // Internal_error_handler
34
35class THD;
36class Time_zone;
37
39
40namespace dd {
41class Routine;
42class Schema;
43class Table;
44
45namespace upgrade {
46/**
47 Bootstrap thread executes SQL statements.
48 Any error in the execution of SQL statements causes call to my_error().
49 At this moment, error handler hook is set to my_message_stderr.
50 my_message_stderr() prints the error messages to standard error stream but
51 it does not follow the standard error format. Further, the error status is
52 not set in Diagnostics Area.
53
54 This class is to create RAII error handler hooks to be used when executing
55 statements from bootstrap thread.
56
57 It will print the error in the standard error format.
58 Diagnostics Area error status will be set to avoid asserts.
59 Error will be handler by caller function.
60*/
61
63 private:
65
66 // Set the error in DA. Optionally print error in log.
67 static void my_message_bootstrap(uint error, const char *str, myf MyFlags);
68
69 // Set abort on error flag and enable error logging for certain fatal error.
70 static void set_abort_on_error(uint error);
71
72 // Check if error should be logged.
73 static bool should_log_error(uint error);
74
75 public:
77
78 // Log all errors to the error log file too.
79 void set_log_error(bool log_error);
80
81 void set_allowlist_errors(std::set<uint> &error_codes);
83
85 static bool m_log_error;
86 static bool abort_on_error;
87 // Set of errors which are logged to error log file always.
88 static std::set<uint> m_allowlist_errors;
89};
90
91/**
92 Class to keep track of upgrade errors during upgrade after 8.0 GA.
93*/
95 private:
97 const int ERROR_LIMIT;
98
99 public:
101 bool has_errors();
102 bool has_too_many_errors();
104};
105
106/**
107 This class keeps a count of all the syntax errors that occurred while parsing
108 views, routines, events or triggers. This count is used along with
109 MAX_SERVER_CHECK_FAILS to exit upgrade.
110*/
112 public:
116 bool handle_condition(THD *, uint sql_errno, const char *,
118 const char *msg) override;
119
120 static bool has_too_many_errors();
121 static bool has_errors();
122 static const char *error_message();
123
125 static bool is_parse_error;
129};
130
131/**
132 RAII for handling creation context of Events and
133 Stored routines.
134*/
135
142
143 public:
146};
147
148/**
149 Performs validation on server metadata.
150
151 @param thd Thread context.
152
153 @return Upon failure, return true, otherwise false.
154 */
156
157/**
158 * @brief Validate the SQL string provided.
159 *
160 * @param thd Thread handle
161 * @param dbname The database used in the SQL string's context.
162 * @param sql The SQL string to be validated
163 * @return true
164 * @return false
165 */
166bool invalid_sql(THD *thd, const char *dbname, const dd::String_type &sql);
167
168/**
169 Validate all the triggers of the given table.
170
171 @param[in] thd Thread handle.
172 @param[in] schema_name Pointer for database name.
173 @param[in] table Triggers of the table to be checked.
174
175 @retval false ON SUCCESS
176 @retval true ON FAILURE
177*/
178bool invalid_triggers(THD *thd, const char *schema_name,
179 const dd::Table &table);
180
181/**
182 Validate a dd::Routine object.
183
184 @param[in] thd Thread handle.
185 @param[in] schema Schema in which the routine belongs.
186 @param[in] routine Routine to be validated.
187
188 @retval false ON SUCCESS
189 @retval true ON FAILURE
190*/
191bool invalid_routine(THD *thd, const dd::Schema &schema,
192 const dd::Routine &routine);
193
194/**
195 Helper function to create a stored procedure from an event body.
196
197 @param[in] thd Thread handle.
198 @param[in] name Name of the event.
199 @param[in] name_len Length of the name of the event.
200 @param[in] body Body of the event.
201 @param[in] body_len Length of the body of the event.
202 @param[out] sp_sql Stored procedure SQL string.
203
204 @retval false ON SUCCESS
205 @retval true ON FAILURE
206*/
207bool build_event_sp(const THD *thd, const char *name, size_t name_len,
208 const char *body, size_t body_len, dd::String_type *sp_sql);
209} // namespace upgrade
210
211} // namespace dd
212#endif // DD_UPGRADE_IMPL__SERVER_H_INCLUDED
#define log_error
Definition: log_client.h:111
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:34
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:62
void clear_allowlist_errors()
Definition: server.cc:131
ErrorHandlerFunctionPointer m_old_error_handler_hook
Definition: server.h:64
Bootstrap_error_handler()
Definition: server.cc:109
static void set_abort_on_error(uint error)
Definition: server.cc:97
static bool should_log_error(uint error)
Definition: server.cc:120
static bool abort_on_error
Definition: server.h:86
static void my_message_bootstrap(uint error, const char *str, myf MyFlags)
Definition: server.cc:84
~Bootstrap_error_handler()
Definition: server.cc:135
static std::set< uint > m_allowlist_errors
Definition: server.h:88
void set_allowlist_errors(std::set< uint > &error_codes)
Definition: server.cc:126
void set_log_error(bool log_error)
Definition: server.cc:116
static bool m_log_error
Definition: server.h:85
RAII for handling creation context of Events and Stored routines.
Definition: server.h:136
THD * m_thd
Definition: server.h:137
::Time_zone * m_saved_time_zone
Definition: server.h:139
const CHARSET_INFO * m_client_cs
Definition: server.h:140
const CHARSET_INFO * m_connection_cl
Definition: server.h:141
~Routine_event_context_guard()
Definition: server.cc:158
Routine_event_context_guard(THD *thd)
Definition: server.cc:150
sql_mode_t m_sql_mode
Definition: server.h:138
This class keeps a count of all the syntax errors that occurred while parsing views,...
Definition: server.h:111
static bool is_parse_error
Definition: server.h:125
Syntax_error_handler()
Definition: server.h:113
static bool has_too_many_errors()
Definition: server.cc:189
static const uint MAX_SERVER_CHECK_FAILS
Definition: server.h:126
Upgrade_error_counter * m_global_counter
Definition: server.h:128
static bool has_errors()
Definition: server.cc:193
static dd::String_type reason
Definition: server.h:127
static const char * error_message()
Definition: server.cc:195
Syntax_error_handler(Upgrade_error_counter *counter)
Definition: server.h:114
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:174
static uint parse_error_count
Definition: server.h:124
Class to keep track of upgrade errors during upgrade after 8.0 GA.
Definition: server.h:94
bool has_too_many_errors()
Definition: server.cc:202
int m_error_count
Definition: server.h:96
Upgrade_error_counter operator++(int)
Definition: server.cc:205
const int ERROR_LIMIT
Definition: server.h:97
Upgrade_error_counter()
Definition: server.h:100
bool has_errors()
Definition: server.cc:201
ulonglong sql_mode_t
Definition: dd_event.h:37
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
void(*)(uint, const char *, myf) ErrorHandlerFunctionPointer
Definition: my_sys.h:224
int myf
Definition: my_inttypes.h:94
unsigned long long int ulonglong
Definition: my_inttypes.h:56
Common header for many mysys elements.
uint counter
Definition: mysqlimport.cc:54
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1044
borrowable::session_track::Schema< true > Schema
Definition: classic_protocol_session_track.h:277
bool invalid_sql(THD *thd, const char *dbname, const dd::String_type &sql)
Validate the SQL string provided.
Definition: server.cc:812
bool do_server_upgrade_checks(THD *thd)
Performs validation on server metadata.
Definition: server.cc:694
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:844
bool invalid_triggers(THD *thd, const char *schema_name, const dd::Table &table)
Validate all the triggers of the given table.
Definition: server.cc:789
bool invalid_routine(THD *thd, const dd::Schema &schema, const dd::Routine &routine)
Validate a dd::Routine object.
Definition: server.cc:749
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
case opt name
Definition: sslopt-case.h:33
Definition: m_ctype.h:385
unsigned int uint
Definition: uca9-dump.cc:75