39 #ifndef UNIV_HOTBACKUP
80 UNIV_INTERN
log_t* log_sys = NULL;
82 #ifdef UNIV_PFS_RWLOCK
83 UNIV_INTERN mysql_pfs_key_t checkpoint_lock_key;
84 # ifdef UNIV_LOG_ARCHIVE
85 UNIV_INTERN mysql_pfs_key_t archive_lock_key;
90 UNIV_INTERN mysql_pfs_key_t log_sys_mutex_key;
91 UNIV_INTERN mysql_pfs_key_t log_flush_order_mutex_key;
100 UNIV_INTERN ibool log_has_printed_chkp_warning = FALSE;
101 UNIV_INTERN time_t log_last_warning_time;
103 #ifdef UNIV_LOG_ARCHIVE
106 UNIV_INTERN byte log_archive_io;
110 #define LOG_BUF_WRITE_MARGIN (4 * OS_FILE_LOG_BLOCK_SIZE)
113 #define LOG_BUF_FLUSH_RATIO 2
114 #define LOG_BUF_FLUSH_MARGIN (LOG_BUF_WRITE_MARGIN + 4 * UNIV_PAGE_SIZE)
119 #define LOG_CHECKPOINT_FREE_PER_THREAD (4 * UNIV_PAGE_SIZE)
120 #define LOG_CHECKPOINT_EXTRA_FREE (8 * UNIV_PAGE_SIZE)
125 #define LOG_POOL_CHECKPOINT_RATIO_ASYNC 32
128 #define LOG_POOL_PREFLUSH_RATIO_SYNC 16
132 #define LOG_POOL_PREFLUSH_RATIO_ASYNC 8
135 #define LOG_ARCHIVE_EXTRA_MARGIN (4 * UNIV_PAGE_SIZE)
138 #define LOG_ARCHIVE_RATIO_ASYNC 16
141 #define LOG_UNLOCK_NONE_FLUSHED_LOCK 1
142 #define LOG_UNLOCK_FLUSH_LOCK 2
145 #define LOG_ARCHIVE_READ 1
146 #define LOG_ARCHIVE_WRITE 2
152 log_io_complete_checkpoint(
void);
154 #ifdef UNIV_LOG_ARCHIVE
159 log_io_complete_archive(
void);
169 log_buf_pool_get_oldest_modification(
void)
196 log_t* log = log_sys;
197 ulint len_upper_limit;
198 #ifdef UNIV_LOG_ARCHIVE
199 ulint archived_lsn_age;
206 ut_a(len < log->buf_size / 2);
208 mutex_enter(&(log->
mutex));
209 ut_ad(!recv_no_log_write);
214 len_upper_limit = LOG_BUF_WRITE_MARGIN + (5 * len) / 4;
218 mutex_exit(&(log->
mutex));
232 #ifdef UNIV_LOG_ARCHIVE
233 if (log->archiving_state != LOG_ARCH_OFF) {
235 archived_lsn_age = log->
lsn - log->archived_lsn;
236 if (archived_lsn_age + len_upper_limit
237 > log->max_archived_lsn_age) {
241 mutex_exit(&(log->
mutex));
243 ut_ad(len_upper_limit <= log->max_archived_lsn_age);
254 #ifdef UNIV_LOG_DEBUG
256 log->old_lsn = log->
lsn;
271 log_t* log = log_sys;
278 ut_ad(!recv_no_log_write);
293 - LOG_BLOCK_TRL_SIZE;
301 log_block =
static_cast<byte*
>(
310 log_block_set_checkpoint_no(log_block,
312 len += LOG_BLOCK_HDR_SIZE + LOG_BLOCK_TRL_SIZE;
342 ulint first_rec_group;
345 log_t* log = log_sys;
346 lsn_t checkpoint_age;
349 ut_ad(!recv_no_log_write);
353 log_block =
static_cast<byte*
>(
359 if (first_rec_group == 0) {
382 if (!log_has_printed_chkp_warning
383 || difftime(time(NULL), log_last_warning_time) > 15) {
385 log_has_printed_chkp_warning = TRUE;
386 log_last_warning_time = time(NULL);
390 " InnoDB: ERROR: the age of the last"
391 " checkpoint is " LSN_PF
",\n"
392 "InnoDB: which exceeds the log group"
393 " capacity " LSN_PF
".\n"
394 "InnoDB: If you are using big"
395 " BLOB or TEXT rows, you must set the\n"
396 "InnoDB: combined size of log files"
397 " at least 10 times bigger than the\n"
398 "InnoDB: largest such row.\n",
404 if (checkpoint_age <= log->max_modified_age_sync) {
419 #ifdef UNIV_LOG_DEBUG
420 log_check_log_recs(log->
buf + log->old_buf_free,
421 log->
buf_free - log->old_buf_free, log->old_lsn);
427 #ifdef UNIV_LOG_ARCHIVE
433 log_pad_current_log_block(
void)
446 - LOG_BLOCK_TRL_SIZE;
448 for (i = 0; i < pad_length; i++) {
490 return(offset - LOG_FILE_HDR_SIZE * (1 + offset / group->
file_size));
507 return(offset + LOG_FILE_HDR_SIZE
508 * (1 + offset / (group->
file_size - LOG_FILE_HDR_SIZE)));
516 log_group_calc_lsn_offset(
522 lsn_t gr_lsn_size_offset;
537 difference = lsn - gr_lsn;
539 difference = gr_lsn -
lsn;
541 difference = difference % group_size;
543 difference = group_size - difference;
546 offset = (gr_lsn_size_offset + difference) % group_size;
559 UNIV_INTERN ibool log_debug_writes = FALSE;
569 ib_int64_t* log_file_offset,
571 ib_uint64_t first_header_lsn,
577 ib_int64_t log_file_size)
580 ib_int64_t capacity = log_file_size - LOG_FILE_HDR_SIZE;
582 ib_int64_t add_this_many;
584 if (lsn < first_header_lsn) {
585 add_this_many = 1 + (first_header_lsn -
lsn)
586 / (capacity * (ib_int64_t) n_log_files);
588 * capacity * (ib_int64_t) n_log_files;
591 ut_a(lsn >= first_header_lsn);
593 file_no = ((ulint)((lsn - first_header_lsn) / capacity))
595 *log_file_offset = (lsn - first_header_lsn) % capacity;
597 *log_file_offset = *log_file_offset + LOG_FILE_HDR_SIZE;
602 #ifndef UNIV_HOTBACKUP
615 group->
lsn_offset = log_group_calc_lsn_offset(lsn, group);
626 log_calc_max_ages(
void)
632 ibool success = TRUE;
633 lsn_t smallest_capacity;
634 lsn_t archive_margin;
635 lsn_t smallest_archive_margin;
637 mutex_enter(&(log_sys->
mutex));
643 smallest_capacity = LSN_MAX;
644 smallest_archive_margin = LSN_MAX;
654 - LOG_ARCHIVE_EXTRA_MARGIN;
656 if (archive_margin < smallest_archive_margin) {
658 smallest_archive_margin = archive_margin;
665 smallest_capacity = smallest_capacity - smallest_capacity / 10;
673 + LOG_CHECKPOINT_EXTRA_FREE;
674 if (free >= smallest_capacity / 2) {
679 margin = smallest_capacity - free;
682 margin = margin - margin / 10;
687 - margin / LOG_POOL_PREFLUSH_RATIO_ASYNC;
689 - margin / LOG_POOL_PREFLUSH_RATIO_SYNC;
692 / LOG_POOL_CHECKPOINT_RATIO_ASYNC;
695 #ifdef UNIV_LOG_ARCHIVE
696 log_sys->max_archived_lsn_age = smallest_archive_margin;
698 log_sys->max_archived_lsn_age_async = smallest_archive_margin
699 - smallest_archive_margin / LOG_ARCHIVE_RATIO_ASYNC;
702 mutex_exit(&(log_sys->
mutex));
706 "InnoDB: Error: ib_logfiles are too small"
707 " for innodb_thread_concurrency %lu.\n"
708 "InnoDB: The combined size of ib_logfiles"
709 " should be bigger than\n"
710 "InnoDB: 200 kB * innodb_thread_concurrency.\n"
711 "InnoDB: To get mysqld to start up, set"
712 " innodb_thread_concurrency in my.cnf\n"
713 "InnoDB: to a lower value, for example, to 8."
714 " After an ERROR-FREE shutdown\n"
715 "InnoDB: of mysqld you can adjust the size of"
716 " ib_logfiles, as explained in\n"
717 "InnoDB: " REFMAN
"adding-and-removing.html\n"
718 "InnoDB: Cannot continue operation."
719 " Calling exit(1).\n",
735 log_sys =
static_cast<log_t*
>(mem_alloc(
sizeof(
log_t)));
737 mutex_create(log_sys_mutex_key, &log_sys->
mutex, SYNC_LOG);
739 mutex_create(log_flush_order_mutex_key,
741 SYNC_LOG_FLUSH_ORDER);
743 mutex_enter(&(log_sys->
mutex));
748 log_sys->
lsn = LOG_START_LSN;
751 ut_a(LOG_BUFFER_SIZE >= 4 * UNIV_PAGE_SIZE);
753 log_sys->buf_ptr =
static_cast<byte*
>(
756 log_sys->
buf =
static_cast<byte*
>(
759 log_sys->
buf_size = LOG_BUFFER_SIZE;
762 - LOG_BUF_FLUSH_MARGIN;
799 SYNC_NO_ORDER_CHECK);
801 log_sys->checkpoint_buf_ptr =
static_cast<byte*
>(
809 #ifdef UNIV_LOG_ARCHIVE
811 log_sys->archiving_state = LOG_ARCH_OFF;
812 log_sys->archived_lsn = log_sys->
lsn;
813 log_sys->next_archived_lsn = 0;
815 log_sys->n_pending_archive_ios = 0;
818 SYNC_NO_ORDER_CHECK);
820 log_sys->archive_buf = NULL;
826 log_sys->archive_buf_size = 0;
838 log_sys->
buf_free = LOG_BLOCK_HDR_SIZE;
839 log_sys->
lsn = LOG_START_LSN + LOG_BLOCK_HDR_SIZE;
844 mutex_exit(&(log_sys->
mutex));
846 #ifdef UNIV_LOG_DEBUG
870 ulint archive_space_id __attribute__((unused)))
887 group->
state = LOG_GROUP_OK;
888 group->
lsn = LOG_START_LSN;
898 #ifdef UNIV_LOG_ARCHIVE
899 group->archive_file_header_bufs_ptr =
static_cast<byte*
>(
902 group->archive_file_header_bufs =
static_cast<byte*
>(
906 for (i = 0; i < n_files; i++) {
914 #ifdef UNIV_LOG_ARCHIVE
915 group->archive_file_header_bufs_ptr[
i] =
static_cast<byte*
>(
918 group->archive_file_header_bufs[
i] =
static_cast<byte*
>(
919 ut_align(group->archive_file_header_bufs_ptr[i],
924 #ifdef UNIV_LOG_ARCHIVE
925 group->archive_space_id = archive_space_id;
927 group->archived_file_no = 0;
928 group->archived_offset = 0;
939 ut_a(log_calc_max_ages());
964 if (code & LOG_UNLOCK_NONE_FLUSHED_LOCK) {
968 if (code & LOG_UNLOCK_FLUSH_LOCK) {
987 if (log_debug_writes) {
989 "Log flushed first to group %lu\n",
996 return(LOG_UNLOCK_NONE_FLUSHED_LOCK);
1002 fprintf(stderr,
"Log flushed to group %lu\n",
1014 log_sys_check_flush_completion(
void)
1038 move_end - move_start);
1044 return(LOG_UNLOCK_FLUSH_LOCK);
1060 #ifdef UNIV_LOG_ARCHIVE
1061 if ((byte*) group == &log_archive_io) {
1064 log_io_complete_archive();
1070 if ((ulint) group & 0x1UL) {
1081 if (log_debug_writes) {
1083 "Checkpoint info written to group %lu\n",
1087 log_io_complete_checkpoint();
1097 && srv_flush_log_at_trx_commit != 2) {
1102 mutex_enter(&(log_sys->
mutex));
1103 ut_ad(!recv_no_log_write);
1110 MONITOR_DEC(MONITOR_PENDING_LOG_WRITE);
1113 unlock = unlock | log_sys_check_flush_completion();
1117 mutex_exit(&(log_sys->
mutex));
1124 log_group_file_header_flush(
1136 ut_ad(!recv_no_log_write);
1137 ut_a(nth_file < group->n_files);
1145 memcpy(buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
" ", 4);
1147 dest_offset = nth_file * group->
file_size;
1150 if (log_debug_writes) {
1152 "Writing log file header to group %lu file %lu\n",
1153 (ulong) group->
id, (ulong) nth_file);
1164 (ulint) (dest_offset / UNIV_PAGE_SIZE),
1165 (ulint) (dest_offset % UNIV_PAGE_SIZE),
1179 log_block_store_checksum(
1199 ulint new_data_offset)
1210 ut_ad(!recv_no_log_write);
1214 if (new_data_offset == 0) {
1215 write_header = TRUE;
1217 write_header = FALSE;
1225 next_offset = log_group_calc_lsn_offset(start_lsn, group);
1227 if ((next_offset % group->
file_size == LOG_FILE_HDR_SIZE)
1233 log_group_file_header_flush(group, (ulint)
1252 if (log_debug_writes) {
1255 "Writing log file segment to group %lu"
1256 " offset " LSN_PF
" len %lu\n"
1257 "start lsn " LSN_PF
"\n"
1258 "First block n:o %lu last block n:o %lu\n",
1259 (ulong) group->
id, next_offset,
1290 ut_a(next_offset / UNIV_PAGE_SIZE <= ULINT_MAX);
1293 (ulint) (next_offset / UNIV_PAGE_SIZE),
1294 (ulint) (next_offset % UNIV_PAGE_SIZE), write_len, buf,
1303 if (write_len < len) {
1304 start_lsn += write_len;
1308 write_header = TRUE;
1328 ibool flush_to_disk)
1338 ulint loop_count = 0;
1355 ut_ad(loop_count < 5);
1358 if (loop_count > 2) {
1359 fprintf(stderr,
"Log loop count %lu\n", loop_count);
1364 mutex_enter(&(log_sys->
mutex));
1365 ut_ad(!recv_no_log_write);
1370 mutex_exit(&(log_sys->
mutex));
1378 && wait != LOG_WAIT_ALL_GROUPS))) {
1380 mutex_exit(&(log_sys->
mutex));
1404 mutex_exit(&(log_sys->
mutex));
1418 mutex_exit(&(log_sys->
mutex));
1424 if (log_debug_writes) {
1426 "Writing log from " LSN_PF
" up to lsn " LSN_PF
"\n",
1447 ut_ad(area_end - area_start > 0);
1451 if (flush_to_disk) {
1457 log_block_set_flush_bit(log_sys->
buf + area_start, TRUE);
1458 log_block_set_checkpoint_no(
1479 group, log_sys->
buf + area_start,
1480 area_end - area_start,
1483 start_offset - area_start);
1490 mutex_exit(&(log_sys->
mutex));
1498 }
else if (flush_to_disk) {
1506 mutex_enter(&(log_sys->
mutex));
1515 MONITOR_DEC(MONITOR_PENDING_LOG_WRITE);
1518 unlock = unlock | log_sys_check_flush_completion();
1522 mutex_exit(&(log_sys->
mutex));
1527 mutex_exit(&(log_sys->
mutex));
1530 case LOG_WAIT_ONE_GROUP:
1533 case LOG_WAIT_ALL_GROUPS:
1555 mutex_enter(&(log_sys->
mutex));
1559 mutex_exit(&(log_sys->
mutex));
1577 mutex_enter(&(log_sys->
mutex));
1581 mutex_exit(&(log_sys->
mutex));
1592 log_flush_margin(
void)
1595 log_t* log = log_sys;
1598 mutex_enter(&(log->
mutex));
1610 mutex_exit(&(log->
mutex));
1625 log_preflush_pool_modified_pages(
1655 MONITOR_FLUSH_SYNC_TOTAL_PAGE,
1656 MONITOR_FLUSH_SYNC_COUNT,
1657 MONITOR_FLUSH_SYNC_PAGES,
1667 log_complete_checkpoint(
void)
1686 log_io_complete_checkpoint(
void)
1689 mutex_enter(&(log_sys->
mutex));
1694 MONITOR_DEC(MONITOR_PENDING_CHECKPOINT_WRITE);
1697 log_complete_checkpoint();
1700 mutex_exit(&(log_sys->
mutex));
1707 log_checkpoint_set_nth_group_info(
1717 + 8 * n + LOG_CHECKPOINT_ARCHIVED_FILE_NO, file_no);
1719 + 8 * n + LOG_CHECKPOINT_ARCHIVED_OFFSET, offset);
1736 + 8 * n + LOG_CHECKPOINT_ARCHIVED_FILE_NO);
1738 + 8 * n + LOG_CHECKPOINT_ARCHIVED_OFFSET);
1745 log_group_checkpoint(
1750 #ifdef UNIV_LOG_ARCHIVE
1751 ib_uint64_t archived_lsn;
1752 ib_uint64_t next_archived_lsn;
1762 #if LOG_CHECKPOINT_SIZE > OS_FILE_LOG_BLOCK_SIZE
1763 # error "LOG_CHECKPOINT_SIZE > OS_FILE_LOG_BLOCK_SIZE"
1774 lsn_offset & 0xFFFFFFFFUL);
1780 #ifdef UNIV_LOG_ARCHIVE
1781 if (log_sys->archiving_state == LOG_ARCH_OFF) {
1782 archived_lsn = LSN_MAX;
1784 archived_lsn = log_sys->archived_lsn;
1786 if (archived_lsn != log_sys->next_archived_lsn) {
1787 next_archived_lsn = log_sys->next_archived_lsn;
1798 log_checkpoint_set_nth_group_info(buf, i, 0, 0);
1804 log_checkpoint_set_nth_group_info(buf, group2->
id,
1805 #ifdef UNIV_LOG_ARCHIVE
1806 group2->archived_file_no,
1807 group2->archived_offset
1820 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
1827 write_offset = LOG_CHECKPOINT_1;
1829 write_offset = LOG_CHECKPOINT_2;
1851 write_offset / UNIV_PAGE_SIZE,
1852 write_offset % UNIV_PAGE_SIZE,
1854 buf, ((byte*) group + 1));
1856 ut_ad(((ulint) group & 0x1UL) == 0);
1861 #ifdef UNIV_HOTBACKUP
1867 log_reset_first_header_and_checkpoint(
1882 lsn = start + LOG_BLOCK_HDR_SIZE;
1885 strcpy((
char*) hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
1888 + (LOG_FILE_WAS_CREATED_BY_HOT_BACKUP
1889 + (
sizeof "ibbackup ") - 1));
1890 buf = hdr_buf + LOG_CHECKPOINT_1;
1896 LOG_FILE_HDR_SIZE + LOG_BLOCK_HDR_SIZE);
1907 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
1916 #ifndef UNIV_HOTBACKUP
1933 field / UNIV_PAGE_SIZE, field % UNIV_PAGE_SIZE,
1953 log_group_checkpoint(group);
1989 mutex_enter(&(log_sys->
mutex));
1991 ut_ad(!recv_no_log_write);
1992 oldest_lsn = log_buf_pool_get_oldest_modification();
1994 mutex_exit(&(log_sys->
mutex));
2006 mutex_enter(&(log_sys->
mutex));
2011 mutex_exit(&(log_sys->
mutex));
2021 mutex_exit(&(log_sys->
mutex));
2035 if (log_debug_writes) {
2036 fprintf(stderr,
"Making checkpoint no "
2037 LSN_PF
" at lsn " LSN_PF
"\n",
2047 mutex_exit(&(log_sys->
mutex));
2077 while (!log_preflush_pool_modified_pages(lsn)) {
2093 log_checkpoint_margin(
void)
2096 log_t* log = log_sys;
2098 lsn_t checkpoint_age;
2099 ib_uint64_t advance;
2101 ibool checkpoint_sync;
2102 ibool do_checkpoint;
2105 checkpoint_sync = FALSE;
2106 do_checkpoint = FALSE;
2109 mutex_enter(&(log->
mutex));
2110 ut_ad(!recv_no_log_write);
2113 mutex_exit(&(log->
mutex));
2118 oldest_lsn = log_buf_pool_get_oldest_modification();
2120 age = log->
lsn - oldest_lsn;
2133 checkpoint_sync = TRUE;
2135 do_checkpoint = TRUE;
2140 do_checkpoint = TRUE;
2147 mutex_exit(&(log->
mutex));
2150 lsn_t new_oldest = oldest_lsn + advance;
2152 success = log_preflush_pool_modified_pages(new_oldest);
2158 mutex_enter(&(log->
mutex));
2162 mutex_exit(&(log->
mutex));
2167 if (do_checkpoint) {
2170 if (checkpoint_sync) {
2190 lsn_t source_offset;
2195 sync = (type == LOG_RECOVER);
2197 source_offset = log_group_calc_lsn_offset(start_lsn, group);
2199 ut_a(end_lsn - start_lsn <= ULINT_MAX);
2200 len = (ulint) (end_lsn - start_lsn);
2212 #ifdef UNIV_LOG_ARCHIVE
2213 if (type == LOG_ARCHIVE) {
2215 log_sys->n_pending_archive_ios++;
2223 ut_a(source_offset / UNIV_PAGE_SIZE <= ULINT_MAX);
2226 (ulint) (source_offset / UNIV_PAGE_SIZE),
2227 (ulint) (source_offset % UNIV_PAGE_SIZE),
2233 if (start_lsn != end_lsn) {
2239 #ifdef UNIV_LOG_ARCHIVE
2247 ulint
id __attribute__((unused)),
2252 sprintf(buf,
"%sib_arch_log_%010lu", srv_arch_dir, (ulong) file_no);
2259 log_group_archive_file_header_write(
2265 ib_uint64_t start_lsn)
2273 ut_a(nth_file < group->n_files);
2275 buf = *(group->archive_file_header_bufs + nth_file);
2283 dest_offset = nth_file * group->
file_size;
2289 fil_io(OS_FILE_WRITE | OS_FILE_LOG,
true, group->archive_space_id,
2290 dest_offset / UNIV_PAGE_SIZE,
2291 dest_offset % UNIV_PAGE_SIZE,
2293 buf, &log_archive_io);
2300 log_group_archive_completed_header_write(
2305 ib_uint64_t end_lsn)
2311 ut_a(nth_file < group->n_files);
2313 buf = *(group->archive_file_header_bufs + nth_file);
2318 dest_offset = nth_file * group->
file_size + LOG_FILE_ARCH_COMPLETED;
2324 fil_io(OS_FILE_WRITE | OS_FILE_LOG,
true, group->archive_space_id,
2325 dest_offset / UNIV_PAGE_SIZE,
2326 dest_offset % UNIV_PAGE_SIZE,
2328 buf + LOG_FILE_ARCH_COMPLETED,
2353 start_lsn = log_sys->archived_lsn;
2357 end_lsn = log_sys->next_archived_lsn;
2361 buf = log_sys->archive_buf;
2365 next_offset = group->archived_offset;
2367 if ((next_offset % group->
file_size == 0)
2373 if (next_offset % group->
file_size == 0) {
2380 group->archived_file_no + n_files);
2382 file_handle = os_file_create(innodb_file_log_key,
2388 file_handle = os_file_create(
2395 "InnoDB: Cannot create or open"
2396 " archive log file %s.\n"
2397 "InnoDB: Cannot continue operation.\n"
2398 "InnoDB: Check that the log archive"
2399 " directory exists,\n"
2400 "InnoDB: you have access rights to it, and\n"
2401 "InnoDB: there is space available.\n", name);
2406 if (log_debug_writes) {
2407 fprintf(stderr,
"Created archive file %s\n", name);
2411 ret = os_file_close(file_handle);
2418 group->archive_space_id, FALSE);
2420 if (next_offset % group->
file_size == 0) {
2421 log_group_archive_file_header_write(
2423 group->archived_file_no + n_files,
2426 next_offset += LOG_FILE_HDR_SIZE;
2430 len = end_lsn - start_lsn;
2438 if (log_debug_writes) {
2440 "Archiving starting at lsn " LSN_PF
", len %lu"
2443 (ulong) len, (ulong) group->
id);
2447 log_sys->n_pending_archive_ios++;
2453 fil_io(OS_FILE_WRITE | OS_FILE_LOG,
false, group->archive_space_id,
2454 (ulint) (next_offset / UNIV_PAGE_SIZE),
2455 (ulint) (next_offset % UNIV_PAGE_SIZE),
2463 if (next_offset % group->
file_size == 0) {
2467 if (end_lsn != start_lsn) {
2472 group->next_archived_file_no = group->archived_file_no + n_files;
2473 group->next_archived_offset = next_offset % group->
file_size;
2483 log_archive_groups(
void)
2492 log_group_archive(group);
2500 log_archive_write_complete_groups(
void)
2507 ib_uint64_t start_lsn;
2508 ib_uint64_t end_lsn;
2515 group->archived_file_no = group->next_archived_file_no;
2516 group->archived_offset = group->next_archived_offset;
2521 n_files = (UNIV_PAGE_SIZE
2526 end_offset = group->archived_offset;
2528 if (end_offset % group->
file_size == 0) {
2530 trunc_files = n_files;
2532 trunc_files = n_files - 1;
2536 if (log_debug_writes && trunc_files) {
2538 "Complete file(s) archived to group %lu\n",
2544 start_lsn = log_sys->next_archived_lsn
2545 - (end_offset - LOG_FILE_HDR_SIZE + trunc_files
2546 * (group->
file_size - LOG_FILE_HDR_SIZE));
2547 end_lsn = start_lsn;
2549 for (i = 0; i < trunc_files; i++) {
2551 end_lsn += group->
file_size - LOG_FILE_HDR_SIZE;
2556 log_group_archive_completed_header_write(group, i, end_lsn);
2559 fil_space_truncate_start(group->archive_space_id,
2563 if (log_debug_writes) {
2564 fputs(
"Archiving writes completed\n", stderr);
2573 log_archive_check_completion_low(
void)
2578 if (log_sys->n_pending_archive_ios == 0
2579 && log_sys->archiving_phase == LOG_ARCHIVE_READ) {
2582 if (log_debug_writes) {
2583 fputs(
"Archiving read completed\n", stderr);
2589 log_sys->archiving_phase = LOG_ARCHIVE_WRITE;
2591 log_archive_groups();
2594 if (log_sys->n_pending_archive_ios == 0
2595 && log_sys->archiving_phase == LOG_ARCHIVE_WRITE) {
2597 log_archive_write_complete_groups();
2599 log_sys->archived_lsn = log_sys->next_archived_lsn;
2601 rw_lock_x_unlock_gen(&(log_sys->archive_lock), LOG_ARCHIVE);
2609 log_io_complete_archive(
void)
2614 mutex_enter(&(log_sys->
mutex));
2618 mutex_exit(&(log_sys->
mutex));
2622 mutex_enter(&(log_sys->
mutex));
2624 ut_ad(log_sys->n_pending_archive_ios > 0);
2626 log_sys->n_pending_archive_ios--;
2628 log_archive_check_completion_low();
2630 mutex_exit(&(log_sys->
mutex));
2644 ibool calc_new_limit;
2645 ib_uint64_t start_lsn;
2646 ib_uint64_t limit_lsn;
2648 calc_new_limit = TRUE;
2650 mutex_enter(&(log_sys->
mutex));
2652 switch (log_sys->archiving_state) {
2655 mutex_exit(&(log_sys->
mutex));
2660 case LOG_ARCH_STOPPED:
2661 case LOG_ARCH_STOPPING2:
2662 mutex_exit(&(log_sys->
mutex));
2664 os_event_wait(log_sys->archiving_on);
2669 start_lsn = log_sys->archived_lsn;
2671 if (calc_new_limit) {
2673 limit_lsn = start_lsn + log_sys->archive_buf_size;
2675 *n_bytes = log_sys->archive_buf_size;
2677 if (limit_lsn >= log_sys->
lsn) {
2684 if (log_sys->archived_lsn >= limit_lsn) {
2691 mutex_exit(&(log_sys->
mutex));
2695 calc_new_limit = FALSE;
2700 if (log_sys->n_pending_archive_ios > 0) {
2703 mutex_exit(&(log_sys->
mutex));
2707 rw_lock_s_unlock(&(log_sys->archive_lock));
2710 *n_bytes = log_sys->archive_buf_size;
2715 rw_lock_x_lock_gen(&(log_sys->archive_lock), LOG_ARCHIVE);
2717 log_sys->archiving_phase = LOG_ARCHIVE_READ;
2719 log_sys->next_archived_lsn = limit_lsn;
2722 if (log_debug_writes) {
2724 "Archiving from lsn " LSN_PF
" to lsn " LSN_PF
"\n",
2725 log_sys->archived_lsn, limit_lsn);
2733 start_lsn, limit_lsn);
2735 mutex_exit(&(log_sys->
mutex));
2739 rw_lock_s_unlock(&(log_sys->archive_lock));
2742 *n_bytes = log_sys->archive_buf_size;
2752 log_archive_all(
void)
2755 ib_uint64_t present_lsn;
2758 mutex_enter(&(log_sys->
mutex));
2760 if (log_sys->archiving_state == LOG_ARCH_OFF) {
2761 mutex_exit(&(log_sys->
mutex));
2766 present_lsn = log_sys->
lsn;
2768 mutex_exit(&(log_sys->
mutex));
2770 log_pad_current_log_block();
2773 mutex_enter(&(log_sys->
mutex));
2775 if (present_lsn <= log_sys->archived_lsn) {
2777 mutex_exit(&(log_sys->
mutex));
2782 mutex_exit(&(log_sys->
mutex));
2793 log_archive_close_groups(
2795 ibool increment_file_count)
2803 if (log_sys->archiving_state == LOG_ARCH_OFF) {
2810 trunc_len = UNIV_PAGE_SIZE
2812 if (trunc_len > 0) {
2818 log_group_archive_completed_header_write(
2819 group, 0, log_sys->archived_lsn);
2821 fil_space_truncate_start(group->archive_space_id,
2823 if (increment_file_count) {
2824 group->archived_offset = 0;
2825 group->archived_file_no += 2;
2829 if (log_debug_writes) {
2831 "Incrementing arch file no to %lu"
2832 " in log group %lu\n",
2833 (ulong) group->archived_file_no + 2,
2853 mutex_enter(&(log_sys->
mutex));
2855 if (log_sys->archiving_state != LOG_ARCH_ON) {
2857 mutex_exit(&(log_sys->
mutex));
2862 log_sys->archiving_state = LOG_ARCH_STOPPING;
2864 mutex_exit(&(log_sys->
mutex));
2868 mutex_enter(&(log_sys->
mutex));
2870 log_sys->archiving_state = LOG_ARCH_STOPPING2;
2873 mutex_exit(&(log_sys->
mutex));
2878 rw_lock_s_unlock(&(log_sys->archive_lock));
2880 mutex_enter(&(log_sys->
mutex));
2885 log_archive_close_groups(TRUE);
2887 mutex_exit(&(log_sys->
mutex));
2898 mutex_enter(&(log_sys->
mutex));
2900 log_sys->archiving_state = LOG_ARCH_STOPPED;
2902 mutex_exit(&(log_sys->
mutex));
2915 mutex_enter(&(log_sys->
mutex));
2917 if (log_sys->archiving_state != LOG_ARCH_STOPPED) {
2919 mutex_exit(&(log_sys->
mutex));
2924 log_sys->archiving_state = LOG_ARCH_ON;
2928 mutex_exit(&(log_sys->
mutex));
2942 mutex_enter(&(log_sys->
mutex));
2944 if (log_sys->archiving_state == LOG_ARCH_STOPPED
2945 || log_sys->archiving_state == LOG_ARCH_OFF) {
2947 log_sys->archiving_state = LOG_ARCH_OFF;
2951 mutex_exit(&(log_sys->
mutex));
2956 mutex_exit(&(log_sys->
mutex));
2973 mutex_enter(&(log_sys->
mutex));
2975 if (log_sys->archiving_state == LOG_ARCH_OFF) {
2977 log_sys->archiving_state = LOG_ARCH_ON;
2979 log_sys->archived_lsn
2982 mutex_exit(&(log_sys->
mutex));
2987 mutex_exit(&(log_sys->
mutex));
2998 log_archive_margin(
void)
3001 log_t* log = log_sys;
3006 mutex_enter(&(log->
mutex));
3008 if (log->archiving_state == LOG_ARCH_OFF) {
3009 mutex_exit(&(log->
mutex));
3014 age = log->
lsn - log->archived_lsn;
3016 if (age > log->max_archived_lsn_age) {
3022 }
else if (age > log->max_archived_lsn_age_async) {
3030 mutex_exit(&(log->
mutex));
3035 mutex_exit(&(log->
mutex));
3060 log_checkpoint_margin();
3062 #ifdef UNIV_LOG_ARCHIVE
3063 log_archive_margin();
3066 mutex_enter(&(log_sys->
mutex));
3067 ut_ad(!recv_no_log_write);
3071 mutex_exit(&(log_sys->
mutex));
3076 mutex_exit(&(log_sys->
mutex));
3095 const char* thread_name;
3098 ib_logf(IB_LOG_LEVEL_INFO,
"Starting shutdown...");
3114 if (thread_name != NULL) {
3119 if (srv_print_verbose_log && count > 600) {
3121 "Waiting for %s to exit", thread_name);
3133 total_trx = trx_sys_any_active_transactions();
3135 if (total_trx > 0) {
3137 if (srv_print_verbose_log && count > 600) {
3139 "Waiting for %lu active transactions to finish",
3163 if (srv_print_verbose_log && count > 600) {
3164 const char* thread_type =
"<null>";
3166 switch (active_thd) {
3174 thread_type =
"worker threads";
3177 thread_type =
"master thread";
3180 thread_type =
"purge thread";
3185 "Waiting for %s to be suspended",
3201 if (srv_print_verbose_log && count > 600) {
3203 "Waiting for page_cleaner to "
3204 "finish flushing of buffer pool");
3209 mutex_enter(&log_sys->
mutex);
3211 #ifdef UNIV_LOG_ARCHIVE
3212 || log_sys->n_pending_archive_ios
3215 mutex_exit(&log_sys->
mutex);
3218 if (srv_print_verbose_log && count > 600) {
3220 "Pending checkpoint_writes: %lu. "
3221 "Pending log flush writes: %lu",
3232 if (srv_print_verbose_log && count > 600) {
3234 "Waiting for %lu buffer page I/Os to complete",
3235 (ulong) pending_io);
3242 #ifdef UNIV_LOG_ARCHIVE
3248 "MySQL has requested a very fast shutdown "
3249 "without flushing the InnoDB buffer pool to "
3250 "data files. At the next mysqld startup "
3251 "InnoDB will do a crash recovery!");
3268 if (thread_name != NULL) {
3270 "Background thread %s woke up "
3271 "during shutdown", thread_name);
3291 mutex_enter(&log_sys->
mutex);
3296 #ifdef UNIV_LOG_ARCHIVE
3297 || (srv_log_archive_on
3298 && lsn != log_sys->archived_lsn + LOG_BLOCK_HDR_SIZE)
3302 mutex_exit(&log_sys->
mutex);
3309 #ifdef UNIV_LOG_ARCHIVE
3317 log_archive_close_groups(TRUE);
3320 mutex_exit(&log_sys->
mutex);
3324 if (thread_name != NULL) {
3326 "Background thread %s woke up during shutdown",
3344 if (srv_print_verbose_log && count > 600) {
3346 "Waiting for dirty buffer pages to be flushed");
3366 "Log sequence number at shutdown " LSN_PF
" "
3367 "is lower than at startup " LSN_PF
"!",
3391 #ifdef UNIV_LOG_DEBUG
3403 ib_uint64_t buf_start_lsn)
3405 ib_uint64_t contiguous_lsn;
3406 ib_uint64_t scanned_lsn;
3425 ut_memcpy(scan_buf, start, end - start);
3429 * UNIV_PAGE_SIZE, FALSE, scan_buf, end - start,
3432 &contiguous_lsn, &scanned_lsn);
3434 ut_a(scanned_lsn == buf_start_lsn + len);
3452 if (0 == mutex_enter_nowait(&(log_sys->
mutex))) {
3453 *lsn = log_sys->
lsn;
3455 mutex_exit(&(log_sys->
mutex));
3471 double time_elapsed;
3472 time_t current_time;
3474 mutex_enter(&(log_sys->
mutex));
3477 "Log sequence number " LSN_PF
"\n"
3478 "Log flushed up to " LSN_PF
"\n"
3479 "Pages flushed up to " LSN_PF
"\n"
3480 "Last checkpoint at " LSN_PF
"\n",
3483 log_buf_pool_get_oldest_modification(),
3486 current_time = time(NULL);
3488 time_elapsed = difftime(current_time,
3491 if (time_elapsed <= 0) {
3496 "%lu pending log writes, %lu pending chkp writes\n"
3497 "%lu log i/o's done, %.2f log i/o's/second\n",
3507 mutex_exit(&(log_sys->
mutex));
3531 for (i = 0; i < group->
n_files; i++) {
3533 #ifdef UNIV_LOG_ARCHIVE
3534 mem_free(group->archive_file_header_bufs_ptr[i]);
3541 #ifdef UNIV_LOG_ARCHIVE
3542 mem_free(group->archive_file_header_bufs_ptr);
3543 mem_free(group->archive_file_header_bufs);
3568 log_group_close(prev_group);
3582 log_sys->buf_ptr = NULL;
3583 log_sys->
buf = NULL;
3584 mem_free(log_sys->checkpoint_buf_ptr);
3585 log_sys->checkpoint_buf_ptr = NULL;
3593 mutex_free(&log_sys->
mutex);
3595 #ifdef UNIV_LOG_ARCHIVE
3596 rw_lock_free(&log_sys->archive_lock);
3600 #ifdef UNIV_LOG_DEBUG
3601 recv_sys_debug_free();
3614 if (log_sys != NULL) {