~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/log/log0recv.cc

  • Committer: David Shrewsbury
  • Date: 2011-02-28 14:33:56 UTC
  • mfrom: (2207 bootstrap)
  • mto: (2208.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2209.
  • Revision ID: shrewsbury.dave@gmail.com-20110228143356-ws2m2tp7an44egkd
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
Recovery
22
22
 
23
23
Created 9/20/1997 Heikki Tuuri
24
 
*******************************************************/
 
24
***+****************************************************/
25
25
 
26
26
#include "log0recv.h"
27
27
 
57
57
UNIV_INTERN ibool       recv_replay_file_ops    = TRUE;
58
58
#endif /* !UNIV_HOTBACKUP */
59
59
 
 
60
#include <drizzled/errmsg_print.h>
 
61
 
60
62
/** Log records are stored in the hash table in chunks at most of this size;
61
63
this must be less than UNIV_PAGE_SIZE as it is stored in the buffer pool */
62
64
#define RECV_DATA_BLOCK_SIZE    (MEM_MAX_ALLOC_IN_BUF - sizeof(recv_data_t))
358
360
        ut_ad(mutex_own(&(recv_sys->mutex)));
359
361
 
360
362
        if (recv_sys->n_addrs != 0) {
361
 
                fprintf(stderr,
362
 
                        "InnoDB: Error: %lu pages with log records"
363
 
                        " were left unprocessed!\n"
364
 
                        "InnoDB: Maximum page number with"
365
 
                        " log records on it %lu\n",
366
 
                        (ulong) recv_sys->n_addrs,
367
 
                        (ulong) recv_max_parsed_page_no);
368
 
                ut_error;
 
363
          drizzled::errmsg_printf(drizzled::error::ERROR,
 
364
                                  "InnoDB: Error: %lu pages with log records were left unprocessed!\n"
 
365
                                  "InnoDB: Maximum page number with log records on it %lu\n",
 
366
                                  (ulong) recv_sys->n_addrs,
 
367
                                  (ulong) recv_max_parsed_page_no);
 
368
          ut_error;
369
369
        }
370
370
 
371
371
        hash_table_free(recv_sys->addr_hash);
686
686
                        if (!recv_check_cp_is_consistent(buf)) {
687
687
#ifdef UNIV_DEBUG
688
688
                                if (log_debug_writes) {
689
 
                                        fprintf(stderr,
690
 
                                                "InnoDB: Checkpoint in group"
691
 
                                                " %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));
 
689
                                  drizzled::errmsg_printf(drizzled::error::INFO,
 
690
                                                          "InnoDB: Checkpoint in group %lu at %lu invalid, %lu\n",
 
691
                                                          (ulong) group->id,
 
692
                                                          (ulong) field,
 
693
                                                          (ulong) mach_read_from_4(
 
694
                                                                                   buf
 
695
                                                                                   + LOG_CHECKPOINT_CHECKSUM_1));
697
696
 
698
697
                                }
699
698
#endif /* UNIV_DEBUG */
711
710
 
712
711
#ifdef UNIV_DEBUG
713
712
                        if (log_debug_writes) {
714
 
                                fprintf(stderr,
715
 
                                        "InnoDB: Checkpoint number %lu"
716
 
                                        " found in group %lu\n",
717
 
                                        (ulong) checkpoint_no,
718
 
                                        (ulong) group->id);
 
713
                          drizzled::errmsg_printf(drizzled::error::INFO,
 
714
                                                  "InnoDB: Checkpoint number %lu found in group %lu\n",
 
715
                                                  (ulong) checkpoint_no,
 
716
                                                  (ulong) group->id);
719
717
                        }
720
718
#endif /* UNIV_DEBUG */
721
719
 
734
732
 
735
733
        if (*max_group == NULL) {
736
734
 
737
 
                fprintf(stderr,
738
 
                        "InnoDB: No valid checkpoint found.\n"
739
 
                        "InnoDB: If this error appears when you are"
740
 
                        " creating an InnoDB database,\n"
741
 
                        "InnoDB: the problem may be that during"
742
 
                        " an earlier attempt you managed\n"
743
 
                        "InnoDB: to create the InnoDB data files,"
744
 
                        " but log file creation failed.\n"
745
 
                        "InnoDB: If that is the case, please refer to\n"
746
 
                        "InnoDB: " REFMAN "error-creating-innodb.html\n");
747
 
                return(DB_ERROR);
 
735
          drizzled::errmsg_printf(drizzled::error::ERROR,
 
736
                                  "InnoDB: No valid checkpoint found. If this error appears when you are"
 
737
                                  " creating an InnoDB database,InnoDB: the problem may be that during"
 
738
                                  " an earlier attempt you managed to create the InnoDB data files,"
 
739
                                  " but log file creation failed. If that is the case, please refer to\n"
 
740
                                  "InnoDB: " REFMAN "error-creating-innodb.html\n");
 
741
          return(DB_ERROR);
748
742
        }
749
743
 
750
744
        return(DB_SUCCESS);
2746
2740
 
2747
2741
                if (finished || (recv_scan_print_counter % 80 == 0)) {
2748
2742
 
2749
 
                        fprintf(stderr,
2750
 
                                "InnoDB: Doing recovery: scanned up to"
2751
 
                                " log sequence number %"PRIu64"\n",
2752
 
                                *group_scanned_lsn);
 
2743
                  drizzled::errmsg_printf(drizzled::error::INFO,
 
2744
                                          "InnoDB: Doing recovery: scanned up to log sequence number %"PRIu64" ",
 
2745
                                          *group_scanned_lsn);
2753
2746
                }
2754
2747
        }
2755
2748
 
2822
2815
 
2823
2816
#ifdef UNIV_DEBUG
2824
2817
        if (log_debug_writes) {
2825
 
                fprintf(stderr,
2826
 
                        "InnoDB: Scanned group %lu up to"
2827
 
                        " log sequence number %"PRIu64"\n",
2828
 
                        (ulong) group->id,
2829
 
                        *group_scanned_lsn);
 
2818
          drizzled::errmsg_printf(drizzled::error::INFO,
 
2819
                                  "InnoDB: Scanned group %lu up to log sequence number %"PRIu64" ", (ulong) group->id, *group_scanned_lsn);
2830
2820
        }
2831
2821
#endif /* UNIV_DEBUG */
2832
2822
}
2928
2918
        }
2929
2919
 
2930
2920
        if (srv_force_recovery >= SRV_FORCE_NO_LOG_REDO) {
2931
 
                fprintf(stderr,
2932
 
                        "InnoDB: The user has set SRV_FORCE_NO_LOG_REDO on\n");
2933
 
                fprintf(stderr,
2934
 
                        "InnoDB: Skipping log redo\n");
 
2921
          drizzled::errmsg_printf(drizzled::error::INFO,
 
2922
                                  "InnoDB: The user has set SRV_FORCE_NO_LOG_REDO on Skipping log redo.");
2935
2923
 
2936
2924
                return(DB_SUCCESS);
2937
2925
        }
2975
2963
                /* This log file was created by ibbackup --restore: print
2976
2964
                a note to the user about it */
2977
2965
 
2978
 
                fprintf(stderr,
2979
 
                        "InnoDB: The log file was created by"
2980
 
                        " ibbackup --apply-log at\n"
2981
 
                        "InnoDB: %s\n",
2982
 
                        log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP);
2983
 
                fprintf(stderr,
2984
 
                        "InnoDB: NOTE: the following crash recovery"
2985
 
                        " is part of a normal restore.\n");
2986
 
 
2987
 
                /* Wipe over the label now */
2988
 
 
2989
 
                memset(log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
2990
 
                       ' ', 4);
2991
 
                /* Write to the log file to wipe over the label */
2992
 
                fil_io(OS_FILE_WRITE | OS_FILE_LOG, TRUE,
2993
 
                       max_cp_group->space_id, 0,
2994
 
                       0, 0, OS_FILE_LOG_BLOCK_SIZE,
2995
 
                       log_hdr_buf, max_cp_group);
 
2966
          drizzled::errmsg_printf(drizzled::error::INFO,
 
2967
                                  "InnoDB: The log file was created by ibbackup --apply-log at %s\n",
 
2968
                                  log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP);
 
2969
          drizzled::errmsg_printf(drizzled::error::INFO,
 
2970
                                  "InnoDB: NOTE: the following crash recovery is part of a normal restore.\n");
 
2971
 
 
2972
          /* Wipe over the label now */
 
2973
 
 
2974
          memset(log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
 
2975
                 ' ', 4);
 
2976
          /* Write to the log file to wipe over the label */
 
2977
          fil_io(OS_FILE_WRITE | OS_FILE_LOG, TRUE,
 
2978
                 max_cp_group->space_id, 0,
 
2979
                 0, 0, OS_FILE_LOG_BLOCK_SIZE,
 
2980
                 log_hdr_buf, max_cp_group);
2996
2981
        }
2997
2982
 
2998
2983
#ifdef UNIV_LOG_ARCHIVE
3109
3094
                    || checkpoint_lsn != min_flushed_lsn) {
3110
3095
 
3111
3096
                        if (checkpoint_lsn < max_flushed_lsn) {
3112
 
                                fprintf(stderr,
3113
 
                                        "InnoDB: #########################"
3114
 
                                        "#################################\n"
3115
 
                                        "InnoDB:                          "
3116
 
                                        "WARNING!\n"
3117
 
                                        "InnoDB: The log sequence number"
3118
 
                                        " in ibdata files is higher\n"
3119
 
                                        "InnoDB: than the log sequence number"
3120
 
                                        " in the ib_logfiles! Are you sure\n"
3121
 
                                        "InnoDB: you are using the right"
3122
 
                                        " ib_logfiles to start up"
3123
 
                                        " the database?\n"
3124
 
                                        "InnoDB: Log sequence number in"
3125
 
                                        " ib_logfiles is %"PRIu64", log\n"
3126
 
                                        "InnoDB: sequence numbers stamped"
3127
 
                                        " to ibdata file headers are between\n"
3128
 
                                        "InnoDB: %"PRIu64" and %"PRIu64".\n"
3129
 
                                        "InnoDB: #########################"
3130
 
                                        "#################################\n",
3131
 
                                        checkpoint_lsn,
3132
 
                                        min_flushed_lsn,
3133
 
                                        max_flushed_lsn);
 
3097
                          drizzled::errmsg_printf(drizzled::error::ERROR,
 
3098
                                                 "InnoDB: #########################"
 
3099
                                                 "#################################\n"
 
3100
                                                 "InnoDB:                          "
 
3101
                                                 "WARNING!\n"
 
3102
                                                 "InnoDB: The log sequence number"
 
3103
                                                 " in ibdata files is higher\n"
 
3104
                                                 "InnoDB: than the log sequence number"
 
3105
                                                 " in the ib_logfiles! Are you sure\n"
 
3106
                                                 "InnoDB: you are using the right"
 
3107
                                                 " ib_logfiles to start up"
 
3108
                                                 " the database?\n"
 
3109
                                                 "InnoDB: Log sequence number in"
 
3110
                                                 " ib_logfiles is %"PRIu64", log\n"
 
3111
                                                 "InnoDB: sequence numbers stamped"
 
3112
                                                 " to ibdata file headers are between\n"
 
3113
                                                 "InnoDB: %"PRIu64" and %"PRIu64".\n"
 
3114
                                                 "InnoDB: #########################"
 
3115
                                                 "#################################\n",
 
3116
                                                 checkpoint_lsn,
 
3117
                                                 min_flushed_lsn,
 
3118
                                                 max_flushed_lsn);
3134
3119
                        }
3135
3120
 
3136
 
                        if (!recv_needed_recovery) {
3137
 
                                fprintf(stderr,
3138
 
                                        "InnoDB: The log sequence number"
3139
 
                                        " in ibdata files does not match\n"
3140
 
                                        "InnoDB: the log sequence number"
3141
 
                                        " in the ib_logfiles!\n");
3142
 
                                recv_init_crash_recovery();
 
3121
                        if (not recv_needed_recovery) {
 
3122
                          drizzled::errmsg_printf(drizzled::error::ERROR,
 
3123
                                                 "InnoDB: The log sequence number in ibdata files does not match the log sequence number in the ib_logfiles!");
 
3124
                          recv_init_crash_recovery();
3143
3125
                        }
3144
3126
                }
3145
3127
 
3151
3133
 
3152
3134
        /* We currently have only one log group */
3153
3135
        if (group_scanned_lsn < checkpoint_lsn) {
3154
 
                ut_print_timestamp(stderr);
3155
 
                fprintf(stderr,
3156
 
                        "  InnoDB: ERROR: We were only able to scan the log"
3157
 
                        " up to\n"
3158
 
                        "InnoDB: %"PRIu64", but a checkpoint was at %"PRIu64".\n"
3159
 
                        "InnoDB: It is possible that"
3160
 
                        " the database is now corrupt!\n",
3161
 
                        group_scanned_lsn,
3162
 
                        checkpoint_lsn);
 
3136
          drizzled::errmsg_printf(drizzled::error::ERROR,
 
3137
                                  "InnoDB: ERROR: We were only able to scan the log up to %"PRIu64", but a checkpoint was at %"PRIu64". "
 
3138
                                  "It is possible that the database is now corrupt!",
 
3139
                                  group_scanned_lsn,
 
3140
                                  checkpoint_lsn);
3163
3141
        }
3164
3142
 
3165
3143
        if (group_scanned_lsn < recv_max_page_lsn) {
3166
 
                ut_print_timestamp(stderr);
3167
 
                fprintf(stderr,
3168
 
                        "  InnoDB: ERROR: We were only able to scan the log"
3169
 
                        " up to %"PRIu64"\n"
3170
 
                        "InnoDB: but a database page a had an lsn %"PRIu64"."
3171
 
                        " It is possible that the\n"
3172
 
                        "InnoDB: database is now corrupt!\n",
3173
 
                        group_scanned_lsn,
3174
 
                        recv_max_page_lsn);
 
3144
          drizzled::errmsg_printf(drizzled::error::ERROR,
 
3145
                                  "InnoDB: ERROR: We were only able to scan the log up to %"PRIu64" "
 
3146
                                  " but a database page a had an lsn %"PRIu64". It is possible that the database is now corrupt!",
 
3147
                                  group_scanned_lsn,
 
3148
                                  recv_max_page_lsn);
3175
3149
        }
3176
3150
 
3177
3151
        if (recv_sys->recovered_lsn < checkpoint_lsn) {
3262
3236
 
3263
3237
#ifdef UNIV_DEBUG
3264
3238
        if (log_debug_writes) {
3265
 
                fprintf(stderr,
3266
 
                        "InnoDB: Log records applied to the database\n");
 
3239
          drizzled::errmsg_printf(drizzled::error::INFO,
 
3240
                        "InnoDB: Log records applied to the database.");
3267
3241
        }
3268
3242
#endif /* UNIV_DEBUG */
3269
3243
 
3270
3244
        if (recv_sys->found_corrupt_log) {
3271
 
 
3272
 
                fprintf(stderr,
3273
 
                        "InnoDB: WARNING: the log file may have been"
3274
 
                        " corrupt and it\n"
3275
 
                        "InnoDB: is possible that the log scan or parsing"
3276
 
                        " did not proceed\n"
3277
 
                        "InnoDB: far enough in recovery. Please run"
3278
 
                        " CHECK TABLE\n"
3279
 
                        "InnoDB: on your InnoDB tables to check that"
3280
 
                        " they are ok!\n"
3281
 
                        "InnoDB: It may be safest to recover your"
3282
 
                        " InnoDB database from\n"
3283
 
                        "InnoDB: a backup!\n");
 
3245
          drizzled::errmsg_printf(drizzled::error::ERROR,
 
3246
                                  "InnoDB: WARNING: the log file may have been corrupt and it\n"
 
3247
                                  "InnoDB: is possible that the log scan or parsing did not proceed\n"
 
3248
                                  "InnoDB: far enough in recovery. Please run CHECK TABLE on your InnoDB tables to check that they are ok! "
 
3249
                                  "InnoDB: It may be safest to recover your database from a backup!");
3284
3250
        }
3285
3251
 
3286
3252
        /* Free the resources of the recovery system */
3438
3404
                                                 name, OS_FILE_CREATE,
3439
3405
                                                 OS_FILE_READ_WRITE,
3440
3406
                                                 &success);
3441
 
                if (!success) {
3442
 
                        fprintf(stderr,
3443
 
                                "InnoDB: Cannot create %s. Check that"
3444
 
                                " the file does not exist yet.\n", name);
 
3407
                if (not success) {
 
3408
                  drizzled::errmsg_printf(drizzled::error::ERROR,
 
3409
                                          "InnoDB: Cannot create %s. Check that the file does not exist yet.\n", name);
3445
3410
 
3446
3411
                        exit(1);
3447
3412
                }
3448
3413
 
3449
 
                fprintf(stderr,
3450
 
                        "Setting log file size to %lu %lu\n",
3451
 
                        (ulong) ut_get_high32(log_file_size),
3452
 
                        (ulong) log_file_size & 0xFFFFFFFFUL);
 
3414
                drizzled::errmsg_printf(drizzled::error::INFO,
 
3415
                                        "Setting log file size to %lu %lu\n",
 
3416
                                        (ulong) ut_get_high32(log_file_size),
 
3417
                                        (ulong) log_file_size & 0xFFFFFFFFUL);
3453
3418
 
3454
3419
                success = os_file_set_size(name, log_file,
3455
3420
                                           log_file_size & 0xFFFFFFFFUL,
3456
3421
                                           ut_get_high32(log_file_size));
3457
3422
 
3458
 
                if (!success) {
3459
 
                        fprintf(stderr,
3460
 
                                "InnoDB: Cannot set %s size to %lu %lu\n",
3461
 
                                name, (ulong) ut_get_high32(log_file_size),
3462
 
                                (ulong) (log_file_size & 0xFFFFFFFFUL));
3463
 
                        exit(1);
 
3423
                if (not success) {
 
3424
                  drizzled::errmsg_printf(drizzled::error::ERROR,
 
3425
                                          "InnoDB: Cannot set %s size to %lu %lu\n",
 
3426
                                          name, (ulong) ut_get_high32(log_file_size),
 
3427
                                          (ulong) (log_file_size & 0xFFFFFFFFUL));
 
3428
                  exit(1);
3464
3429
                }
3465
3430
 
3466
3431
                os_file_flush(log_file);
3480
3445
                                         name, OS_FILE_OPEN,
3481
3446
                                         OS_FILE_READ_WRITE, &success);
3482
3447
        if (!success) {
3483
 
                fprintf(stderr, "InnoDB: Cannot open %s.\n", name);
 
3448
          drizzled::errmsg_printf(drizzled::error::ERROR, "InnoDB: Cannot open %s.\n", name);
3484
3449
 
3485
 
                exit(1);
3486
 
        }
 
3450
          exit(1);
 
3451
        }
3487
3452
 
3488
3453
        os_file_write(name, log_file, buf, 0, 0,
3489
3454
                      LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE);
3562
3527
 
3563
3528
        ut_a(file_size_high == 0);
3564
3529
 
3565
 
        fprintf(stderr, "InnoDB: Opened archived log file %s\n", name);
 
3530
        drizzled::errmsg_printf(drizzled::error::INFO,
 
3531
                                "InnoDB: Opened archived log file %s\n", name);
3566
3532
 
3567
3533
        ret = os_file_close(file_handle);
3568
3534
 
3569
3535
        if (file_size < LOG_FILE_HDR_SIZE) {
3570
 
                fprintf(stderr,
3571
 
                        "InnoDB: Archive file header incomplete %s\n", name);
 
3536
          drizzled::errmsg_printf(drizzled::error::ERROR,
 
3537
                                  "InnoDB: Archive file header incomplete %s\n", name);
3572
3538
 
3573
3539
                return(TRUE);
3574
3540
        }
3592
3558
        if (mach_read_from_4(buf + LOG_GROUP_ID) != group->id
3593
3559
            || mach_read_from_4(buf + LOG_FILE_NO)
3594
3560
            != group->archived_file_no) {
3595
 
                fprintf(stderr,
 
3561
          drizzled::errmsg_printf(drizzled::error::ERROR,
3596
3562
                        "InnoDB: Archive file header inconsistent %s\n", name);
3597
3563
 
3598
3564
                return(TRUE);
3599
3565
        }
3600
3566
 
3601
3567
        if (!mach_read_from_4(buf + LOG_FILE_ARCH_COMPLETED)) {
3602
 
                fprintf(stderr,
 
3568
          drizzled::errmsg_printf(drizzled::error::ERROR,
3603
3569
                        "InnoDB: Archive file not completely written %s\n",
3604
3570
                        name);
3605
3571
 
3612
3578
        if (!recv_sys->scanned_lsn) {
3613
3579
 
3614
3580
                if (recv_sys->parse_start_lsn < start_lsn) {
3615
 
                        fprintf(stderr,
3616
 
                                "InnoDB: Archive log file %s"
3617
 
                                " starts from too big a lsn\n",
3618
 
                                name);
3619
 
                        return(TRUE);
 
3581
                  drizzled::errmsg_printf(drizzled::error::ERROR,
 
3582
                                          "InnoDB: Archive log file %s starts from too big a lsn\n", name);
 
3583
                  return(TRUE);
3620
3584
                }
3621
3585
 
3622
3586
                recv_sys->scanned_lsn = start_lsn;
3624
3588
 
3625
3589
        if (recv_sys->scanned_lsn != start_lsn) {
3626
3590
 
3627
 
                fprintf(stderr,
3628
 
                        "InnoDB: Archive log file %s starts from"
3629
 
                        " a wrong lsn\n",
3630
 
                        name);
3631
 
                return(TRUE);
 
3591
          drizzled::errmsg_printf(drizzled::error::ERROR,
 
3592
                                  "InnoDB: Archive log file %s starts from a wrong lsn\n", name);
 
3593
          return(TRUE);
3632
3594
        }
3633
3595
 
3634
3596
        read_offset = LOG_FILE_HDR_SIZE;
3648
3610
 
3649
3611
#ifdef UNIV_DEBUG
3650
3612
                if (log_debug_writes) {
3651
 
                        fprintf(stderr,
3652
 
                                "InnoDB: Archive read starting at"
3653
 
                                " lsn %"PRIu64", len %lu from file %s\n",
3654
 
                                start_lsn,
3655
 
                                (ulong) len, name);
 
3613
                  drizzled::errmsg_printf(drizzled::error::INFO,
 
3614
                                          "InnoDB: Archive read starting at lsn %"PRIu64", len %lu from file %s\n",
 
3615
                                          start_lsn, (ulong) len, name);
3656
3616
                }
3657
3617
#endif /* UNIV_DEBUG */
3658
3618
 
3672
3632
                }
3673
3633
 
3674
3634
                if (ret) {
3675
 
                        fprintf(stderr,
3676
 
                                "InnoDB: Archive log file %s"
3677
 
                                " does not scan right\n",
3678
 
                                name);
3679
 
                        return(TRUE);
 
3635
                  drizzled::errmsg_printf(drizzled::error::ERROR,
 
3636
                                          "InnoDB: Archive log file %s does not scan right.", name);
 
3637
                  return(TRUE);
3680
3638
                }
3681
3639
 
3682
3640
                read_offset += len;
3735
3693
        }
3736
3694
 
3737
3695
        if (!group) {
3738
 
                fprintf(stderr,
 
3696
          drizzled::errmsg_printf(drizzled::error::ERROR,
3739
3697
                        "InnoDB: There is no log group defined with id %lu!\n",
3740
3698
                        (ulong) group_id);
3741
3699
                return(DB_ERROR);