diff options
Diffstat (limited to 'innobase/log/log0log.c')
-rw-r--r-- | innobase/log/log0log.c | 227 |
1 files changed, 75 insertions, 152 deletions
diff --git a/innobase/log/log0log.c b/innobase/log/log0log.c index 292fed4b4ec..923ab448e07 100644 --- a/innobase/log/log0log.c +++ b/innobase/log/log0log.c @@ -32,18 +32,20 @@ ulint log_fsp_current_free_limit = 0; log_t* log_sys = NULL; ibool log_do_write = TRUE; -#ifdef UNIV_LOG_DEBUG + ibool log_debug_writes = FALSE; -#endif /* UNIV_LOG_DEBUG */ + /* These control how often we print warnings if the last checkpoint is too old */ ibool log_has_printed_chkp_warning = FALSE; time_t log_last_warning_time; +#ifdef UNIV_LOG_ARCHIVE /* Pointer to this variable is used as the i/o-message when we do i/o to an archive */ byte log_archive_io; +#endif /* UNIV_LOG_ARCHIVE */ /* A margin for free space in the log buffer before a log entry is catenated */ #define LOG_BUF_WRITE_MARGIN (4 * OS_FILE_LOG_BLOCK_SIZE) @@ -90,12 +92,14 @@ static void log_io_complete_checkpoint(void); /*============================*/ +#ifdef UNIV_LOG_ARCHIVE /********************************************************** Completes an archiving i/o. */ static void log_io_complete_archive(void); /*=========================*/ +#endif /* UNIV_LOG_ARCHIVE */ /******************************************************************** Sets the global variable log_fsp_current_free_limit. Also makes a checkpoint, @@ -160,9 +164,13 @@ log_reserve_and_open( { log_t* log = log_sys; ulint len_upper_limit; +#ifdef UNIV_LOG_ARCHIVE ulint archived_lsn_age; - ulint count = 0; ulint dummy; +#endif /* UNIV_LOG_ARCHIVE */ +#ifdef UNIV_DEBUG + ulint count = 0; +#endif /* UNIV_DEBUG */ ut_a(len < log->buf_size / 2); loop: @@ -182,13 +190,12 @@ loop: log_buffer_flush_to_disk(); - count++; - - ut_ad(count < 50); + ut_ad(++count < 50); goto loop; } +#ifdef UNIV_LOG_ARCHIVE if (log->archiving_state != LOG_ARCH_OFF) { archived_lsn_age = ut_dulint_minus(log->lsn, @@ -204,13 +211,12 @@ loop: log_archive_do(TRUE, &dummy); - count++; - - ut_ad(count < 50); + ut_ad(++count < 50); goto loop; } } +#endif /* UNIV_LOG_ARCHIVE */ #ifdef UNIV_LOG_DEBUG log->old_buf_free = log->buf_free; @@ -378,6 +384,7 @@ function_exit: return(lsn); } +#ifdef UNIV_LOG_ARCHIVE /********************************************************** Pads the current log block full with dummy log records. Used in producing consistent archived log files. */ @@ -410,6 +417,7 @@ log_pad_current_log_block(void) ut_a((ut_dulint_get_low(lsn) % OS_FILE_LOG_BLOCK_SIZE) == LOG_BLOCK_HDR_SIZE); } +#endif /* UNIV_LOG_ARCHIVE */ /********************************************************** Calculates the data capacity of a log group, when the log file headers are not @@ -663,11 +671,13 @@ log_calc_max_ages(void) / LOG_POOL_CHECKPOINT_RATIO_ASYNC; log_sys->max_checkpoint_age = margin; +#ifdef UNIV_LOG_ARCHIVE log_sys->max_archived_lsn_age = smallest_archive_margin; log_sys->max_archived_lsn_age_async = smallest_archive_margin - smallest_archive_margin / LOG_ARCHIVE_RATIO_ASYNC; +#endif /* UNIV_LOG_ARCHIVE */ failure: mutex_exit(&(log_sys->mutex)); @@ -767,6 +777,7 @@ log_init(void) memset(log_sys->checkpoint_buf, '\0', OS_FILE_LOG_BLOCK_SIZE); /*----------------------------*/ +#ifdef UNIV_LOG_ARCHIVE /* Under MySQL, log archiving is always off */ log_sys->archiving_state = LOG_ARCH_OFF; log_sys->archived_lsn = log_sys->lsn; @@ -788,13 +799,10 @@ log_init(void) /* memset(log_sys->archive_buf, '\0', LOG_ARCHIVE_BUF_SIZE); */ log_sys->archiving_on = os_event_create(NULL); +#endif /* UNIV_LOG_ARCHIVE */ /*----------------------------*/ - - log_sys->online_backup_state = FALSE; - /*----------------------------*/ - log_block_init(log_sys->buf, log_sys->lsn); log_block_set_first_rec_group(log_sys->buf, LOG_BLOCK_HDR_SIZE); @@ -827,7 +835,8 @@ log_group_init( ulint space_id, /* in: space id of the file space which contains the log files of this group */ - ulint archive_space_id) /* in: space id of the file space + ulint archive_space_id __attribute__((unused))) + /* in: space id of the file space which contains some archived log files for this group; currently, only for the first log group this is @@ -849,7 +858,9 @@ log_group_init( group->n_pending_writes = 0; group->file_header_bufs = mem_alloc(sizeof(byte*) * n_files); +#ifdef UNIV_LOG_ARCHIVE group->archive_file_header_bufs = mem_alloc(sizeof(byte*) * n_files); +#endif /* UNIV_LOG_ARCHIVE */ for (i = 0; i < n_files; i++) { *(group->file_header_bufs + i) = ut_align( @@ -859,17 +870,21 @@ log_group_init( memset(*(group->file_header_bufs + i), '\0', LOG_FILE_HDR_SIZE); +#ifdef UNIV_LOG_ARCHIVE *(group->archive_file_header_bufs + i) = ut_align( mem_alloc(LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE), OS_FILE_LOG_BLOCK_SIZE); memset(*(group->archive_file_header_bufs + i), '\0', LOG_FILE_HDR_SIZE); +#endif /* UNIV_LOG_ARCHIVE */ } +#ifdef UNIV_LOG_ARCHIVE group->archive_space_id = archive_space_id; group->archived_file_no = 0; group->archived_offset = 0; +#endif /* UNIV_LOG_ARCHIVE */ group->checkpoint_buf = ut_align( mem_alloc(2 * OS_FILE_LOG_BLOCK_SIZE), @@ -930,12 +945,10 @@ log_group_check_flush_completion( #endif /* UNIV_SYNC_DEBUG */ if (!log_sys->one_flushed && group->n_pending_writes == 0) { -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fprintf(stderr, "Log flushed first to group %lu\n", (ulong) group->id); } -#endif /* UNIV_LOG_DEBUG */ log_sys->written_to_some_lsn = log_sys->write_lsn; log_sys->one_flushed = TRUE; @@ -943,12 +956,10 @@ log_group_check_flush_completion( return(LOG_UNLOCK_NONE_FLUSHED_LOCK); } -#ifdef UNIV_LOG_DEBUG if (log_debug_writes && (group->n_pending_writes == 0)) { fprintf(stderr, "Log flushed to group %lu\n", (ulong) group->id); } -#endif /* UNIV_LOG_DEBUG */ return(0); } @@ -1006,6 +1017,7 @@ log_io_complete( { ulint unlock; +#ifdef UNIV_LOG_ARCHIVE if ((byte*)group == &log_archive_io) { /* It was an archive write */ @@ -1013,6 +1025,7 @@ log_io_complete( return; } +#endif /* UNIV_LOG_ARCHIVE */ if ((ulint)group & 0x1UL) { /* It was a checkpoint write */ @@ -1024,13 +1037,11 @@ log_io_complete( fil_flush(group->space_id); } -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fprintf(stderr, "Checkpoint info written to group %lu\n", group->id); } -#endif /* UNIV_LOG_DEBUG */ log_io_complete_checkpoint(); @@ -1093,13 +1104,11 @@ log_group_file_header_flush( dest_offset = nth_file * group->file_size; -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fprintf(stderr, "Writing log file header to group %lu file %lu\n", (ulong) group->id, (ulong) nth_file); } -#endif /* UNIV_LOG_DEBUG */ if (log_do_write) { log_sys->n_log_ios++; @@ -1183,7 +1192,6 @@ loop: write_len = len; } -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fprintf(stderr, @@ -1193,7 +1201,7 @@ loop: (ulong) group->id, (ulong) next_offset, (ulong) write_len, (ulong) ut_dulint_get_high(start_lsn), - (ulong) ut_dulint_get_low(start_lsn). + (ulong) ut_dulint_get_low(start_lsn), (ulong) log_block_get_hdr_no(buf), (ulong) log_block_get_hdr_no( buf + write_len - OS_FILE_LOG_BLOCK_SIZE)); @@ -1207,7 +1215,6 @@ loop: + i * OS_FILE_LOG_BLOCK_SIZE)); } } -#endif /* UNIV_LOG_DEBUG */ /* Calculate the checksums for each log block and write them to the trailer fields of the log blocks */ @@ -1335,7 +1342,6 @@ loop: return; } -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fprintf(stderr, "Writing log from %lu %lu up to lsn %lu %lu\n", @@ -1344,7 +1350,6 @@ loop: (ulong) ut_dulint_get_high(log_sys->lsn), (ulong) ut_dulint_get_low(log_sys->lsn)); } -#endif /* UNIV_LOG_DEBUG */ log_sys->n_pending_writes++; @@ -1633,8 +1638,10 @@ log_group_checkpoint( log_group_t* group) /* in: log group */ { log_group_t* group2; +#ifdef UNIV_LOG_ARCHIVE dulint archived_lsn; dulint next_archived_lsn; +#endif /* UNIV_LOG_ARCHIVE */ ulint write_offset; ulint fold; byte* buf; @@ -1657,6 +1664,7 @@ log_group_checkpoint( mach_write_to_4(buf + LOG_CHECKPOINT_LOG_BUF_SIZE, log_sys->buf_size); +#ifdef UNIV_LOG_ARCHIVE if (log_sys->archiving_state == LOG_ARCH_OFF) { archived_lsn = ut_dulint_max; } else { @@ -1668,8 +1676,11 @@ log_group_checkpoint( /* For debugging only */ } } - + mach_write_to_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN, archived_lsn); +#else /* UNIV_LOG_ARCHIVE */ + mach_write_to_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN, ut_dulint_max); +#endif /* UNIV_LOG_ARCHIVE */ for (i = 0; i < LOG_MAX_N_GROUPS; i++) { log_checkpoint_set_nth_group_info(buf, i, 0, 0); @@ -1679,8 +1690,13 @@ log_group_checkpoint( while (group2) { log_checkpoint_set_nth_group_info(buf, group2->id, +#ifdef UNIV_LOG_ARCHIVE group2->archived_file_no, - group2->archived_offset); + group2->archived_offset +#else /* UNIV_LOG_ARCHIVE */ + 0, 0 +#endif /* UNIV_LOG_ARCHIVE */ + ); group2 = UT_LIST_GET_NEXT(log_groups, group2); } @@ -1903,14 +1919,12 @@ log_checkpoint( log_sys->next_checkpoint_lsn = oldest_lsn; -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fprintf(stderr, "Making checkpoint no %lu at lsn %lu %lu\n", (ulong) ut_dulint_get_low(log_sys->next_checkpoint_no), (ulong) ut_dulint_get_high(oldest_lsn), (ulong) ut_dulint_get_low(oldest_lsn)); } -#endif /* UNIV_LOG_DEBUG */ log_groups_write_checkpoint_info(); @@ -2106,16 +2120,18 @@ loop: len = group->file_size - (source_offset % group->file_size); } +#ifdef UNIV_LOG_ARCHIVE if (type == LOG_ARCHIVE) { log_sys->n_pending_archive_ios++; } +#endif /* UNIV_LOG_ARCHIVE */ log_sys->n_log_ios++; fil_io(OS_FILE_READ | OS_FILE_LOG, sync, group->space_id, source_offset / UNIV_PAGE_SIZE, source_offset % UNIV_PAGE_SIZE, - len, buf, &log_archive_io); + len, buf, NULL); start_lsn = ut_dulint_add(start_lsn, len); buf += len; @@ -2126,6 +2142,7 @@ loop: } } +#ifdef UNIV_LOG_ARCHIVE /********************************************************** Generates an archived log file name. */ @@ -2138,8 +2155,6 @@ log_archived_file_name_gen( currently we only archive the first group */ ulint file_no)/* in: file number */ { - ut_a(0); - sprintf(buf, "%sib_arch_log_%010lu", srv_arch_dir, (ulong) file_no); } @@ -2160,8 +2175,6 @@ log_group_archive_file_header_write( ulint dest_offset; #ifdef UNIV_SYNC_DEBUG - ut_a(0); - ut_ad(mutex_own(&(log_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ @@ -2201,8 +2214,6 @@ log_group_archive_completed_header_write( ulint dest_offset; #ifdef UNIV_SYNC_DEBUG - ut_a(0); - ut_ad(mutex_own(&(log_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ ut_a(nth_file < group->n_files); @@ -2244,8 +2255,6 @@ log_group_archive( ulint open_mode; #ifdef UNIV_SYNC_DEBUG - ut_a(0); - ut_ad(mutex_own(&(log_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ @@ -2296,11 +2305,9 @@ loop: exit(1); } -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fprintf(stderr, "Created archive file %s\n", name); } -#endif /* UNIV_LOG_DEBUG */ ret = os_file_close(file_handle); @@ -2327,7 +2334,6 @@ loop: len = group->file_size - (next_offset % group->file_size); } -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fprintf(stderr, "Archiving starting at lsn %lu %lu, len %lu to group %lu\n", @@ -2335,7 +2341,6 @@ loop: (ulong) ut_dulint_get_low(start_lsn), (ulong) len, (ulong) group->id); } -#endif /* UNIV_LOG_DEBUG */ log_sys->n_pending_archive_ios++; @@ -2376,8 +2381,6 @@ log_archive_groups(void) log_group_t* group; #ifdef UNIV_SYNC_DEBUG - ut_a(0); - ut_ad(mutex_own(&(log_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ @@ -2403,8 +2406,6 @@ log_archive_write_complete_groups(void) ulint i; #ifdef UNIV_SYNC_DEBUG - ut_a(0); - ut_ad(mutex_own(&(log_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ @@ -2430,13 +2431,11 @@ log_archive_write_complete_groups(void) trunc_files = n_files - 1; } -#ifdef UNIV_LOG_DEBUG if (log_debug_writes && trunc_files) { fprintf(stderr, "Complete file(s) archived to group %lu\n", (ulong) group->id); } -#endif /* UNIV_LOG_DEBUG */ /* Calculate the archive file space start lsn */ start_lsn = ut_dulint_subtract(log_sys->next_archived_lsn, @@ -2459,11 +2458,9 @@ log_archive_write_complete_groups(void) fil_space_truncate_start(group->archive_space_id, trunc_files * group->file_size); -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fputs("Archiving writes completed\n", stderr); } -#endif /* UNIV_LOG_DEBUG */ } /********************************************************** @@ -2474,19 +2471,15 @@ log_archive_check_completion_low(void) /*==================================*/ { #ifdef UNIV_SYNC_DEBUG - ut_a(0); - ut_ad(mutex_own(&(log_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ if (log_sys->n_pending_archive_ios == 0 && log_sys->archiving_phase == LOG_ARCHIVE_READ) { -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fputs("Archiving read completed\n", stderr); } -#endif /* UNIV_LOG_DEBUG */ /* Archive buffer has now been read in: start archive writes */ @@ -2515,8 +2508,6 @@ log_io_complete_archive(void) { log_group_t* group; - ut_a(0); - mutex_enter(&(log_sys->mutex)); group = UT_LIST_GET_FIRST(log_sys->log_groups); @@ -2552,8 +2543,6 @@ log_archive_do( dulint start_lsn; dulint limit_lsn; - ut_a(0); - calc_new_limit = TRUE; loop: mutex_enter(&(log_sys->mutex)); @@ -2634,7 +2623,6 @@ loop: log_sys->next_archived_lsn = limit_lsn; -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fprintf(stderr, "Archiving from lsn %lu %lu to lsn %lu %lu\n", @@ -2643,7 +2631,6 @@ loop: (ulong) ut_dulint_get_high(limit_lsn), (ulong) ut_dulint_get_low(limit_lsn)); } -#endif /* UNIV_LOG_DEBUG */ /* Read the log segment to the archive buffer */ @@ -2682,8 +2669,6 @@ log_archive_all(void) return; } - ut_a(0); - present_lsn = log_sys->lsn; mutex_exit(&(log_sys->mutex)); @@ -2728,8 +2713,6 @@ log_archive_close_groups( return; } - ut_a(0); - group = UT_LIST_GET_FIRST(log_sys->log_groups); trunc_len = UNIV_PAGE_SIZE @@ -2750,14 +2733,12 @@ log_archive_close_groups( group->archived_file_no += 2; } -#ifdef UNIV_LOG_DEBUG if (log_debug_writes) { fprintf(stderr, "Incrementing arch file no to %lu in log group %lu\n", (ulong) group->archived_file_no + 2, (ulong) group->id); } -#endif /* UNIV_LOG_DEBUG */ } } @@ -2774,8 +2755,6 @@ log_archive_stop(void) { ibool success; - ut_a(0); - mutex_enter(&(log_sys->mutex)); if (log_sys->archiving_state != LOG_ARCH_ON) { @@ -2838,8 +2817,6 @@ log_archive_start(void) /*===================*/ /* out: DB_SUCCESS or DB_ERROR */ { - ut_a(0); - mutex_enter(&(log_sys->mutex)); if (log_sys->archiving_state != LOG_ARCH_STOPPED) { @@ -2866,7 +2843,6 @@ log_archive_noarchivelog(void) /*==========================*/ /* out: DB_SUCCESS or DB_ERROR */ { - ut_a(0); loop: mutex_enter(&(log_sys->mutex)); @@ -2899,7 +2875,6 @@ log_archive_archivelog(void) /*========================*/ /* out: DB_SUCCESS or DB_ERROR */ { - ut_a(0); mutex_enter(&(log_sys->mutex)); if (log_sys->archiving_state == LOG_ARCH_OFF) { @@ -2918,7 +2893,6 @@ log_archive_archivelog(void) return(DB_ERROR); } -#ifdef notdefined /******************************************************************** Tries to establish a big enough margin of free space in the log groups, such that a new log entry can be catenated without an immediate need for @@ -2972,7 +2946,7 @@ loop: goto loop; } } -#endif +#endif /* UNIV_LOG_ARCHIVE */ /************************************************************************ Checks that there is enough free space in the log to start a new query step. @@ -2989,7 +2963,9 @@ loop: log_checkpoint_margin(); - /* log_archive_margin(); */ +#ifdef UNIV_LOG_ARCHIVE + log_archive_margin(); +#endif /* UNIV_LOG_ARCHIVE */ mutex_enter(&(log_sys->mutex)); @@ -3003,66 +2979,6 @@ loop: mutex_exit(&(log_sys->mutex)); } -/********************************************************** -Switches the database to the online backup state. */ - -ulint -log_switch_backup_state_on(void) -/*============================*/ - /* out: DB_SUCCESS or DB_ERROR */ -{ - dulint backup_lsn; - - mutex_enter(&(log_sys->mutex)); - - if (log_sys->online_backup_state) { - - /* The database is already in that state */ - - mutex_exit(&(log_sys->mutex)); - - return(DB_ERROR); - } - - log_sys->online_backup_state = TRUE; - - backup_lsn = log_sys->lsn; - - log_sys->online_backup_lsn = backup_lsn; - - mutex_exit(&(log_sys->mutex)); - - /* log_checkpoint_and_mark_file_spaces(); */ - - return(DB_SUCCESS); -} - -/********************************************************** -Switches the online backup state off. */ - -ulint -log_switch_backup_state_off(void) -/*=============================*/ - /* out: DB_SUCCESS or DB_ERROR */ -{ - mutex_enter(&(log_sys->mutex)); - - if (!log_sys->online_backup_state) { - - /* The database is already in that state */ - - mutex_exit(&(log_sys->mutex)); - - return(DB_ERROR); - } - - log_sys->online_backup_state = FALSE; - - mutex_exit(&(log_sys->mutex)); - - return(DB_SUCCESS); -} - /******************************************************************** Makes a checkpoint at the latest lsn and writes it to first page of each data file in the database, so that we know that the file spaces contain @@ -3111,9 +3027,12 @@ loop: mutex_enter(&(log_sys->mutex)); - if (log_sys->n_pending_archive_ios - + log_sys->n_pending_checkpoint_writes - + log_sys->n_pending_writes > 0) { + if ( +#ifdef UNIV_LOG_ARCHIVE + log_sys->n_pending_archive_ios || +#endif /* UNIV_LOG_ARCHIVE */ + log_sys->n_pending_checkpoint_writes || + log_sys->n_pending_writes) { mutex_exit(&(log_sys->mutex)); @@ -3127,7 +3046,9 @@ loop: goto loop; } - /* log_archive_all(); */ +#ifdef UNIV_LOG_ARCHIVE + log_archive_all(); +#endif /* UNIV_LOG_ARCHIVE */ log_make_checkpoint_at(ut_dulint_max, TRUE); mutex_enter(&(log_sys->mutex)); @@ -3135,10 +3056,13 @@ loop: lsn = log_sys->lsn; if (ut_dulint_cmp(lsn, log_sys->last_checkpoint_lsn) != 0 +#ifdef UNIV_LOG_ARCHIVE || (srv_log_archive_on && ut_dulint_cmp(lsn, ut_dulint_add(log_sys->archived_lsn, LOG_BLOCK_HDR_SIZE)) - != 0)) { + != 0) +#endif /* UNIV_LOG_ARCHIVE */ + ) { mutex_exit(&(log_sys->mutex)); @@ -3146,15 +3070,17 @@ loop: } arch_log_no = 0; -/* - UT_LIST_GET_FIRST(log_sys->log_groups)->archived_file_no; - + +#ifdef UNIV_LOG_ARCHIVE + UT_LIST_GET_FIRST(log_sys->log_groups)->archived_file_no; + if (0 == UT_LIST_GET_FIRST(log_sys->log_groups)->archived_offset) { - + arch_log_no--; } -*/ - /* log_archive_close_groups(TRUE); */ + + log_archive_close_groups(TRUE); +#endif /* UNIV_LOG_ARCHIVE */ mutex_exit(&(log_sys->mutex)); @@ -3227,7 +3153,6 @@ loop: ut_a(0 == ut_dulint_cmp(lsn, log_sys->lsn)); } -#ifdef UNIV_LOG_DEBUG /********************************************************** Checks by parsing that the catenated log segment for a single mtr is consistent. */ @@ -3280,7 +3205,6 @@ log_check_log_recs( return(TRUE); } -#endif /* UNIV_LOG_DEBUG */ /********************************************************** Peeks the current lsn. */ @@ -3292,8 +3216,7 @@ log_peek_lsn( log system mutex */ dulint* lsn) /* out: if returns TRUE, current lsn is here */ { - if (0 == mutex_enter_nowait(&(log_sys->mutex), (char*)__FILE__, - __LINE__)) { + if (0 == mutex_enter_nowait(&(log_sys->mutex), __FILE__, __LINE__)) { *lsn = log_sys->lsn; mutex_exit(&(log_sys->mutex)); |