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