drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
log0recv.cc
1/*****************************************************************************
2
3Copyright (C) 1997, 2010, Innobase Oy. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15St, Fifth Floor, Boston, MA 02110-1301 USA
16
17*****************************************************************************/
18
19/**************************************************/
25
26#include "log0recv.h"
27
28#ifdef UNIV_NONINL
29#include "log0recv.ic"
30#endif
31
32#include "mem0mem.h"
33#include "buf0buf.h"
34#include "buf0flu.h"
35#include "mtr0mtr.h"
36#include "mtr0log.h"
37#include "page0cur.h"
38#include "page0zip.h"
39#include "btr0btr.h"
40#include "btr0cur.h"
41#include "ibuf0ibuf.h"
42#include "trx0undo.h"
43#include "trx0rec.h"
44#include "fil0fil.h"
45#include "xtrabackup_api.h"
46#ifndef UNIV_HOTBACKUP
47# include "buf0rea.h"
48# include "srv0srv.h"
49# include "srv0start.h"
50# include "trx0roll.h"
51# include "row0merge.h"
52# include "sync0sync.h"
53#else /* !UNIV_HOTBACKUP */
54
58UNIV_INTERN ibool recv_replay_file_ops = TRUE;
59#endif /* !UNIV_HOTBACKUP */
60
61#include <boost/scoped_array.hpp>
62
63#include <drizzled/errmsg_print.h>
64
67#define RECV_DATA_BLOCK_SIZE (MEM_MAX_ALLOC_IN_BUF - sizeof(recv_data_t))
68
70#define RECV_READ_AHEAD_AREA 32
71
73UNIV_INTERN recv_sys_t* recv_sys = NULL;
77UNIV_INTERN ibool recv_recovery_on;
78#ifdef UNIV_LOG_ARCHIVE
80UNIV_INTERN ibool recv_recovery_from_backup_on;
81#endif /* UNIV_LOG_ARCHIVE */
82
83#ifndef UNIV_HOTBACKUP
85UNIV_INTERN ibool recv_needed_recovery;
86# ifdef UNIV_DEBUG
89UNIV_INTERN ibool recv_no_log_write = FALSE;
90# endif /* UNIV_DEBUG */
91
95UNIV_INTERN ibool recv_lsn_checks_on;
96
105static ibool recv_log_scan_is_startup_type;
106
116UNIV_INTERN ibool recv_no_ibuf_operations;
118# define recv_is_making_a_backup FALSE
120# define recv_is_from_backup FALSE
121#else /* !UNIV_HOTBACKUP */
122# define recv_needed_recovery FALSE
124UNIV_INTERN ibool recv_is_making_a_backup = FALSE;
126UNIV_INTERN ibool recv_is_from_backup = FALSE;
127# define buf_pool_get_curr_size() (5 * 1024 * 1024)
128#endif /* !UNIV_HOTBACKUP */
131static ulint recv_scan_print_counter;
132
134static ulint recv_previous_parsed_rec_type;
136static ulint recv_previous_parsed_rec_offset;
138static ulint recv_previous_parsed_rec_is_multi;
139
141UNIV_INTERN ulint recv_max_parsed_page_no;
142
149UNIV_INTERN ulint recv_n_pool_free_frames;
150
154UNIV_INTERN ib_uint64_t recv_max_page_lsn;
155
156#ifdef UNIV_PFS_THREAD
157UNIV_INTERN mysql_pfs_key_t trx_rollback_clean_thread_key;
158#endif /* UNIV_PFS_THREAD */
159
160#ifdef UNIV_PFS_MUTEX
161UNIV_INTERN mysql_pfs_key_t recv_sys_mutex_key;
162#endif /* UNIV_PFS_MUTEX */
163
164/* prototypes */
165
166#ifndef UNIV_HOTBACKUP
167/*******************************************************/
170static
171void
172recv_init_crash_recovery(void);
173/*===========================*/
174#endif /* !UNIV_HOTBACKUP */
175
176/********************************************************/
178UNIV_INTERN
179void
181/*=================*/
182{
183 if (recv_sys != NULL) {
184
185 return;
186 }
187
188 recv_sys = static_cast<recv_sys_t *>(mem_alloc(sizeof(*recv_sys)));
189 memset(recv_sys, 0x0, sizeof(*recv_sys));
190
191 mutex_create(recv_sys_mutex_key, &recv_sys->mutex, SYNC_RECV);
192
193 recv_sys->heap = NULL;
194 recv_sys->addr_hash = NULL;
195}
196
197/********************************************************/
199UNIV_INTERN
200void
202/*================*/
203{
204 if (recv_sys != NULL) {
205 if (recv_sys->addr_hash != NULL) {
206 hash_table_free(recv_sys->addr_hash);
207 }
208
209 if (recv_sys->heap != NULL) {
210 mem_heap_free(recv_sys->heap);
211 }
212
213 if (recv_sys->buf != NULL) {
214 ut_free(recv_sys->buf);
215 }
216
217 if (recv_sys->last_block_buf_start != NULL) {
218 mem_free(recv_sys->last_block_buf_start);
219 }
220
221 mutex_free(&recv_sys->mutex);
222
224 recv_sys = NULL;
225 }
226}
227
228/********************************************************/
230UNIV_INTERN
231void
233/*===================*/
234{
235 if (recv_sys != NULL) {
236 if (recv_sys->addr_hash != NULL) {
237 hash_table_free(recv_sys->addr_hash);
238 }
239
240 if (recv_sys->heap != NULL) {
241 mem_heap_free(recv_sys->heap);
242 }
243
244 if (recv_sys->buf != NULL) {
245 ut_free(recv_sys->buf);
246 }
247
248 if (recv_sys->last_block_buf_start != NULL) {
249 mem_free(recv_sys->last_block_buf_start);
250 }
251
253 recv_sys = NULL;
254 }
255}
256
257#ifndef UNIV_HOTBACKUP
258/************************************************************
259Reset the state of the recovery system variables. */
260UNIV_INTERN
261void
263/*===================*/
264{
265 recv_lsn_checks_on = FALSE;
266
268
269 recv_recovery_on = FALSE;
270
271#ifdef UNIV_LOG_ARCHIVE
272 recv_recovery_from_backup_on = FALSE;
273#endif /* UNIV_LOG_ARCHIVE */
274
275 recv_needed_recovery = FALSE;
276
277 recv_lsn_checks_on = FALSE;
278
279 recv_log_scan_is_startup_type = FALSE;
280
282
283 recv_scan_print_counter = 0;
284
285 recv_previous_parsed_rec_type = 999999;
286
287 recv_previous_parsed_rec_offset = 0;
288
289 recv_previous_parsed_rec_is_multi = 0;
290
292
294
295 recv_max_page_lsn = 0;
296}
297#endif /* !UNIV_HOTBACKUP */
298
299/************************************************************
300Inits the recovery system for a recovery operation. */
301UNIV_INTERN
302void
304/*==========*/
305 ulint available_memory)
306{
307 if (recv_sys->heap != NULL) {
308
309 return;
310 }
311
312#ifndef UNIV_HOTBACKUP
313 /* Initialize red-black tree for fast insertions into the
314 flush_list during recovery process.
315 As this initialization is done while holding the buffer pool
316 mutex we perform it before acquiring recv_sys->mutex. */
317#ifndef UNIV_HOTBACKUP
319#endif /* !UNIV_HOTBACKUP */
320
321 mutex_enter(&(recv_sys->mutex));
322
324#else /* !UNIV_HOTBACKUP */
325 recv_sys->heap = mem_heap_create(256);
326 recv_is_from_backup = TRUE;
327#endif /* !UNIV_HOTBACKUP */
328
329 /* Set appropriate value of recv_n_pool_free_frames. */
330 if (buf_pool_get_curr_size() >= (10 * 1024 * 1024)) {
331 /* Buffer pool of size greater than 10 MB. */
333 }
334
335 recv_sys->buf = static_cast<byte *>(ut_malloc(RECV_PARSING_BUF_SIZE));
336 recv_sys->len = 0;
337 recv_sys->recovered_offset = 0;
338
339 recv_sys->addr_hash = hash_create(available_memory / 512);
340 recv_sys->n_addrs = 0;
341
342 recv_sys->apply_log_recs = FALSE;
343 recv_sys->apply_batch_on = FALSE;
344
345 recv_sys->last_block_buf_start = static_cast<byte *>(mem_alloc(2 * OS_FILE_LOG_BLOCK_SIZE));
346
347 recv_sys->last_block = static_cast<byte *>(ut_align(recv_sys->last_block_buf_start,
349 recv_sys->found_corrupt_log = FALSE;
350
351 recv_max_page_lsn = 0;
352
353 mutex_exit(&(recv_sys->mutex));
354}
355
356/********************************************************/
358static
359void
360recv_sys_empty_hash(void)
361/*=====================*/
362{
363 ut_ad(mutex_own(&(recv_sys->mutex)));
364
365 if (recv_sys->n_addrs != 0) {
366 drizzled::errmsg_printf(drizzled::error::ERROR,
367 "InnoDB: Error: %lu pages with log records were left unprocessed!\n"
368 "InnoDB: Maximum page number with log records on it %lu\n",
369 (ulong) recv_sys->n_addrs,
371 ut_error;
372 }
373
374 hash_table_free(recv_sys->addr_hash);
376
377 recv_sys->addr_hash = hash_create(buf_pool_get_curr_size() / 512);
378}
379
380#ifndef UNIV_HOTBACKUP
381# ifndef UNIV_LOG_DEBUG
382/********************************************************/
384static
385void
386recv_sys_debug_free(void)
387/*=====================*/
388{
389 mutex_enter(&(recv_sys->mutex));
390
391 hash_table_free(recv_sys->addr_hash);
392 mem_heap_free(recv_sys->heap);
393 ut_free(recv_sys->buf);
394 mem_free(recv_sys->last_block_buf_start);
395
396 recv_sys->buf = NULL;
397 recv_sys->heap = NULL;
398 recv_sys->addr_hash = NULL;
399 recv_sys->last_block_buf_start = NULL;
400
401 mutex_exit(&(recv_sys->mutex));
402
403 /* Free up the flush_rbt. */
405}
406# endif /* UNIV_LOG_DEBUG */
407
408/********************************************************/
410static
411void
412recv_truncate_group(
413/*================*/
414 log_group_t* group,
415 ib_uint64_t recovered_lsn,
417 ib_uint64_t limit_lsn,
419 ib_uint64_t checkpoint_lsn,
421 ib_uint64_t archived_lsn)
423{
424 ib_uint64_t start_lsn;
425 ib_uint64_t end_lsn;
426 ib_uint64_t finish_lsn1;
427 ib_uint64_t finish_lsn2;
428 ib_uint64_t finish_lsn;
429 ulint len;
430 ulint i;
431
432 if (archived_lsn == IB_ULONGLONG_MAX) {
433 /* Checkpoint was taken in the NOARCHIVELOG mode */
434 archived_lsn = checkpoint_lsn;
435 }
436
437 finish_lsn1 = ut_uint64_align_down(archived_lsn,
439 + log_group_get_capacity(group);
440
441 finish_lsn2 = ut_uint64_align_up(recovered_lsn,
443 + recv_sys->last_log_buf_size;
444
445 if (limit_lsn != IB_ULONGLONG_MAX) {
446 /* We do not know how far we should erase log records: erase
447 as much as possible */
448
449 finish_lsn = finish_lsn1;
450 } else {
451 /* It is enough to erase the length of the log buffer */
452 finish_lsn = finish_lsn1 < finish_lsn2
453 ? finish_lsn1 : finish_lsn2;
454 }
455
457
458 /* Write the log buffer full of zeros */
459 for (i = 0; i < RECV_SCAN_SIZE; i++) {
460
461 *(log_sys->buf + i) = '\0';
462 }
463
464 start_lsn = ut_uint64_align_down(recovered_lsn,
466
467 if (start_lsn != recovered_lsn) {
468 /* Copy the last incomplete log block to the log buffer and
469 edit its data length: */
470
471 ut_memcpy(log_sys->buf, recv_sys->last_block,
473 log_block_set_data_len(log_sys->buf,
474 (ulint) (recovered_lsn - start_lsn));
475 }
476
477 if (start_lsn >= finish_lsn) {
478
479 return;
480 }
481
482 for (;;) {
483 end_lsn = start_lsn + RECV_SCAN_SIZE;
484
485 if (end_lsn > finish_lsn) {
486
487 end_lsn = finish_lsn;
488 }
489
490 len = (ulint) (end_lsn - start_lsn);
491
492 log_group_write_buf(group, log_sys->buf, len, start_lsn, 0);
493 if (end_lsn >= finish_lsn) {
494
495 return;
496 }
497
498 /* Write the log buffer full of zeros */
499 for (i = 0; i < RECV_SCAN_SIZE; i++) {
500
501 *(log_sys->buf + i) = '\0';
502 }
503
504 start_lsn = end_lsn;
505 }
506}
507
508/********************************************************/
511static
512void
513recv_copy_group(
514/*============*/
515 log_group_t* up_to_date_group,
517 log_group_t* group,
519 ib_uint64_t recovered_lsn)
521{
522 ib_uint64_t start_lsn;
523 ib_uint64_t end_lsn;
524 ulint len;
525
526 if (group->scanned_lsn >= recovered_lsn) {
527
528 return;
529 }
530
532
533 start_lsn = ut_uint64_align_down(group->scanned_lsn,
535 for (;;) {
536 end_lsn = start_lsn + RECV_SCAN_SIZE;
537
538 if (end_lsn > recovered_lsn) {
539 end_lsn = ut_uint64_align_up(recovered_lsn,
541 }
542
543 log_group_read_log_seg(LOG_RECOVER, log_sys->buf,
544 up_to_date_group, start_lsn, end_lsn);
545
546 len = (ulint) (end_lsn - start_lsn);
547
548 log_group_write_buf(group, log_sys->buf, len, start_lsn, 0);
549
550 if (end_lsn >= recovered_lsn) {
551
552 return;
553 }
554
555 start_lsn = end_lsn;
556 }
557}
558
559/********************************************************/
564static
565void
566recv_synchronize_groups(
567/*====================*/
568 log_group_t* up_to_date_group)
570{
571 log_group_t* group;
572 ib_uint64_t start_lsn;
573 ib_uint64_t end_lsn;
574 ib_uint64_t recovered_lsn;
575
576 recovered_lsn = recv_sys->recovered_lsn;
577
578 /* Read the last recovered log block to the recovery system buffer:
579 the block is always incomplete */
580
581 start_lsn = ut_uint64_align_down(recovered_lsn,
583 end_lsn = ut_uint64_align_up(recovered_lsn, OS_FILE_LOG_BLOCK_SIZE);
584
585 ut_a(start_lsn != end_lsn);
586
587 log_group_read_log_seg(LOG_RECOVER, recv_sys->last_block,
588 up_to_date_group, start_lsn, end_lsn);
589
590 group = UT_LIST_GET_FIRST(log_sys->log_groups);
591
592 while (group) {
593 if (group != up_to_date_group) {
594
595 /* Copy log data if needed */
596
597 recv_copy_group(group, up_to_date_group,
598 recovered_lsn);
599 }
600
601 /* Update the fields in the group struct to correspond to
602 recovered_lsn */
603
604 log_group_set_fields(group, recovered_lsn);
605
606 group = UT_LIST_GET_NEXT(log_groups, group);
607 }
608
609 /* Copy the checkpoint info to the groups; remember that we have
610 incremented checkpoint_no by one, and the info will not be written
611 over the max checkpoint info, thus making the preservation of max
612 checkpoint info on disk certain */
613
615
616 mutex_exit(&(log_sys->mutex));
617
618 /* Wait for the checkpoint write to complete */
619 rw_lock_s_lock(&(log_sys->checkpoint_lock));
620 rw_lock_s_unlock(&(log_sys->checkpoint_lock));
621
622 mutex_enter(&(log_sys->mutex));
623}
624#endif /* !UNIV_HOTBACKUP */
625
626/***********************************************************************/
629ibool
630recv_check_cp_is_consistent(
631/*========================*/
632 const byte* buf)
633{
634 ulint fold;
635
636 fold = ut_fold_binary(buf, LOG_CHECKPOINT_CHECKSUM_1);
637
638 if ((fold & 0xFFFFFFFFUL) != mach_read_from_4(
639 buf + LOG_CHECKPOINT_CHECKSUM_1)) {
640 return(FALSE);
641 }
642
643 fold = ut_fold_binary(buf + LOG_CHECKPOINT_LSN,
644 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
645
646 if ((fold & 0xFFFFFFFFUL) != mach_read_from_4(
647 buf + LOG_CHECKPOINT_CHECKSUM_2)) {
648 return(FALSE);
649 }
650
651 return(TRUE);
652}
653
654#ifndef UNIV_HOTBACKUP
655/********************************************************/
658ulint
659recv_find_max_checkpoint(
660/*=====================*/
661 log_group_t** max_group,
662 ulint* max_field)
664{
665 log_group_t* group;
666 ib_uint64_t max_no;
667 ib_uint64_t checkpoint_no;
668 ulint field;
669 byte* buf;
670
671 group = UT_LIST_GET_FIRST(log_sys->log_groups);
672
673 max_no = 0;
674 *max_group = NULL;
675 *max_field = 0;
676
677 buf = log_sys->checkpoint_buf;
678
679 while (group) {
680 group->state = LOG_GROUP_CORRUPTED;
681
682 for (field = LOG_CHECKPOINT_1; field <= LOG_CHECKPOINT_2;
683 field += LOG_CHECKPOINT_2 - LOG_CHECKPOINT_1) {
684
685 log_group_read_checkpoint_info(group, field);
686
687 if (!recv_check_cp_is_consistent(buf)) {
688#ifdef UNIV_DEBUG
689 if (log_debug_writes) {
690 drizzled::errmsg_printf(drizzled::error::INFO,
691 "InnoDB: Checkpoint in group %lu at %lu invalid, %lu\n",
692 (ulong) group->id,
693 (ulong) field,
694 (ulong) mach_read_from_4(
695 buf
696 + LOG_CHECKPOINT_CHECKSUM_1));
697
698 }
699#endif /* UNIV_DEBUG */
700 goto not_consistent;
701 }
702
703 group->state = LOG_GROUP_OK;
704
705 group->lsn = mach_read_from_8(
706 buf + LOG_CHECKPOINT_LSN);
707
708#ifdef UNIV_LOG_ARCHIVE
709#error "UNIV_LOG_ARCHIVE could not be enabled"
710#endif
711 {
712 ib_uint64_t tmp_lsn_offset = mach_read_from_8(
713 buf + LOG_CHECKPOINT_ARCHIVED_LSN);
714 if (sizeof(ulint) != 4
715 && tmp_lsn_offset != IB_ULONGLONG_MAX) {
716 group->lsn_offset = (ulint) tmp_lsn_offset;
717 } else {
719 buf + LOG_CHECKPOINT_OFFSET);
720 }
721 }
722
723 checkpoint_no = mach_read_from_8(
724 buf + LOG_CHECKPOINT_NO);
725
726#ifdef UNIV_DEBUG
727 if (log_debug_writes) {
728 drizzled::errmsg_printf(drizzled::error::INFO,
729 "InnoDB: Checkpoint number %lu found in group %lu\n",
730 (ulong) checkpoint_no,
731 (ulong) group->id);
732 }
733#endif /* UNIV_DEBUG */
734
735 if (checkpoint_no >= max_no) {
736 *max_group = group;
737 *max_field = field;
738 max_no = checkpoint_no;
739 }
740
741not_consistent:
742 ;
743 }
744
745 group = UT_LIST_GET_NEXT(log_groups, group);
746 }
747
748 if (*max_group == NULL) {
749
750 drizzled::errmsg_printf(drizzled::error::ERROR,
751 "InnoDB: No valid checkpoint found. If this error appears when you are"
752 " creating an InnoDB database,InnoDB: the problem may be that during"
753 " an earlier attempt you managed to create the InnoDB data files,"
754 " but log file creation failed. If that is the case, please refer to\n"
755 "InnoDB: " REFMAN "error-creating-innodb.html\n");
756 return(DB_ERROR);
757 }
758
759 return(DB_SUCCESS);
760}
761#else /* !UNIV_HOTBACKUP */
762/*******************************************************************/
765UNIV_INTERN
766ibool
767recv_read_cp_info_for_backup(
768/*=========================*/
769 const byte* hdr,
771 ib_uint64_t* lsn,
772 ulint* offset,
773 ulint* fsp_limit,
776 ib_uint64_t* cp_no,
777 ib_uint64_t* first_header_lsn)
780{
781 ulint max_cp = 0;
782 ib_uint64_t max_cp_no = 0;
783 const byte* cp_buf;
784
785 cp_buf = hdr + LOG_CHECKPOINT_1;
786
787 if (recv_check_cp_is_consistent(cp_buf)) {
788 max_cp_no = mach_read_from_8(cp_buf + LOG_CHECKPOINT_NO);
789 max_cp = LOG_CHECKPOINT_1;
790 }
791
792 cp_buf = hdr + LOG_CHECKPOINT_2;
793
794 if (recv_check_cp_is_consistent(cp_buf)) {
795 if (mach_read_from_8(cp_buf + LOG_CHECKPOINT_NO) > max_cp_no) {
796 max_cp = LOG_CHECKPOINT_2;
797 }
798 }
799
800 if (max_cp == 0) {
801 return(FALSE);
802 }
803
804 cp_buf = hdr + max_cp;
805
806 *lsn = mach_read_from_8(cp_buf + LOG_CHECKPOINT_LSN);
807 *offset = mach_read_from_4(cp_buf + LOG_CHECKPOINT_OFFSET);
808
809 /* If the user is running a pre-3.23.50 version of InnoDB, its
810 checkpoint data does not contain the fsp limit info */
811 if (mach_read_from_4(cp_buf + LOG_CHECKPOINT_FSP_MAGIC_N)
812 == LOG_CHECKPOINT_FSP_MAGIC_N_VAL) {
813
814 *fsp_limit = mach_read_from_4(
815 cp_buf + LOG_CHECKPOINT_FSP_FREE_LIMIT);
816
817 if (*fsp_limit == 0) {
818 *fsp_limit = 1000000000;
819 }
820 } else {
821 *fsp_limit = 1000000000;
822 }
823
824 /* fprintf(stderr, "fsp limit %lu MB\n", *fsp_limit); */
825
826 *cp_no = mach_read_from_8(cp_buf + LOG_CHECKPOINT_NO);
827
828 *first_header_lsn = mach_read_from_8(hdr + LOG_FILE_START_LSN);
829
830 return(TRUE);
831}
832#endif /* !UNIV_HOTBACKUP */
833
834/******************************************************/
840ibool
841log_block_checksum_is_ok_or_old_format(
842/*===================================*/
843 const byte* block)
844{
845#ifdef UNIV_LOG_DEBUG
846 return(TRUE);
847#endif /* UNIV_LOG_DEBUG */
848 if (log_block_calc_checksum(block) == log_block_get_checksum(block)) {
849
850 return(TRUE);
851 }
852
853 if (log_block_get_hdr_no(block) == log_block_get_checksum(block)) {
854
855 /* We assume the log block is in the format of
856 InnoDB version < 3.23.52 and the block is ok */
857#if 0
858 fprintf(stderr,
859 "InnoDB: Scanned old format < InnoDB-3.23.52"
860 " log block number %lu\n",
861 log_block_get_hdr_no(block));
862#endif
863 return(TRUE);
864 }
865
866 return(FALSE);
867}
868
869#ifdef UNIV_HOTBACKUP
870/*******************************************************************/
873UNIV_INTERN
874void
875recv_scan_log_seg_for_backup(
876/*=========================*/
877 byte* buf,
878 ulint buf_len,
879 ib_uint64_t* scanned_lsn,
881 ulint* scanned_checkpoint_no,
885 ulint* n_bytes_scanned)
888{
889 ulint data_len;
890 byte* log_block;
891 ulint no;
892
893 *n_bytes_scanned = 0;
894
895 for (log_block = buf; log_block < buf + buf_len;
896 log_block += OS_FILE_LOG_BLOCK_SIZE) {
897
898 no = log_block_get_hdr_no(log_block);
899
900#if 0
901 fprintf(stderr, "Log block header no %lu\n", no);
902#endif
903
904 if (no != log_block_convert_lsn_to_no(*scanned_lsn)
905 || !log_block_checksum_is_ok_or_old_format(log_block)) {
906#if 0
907 fprintf(stderr,
908 "Log block n:o %lu, scanned lsn n:o %lu\n",
909 no, log_block_convert_lsn_to_no(*scanned_lsn));
910#endif
911 /* Garbage or an incompletely written log block */
912
913 log_block += OS_FILE_LOG_BLOCK_SIZE;
914#if 0
915 fprintf(stderr,
916 "Next log block n:o %lu\n",
917 log_block_get_hdr_no(log_block));
918#endif
919 break;
920 }
921
922 if (*scanned_checkpoint_no > 0
923 && log_block_get_checkpoint_no(log_block)
924 < *scanned_checkpoint_no
925 && *scanned_checkpoint_no
926 - log_block_get_checkpoint_no(log_block)
927 > 0x80000000UL) {
928
929 /* Garbage from a log buffer flush which was made
930 before the most recent database recovery */
931#if 0
932 fprintf(stderr,
933 "Scanned cp n:o %lu, block cp n:o %lu\n",
934 *scanned_checkpoint_no,
935 log_block_get_checkpoint_no(log_block));
936#endif
937 break;
938 }
939
940 data_len = log_block_get_data_len(log_block);
941
942 *scanned_checkpoint_no
943 = log_block_get_checkpoint_no(log_block);
944 *scanned_lsn += data_len;
945
946 *n_bytes_scanned += data_len;
947
948 if (data_len < OS_FILE_LOG_BLOCK_SIZE) {
949 /* Log data ends here */
950
951#if 0
952 fprintf(stderr, "Log block data len %lu\n",
953 data_len);
954#endif
955 break;
956 }
957 }
958}
959#endif /* UNIV_HOTBACKUP */
960
961/*******************************************************************/
965static
966byte*
967recv_parse_or_apply_log_rec_body(
968/*=============================*/
969 byte type,
970 byte* ptr,
971 byte* end_ptr,
972 buf_block_t* block,
976 mtr_t* mtr)
978{
979 dict_index_t* index = NULL;
980 page_t* page;
981 page_zip_des_t* page_zip;
982#ifdef UNIV_DEBUG
983 ulint page_type;
984#endif /* UNIV_DEBUG */
985
986 ut_ad(!block == !mtr);
987
988 if (block) {
989 page = block->frame;
990 page_zip = buf_block_get_page_zip(block);
991 ut_d(page_type = fil_page_get_type(page));
992 } else {
993 page = NULL;
994 page_zip = NULL;
995 ut_d(page_type = FIL_PAGE_TYPE_ALLOCATED);
996 }
997
998 switch (type) {
999#ifdef UNIV_LOG_LSN_DEBUG
1000 case MLOG_LSN:
1001 /* The LSN is checked in recv_parse_log_rec(). */
1002 break;
1003#endif /* UNIV_LOG_LSN_DEBUG */
1004 case MLOG_1BYTE: case MLOG_2BYTES: case MLOG_4BYTES: case MLOG_8BYTES:
1005#ifdef UNIV_DEBUG
1006 if (page && page_type == FIL_PAGE_TYPE_ALLOCATED
1007 && end_ptr >= ptr + 2) {
1008 /* It is OK to set FIL_PAGE_TYPE and certain
1009 list node fields on an empty page. Any other
1010 write is not OK. */
1011
1012 /* NOTE: There may be bogus assertion failures for
1013 dict_hdr_create(), trx_rseg_header_create(),
1014 trx_sys_create_doublewrite_buf(), and
1015 trx_sysf_create().
1016 These are only called during database creation. */
1017 ulint offs = mach_read_from_2(ptr);
1018
1019 switch (type) {
1020 default:
1021 ut_error;
1022 case MLOG_2BYTES:
1023 /* Note that this can fail when the
1024 redo log been written with something
1025 older than InnoDB Plugin 1.0.4. */
1026 ut_ad(offs == FIL_PAGE_TYPE
1027 || offs == IBUF_TREE_SEG_HEADER
1028 + IBUF_HEADER + FSEG_HDR_OFFSET
1029 || offs == PAGE_BTR_IBUF_FREE_LIST
1030 + PAGE_HEADER + FIL_ADDR_BYTE
1031 || offs == PAGE_BTR_IBUF_FREE_LIST
1032 + PAGE_HEADER + FIL_ADDR_BYTE
1033 + FIL_ADDR_SIZE
1034 || offs == PAGE_BTR_SEG_LEAF
1035 + PAGE_HEADER + FSEG_HDR_OFFSET
1036 || offs == PAGE_BTR_SEG_TOP
1037 + PAGE_HEADER + FSEG_HDR_OFFSET
1038 || offs == PAGE_BTR_IBUF_FREE_LIST_NODE
1039 + PAGE_HEADER + FIL_ADDR_BYTE
1040 + 0 /*FLST_PREV*/
1041 || offs == PAGE_BTR_IBUF_FREE_LIST_NODE
1042 + PAGE_HEADER + FIL_ADDR_BYTE
1043 + FIL_ADDR_SIZE /*FLST_NEXT*/);
1044 break;
1045 case MLOG_4BYTES:
1046 /* Note that this can fail when the
1047 redo log been written with something
1048 older than InnoDB Plugin 1.0.4. */
1049 ut_ad(0
1050 || offs == IBUF_TREE_SEG_HEADER
1051 + IBUF_HEADER + FSEG_HDR_SPACE
1052 || offs == IBUF_TREE_SEG_HEADER
1053 + IBUF_HEADER + FSEG_HDR_PAGE_NO
1054 || offs == PAGE_BTR_IBUF_FREE_LIST
1055 + PAGE_HEADER/* flst_init */
1056 || offs == PAGE_BTR_IBUF_FREE_LIST
1057 + PAGE_HEADER + FIL_ADDR_PAGE
1058 || offs == PAGE_BTR_IBUF_FREE_LIST
1059 + PAGE_HEADER + FIL_ADDR_PAGE
1060 + FIL_ADDR_SIZE
1061 || offs == PAGE_BTR_SEG_LEAF
1062 + PAGE_HEADER + FSEG_HDR_PAGE_NO
1063 || offs == PAGE_BTR_SEG_LEAF
1064 + PAGE_HEADER + FSEG_HDR_SPACE
1065 || offs == PAGE_BTR_SEG_TOP
1066 + PAGE_HEADER + FSEG_HDR_PAGE_NO
1067 || offs == PAGE_BTR_SEG_TOP
1068 + PAGE_HEADER + FSEG_HDR_SPACE
1069 || offs == PAGE_BTR_IBUF_FREE_LIST_NODE
1070 + PAGE_HEADER + FIL_ADDR_PAGE
1071 + 0 /*FLST_PREV*/
1072 || offs == PAGE_BTR_IBUF_FREE_LIST_NODE
1073 + PAGE_HEADER + FIL_ADDR_PAGE
1074 + FIL_ADDR_SIZE /*FLST_NEXT*/);
1075 break;
1076 }
1077 }
1078#endif /* UNIV_DEBUG */
1079 ptr = mlog_parse_nbytes(type, ptr, end_ptr, page, page_zip);
1080 break;
1082 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1083
1084 if (NULL != (ptr = mlog_parse_index(
1085 ptr, end_ptr,
1086 type == MLOG_COMP_REC_INSERT,
1087 &index))) {
1088 ut_a(!page
1089 || (ibool)!!page_is_comp(page)
1090 == dict_table_is_comp(index->table));
1091 ptr = page_cur_parse_insert_rec(FALSE, ptr, end_ptr,
1092 block, index, mtr);
1093 }
1094 break;
1096 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1097
1098 if (NULL != (ptr = mlog_parse_index(
1099 ptr, end_ptr,
1101 &index))) {
1102 ut_a(!page
1103 || (ibool)!!page_is_comp(page)
1104 == dict_table_is_comp(index->table));
1105 ptr = btr_cur_parse_del_mark_set_clust_rec(
1106 ptr, end_ptr, page, page_zip, index);
1107 }
1108 break;
1110 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1111 /* This log record type is obsolete, but we process it for
1112 backward compatibility with MySQL 5.0.3 and 5.0.4. */
1113 ut_a(!page || page_is_comp(page));
1114 ut_a(!page_zip);
1115 ptr = mlog_parse_index(ptr, end_ptr, TRUE, &index);
1116 if (!ptr) {
1117 break;
1118 }
1119 /* Fall through */
1121 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1122 ptr = btr_cur_parse_del_mark_set_sec_rec(ptr, end_ptr,
1123 page, page_zip);
1124 break;
1126 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1127
1128 if (NULL != (ptr = mlog_parse_index(
1129 ptr, end_ptr,
1131 &index))) {
1132 ut_a(!page
1133 || (ibool)!!page_is_comp(page)
1134 == dict_table_is_comp(index->table));
1135 ptr = btr_cur_parse_update_in_place(ptr, end_ptr, page,
1136 page_zip, index);
1137 }
1138 break;
1141 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1142
1143 if (NULL != (ptr = mlog_parse_index(
1144 ptr, end_ptr,
1146 || type == MLOG_COMP_LIST_START_DELETE,
1147 &index))) {
1148 ut_a(!page
1149 || (ibool)!!page_is_comp(page)
1150 == dict_table_is_comp(index->table));
1151 ptr = page_parse_delete_rec_list(type, ptr, end_ptr,
1152 block, index, mtr);
1153 }
1154 break;
1156 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1157
1158 if (NULL != (ptr = mlog_parse_index(
1159 ptr, end_ptr,
1161 &index))) {
1162 ut_a(!page
1163 || (ibool)!!page_is_comp(page)
1164 == dict_table_is_comp(index->table));
1166 ptr, end_ptr, block, index, mtr);
1167 }
1168 break;
1170 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1171
1172 if (NULL != (ptr = mlog_parse_index(
1173 ptr, end_ptr,
1175 &index))) {
1176 ut_a(!page
1177 || (ibool)!!page_is_comp(page)
1178 == dict_table_is_comp(index->table));
1179 ptr = btr_parse_page_reorganize(ptr, end_ptr, index,
1180 block, mtr);
1181 }
1182 break;
1184 /* Allow anything in page_type when creating a page. */
1185 ut_a(!page_zip);
1186 ptr = page_parse_create(ptr, end_ptr,
1187 type == MLOG_COMP_PAGE_CREATE,
1188 block, mtr);
1189 break;
1190 case MLOG_UNDO_INSERT:
1191 ut_ad(!page || page_type == FIL_PAGE_UNDO_LOG);
1192 ptr = trx_undo_parse_add_undo_rec(ptr, end_ptr, page);
1193 break;
1195 ut_ad(!page || page_type == FIL_PAGE_UNDO_LOG);
1196 ptr = trx_undo_parse_erase_page_end(ptr, end_ptr, page, mtr);
1197 break;
1198 case MLOG_UNDO_INIT:
1199 /* Allow anything in page_type when creating a page. */
1200 ptr = trx_undo_parse_page_init(ptr, end_ptr, page, mtr);
1201 break;
1203 ut_ad(!page || page_type == FIL_PAGE_UNDO_LOG);
1204 ptr = trx_undo_parse_discard_latest(ptr, end_ptr, page, mtr);
1205 break;
1208 ut_ad(!page || page_type == FIL_PAGE_UNDO_LOG);
1209 ptr = trx_undo_parse_page_header(type, ptr, end_ptr,
1210 page, mtr);
1211 break;
1213 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1214 /* On a compressed page, MLOG_COMP_REC_MIN_MARK
1215 will be followed by MLOG_COMP_REC_DELETE
1216 or MLOG_ZIP_WRITE_HEADER(FIL_PAGE_PREV, FIL_NULL)
1217 in the same mini-transaction. */
1218 ut_a(type == MLOG_COMP_REC_MIN_MARK || !page_zip);
1219 ptr = btr_parse_set_min_rec_mark(
1220 ptr, end_ptr, type == MLOG_COMP_REC_MIN_MARK,
1221 page, mtr);
1222 break;
1224 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1225
1226 if (NULL != (ptr = mlog_parse_index(
1227 ptr, end_ptr,
1228 type == MLOG_COMP_REC_DELETE,
1229 &index))) {
1230 ut_a(!page
1231 || (ibool)!!page_is_comp(page)
1232 == dict_table_is_comp(index->table));
1233 ptr = page_cur_parse_delete_rec(ptr, end_ptr,
1234 block, index, mtr);
1235 }
1236 break;
1238 /* Allow anything in page_type when creating a page. */
1239 ptr = ibuf_parse_bitmap_init(ptr, end_ptr, block, mtr);
1240 break;
1242 /* Allow anything in page_type when creating a page. */
1243 ptr = fsp_parse_init_file_page(ptr, end_ptr, block);
1244 break;
1245 case MLOG_WRITE_STRING:
1246 ut_ad(!page || page_type != FIL_PAGE_TYPE_ALLOCATED);
1247 ptr = mlog_parse_string(ptr, end_ptr, page, page_zip);
1248 break;
1249 case MLOG_FILE_CREATE:
1250 case MLOG_FILE_RENAME:
1251 case MLOG_FILE_DELETE:
1252 case MLOG_FILE_CREATE2:
1253 ptr = fil_op_log_parse_or_replay(ptr, end_ptr, type, 0, 0);
1254 break;
1256 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1257 ptr = page_zip_parse_write_node_ptr(ptr, end_ptr,
1258 page, page_zip);
1259 break;
1261 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1262 ptr = page_zip_parse_write_blob_ptr(ptr, end_ptr,
1263 page, page_zip);
1264 break;
1266 ut_ad(!page || page_type == FIL_PAGE_INDEX);
1267 ptr = page_zip_parse_write_header(ptr, end_ptr,
1268 page, page_zip);
1269 break;
1271 /* Allow anything in page_type when creating a page. */
1272 ptr = page_zip_parse_compress(ptr, end_ptr,
1273 page, page_zip);
1274 break;
1275 default:
1276 ptr = NULL;
1277 recv_sys->found_corrupt_log = TRUE;
1278 }
1279
1280 if (index) {
1281 dict_table_t* table = index->table;
1282
1283 dict_mem_index_free(index);
1284 dict_mem_table_free(table);
1285 }
1286
1287 return(ptr);
1288}
1289
1290/*********************************************************************/
1294UNIV_INLINE
1295ulint
1296recv_fold(
1297/*======*/
1298 ulint space,
1299 ulint page_no)
1300{
1301 return(ut_fold_ulint_pair(space, page_no));
1302}
1303
1304/*********************************************************************/
1308UNIV_INLINE
1309ulint
1310recv_hash(
1311/*======*/
1312 ulint space,
1313 ulint page_no)
1314{
1315 return(hash_calc_hash(recv_fold(space, page_no), recv_sys->addr_hash));
1316}
1317
1318/*********************************************************************/
1321static
1323recv_get_fil_addr_struct(
1324/*=====================*/
1325 ulint space,
1326 ulint page_no)
1327{
1328 recv_addr_t* recv_addr;
1329
1330 recv_addr = static_cast<recv_addr_t *>(HASH_GET_FIRST(recv_sys->addr_hash,
1331 recv_hash(space, page_no)));
1332 while (recv_addr) {
1333 if ((recv_addr->space == space)
1334 && (recv_addr->page_no == page_no)) {
1335
1336 break;
1337 }
1338
1339 recv_addr = static_cast<recv_addr_t *>(HASH_GET_NEXT(addr_hash, recv_addr));
1340 }
1341
1342 return(recv_addr);
1343}
1344
1345/*******************************************************************/
1347static
1348void
1349recv_add_to_hash_table(
1350/*===================*/
1351 byte type,
1352 ulint space,
1353 ulint page_no,
1354 byte* body,
1355 byte* rec_end,
1356 ib_uint64_t start_lsn,
1357 ib_uint64_t end_lsn)
1358{
1359 recv_t* recv;
1360 ulint len;
1361 recv_data_t* recv_data;
1362 recv_data_t** prev_field;
1363 recv_addr_t* recv_addr;
1364
1365 if (fil_tablespace_deleted_or_being_deleted_in_mem(space, -1)) {
1366 /* The tablespace does not exist any more: do not store the
1367 log record */
1368
1369 return;
1370 }
1371
1372 len = rec_end - body;
1373
1374 recv = static_cast<recv_t *>(mem_heap_alloc(recv_sys->heap, sizeof(recv_t)));
1375 recv->type = type;
1376 recv->len = rec_end - body;
1377 recv->start_lsn = start_lsn;
1378 recv->end_lsn = end_lsn;
1379
1380 recv_addr = recv_get_fil_addr_struct(space, page_no);
1381
1382 if (recv_addr == NULL) {
1383 recv_addr = static_cast<recv_addr_t *>(mem_heap_alloc(recv_sys->heap,
1384 sizeof(recv_addr_t)));
1385 recv_addr->space = space;
1386 recv_addr->page_no = page_no;
1387 recv_addr->state = RECV_NOT_PROCESSED;
1388
1389 UT_LIST_INIT(recv_addr->rec_list);
1390
1391 HASH_INSERT(recv_addr_t, addr_hash, recv_sys->addr_hash,
1392 recv_fold(space, page_no), recv_addr);
1393 recv_sys->n_addrs++;
1394#if 0
1395 fprintf(stderr, "Inserting log rec for space %lu, page %lu\n",
1396 space, page_no);
1397#endif
1398 }
1399
1400 UT_LIST_ADD_LAST(rec_list, recv_addr->rec_list, recv);
1401
1402 prev_field = &(recv->data);
1403
1404 /* Store the log record body in chunks of less than UNIV_PAGE_SIZE:
1405 recv_sys->heap grows into the buffer pool, and bigger chunks could not
1406 be allocated */
1407
1408 while (rec_end > body) {
1409
1410 len = rec_end - body;
1411
1412 if (len > RECV_DATA_BLOCK_SIZE) {
1413 len = RECV_DATA_BLOCK_SIZE;
1414 }
1415
1416 recv_data = static_cast<recv_data_t *>(mem_heap_alloc(recv_sys->heap,
1417 sizeof(recv_data_t) + len));
1418 *prev_field = recv_data;
1419
1420 memcpy(recv_data + 1, body, len);
1421
1422 prev_field = &(recv_data->next);
1423
1424 body += len;
1425 }
1426
1427 *prev_field = NULL;
1428}
1429
1430/*********************************************************************/
1432static
1433void
1434recv_data_copy_to_buf(
1435/*==================*/
1436 byte* buf,
1437 recv_t* recv)
1438{
1439 recv_data_t* recv_data;
1440 ulint part_len;
1441 ulint len;
1442
1443 len = recv->len;
1444 recv_data = recv->data;
1445
1446 while (len > 0) {
1447 if (len > RECV_DATA_BLOCK_SIZE) {
1448 part_len = RECV_DATA_BLOCK_SIZE;
1449 } else {
1450 part_len = len;
1451 }
1452
1453 ut_memcpy(buf, ((byte*)recv_data) + sizeof(recv_data_t),
1454 part_len);
1455 buf += part_len;
1456 len -= part_len;
1457
1458 recv_data = recv_data->next;
1459 }
1460}
1461
1462/************************************************************************/
1466UNIV_INTERN
1467void
1469/*===================*/
1470#ifndef UNIV_HOTBACKUP
1471 ibool just_read_in,
1474#endif /* !UNIV_HOTBACKUP */
1475 buf_block_t* block)
1476{
1477 page_t* page;
1478 page_zip_des_t* page_zip;
1479 recv_addr_t* recv_addr;
1480 recv_t* recv;
1481 byte* buf;
1482 ib_uint64_t start_lsn;
1483 ib_uint64_t end_lsn;
1484 ib_uint64_t page_lsn;
1485 ib_uint64_t page_newest_lsn;
1486 ibool modification_to_page;
1487#ifndef UNIV_HOTBACKUP
1488 ibool success;
1489#endif /* !UNIV_HOTBACKUP */
1490 mtr_t mtr;
1491
1492 mutex_enter(&(recv_sys->mutex));
1493
1494 if (recv_sys->apply_log_recs == FALSE) {
1495
1496 /* Log records should not be applied now */
1497
1498 mutex_exit(&(recv_sys->mutex));
1499
1500 return;
1501 }
1502
1503 recv_addr = recv_get_fil_addr_struct(buf_block_get_space(block),
1504 buf_block_get_page_no(block));
1505
1506 if ((recv_addr == NULL)
1507 || (recv_addr->state == RECV_BEING_PROCESSED)
1508 || (recv_addr->state == RECV_PROCESSED)) {
1509
1510 mutex_exit(&(recv_sys->mutex));
1511
1512 return;
1513 }
1514
1515#if 0
1516 fprintf(stderr, "Recovering space %lu, page %lu\n",
1518#endif
1519
1520 recv_addr->state = RECV_BEING_PROCESSED;
1521
1522 mutex_exit(&(recv_sys->mutex));
1523
1524 mtr_start(&mtr);
1525 mtr_set_log_mode(&mtr, MTR_LOG_NONE);
1526
1527 page = block->frame;
1528 page_zip = buf_block_get_page_zip(block);
1529
1530#ifndef UNIV_HOTBACKUP
1531 if (just_read_in) {
1532 /* Move the ownership of the x-latch on the page to
1533 this OS thread, so that we can acquire a second
1534 x-latch on it. This is needed for the operations to
1535 the page to pass the debug checks. */
1536
1537 rw_lock_x_lock_move_ownership(&block->lock);
1538 }
1539
1540 success = buf_page_get_known_nowait(RW_X_LATCH, block,
1542 __FILE__, __LINE__,
1543 &mtr);
1544 ut_a(success);
1545
1546 buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
1547#endif /* !UNIV_HOTBACKUP */
1548
1549 /* Read the newest modification lsn from the page */
1550 page_lsn = mach_read_from_8(page + FIL_PAGE_LSN);
1551
1552#ifndef UNIV_HOTBACKUP
1553 /* It may be that the page has been modified in the buffer
1554 pool: read the newest modification lsn there */
1555
1556 page_newest_lsn = buf_page_get_newest_modification(&block->page);
1557
1558 if (page_newest_lsn) {
1559
1560 page_lsn = page_newest_lsn;
1561 }
1562#else /* !UNIV_HOTBACKUP */
1563 /* In recovery from a backup we do not really use the buffer pool */
1564 page_newest_lsn = 0;
1565#endif /* !UNIV_HOTBACKUP */
1566
1567 modification_to_page = FALSE;
1568 start_lsn = end_lsn = 0;
1569
1570 recv = UT_LIST_GET_FIRST(recv_addr->rec_list);
1571
1572 while (recv) {
1573 end_lsn = recv->end_lsn;
1574
1575 if (recv->len > RECV_DATA_BLOCK_SIZE) {
1576 /* We have to copy the record body to a separate
1577 buffer */
1578
1579 buf = static_cast<byte *>(mem_alloc(recv->len));
1580
1581 recv_data_copy_to_buf(buf, recv);
1582 } else {
1583 buf = ((byte*)(recv->data)) + sizeof(recv_data_t);
1584 }
1585
1586 if (recv->type == MLOG_INIT_FILE_PAGE) {
1587 page_lsn = page_newest_lsn;
1588
1589 memset(FIL_PAGE_LSN + page, 0, 8);
1590 memset(UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM
1591 + page, 0, 8);
1592
1593 if (page_zip) {
1594 memset(FIL_PAGE_LSN + page_zip->data, 0, 8);
1595 }
1596 }
1597
1598 if (recv->start_lsn >= page_lsn) {
1599
1600 ib_uint64_t page_end_lsn;
1601
1602 if (!modification_to_page) {
1603
1604 modification_to_page = TRUE;
1605 start_lsn = recv->start_lsn;
1606 }
1607
1608#ifdef UNIV_DEBUG
1609 if (log_debug_writes) {
1610 fprintf(stderr,
1611 "InnoDB: Applying log rec"
1612 " type %lu len %lu"
1613 " to space %lu page no %lu\n",
1614 (ulong) recv->type, (ulong) recv->len,
1615 (ulong) recv_addr->space,
1616 (ulong) recv_addr->page_no);
1617 }
1618#endif /* UNIV_DEBUG */
1619
1620 recv_parse_or_apply_log_rec_body(recv->type, buf,
1621 buf + recv->len,
1622 block, &mtr);
1623
1624 page_end_lsn = recv->start_lsn + recv->len;
1625 mach_write_to_8(FIL_PAGE_LSN + page, page_end_lsn);
1626 mach_write_to_8(UNIV_PAGE_SIZE
1628 + page, page_end_lsn);
1629
1630 if (page_zip) {
1632 + page_zip->data, page_end_lsn);
1633 }
1634 }
1635
1636 if (recv->len > RECV_DATA_BLOCK_SIZE) {
1637 mem_free(buf);
1638 }
1639
1640 recv = UT_LIST_GET_NEXT(rec_list, recv);
1641 }
1642
1643#ifdef UNIV_ZIP_DEBUG
1644 if (fil_page_get_type(page) == FIL_PAGE_INDEX) {
1645 page_zip_des_t* page_zip = buf_block_get_page_zip(block);
1646
1647 if (page_zip) {
1648 ut_a(page_zip_validate_low(page_zip, page, FALSE));
1649 }
1650 }
1651#endif /* UNIV_ZIP_DEBUG */
1652
1653 mutex_enter(&(recv_sys->mutex));
1654
1655 if (recv_max_page_lsn < page_lsn) {
1656 recv_max_page_lsn = page_lsn;
1657 }
1658
1659 recv_addr->state = RECV_PROCESSED;
1660
1661 ut_a(recv_sys->n_addrs);
1662 recv_sys->n_addrs--;
1663
1664 mutex_exit(&(recv_sys->mutex));
1665
1666#ifndef UNIV_HOTBACKUP
1667 if (modification_to_page) {
1668 ut_a(block);
1669
1671 buf_flush_recv_note_modification(block, start_lsn, end_lsn);
1673 }
1674#endif /* !UNIV_HOTBACKUP */
1675
1676 /* Make sure that committing mtr does not change the modification
1677 lsn values of page */
1678
1679 mtr.modifications = FALSE;
1680
1681 mtr_commit(&mtr);
1682}
1683
1684#ifndef UNIV_HOTBACKUP
1685/*******************************************************************/
1689static
1690ulint
1691recv_read_in_area(
1692/*==============*/
1693 ulint space,
1694 ulint zip_size,
1695 ulint page_no)
1696{
1697 recv_addr_t* recv_addr;
1698 ulint page_nos[RECV_READ_AHEAD_AREA];
1699 ulint low_limit;
1700 ulint n;
1701
1702 low_limit = page_no - (page_no % RECV_READ_AHEAD_AREA);
1703
1704 n = 0;
1705
1706 for (page_no = low_limit; page_no < low_limit + RECV_READ_AHEAD_AREA;
1707 page_no++) {
1708 recv_addr = recv_get_fil_addr_struct(space, page_no);
1709
1710 if (recv_addr && !buf_page_peek(space, page_no)) {
1711
1712 mutex_enter(&(recv_sys->mutex));
1713
1714 if (recv_addr->state == RECV_NOT_PROCESSED) {
1715 recv_addr->state = RECV_BEING_READ;
1716
1717 page_nos[n] = page_no;
1718
1719 n++;
1720 }
1721
1722 mutex_exit(&(recv_sys->mutex));
1723 }
1724 }
1725
1726 buf_read_recv_pages(FALSE, space, zip_size, page_nos, n);
1727 /*
1728 fprintf(stderr, "Recv pages at %lu n %lu\n", page_nos[0], n);
1729 */
1730 return(n);
1731}
1732
1733/*******************************************************************/
1736UNIV_INTERN
1737void
1739/*=======================*/
1740 ibool allow_ibuf)
1749{
1750 recv_addr_t* recv_addr;
1751 ulint i;
1752 ulint n_pages;
1753 ibool has_printed = FALSE;
1754 mtr_t mtr;
1755loop:
1756 mutex_enter(&(recv_sys->mutex));
1757
1758 if (recv_sys->apply_batch_on) {
1759
1760 mutex_exit(&(recv_sys->mutex));
1761
1762 os_thread_sleep(500000);
1763
1764 goto loop;
1765 }
1766
1767 ut_ad(!allow_ibuf == mutex_own(&log_sys->mutex));
1768
1769 if (!allow_ibuf) {
1771 }
1772
1773 recv_sys->apply_log_recs = TRUE;
1774 recv_sys->apply_batch_on = TRUE;
1775
1776 for (i = 0; i < hash_get_n_cells(recv_sys->addr_hash); i++) {
1777
1778 recv_addr = static_cast<recv_addr_t *>(HASH_GET_FIRST(recv_sys->addr_hash, i));
1779
1780 while (recv_addr) {
1781 ulint space = recv_addr->space;
1782 ulint zip_size = fil_space_get_zip_size(space);
1783 ulint page_no = recv_addr->page_no;
1784
1785 if (recv_addr->state == RECV_NOT_PROCESSED) {
1786 if (!has_printed) {
1787 ut_print_timestamp(stderr);
1788 fputs(" InnoDB: Starting an"
1789 " apply batch of log records"
1790 " to the database...\n"
1791 "InnoDB: Progress in percents: ",
1792 stderr);
1793 has_printed = TRUE;
1794 }
1795
1796 mutex_exit(&(recv_sys->mutex));
1797
1798 if (buf_page_peek(space, page_no)) {
1799 buf_block_t* block;
1800
1801 mtr_start(&mtr);
1802
1803 block = buf_page_get(
1804 space, zip_size, page_no,
1805 RW_X_LATCH, &mtr);
1806 buf_block_dbg_add_level(
1807 block, SYNC_NO_ORDER_CHECK);
1808
1809 recv_recover_page(FALSE, block);
1810 mtr_commit(&mtr);
1811 } else {
1812 recv_read_in_area(space, zip_size,
1813 page_no);
1814 }
1815
1816 mutex_enter(&(recv_sys->mutex));
1817 }
1818
1819 recv_addr = static_cast<recv_addr_t *>(HASH_GET_NEXT(addr_hash, recv_addr));
1820 }
1821
1822 if (has_printed
1823 && (i * 100) / hash_get_n_cells(recv_sys->addr_hash)
1824 != ((i + 1) * 100)
1825 / hash_get_n_cells(recv_sys->addr_hash)) {
1826
1827 fprintf(stderr, "%lu ", (ulong)
1828 ((i * 100)
1829 / hash_get_n_cells(recv_sys->addr_hash)));
1830 }
1831 }
1832
1833 /* Wait until all the pages have been processed */
1834
1835 while (recv_sys->n_addrs != 0) {
1836
1837 mutex_exit(&(recv_sys->mutex));
1838
1839 os_thread_sleep(500000);
1840
1841 mutex_enter(&(recv_sys->mutex));
1842 }
1843
1844 if (has_printed) {
1845
1846 fprintf(stderr, "\n");
1847 }
1848
1849 if (!allow_ibuf) {
1850 /* Flush all the file pages to disk and invalidate them in
1851 the buffer pool */
1852
1853 ut_d(recv_no_log_write = TRUE);
1854 mutex_exit(&(recv_sys->mutex));
1855 mutex_exit(&(log_sys->mutex));
1856
1857 n_pages = buf_flush_list(ULINT_MAX, IB_ULONGLONG_MAX);
1858 ut_a(n_pages != ULINT_UNDEFINED);
1859
1860 buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST);
1861
1863
1864 mutex_enter(&(log_sys->mutex));
1865 mutex_enter(&(recv_sys->mutex));
1866 ut_d(recv_no_log_write = FALSE);
1867
1869 }
1870
1871 recv_sys->apply_log_recs = FALSE;
1872 recv_sys->apply_batch_on = FALSE;
1873
1874 recv_sys_empty_hash();
1875
1876 if (has_printed) {
1877 fprintf(stderr, "InnoDB: Apply batch completed\n");
1878 }
1879
1880 mutex_exit(&(recv_sys->mutex));
1881}
1882#else /* !UNIV_HOTBACKUP */
1883/*******************************************************************/
1885UNIV_INTERN
1886void
1887recv_apply_log_recs_for_backup(void)
1888/*================================*/
1889{
1890 recv_addr_t* recv_addr;
1891 ulint n_hash_cells;
1892 buf_block_t* block;
1893 ulint actual_size;
1894 ibool success;
1895 ulint error;
1896 ulint i;
1897
1898 recv_sys->apply_log_recs = TRUE;
1899 recv_sys->apply_batch_on = TRUE;
1900
1901 block = back_block1;
1902
1903 fputs("InnoDB: Starting an apply batch of log records"
1904 " to the database...\n"
1905 "InnoDB: Progress in percents: ", stderr);
1906
1907 n_hash_cells = hash_get_n_cells(recv_sys->addr_hash);
1908
1909 for (i = 0; i < n_hash_cells; i++) {
1910 /* The address hash table is externally chained */
1911 recv_addr = hash_get_nth_cell(recv_sys->addr_hash, i)->node;
1912
1913 while (recv_addr != NULL) {
1914
1915 ulint zip_size
1916 = fil_space_get_zip_size(recv_addr->space);
1917
1918 if (zip_size == ULINT_UNDEFINED) {
1919#if 0
1920 fprintf(stderr,
1921 "InnoDB: Warning: cannot apply"
1922 " log record to"
1923 " tablespace %lu page %lu,\n"
1924 "InnoDB: because tablespace with"
1925 " that id does not exist.\n",
1926 recv_addr->space, recv_addr->page_no);
1927#endif
1928 recv_addr->state = RECV_PROCESSED;
1929
1930 ut_a(recv_sys->n_addrs);
1931 recv_sys->n_addrs--;
1932
1933 goto skip_this_recv_addr;
1934 }
1935
1936 /* We simulate a page read made by the buffer pool, to
1937 make sure the recovery apparatus works ok. We must init
1938 the block. */
1939
1940 buf_page_init_for_backup_restore(
1941 recv_addr->space, recv_addr->page_no,
1942 zip_size, block);
1943
1944 /* Extend the tablespace's last file if the page_no
1945 does not fall inside its bounds; we assume the last
1946 file is auto-extending, and ibbackup copied the file
1947 when it still was smaller */
1948
1949 success = fil_extend_space_to_desired_size(
1950 &actual_size,
1951 recv_addr->space, recv_addr->page_no + 1);
1952 if (!success) {
1953 fprintf(stderr,
1954 "InnoDB: Fatal error: cannot extend"
1955 " tablespace %lu to hold %lu pages\n",
1956 recv_addr->space, recv_addr->page_no);
1957
1958 exit(1);
1959 }
1960
1961 /* Read the page from the tablespace file using the
1962 fil0fil.c routines */
1963
1964 if (zip_size) {
1965 error = fil_io(OS_FILE_READ, TRUE,
1966 recv_addr->space, zip_size,
1967 recv_addr->page_no, 0, zip_size,
1968 block->page.zip.data, NULL);
1969 if (error == DB_SUCCESS
1970 && !buf_zip_decompress(block, TRUE)) {
1971 exit(1);
1972 }
1973 } else {
1974 error = fil_io(OS_FILE_READ, TRUE,
1975 recv_addr->space, 0,
1976 recv_addr->page_no, 0,
1977 UNIV_PAGE_SIZE,
1978 block->frame, NULL);
1979 }
1980
1981 if (error != DB_SUCCESS) {
1982 fprintf(stderr,
1983 "InnoDB: Fatal error: cannot read"
1984 " from tablespace"
1985 " %lu page number %lu\n",
1986 (ulong) recv_addr->space,
1987 (ulong) recv_addr->page_no);
1988
1989 exit(1);
1990 }
1991
1992 /* Apply the log records to this page */
1993 recv_recover_page(FALSE, block);
1994
1995 /* Write the page back to the tablespace file using the
1996 fil0fil.c routines */
1997
1998 buf_flush_init_for_writing(
1999 block->frame, buf_block_get_page_zip(block),
2000 mach_read_from_8(block->frame + FIL_PAGE_LSN));
2001
2002 if (zip_size) {
2003 error = fil_io(OS_FILE_WRITE, TRUE,
2004 recv_addr->space, zip_size,
2005 recv_addr->page_no, 0,
2006 zip_size,
2007 block->page.zip.data, NULL);
2008 } else {
2009 error = fil_io(OS_FILE_WRITE, TRUE,
2010 recv_addr->space, 0,
2011 recv_addr->page_no, 0,
2012 UNIV_PAGE_SIZE,
2013 block->frame, NULL);
2014 }
2015skip_this_recv_addr:
2016 recv_addr = HASH_GET_NEXT(addr_hash, recv_addr);
2017 }
2018
2019 if ((100 * i) / n_hash_cells
2020 != (100 * (i + 1)) / n_hash_cells) {
2021 fprintf(stderr, "%lu ",
2022 (ulong) ((100 * i) / n_hash_cells));
2023 fflush(stderr);
2024 }
2025 }
2026
2027 recv_sys_empty_hash();
2028}
2029#endif /* !UNIV_HOTBACKUP */
2030
2031/*******************************************************************/
2034static
2035ulint
2036recv_parse_log_rec(
2037/*===============*/
2038 byte* ptr,
2039 byte* end_ptr,
2040 byte* type,
2041 ulint* space,
2042 ulint* page_no,
2043 byte** body)
2044{
2045 byte* new_ptr;
2046
2047 *body = NULL;
2048
2049 if (ptr == end_ptr) {
2050
2051 return(0);
2052 }
2053
2054 if (*ptr == MLOG_MULTI_REC_END) {
2055
2056 *type = *ptr;
2057
2058 return(1);
2059 }
2060
2061 if (*ptr == MLOG_DUMMY_RECORD) {
2062 *type = *ptr;
2063
2064 *space = ULINT_UNDEFINED - 1; /* For debugging */
2065
2066 return(1);
2067 }
2068
2069 new_ptr = mlog_parse_initial_log_record(ptr, end_ptr, type, space,
2070 page_no);
2071 *body = new_ptr;
2072
2073 if (UNIV_UNLIKELY(!new_ptr)) {
2074
2075 return(0);
2076 }
2077
2078#ifdef UNIV_LOG_LSN_DEBUG
2079 if (*type == MLOG_LSN) {
2080 ib_uint64_t lsn = (ib_uint64_t) *space << 32 | *page_no;
2081# ifdef UNIV_LOG_DEBUG
2082 ut_a(lsn == log_sys->old_lsn);
2083# else /* UNIV_LOG_DEBUG */
2084 ut_a(lsn == recv_sys->recovered_lsn);
2085# endif /* UNIV_LOG_DEBUG */
2086 }
2087#endif /* UNIV_LOG_LSN_DEBUG */
2088
2089 new_ptr = recv_parse_or_apply_log_rec_body(*type, new_ptr, end_ptr,
2090 NULL, NULL);
2091 if (UNIV_UNLIKELY(new_ptr == NULL)) {
2092
2093 return(0);
2094 }
2095
2096 if (*page_no > recv_max_parsed_page_no) {
2097 recv_max_parsed_page_no = *page_no;
2098 }
2099
2100 return(new_ptr - ptr);
2101}
2102
2103/*******************************************************/
2105static
2106ib_uint64_t
2107recv_calc_lsn_on_data_add(
2108/*======================*/
2109 ib_uint64_t lsn,
2110 ib_uint64_t len)
2112{
2113 ulint frag_len;
2114 ulint lsn_len;
2115
2116 frag_len = (((ulint) lsn) % OS_FILE_LOG_BLOCK_SIZE)
2117 - LOG_BLOCK_HDR_SIZE;
2118 ut_ad(frag_len < OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_HDR_SIZE
2119 - LOG_BLOCK_TRL_SIZE);
2120 lsn_len = (ulint) len;
2121 lsn_len += (lsn_len + frag_len)
2122 / (OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_HDR_SIZE
2123 - LOG_BLOCK_TRL_SIZE)
2124 * (LOG_BLOCK_HDR_SIZE + LOG_BLOCK_TRL_SIZE);
2125
2126 return(lsn + lsn_len);
2127}
2128
2129#ifdef UNIV_LOG_DEBUG
2130/*******************************************************/
2133static
2134void
2135recv_check_incomplete_log_recs(
2136/*===========================*/
2137 byte* ptr,
2138 ulint len)
2139{
2140 ulint i;
2141 byte type;
2142 ulint space;
2143 ulint page_no;
2144 byte* body;
2145
2146 for (i = 0; i < len; i++) {
2147 ut_a(0 == recv_parse_log_rec(ptr, ptr + i, &type, &space,
2148 &page_no, &body));
2149 }
2150}
2151#endif /* UNIV_LOG_DEBUG */
2152
2153/*******************************************************/
2155static
2156void
2157recv_report_corrupt_log(
2158/*====================*/
2159 byte* ptr,
2160 byte type,
2161 ulint space,
2162 ulint page_no)
2163{
2164 fprintf(stderr,
2165 "InnoDB: ############### CORRUPT LOG RECORD FOUND\n"
2166 "InnoDB: Log record type %lu, space id %lu, page number %lu\n"
2167 "InnoDB: Log parsing proceeded successfully up to %" PRIu64 "\n"
2168 "InnoDB: Previous log record type %lu, is multi %lu\n"
2169 "InnoDB: Recv offset %lu, prev %lu\n",
2170 (ulong) type, (ulong) space, (ulong) page_no,
2171 recv_sys->recovered_lsn,
2172 (ulong) recv_previous_parsed_rec_type,
2173 (ulong) recv_previous_parsed_rec_is_multi,
2174 (ulong) (ptr - recv_sys->buf),
2175 (ulong) recv_previous_parsed_rec_offset);
2176
2177 if ((ulint)(ptr - recv_sys->buf + 100)
2178 > recv_previous_parsed_rec_offset
2179 && (ulint)(ptr - recv_sys->buf + 100
2180 - recv_previous_parsed_rec_offset)
2181 < 200000) {
2182 fputs("InnoDB: Hex dump of corrupt log starting"
2183 " 100 bytes before the start\n"
2184 "InnoDB: of the previous log rec,\n"
2185 "InnoDB: and ending 100 bytes after the start"
2186 " of the corrupt rec:\n",
2187 stderr);
2188
2189 ut_print_buf(stderr,
2190 recv_sys->buf
2191 + recv_previous_parsed_rec_offset - 100,
2192 ptr - recv_sys->buf + 200
2193 - recv_previous_parsed_rec_offset);
2194 putc('\n', stderr);
2195 }
2196
2197#ifndef UNIV_HOTBACKUP
2198 if (!srv_force_recovery) {
2199 fputs("InnoDB: Set innodb_force_recovery"
2200 " to ignore this error.\n", stderr);
2201 ut_error;
2202 }
2203#endif /* !UNIV_HOTBACKUP */
2204
2205 fputs("InnoDB: WARNING: the log file may have been corrupt and it\n"
2206 "InnoDB: is possible that the log scan did not proceed\n"
2207 "InnoDB: far enough in recovery! Please run CHECK TABLE\n"
2208 "InnoDB: on your InnoDB tables to check that they are ok!\n"
2209 "InnoDB: If mysqld crashes after this recovery, look at\n"
2210 "InnoDB: " REFMAN "forcing-innodb-recovery.html\n"
2211 "InnoDB: about forcing recovery.\n", stderr);
2212
2213 fflush(stderr);
2214}
2215
2216/*******************************************************/
2220static
2221ibool
2222recv_parse_log_recs(
2223/*================*/
2224 ibool store_to_hash)
2227{
2228 byte* ptr;
2229 byte* end_ptr;
2230 ulint single_rec;
2231 ulint len;
2232 ulint total_len;
2233 ib_uint64_t new_recovered_lsn;
2234 ib_uint64_t old_lsn;
2235 byte type;
2236 ulint space;
2237 ulint page_no;
2238 byte* body;
2239
2240 ut_ad(mutex_own(&(log_sys->mutex)));
2241 ut_ad(recv_sys->parse_start_lsn != 0);
2242loop:
2243 ptr = recv_sys->buf + recv_sys->recovered_offset;
2244
2245 end_ptr = recv_sys->buf + recv_sys->len;
2246
2247 if (ptr == end_ptr) {
2248
2249 return(FALSE);
2250 }
2251
2252 single_rec = (ulint)*ptr & MLOG_SINGLE_REC_FLAG;
2253
2254 if (single_rec || *ptr == MLOG_DUMMY_RECORD) {
2255 /* The mtr only modified a single page, or this is a file op */
2256
2257 old_lsn = recv_sys->recovered_lsn;
2258
2259 /* Try to parse a log record, fetching its type, space id,
2260 page no, and a pointer to the body of the log record */
2261
2262 len = recv_parse_log_rec(ptr, end_ptr, &type, &space,
2263 &page_no, &body);
2264
2265 if (len == 0 || recv_sys->found_corrupt_log) {
2266 if (recv_sys->found_corrupt_log) {
2267
2268 recv_report_corrupt_log(ptr,
2269 type, space, page_no);
2270 }
2271
2272 return(FALSE);
2273 }
2274
2275 new_recovered_lsn = recv_calc_lsn_on_data_add(old_lsn, len);
2276
2277 if (new_recovered_lsn > recv_sys->scanned_lsn) {
2278 /* The log record filled a log block, and we require
2279 that also the next log block should have been scanned
2280 in */
2281
2282 return(FALSE);
2283 }
2284
2285 recv_previous_parsed_rec_type = (ulint)type;
2286 recv_previous_parsed_rec_offset = recv_sys->recovered_offset;
2287 recv_previous_parsed_rec_is_multi = 0;
2288
2289 recv_sys->recovered_offset += len;
2290 recv_sys->recovered_lsn = new_recovered_lsn;
2291
2292#ifdef UNIV_DEBUG
2293 if (log_debug_writes) {
2294 fprintf(stderr,
2295 "InnoDB: Parsed a single log rec"
2296 " type %lu len %lu space %lu page no %lu\n",
2297 (ulong) type, (ulong) len, (ulong) space,
2298 (ulong) page_no);
2299 }
2300#endif /* UNIV_DEBUG */
2301
2302 if (type == MLOG_DUMMY_RECORD) {
2303 /* Do nothing */
2304
2305 } else if (!store_to_hash) {
2306 /* In debug checking, update a replicate page
2307 according to the log record, and check that it
2308 becomes identical with the original page */
2309#ifdef UNIV_LOG_DEBUG
2310 recv_check_incomplete_log_recs(ptr, len);
2311#endif/* UNIV_LOG_DEBUG */
2312
2313 } else if (type == MLOG_FILE_CREATE
2314 || type == MLOG_FILE_CREATE2
2315 || type == MLOG_FILE_RENAME
2316 || type == MLOG_FILE_DELETE) {
2317 ut_a(space);
2318#ifdef UNIV_HOTBACKUP
2319 if (recv_replay_file_ops) {
2320
2321 /* In ibbackup --apply-log, replay an .ibd file
2322 operation, if possible; note that
2323 fil_path_to_mysql_datadir is set in ibbackup to
2324 point to the datadir we should use there */
2325
2326 if (NULL == fil_op_log_parse_or_replay(
2327 body, end_ptr, type,
2328 space, page_no)) {
2329 fprintf(stderr,
2330 "InnoDB: Error: file op"
2331 " log record of type %lu"
2332 " space %lu not complete in\n"
2333 "InnoDB: the replay phase."
2334 " Path %s\n",
2335 (ulint)type, space,
2336 (char*)(body + 2));
2337
2338 ut_error;
2339 }
2340 }
2341#endif
2342 /* In normal mysqld crash recovery we do not try to
2343 replay file operations */
2344#ifdef UNIV_LOG_LSN_DEBUG
2345 } else if (type == MLOG_LSN) {
2346 /* Do not add these records to the hash table.
2347 The page number and space id fields are misused
2348 for something else. */
2349#endif /* UNIV_LOG_LSN_DEBUG */
2350 } else {
2351 recv_add_to_hash_table(type, space, page_no, body,
2352 ptr + len, old_lsn,
2353 recv_sys->recovered_lsn);
2354 }
2355 } else {
2356 /* Check that all the records associated with the single mtr
2357 are included within the buffer */
2358
2359 total_len = 0;
2360 for (;;) {
2361 len = recv_parse_log_rec(ptr, end_ptr, &type, &space,
2362 &page_no, &body);
2363 if (len == 0 || recv_sys->found_corrupt_log) {
2364
2365 if (recv_sys->found_corrupt_log) {
2366
2367 recv_report_corrupt_log(
2368 ptr, type, space, page_no);
2369 }
2370
2371 return(FALSE);
2372 }
2373
2374 recv_previous_parsed_rec_type = (ulint)type;
2375 recv_previous_parsed_rec_offset
2376 = recv_sys->recovered_offset + total_len;
2377 recv_previous_parsed_rec_is_multi = 1;
2378
2379#ifdef UNIV_LOG_DEBUG
2380 if ((!store_to_hash) && (type != MLOG_MULTI_REC_END)) {
2381 recv_check_incomplete_log_recs(ptr, len);
2382 }
2383#endif /* UNIV_LOG_DEBUG */
2384
2385#ifdef UNIV_DEBUG
2386 if (log_debug_writes) {
2387 fprintf(stderr,
2388 "InnoDB: Parsed a multi log rec"
2389 " type %lu len %lu"
2390 " space %lu page no %lu\n",
2391 (ulong) type, (ulong) len,
2392 (ulong) space, (ulong) page_no);
2393 }
2394#endif /* UNIV_DEBUG */
2395
2396 total_len += len;
2397 ptr += len;
2398
2399 if (type == MLOG_MULTI_REC_END) {
2400
2401 /* Found the end mark for the records */
2402
2403 break;
2404 }
2405 }
2406
2407 new_recovered_lsn = recv_calc_lsn_on_data_add(
2408 recv_sys->recovered_lsn, total_len);
2409
2410 if (new_recovered_lsn > recv_sys->scanned_lsn) {
2411 /* The log record filled a log block, and we require
2412 that also the next log block should have been scanned
2413 in */
2414
2415 return(FALSE);
2416 }
2417
2418 /* Add all the records to the hash table */
2419
2420 ptr = recv_sys->buf + recv_sys->recovered_offset;
2421
2422 for (;;) {
2423 old_lsn = recv_sys->recovered_lsn;
2424 len = recv_parse_log_rec(ptr, end_ptr, &type, &space,
2425 &page_no, &body);
2426 if (recv_sys->found_corrupt_log) {
2427
2428 recv_report_corrupt_log(ptr,
2429 type, space, page_no);
2430 }
2431
2432 ut_a(len != 0);
2433 ut_a(0 == ((ulint)*ptr & MLOG_SINGLE_REC_FLAG));
2434
2435 recv_sys->recovered_offset += len;
2436 recv_sys->recovered_lsn
2437 = recv_calc_lsn_on_data_add(old_lsn, len);
2438 if (type == MLOG_MULTI_REC_END) {
2439
2440 /* Found the end mark for the records */
2441
2442 break;
2443 }
2444
2445 if (store_to_hash
2446#ifdef UNIV_LOG_LSN_DEBUG
2447 && type != MLOG_LSN
2448#endif /* UNIV_LOG_LSN_DEBUG */
2449 ) {
2450 recv_add_to_hash_table(type, space, page_no,
2451 body, ptr + len,
2452 old_lsn,
2453 new_recovered_lsn);
2454 }
2455
2456 ptr += len;
2457 }
2458 }
2459
2460 goto loop;
2461}
2462
2463/*******************************************************/
2467static
2468ibool
2469recv_sys_add_to_parsing_buf(
2470/*========================*/
2471 const byte* log_block,
2472 ib_uint64_t scanned_lsn)
2474{
2475 ulint more_len;
2476 ulint data_len;
2477 ulint start_offset;
2478 ulint end_offset;
2479
2480 ut_ad(scanned_lsn >= recv_sys->scanned_lsn);
2481
2482 if (!recv_sys->parse_start_lsn) {
2483 /* Cannot start parsing yet because no start point for
2484 it found */
2485
2486 return(FALSE);
2487 }
2488
2489 data_len = log_block_get_data_len(log_block);
2490
2491 if (recv_sys->parse_start_lsn >= scanned_lsn) {
2492
2493 return(FALSE);
2494
2495 } else if (recv_sys->scanned_lsn >= scanned_lsn) {
2496
2497 return(FALSE);
2498
2499 } else if (recv_sys->parse_start_lsn > recv_sys->scanned_lsn) {
2500 more_len = (ulint) (scanned_lsn - recv_sys->parse_start_lsn);
2501 } else {
2502 more_len = (ulint) (scanned_lsn - recv_sys->scanned_lsn);
2503 }
2504
2505 if (more_len == 0) {
2506
2507 return(FALSE);
2508 }
2509
2510 ut_ad(data_len >= more_len);
2511
2512 start_offset = data_len - more_len;
2513
2514 if (start_offset < LOG_BLOCK_HDR_SIZE) {
2515 start_offset = LOG_BLOCK_HDR_SIZE;
2516 }
2517
2518 end_offset = data_len;
2519
2520 if (end_offset > OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_TRL_SIZE) {
2521 end_offset = OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_TRL_SIZE;
2522 }
2523
2524 ut_ad(start_offset <= end_offset);
2525
2526 if (start_offset < end_offset) {
2527 ut_memcpy(recv_sys->buf + recv_sys->len,
2528 log_block + start_offset, end_offset - start_offset);
2529
2530 recv_sys->len += end_offset - start_offset;
2531
2533 }
2534
2535 return(TRUE);
2536}
2537
2538/*******************************************************/
2540static
2541void
2542recv_sys_justify_left_parsing_buf(void)
2543/*===================================*/
2544{
2545 ut_memmove(recv_sys->buf, recv_sys->buf + recv_sys->recovered_offset,
2546 recv_sys->len - recv_sys->recovered_offset);
2547
2548 recv_sys->len -= recv_sys->recovered_offset;
2549
2550 recv_sys->recovered_offset = 0;
2551}
2552
2553/*******************************************************/
2560UNIV_INTERN
2561ibool
2563/*===============*/
2564 ulint available_memory,
2566 ibool store_to_hash,
2570 const byte* buf,
2572 ulint len,
2573 ib_uint64_t start_lsn,
2574 ib_uint64_t* contiguous_lsn,
2577 ib_uint64_t* group_scanned_lsn)
2579{
2580 const byte* log_block;
2581 ulint no;
2582 ib_uint64_t scanned_lsn;
2583 ibool finished;
2584 ulint data_len;
2585 ibool more_data;
2586
2587 ut_ad(start_lsn % OS_FILE_LOG_BLOCK_SIZE == 0);
2588 ut_ad(len % OS_FILE_LOG_BLOCK_SIZE == 0);
2590 ut_a(store_to_hash <= TRUE);
2591
2592 finished = FALSE;
2593
2594 log_block = buf;
2595 scanned_lsn = start_lsn;
2596 more_data = FALSE;
2597
2598 do {
2599 no = log_block_get_hdr_no(log_block);
2600 /*
2601 fprintf(stderr, "Log block header no %lu\n", no);
2602
2603 fprintf(stderr, "Scanned lsn no %lu\n",
2604 log_block_convert_lsn_to_no(scanned_lsn));
2605 */
2606 if (no != log_block_convert_lsn_to_no(scanned_lsn)
2607 || !log_block_checksum_is_ok_or_old_format(log_block)) {
2608
2609 if (no == log_block_convert_lsn_to_no(scanned_lsn)
2610 && !log_block_checksum_is_ok_or_old_format(
2611 log_block)) {
2612 fprintf(stderr,
2613 "InnoDB: Log block no %lu at"
2614 " lsn %" PRIu64 " has\n"
2615 "InnoDB: ok header, but checksum field"
2616 " contains %lu, should be %lu\n",
2617 (ulong) no,
2618 scanned_lsn,
2619 (ulong) log_block_get_checksum(
2620 log_block),
2622 log_block));
2623 }
2624
2625 /* Garbage or an incompletely written log block */
2626
2627 finished = TRUE;
2628
2629 break;
2630 }
2631
2632 if (log_block_get_flush_bit(log_block)) {
2633 /* This block was a start of a log flush operation:
2634 we know that the previous flush operation must have
2635 been completed for all log groups before this block
2636 can have been flushed to any of the groups. Therefore,
2637 we know that log data is contiguous up to scanned_lsn
2638 in all non-corrupt log groups. */
2639
2640 if (scanned_lsn > *contiguous_lsn) {
2641 *contiguous_lsn = scanned_lsn;
2642 }
2643 }
2644
2645 data_len = log_block_get_data_len(log_block);
2646
2647 if ((store_to_hash || (data_len == OS_FILE_LOG_BLOCK_SIZE))
2648 && scanned_lsn + data_len > recv_sys->scanned_lsn
2649 && (recv_sys->scanned_checkpoint_no > 0)
2650 && (log_block_get_checkpoint_no(log_block)
2651 < recv_sys->scanned_checkpoint_no)
2652 && (recv_sys->scanned_checkpoint_no
2653 - log_block_get_checkpoint_no(log_block)
2654 > 0x80000000UL)) {
2655
2656 /* Garbage from a log buffer flush which was made
2657 before the most recent database recovery */
2658
2659 finished = TRUE;
2660#ifdef UNIV_LOG_DEBUG
2661 /* This is not really an error, but currently
2662 we stop here in the debug version: */
2663
2664 ut_error;
2665#endif
2666 break;
2667 }
2668
2669 if (!recv_sys->parse_start_lsn
2670 && (log_block_get_first_rec_group(log_block) > 0)) {
2671
2672 /* We found a point from which to start the parsing
2673 of log records */
2674
2675 recv_sys->parse_start_lsn = scanned_lsn
2676 + log_block_get_first_rec_group(log_block);
2677 recv_sys->scanned_lsn = recv_sys->parse_start_lsn;
2678 recv_sys->recovered_lsn = recv_sys->parse_start_lsn;
2679 }
2680
2681 scanned_lsn += data_len;
2682
2683 if (scanned_lsn > recv_sys->scanned_lsn) {
2684
2685 /* We have found more entries. If this scan is
2686 of startup type, we must initiate crash recovery
2687 environment before parsing these log records. */
2688
2689#ifndef UNIV_HOTBACKUP
2690 if (recv_log_scan_is_startup_type
2692
2693 fprintf(stderr,
2694 "InnoDB: Log scan progressed"
2695 " past the checkpoint lsn %" PRIu64 "\n",
2696 recv_sys->scanned_lsn);
2697 recv_init_crash_recovery();
2698 }
2699#endif /* !UNIV_HOTBACKUP */
2700
2701 /* We were able to find more log data: add it to the
2702 parsing buffer if parse_start_lsn is already
2703 non-zero */
2704
2705 if (recv_sys->len + 4 * OS_FILE_LOG_BLOCK_SIZE
2707 fprintf(stderr,
2708 "InnoDB: Error: log parsing"
2709 " buffer overflow."
2710 " Recovery may have failed!\n");
2711
2712 recv_sys->found_corrupt_log = TRUE;
2713
2714#ifndef UNIV_HOTBACKUP
2715 if (!srv_force_recovery) {
2716 fputs("InnoDB: Set"
2717 " innodb_force_recovery"
2718 " to ignore this error.\n",
2719 stderr);
2720 ut_error;
2721 }
2722#endif /* !UNIV_HOTBACKUP */
2723
2724 } else if (!recv_sys->found_corrupt_log) {
2725 more_data = recv_sys_add_to_parsing_buf(
2726 log_block, scanned_lsn);
2727 }
2728
2729 recv_sys->scanned_lsn = scanned_lsn;
2730 recv_sys->scanned_checkpoint_no
2731 = log_block_get_checkpoint_no(log_block);
2732 }
2733
2734 if (data_len < OS_FILE_LOG_BLOCK_SIZE) {
2735 /* Log data for this group ends here */
2736
2737 finished = TRUE;
2738 break;
2739 } else {
2740 log_block += OS_FILE_LOG_BLOCK_SIZE;
2741 }
2742 } while (log_block < buf + len && !finished);
2743
2744 *group_scanned_lsn = scanned_lsn;
2745
2747 || (recv_is_from_backup && !recv_is_making_a_backup)) {
2748 recv_scan_print_counter++;
2749
2750 if (finished || (recv_scan_print_counter % 80 == 0)) {
2751
2752 drizzled::errmsg_printf(drizzled::error::INFO,
2753 "InnoDB: Doing recovery: scanned up to log sequence number %" PRIu64 " ",
2754 *group_scanned_lsn);
2755 }
2756 }
2757
2758 if (more_data && !recv_sys->found_corrupt_log) {
2759 /* Try to parse more log records */
2760
2761 recv_parse_log_recs(store_to_hash);
2762
2763#ifndef UNIV_HOTBACKUP
2764 if (store_to_hash
2765 && mem_heap_get_size(recv_sys->heap) > available_memory) {
2766
2767 /* Hash table of log records has grown too big:
2768 empty it; FALSE means no ibuf operations
2769 allowed, as we cannot add new records to the
2770 log yet: they would be produced by ibuf
2771 operations */
2772
2774 }
2775#endif /* !UNIV_HOTBACKUP */
2776
2777 if (recv_sys->recovered_offset > RECV_PARSING_BUF_SIZE / 4) {
2778 /* Move parsing buffer data to the buffer start */
2779
2780 recv_sys_justify_left_parsing_buf();
2781 }
2782 }
2783
2784 return(finished);
2785}
2786
2787#ifndef UNIV_HOTBACKUP
2788/*******************************************************/
2791static
2792void
2793recv_group_scan_log_recs(
2794/*=====================*/
2795 log_group_t* group,
2796 ib_uint64_t* contiguous_lsn,
2799 ib_uint64_t* group_scanned_lsn)
2801{
2802 ibool finished;
2803 ib_uint64_t start_lsn;
2804 ib_uint64_t end_lsn;
2805
2806 finished = FALSE;
2807
2808 start_lsn = *contiguous_lsn;
2809
2810 while (!finished) {
2811 end_lsn = start_lsn + RECV_SCAN_SIZE;
2812
2813 log_group_read_log_seg(LOG_RECOVER, log_sys->buf,
2814 group, start_lsn, end_lsn);
2815
2816 finished = recv_scan_log_recs(
2819 * UNIV_PAGE_SIZE,
2820 TRUE, log_sys->buf, RECV_SCAN_SIZE,
2821 start_lsn, contiguous_lsn, group_scanned_lsn);
2822 start_lsn = end_lsn;
2823 }
2824
2825#ifdef UNIV_DEBUG
2826 if (log_debug_writes) {
2827 drizzled::errmsg_printf(drizzled::error::INFO,
2828 "InnoDB: Scanned group %lu up to log sequence number %" PRIu64 " ", (ulong) group->id, *group_scanned_lsn);
2829 }
2830#endif /* UNIV_DEBUG */
2831}
2832
2833/*******************************************************/
2836static
2837void
2838recv_init_crash_recovery(void)
2839/*==========================*/
2840{
2842
2843 recv_needed_recovery = TRUE;
2844
2845 ut_print_timestamp(stderr);
2846
2847 fprintf(stderr,
2848 " InnoDB: Database was not"
2849 " shut down normally!\n"
2850 "InnoDB: Starting crash recovery.\n");
2851
2852 fprintf(stderr,
2853 "InnoDB: Reading tablespace information"
2854 " from the .ibd files...\n");
2855
2857
2858 /* If we are using the doublewrite method, we will
2859 check if there are half-written pages in data files,
2860 and restore them from the doublewrite buffer if
2861 possible */
2862
2863 if (srv_force_recovery < SRV_FORCE_NO_LOG_REDO) {
2864
2865 fprintf(stderr,
2866 "InnoDB: Restoring possible"
2867 " half-written data pages from"
2868 " the doublewrite\n"
2869 "InnoDB: buffer...\n");
2871 }
2872}
2873
2874/********************************************************/
2880UNIV_INTERN
2881ulint
2883/*=====================================*/
2884#ifdef UNIV_LOG_ARCHIVE
2885 ulint type,
2887 ib_uint64_t limit_lsn,
2889#endif /* UNIV_LOG_ARCHIVE */
2890 ib_uint64_t min_flushed_lsn,
2892 ib_uint64_t max_flushed_lsn)
2894{
2895 log_group_t* group;
2896 log_group_t* max_cp_group;
2897 log_group_t* up_to_date_group;
2898 ulint max_cp_field;
2899 ulint log_hdr_log_block_size;
2900 ib_uint64_t checkpoint_lsn;
2901 ib_uint64_t checkpoint_no;
2902 ib_uint64_t old_scanned_lsn;
2903 ib_uint64_t group_scanned_lsn= 0;
2904 ib_uint64_t contiguous_lsn;
2905#ifdef UNIV_LOG_ARCHIVE
2906 ib_uint64_t archived_lsn;
2907#endif /* UNIV_LOG_ARCHIVE */
2908 byte* buf;
2909 boost::scoped_array<byte> log_hdr_buf_base(
2910 new byte[LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE]);
2911 byte* log_hdr_buf
2912 = (byte *)ut_align(log_hdr_buf_base.get(), OS_FILE_LOG_BLOCK_SIZE);
2913 ulint err;
2914
2915#ifdef UNIV_LOG_ARCHIVE
2916 ut_ad(type != LOG_CHECKPOINT || limit_lsn == IB_ULONGLONG_MAX);
2918# define TYPE_CHECKPOINT (type == LOG_CHECKPOINT)
2920# define LIMIT_LSN limit_lsn
2921#else /* UNIV_LOG_ARCHIVE */
2923# define TYPE_CHECKPOINT 1
2925# define LIMIT_LSN IB_ULONGLONG_MAX
2926#endif /* UNIV_LOG_ARCHIVE */
2927
2928 if (TYPE_CHECKPOINT) {
2931 }
2932
2933 if (srv_force_recovery >= SRV_FORCE_NO_LOG_REDO) {
2934 drizzled::errmsg_printf(drizzled::error::INFO,
2935 "InnoDB: The user has set SRV_FORCE_NO_LOG_REDO on Skipping log redo.");
2936
2937 return(DB_SUCCESS);
2938 }
2939
2940 recv_recovery_on = TRUE;
2941
2942 recv_sys->limit_lsn = LIMIT_LSN;
2943
2944 mutex_enter(&(log_sys->mutex));
2945
2946 /* Look for the latest checkpoint from any of the log groups */
2947
2948 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
2949
2950 if (err != DB_SUCCESS) {
2951
2952 mutex_exit(&(log_sys->mutex));
2953
2954 return(err);
2955 }
2956
2957 log_group_read_checkpoint_info(max_cp_group, max_cp_field);
2958
2959 buf = log_sys->checkpoint_buf;
2960
2961 checkpoint_lsn = mach_read_from_8(buf + LOG_CHECKPOINT_LSN);
2962 checkpoint_no = mach_read_from_8(buf + LOG_CHECKPOINT_NO);
2963#ifdef UNIV_LOG_ARCHIVE
2964 archived_lsn = mach_read_from_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN);
2965#endif /* UNIV_LOG_ARCHIVE */
2966
2967 /* Read the first log file header to print a note if this is
2968 a recovery from a restored InnoDB Hot Backup */
2969
2970 fil_io(OS_FILE_READ | OS_FILE_LOG, TRUE, max_cp_group->space_id, 0,
2971 0, 0, LOG_FILE_HDR_SIZE,
2972 log_hdr_buf, max_cp_group);
2973
2974 if (0 == ut_memcmp(log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
2975 (byte*)"ibbackup", (sizeof "ibbackup") - 1)) {
2976 /* This log file was created by ibbackup --restore: print
2977 a note to the user about it */
2978
2979 drizzled::errmsg_printf(drizzled::error::INFO,
2980 "InnoDB: The log file was created by ibbackup --apply-log at %s\n",
2981 log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP);
2982 drizzled::errmsg_printf(drizzled::error::INFO,
2983 "InnoDB: NOTE: the following crash recovery is part of a normal restore.\n");
2984
2985 /* Wipe over the label now */
2986
2987 memset(log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
2988 ' ', 4);
2989 /* Write to the log file to wipe over the label */
2990 fil_io(OS_FILE_WRITE | OS_FILE_LOG, TRUE,
2991 max_cp_group->space_id, 0,
2993 log_hdr_buf, max_cp_group);
2994 }
2995
2996 log_hdr_log_block_size
2997 = mach_read_from_4(log_hdr_buf + LOG_FILE_OS_FILE_LOG_BLOCK_SIZE);
2998 if (log_hdr_log_block_size == 0) {
2999 /* 0 means default value */
3000 log_hdr_log_block_size = 512;
3001 }
3002 if (log_hdr_log_block_size != srv_log_block_size) {
3003 drizzled::errmsg_printf(drizzled::error::ERROR,
3004 "InnoDB: Error: The block size of ib_logfile (%lu) "
3005 "is not equal to innodb_log_block_size.\n"
3006 "InnoDB: Error: Suggestion - Recreate log files.\n",
3007 log_hdr_log_block_size);
3008 return(DB_ERROR);
3009 }
3010
3011#ifdef UNIV_LOG_ARCHIVE
3012 group = UT_LIST_GET_FIRST(log_sys->log_groups);
3013
3014 while (group) {
3016 &(group->archived_file_no),
3017 &(group->archived_offset));
3018
3019 group = UT_LIST_GET_NEXT(log_groups, group);
3020 }
3021#endif /* UNIV_LOG_ARCHIVE */
3022
3023 if (TYPE_CHECKPOINT) {
3024 /* Start reading the log groups from the checkpoint lsn up. The
3025 variable contiguous_lsn contains an lsn up to which the log is
3026 known to be contiguously written to all log groups. */
3027
3028 recv_sys->parse_start_lsn = checkpoint_lsn;
3029 recv_sys->scanned_lsn = checkpoint_lsn;
3030 recv_sys->scanned_checkpoint_no = 0;
3031 recv_sys->recovered_lsn = checkpoint_lsn;
3032
3033 srv_start_lsn = checkpoint_lsn;
3034 }
3035
3036 contiguous_lsn = ut_uint64_align_down(recv_sys->scanned_lsn,
3038 if (TYPE_CHECKPOINT) {
3039 up_to_date_group = max_cp_group;
3040#ifdef UNIV_LOG_ARCHIVE
3041 } else {
3042 ulint capacity;
3043
3044 /* Try to recover the remaining part from logs: first from
3045 the logs of the archived group */
3046
3047 group = recv_sys->archive_group;
3048 capacity = log_group_get_capacity(group);
3049
3050 if (recv_sys->scanned_lsn > checkpoint_lsn + capacity
3051 || checkpoint_lsn > recv_sys->scanned_lsn + capacity) {
3052
3053 mutex_exit(&(log_sys->mutex));
3054
3055 /* The group does not contain enough log: probably
3056 an archived log file was missing or corrupt */
3057
3058 return(DB_ERROR);
3059 }
3060
3061 recv_group_scan_log_recs(group, &contiguous_lsn,
3062 &group_scanned_lsn);
3063 if (recv_sys->scanned_lsn < checkpoint_lsn) {
3064
3065 mutex_exit(&(log_sys->mutex));
3066
3067 /* The group did not contain enough log: an archived
3068 log file was missing or invalid, or the log group
3069 was corrupt */
3070
3071 return(DB_ERROR);
3072 }
3073
3074 group->scanned_lsn = group_scanned_lsn;
3075 up_to_date_group = group;
3076#endif /* UNIV_LOG_ARCHIVE */
3077 }
3078
3080
3081 group = UT_LIST_GET_FIRST(log_sys->log_groups);
3082
3083#ifdef UNIV_LOG_ARCHIVE
3084 if ((type == LOG_ARCHIVE) && (group == recv_sys->archive_group)) {
3085 group = UT_LIST_GET_NEXT(log_groups, group);
3086 }
3087#endif /* UNIV_LOG_ARCHIVE */
3088
3089 /* Set the flag to publish that we are doing startup scan. */
3090 recv_log_scan_is_startup_type = TYPE_CHECKPOINT;
3091 while (group) {
3092 old_scanned_lsn = recv_sys->scanned_lsn;
3093
3094 recv_group_scan_log_recs(group, &contiguous_lsn,
3095 &group_scanned_lsn);
3096 group->scanned_lsn = group_scanned_lsn;
3097
3098 if (old_scanned_lsn < group_scanned_lsn) {
3099 /* We found a more up-to-date group */
3100
3101 up_to_date_group = group;
3102 }
3103
3104#ifdef UNIV_LOG_ARCHIVE
3105 if ((type == LOG_ARCHIVE)
3106 && (group == recv_sys->archive_group)) {
3107 group = UT_LIST_GET_NEXT(log_groups, group);
3108 }
3109#endif /* UNIV_LOG_ARCHIVE */
3110
3111 group = UT_LIST_GET_NEXT(log_groups, group);
3112 }
3113
3114 /* Done with startup scan. Clear the flag. */
3115 recv_log_scan_is_startup_type = FALSE;
3116 if (TYPE_CHECKPOINT) {
3117 /* NOTE: we always do a 'recovery' at startup, but only if
3118 there is something wrong we will print a message to the
3119 user about recovery: */
3120
3121 if (checkpoint_lsn != max_flushed_lsn
3122 || checkpoint_lsn != min_flushed_lsn) {
3123
3124 if (checkpoint_lsn < max_flushed_lsn) {
3125 drizzled::errmsg_printf(drizzled::error::ERROR,
3126 "InnoDB: #########################"
3127 "#################################\n"
3128 "InnoDB: "
3129 "WARNING!\n"
3130 "InnoDB: The log sequence number"
3131 " in ibdata files is higher\n"
3132 "InnoDB: than the log sequence number"
3133 " in the ib_logfiles! Are you sure\n"
3134 "InnoDB: you are using the right"
3135 " ib_logfiles to start up"
3136 " the database?\n"
3137 "InnoDB: Log sequence number in"
3138 " ib_logfiles is %" PRIu64 ", log\n"
3139 "InnoDB: sequence numbers stamped"
3140 " to ibdata file headers are between\n"
3141 "InnoDB: %" PRIu64 " and %" PRIu64 ".\n"
3142 "InnoDB: #########################"
3143 "#################################\n",
3144 checkpoint_lsn,
3145 min_flushed_lsn,
3146 max_flushed_lsn);
3147 }
3148
3149 if (not recv_needed_recovery) {
3150 drizzled::errmsg_printf(drizzled::error::ERROR,
3151 "InnoDB: The log sequence number in ibdata files does not match the log sequence number in the ib_logfiles!");
3152 recv_init_crash_recovery();
3153 }
3154 }
3155
3156 if (!recv_needed_recovery) {
3157 /* Init the doublewrite buffer memory structure */
3159 }
3160 }
3161
3162 /* We currently have only one log group */
3163 if (group_scanned_lsn < checkpoint_lsn) {
3164 drizzled::errmsg_printf(drizzled::error::ERROR,
3165 "InnoDB: ERROR: We were only able to scan the log up to %" PRIu64 ", but a checkpoint was at %" PRIu64 ". "
3166 "It is possible that the database is now corrupt!",
3167 group_scanned_lsn,
3168 checkpoint_lsn);
3169 }
3170
3171 if (group_scanned_lsn < recv_max_page_lsn) {
3172 drizzled::errmsg_printf(drizzled::error::ERROR,
3173 "InnoDB: ERROR: We were only able to scan the log up to %" PRIu64 " "
3174 " but a database page a had an lsn %" PRIu64 ". It is possible that the database is now corrupt!",
3175 group_scanned_lsn,
3176 recv_max_page_lsn);
3177 }
3178
3179 if (recv_sys->recovered_lsn < checkpoint_lsn) {
3180
3181 mutex_exit(&(log_sys->mutex));
3182
3183 if (recv_sys->recovered_lsn >= LIMIT_LSN) {
3184
3185 return(DB_SUCCESS);
3186 }
3187
3188 ut_error;
3189
3190 return(DB_ERROR);
3191 }
3192
3193 /* Synchronize the uncorrupted log groups to the most up-to-date log
3194 group; we also copy checkpoint info to groups */
3195
3196 log_sys->next_checkpoint_lsn = checkpoint_lsn;
3197 log_sys->next_checkpoint_no = checkpoint_no + 1;
3198
3199#ifdef UNIV_LOG_ARCHIVE
3200 log_sys->archived_lsn = archived_lsn;
3201#endif /* UNIV_LOG_ARCHIVE */
3202
3203 recv_synchronize_groups(up_to_date_group);
3204
3205 if (!recv_needed_recovery) {
3206 ut_a(checkpoint_lsn == recv_sys->recovered_lsn);
3207 } else {
3208 srv_start_lsn = recv_sys->recovered_lsn;
3209 }
3210
3211 log_sys->lsn = recv_sys->recovered_lsn;
3212
3213 ut_memcpy(log_sys->buf, recv_sys->last_block, OS_FILE_LOG_BLOCK_SIZE);
3214
3215 log_sys->buf_free = (ulint) log_sys->lsn % OS_FILE_LOG_BLOCK_SIZE;
3216 log_sys->buf_next_to_write = log_sys->buf_free;
3217 log_sys->written_to_some_lsn = log_sys->lsn;
3218 log_sys->written_to_all_lsn = log_sys->lsn;
3219
3220 log_sys->last_checkpoint_lsn = checkpoint_lsn;
3221
3222 log_sys->next_checkpoint_no = checkpoint_no + 1;
3223
3224#ifdef UNIV_LOG_ARCHIVE
3225 if (archived_lsn == IB_ULONGLONG_MAX) {
3226
3227 log_sys->archiving_state = LOG_ARCH_OFF;
3228 }
3229#endif /* UNIV_LOG_ARCHIVE */
3230
3231 mutex_enter(&(recv_sys->mutex));
3232
3233 recv_sys->apply_log_recs = TRUE;
3234
3235 mutex_exit(&(recv_sys->mutex));
3236
3237 mutex_exit(&(log_sys->mutex));
3238
3239 recv_lsn_checks_on = TRUE;
3240
3241 /* The database is now ready to start almost normal processing of user
3242 transactions: transaction rollbacks and the application of the log
3243 records in the hash table can be run in background. */
3244
3245 return(DB_SUCCESS);
3246
3247#undef TYPE_CHECKPOINT
3248#undef LIMIT_LSN
3249}
3250
3251/********************************************************/
3253UNIV_INTERN
3254void
3256/*======================================*/
3257{
3258 /* Apply the hashed log records to the respective file pages */
3259
3260 if (srv_force_recovery < SRV_FORCE_NO_LOG_REDO) {
3261
3263 }
3264
3265#ifdef UNIV_DEBUG
3266 if (log_debug_writes) {
3267 drizzled::errmsg_printf(drizzled::error::INFO,
3268 "InnoDB: Log records applied to the database.");
3269 }
3270#endif /* UNIV_DEBUG */
3271
3272 if (recv_sys->found_corrupt_log) {
3273 drizzled::errmsg_printf(drizzled::error::ERROR,
3274 "InnoDB: WARNING: the log file may have been corrupt and it\n"
3275 "InnoDB: is possible that the log scan or parsing did not proceed\n"
3276 "InnoDB: far enough in recovery. Please run CHECK TABLE on your InnoDB tables to check that they are ok! "
3277 "InnoDB: It may be safest to recover your database from a backup!");
3278 }
3279
3280 /* Free the resources of the recovery system */
3281
3282 recv_recovery_on = FALSE;
3283
3284#ifndef UNIV_LOG_DEBUG
3285 recv_sys_debug_free();
3286#endif
3287 /* Roll back any recovered data dictionary transactions, so
3288 that the data dictionary tables will be free of any locks.
3289 The data dictionary latch should guarantee that there is at
3290 most one data dictionary transaction active at a time. */
3291 if (! srv_apply_log_only)
3293}
3294
3295/********************************************************/
3297UNIV_INTERN
3298void
3300/*===============================*/
3301{
3302 int i;
3303
3304#ifdef UNIV_SYNC_DEBUG
3305 /* Wait for a while so that created threads have time to suspend
3306 themselves before we switch the latching order checks on */
3307 os_thread_sleep(1000000);
3308
3309 /* Switch latching order checks on in sync0sync.c */
3310 sync_order_checks_on = TRUE;
3311#endif
3312 /* Drop partially created indexes. */
3314 /* Drop temporary tables. */
3316
3317 if (srv_force_recovery < SRV_FORCE_NO_TRX_UNDO) {
3318 /* Rollback the uncommitted transactions which have no user
3319 session */
3320
3322 (void *)&i, NULL);
3323 }
3324}
3325
3326/******************************************************/
3328UNIV_INTERN
3329void
3331/*============*/
3332 ib_uint64_t lsn,
3337#ifdef UNIV_LOG_ARCHIVE
3338 ulint arch_log_no,
3339#endif /* UNIV_LOG_ARCHIVE */
3340 ibool new_logs_created)
3344{
3345 log_group_t* group;
3346
3347 ut_ad(mutex_own(&(log_sys->mutex)));
3348
3349 log_sys->lsn = ut_uint64_align_up(lsn, OS_FILE_LOG_BLOCK_SIZE);
3350
3351 group = UT_LIST_GET_FIRST(log_sys->log_groups);
3352
3353 while (group) {
3354 group->lsn = log_sys->lsn;
3355 group->lsn_offset = LOG_FILE_HDR_SIZE;
3356#ifdef UNIV_LOG_ARCHIVE
3357 group->archived_file_no = arch_log_no;
3358 group->archived_offset = 0;
3359#endif /* UNIV_LOG_ARCHIVE */
3360
3361 if (!new_logs_created) {
3362 recv_truncate_group(group, group->lsn, group->lsn,
3363 group->lsn, group->lsn);
3364 }
3365
3366 group = UT_LIST_GET_NEXT(log_groups, group);
3367 }
3368
3369 log_sys->buf_next_to_write = 0;
3370 log_sys->written_to_some_lsn = log_sys->lsn;
3371 log_sys->written_to_all_lsn = log_sys->lsn;
3372
3373 log_sys->next_checkpoint_no = 0;
3374 log_sys->last_checkpoint_lsn = 0;
3375
3376#ifdef UNIV_LOG_ARCHIVE
3377 log_sys->archived_lsn = log_sys->lsn;
3378#endif /* UNIV_LOG_ARCHIVE */
3379
3380 log_block_init(log_sys->buf, log_sys->lsn);
3381 log_block_set_first_rec_group(log_sys->buf, LOG_BLOCK_HDR_SIZE);
3382
3383 log_sys->buf_free = LOG_BLOCK_HDR_SIZE;
3384 log_sys->lsn += LOG_BLOCK_HDR_SIZE;
3385
3386 mutex_exit(&(log_sys->mutex));
3387
3388 /* Reset the checkpoint fields in logs */
3389
3390 log_make_checkpoint_at(IB_ULONGLONG_MAX, TRUE);
3391 log_make_checkpoint_at(IB_ULONGLONG_MAX, TRUE);
3392
3393 mutex_enter(&(log_sys->mutex));
3394}
3395#endif /* !UNIV_HOTBACKUP */
3396
3397#ifdef UNIV_HOTBACKUP
3398/******************************************************/
3400UNIV_INTERN
3401void
3402recv_reset_log_files_for_backup(
3403/*============================*/
3404 const char* log_dir,
3405 ulint n_log_files,
3406 ulint log_file_size,
3407 ib_uint64_t lsn)
3409{
3410 os_file_t log_file;
3411 ibool success;
3412 byte* buf;
3413 ulint i;
3414 ulint log_dir_len;
3415 char name[5000];
3416 static const char ib_logfile_basename[] = "ib_logfile";
3417
3418 log_dir_len = strlen(log_dir);
3419 /* full path name of ib_logfile consists of log dir path + basename
3420 + number. This must fit in the name buffer.
3421 */
3422 ut_a(log_dir_len + strlen(ib_logfile_basename) + 11 < sizeof(name));
3423
3424 buf = ut_malloc(LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE);
3425 memset(buf, '\0', LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE);
3426
3427 for (i = 0; i < n_log_files; i++) {
3428
3429 sprintf(name, "%s%s%lu", log_dir,
3430 ib_logfile_basename, (ulong)i);
3431
3432 log_file = os_file_create_simple(innodb_file_log_key,
3433 name, OS_FILE_CREATE,
3434 OS_FILE_READ_WRITE,
3435 &success);
3436 if (not success) {
3437 drizzled::errmsg_printf(drizzled::error::ERROR,
3438 "InnoDB: Cannot create %s. Check that the file does not exist yet.\n", name);
3439
3440 exit(1);
3441 }
3442
3443 drizzled::errmsg_printf(drizzled::error::INFO,
3444 "Setting log file size to %lu %lu\n",
3445 (ulong) ut_get_high32(log_file_size),
3446 (ulong) log_file_size & 0xFFFFFFFFUL);
3447
3448 success = os_file_set_size(name, log_file,
3449 log_file_size & 0xFFFFFFFFUL,
3450 ut_get_high32(log_file_size));
3451
3452 if (not success) {
3453 drizzled::errmsg_printf(drizzled::error::ERROR,
3454 "InnoDB: Cannot set %s size to %lu %lu\n",
3455 name, (ulong) ut_get_high32(log_file_size),
3456 (ulong) (log_file_size & 0xFFFFFFFFUL));
3457 exit(1);
3458 }
3459
3460 os_file_flush(log_file);
3461 os_file_close(log_file);
3462 }
3463
3464 /* We pretend there is a checkpoint at lsn + LOG_BLOCK_HDR_SIZE */
3465
3466 log_reset_first_header_and_checkpoint(buf, lsn);
3467
3468 log_block_init_in_old_format(buf + LOG_FILE_HDR_SIZE, lsn);
3469 log_block_set_first_rec_group(buf + LOG_FILE_HDR_SIZE,
3470 LOG_BLOCK_HDR_SIZE);
3471 sprintf(name, "%s%s%lu", log_dir, ib_logfile_basename, (ulong)0);
3472
3473 log_file = os_file_create_simple(innodb_file_log_key,
3474 name, OS_FILE_OPEN,
3475 OS_FILE_READ_WRITE, &success);
3476 if (!success) {
3477 drizzled::errmsg_printf(drizzled::error::ERROR, "InnoDB: Cannot open %s.\n", name);
3478
3479 exit(1);
3480 }
3481
3482 os_file_write(name, log_file, buf, 0, 0,
3483 LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE);
3484 os_file_flush(log_file);
3485 os_file_close(log_file);
3486
3487 ut_free(buf);
3488}
3489#endif /* UNIV_HOTBACKUP */
3490
3491#ifdef UNIV_LOG_ARCHIVE
3492/* Dead code */
3493/******************************************************/
3496static
3497ibool
3498log_group_recover_from_archive_file(
3499/*================================*/
3500 log_group_t* group)
3501{
3502 os_file_t file_handle;
3503 ib_uint64_t start_lsn;
3504 ib_uint64_t file_end_lsn;
3505 ib_uint64_t dummy_lsn;
3506 ib_uint64_t scanned_lsn;
3507 ulint len;
3508 ibool ret;
3509 byte* buf;
3510 ulint read_offset;
3511 ulint file_size;
3512 ulint file_size_high;
3513 int input_char;
3514 char name[10000];
3515
3516 ut_a(0);
3517
3518try_open_again:
3519 buf = log_sys->buf;
3520
3521 /* Add the file to the archive file space; open the file */
3522
3523 log_archived_file_name_gen(name, group->id, group->archived_file_no);
3524
3525 file_handle = os_file_create(innodb_file_log_key,
3526 name, OS_FILE_OPEN,
3527 OS_FILE_LOG, OS_FILE_AIO, &ret);
3528
3529 if (ret == FALSE) {
3530ask_again:
3531 fprintf(stderr,
3532 "InnoDB: Do you want to copy additional"
3533 " archived log files\n"
3534 "InnoDB: to the directory\n");
3535 fprintf(stderr,
3536 "InnoDB: or were these all the files needed"
3537 " in recovery?\n");
3538 fprintf(stderr,
3539 "InnoDB: (Y == copy more files; N == this is all)?");
3540
3541 input_char = getchar();
3542
3543 if (input_char == (int) 'N') {
3544
3545 return(TRUE);
3546 } else if (input_char == (int) 'Y') {
3547
3548 goto try_open_again;
3549 } else {
3550 goto ask_again;
3551 }
3552 }
3553
3554 ret = os_file_get_size(file_handle, &file_size, &file_size_high);
3555 ut_a(ret);
3556
3557 ut_a(file_size_high == 0);
3558
3559 drizzled::errmsg_printf(drizzled::error::INFO,
3560 "InnoDB: Opened archived log file %s\n", name);
3561
3562 ret = os_file_close(file_handle);
3563
3564 if (file_size < LOG_FILE_HDR_SIZE) {
3565 drizzled::errmsg_printf(drizzled::error::ERROR,
3566 "InnoDB: Archive file header incomplete %s\n", name);
3567
3568 return(TRUE);
3569 }
3570
3571 ut_a(ret);
3572
3573 /* Add the archive file as a node to the space */
3574
3575 fil_node_create(name, 1 + file_size / UNIV_PAGE_SIZE,
3576 group->archive_space_id, FALSE);
3577#if RECV_SCAN_SIZE < LOG_FILE_HDR_SIZE
3578# error "RECV_SCAN_SIZE < LOG_FILE_HDR_SIZE"
3579#endif
3580
3581 /* Read the archive file header */
3582 fil_io(OS_FILE_READ | OS_FILE_LOG, TRUE, group->archive_space_id, 0, 0,
3583 LOG_FILE_HDR_SIZE, buf, NULL);
3584
3585 /* Check if the archive file header is consistent */
3586
3587 if (mach_read_from_4(buf + LOG_GROUP_ID) != group->id
3588 || mach_read_from_4(buf + LOG_FILE_NO)
3589 != group->archived_file_no) {
3590 drizzled::errmsg_printf(drizzled::error::ERROR,
3591 "InnoDB: Archive file header inconsistent %s\n", name);
3592
3593 return(TRUE);
3594 }
3595
3596 if (!mach_read_from_4(buf + LOG_FILE_ARCH_COMPLETED)) {
3597 drizzled::errmsg_printf(drizzled::error::ERROR,
3598 "InnoDB: Archive file not completely written %s\n",
3599 name);
3600
3601 return(TRUE);
3602 }
3603
3604 start_lsn = mach_read_from_8(buf + LOG_FILE_START_LSN);
3605 file_end_lsn = mach_read_from_8(buf + LOG_FILE_END_LSN);
3606
3607 if (!recv_sys->scanned_lsn) {
3608
3609 if (recv_sys->parse_start_lsn < start_lsn) {
3610 drizzled::errmsg_printf(drizzled::error::ERROR,
3611 "InnoDB: Archive log file %s starts from too big a lsn\n", name);
3612 return(TRUE);
3613 }
3614
3615 recv_sys->scanned_lsn = start_lsn;
3616 }
3617
3618 if (recv_sys->scanned_lsn != start_lsn) {
3619
3620 drizzled::errmsg_printf(drizzled::error::ERROR,
3621 "InnoDB: Archive log file %s starts from a wrong lsn\n", name);
3622 return(TRUE);
3623 }
3624
3625 read_offset = LOG_FILE_HDR_SIZE;
3626
3627 for (;;) {
3628 len = RECV_SCAN_SIZE;
3629
3630 if (read_offset + len > file_size) {
3631 len = ut_calc_align_down(file_size - read_offset,
3633 }
3634
3635 if (len == 0) {
3636
3637 break;
3638 }
3639
3640#ifdef UNIV_DEBUG
3641 if (log_debug_writes) {
3642 drizzled::errmsg_printf(drizzled::error::INFO,
3643 "InnoDB: Archive read starting at lsn %" PRIu64 ", len %lu from file %s\n",
3644 start_lsn, (ulong) len, name);
3645 }
3646#endif /* UNIV_DEBUG */
3647
3648 fil_io(OS_FILE_READ | OS_FILE_LOG, TRUE,
3649 group->archive_space_id, read_offset / UNIV_PAGE_SIZE,
3650 read_offset % UNIV_PAGE_SIZE, len, buf, NULL);
3651
3652 ret = recv_scan_log_recs(
3655 * UNIV_PAGE_SIZE, TRUE, buf, len, start_lsn,
3656 &dummy_lsn, &scanned_lsn);
3657
3658 if (scanned_lsn == file_end_lsn) {
3659
3660 return(FALSE);
3661 }
3662
3663 if (ret) {
3664 drizzled::errmsg_printf(drizzled::error::ERROR,
3665 "InnoDB: Archive log file %s does not scan right.", name);
3666 return(TRUE);
3667 }
3668
3669 read_offset += len;
3670 start_lsn += len;
3671
3672 ut_ad(start_lsn == scanned_lsn);
3673 }
3674
3675 return(FALSE);
3676}
3677
3678/********************************************************/
3681UNIV_INTERN
3682ulint
3683recv_recovery_from_archive_start(
3684/*=============================*/
3685 ib_uint64_t min_flushed_lsn,
3687 ib_uint64_t limit_lsn,
3689 ulint first_log_no)
3694{
3695 log_group_t* group;
3696 ulint group_id;
3697 ulint trunc_len;
3698 ibool ret;
3699 ulint err;
3700
3701 ut_a(0);
3702
3705
3706 recv_recovery_on = TRUE;
3707 recv_recovery_from_backup_on = TRUE;
3708
3709 recv_sys->limit_lsn = limit_lsn;
3710
3711 group_id = 0;
3712
3713 group = UT_LIST_GET_FIRST(log_sys->log_groups);
3714
3715 while (group) {
3716 if (group->id == group_id) {
3717
3718 break;
3719 }
3720
3721 group = UT_LIST_GET_NEXT(log_groups, group);
3722 }
3723
3724 if (!group) {
3725 drizzled::errmsg_printf(drizzled::error::ERROR,
3726 "InnoDB: There is no log group defined with id %lu!\n",
3727 (ulong) group_id);
3728 return(DB_ERROR);
3729 }
3730
3731 group->archived_file_no = first_log_no;
3732
3733 recv_sys->parse_start_lsn = min_flushed_lsn;
3734
3735 recv_sys->scanned_lsn = 0;
3736 recv_sys->scanned_checkpoint_no = 0;
3737 recv_sys->recovered_lsn = recv_sys->parse_start_lsn;
3738
3739 recv_sys->archive_group = group;
3740
3741 ret = FALSE;
3742
3743 mutex_enter(&(log_sys->mutex));
3744
3745 while (!ret) {
3746 ret = log_group_recover_from_archive_file(group);
3747
3748 /* Close and truncate a possible processed archive file
3749 from the file space */
3750
3751 trunc_len = UNIV_PAGE_SIZE
3752 * fil_space_get_size(group->archive_space_id);
3753 if (trunc_len > 0) {
3754 fil_space_truncate_start(group->archive_space_id,
3755 trunc_len);
3756 }
3757
3758 group->archived_file_no++;
3759 }
3760
3761 if (recv_sys->recovered_lsn < limit_lsn) {
3762
3763 if (!recv_sys->scanned_lsn) {
3764
3765 recv_sys->scanned_lsn = recv_sys->parse_start_lsn;
3766 }
3767
3768 mutex_exit(&(log_sys->mutex));
3769
3770 err = recv_recovery_from_checkpoint_start(LOG_ARCHIVE,
3771 limit_lsn,
3772 IB_ULONGLONG_MAX,
3773 IB_ULONGLONG_MAX);
3774 if (err != DB_SUCCESS) {
3775
3776 return(err);
3777 }
3778
3779 mutex_enter(&(log_sys->mutex));
3780 }
3781
3782 if (limit_lsn != IB_ULONGLONG_MAX) {
3783
3785
3786 recv_reset_logs(recv_sys->recovered_lsn, 0, FALSE);
3787 }
3788
3789 mutex_exit(&(log_sys->mutex));
3790
3791 return(DB_SUCCESS);
3792}
3793
3794/********************************************************/
3796UNIV_INTERN
3797void
3798recv_recovery_from_archive_finish(void)
3799/*===================================*/
3800{
3802
3803 recv_recovery_from_backup_on = FALSE;
3804}
3805#endif /* UNIV_LOG_ARCHIVE */
UNIV_INLINE ib_uint64_t buf_page_get_newest_modification(const buf_page_t *bpage)
UNIV_INLINE ibool buf_page_peek(ulint space, ulint offset)
UNIV_INLINE ulint buf_pool_get_curr_size(void)
#define BUF_KEEP_OLD
Definition buf0buf.h:65
UNIV_INTERN void buf_pool_invalidate(void)
Definition buf0buf.cc:4251
UNIV_INLINE ulint buf_block_get_space(const buf_block_t *block) __attribute__((pure))
#define buf_block_get_page_zip(block)
Definition buf0buf.h:1021
UNIV_INLINE ulint buf_block_get_page_no(const buf_block_t *block) __attribute__((pure))
UNIV_INLINE ulint buf_pool_get_n_pages(void)
#define buf_page_get(SP, ZS, OF, LA, MTR)
Definition buf0buf.h:303
UNIV_INTERN void buf_flush_free_flush_rbt(void)
Definition buf0flu.cc:251
UNIV_INLINE void buf_flush_recv_note_modification(buf_block_t *block, ib_uint64_t start_lsn, ib_uint64_t end_lsn)
UNIV_INTERN void buf_flush_init_flush_rbt(void)
Definition buf0flu.cc:227
@ BUF_FLUSH_LIST
Definition buf0types.h:50
struct buf_block_struct buf_block_t
Definition buf0types.h:33
UNIV_INLINE ibool dict_table_is_comp(const dict_table_t *table)
#define FIL_PAGE_TYPE
Definition fil0fil.h:99
#define FIL_PAGE_END_LSN_OLD_CHKSUM
Definition fil0fil.h:124
#define FIL_PAGE_UNDO_LOG
Definition fil0fil.h:133
#define FIL_PAGE_INDEX
Definition fil0fil.h:132
#define FIL_PAGE_LSN
Definition fil0fil.h:97
#define FIL_PAGE_TYPE_ALLOCATED
Definition fil0fil.h:137
UNIV_INTERN ulint fil_load_single_table_tablespaces(void)
Definition fil0fil.cc:3521
UNIV_INLINE hash_cell_t * hash_get_nth_cell(hash_table_t *table, ulint n)
#define HASH_INSERT(TYPE, NAME, TABLE, FOLD, DATA)
Definition hash0hash.h:101
UNIV_INLINE ulint hash_get_n_cells(hash_table_t *table)
UNIV_INLINE ulint hash_calc_hash(ulint fold, hash_table_t *table)
#define HASH_GET_NEXT(NAME, DATA)
Definition hash0hash.h:172
#define HASH_GET_FIRST(TABLE, HASH_VAL)
Definition hash0hash.h:166
UNIV_INTERN void log_group_set_fields(log_group_t *group, ib_uint64_t lsn)
Definition log0log.cc:676
UNIV_INTERN void log_group_read_checkpoint_info(log_group_t *group, ulint field)
Definition log0log.cc:1969
UNIV_INLINE ulint log_block_get_checkpoint_no(const byte *log_block)
#define log_flush_order_mutex_exit()
Definition log0log.h:949
UNIV_INTERN void log_make_checkpoint_at(ib_uint64_t lsn, ibool write_always)
Definition log0log.cc:2102
UNIV_INLINE ulint log_block_get_data_len(const byte *log_block)
UNIV_INTERN ulint log_group_get_capacity(const log_group_t *group)
Definition log0log.cc:527
UNIV_INLINE ulint log_block_get_hdr_no(const byte *log_block)
UNIV_INLINE ulint log_block_convert_lsn_to_no(ib_uint64_t lsn)
UNIV_INLINE ulint log_block_calc_checksum(const byte *block)
UNIV_INLINE void log_block_init_in_old_format(byte *log_block, ib_uint64_t lsn)
UNIV_INTERN void log_checkpoint_get_nth_group_info(const byte *buf, ulint n, ulint *file_no, ulint *offset)
Definition log0log.cc:1773
UNIV_INLINE ibool log_block_get_flush_bit(const byte *log_block)
UNIV_INLINE void log_block_init(byte *log_block, ib_uint64_t lsn)
UNIV_INLINE void log_block_set_data_len(byte *log_block, ulint len)
UNIV_INLINE ulint log_block_get_checksum(const byte *log_block)
UNIV_INTERN void log_group_write_buf(log_group_t *group, byte *buf, ulint len, ib_uint64_t start_lsn, ulint new_data_offset)
Definition log0log.cc:1255
UNIV_INLINE ulint log_block_get_first_rec_group(const byte *log_block)
UNIV_INTERN void log_group_read_log_seg(ulint type, byte *buf, log_group_t *group, ib_uint64_t start_lsn, ib_uint64_t end_lsn)
Definition log0log.cc:2229
#define log_flush_order_mutex_enter()
Definition log0log.h:945
struct log_group_struct log_group_t
Definition log0log.h:48
UNIV_INTERN void log_archived_file_name_gen(char *buf, ulint id, ulint file_no)
UNIV_INLINE void log_block_set_first_rec_group(byte *log_block, ulint offset)
UNIV_INTERN void log_groups_write_checkpoint_info(void)
Definition log0log.cc:1987
UNIV_INTERN void recv_recovery_rollback_active(void)
Definition log0recv.cc:3299
UNIV_INTERN void recv_reset_logs(ib_uint64_t lsn, ibool new_logs_created)
Definition log0recv.cc:3330
struct recv_addr_struct recv_addr_t
Definition log0recv.h:367
ibool recv_needed_recovery
Definition log0recv.cc:85
UNIV_INTERN ulint recv_recovery_from_checkpoint_start_func(ib_uint64_t min_flushed_lsn, ib_uint64_t max_flushed_lsn)
Definition log0recv.cc:2882
#define RECV_PARSING_BUF_SIZE
Definition log0recv.h:482
struct recv_struct recv_t
Definition log0recv.h:334
@ RECV_BEING_READ
Definition log0recv.h:358
@ RECV_BEING_PROCESSED
Definition log0recv.h:360
@ RECV_NOT_PROCESSED
Definition log0recv.h:356
@ RECV_PROCESSED
Definition log0recv.h:363
UNIV_INTERN void recv_sys_mem_free(void)
Definition log0recv.cc:232
struct recv_data_struct recv_data_t
Definition log0recv.h:324
struct recv_sys_struct recv_sys_t
Definition log0recv.h:380
UNIV_INTERN void recv_sys_close(void)
Definition log0recv.cc:201
UNIV_INTERN void recv_apply_hashed_log_recs(ibool allow_ibuf)
Definition log0recv.cc:1738
UNIV_INTERN void recv_recover_page_func(ibool just_read_in, buf_block_t *block)
Definition log0recv.cc:1468
recv_sys_t * recv_sys
Definition log0recv.cc:73
ulint recv_max_parsed_page_no
Definition log0recv.cc:141
UNIV_INTERN void recv_sys_var_init(void)
Definition log0recv.cc:262
UNIV_INTERN void recv_sys_create(void)
Definition log0recv.cc:180
#define recv_recovery_from_checkpoint_start(type, lim, min, max)
Definition log0recv.h:171
UNIV_INTERN ibool recv_scan_log_recs(ulint available_memory, ibool store_to_hash, const byte *buf, ulint len, ib_uint64_t start_lsn, ib_uint64_t *contiguous_lsn, ib_uint64_t *group_scanned_lsn)
Definition log0recv.cc:2562
ibool recv_no_ibuf_operations
Definition log0recv.cc:116
#define RECV_SCAN_SIZE
Definition log0recv.h:486
ibool recv_lsn_checks_on
Definition log0recv.cc:95
ulint recv_n_pool_free_frames
Definition log0recv.cc:149
UNIV_INTERN void recv_recovery_from_checkpoint_finish(void)
Definition log0recv.cc:3255
#define recv_recover_page(jri, block)
Definition log0recv.h:115
ibool recv_recovery_on
Definition log0recv.cc:77
UNIV_INTERN void recv_sys_init(ulint available_memory)
Definition log0recv.cc:303
UNIV_INLINE ib_uint64_t mach_read_from_8(const byte *b) __attribute__((nonnull
UNIV_INLINE void mach_write_to_8(byte *b, ib_uint64_t n)
UNIV_INLINE ulint mach_read_from_2(const byte *b) __attribute__((nonnull
UNIV_INLINE ulint mach_read_from_4(const byte *b) __attribute__((nonnull
#define mem_heap_create(N)
Definition mem0mem.h:91
UNIV_INLINE ulint mem_heap_get_size(mem_heap_t *heap)
#define mem_free(PTR)
Definition mem0mem.h:243
UNIV_INLINE void mem_heap_empty(mem_heap_t *heap)
#define mem_heap_create_in_buffer(N)
Definition mem0mem.h:97
UNIV_INLINE void * mem_heap_alloc(mem_heap_t *heap, ulint n)
#define mem_heap_free(heap)
Definition mem0mem.h:111
UNIV_INTERN byte * mlog_parse_string(byte *ptr, byte *end_ptr, byte *page, void *page_zip)
Definition mtr0log.cc:388
UNIV_INTERN byte * mlog_parse_initial_log_record(byte *ptr, byte *end_ptr, byte *type, ulint *space, ulint *page_no)
Definition mtr0log.cc:100
UNIV_INTERN byte * mlog_parse_index(byte *ptr, const byte *end_ptr, ibool comp, dict_index_t **index)
Definition mtr0log.cc:537
UNIV_INTERN byte * mlog_parse_nbytes(ulint type, byte *ptr, byte *end_ptr, byte *page, void *page_zip)
Definition mtr0log.cc:140
#define MLOG_REC_UPDATE_IN_PLACE
Definition mtr0mtr.h:75
#define MLOG_UNDO_HDR_DISCARD
Definition mtr0mtr.h:95
#define MLOG_COMP_REC_CLUST_DELETE_MARK
Definition mtr0mtr.h:141
#define MLOG_REC_DELETE
Definition mtr0mtr.h:77
#define MLOG_INIT_FILE_PAGE
Definition mtr0mtr.h:111
#define MLOG_2BYTES
Definition mtr0mtr.h:67
#define MLOG_DUMMY_RECORD
Definition mtr0mtr.h:126
UNIV_INTERN void mtr_commit(mtr_t *mtr) __attribute__((nonnull))
Definition mtr0mtr.cc:247
#define MLOG_COMP_PAGE_CREATE
Definition mtr0mtr.h:138
#define MLOG_FILE_RENAME
Definition mtr0mtr.h:130
#define MLOG_MULTI_REC_END
Definition mtr0mtr.h:122
#define MLOG_UNDO_ERASE_END
Definition mtr0mtr.h:91
#define MLOG_REC_INSERT
Definition mtr0mtr.h:70
#define MLOG_COMP_REC_UPDATE_IN_PLACE
Definition mtr0mtr.h:153
#define MLOG_UNDO_INSERT
Definition mtr0mtr.h:89
#define MLOG_COMP_PAGE_REORGANIZE
Definition mtr0mtr.h:168
#define MLOG_ZIP_WRITE_NODE_PTR
Definition mtr0mtr.h:171
#define MLOG_COMP_LIST_END_COPY_CREATED
Definition mtr0mtr.h:163
#define MLOG_8BYTES
Definition mtr0mtr.h:69
#define MLOG_UNDO_INIT
Definition mtr0mtr.h:93
#define MLOG_REC_MIN_MARK
Definition mtr0mtr.h:101
#define MLOG_COMP_REC_SEC_DELETE_MARK
Definition mtr0mtr.h:145
#define MLOG_PAGE_CREATE
Definition mtr0mtr.h:88
UNIV_INLINE void mtr_start(mtr_t *mtr) __attribute__((nonnull))
#define MLOG_ZIP_PAGE_COMPRESS
Definition mtr0mtr.h:179
#define MLOG_LIST_END_DELETE
Definition mtr0mtr.h:79
#define MLOG_COMP_REC_MIN_MARK
Definition mtr0mtr.h:134
#define MLOG_UNDO_HDR_REUSE
Definition mtr0mtr.h:97
#define MLOG_COMP_LIST_END_DELETE
Definition mtr0mtr.h:159
#define MLOG_1BYTE
Definition mtr0mtr.h:66
#define MLOG_SINGLE_REC_FLAG
Definition mtr0mtr.h:60
#define MLOG_FILE_CREATE
Definition mtr0mtr.h:128
#define MLOG_COMP_LIST_START_DELETE
Definition mtr0mtr.h:161
#define MLOG_REC_SEC_DELETE_MARK
Definition mtr0mtr.h:73
#define MLOG_4BYTES
Definition mtr0mtr.h:68
#define MLOG_COMP_REC_INSERT
Definition mtr0mtr.h:140
#define MLOG_IBUF_BITMAP_INIT
Definition mtr0mtr.h:105
#define MLOG_REC_CLUST_DELETE_MARK
Definition mtr0mtr.h:71
#define MLOG_ZIP_WRITE_HEADER
Definition mtr0mtr.h:177
#define MLOG_PAGE_REORGANIZE
Definition mtr0mtr.h:85
#define MLOG_UNDO_HDR_CREATE
Definition mtr0mtr.h:99
UNIV_INLINE ulint mtr_set_log_mode(mtr_t *mtr, ulint mode)
#define MLOG_FILE_DELETE
Definition mtr0mtr.h:132
#define MLOG_ZIP_WRITE_BLOB_PTR
Definition mtr0mtr.h:174
#define MLOG_COMP_REC_DELETE
Definition mtr0mtr.h:157
#define MLOG_LIST_END_COPY_CREATED
Definition mtr0mtr.h:83
#define MLOG_LIST_START_DELETE
Definition mtr0mtr.h:81
#define MLOG_FILE_CREATE2
Definition mtr0mtr.h:169
#define MLOG_WRITE_STRING
Definition mtr0mtr.h:120
int os_file_t
Definition os0file.h:87
UNIV_INTERN ibool os_file_get_size(os_file_t file, ulint *size, ulint *size_high)
Definition os0file.cc:1882
#define OS_FILE_LOG_BLOCK_SIZE
Definition os0file.h:104
UNIV_INTERN ibool os_file_set_size(const char *name, os_file_t file, ulint size, ulint size_high)
Definition os0file.cc:1953
#define OS_FILE_OPEN
Definition os0file.h:107
#define OS_FILE_READ
Definition os0file.h:142
UNIV_INTERN os_thread_t os_thread_create(os_posix_f_t start_f, void *arg, os_thread_id_t *thread_id)
Definition os0thread.cc:110
UNIV_INTERN void os_thread_sleep(ulint tm)
Definition os0thread.cc:265
UNIV_INTERN byte * page_cur_parse_insert_rec(ibool is_short, byte *ptr, byte *end_ptr, buf_block_t *block, dict_index_t *index, mtr_t *mtr)
Definition page0cur.cc:757
UNIV_INTERN byte * page_parse_copy_rec_list_to_created_page(byte *ptr, byte *end_ptr, buf_block_t *block, dict_index_t *index, mtr_t *mtr)
Definition page0cur.cc:1542
UNIV_INTERN byte * page_cur_parse_delete_rec(byte *ptr, byte *end_ptr, buf_block_t *block, dict_index_t *index, mtr_t *mtr)
Definition page0cur.cc:1809
UNIV_INTERN byte * page_parse_create(byte *ptr, byte *end_ptr, ulint comp, buf_block_t *block, mtr_t *mtr)
Definition page0page.cc:313
UNIV_INLINE ulint page_is_comp(const page_t *page)
UNIV_INTERN byte * page_parse_delete_rec_list(byte type, byte *ptr, byte *end_ptr, buf_block_t *block, dict_index_t *index, mtr_t *mtr)
Definition page0page.cc:874
struct page_zip_des_struct page_zip_des_t
Definition page0types.h:44
#define page_t
Definition page0types.h:35
UNIV_INTERN byte * page_zip_parse_write_blob_ptr(byte *ptr, byte *end_ptr, page_t *page, page_zip_des_t *page_zip)
Definition page0zip.cc:3561
UNIV_INTERN byte * page_zip_parse_write_header(byte *ptr, byte *end_ptr, page_t *page, page_zip_des_t *page_zip)
Definition page0zip.cc:4306
UNIV_INTERN void UNIV_INTERN byte * page_zip_parse_write_node_ptr(byte *ptr, byte *end_ptr, page_t *page, page_zip_des_t *page_zip)
Definition page0zip.cc:3704
UNIV_INTERN byte * page_zip_parse_compress(byte *ptr, byte *end_ptr, page_t *page, page_zip_des_t *page_zip) __attribute__((nonnull(1
UNIV_INTERN void row_merge_drop_temp_indexes(void)
UNIV_INTERN void row_mysql_drop_temp_tables(void)
@ SRV_FORCE_NO_LOG_REDO
Definition srv0srv.h:452
@ SRV_FORCE_NO_TRX_UNDO
Definition srv0srv.h:443
ulint srv_buf_pool_instances
Definition srv0srv.cc:255
ib_uint64_t srv_start_lsn
Definition srv0start.cc:99
ib_uint64_t scanned_lsn
Definition log0log.h:721
ib_uint64_t lsn
Definition log0log.h:690
byte * checkpoint_buf
Definition log0log.h:725
page_zip_t * data
Definition page0types.h:68
unsigned space
Definition log0recv.h:372
unsigned page_no
Definition log0recv.h:373
enum recv_addr_state state
Definition log0recv.h:370
recv_data_t * next
Definition log0recv.h:327
recv_data_t * data
Definition log0recv.h:339
ulint len
Definition log0recv.h:338
ib_uint64_t start_lsn
Definition log0recv.h:341
ib_uint64_t end_lsn
Definition log0recv.h:345
#define rw_lock_s_lock(M)
Definition sync0rw.h:155
UNIV_INTERN void rw_lock_x_lock_move_ownership(rw_lock_t *lock)
Definition sync0rw.cc:473
UNIV_INTERN byte * trx_undo_parse_add_undo_rec(byte *ptr, byte *end_ptr, page_t *page)
Definition trx0rec.cc:94
UNIV_INTERN byte * trx_undo_parse_erase_page_end(byte *ptr, byte *end_ptr, page_t *page, mtr_t *mtr)
Definition trx0rec.cc:1123
UNIV_INTERN void trx_rollback_or_clean_recovered(ibool all)
Definition trx0roll.cc:537
UNIV_INTERN os_thread_ret_t trx_rollback_or_clean_all_recovered(void *arg)
Definition trx0roll.cc:611
UNIV_INTERN void trx_sys_doublewrite_init_or_restore_pages(ibool restore_corrupt_pages)
Definition trx0sys.cc:430
UNIV_INTERN byte * trx_undo_parse_page_header(ulint type, byte *ptr, byte *end_ptr, page_t *page, mtr_t *mtr)
Definition trx0undo.cc:701
UNIV_INTERN byte * trx_undo_parse_page_init(byte *ptr, byte *end_ptr, page_t *page, mtr_t *mtr)
Definition trx0undo.cc:360
UNIV_INTERN byte * trx_undo_parse_discard_latest(byte *ptr, byte *end_ptr, page_t *page, mtr_t *mtr)
Definition trx0undo.cc:817
UNIV_INLINE void * ut_align(const void *ptr, ulint align_no)
UNIV_INLINE ib_uint64_t ut_uint64_align_up(ib_uint64_t n, ulint align_no)
UNIV_INLINE ib_uint64_t ut_uint64_align_down(ib_uint64_t n, ulint align_no)
#define ut_error
Definition ut0dbg.h:115
#define ut_ad(EXPR)
Definition ut0dbg.h:127
#define ut_d(EXPR)
Definition ut0dbg.h:129
#define ut_a(EXPR)
Definition ut0dbg.h:105
#define UT_LIST_GET_FIRST(BASE)
Definition ut0lst.h:223
#define UT_LIST_ADD_LAST(NAME, BASE, N)
Definition ut0lst.h:118
#define UT_LIST_GET_NEXT(NAME, N)
Definition ut0lst.h:200
#define UT_LIST_INIT(BASE)
Definition ut0lst.h:83
UNIV_INLINE void * ut_memcpy(void *dest, const void *sour, ulint n)
UNIV_INLINE void * ut_memmove(void *dest, const void *sour, ulint n)
UNIV_INLINE int ut_memcmp(const void *str1, const void *str2, ulint n)
UNIV_INTERN void ut_free(void *ptr)
Definition ut0mem.cc:294
UNIV_INTERN void * ut_malloc(ulint n)
Definition ut0mem.cc:235
UNIV_INLINE ulint ut_fold_ulint_pair(ulint n1, ulint n2) __attribute__((const))
UNIV_INLINE ulint ut_fold_binary(const byte *str, ulint len) __attribute__((pure))
UNIV_INTERN void ut_print_buf(FILE *file, const void *buf, ulint len)
Definition ut0ut.cc:436
UNIV_INTERN void ut_print_timestamp(FILE *file)
Definition ut0ut.cc:239
#define ut_calc_align_down(n, m)
Definition ut0ut.h:180
UNIV_INTERN ulint ut_get_high32(ulint a)
Definition ut0ut.cc:111