MySQL  8.0.19
Source Code Documentation
bootstrap_ctx.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
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__BOOTSTRAP_CTX_INCLUDED
24 #define DD__BOOTSTRAP_CTX_INCLUDED
25 
26 #include <set>
27 
28 #include "my_dbug.h" // DBUG_ASSERT
29 #include "my_inttypes.h" // uint
30 #include "mysql_version.h" // MYSQL_VERSION_ID
31 #include "sql/dd/dd_version.h" // DD_VERSION
32 #include "sql/dd/info_schema/metadata.h" // IS_DD_VERSION
33 #include "sql/mysqld.h" // opt_initialize
34 
35 class THD;
36 
37 namespace dd {
38 namespace bootstrap {
39 
40 // Enumeration of bootstrapping stages.
41 enum class Stage {
42  NOT_STARTED, // Not started.
43  STARTED, // Started, nothing prepared yet.
44  CREATED_TABLESPACES, // Created predefined tablespaces.
45  FETCHED_PROPERTIES, // Done reading DD properties.
46  CREATED_TABLES, // Tables created, able to store persistently.
47  SYNCED, // Cached meta data synced with persistent storage.
48  UPGRADED_TABLES, // Created new table versions and migrated meta data.
49  POPULATED, // (Re)populated tables with meta data.
50  STORED_DD_META_DATA, // Stored the hard coded meta data of the DD tables.
51  VERSION_UPDATED, // The properties in 'dd_properties' are updated.
52  FINISHED // Completed.
53 };
54 
55 // Individual DD version labels that we can refer to.
56 static constexpr uint DD_VERSION_80011 = 80011;
57 static constexpr uint DD_VERSION_80012 = 80012;
58 static constexpr uint DD_VERSION_80013 = 80013;
59 static constexpr uint DD_VERSION_80014 = 80014;
60 static constexpr uint DD_VERSION_80015 = 80015;
61 static constexpr uint DD_VERSION_80016 = 80016;
62 static constexpr uint DD_VERSION_80017 = 80017;
63 
64 /*
65  Set of supported DD version labels. A supported DD version is a version
66  from which we can upgrade. In the case of downgrade, this is not relevant,
67  since the set of supported versions is defined when the server is built,
68  and newer version numbers are not added to this set. in the case of
69  downgrade, we instead have to check the MINOR_DOWNGRADE_THRESHOLD, which is
70  stored in the 'dd_properties' table by the server from which we downgrade.
71 */
72 static std::set<uint> supported_dd_versions = {
75 
76 // Individual server version labels that we can refer to.
77 static constexpr uint SERVER_VERSION_50700 = 50700;
78 static constexpr uint SERVER_VERSION_80011 = 80011;
79 static constexpr uint SERVER_VERSION_80013 = 80013;
80 static constexpr uint SERVER_VERSION_80014 = 80014;
81 static constexpr uint SERVER_VERSION_80015 = 80015;
82 static constexpr uint SERVER_VERSION_80016 = 80016;
83 
84 /*
85  Set of unsupported server version labels. An unsupported server version is a
86  version from which we can't upgrade.
87 */
88 static std::set<uint> unsupported_server_versions = {};
89 
91  private:
96 
99 
100  public:
102 
103  static DD_bootstrap_ctx &instance();
104 
105  Stage get_stage() const { return m_stage; }
106 
107  void set_stage(Stage stage) { m_stage = stage; }
108 
109  bool supported_dd_version() const {
111  supported_dd_versions.end());
112  }
113 
114  void set_actual_dd_version(uint actual_dd_version) {
115  m_actual_dd_version = actual_dd_version;
116  }
117 
118  void set_actual_I_S_version(uint actual_I_S_version) {
119  m_actual_I_S_version = actual_I_S_version;
120  }
121 
123 
125 
130  }
131 
132  bool dd_upgrade_done() const { return m_did_dd_upgrade_from != 0; }
133 
137  }
138 
139  bool I_S_upgrade_done() const { return m_did_I_S_upgrade_from != 0; }
140 
141  bool actual_dd_version_is(uint compare_actual_dd_version) const {
142  return (m_actual_dd_version == compare_actual_dd_version);
143  }
144 
146  return (unsupported_server_versions.find(version) ==
148  MYSQL_VERSION_ID > version;
149  }
150 
153  }
154 
155  void set_upgraded_server_version(uint upgraded_server_version) {
156  m_upgraded_server_version = upgraded_server_version;
157  }
158 
160 
161  bool upgraded_server_version_is(uint compare_upgraded_server_version) const {
162  return (m_upgraded_server_version == compare_upgraded_server_version);
163  }
164 
165  bool is_restart() const {
167  (m_upgraded_server_version == MYSQL_VERSION_ID);
168  }
169 
170  bool is_dd_upgrade() const {
172  }
173 
174  bool is_server_upgrade() const {
175  return !opt_initialize && (m_upgraded_server_version < MYSQL_VERSION_ID);
176  }
177 
178  bool is_dd_upgrade_from_before(uint compare_actual_dd_version) const {
179  return (is_dd_upgrade() && m_actual_dd_version < compare_actual_dd_version);
180  }
181 
183  uint compare_upgraded_server_version) const {
184  return (is_server_upgrade() &&
185  m_upgraded_server_version < compare_upgraded_server_version);
186  }
187 
189  uint compare_upgraded_server_version) const {
190  return (is_server_upgrade() &&
191  m_upgraded_server_version > compare_upgraded_server_version);
192  }
193 
194  bool is_minor_downgrade() const {
195  return !opt_initialize &&
196  (m_actual_dd_version / 10000 == dd::DD_VERSION / 10000) &&
198  }
199 
200  bool is_above_minor_downgrade_threshold(THD *thd) const;
201 
202  bool is_initialize() const {
204  }
205 };
206 
207 } // namespace bootstrap
208 } // namespace dd
209 
210 #endif // DD__BOOTSTRAP_CTX_INCLUDED
dd::bootstrap::DD_VERSION_80012
static constexpr uint DD_VERSION_80012
Definition: bootstrap_ctx.h:57
dd::bootstrap::DD_bootstrap_ctx::m_stage
Stage m_stage
Definition: bootstrap_ctx.h:95
THD
Definition: sql_class.h:764
dd::bootstrap::DD_bootstrap_ctx::get_stage
Stage get_stage() const
Definition: bootstrap_ctx.h:105
dd::DD_VERSION
static const uint DD_VERSION
Definition: dd_version.h:187
dd::bootstrap::DD_bootstrap_ctx::supported_server_version
bool supported_server_version() const
Definition: bootstrap_ctx.h:151
dd::bootstrap::DD_bootstrap_ctx::is_server_upgrade_from_before
bool is_server_upgrade_from_before(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:182
dd::bootstrap::SERVER_VERSION_50700
static constexpr uint SERVER_VERSION_50700
Definition: bootstrap_ctx.h:77
dd::bootstrap::DD_bootstrap_ctx::m_did_I_S_upgrade_from
uint m_did_I_S_upgrade_from
Definition: bootstrap_ctx.h:97
metadata.h
dd_version.h
dd::bootstrap::DD_bootstrap_ctx::get_upgraded_server_version
uint get_upgraded_server_version() const
Definition: bootstrap_ctx.h:159
bootstrap
Definition: bootstrap.cc:68
version
const string version("\"Version\"")
dd::bootstrap::SERVER_VERSION_80013
static constexpr uint SERVER_VERSION_80013
Definition: bootstrap_ctx.h:79
dd::bootstrap::Stage::POPULATED
@ POPULATED
my_dbug.h
dd::bootstrap::DD_bootstrap_ctx::set_stage
void set_stage(Stage stage)
Definition: bootstrap_ctx.h:107
dd::bootstrap::DD_bootstrap_ctx::is_dd_upgrade_from_before
bool is_dd_upgrade_from_before(uint compare_actual_dd_version) const
Definition: bootstrap_ctx.h:178
dd::bootstrap::DD_bootstrap_ctx::set_actual_I_S_version
void set_actual_I_S_version(uint actual_I_S_version)
Definition: bootstrap_ctx.h:118
dd::bootstrap::DD_bootstrap_ctx::get_actual_I_S_version
uint get_actual_I_S_version() const
Definition: bootstrap_ctx.h:124
dd::bootstrap::DD_bootstrap_ctx::upgraded_server_version_is
bool upgraded_server_version_is(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:161
dd
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
dd::bootstrap::SERVER_VERSION_80011
static constexpr uint SERVER_VERSION_80011
Definition: bootstrap_ctx.h:78
dd::bootstrap::DD_bootstrap_ctx::dd_upgrade_done
bool dd_upgrade_done() const
Definition: bootstrap_ctx.h:132
dd::bootstrap::DD_VERSION_80016
static constexpr uint DD_VERSION_80016
Definition: bootstrap_ctx.h:61
dd::bootstrap::Stage::CREATED_TABLES
@ CREATED_TABLES
dd::bootstrap::supported_dd_versions
static std::set< uint > supported_dd_versions
Definition: bootstrap_ctx.h:72
dd::bootstrap::Stage::STORED_DD_META_DATA
@ STORED_DD_META_DATA
dd::bootstrap::DD_bootstrap_ctx::is_server_upgrade
bool is_server_upgrade() const
Definition: bootstrap_ctx.h:174
dd::bootstrap::DD_bootstrap_ctx::m_upgraded_server_version
uint m_upgraded_server_version
Definition: bootstrap_ctx.h:94
dd::bootstrap::Stage::FINISHED
@ FINISHED
dd::bootstrap::DD_bootstrap_ctx::supported_dd_version
bool supported_dd_version() const
Definition: bootstrap_ctx.h:109
my_inttypes.h
dd::bootstrap::Stage::SYNCED
@ SYNCED
dd::bootstrap::DD_bootstrap_ctx::set_I_S_upgrade_done
void set_I_S_upgrade_done()
Definition: bootstrap_ctx.h:134
dd::bootstrap::DD_bootstrap_ctx::is_restart
bool is_restart() const
Definition: bootstrap_ctx.h:165
dd::bootstrap::DD_VERSION_80015
static constexpr uint DD_VERSION_80015
Definition: bootstrap_ctx.h:60
dd::bootstrap::DD_bootstrap_ctx::instance
static DD_bootstrap_ctx & instance()
Definition: bootstrap_ctx.cc:29
uint
unsigned int uint
Definition: uca-dump.cc:29
dd::bootstrap::SERVER_VERSION_80014
static constexpr uint SERVER_VERSION_80014
Definition: bootstrap_ctx.h:80
dd::bootstrap::DD_VERSION_80013
static constexpr uint DD_VERSION_80013
Definition: bootstrap_ctx.h:58
dd::bootstrap::Stage::STARTED
@ STARTED
dd::bootstrap::DD_VERSION_80011
static constexpr uint DD_VERSION_80011
Definition: bootstrap_ctx.h:56
dd::bootstrap::DD_bootstrap_ctx::m_did_dd_upgrade_from
uint m_did_dd_upgrade_from
Definition: bootstrap_ctx.h:92
dd::bootstrap::DD_bootstrap_ctx::DD_bootstrap_ctx
DD_bootstrap_ctx()
Definition: bootstrap_ctx.h:101
dd::bootstrap::DD_bootstrap_ctx::is_server_upgrade_from_after
bool is_server_upgrade_from_after(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:188
dd::bootstrap::DD_bootstrap_ctx::is_dd_upgrade
bool is_dd_upgrade() const
Definition: bootstrap_ctx.h:170
dd::bootstrap::DD_bootstrap_ctx::m_actual_I_S_version
uint m_actual_I_S_version
Definition: bootstrap_ctx.h:98
dd::bootstrap::DD_VERSION_80017
static constexpr uint DD_VERSION_80017
Definition: bootstrap_ctx.h:62
dd::bootstrap::DD_VERSION_80014
static constexpr uint DD_VERSION_80014
Definition: bootstrap_ctx.h:59
dd::bootstrap::Stage::CREATED_TABLESPACES
@ CREATED_TABLESPACES
dd::bootstrap::unsupported_server_versions
static std::set< uint > unsupported_server_versions
Definition: bootstrap_ctx.h:88
dd::bootstrap::DD_bootstrap_ctx::is_above_minor_downgrade_threshold
bool is_above_minor_downgrade_threshold(THD *thd) const
Definition: bootstrap_ctx.cc:34
dd::bootstrap::DD_bootstrap_ctx::supported_server_version
bool supported_server_version(uint version) const
Definition: bootstrap_ctx.h:145
DBUG_ASSERT
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
dd::bootstrap::DD_bootstrap_ctx::set_actual_dd_version
void set_actual_dd_version(uint actual_dd_version)
Definition: bootstrap_ctx.h:114
dd::bootstrap::DD_bootstrap_ctx::m_actual_dd_version
uint m_actual_dd_version
Definition: bootstrap_ctx.h:93
mysqld.h
dd::bootstrap::DD_bootstrap_ctx::I_S_upgrade_done
bool I_S_upgrade_done() const
Definition: bootstrap_ctx.h:139
dd::bootstrap::SERVER_VERSION_80015
static constexpr uint SERVER_VERSION_80015
Definition: bootstrap_ctx.h:81
dd::bootstrap::DD_bootstrap_ctx::is_minor_downgrade
bool is_minor_downgrade() const
Definition: bootstrap_ctx.h:194
dd::bootstrap::DD_bootstrap_ctx::get_actual_dd_version
uint get_actual_dd_version() const
Definition: bootstrap_ctx.h:122
dd::bootstrap::SERVER_VERSION_80016
static constexpr uint SERVER_VERSION_80016
Definition: bootstrap_ctx.h:82
dd::bootstrap::DD_bootstrap_ctx::is_initialize
bool is_initialize() const
Definition: bootstrap_ctx.h:202
dd::bootstrap::Stage::FETCHED_PROPERTIES
@ FETCHED_PROPERTIES
dd::bootstrap::DD_bootstrap_ctx::actual_dd_version_is
bool actual_dd_version_is(uint compare_actual_dd_version) const
Definition: bootstrap_ctx.h:141
dd::bootstrap::DD_bootstrap_ctx
Definition: bootstrap_ctx.h:90
opt_initialize
bool opt_initialize
Definition: mysqld.cc:1027
dd::bootstrap::DD_bootstrap_ctx::set_dd_upgrade_done
void set_dd_upgrade_done()
Definition: bootstrap_ctx.h:126
dd::bootstrap::Stage::NOT_STARTED
@ NOT_STARTED
dd::bootstrap::Stage::VERSION_UPDATED
@ VERSION_UPDATED
dd::bootstrap::Stage::UPGRADED_TABLES
@ UPGRADED_TABLES
dd::bootstrap::Stage
Stage
Definition: bootstrap_ctx.h:41
dd::bootstrap::DD_bootstrap_ctx::set_upgraded_server_version
void set_upgraded_server_version(uint upgraded_server_version)
Definition: bootstrap_ctx.h:155