Debian Codegraph @

storage/innobase/include/clone0api.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 2017, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file include/clone0api.h
29 Innodb Clone Interface
30
31 *******************************************************/
32
33 #ifndef CLONE_API_INCLUDE
34 #define CLONE_API_INCLUDE
35
36 #include "univ.i"
37 #ifndef UNIV_HOTBACKUP
38 #include "sql/handler.h"
39
40 /** Get capability flags for clone operation
41 @param[out] flags capability flag */
42 void innodb_clone_get_capability(Ha_clone_flagset &flags);
43
44 /** Begin copy from source database
45 @param[in] hton handlerton for SE
46 @param[in] thd server thread handle
47 @param[in,out] loc locator
48 @param[in,out] loc_len locator length
49 @param[out] task_id task identifier
50 @param[in] type clone type
51 @param[in] mode mode for starting clone
52 @return error code */
53 int innodb_clone_begin(handlerton *hton, THD *thd, const byte *&loc,
54 uint &loc_len, uint &task_id, Ha_clone_type type,
55 Ha_clone_mode mode);
56
57 /** Copy data from source database in chunks via callback
58 @param[in] hton handlerton for SE
59 @param[in] thd server thread handle
60 @param[in] loc locator
61 @param[in] loc_len locator length in bytes
62 @param[in] task_id task identifier
63 @param[in] cbk callback interface for sending data
64 @return error code */
65 int innodb_clone_copy(handlerton *hton, THD *thd, const byte *loc, uint loc_len,
66 uint task_id, Ha_clone_cbk *cbk);
67
68 /** Acknowledge data to source database
69 @param[in] hton handlerton for SE
70 @param[in] thd server thread handle
71 @param[in] loc locator
72 @param[in] loc_len locator length in bytes
73 @param[in] task_id task identifier
74 @param[in] in_err inform any error occurred
75 @param[in] cbk callback interface for receiving data
76 @return error code */
77 int innodb_clone_ack(handlerton *hton, THD *thd, const byte *loc, uint loc_len,
78 uint task_id, int in_err, Ha_clone_cbk *cbk);
79
80 /** End copy from source database
81 @param[in] hton handlerton for SE
82 @param[in] thd server thread handle
83 @param[in] loc locator
84 @param[in] loc_len locator length in bytes
85 @param[in] task_id task identifier
86 @param[in] in_err error code when ending after error
87 @return error code */
88 int innodb_clone_end(handlerton *hton, THD *thd, const byte *loc, uint loc_len,
89 uint task_id, int in_err);
90
91 /** Begin apply to destination database
92 @param[in] hton handlerton for SE
93 @param[in] thd server thread handle
94 @param[in,out] loc locator
95 @param[in,out] loc_len locator length
96 @param[out] task_id task identifier
97 @param[in] mode mode for starting clone
98 @param[in] data_dir target data directory
99 @return error code */
100 int innodb_clone_apply_begin(handlerton *hton, THD *thd, const byte *&loc,
101 uint &loc_len, uint &task_id, Ha_clone_mode mode,
102 const char *data_dir);
103
104 /** Apply data to destination database in chunks via callback
105 @param[in] hton handlerton for SE
106 @param[in] thd server thread handle
107 @param[in] loc locator
108 @param[in] loc_len locator length in bytes
109 @param[in] task_id task identifier
110 @param[in] in_err inform any error occurred
111 @param[in] cbk callback interface for receiving data
112 @return error code */
113 int innodb_clone_apply(handlerton *hton, THD *thd, const byte *loc,
114 uint loc_len, uint task_id, int in_err,
115 Ha_clone_cbk *cbk);
116
117 /** End apply to destination database
118 @param[in] hton handlerton for SE
119 @param[in] thd server thread handle
120 @param[in] loc locator
121 @param[in] loc_len locator length in bytes
122 @param[in] task_id task identifier
123 @param[in] in_err error code when ending after error
124 @return error code */
125 int innodb_clone_apply_end(handlerton *hton, THD *thd, const byte *loc,
126 uint loc_len, uint task_id, int in_err);
127
128 /** Check and delete any old list files. */
129 void clone_init_list_files();
130
131 /** Add file name to clone list file for future replacement or rollback.
132 @param[in] list_file_name list file name where to add the file
133 @param[in] file_name file name to add to the list
134 @return error code */
135 int clone_add_to_list_file(const char *list_file_name, const char *file_name);
136
137 /** Remove one of the clone list files.
138 @param[in] file_name list file name to delete */
139 void clone_remove_list_file(const char *file_name);
140
141 /** Revert back clone changes in case of an error. */
142 void clone_files_error();
143
144 #ifdef UNIV_DEBUG
145 /** Debug function to check and crash during recovery.
146 @param[in] is_cloned_db if cloned database recovery */
147 bool clone_check_recovery_crashpoint(bool is_cloned_db);
148 #endif
149
150 /** Change cloned file states during recovery.
151 @param[in] finished if recovery is finishing */
152 void clone_files_recovery(bool finished);
153
154 /** Update cloned GTIDs to recovery status file.
155 @param[in] gtids cloned GTIDs */
156 void clone_update_gtid_status(std::string &gtids);
157
158 /** Initialize Clone system
159 @return inndodb error code */
160 dberr_t clone_init();
161
162 /** Uninitialize Clone system */
163 void clone_free();
164
165 /** Check if active clone is running.
166 @return true, if any active clone is found. */
167 bool clone_check_active();
168
169 /** @return true, if clone provisioning in progress. */
170 bool clone_check_provisioning();
171 #endif /* !UNIV_HOTBACKUP */
172
173 /** Fix cloned non-Innodb tables during recovery.
174 @param[in,out] thd current THD
175 @return true if error */
176 bool fix_cloned_tables(THD *thd);
177
178 /** Clone Notification handler. */
179 class Clone_notify {
180 public:
181 /** Notification type. Currently used by various DDL commands. */
182 enum class Type {
183 /* Space is being created. */
184 SPACE_CREATE,
185 /* Space is being dropped. */
186 SPACE_DROP,
187 /* Space is being renamed. */
188 SPACE_RENAME,
189 /* Space is being discarded or imported. */
190 SPACE_IMPORT,
191 /* Space encryption property is altered. */
192 SPACE_ALTER_ENCRYPT,
193 /* Space encryption property of general tablespace is altered. */
194 SPACE_ALTER_ENCRYPT_GENERAL,
195 /* Space encryption flags of general tablespace are altered. */
196 SPACE_ALTER_ENCRYPT_GENERAL_FLAGS,
197 /* In place Alter general notification. */
198 SPACE_ALTER_INPLACE,
199 /* Inplace Alter bulk operation. */
200 SPACE_ALTER_INPLACE_BULK,
201 /* Special consideration is needed for UNDO as these DDLs
202 don't use DDL log and needs special consideration during recovery. */
203 SPACE_UNDO_DDL,
204 /* Redo logging is being disabled. */
205 SYSTEM_REDO_DISABLE
206 };
207
208 #ifdef UNIV_HOTBACKUP
209 Clone_notify(Type, space_id_t, bool) : m_error() {}
210 ~Clone_notify() {}
211 #else
212 /** Constructor to initiate notification.
213 @param[in] type notification type
214 @param[in] space tablespace ID for which notification is sent
215 @param[in] no_wait set error and return immediately if needs to wait */
216 Clone_notify(Type type, space_id_t space, bool no_wait);
217
218 /** Destructor to automatically end notification. */
219 ~Clone_notify();
220 #endif /* UNIV_HOTBACKUP */
221
222 /** Get notification message for printing.
223 @param[in] begin true if notification begin otherwise end
224 @param[out] mesg notification message */
225 void get_mesg(bool begin, std::string &mesg);
226
227 /** @return true iff notification failed. */
228 bool failed() const { return m_error != 0; }
229
230 /** @return saved error code. */
231 int get_error() const { return m_error; }
232
233 /** Disable copy construction */
234 Clone_notify(const Clone_notify &) = delete;
235
236 /** Disable assignment */
237 Clone_notify &operator=(Clone_notify const &) = delete;
238
239 private:
240 /** Notification wait type set. */
241 enum class Wait_at {
242 /* Clone doesn't need to wait. */
243 NONE,
244 /* Clone needs to wait before entering. */
245 ENTER,
246 /* Clone needs to wait before state change. */
247 STATE_CHANGE,
248 /* Clone needs to abort. */
249 ABORT
250 };
251
252 private:
253 /** Tablespace ID for which notification is sent. */
254 space_id_t m_space_id;
255
256 /** Notification type. */
257 Type m_type;
258
259 /** Wait type set. */
260 Wait_at m_wait;
261
262 /** Blocked clone state if clone is blocked. */
263 uint32_t m_blocked_state;
264
265 /** Saved error. */
266 int m_error;
267 };
268
269 #endif /* CLONE_API_INCLUDE */