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