MySQL 9.2.0
Source Code Documentation
bootstrap_ctx.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef DD__BOOTSTRAP_CTX_INCLUDED
25#define DD__BOOTSTRAP_CTX_INCLUDED
26
27#include <assert.h>
28#include <set>
29
30#include "my_inttypes.h" // uint
31#include "mysql_version.h" // MYSQL_VERSION_ID
32#include "sql/dd/dd_version.h" // DD_VERSION
33#include "sql/dd/info_schema/metadata.h" // IS_DD_VERSION
34#include "sql/mysqld.h" // opt_initialize
35
36class THD;
37
38namespace dd {
39namespace bootstrap {
40
41// Enumeration of bootstrapping stages.
42enum class Stage {
43 NOT_STARTED, // Not started.
44 STARTED, // Started, nothing prepared yet.
45 CREATED_TABLESPACES, // Created predefined tablespaces.
46 FETCHED_PROPERTIES, // Done reading DD properties.
47 CREATED_TABLES, // Tables created, able to store persistently.
48 SYNCED, // Cached meta data synced with persistent storage.
49 UPGRADED_TABLES, // Created new table versions and migrated meta data.
50 POPULATED, // (Re)populated tables with meta data.
51 STORED_DD_META_DATA, // Stored the hard coded meta data of the DD tables.
52 VERSION_UPDATED, // The properties in 'dd_properties' are updated.
53 FINISHED // Completed.
54};
55
56// Individual DD version labels that we can refer to.
57static constexpr uint DD_VERSION_80011 = 80011;
58static constexpr uint DD_VERSION_80012 = 80012;
59static constexpr uint DD_VERSION_80013 = 80013;
60static constexpr uint DD_VERSION_80014 = 80014;
61static constexpr uint DD_VERSION_80015 = 80015;
62static constexpr uint DD_VERSION_80016 = 80016;
63static constexpr uint DD_VERSION_80017 = 80017;
64static constexpr uint DD_VERSION_80021 = 80021;
65static constexpr uint DD_VERSION_80022 = 80022;
66static constexpr uint DD_VERSION_80023 = 80023;
67static constexpr uint DD_VERSION_80200 = 80200;
68static constexpr uint DD_VERSION_80300 = 80300;
69static constexpr uint DD_VERSION_80400 = 80400;
70static constexpr uint DD_VERSION_90000 = 90000;
71static constexpr uint DD_VERSION_90200 = 90200;
72
73/*
74 Set of supported DD version labels. A supported DD version is a version
75 from which we can upgrade. In the case of downgrade, this is not relevant,
76 since the set of supported versions is defined when the server is built,
77 and newer version numbers are not added to this set. in the case of
78 downgrade, we instead have to check the MINOR_DOWNGRADE_THRESHOLD, which is
79 stored in the 'dd_properties' table by the server from which we downgrade.
80*/
81static std::set<uint> supported_dd_versions = {
86
87// Individual server version labels that we can refer to.
88static constexpr uint SERVER_VERSION_50700 = 50700;
89static constexpr uint SERVER_VERSION_80011 = 80011;
90static constexpr uint SERVER_VERSION_80013 = 80013;
91static constexpr uint SERVER_VERSION_80014 = 80014;
92static constexpr uint SERVER_VERSION_80015 = 80015;
93static constexpr uint SERVER_VERSION_80016 = 80016;
94static constexpr uint SERVER_VERSION_90100 = 90100;
95
96/*
97 Set of unsupported server version labels. An unsupported server version is a
98 version from which we can't upgrade or downgrade.
99*/
100static std::set<uint> unsupported_server_versions = {};
101
103 private:
108
111
112 public:
113 DD_bootstrap_ctx() = default;
114
115 static DD_bootstrap_ctx &instance();
116
117 Stage get_stage() const { return m_stage; }
118
119 void set_stage(Stage stage) { m_stage = stage; }
120
121 bool supported_dd_version() const {
124 }
125
126 void set_actual_dd_version(uint actual_dd_version) {
127 m_actual_dd_version = actual_dd_version;
128 }
129
130 void set_actual_I_S_version(uint actual_I_S_version) {
131 m_actual_I_S_version = actual_I_S_version;
132 }
133
135
137
139 assert(m_did_dd_upgrade_from == 0);
140 assert(is_dd_upgrade());
142 }
143
144 bool dd_upgrade_done() const { return m_did_dd_upgrade_from != 0; }
145
147 assert(m_did_I_S_upgrade_from == 0);
149 }
150
151 bool I_S_upgrade_done() const { return m_did_I_S_upgrade_from != 0; }
152
153 bool actual_dd_version_is(uint compare_actual_dd_version) const {
154 return (m_actual_dd_version == compare_actual_dd_version);
155 }
156
158 return (unsupported_server_versions.find(version) ==
161 }
162
165 }
166
167 bool is_server_patch_downgrade(uint compare_server_version) const {
168 return (compare_server_version / 100 == MYSQL_VERSION_ID / 100) &&
169 (compare_server_version % 100 > MYSQL_VERSION_ID % 100);
170 }
171
174 }
175
176 void set_upgraded_server_version(uint upgraded_server_version) {
177 m_upgraded_server_version = upgraded_server_version;
178 }
179
181
182 bool upgraded_server_version_is(uint compare_upgraded_server_version) const {
183 return (m_upgraded_server_version == compare_upgraded_server_version);
184 }
185
186 bool is_restart() const {
189 }
190
191 bool is_dd_upgrade() const {
193 }
194
195 bool is_server_upgrade() const {
197 }
198
199 bool is_dd_upgrade_from_before(uint compare_actual_dd_version) const {
200 return (is_dd_upgrade() && m_actual_dd_version < compare_actual_dd_version);
201 }
202
204 uint compare_upgraded_server_version) const {
205 return (is_server_upgrade() &&
206 m_upgraded_server_version < compare_upgraded_server_version);
207 }
208
210 uint compare_upgraded_server_version) const {
211 return (is_server_upgrade() &&
212 m_upgraded_server_version > compare_upgraded_server_version);
213 }
214
215 bool is_minor_downgrade() const {
216 return !opt_initialize &&
217 (m_actual_dd_version / 10000 == dd::DD_VERSION / 10000) &&
219 }
220
222
223 bool is_initialize() const {
225 }
226};
227
228} // namespace bootstrap
229} // namespace dd
230
231#endif // DD__BOOTSTRAP_CTX_INCLUDED
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: bootstrap_ctx.h:102
bool I_S_upgrade_done() const
Definition: bootstrap_ctx.h:151
bool is_minor_downgrade() const
Definition: bootstrap_ctx.h:215
bool supported_server_version(uint version) const
Definition: bootstrap_ctx.h:157
bool supported_server_version() const
Definition: bootstrap_ctx.h:163
bool is_server_upgrade_from_after(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:209
bool is_server_upgrade_from_before(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:203
bool is_initialize() const
Definition: bootstrap_ctx.h:223
void set_I_S_upgrade_done()
Definition: bootstrap_ctx.h:146
uint m_actual_dd_version
Definition: bootstrap_ctx.h:105
uint m_did_I_S_upgrade_from
Definition: bootstrap_ctx.h:109
void set_upgraded_server_version(uint upgraded_server_version)
Definition: bootstrap_ctx.h:176
uint get_actual_dd_version() const
Definition: bootstrap_ctx.h:134
void set_dd_upgrade_done()
Definition: bootstrap_ctx.h:138
void set_actual_dd_version(uint actual_dd_version)
Definition: bootstrap_ctx.h:126
bool is_server_patch_downgrade() const
Definition: bootstrap_ctx.h:172
uint get_actual_I_S_version() const
Definition: bootstrap_ctx.h:136
bool is_restart() const
Definition: bootstrap_ctx.h:186
bool is_dd_upgrade() const
Definition: bootstrap_ctx.h:191
Stage m_stage
Definition: bootstrap_ctx.h:107
bool supported_dd_version() const
Definition: bootstrap_ctx.h:121
uint m_upgraded_server_version
Definition: bootstrap_ctx.h:106
static DD_bootstrap_ctx & instance()
Definition: bootstrap_ctx.cc:30
Stage get_stage() const
Definition: bootstrap_ctx.h:117
bool is_server_patch_downgrade(uint compare_server_version) const
Definition: bootstrap_ctx.h:167
uint get_upgraded_server_version() const
Definition: bootstrap_ctx.h:180
void set_stage(Stage stage)
Definition: bootstrap_ctx.h:119
bool is_server_upgrade() const
Definition: bootstrap_ctx.h:195
bool is_dd_upgrade_from_before(uint compare_actual_dd_version) const
Definition: bootstrap_ctx.h:199
uint m_did_dd_upgrade_from
Definition: bootstrap_ctx.h:104
bool upgraded_server_version_is(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:182
bool actual_dd_version_is(uint compare_actual_dd_version) const
Definition: bootstrap_ctx.h:153
uint m_actual_I_S_version
Definition: bootstrap_ctx.h:110
bool dd_upgrade_done() const
Definition: bootstrap_ctx.h:144
void set_actual_I_S_version(uint actual_I_S_version)
Definition: bootstrap_ctx.h:130
bool is_above_minor_downgrade_threshold(THD *thd) const
Definition: bootstrap_ctx.cc:35
Data dictionary version.
Some integer typedefs for easier portability.
#define MYSQL_VERSION_ID
Definition: mysql_version.h:15
bool opt_initialize
Definition: mysqld.cc:1256
Definition: bootstrap.cc:71
static constexpr uint DD_VERSION_90200
Definition: bootstrap_ctx.h:71
static constexpr uint DD_VERSION_80300
Definition: bootstrap_ctx.h:68
static constexpr uint DD_VERSION_80015
Definition: bootstrap_ctx.h:61
Stage
Definition: bootstrap_ctx.h:42
static constexpr uint SERVER_VERSION_80011
Definition: bootstrap_ctx.h:89
static constexpr uint DD_VERSION_80014
Definition: bootstrap_ctx.h:60
static constexpr uint SERVER_VERSION_80015
Definition: bootstrap_ctx.h:92
static constexpr uint DD_VERSION_80013
Definition: bootstrap_ctx.h:59
static constexpr uint DD_VERSION_80016
Definition: bootstrap_ctx.h:62
static constexpr uint DD_VERSION_80012
Definition: bootstrap_ctx.h:58
static std::set< uint > supported_dd_versions
Definition: bootstrap_ctx.h:81
static constexpr uint DD_VERSION_80023
Definition: bootstrap_ctx.h:66
static constexpr uint DD_VERSION_80200
Definition: bootstrap_ctx.h:67
static constexpr uint DD_VERSION_80022
Definition: bootstrap_ctx.h:65
static constexpr uint DD_VERSION_90000
Definition: bootstrap_ctx.h:70
static constexpr uint SERVER_VERSION_80013
Definition: bootstrap_ctx.h:90
static constexpr uint DD_VERSION_80021
Definition: bootstrap_ctx.h:64
static constexpr uint DD_VERSION_80017
Definition: bootstrap_ctx.h:63
static constexpr uint SERVER_VERSION_50700
Definition: bootstrap_ctx.h:88
static std::set< uint > unsupported_server_versions
Definition: bootstrap_ctx.h:100
static constexpr uint SERVER_VERSION_90100
Definition: bootstrap_ctx.h:94
static constexpr uint SERVER_VERSION_80014
Definition: bootstrap_ctx.h:91
static constexpr uint SERVER_VERSION_80016
Definition: bootstrap_ctx.h:93
static constexpr uint DD_VERSION_80011
Definition: bootstrap_ctx.h:57
static constexpr uint DD_VERSION_80400
Definition: bootstrap_ctx.h:69
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
static const uint DD_VERSION
Definition: dd_version.h:235
required uint64 version
Definition: replication_group_member_actions.proto:41