MySQL 8.0.40
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;
67
68/*
69 Set of supported DD version labels. A supported DD version is a version
70 from which we can upgrade. In the case of downgrade, this is not relevant,
71 since the set of supported versions is defined when the server is built,
72 and newer version numbers are not added to this set. in the case of
73 downgrade, we instead have to check the MINOR_DOWNGRADE_THRESHOLD, which is
74 stored in the 'dd_properties' table by the server from which we downgrade.
75*/
76static std::set<uint> supported_dd_versions = {
80
81// Individual server version labels that we can refer to.
82static constexpr uint SERVER_VERSION_50700 = 50700;
83static constexpr uint SERVER_VERSION_80011 = 80011;
84static constexpr uint SERVER_VERSION_80013 = 80013;
85static constexpr uint SERVER_VERSION_80014 = 80014;
86static constexpr uint SERVER_VERSION_80015 = 80015;
87static constexpr uint SERVER_VERSION_80016 = 80016;
88
89/*
90 Set of unsupported server version labels. An unsupported server version is a
91 version from which we can't upgrade or downgrade.
92*/
93static std::set<uint> unsupported_server_versions = {};
94
96 private:
101
104
105 public:
106 DD_bootstrap_ctx() = default;
107
108 static DD_bootstrap_ctx &instance();
109
110 Stage get_stage() const { return m_stage; }
111
112 void set_stage(Stage stage) { m_stage = stage; }
113
114 bool supported_dd_version() const {
117 }
118
119 void set_actual_dd_version(uint actual_dd_version) {
120 m_actual_dd_version = actual_dd_version;
121 }
122
123 void set_actual_I_S_version(uint actual_I_S_version) {
124 m_actual_I_S_version = actual_I_S_version;
125 }
126
128
130
132 assert(m_did_dd_upgrade_from == 0);
133 assert(is_dd_upgrade());
135 }
136
137 bool dd_upgrade_done() const { return m_did_dd_upgrade_from != 0; }
138
140 assert(m_did_I_S_upgrade_from == 0);
142 }
143
144 bool I_S_upgrade_done() const { return m_did_I_S_upgrade_from != 0; }
145
146 bool actual_dd_version_is(uint compare_actual_dd_version) const {
147 return (m_actual_dd_version == compare_actual_dd_version);
148 }
149
151 return (unsupported_server_versions.find(version) ==
154 }
155
158 }
159
161 return (compare_server_version / 100 == MYSQL_VERSION_ID / 100) &&
163 }
164
167 }
168
169 void set_upgraded_server_version(uint upgraded_server_version) {
170 m_upgraded_server_version = upgraded_server_version;
171 }
172
174
175 bool upgraded_server_version_is(uint compare_upgraded_server_version) const {
176 return (m_upgraded_server_version == compare_upgraded_server_version);
177 }
178
179 bool is_restart() const {
182 }
183
184 bool is_dd_upgrade() const {
186 }
187
188 bool is_server_upgrade() const {
190 }
191
192 bool is_dd_upgrade_from_before(uint compare_actual_dd_version) const {
193 return (is_dd_upgrade() && m_actual_dd_version < compare_actual_dd_version);
194 }
195
197 uint compare_upgraded_server_version) const {
198 return (is_server_upgrade() &&
199 m_upgraded_server_version < compare_upgraded_server_version);
200 }
201
203 uint compare_upgraded_server_version) const {
204 return (is_server_upgrade() &&
205 m_upgraded_server_version > compare_upgraded_server_version);
206 }
207
208 bool is_minor_downgrade() const {
209 return !opt_initialize &&
210 (m_actual_dd_version / 10000 == dd::DD_VERSION / 10000) &&
212 }
213
215
216 bool is_initialize() const {
218 }
219};
220
221} // namespace bootstrap
222} // namespace dd
223
224#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:34
Definition: bootstrap_ctx.h:95
bool I_S_upgrade_done() const
Definition: bootstrap_ctx.h:144
bool is_minor_downgrade() const
Definition: bootstrap_ctx.h:208
bool supported_server_version(uint version) const
Definition: bootstrap_ctx.h:150
bool supported_server_version() const
Definition: bootstrap_ctx.h:156
bool is_server_upgrade_from_after(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:202
bool is_server_upgrade_from_before(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:196
bool is_initialize() const
Definition: bootstrap_ctx.h:216
void set_I_S_upgrade_done()
Definition: bootstrap_ctx.h:139
uint m_actual_dd_version
Definition: bootstrap_ctx.h:98
uint m_did_I_S_upgrade_from
Definition: bootstrap_ctx.h:102
void set_upgraded_server_version(uint upgraded_server_version)
Definition: bootstrap_ctx.h:169
uint get_actual_dd_version() const
Definition: bootstrap_ctx.h:127
void set_dd_upgrade_done()
Definition: bootstrap_ctx.h:131
void set_actual_dd_version(uint actual_dd_version)
Definition: bootstrap_ctx.h:119
bool is_server_patch_downgrade() const
Definition: bootstrap_ctx.h:165
uint get_actual_I_S_version() const
Definition: bootstrap_ctx.h:129
bool is_restart() const
Definition: bootstrap_ctx.h:179
bool is_dd_upgrade() const
Definition: bootstrap_ctx.h:184
Stage m_stage
Definition: bootstrap_ctx.h:100
bool supported_dd_version() const
Definition: bootstrap_ctx.h:114
uint m_upgraded_server_version
Definition: bootstrap_ctx.h:99
static DD_bootstrap_ctx & instance()
Definition: bootstrap_ctx.cc:30
Stage get_stage() const
Definition: bootstrap_ctx.h:110
bool is_server_patch_downgrade(uint compare_server_version) const
Definition: bootstrap_ctx.h:160
uint get_upgraded_server_version() const
Definition: bootstrap_ctx.h:173
void set_stage(Stage stage)
Definition: bootstrap_ctx.h:112
bool is_server_upgrade() const
Definition: bootstrap_ctx.h:188
bool is_dd_upgrade_from_before(uint compare_actual_dd_version) const
Definition: bootstrap_ctx.h:192
uint m_did_dd_upgrade_from
Definition: bootstrap_ctx.h:97
bool upgraded_server_version_is(uint compare_upgraded_server_version) const
Definition: bootstrap_ctx.h:175
bool actual_dd_version_is(uint compare_actual_dd_version) const
Definition: bootstrap_ctx.h:146
uint m_actual_I_S_version
Definition: bootstrap_ctx.h:103
bool dd_upgrade_done() const
Definition: bootstrap_ctx.h:137
void set_actual_I_S_version(uint actual_I_S_version)
Definition: bootstrap_ctx.h:123
bool is_above_minor_downgrade_threshold(THD *thd) const
Definition: bootstrap_ctx.cc:35
bool compare_server_version(std::string ver1, std::string ver2)
Compares versions and determine if clone is allowed.
Definition: clone_protocol_service.cc:351
Data dictionary version.
Some integer typedefs for easier portability.
#define MYSQL_VERSION_ID
Definition: mysql_version.h:15
bool opt_initialize
Definition: mysqld.cc:1227
Definition: bootstrap.cc:70
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:83
static constexpr uint DD_VERSION_80014
Definition: bootstrap_ctx.h:60
static constexpr uint SERVER_VERSION_80015
Definition: bootstrap_ctx.h:86
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:76
static constexpr uint DD_VERSION_80023
Definition: bootstrap_ctx.h:66
static constexpr uint DD_VERSION_80022
Definition: bootstrap_ctx.h:65
static constexpr uint SERVER_VERSION_80013
Definition: bootstrap_ctx.h:84
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:82
static std::set< uint > unsupported_server_versions
Definition: bootstrap_ctx.h:93
static constexpr uint SERVER_VERSION_80014
Definition: bootstrap_ctx.h:85
static constexpr uint SERVER_VERSION_80016
Definition: bootstrap_ctx.h:87
static constexpr uint DD_VERSION_80011
Definition: bootstrap_ctx.h:57
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
static const uint DD_VERSION
Definition: dd_version.h:210
required uint64 version
Definition: replication_group_member_actions.proto:41
unsigned int uint
Definition: uca9-dump.cc:75