~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

edit

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
 
 
62
60
/** Log records are stored in the hash table in chunks at most of this size;
63
61
this must be less than UNIV_PAGE_SIZE as it is stored in the buffer pool */
64
62
#define RECV_DATA_BLOCK_SIZE    (MEM_MAX_ALLOC_IN_BUF - sizeof(recv_data_t))
360
358
        ut_ad(mutex_own(&(recv_sys->mutex)));
361
359
 
362
360
        if (recv_sys->n_addrs != 0) {
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;
 
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;
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
 
                                  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));
 
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));
696
697
 
697
698
                                }
698
699
#endif /* UNIV_DEBUG */
710
711
 
711
712
#ifdef UNIV_DEBUG
712
713
                        if (log_debug_writes) {
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);
 
714
                                fprintf(stderr,
 
715
                                        "InnoDB: Checkpoint number %lu"
 
716
                                        " found in group %lu\n",
 
717
                                        (ulong) checkpoint_no,
 
718
                                        (ulong) group->id);
717
719
                        }
718
720
#endif /* UNIV_DEBUG */
719
721
 
732
734
 
733
735
        if (*max_group == NULL) {
734
736
 
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);
 
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);
742
748
        }
743
749
 
744
750
        return(DB_SUCCESS);
2740
2746
 
2741
2747
                if (finished || (recv_scan_print_counter % 80 == 0)) {
2742
2748
 
2743
 
                  drizzled::errmsg_printf(drizzled::error::INFO,
2744
 
                                          "InnoDB: Doing recovery: scanned up to log sequence number %"PRIu64" ",
2745
 
                                          *group_scanned_lsn);
 
2749
                        fprintf(stderr,
 
2750
                                "InnoDB: Doing recovery: scanned up to"
 
2751
                                " log sequence number %"PRIu64"\n",
 
2752
                                *group_scanned_lsn);
2746
2753
                }
2747
2754
        }
2748
2755
 
2815
2822
 
2816
2823
#ifdef UNIV_DEBUG
2817
2824
        if (log_debug_writes) {
2818
 
          drizzled::errmsg_printf(drizzled::error::INFO,
2819
 
                                  "InnoDB: Scanned group %lu up to log sequence number %"PRIu64" ", (ulong) group->id, *group_scanned_lsn);
 
2825
                fprintf(stderr,
 
2826
                        "InnoDB: Scanned group %lu up to"
 
2827
                        " log sequence number %"PRIu64"\n",
 
2828
                        (ulong) group->id,
 
2829
                        *group_scanned_lsn);
2820
2830
        }
2821
2831
#endif /* UNIV_DEBUG */
2822
2832
}
2918
2928
        }
2919
2929
 
2920
2930
        if (srv_force_recovery >= SRV_FORCE_NO_LOG_REDO) {
2921
 
          drizzled::errmsg_printf(drizzled::error::INFO,
2922
 
                                  "InnoDB: The user has set SRV_FORCE_NO_LOG_REDO on Skipping 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");
2923
2935
 
2924
2936
                return(DB_SUCCESS);
2925
2937
        }
2963
2975
                /* This log file was created by ibbackup --restore: print
2964
2976
                a note to the user about it */
2965
2977
 
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);
 
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);
2981
2996
        }
2982
2997
 
2983
2998
#ifdef UNIV_LOG_ARCHIVE
3094
3109
                    || checkpoint_lsn != min_flushed_lsn) {
3095
3110
 
3096
3111
                        if (checkpoint_lsn < 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);
 
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);
3119
3134
                        }
3120
3135
 
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();
 
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();
3125
3143
                        }
3126
3144
                }
3127
3145
 
3133
3151
 
3134
3152
        /* We currently have only one log group */
3135
3153
        if (group_scanned_lsn < 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);
 
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);
3141
3163
        }
3142
3164
 
3143
3165
        if (group_scanned_lsn < 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);
 
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);
3149
3175
        }
3150
3176
 
3151
3177
        if (recv_sys->recovered_lsn < checkpoint_lsn) {
3236
3262
 
3237
3263
#ifdef UNIV_DEBUG
3238
3264
        if (log_debug_writes) {
3239
 
          drizzled::errmsg_printf(drizzled::error::INFO,
3240
 
                        "InnoDB: Log records applied to the database.");
 
3265
                fprintf(stderr,
 
3266
                        "InnoDB: Log records applied to the database\n");
3241
3267
        }
3242
3268
#endif /* UNIV_DEBUG */
3243
3269
 
 
3270
        if (recv_needed_recovery) {
 
3271
                trx_sys_print_mysql_master_log_pos();
 
3272
                trx_sys_print_mysql_binlog_offset();
 
3273
        }
 
3274
 
3244
3275
        if (recv_sys->found_corrupt_log) {
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!");
 
3276
 
 
3277
                fprintf(stderr,
 
3278
                        "InnoDB: WARNING: the log file may have been"
 
3279
                        " corrupt and it\n"
 
3280
                        "InnoDB: is possible that the log scan or parsing"
 
3281
                        " did not proceed\n"
 
3282
                        "InnoDB: far enough in recovery. Please run"
 
3283
                        " CHECK TABLE\n"
 
3284
                        "InnoDB: on your InnoDB tables to check that"
 
3285
                        " they are ok!\n"
 
3286
                        "InnoDB: It may be safest to recover your"
 
3287
                        " InnoDB database from\n"
 
3288
                        "InnoDB: a backup!\n");
3250
3289
        }
3251
3290
 
3252
3291
        /* Free the resources of the recovery system */
3404
3443
                                                 name, OS_FILE_CREATE,
3405
3444
                                                 OS_FILE_READ_WRITE,
3406
3445
                                                 &success);
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);
 
3446
                if (!success) {
 
3447
                        fprintf(stderr,
 
3448
                                "InnoDB: Cannot create %s. Check that"
 
3449
                                " the file does not exist yet.\n", name);
3410
3450
 
3411
3451
                        exit(1);
3412
3452
                }
3413
3453
 
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);
 
3454
                fprintf(stderr,
 
3455
                        "Setting log file size to %lu %lu\n",
 
3456
                        (ulong) ut_get_high32(log_file_size),
 
3457
                        (ulong) log_file_size & 0xFFFFFFFFUL);
3418
3458
 
3419
3459
                success = os_file_set_size(name, log_file,
3420
3460
                                           log_file_size & 0xFFFFFFFFUL,
3421
3461
                                           ut_get_high32(log_file_size));
3422
3462
 
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);
 
3463
                if (!success) {
 
3464
                        fprintf(stderr,
 
3465
                                "InnoDB: Cannot set %s size to %lu %lu\n",
 
3466
                                name, (ulong) ut_get_high32(log_file_size),
 
3467
                                (ulong) (log_file_size & 0xFFFFFFFFUL));
 
3468
                        exit(1);
3429
3469
                }
3430
3470
 
3431
3471
                os_file_flush(log_file);
3445
3485
                                         name, OS_FILE_OPEN,
3446
3486
                                         OS_FILE_READ_WRITE, &success);
3447
3487
        if (!success) {
3448
 
          drizzled::errmsg_printf(drizzled::error::ERROR, "InnoDB: Cannot open %s.\n", name);
 
3488
                fprintf(stderr, "InnoDB: Cannot open %s.\n", name);
3449
3489
 
3450
 
          exit(1);
3451
 
        }
 
3490
                exit(1);
 
3491
        }
3452
3492
 
3453
3493
        os_file_write(name, log_file, buf, 0, 0,
3454
3494
                      LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE);
3527
3567
 
3528
3568
        ut_a(file_size_high == 0);
3529
3569
 
3530
 
        drizzled::errmsg_printf(drizzled::error::INFO,
3531
 
                                "InnoDB: Opened archived log file %s\n", name);
 
3570
        fprintf(stderr, "InnoDB: Opened archived log file %s\n", name);
3532
3571
 
3533
3572
        ret = os_file_close(file_handle);
3534
3573
 
3535
3574
        if (file_size < LOG_FILE_HDR_SIZE) {
3536
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
3537
 
                                  "InnoDB: Archive file header incomplete %s\n", name);
 
3575
                fprintf(stderr,
 
3576
                        "InnoDB: Archive file header incomplete %s\n", name);
3538
3577
 
3539
3578
                return(TRUE);
3540
3579
        }
3558
3597
        if (mach_read_from_4(buf + LOG_GROUP_ID) != group->id
3559
3598
            || mach_read_from_4(buf + LOG_FILE_NO)
3560
3599
            != group->archived_file_no) {
3561
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
 
3600
                fprintf(stderr,
3562
3601
                        "InnoDB: Archive file header inconsistent %s\n", name);
3563
3602
 
3564
3603
                return(TRUE);
3565
3604
        }
3566
3605
 
3567
3606
        if (!mach_read_from_4(buf + LOG_FILE_ARCH_COMPLETED)) {
3568
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
 
3607
                fprintf(stderr,
3569
3608
                        "InnoDB: Archive file not completely written %s\n",
3570
3609
                        name);
3571
3610
 
3578
3617
        if (!recv_sys->scanned_lsn) {
3579
3618
 
3580
3619
                if (recv_sys->parse_start_lsn < start_lsn) {
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
                        fprintf(stderr,
 
3621
                                "InnoDB: Archive log file %s"
 
3622
                                " starts from too big a lsn\n",
 
3623
                                name);
 
3624
                        return(TRUE);
3584
3625
                }
3585
3626
 
3586
3627
                recv_sys->scanned_lsn = start_lsn;
3588
3629
 
3589
3630
        if (recv_sys->scanned_lsn != start_lsn) {
3590
3631
 
3591
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
3592
 
                                  "InnoDB: Archive log file %s starts from a wrong lsn\n", name);
3593
 
          return(TRUE);
 
3632
                fprintf(stderr,
 
3633
                        "InnoDB: Archive log file %s starts from"
 
3634
                        " a wrong lsn\n",
 
3635
                        name);
 
3636
                return(TRUE);
3594
3637
        }
3595
3638
 
3596
3639
        read_offset = LOG_FILE_HDR_SIZE;
3610
3653
 
3611
3654
#ifdef UNIV_DEBUG
3612
3655
                if (log_debug_writes) {
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
                        fprintf(stderr,
 
3657
                                "InnoDB: Archive read starting at"
 
3658
                                " lsn %"PRIu64", len %lu from file %s\n",
 
3659
                                start_lsn,
 
3660
                                (ulong) len, name);
3616
3661
                }
3617
3662
#endif /* UNIV_DEBUG */
3618
3663
 
3632
3677
                }
3633
3678
 
3634
3679
                if (ret) {
3635
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
3636
 
                                          "InnoDB: Archive log file %s does not scan right.", name);
3637
 
                  return(TRUE);
 
3680
                        fprintf(stderr,
 
3681
                                "InnoDB: Archive log file %s"
 
3682
                                " does not scan right\n",
 
3683
                                name);
 
3684
                        return(TRUE);
3638
3685
                }
3639
3686
 
3640
3687
                read_offset += len;
3693
3740
        }
3694
3741
 
3695
3742
        if (!group) {
3696
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
 
3743
                fprintf(stderr,
3697
3744
                        "InnoDB: There is no log group defined with id %lu!\n",
3698
3745
                        (ulong) group_id);
3699
3746
                return(DB_ERROR);