MySQL  8.0.27
Source Code Documentation
sql_system_table_check.h
Go to the documentation of this file.
1 /* Copyright (c) 2020, 2021, 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 SQL_SYSTEM_TABLE_CHECK_INCLUDED
24 #define SQL_SYSTEM_TABLE_CHECK_INCLUDED
25 
26 #include "my_loglevel.h" // enum loglevel
27 #include "mysql/components/services/log_builtins.h" // LogErr, LogEvent
28 #include "mysqld_error.h" // ER_*
29 #include "sql/table.h" // Table_check_intact
30 
31 class THD;
32 
33 /**
34  Class to check if system table is intact.
35 */
37  public:
38  explicit System_table_intact(THD *thd, enum loglevel log_level = ERROR_LEVEL)
39  : m_thd(thd), m_log_level(log_level) {
40  has_keys = true;
41  }
42 
43  THD *thd() { return m_thd; }
44 
45  protected:
46  void report_error(uint code, const char *fmt, ...) override
47  MY_ATTRIBUTE((format(printf, 3, 4))) {
48  va_list args;
49  va_start(args, fmt);
50 
51  if (code == 0)
52  LogEvent()
54  .errcode(ER_SERVER_TABLE_CHECK_FAILED)
57  .messagev(fmt, args);
58  else if (code == ER_CANNOT_LOAD_FROM_TABLE_V2) {
59  char *db_name, *table_name;
60  db_name = va_arg(args, char *);
61  table_name = va_arg(args, char *);
62  my_error(code, MYF(0), db_name, table_name);
63  LogErr(m_log_level, ER_SERVER_CANNOT_LOAD_FROM_TABLE_V2, db_name,
64  table_name);
65  } else {
66  my_printv_error(code, ER_THD_NONCONST(m_thd, code), MYF(0), args);
67  va_end(args);
68 
69  if (code == ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE_V2)
70  code = ER_SERVER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE_V2;
71  else if (code == ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2)
72  code = ER_SERVER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2;
73  else
74  code = ER_SERVER_ACL_TABLE_ERROR;
75 
76  va_start(args, fmt);
77  LogEvent()
79  .errcode(code)
82  .messagev(fmt, args);
83  }
84 
85  va_end(args);
86  }
87 
88  private:
90  enum loglevel m_log_level;
91 };
92 #endif // SQL_SYSTEM_TABLE_CHECK_INCLUDED
Modular logger: fluid API.
Definition: log_builtins.h:865
LogEvent & source_file(const char *val)
Which source file was the problem detected in?
Definition: log_builtins.h:1022
LogEvent & errcode(longlong val)
Append a numeric error code.
Definition: log_builtins.h:961
LogEvent & prio(longlong val)
Set error message priority.
Definition: log_builtins.h:1184
LogEvent & messagev(const char *fmt, va_list ap)
Fill in a format string by substituting the % with the given arguments, then add the result as the ev...
Definition: log_builtins.h:1236
LogEvent & subsys(const char *val)
Which subsystem in the source was the problem detected in? ("Repl"/"InnoDB"/"Server")
Definition: log_builtins.h:1059
Class to check if system table is intact.
Definition: sql_system_table_check.h:36
enum loglevel m_log_level
Definition: sql_system_table_check.h:90
THD * thd()
Definition: sql_system_table_check.h:43
THD * m_thd
Definition: sql_system_table_check.h:89
System_table_intact(THD *thd, enum loglevel log_level=ERROR_LEVEL)
Definition: sql_system_table_check.h:38
void report_error(uint code, const char *fmt,...) override
Definition: sql_system_table_check.h:46
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
Definition: table.h:593
bool has_keys
Definition: table.h:595
const char * ER_THD_NONCONST(const THD *thd, int mysql_errno)
Definition: derror.cc:110
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:215
void my_printv_error(uint error, const char *format, myf MyFlags, va_list ap)
Print an error message.
Definition: my_error.cc:289
#define LogErr(severity, ecode,...)
Definition: log_builtins.h:827
#define LOG_SUBSYSTEM_TAG
Definition: log_sink_test.cc:26
#define MY_BASENAME
Definition: my_basename.h:39
#define MYF(v)
Definition: my_inttypes.h:96
Definition of the global "loglevel" enumeration.
loglevel
Definition: my_loglevel.h:40
@ WARNING_LEVEL
Definition: my_loglevel.h:43
@ ERROR_LEVEL
Definition: my_loglevel.h:42
const char * table_name
Definition: rules_table_service.cc:55
const char * db_name
Definition: rules_table_service.cc:54
unsigned int uint
Definition: uca-dump.cc:29