Debian Codegraph @

storage/innobase/arch/arch0recv.cc

raw
1 /*****************************************************************************
2
3
4 Copyright (c) 2018, 2026, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
27 *****************************************************************************/
28
29 /**************************************************/ /**
30 @file include/arch0recv.h
31 Interface for crash recovery for page archiver system.
32
33 *******************************************************/
34
35 #include "arch0recv.h"
36
37 dberr_t Arch_Page_Sys::recover() {
38 DBUG_PRINT("page_archiver", ("Crash Recovery"));
39
40 Recovery arch_recv(this, ARCH_DIR);
41
42 auto err = arch_recv.init_dblwr();
43
44 if (err == DB_FILE_READ_BEYOND_SIZE) {
45 ib::error(ER_IB_ERR_PAGE_ARCH_DBLWR_INIT_FAILED);
46 }
47
48 /* Scan for group directories and files */
49 if (!arch_recv.scan_for_groups()) {
50 DBUG_PRINT("page_archiver", ("No group information available"));
51 return DB_SUCCESS;
52 }
53
54 err = arch_recv.recover();
55
56 if (err != DB_SUCCESS) {
57 ib::error(ER_IB_ERR_PAGE_ARCH_RECOVERY_FAILED);
58 return err;
59 }
60
61 err = arch_recv.load_archiver();
62
63 if (err != DB_SUCCESS) {
64 ib::error(ER_IB_ERR_PAGE_ARCH_RECOVERY_FAILED);
65 }
66
67 return err;
68 }
69
70 dberr_t Arch_Page_Sys::Recovery::init_dblwr() {
71 auto err = m_dblwr_ctx.init(
72 ARCH_DBLWR_DIR, ARCH_DBLWR_FILE, ARCH_DBLWR_NUM_FILES,
73 static_cast<uint64_t>(ARCH_PAGE_BLK_SIZE) * ARCH_DBLWR_FILE_CAPACITY);
74
75 if (err == DB_SUCCESS) {
76 err = m_dblwr_ctx.read_file();
77 }
78
79 return err;
80 }
81
82 dberr_t Arch_Dblwr_Ctx::init(const char *dblwr_path,
83 const char *dblwr_base_file, uint dblwr_num_files,
84 uint64_t dblwr_file_size) {
85 m_file_size = dblwr_file_size;
86
87 m_buf = static_cast<byte *>(
88 ut::zalloc_withkey(UT_NEW_THIS_FILE_PSI_KEY, m_file_size));
89
90 if (m_buf == nullptr) {
91 return DB_OUT_OF_MEMORY;
92 }
93
94 auto err =
95 m_file_ctx.init(ARCH_DIR, dblwr_path, dblwr_base_file, dblwr_num_files);
96
97 return err;
98 }
99
100 dberr_t Arch_Dblwr_Ctx::read_file() {
101 auto err = m_file_ctx.open(true, LSN_MAX, 0, 0, m_file_size);
102
103 if (err != DB_SUCCESS) {
104 return err;
105 }
106
107 if (m_file_ctx.get_phy_size() < m_file_size) {
108 return DB_FILE_READ_BEYOND_SIZE;
109 }
110
111 ut_ad(m_buf != nullptr);
112
113 /* Read the entire file. */
114 err = m_file_ctx.read(m_buf, 0, static_cast<uint>(m_file_size));
115
116 return err;
117 }
118
119 void Arch_Dblwr_Ctx::validate_and_fill_blocks(size_t num_files) {
120 auto ARCH_UNKNOWN_BLOCK = std::numeric_limits<uint64_t>::max();
121 uint64_t full_flush_blk_num = ARCH_UNKNOWN_BLOCK;
122
123 for (uint dblwr_block_num = 0;
124 dblwr_block_num < m_file_size / ARCH_PAGE_BLK_SIZE; ++dblwr_block_num) {
125 auto dblwr_block_offset = m_buf + (dblwr_block_num * ARCH_PAGE_BLK_SIZE);
126 auto block_num = Arch_Block::get_block_number(dblwr_block_offset);
127 uint file_index = Arch_Block::get_file_index(
128 block_num, Arch_Block::get_type(dblwr_block_offset));
129
130 ut_ad(file_index < num_files);
131
132 /* If the block does not belong to the last file then ignore. */
133 if (file_index != num_files - 1) {
134 continue;
135 }
136
137 if (!Arch_Block::validate(dblwr_block_offset)) {
138 continue;
139 }
140
141 Arch_Dblwr_Block dblwr_block;
142
143 switch (dblwr_block_num) {
144 case ARCH_PAGE_DBLWR_RESET_PAGE:
145 dblwr_block.m_block_type = ARCH_RESET_BLOCK;
146 dblwr_block.m_flush_type = ARCH_FLUSH_NORMAL;
147 break;
148
149 case ARCH_PAGE_DBLWR_FULL_FLUSH_PAGE:
150 full_flush_blk_num = block_num;
151
152 dblwr_block.m_block_type = ARCH_DATA_BLOCK;
153 dblwr_block.m_flush_type = ARCH_FLUSH_NORMAL;
154 break;
155
156 case ARCH_PAGE_DBLWR_PARTIAL_FLUSH_PAGE:
157 /* It's possible that the partial flush block might have been fully
158 flushed, in which case we need to skip this block. */
159 if (full_flush_blk_num != ARCH_UNKNOWN_BLOCK &&
160 full_flush_blk_num >= block_num) {
161 continue;
162 }
163
164 dblwr_block.m_block_type = ARCH_DATA_BLOCK;
165 dblwr_block.m_flush_type = ARCH_FLUSH_PARTIAL;
166 break;
167
168 default:
169 ut_d(ut_error);
170 }
171
172 dblwr_block.m_block = dblwr_block_offset;
173 dblwr_block.m_block_num = block_num;
174
175 m_blocks.push_back(dblwr_block);
176 }
177 }
178
179 #ifdef UNIV_DEBUG
180 void Arch_Page_Sys::Recovery::print() {
181 for (auto group = m_dir_group_info_map.begin();
182 group != m_dir_group_info_map.end(); ++group) {
183 DBUG_PRINT("page_archiver", ("Group : %s\t%u", group->first.c_str(),
184 group->second.m_active));
185 }
186 }
187 #endif
188
189 void Arch_Page_Sys::Recovery::read_group_dirs(const std::string file_path) {
190 if (file_path.find(ARCH_PAGE_DIR) == std::string::npos) {
191 return;
192 }
193
194 try {
195 size_t pos = file_path.find(ARCH_PAGE_DIR);
196
197 lsn_t start_lsn = static_cast<lsn_t>(
198 std::stoull(file_path.substr(pos + strlen(ARCH_PAGE_DIR))));
199
200 auto &group_info = m_dir_group_info_map[file_path];
201
202 group_info.m_start_lsn = start_lsn;
203
204 } catch (const std::exception &) {
205 ib::error(ER_IB_ERR_PAGE_ARCH_INVALID_FORMAT) << ARCH_PAGE_FILE;
206 return;
207 }
208 }
209
210 void Arch_Page_Sys::Recovery::read_group_files(const std::string dir_path,
211 const std::string file_path) {
212 if (file_path.find(ARCH_PAGE_FILE) == std::string::npos &&
213 file_path.find(ARCH_PAGE_GROUP_ACTIVE_FILE_NAME) == std::string::npos &&
214 file_path.find(ARCH_PAGE_GROUP_DURABLE_FILE_NAME) == std::string::npos) {
215 return;
216 }
217
218 auto &info = m_dir_group_info_map[dir_path];
219
220 if (file_path.find(ARCH_PAGE_GROUP_ACTIVE_FILE_NAME) != std::string::npos) {
221 info.m_active = true;
222 return;
223 }
224
225 if (file_path.find(ARCH_PAGE_GROUP_DURABLE_FILE_NAME) != std::string::npos) {
226 info.m_durable = true;
227 return;
228 }
229
230 info.m_num_files += 1;
231
232 /* Fetch start index. */
233 try {
234 size_t found = file_path.find(ARCH_PAGE_FILE);
235
236 size_t file_index = static_cast<uint>(
237 std::stoi(file_path.substr(found + strlen(ARCH_PAGE_FILE))));
238
239 if (info.m_file_start_index > file_index) {
240 info.m_file_start_index = file_index;
241 }
242 } catch (const std::exception &) {
243 ib::error(ER_IB_ERR_PAGE_ARCH_INVALID_FORMAT) << ARCH_PAGE_FILE;
244 return;
245 }
246 }
247
248 bool Arch_Page_Sys::Recovery::scan_for_groups() {
249 os_file_type_t type;
250 bool exists;
251
252 os_file_status(m_arch_dir_name.c_str(), &exists, &type);
253
254 if (!exists || type != OS_FILE_TYPE_DIR) {
255 return false;
256 }
257
258 Dir_Walker::walk(m_arch_dir_name, false, [&](const std::string file_path) {
259 read_group_dirs(file_path);
260 });
261
262 if (m_dir_group_info_map.size() == 0) {
263 return false;
264 }
265
266 for (auto it = m_dir_group_info_map.begin(); it != m_dir_group_info_map.end();
267 ++it) {
268 Dir_Walker::walk(it->first, true, [&](const std::string file_path) {
269 read_group_files(it->first, file_path);
270 });
271 }
272
273 ut_d(print());
274
275 return true;
276 }
277
278 dberr_t Arch_Group::Recovery::replace_pages_from_dblwr(
279 Arch_Dblwr_Ctx *dblwr_ctx) {
280 dberr_t err{DB_SUCCESS};
281
282 uint num_files = m_group->get_file_count();
283
284 ut_ad(num_files);
285
286 dblwr_ctx->validate_and_fill_blocks(num_files);
287
288 auto &file_ctx = m_group->m_file_ctx;
289
290 err = file_ctx.open(false, m_group->m_begin_lsn, num_files - 1, 0,
291 m_group->get_file_size());
292
293 if (err != DB_SUCCESS) {
294 return err;
295 }
296
297 Arch_scope_guard file_ctx_guard([&file_ctx] { file_ctx.close(); });
298
299 auto dblwr_blocks = dblwr_ctx->blocks();
300
301 for (uint index = 0; index < dblwr_blocks.size(); ++index) {
302 auto dblwr_block = dblwr_blocks[index];
303 uint64_t offset = Arch_Block::get_file_offset(
304 dblwr_block.m_block_num, Arch_Block::get_type(dblwr_block.m_block));
305
306 if (file_ctx.get_phy_size() < offset) {
307 break;
308 }
309
310 err = file_ctx.write(nullptr, dblwr_block.m_block,
311 static_cast<uint>(offset), ARCH_PAGE_BLK_SIZE);
312
313 if (err != DB_SUCCESS) {
314 break;
315 }
316 }
317
318 return err;
319 }
320
321 dberr_t Arch_Group::Recovery::cleanup_if_required(Arch_Recv_Group_Info &info) {
322 ut_ad(!info.m_durable || info.m_num_files > 0);
323
324 auto &file_ctx = m_group->m_file_ctx;
325 auto start_index = info.m_file_start_index;
326 uint index = start_index + info.m_num_files - 1;
327
328 ut_ad(file_ctx.is_closed());
329
330 /* Open the last file in the group. */
331 auto err = file_ctx.open(true, m_group->m_begin_lsn, index, 0,
332 m_group->get_file_size());
333
334 if (err != DB_SUCCESS) {
335 return err;
336 }
337
338 Arch_scope_guard file_ctx_guard([&file_ctx] { file_ctx.close(); });
339
340 /* We check whether the archive file has anything else apart from the header
341 * that was written to it during creation phase and treat it as an empty file
342 * if it only has the header. */
343
344 if (file_ctx.get_phy_size() > m_group->m_header_len && info.m_durable) {
345 return DB_SUCCESS;
346 }
347
348 info.m_new_empty_file = true;
349
350 /* No blocks have been flushed into the file so delete the file. */
351
352 char file_path[MAX_ARCH_PAGE_FILE_NAME_LEN];
353 char dir_path[MAX_ARCH_DIR_NAME_LEN];
354
355 file_ctx.build_name(index, m_group->m_begin_lsn, file_path,
356 MAX_ARCH_PAGE_FILE_NAME_LEN);
357
358 auto found = std::string(file_path).find(ARCH_PAGE_FILE);
359 ut_ad(found != std::string::npos);
360 auto file_name = std::string(file_path).substr(found);
361
362 file_ctx.build_dir_name(m_group->m_begin_lsn, dir_path,
363 MAX_ARCH_DIR_NAME_LEN);
364
365 file_ctx_guard.cleanup();
366
367 arch_remove_file(dir_path, file_name.c_str());
368
369 --info.m_num_files;
370
371 /* If there are no archive files in the group or if it's not a durable group
372 we might as well purge it. */
373 if (info.m_num_files == 0 || !info.m_durable) {
374 m_group->m_is_active = false;
375
376 found = std::string(dir_path).find(ARCH_PAGE_DIR);
377 ut_ad(found != std::string::npos);
378
379 auto path = std::string(dir_path).substr(0, found - 1);
380 auto dir_name = std::string(dir_path).substr(found);
381
382 info.m_num_files = 0;
383 arch_remove_dir(path.c_str(), dir_name.c_str());
384
385 return err;
386 }
387
388 /* Need to reinitialize the file context as num_files has changed. */
389 err =
390 file_ctx.init(ARCH_DIR, ARCH_PAGE_DIR, ARCH_PAGE_FILE, info.m_num_files);
391
392 return err;
393 }
394
395 dberr_t Arch_Page_Sys::Recovery::recover() {
396 dberr_t err = DB_SUCCESS;
397 uint num_active [[maybe_unused]] = 0;
398
399 for (auto info = m_dir_group_info_map.begin();
400 info != m_dir_group_info_map.end(); ++info) {
401 auto &group_info = info->second;
402
403 Arch_Group *group = ut::new_withkey<Arch_Group>(
404 ut::make_psi_memory_key(mem_key_archive), group_info.m_start_lsn,
405 ARCH_PAGE_FILE_HDR_SIZE, m_page_sys->get_mutex());
406
407 if (group == nullptr) {
408 return DB_OUT_OF_MEMORY;
409 }
410
411 err = group->recover(group_info, &m_dblwr_ctx);
412
413 if (err != DB_SUCCESS) {
414 ut::delete_(group);
415 break;
416 }
417
418 if (group_info.m_num_files == 0) {
419 ut::delete_(group);
420 continue;
421 }
422
423 if (group_info.m_active) {
424 ++num_active;
425 }
426
427 group_info.m_group = group;
428 }
429
430 /* There can be only one active group at a time. */
431 ut_ad(num_active <= 1);
432
433 return err;
434 }
435
436 dberr_t Arch_Page_Sys::Recovery::load_archiver() {
437 dberr_t err = DB_SUCCESS;
438
439 for (auto info_map = m_dir_group_info_map.begin();
440 info_map != m_dir_group_info_map.end(); ++info_map) {
441 auto &info = info_map->second;
442
443 if (info.m_group == nullptr) {
444 continue;
445 }
446
447 m_page_sys->m_group_list.push_back(info.m_group);
448
449 if (!info.m_active) {
450 continue;
451 }
452
453 /* Group was active at the time of shutdown/crash so start page archiving.
454 */
455
456 err = info.m_group->open_file(info.m_write_pos, info.m_new_empty_file);
457
458 if (err != DB_SUCCESS) {
459 break;
460 }
461
462 int error = m_page_sys->recovery_load_and_start(info);
463
464 if (error) {
465 err = DB_ERROR;
466 break;
467 }
468 }
469
470 return err;
471 }
472
473 dberr_t Arch_Group::recover(Arch_Recv_Group_Info &group_info,
474 Arch_Dblwr_Ctx *dblwr_ctx) {
475 Recovery group_recv(this);
476
477 const auto file_size =
478 static_cast<uint64_t>(ARCH_PAGE_BLK_SIZE) * ARCH_PAGE_FILE_CAPACITY;
479
480 auto err = init_file_ctx(ARCH_DIR, ARCH_PAGE_DIR, ARCH_PAGE_FILE,
481 group_info.m_num_files, file_size, 0);
482
483 if (err != DB_SUCCESS) {
484 return err;
485 }
486
487 if (group_info.m_active) {
488 /* Since the group was active at the time of crash it's possible that the
489 doublewrite buffer might have the latest data in case of a crash. */
490
491 err = group_recv.replace_pages_from_dblwr(dblwr_ctx);
492
493 if (err != DB_SUCCESS) {
494 return err;
495 }
496 }
497
498 err = group_recv.cleanup_if_required(group_info);
499
500 if (err != DB_SUCCESS || group_info.m_num_files == 0) {
501 return err;
502 }
503
504 err = group_recv.parse(group_info);
505
506 if (err != DB_SUCCESS) {
507 return err;
508 }
509
510 if (!group_info.m_active) {
511 auto end_lsn = group_info.m_last_stop_lsn;
512 ut_ad(end_lsn != LSN_MAX);
513
514 m_stop_pos = group_info.m_write_pos;
515 m_end_lsn = end_lsn;
516
517 group_recv.attach();
518 disable(end_lsn);
519 }
520
521 #ifdef UNIV_DEBUG
522 Arch_File_Ctx::Recovery file_ctx_recv(m_file_ctx);
523 file_ctx_recv.reset_print(group_info.m_file_start_index);
524 #endif
525
526 return err;
527 }
528
529 #ifdef UNIV_DEBUG
530 void Arch_File_Ctx::Recovery::reset_print(uint file_start_index) {
531 Arch_Reset reset;
532 Arch_Reset_File reset_file;
533 Arch_Point start_point;
534
535 DBUG_PRINT("page_archiver", ("No. of files : %u", m_file_ctx.m_count));
536
537 if (m_file_ctx.m_reset.size() == 0) {
538 DBUG_PRINT("page_archiver", ("No reset info available for this group."));
539 }
540
541 for (auto reset_file : m_file_ctx.m_reset) {
542 DBUG_PRINT("page_archiver", ("File %u\tFile LSN : %" PRIu64 "",
543 reset_file.m_file_index, reset_file.m_lsn));
544
545 if (reset_file.m_start_point.size() == 0) {
546 DBUG_PRINT("page_archiver", ("No reset info available for this file."));
547 }
548
549 for (uint i = 0; i < reset_file.m_start_point.size(); i++) {
550 start_point = reset_file.m_start_point[i];
551 DBUG_PRINT("page_archiver",
552 ("\tReset lsn : %" PRIu64 ", reset_pos : %" PRIu64 "\t %u",
553 start_point.lsn, start_point.pos.m_block_num,
554 start_point.pos.m_offset));
555 }
556 }
557
558 DBUG_PRINT("page_archiver",
559 ("Starting index of the file : %u", file_start_index));
560
561 DBUG_PRINT("page_archiver", ("Latest stop points"));
562 uint file_index = 0;
563 for (auto stop_point : m_file_ctx.m_stop_points) {
564 DBUG_PRINT("page_archiver",
565 ("\tFile %u : %" PRIu64 "", file_index, stop_point));
566 ++file_index;
567 }
568 }
569 #endif
570
571 dberr_t Arch_Group::Recovery::parse(Arch_Recv_Group_Info &info) {
572 dberr_t err = DB_SUCCESS;
573
574 size_t num_files = m_group->get_file_count();
575
576 if (num_files == 0) {
577 DBUG_PRINT("page_archiver", ("No group information available"));
578 return DB_SUCCESS;
579 }
580
581 uint start_index = info.m_file_start_index;
582 size_t file_count = start_index + num_files;
583
584 auto &file_ctx = m_group->m_file_ctx;
585
586 for (uint file_index = start_index; file_index < file_count; ++file_index) {
587 Arch_File_Ctx::Recovery file_ctx_recv(file_ctx);
588 Arch_scope_guard file_ctx_guard([&file_ctx] { file_ctx.close(); });
589
590 if (file_index == start_index) {
591 err = file_ctx.open(true, m_group->m_begin_lsn, start_index, 0,
592 m_group->get_file_size());
593 } else {
594 err =
595 file_ctx.open_next(m_group->m_begin_lsn, 0, m_group->get_file_size());
596 }
597
598 if (err != DB_SUCCESS) {
599 break;
600 }
601
602 bool last_file = (file_index + 1 == file_count);
603
604 err = file_ctx_recv.parse_reset_points(file_index, last_file, info);
605
606 if (err != DB_SUCCESS) {
607 break;
608 }
609
610 err = file_ctx_recv.parse_stop_points(last_file, info);
611
612 if (err != DB_SUCCESS) {
613 break;
614 }
615 }
616
617 return err;
618 }
619
620 dberr_t Arch_File_Ctx::Recovery::parse_stop_points(bool last_file,
621 Arch_Recv_Group_Info &info) {
622 ut_ad(!m_file_ctx.is_closed());
623
624 uint64_t offset;
625 byte buf[ARCH_PAGE_BLK_SIZE];
626
627 auto phy_size = m_file_ctx.get_phy_size();
628
629 if (last_file) {
630 offset = phy_size - ARCH_PAGE_BLK_SIZE;
631 } else {
632 offset = ARCH_PAGE_FILE_DATA_CAPACITY * ARCH_PAGE_BLK_SIZE;
633 }
634
635 if (phy_size < offset + ARCH_PAGE_BLK_SIZE) {
636 return DB_FILE_READ_BEYOND_SIZE;
637 }
638
639 auto err = m_file_ctx.read(buf, offset, ARCH_PAGE_BLK_SIZE);
640
641 if (err != DB_SUCCESS) {
642 return err;
643 }
644
645 auto stop_lsn = Arch_Block::get_stop_lsn(buf);
646 m_file_ctx.m_stop_points.push_back(stop_lsn);
647
648 if (last_file) {
649 info.m_last_stop_lsn = stop_lsn;
650 memcpy(info.m_last_data_block, buf, ARCH_PAGE_BLK_SIZE);
651 }
652
653 info.m_write_pos.init();
654 info.m_write_pos.m_block_num = Arch_Block::get_block_number(buf);
655 info.m_write_pos.m_offset =
656 Arch_Block::get_data_len(buf) + ARCH_PAGE_BLK_HEADER_LENGTH;
657
658 return err;
659 }
660
661 dberr_t Arch_File_Ctx::Recovery::parse_reset_points(
662 uint file_index, bool last_file, Arch_Recv_Group_Info &info) {
663 ut_ad(!m_file_ctx.is_closed());
664 ut_ad(m_file_ctx.m_index == file_index);
665
666 byte buf[ARCH_PAGE_BLK_SIZE];
667
668 if (m_file_ctx.get_phy_size() < ARCH_PAGE_BLK_SIZE) {
669 return DB_FILE_READ_BEYOND_SIZE;
670 }
671
672 /* Read reset block to fetch reset points. */
673 auto err = m_file_ctx.read(buf, 0, ARCH_PAGE_BLK_SIZE);
674
675 if (err != DB_SUCCESS) {
676 return err;
677 }
678
679 auto block_num = Arch_Block::get_block_number(buf);
680 auto data_len = Arch_Block::get_data_len(buf);
681
682 if (file_index != block_num) {
683 /* This means there was no reset for this file and hence the
684 reset block was not flushed. */
685
686 ut_ad(ut::is_zeros(buf, ARCH_PAGE_BLK_SIZE));
687 info.m_reset_pos.init();
688 info.m_reset_pos.m_block_num = file_index;
689 return err;
690 }
691
692 /* Normal case. */
693 info.m_reset_pos.m_block_num = block_num;
694 info.m_reset_pos.m_offset = data_len + ARCH_PAGE_BLK_HEADER_LENGTH;
695
696 if (last_file) {
697 memcpy(info.m_last_reset_block, buf, ARCH_PAGE_BLK_SIZE);
698 }
699
700 Arch_Reset_File reset_file;
701 reset_file.init();
702 reset_file.m_file_index = file_index;
703
704 if (data_len != 0) {
705 uint length = 0;
706 byte *buf1 = buf + ARCH_PAGE_BLK_HEADER_LENGTH;
707
708 ut_ad(data_len >= ARCH_PAGE_FILE_HEADER_RESET_LSN_SIZE +
709 ARCH_PAGE_FILE_HEADER_RESET_POS_SIZE);
710
711 reset_file.m_lsn = mach_read_from_8(buf1);
712 length += ARCH_PAGE_FILE_HEADER_RESET_LSN_SIZE;
713
714 Arch_Point start_point;
715 Arch_Page_Pos pos;
716
717 while (length != data_len) {
718 ut_ad((data_len - length) % ARCH_PAGE_FILE_HEADER_RESET_POS_SIZE == 0);
719
720 pos.m_block_num = mach_read_from_2(buf1 + length);
721 length += ARCH_PAGE_FILE_HEADER_RESET_BLOCK_NUM_SIZE;
722
723 pos.m_offset = mach_read_from_2(buf1 + length);
724 length += ARCH_PAGE_FILE_HEADER_RESET_BLOCK_OFFSET_SIZE;
725
726 start_point.lsn = m_file_ctx.fetch_reset_lsn(pos.m_block_num);
727 start_point.pos = pos;
728
729 reset_file.m_start_point.push_back(start_point);
730 }
731
732 m_file_ctx.m_reset.push_back(reset_file);
733 }
734
735 info.m_last_reset_file = reset_file;
736
737 return err;
738 }
739
740 lsn_t Arch_File_Ctx::fetch_reset_lsn(uint64_t block_num) {
741 ut_ad(!is_closed());
742 ut_ad(Arch_Block::get_file_index(block_num, ARCH_DATA_BLOCK) == m_index);
743
744 byte buf[ARCH_PAGE_BLK_SIZE];
745
746 auto offset = Arch_Block::get_file_offset(block_num, ARCH_DATA_BLOCK);
747
748 ut_ad(offset + ARCH_PAGE_BLK_SIZE <= get_phy_size());
749
750 auto err = read(buf, offset, ARCH_PAGE_BLK_HEADER_LENGTH);
751
752 if (err != DB_SUCCESS) {
753 return (LSN_MAX);
754 }
755
756 auto lsn = Arch_Block::get_reset_lsn(buf);
757
758 ut_ad(lsn != LSN_MAX);
759
760 return (lsn);
761 }