MySQL 9.1.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;
70
71/*
72 Set of supported DD version labels. A supported DD version is a version
73 from which we can upgrade. In the case of downgrade, this is not relevant,
74 since the set of supported versions is defined when the server is built,
75 and newer version numbers are not added to this set. in the case of
76 downgrade, we instead have to check the MINOR_DOWNGRADE_THRESHOLD, which is
77 stored in the 'dd_properties' table by the server from which we downgrade.
78*/
79static std::set<uint> supported_dd_versions = {
83
84// Individual server version labels that we can refer to.
85static constexpr uint SERVER_VERSION_50700 = 50700;
86static constexpr uint SERVER_VERSION_80011 = 80011;
87static constexpr uint SERVER_VERSION_80013 = 80013;
88static constexpr uint SERVER_VERSION_80014 = 80014;
89static constexpr uint SERVER_VERSION_80015 = 80015;
90static constexpr uint SERVER_VERSION_80016 = 80016;
91static constexpr uint SERVER_VERSION_90100 = 90100;
92
93/*
94 Set of unsupported server version labels. An unsupported server version is a
95 version from which we can't upgrade or downgrade.
96*/
97static std::set<uint> unsupported_server_versions = {};
98
100 private:
105
108
109 public:
110 DD_bootstrap_ctx() = default;
111
112 static DD_bootstrap_ctx &instance();
113
114 Stage get_stage() const { return m_stage; }
115
116 void set_stage(Stage stage) { m_stage = stage; }
117
118 bool supported_dd_version() const {
121 }
122
123 void set_actual_dd_version(uint actual_dd_version) {
124 m_actual_dd_version = actual_dd_version;
125 }
126
127 void set_actual_I_S_version(uint actual_I_S_version) {
128 m_actual_I_S_version = actual_I_S_version;
129 }
130
132
134
136 assert(m_did_dd_upgrade_from == 0);
137 assert(is_dd_upgrade());
139 }
140
141 bool dd_upgrade_done() const { return m_did_dd_upgrade_from != 0; }
142
144 assert(m_did_I_S_upgrade_from == 0);
146 }
147
148 bool I_S_upgrade_done() const { return m_did_I_S_upgrade_from != 0; }
149
150 bool actual_dd_version_is(uint compare_actual_dd_version) const {
151 return (m_actual_dd_version == compare_actual_dd_version);
152 }
153
155 return (unsupported_server_versions.find(version) ==
158 }
159
162 }
163
164 bool is_server_patch_downgrade(uint compare_server_version) const {
165 return (compare_server_version / 100 == MYSQL_VERSION_ID / 100) &&
166 (compare_server_version % 100 > MYSQL_VERSION_ID % 100);
167 }
168
171 }
172
173 void set_upgraded_server_version(uint upgraded_server_version) {
174 m_upgraded_server_version = upgraded_server_version;
175 }
176
178
179 bool upgraded_server_version_is(uint compare_upgraded_server_version) const {
180 return (m_upgraded_server_version == compare_upgraded_server_version);
181 }
182
183 bool is_restart() const {
186 }
187
188 bool is_dd_upgrade() const {
190 }
191
192 bool is_server_upgrade() const {
194 }
195
196 bool is_dd_upgrade_from_before(uint compare_actual_dd_version) const {
197 return (is_dd_upgrade() && m_actual_dd_version < compare_actual_dd_version);
198 }
199
201 uint compare_upgraded_server_version) const {
202 return (is_server_upgrade() &&
203 m_upgraded_server_version < compare_upgraded_server_version);
204 }
205
207 uint compare_upgraded_server_version) const {
208 return (is_server_upgrade() &&
209 m_upgraded_server_version > compare_upgraded_server_version);
210 }
211
212 bool is_minor_downgrade() const {
213 return !opt_initialize &&
214 (m_actual_dd_version / 10000 == dd::DD_VERSION / 10000) &&
216 }
217
219
220 bool is_initialize() const {
222 }
223};
224
225} // namespace bootstrap
226} // namespace dd
227
228#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:99
bool I_S_upgrade_done() const
Definition: bootstrap_ctx.h:148
bool is_minor_downgrade() const
Definition: bootstrap_ctx.h:212
bool supported_server_version(uint version) const
Definition: bootstrap_ctx.h:154
bool supported_server_version() const
Definition: bootstrap_ctx.h:160
bool is_server_upgrade_from_after(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:206
bool is_server_upgrade_from_before(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:200
bool is_initialize() const
Definition: bootstrap_ctx.h:220
void set_I_S_upgrade_done()
Definition: bootstrap_ctx.h:143
uint m_actual_dd_version
Definition: bootstrap_ctx.h:102
uint m_did_I_S_upgrade_from
Definition: bootstrap_ctx.h:106
void set_upgraded_server_version(uint upgraded_server_version)
Definition: bootstrap_ctx.h:173
uint get_actual_dd_version() const
Definition: bootstrap_ctx.h:131
void set_dd_upgrade_done()
Definition: bootstrap_ctx.h:135
void set_actual_dd_version(uint actual_dd_version)
Definition: bootstrap_ctx.h:123
bool is_server_patch_downgrade() const
Definition: bootstrap_ctx.h:169
uint get_actual_I_S_version() const
Definition: bootstrap_ctx.h:133
bool is_restart() const
Definition: bootstrap_ctx.h:183
bool is_dd_upgrade() const
Definition: bootstrap_ctx.h:188
Stage m_stage
Definition: bootstrap_ctx.h:104
bool supported_dd_version() const
Definition: bootstrap_ctx.h:118
uint m_upgraded_server_version
Definition: bootstrap_ctx.h:103
static DD_bootstrap_ctx & instance()
Definition: bootstrap_ctx.cc:30
Stage get_stage() const
Definition: bootstrap_ctx.h:114
bool is_server_patch_downgrade(uint compare_server_version) const
Definition: bootstrap_ctx.h:164
uint get_upgraded_server_version() const
Definition: bootstrap_ctx.h:177
void set_stage(Stage stage)
Definition: bootstrap_ctx.h:116
bool is_server_upgrade() const
Definition: bootstrap_ctx.h:192
bool is_dd_upgrade_from_before(uint compare_actual_dd_version) const
Definition: bootstrap_ctx.h:196
uint m_did_dd_upgrade_from
Definition: bootstrap_ctx.h:101
bool upgraded_server_version_is(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:179
bool actual_dd_version_is(uint compare_actual_dd_version) const
Definition: bootstrap_ctx.h:150
uint m_actual_I_S_version
Definition: bootstrap_ctx.h:107
bool dd_upgrade_done() const
Definition: bootstrap_ctx.h:141
void set_actual_I_S_version(uint actual_I_S_version)
Definition: bootstrap_ctx.h:127
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:1251
Definition: bootstrap.cc: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:86
static constexpr uint DD_VERSION_80014
Definition: bootstrap_ctx.h:60
static constexpr uint SERVER_VERSION_80015
Definition: bootstrap_ctx.h:89
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:79
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 SERVER_VERSION_80013
Definition: bootstrap_ctx.h:87
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:85
static std::set< uint > unsupported_server_versions
Definition: bootstrap_ctx.h:97
static constexpr uint SERVER_VERSION_90100
Definition: bootstrap_ctx.h:91
static constexpr uint SERVER_VERSION_80014
Definition: bootstrap_ctx.h:88
static constexpr uint SERVER_VERSION_80016
Definition: bootstrap_ctx.h:90
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:228
required uint64 version
Definition: replication_group_member_actions.proto:41