File: server.h

package info (click to toggle)
mysql-8.0 8.0.45-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,048 kB
  • sloc: cpp: 4,685,434; ansic: 412,712; pascal: 108,396; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; python: 21,816; sh: 17,285; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,083; makefile: 1,793; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (212 lines) | stat: -rw-r--r-- 6,666 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* Copyright (c) 2019, 2025, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is designed to work with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have either included with
   the program or referenced in the documentation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#ifndef DD_UPGRADE_IMPL__SERVER_H_INCLUDED
#define DD_UPGRADE_IMPL__SERVER_H_INCLUDED

#include <stdio.h>

#include <set>

#include "my_sys.h"  // ErrorHandlerFunctionPointer
#include "sql/dd/string_type.h"
#include "sql/error_handler.h"  // Internal_error_handler

class THD;
class Time_zone;

using sql_mode_t = ulonglong;

namespace dd {
class Routine;
class Schema;
class Table;

namespace upgrade {
/**
  Bootstrap thread executes SQL statements.
  Any error in the execution of SQL statements causes call to my_error().
  At this moment, error handler hook is set to my_message_stderr.
  my_message_stderr() prints the error messages to standard error stream but
  it does not follow the standard error format. Further, the error status is
  not set in Diagnostics Area.

  This class is to create RAII error handler hooks to be used when executing
  statements from bootstrap thread.

  It will print the error in the standard error format.
  Diagnostics Area error status will be set to avoid asserts.
  Error will be handler by caller function.
*/

class Bootstrap_error_handler {
 private:
  ErrorHandlerFunctionPointer m_old_error_handler_hook;

  //  Set the error in DA. Optionally print error in log.
  static void my_message_bootstrap(uint error, const char *str, myf MyFlags);

  // Set abort on error flag and enable error logging for certain fatal error.
  static void set_abort_on_error(uint error);

  // Check if error should be logged.
  static bool should_log_error(uint error);

 public:
  Bootstrap_error_handler();

  // Log all errors to the error log file too.
  void set_log_error(bool log_error);

  void set_allowlist_errors(std::set<uint> &error_codes);
  void clear_allowlist_errors();

  ~Bootstrap_error_handler();
  static bool m_log_error;
  static bool abort_on_error;
  // Set of errors which are logged to error log file always.
  static std::set<uint> m_allowlist_errors;
};

/**
  Class to keep track of upgrade errors during upgrade after 8.0 GA.
*/
class Upgrade_error_counter {
 private:
  int m_error_count;
  const int ERROR_LIMIT;

 public:
  Upgrade_error_counter() : m_error_count(0), ERROR_LIMIT(50) {}
  bool has_errors();
  bool has_too_many_errors();
  Upgrade_error_counter operator++(int);
};

/**
  This class keeps a count of all the syntax errors that occurred while parsing
  views, routines, events or triggers. This count is used along with
  MAX_SERVER_CHECK_FAILS to exit upgrade.
*/
class Syntax_error_handler : public Internal_error_handler {
 public:
  Syntax_error_handler() : m_global_counter(nullptr) {}
  Syntax_error_handler(Upgrade_error_counter *counter)
      : m_global_counter(counter) {}
  bool handle_condition(THD *, uint sql_errno, const char *,
                        Sql_condition::enum_severity_level *,
                        const char *msg) override;

  static bool has_too_many_errors();
  static bool has_errors();
  static const char *error_message();

  static uint parse_error_count;
  static bool is_parse_error;
  static const uint MAX_SERVER_CHECK_FAILS;
  static dd::String_type reason;
  Upgrade_error_counter *m_global_counter;
};

/**
   RAII for handling creation context of Events and
   Stored routines.
*/

class Routine_event_context_guard {
  THD *m_thd;
  sql_mode_t m_sql_mode;
  ::Time_zone *m_saved_time_zone;
  const CHARSET_INFO *m_client_cs;
  const CHARSET_INFO *m_connection_cl;

 public:
  Routine_event_context_guard(THD *thd);
  ~Routine_event_context_guard();
};

/**
  Performs validation on server metadata.

  @param thd    Thread context.

  @return       Upon failure, return true, otherwise false.
 */
bool do_server_upgrade_checks(THD *thd);

/**
 * @brief Validate the SQL string provided.
 *
 * @param thd       Thread handle
 * @param dbname    The database used in the SQL string's context.
 * @param sql       The SQL string to be validated
 * @return true
 * @return false
 */
bool invalid_sql(THD *thd, const char *dbname, const dd::String_type &sql);

/**
  Validate all the triggers of the given table.

  @param[in]  thd                        Thread handle.
  @param[in]  schema_name                Pointer for database name.
  @param[in]  table                      Triggers of the table to be checked.

  @retval false  ON SUCCESS
  @retval true   ON FAILURE
*/
bool invalid_triggers(THD *thd, const char *schema_name,
                      const dd::Table &table);

/**
  Validate a dd::Routine object.

  @param[in]  thd        Thread handle.
  @param[in]  schema     Schema in which the routine belongs.
  @param[in]  routine    Routine to be validated.

  @retval false  ON SUCCESS
  @retval true   ON FAILURE
*/
bool invalid_routine(THD *thd, const dd::Schema &schema,
                     const dd::Routine &routine);

/**
  Helper function to create a stored procedure from an event body.

  @param[in]  thd             Thread handle.
  @param[in]  name            Name of the event.
  @param[in]  name_len        Length of the name of the event.
  @param[in]  body            Body of the event.
  @param[in]  body_len        Length of the body of the event.
  @param[out] sp_sql          Stored procedure SQL string.

  @retval false  ON SUCCESS
  @retval true   ON FAILURE
*/
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);
}  // namespace upgrade

}  // namespace dd
#endif  // DD_UPGRADE_IMPL__SERVER_H_INCLUDED