MySQL 9.0.0
Source Code Documentation
arch0recv.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2018, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License, version 2.0,
7as published by the Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License, version 2.0, for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; if not, write to the Free Software
24Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/**************************************************/ /**
29 @file include/arch0recv.h
30 Interface for crash recovery for page archiver system.
31
32 *******************************************************/
33
34#ifndef ARCH_RECV_INCLUDE
35#define ARCH_RECV_INCLUDE
36
37#include "arch0arch.h"
38#include "arch0page.h"
39
40/** Info related to each group parsed at different stages of page archive
41recovery. */
43 public:
47
48 m_last_reset_block = static_cast<byte *>(ut::zalloc_withkey(
50 m_last_data_block = static_cast<byte *>(ut::zalloc_withkey(
52 }
53
57 }
58
59 /** Disable assignment. */
61
62 /** Disable copy construction. */
64
65 /** Group data. */
67
68 /** Number of archived files belonging to the group. */
69 uint m_num_files{0};
70
71 /** Group is active or not. */
72 bool m_active{false};
73
74 /** True if group is from durable archiving, false if left over from a crash
75 during clone operation. */
76 bool m_durable{false};
77
78 /** True if a new empty file was present in the group directory.
79 This can happen in case of a crash while writing to a new file. */
80 bool m_new_empty_file{false};
81
82 /** The file index which is part of the file name may not necessarily
83 be 0 always. It's possible that purge might have purged files in the
84 group leading to the file index of the first file in the group being
85 greater than 0. So we need this info to know the index of the first
86 file in the group. */
87 uint m_file_start_index{std::numeric_limits<uint>::max()};
88
89 /** Last reset position of the group. */
91
92 /** Last write position of the group. */
94
95 /** Reset block of the last reset file in a group. */
96 byte *m_last_reset_block{nullptr};
97
98 /** Data block of the last reset file in a group. */
99 byte *m_last_data_block{nullptr};
100
101 /** Reset file structure of the last reset file */
103
104 /** Start LSN of the group. */
106
107 /** Last stop LSN of the group if active, else end LSN. */
109};
110
111/** Mapping of group directory name to information related to the recovery
112group info. */
114 std::unordered_map<std::string, Arch_Recv_Group_Info>;
115
116/** Doublewrite buffer block along with their info. */
118 /** Type of block flushed into the doublewrite block */
120
121 /** Flush type of the block flushed into the doublewrite buffer */
123
124 /** Block number of the block flushed into the doublewrite buffer */
125 uint64_t m_block_num;
126
127 /** Doublewrite buffer block */
128 byte *m_block;
129};
130
131/** Vector of doublewrite buffer blocks and their info. */
132using Arch_Dblwr_Blocks = std::vector<Arch_Dblwr_Block>;
133
134/** Doublewrite buffer context. */
136 public:
137 /** Constructor: Initialize members */
138 Arch_Dblwr_Ctx() = default;
139
143 }
144
145 /** Initialize the doublewrite buffer.
146 @param[in] path path to the file
147 @param[in] base_file file name prefix
148 @param[in] num_files initial number of files
149 @param[in] file_size file size in bytes
150 @return error code. */
151 dberr_t init(const char *path, const char *base_file, uint num_files,
152 uint64_t file_size);
153
154 /** Read the doublewrite buffer file.
155 @return error code */
157
158 /** Validate the blocks contained in the m_buf buffer and load only the valid
159 buffers into m_blocks.
160 @param[in] num_files number of files in the group information required to
161 validate the blocks */
162 void validate_and_fill_blocks(size_t num_files);
163
164 /** Get doubewrite buffer blocks.
165 @return doublewrite buffer blocks */
167
168 /** Disable copy construction. */
170
171 /** Disable assignment. */
173
174 private:
175 /** Buffer to hold the contents of the doublwrite buffer. */
176 byte *m_buf{nullptr};
177
178 /** Total file size of the file which holds the doublewrite buffer. */
179 uint64_t m_file_size{};
180
181 /** Doublewrite buffer file context. */
183
184 /** List of doublewrite buffer blocks. */
186};
187
188/** Recovery system data structure for the archiver. */
190 public:
191 /** Constructor: Initialize members
192 @param[in,out] page_sys global dirty page archive system
193 @param[in] dir_name main archiver directory name */
194 Recovery(Arch_Page_Sys *page_sys, const char *dir_name)
195 : m_arch_dir_name(dir_name), m_page_sys(page_sys) {}
196
197 /** Destructor: Close open file and free resources */
198 ~Recovery() = default;
199
200 /** Initialise the archiver's recovery system.
201 @return error code. */
203
204 /** Scan the archive directory and fetch all info related to group
205 directories and its files.
206 @return true if the scan was successful. */
207 bool scan_for_groups();
208
209#ifdef UNIV_DEBUG
210 /** Print information related to the archiver recovery system added
211 for debugging purposes. */
212 void print();
213#endif
214
215 /** Parse for group information and fill the group.
216 @return error code. */
218
219 /** Load archiver with the related data and start tracking if required.
220 @return error code. */
222
223 /** Disable copy construction */
224 Recovery(Recovery const &) = delete;
225
226 /** Disable assignment */
227 Recovery &operator=(Recovery const &) = delete;
228
229 private:
230 /** Read all the group directories and store information related to them
231 required for parsing.
232 @param[in] file_path file path information */
233 void read_group_dirs(const std::string file_path);
234
235 /** Read all the archived files belonging to a group and store information
236 related to them required for parsing.
237 @param[in] dir_path dir path information
238 @param[in] file_path file path information */
239 void read_group_files(const std::string dir_path,
240 const std::string file_path);
241
242 private:
243 /** Archive directory. */
244 std::string m_arch_dir_name;
245
246 /** Global dirty page archive system */
248
249 /** Doublewrite buffer context. */
251
252 /** Mapping of group directory names and group information related to
253 the group. */
255};
256
257/** Recovery system data structure for the archiver. */
259 public:
260 /** Constructor.
261 @param[in] group the parent class group object */
263 ut_ad(group != nullptr);
264 m_group = group;
265 }
266
267 /** Destructor. */
269
270 /** Check and replace blocks in archived files belonging to a group
271 from the doublewrite buffer if required.
272 @param[in] dblwr_ctx Doublewrite context which has the doublewrite
273 buffer blocks
274 @return error code */
276
277 /** Delete the last file if there are no blocks flushed to it.
278 @param[in,out] info information related to group required for recovery
279 @return error code. */
281
282 /** Start parsing the archive file for archive group information.
283 @param[in,out] info information related to group required for recovery
284 @return error code */
286
287 /** Attach system client to the archiver during recovery if any group was
288 active at the time of crash. */
290
291 /** Disable copy construction */
292 Recovery(Recovery const &) = delete;
293
294 /** Disable assignment */
295 Recovery &operator=(Recovery const &) = delete;
296
297 private:
298 /** The parent class group object. */
300};
301
302/** Recovery system data structure for the archiver. */
304 public:
305 /** Constructor.
306 @param[in] file_ctx file context to be used by this recovery class */
307 Recovery(Arch_File_Ctx &file_ctx) : m_file_ctx(file_ctx) {}
308
309 /** Destructor. */
311
312#ifdef UNIV_DEBUG
313 /** Print recovery related data.
314 @param[in] file_start_index file index from where to begin */
315 void reset_print(uint file_start_index);
316#endif
317
318 /** Fetch the reset points pertaining to a file.
319 @param[in] file_index file index of the file from which reset points
320 needs to be fetched
321 @param[in] last_file true if the file for which the stop point is
322 being fetched for is the last file
323 @param[in,out] info information related to group required for recovery
324 @return error code. */
325 dberr_t parse_reset_points(uint file_index, bool last_file,
327
328 /** Fetch the stop lsn pertaining to a file.
329 @param[in] last_file true if the file for which the stop point is
330 being fetched for is the last file
331 @param[in,out] info information related to group required for recovery
332 @return error code. */
333 dberr_t parse_stop_points(bool last_file, Arch_Recv_Group_Info &info);
334
335 /** Disable copy construction */
336 Recovery(Recovery const &) = delete;
337
338 /** Disable assignment */
339 Recovery &operator=(Recovery const &) = delete;
340
341 private:
342 /** File context. */
344};
345
346#endif /* ARCH_RECV_INCLUDE */
Common interface for redo log and dirty page archiver system.
Arch_Blk_Flush_Type
Archiver block flush type.
Definition: arch0arch.h:222
Arch_Blk_Type
Archiver block type.
Definition: arch0arch.h:213
constexpr uint ARCH_PAGE_BLK_SIZE
Memory block size.
Definition: arch0arch.h:91
Innodb interface for modified page archive.
std::unordered_map< std::string, Arch_Recv_Group_Info > Arch_Dir_Group_Info_Map
Mapping of group directory name to information related to the recovery group info.
Definition: arch0recv.h:114
std::vector< Arch_Dblwr_Block > Arch_Dblwr_Blocks
Vector of doublewrite buffer blocks and their info.
Definition: arch0recv.h:132
Doublewrite buffer context.
Definition: arch0recv.h:135
uint64_t m_file_size
Total file size of the file which holds the doublewrite buffer.
Definition: arch0recv.h:179
Arch_Dblwr_Blocks blocks()
Get doubewrite buffer blocks.
Definition: arch0recv.h:166
Arch_Dblwr_Ctx()=default
Constructor: Initialize members.
Arch_Dblwr_Ctx & operator=(Arch_Dblwr_Ctx const &)=delete
Disable assignment.
dberr_t read_file()
Read the doublewrite buffer file.
Definition: arch0recv.cc:100
~Arch_Dblwr_Ctx()
Definition: arch0recv.h:140
dberr_t init(const char *path, const char *base_file, uint num_files, uint64_t file_size)
Initialize the doublewrite buffer.
Definition: arch0recv.cc:82
Arch_Dblwr_Blocks m_blocks
List of doublewrite buffer blocks.
Definition: arch0recv.h:185
Arch_File_Ctx m_file_ctx
Doublewrite buffer file context.
Definition: arch0recv.h:182
Arch_Dblwr_Ctx(Arch_Dblwr_Ctx const &)=delete
Disable copy construction.
byte * m_buf
Buffer to hold the contents of the doublwrite buffer.
Definition: arch0recv.h:176
void validate_and_fill_blocks(size_t num_files)
Validate the blocks contained in the m_buf buffer and load only the valid buffers into m_blocks.
Definition: arch0recv.cc:119
Recovery system data structure for the archiver.
Definition: arch0recv.h:303
~Recovery()
Destructor.
Definition: arch0recv.h:310
dberr_t parse_stop_points(bool last_file, Arch_Recv_Group_Info &info)
Fetch the stop lsn pertaining to a file.
Definition: arch0recv.cc:620
void reset_print(uint file_start_index)
Print recovery related data.
Definition: arch0recv.cc:530
Arch_File_Ctx & m_file_ctx
File context.
Definition: arch0recv.h:343
Recovery & operator=(Recovery const &)=delete
Disable assignment.
Recovery(Arch_File_Ctx &file_ctx)
Constructor.
Definition: arch0recv.h:307
dberr_t parse_reset_points(uint file_index, bool last_file, Arch_Recv_Group_Info &info)
Fetch the reset points pertaining to a file.
Definition: arch0recv.cc:661
Recovery(Recovery const &)=delete
Disable copy construction.
Archiver file context.
Definition: arch0arch.h:531
void close()
Close file, if open.
Definition: arch0arch.h:628
Recovery system data structure for the archiver.
Definition: arch0recv.h:258
Arch_Group * m_group
The parent class group object.
Definition: arch0recv.h:299
dberr_t replace_pages_from_dblwr(Arch_Dblwr_Ctx *dblwr_ctx)
Check and replace blocks in archived files belonging to a group from the doublewrite buffer if requir...
Definition: arch0recv.cc:278
dberr_t parse(Arch_Recv_Group_Info &info)
Start parsing the archive file for archive group information.
Definition: arch0recv.cc:571
Recovery(Recovery const &)=delete
Disable copy construction.
~Recovery()
Destructor.
Definition: arch0recv.h:268
void attach()
Attach system client to the archiver during recovery if any group was active at the time of crash.
Definition: arch0recv.h:289
Recovery(Arch_Group *group)
Constructor.
Definition: arch0recv.h:262
dberr_t cleanup_if_required(Arch_Recv_Group_Info &info)
Delete the last file if there are no blocks flushed to it.
Definition: arch0recv.cc:321
Recovery & operator=(Recovery const &)=delete
Disable assignment.
Contiguous archived data for redo log or page tracking.
Definition: arch0arch.h:843
uint m_dur_ref_count
Number of clients referencing for durable archiving.
Definition: arch0arch.h:1261
Recovery system data structure for the archiver.
Definition: arch0recv.h:189
dberr_t load_archiver()
Load archiver with the related data and start tracking if required.
Definition: arch0recv.cc:436
dberr_t init_dblwr()
Initialise the archiver's recovery system.
Definition: arch0recv.cc:70
std::string m_arch_dir_name
Archive directory.
Definition: arch0recv.h:244
Arch_Dir_Group_Info_Map m_dir_group_info_map
Mapping of group directory names and group information related to the group.
Definition: arch0recv.h:254
bool scan_for_groups()
Scan the archive directory and fetch all info related to group directories and its files.
Definition: arch0recv.cc:248
Arch_Dblwr_Ctx m_dblwr_ctx
Doublewrite buffer context.
Definition: arch0recv.h:250
Recovery(Recovery const &)=delete
Disable copy construction.
Recovery & operator=(Recovery const &)=delete
Disable assignment.
dberr_t recover()
Parse for group information and fill the group.
Definition: arch0recv.cc:395
void print()
Print information related to the archiver recovery system added for debugging purposes.
Definition: arch0recv.cc:180
Recovery(Arch_Page_Sys *page_sys, const char *dir_name)
Constructor: Initialize members.
Definition: arch0recv.h:194
void read_group_files(const std::string dir_path, const std::string file_path)
Read all the archived files belonging to a group and store information related to them required for p...
Definition: arch0recv.cc:210
Arch_Page_Sys * m_page_sys
Global dirty page archive system.
Definition: arch0recv.h:247
~Recovery()=default
Destructor: Close open file and free resources.
void read_group_dirs(const std::string file_path)
Read all the group directories and store information related to them required for parsing.
Definition: arch0recv.cc:189
Dirty page archive system.
Definition: arch0arch.h:1553
Info related to each group parsed at different stages of page archive recovery.
Definition: arch0recv.h:42
uint m_num_files
Number of archived files belonging to the group.
Definition: arch0recv.h:69
bool m_durable
True if group is from durable archiving, false if left over from a crash during clone operation.
Definition: arch0recv.h:76
lsn_t m_start_lsn
Start LSN of the group.
Definition: arch0recv.h:105
Arch_Recv_Group_Info & operator=(const Arch_Recv_Group_Info &)=delete
Disable assignment.
byte * m_last_data_block
Data block of the last reset file in a group.
Definition: arch0recv.h:99
uint m_file_start_index
The file index which is part of the file name may not necessarily be 0 always.
Definition: arch0recv.h:87
bool m_active
Group is active or not.
Definition: arch0recv.h:72
~Arch_Recv_Group_Info()
Definition: arch0recv.h:54
byte * m_last_reset_block
Reset block of the last reset file in a group.
Definition: arch0recv.h:96
Arch_Group * m_group
Group data.
Definition: arch0recv.h:66
Arch_Recv_Group_Info()
Definition: arch0recv.h:44
Arch_Recv_Group_Info(const Arch_Recv_Group_Info &)=delete
Disable copy construction.
bool m_new_empty_file
True if a new empty file was present in the group directory.
Definition: arch0recv.h:80
Arch_Page_Pos m_reset_pos
Last reset position of the group.
Definition: arch0recv.h:90
lsn_t m_last_stop_lsn
Last stop LSN of the group if active, else end LSN.
Definition: arch0recv.h:108
Arch_Reset_File m_last_reset_file
Reset file structure of the last reset file.
Definition: arch0recv.h:102
Arch_Page_Pos m_write_pos
Last write position of the group.
Definition: arch0recv.h:93
dberr_t
Definition: db0err.h:39
constexpr lsn_t LSN_MAX
Maximum possible lsn value is slightly higher than the maximum sn value, because lsn sequence enumera...
Definition: log0constants.h:159
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:63
static size_t file_size
Definition: mysql_config_editor.cc:72
static char * path
Definition: mysqldump.cc:149
void * zalloc_withkey(PSI_memory_key_t key, std::size_t size) noexcept
Dynamically allocates zero-initialized storage of given size.
Definition: ut0new.h:633
void free(void *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::malloc*(),...
Definition: ut0new.h:718
PSI_memory_key_t make_psi_memory_key(PSI_memory_key key)
Convenience helper function to create type-safe representation of PSI_memory_key.
Definition: ut0new.h:190
Doublewrite buffer block along with their info.
Definition: arch0recv.h:117
Arch_Blk_Type m_block_type
Type of block flushed into the doublewrite block.
Definition: arch0recv.h:119
uint64_t m_block_num
Block number of the block flushed into the doublewrite buffer.
Definition: arch0recv.h:125
Arch_Blk_Flush_Type m_flush_type
Flush type of the block flushed into the doublewrite buffer.
Definition: arch0recv.h:122
byte * m_block
Doublewrite buffer block.
Definition: arch0recv.h:128
Position in page ID archiving system.
Definition: arch0arch.h:299
void init()
Initialize a position.
Definition: arch0page.cc:1443
Definition: arch0arch.h:331
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
PSI_memory_key mem_key_archive
Definition: ut0new.cc:48