MySQL 8.0.33
Source Code Documentation
server.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef DD_UPGRADE_IMPL__SERVER_H_INCLUDED
24#define DD_UPGRADE_IMPL__SERVER_H_INCLUDED
25
26#include <stdio.h>
27
28#include <set>
29
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
38
39namespace dd {
40class Routine;
41class Schema;
42class Table;
43
44namespace upgrade {
45/**
46 Bootstrap thread executes SQL statements.
47 Any error in the execution of SQL statements causes call to my_error().
48 At this moment, error handler hook is set to my_message_stderr.
49 my_message_stderr() prints the error messages to standard error stream but
50 it does not follow the standard error format. Further, the error status is
51 not set in Diagnostics Area.
52
53 This class is to create RAII error handler hooks to be used when executing
54 statements from bootstrap thread.
55
56 It will print the error in the standard error format.
57 Diagnostics Area error status will be set to avoid asserts.
58 Error will be handler by caller function.
59*/
60
62 private:
64
65 // Set the error in DA. Optionally print error in log.
66 static void my_message_bootstrap(uint error, const char *str, myf MyFlags);
67
68 // Set abort on error flag and enable error logging for certain fatal error.
69 static void set_abort_on_error(uint error);
70
71 // Check if error should be logged.
72 static bool should_log_error(uint error);
73
74 public:
76
77 // Log all errors to the error log file too.
78 void set_log_error(bool log_error);
79
80 void set_allowlist_errors(std::set<uint> &error_codes);
82
84 static bool m_log_error;
85 static bool abort_on_error;
86 // Set of errors which are logged to error log file always.
87 static std::set<uint> m_allowlist_errors;
88};
89
90/**
91 Class to keep track of upgrade errors during upgrade after 8.0 GA.
92*/
94 private:
96 const int ERROR_LIMIT;
97
98 public:
100 bool has_errors();
101 bool has_too_many_errors();
103};
104
105/**
106 This class keeps a count of all the syntax errors that occurred while parsing
107 views, routines, events or triggers. This count is used along with
108 MAX_SERVER_CHECK_FAILS to exit upgrade.
109*/
111 public:
115 bool handle_condition(THD *, uint sql_errno, const char *,
117 const char *msg) override;
118
119 static bool has_too_many_errors();
120 static bool has_errors();
121 static const char *error_message();
122
124 static bool is_parse_error;
128};
129
130/**
131 RAII for handling creation context of Events and
132 Stored routines.
133*/
134
141
142 public:
145};
146
147/**
148 Performs validation on server metadata.
149
150 @param thd Thread context.
151
152 @return Upon failure, return true, otherwise false.
153 */
155
156/**
157 * @brief Validate the SQL string provided.
158 *
159 * @param thd Thread handle
160 * @param dbname The database used in the SQL string's context.
161 * @param sql The SQL string to be validated
162 * @return true
163 * @return false
164 */
165bool invalid_sql(THD *thd, const char *dbname, const dd::String_type &sql);
166
167/**
168 Validate all the triggers of the given table.
169
170 @param[in] thd Thread handle.
171 @param[in] schema_name Pointer for database name.
172 @param[in] table Triggers of the table to be checked.
173
174 @retval false ON SUCCESS
175 @retval true ON FAILURE
176*/
177bool invalid_triggers(THD *thd, const char *schema_name,
178 const dd::Table &table);
179
180/**
181 Validate a dd::Routine object.
182
183 @param[in] thd Thread handle.
184 @param[in] schema Schema in which the routine belongs.
185 @param[in] routine Routine to be validated.
186
187 @retval false ON SUCCESS
188 @retval true ON FAILURE
189*/
190bool invalid_routine(THD *thd, const dd::Schema &schema,
191 const dd::Routine &routine);
192
193/**
194 Helper function to create a stored procedure from an event body.
195
196 @param[in] thd Thread handle.
197 @param[in] name Name of the event.
198 @param[in] name_len Length of the name of the event.
199 @param[in] body Body of the event.
200 @param[in] body_len Length of the body of the event.
201 @param[out] sp_sql Stored procedure SQL string.
202
203 @retval false ON SUCCESS
204 @retval true ON FAILURE
205*/
206bool build_event_sp(const THD *thd, const char *name, size_t name_len,
207 const char *body, size_t body_len, dd::String_type *sp_sql);
208} // namespace upgrade
209
210} // namespace dd
211#endif // DD_UPGRADE_IMPL__SERVER_H_INCLUDED
#define log_error
Definition: log_client.h:110
This class represents the interface for internal error handlers.
Definition: error_handler.h:46
enum_severity_level
Enumeration value describing the severity of the condition.
Definition: sql_error.h:62
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t co...
Definition: tztime.h:48
Abstract base class for functions and procedures.
Definition: routine.h:60
Definition: schema.h:62
Definition: table.h:46
Bootstrap thread executes SQL statements.
Definition: server.h:61
void clear_allowlist_errors()
Definition: server.cc:130
ErrorHandlerFunctionPointer m_old_error_handler_hook
Definition: server.h:63
Bootstrap_error_handler()
Definition: server.cc:108
static void set_abort_on_error(uint error)
Definition: server.cc:96
static bool should_log_error(uint error)
Definition: server.cc:119
static bool abort_on_error
Definition: server.h:85
static void my_message_bootstrap(uint error, const char *str, myf MyFlags)
Definition: server.cc:83
~Bootstrap_error_handler()
Definition: server.cc:134
static std::set< uint > m_allowlist_errors
Definition: server.h:87
void set_allowlist_errors(std::set< uint > &error_codes)
Definition: server.cc:125
void set_log_error(bool log_error)
Definition: server.cc:115
static bool m_log_error
Definition: server.h:84
RAII for handling creation context of Events and Stored routines.
Definition: server.h:135
THD * m_thd
Definition: server.h:136
::Time_zone * m_saved_time_zone
Definition: server.h:138
const CHARSET_INFO * m_client_cs
Definition: server.h:139
const CHARSET_INFO * m_connection_cl
Definition: server.h:140
~Routine_event_context_guard()
Definition: server.cc:157
Routine_event_context_guard(THD *thd)
Definition: server.cc:149
sql_mode_t m_sql_mode
Definition: server.h:137
This class keeps a count of all the syntax errors that occurred while parsing views,...
Definition: server.h:110
static bool is_parse_error
Definition: server.h:124
Syntax_error_handler()
Definition: server.h:112
static bool has_too_many_errors()
Definition: server.cc:188
static const uint MAX_SERVER_CHECK_FAILS
Definition: server.h:125
Upgrade_error_counter * m_global_counter
Definition: server.h:127
static bool has_errors()
Definition: server.cc:192
static dd::String_type reason
Definition: server.h:126
static const char * error_message()
Definition: server.cc:194
Syntax_error_handler(Upgrade_error_counter *counter)
Definition: server.h:113
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:173
static uint parse_error_count
Definition: server.h:123
Class to keep track of upgrade errors during upgrade after 8.0 GA.
Definition: server.h:93
bool has_too_many_errors()
Definition: server.cc:201
int m_error_count
Definition: server.h:95
Upgrade_error_counter operator++(int)
Definition: server.cc:204
const int ERROR_LIMIT
Definition: server.h:96
Upgrade_error_counter()
Definition: server.h:99
bool has_errors()
Definition: server.cc:200
ulonglong sql_mode_t
Definition: dd_event.h:36
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
void(*)(uint, const char *, myf) ErrorHandlerFunctionPointer
Definition: my_sys.h:223
int myf
Definition: my_inttypes.h:93
unsigned long long int ulonglong
Definition: my_inttypes.h:55
Common header for many mysys elements.
uint counter
Definition: mysqlimport.cc:53
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1054
borrowable::session_track::Schema< true > Schema
Definition: classic_protocol_session_track.h:276
bool invalid_sql(THD *thd, const char *dbname, const dd::String_type &sql)
Validate the SQL string provided.
Definition: server.cc:807
bool do_server_upgrade_checks(THD *thd)
Performs validation on server metadata.
Definition: server.cc:689
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:839
bool invalid_triggers(THD *thd, const char *schema_name, const dd::Table &table)
Validate all the triggers of the given table.
Definition: server.cc:784
bool invalid_routine(THD *thd, const dd::Schema &schema, const dd::Routine &routine)
Validate a dd::Routine object.
Definition: server.cc:744
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
case opt name
Definition: sslopt-case.h:32
Definition: m_ctype.h:382
unsigned int uint
Definition: uca9-dump.cc:74