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