39 #ifndef UNIV_HOTBACKUP
53 #include <drizzled/errmsg_print.h>
83 UNIV_INTERN ulint log_fsp_current_free_limit = 0;
86 UNIV_INTERN
log_t* log_sys = NULL;
88 #ifdef UNIV_PFS_RWLOCK
89 UNIV_INTERN mysql_pfs_key_t checkpoint_lock_key;
90 # ifdef UNIV_LOG_ARCHIVE
91 UNIV_INTERN mysql_pfs_key_t archive_lock_key;
96 UNIV_INTERN mysql_pfs_key_t log_sys_mutex_key;
97 UNIV_INTERN mysql_pfs_key_t log_flush_order_mutex_key;
106 UNIV_INTERN ibool log_has_printed_chkp_warning = FALSE;
107 UNIV_INTERN time_t log_last_warning_time;
109 #ifdef UNIV_LOG_ARCHIVE
112 UNIV_INTERN byte log_archive_io;
116 #define LOG_BUF_WRITE_MARGIN (4 * OS_FILE_LOG_BLOCK_SIZE)
119 #define LOG_BUF_FLUSH_RATIO 2
120 #define LOG_BUF_FLUSH_MARGIN (LOG_BUF_WRITE_MARGIN + 4 * UNIV_PAGE_SIZE)
125 #define LOG_CHECKPOINT_FREE_PER_THREAD (4 * UNIV_PAGE_SIZE)
126 #define LOG_CHECKPOINT_EXTRA_FREE (8 * UNIV_PAGE_SIZE)
131 #define LOG_POOL_CHECKPOINT_RATIO_ASYNC 32
134 #define LOG_POOL_PREFLUSH_RATIO_SYNC 16
138 #define LOG_POOL_PREFLUSH_RATIO_ASYNC 8
141 #define LOG_ARCHIVE_EXTRA_MARGIN (4 * UNIV_PAGE_SIZE)
144 #define LOG_ARCHIVE_RATIO_ASYNC 16
147 #define LOG_UNLOCK_NONE_FLUSHED_LOCK 1
148 #define LOG_UNLOCK_FLUSH_LOCK 2
151 #define LOG_ARCHIVE_READ 1
152 #define LOG_ARCHIVE_WRITE 2
158 log_io_complete_checkpoint(
void);
160 #ifdef UNIV_LOG_ARCHIVE
165 log_io_complete_archive(
void);
181 mutex_enter(&(log_sys->
mutex));
183 log_fsp_current_free_limit = limit;
185 mutex_exit(&(log_sys->
mutex));
202 log_buf_pool_get_oldest_modification(
void)
229 log_t* log = log_sys;
230 ulint len_upper_limit;
231 #ifdef UNIV_LOG_ARCHIVE
232 ulint archived_lsn_age;
239 ut_a(len < log->buf_size / 2);
241 mutex_enter(&(log->
mutex));
242 ut_ad(!recv_no_log_write);
247 len_upper_limit = LOG_BUF_WRITE_MARGIN + (5 * len) / 4;
251 mutex_exit(&(log->
mutex));
265 #ifdef UNIV_LOG_ARCHIVE
266 if (log->archiving_state != LOG_ARCH_OFF) {
268 archived_lsn_age = log->
lsn - log->archived_lsn;
269 if (archived_lsn_age + len_upper_limit
270 > log->max_archived_lsn_age) {
274 mutex_exit(&(log->
mutex));
276 ut_ad(len_upper_limit <= log->max_archived_lsn_age);
287 #ifdef UNIV_LOG_DEBUG
304 log_t* log = log_sys;
311 ut_ad(!recv_no_log_write);
326 - LOG_BLOCK_TRL_SIZE;
341 log_block_set_checkpoint_no(log_block,
343 len += LOG_BLOCK_HDR_SIZE + LOG_BLOCK_TRL_SIZE;
361 srv_log_write_requests++;
368 log_max_modified_age_async()
371 if (srv_checkpoint_age_target) {
373 srv_checkpoint_age_target
374 - srv_checkpoint_age_target / 8));
384 log_max_checkpoint_age_async()
387 if (srv_checkpoint_age_target) {
389 srv_checkpoint_age_target));
406 ulint first_rec_group;
407 ib_uint64_t oldest_lsn;
409 log_t* log = log_sys;
410 ib_uint64_t checkpoint_age;
413 ut_ad(!recv_no_log_write);
421 if (first_rec_group == 0) {
444 if (!log_has_printed_chkp_warning
445 || difftime(time(NULL), log_last_warning_time) > 15) {
447 log_has_printed_chkp_warning = TRUE;
448 log_last_warning_time = time(NULL);
452 " InnoDB: ERROR: the age of the last"
453 " checkpoint is %lu,\n"
454 "InnoDB: which exceeds the log group"
456 "InnoDB: If you are using big"
457 " BLOB or TEXT rows, you must set the\n"
458 "InnoDB: combined size of log files"
459 " at least 10 times bigger than the\n"
460 "InnoDB: largest such row.\n",
461 (ulong) checkpoint_age,
466 if (checkpoint_age <= log_max_modified_age_async()) {
474 || lsn - oldest_lsn > log_max_modified_age_async()
475 || checkpoint_age > log_max_checkpoint_age_async()) {
481 #ifdef UNIV_LOG_DEBUG
489 #ifdef UNIV_LOG_ARCHIVE
495 log_pad_current_log_block(
void)
508 - LOG_BLOCK_TRL_SIZE;
510 for (i = 0; i < pad_length; i++) {
544 log_group_calc_size_offset(
552 return(offset - LOG_FILE_HDR_SIZE * (1 + offset / group->
file_size));
561 log_group_calc_real_offset(
569 return(offset + LOG_FILE_HDR_SIZE
570 * (1 + offset / (group->
file_size - LOG_FILE_HDR_SIZE)));
578 log_group_calc_lsn_offset(
585 ib_int64_t gr_lsn_size_offset;
586 ib_int64_t difference;
587 ib_int64_t group_size;
597 gr_lsn_size_offset = (ib_int64_t)
598 log_group_calc_size_offset(group->
lsn_offset, group);
604 difference = (ib_int64_t) (lsn - gr_lsn);
606 difference = (ib_int64_t) (gr_lsn - lsn);
608 difference = difference % group_size;
610 difference = group_size - difference;
613 offset = (gr_lsn_size_offset + difference) % group_size;
616 ut_a((
sizeof(ulint) != 4) || (offset < (((ib_int64_t) 1) << 32)));
623 return(log_group_calc_real_offset((ulint)offset, group));
628 UNIV_INTERN ibool log_debug_writes = FALSE;
638 ib_int64_t* log_file_offset,
640 ib_uint64_t first_header_lsn,
646 ib_int64_t log_file_size)
649 ib_int64_t capacity = log_file_size - LOG_FILE_HDR_SIZE;
651 ib_int64_t add_this_many;
653 if (lsn < first_header_lsn) {
654 add_this_many = 1 + (first_header_lsn - lsn)
655 / (capacity * (ib_int64_t)n_log_files);
657 * capacity * (ib_int64_t)n_log_files;
660 ut_a(lsn >= first_header_lsn);
662 file_no = ((ulint)((lsn - first_header_lsn) / capacity))
664 *log_file_offset = (lsn - first_header_lsn) % capacity;
666 *log_file_offset = *log_file_offset + LOG_FILE_HDR_SIZE;
671 #ifndef UNIV_HOTBACKUP
684 group->
lsn_offset = log_group_calc_lsn_offset(lsn, group);
695 log_calc_max_ages(
void)
701 ibool success = TRUE;
702 ulint smallest_capacity;
703 ulint archive_margin;
704 ulint smallest_archive_margin;
706 mutex_enter(&(log_sys->
mutex));
712 smallest_capacity = ULINT_MAX;
713 smallest_archive_margin = ULINT_MAX;
723 - LOG_ARCHIVE_EXTRA_MARGIN;
725 if (archive_margin < smallest_archive_margin) {
727 smallest_archive_margin = archive_margin;
734 smallest_capacity = smallest_capacity - smallest_capacity / 10;
741 free = LOG_CHECKPOINT_FREE_PER_THREAD * (10 + srv_thread_concurrency)
742 + LOG_CHECKPOINT_EXTRA_FREE;
743 if (free >= smallest_capacity / 2) {
748 margin = smallest_capacity - free;
753 margin = margin - margin / 10;
758 - margin / LOG_POOL_PREFLUSH_RATIO_ASYNC;
760 - margin / LOG_POOL_PREFLUSH_RATIO_SYNC;
763 / LOG_POOL_CHECKPOINT_RATIO_ASYNC;
766 #ifdef UNIV_LOG_ARCHIVE
767 log_sys->max_archived_lsn_age = smallest_archive_margin;
769 log_sys->max_archived_lsn_age_async = smallest_archive_margin
770 - smallest_archive_margin / LOG_ARCHIVE_RATIO_ASYNC;
773 mutex_exit(&(log_sys->
mutex));
777 "InnoDB: Error: ib_logfiles are too small"
778 " for innodb_thread_concurrency %lu.\n"
779 "InnoDB: The combined size of ib_logfiles"
780 " should be bigger than\n"
781 "InnoDB: 200 kB * innodb_thread_concurrency.\n"
782 "InnoDB: To get mysqld to start up, set"
783 " innodb_thread_concurrency in my.cnf\n"
784 "InnoDB: to a lower value, for example, to 8."
785 " After an ERROR-FREE shutdown\n"
786 "InnoDB: of mysqld you can adjust the size of"
787 " ib_logfiles, as explained in\n"
788 "InnoDB: " REFMAN
"adding-and-removing.html\n"
789 "InnoDB: Cannot continue operation."
790 " Calling exit(1).\n",
791 (ulong)srv_thread_concurrency);
806 log_sys =
static_cast<log_t *
>(mem_alloc(
sizeof(
log_t)));
808 mutex_create(log_sys_mutex_key, &log_sys->
mutex, SYNC_LOG);
810 mutex_create(log_flush_order_mutex_key,
812 SYNC_LOG_FLUSH_ORDER);
814 mutex_enter(&(log_sys->
mutex));
819 log_sys->
lsn = LOG_START_LSN;
822 ut_a(LOG_BUFFER_SIZE >= 4 * UNIV_PAGE_SIZE);
827 log_sys->
buf_size = LOG_BUFFER_SIZE;
829 memset(log_sys->
buf,
'\0', LOG_BUFFER_SIZE);
832 - LOG_BUF_FLUSH_MARGIN;
869 SYNC_NO_ORDER_CHECK);
877 #ifdef UNIV_LOG_ARCHIVE
879 log_sys->archiving_state = LOG_ARCH_OFF;
880 log_sys->archived_lsn = log_sys->
lsn;
881 log_sys->next_archived_lsn = 0;
883 log_sys->n_pending_archive_ios = 0;
886 SYNC_NO_ORDER_CHECK);
888 log_sys->archive_buf = NULL;
894 log_sys->archive_buf_size = 0;
906 log_sys->
buf_free = LOG_BLOCK_HDR_SIZE;
907 log_sys->
lsn = LOG_START_LSN + LOG_BLOCK_HDR_SIZE;
909 mutex_exit(&(log_sys->
mutex));
911 #ifdef UNIV_LOG_DEBUG
952 group->
state = LOG_GROUP_OK;
953 group->
lsn = LOG_START_LSN;
957 group->
file_header_bufs_ptr =
static_cast<unsigned char **
>(mem_alloc(
sizeof(byte*) * n_files));
958 group->
file_header_bufs =
static_cast<unsigned char **
>(mem_alloc(
sizeof(byte*) * n_files));
959 #ifdef UNIV_LOG_ARCHIVE
960 group->archive_file_header_bufs_ptr = mem_alloc(
961 sizeof(byte*) * n_files);
962 group->archive_file_header_bufs = mem_alloc(
sizeof(byte*) * n_files);
965 for (i = 0; i < n_files; i++) {
976 #ifdef UNIV_LOG_ARCHIVE
977 group->archive_file_header_bufs_ptr[i] = mem_alloc(
980 group->archive_file_header_bufs[i] =
ut_align(
981 group->archive_file_header_bufs_ptr[i],
984 memset(*(group->archive_file_header_bufs + i),
'\0',
989 #ifdef UNIV_LOG_ARCHIVE
990 group->archive_space_id = archive_space_id;
992 group->archived_file_no = 0;
993 group->archived_offset = 0;
1004 ut_a(log_calc_max_ages());
1011 log_flush_do_unlocks(
1029 if (code & LOG_UNLOCK_NONE_FLUSHED_LOCK) {
1033 if (code & LOG_UNLOCK_FLUSH_LOCK) {
1044 log_group_check_flush_completion(
1052 if (log_debug_writes) {
1054 "Log flushed first to group %lu\n",
1061 return(LOG_UNLOCK_NONE_FLUSHED_LOCK);
1067 fprintf(stderr,
"Log flushed to group %lu\n",
1079 log_sys_check_flush_completion(
void)
1103 move_end - move_start);
1109 return(LOG_UNLOCK_FLUSH_LOCK);
1125 #ifdef UNIV_LOG_ARCHIVE
1126 if ((byte*)group == &log_archive_io) {
1129 log_io_complete_archive();
1135 if ((ulint)group & 0x1UL) {
1147 if (log_debug_writes) {
1149 "Checkpoint info written to group %lu\n",
1153 log_io_complete_checkpoint();
1164 && srv_flush_log_at_trx_commit != 2) {
1169 mutex_enter(&(log_sys->
mutex));
1170 ut_ad(!recv_no_log_write);
1178 unlock = log_group_check_flush_completion(group);
1179 unlock = unlock | log_sys_check_flush_completion();
1181 log_flush_do_unlocks(unlock);
1183 mutex_exit(&(log_sys->
mutex));
1190 log_group_file_header_flush(
1195 ib_uint64_t start_lsn)
1202 ut_ad(!recv_no_log_write);
1203 ut_a(nth_file < group->n_files);
1211 memcpy(buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
" ", 4);
1214 srv_log_block_size);
1216 dest_offset = nth_file * group->
file_size;
1219 if (log_debug_writes) {
1221 "Writing log file header to group %lu file %lu\n",
1222 (ulong) group->
id, (ulong) nth_file);
1228 srv_os_log_pending_writes++;
1231 dest_offset / UNIV_PAGE_SIZE,
1232 dest_offset % UNIV_PAGE_SIZE,
1236 srv_os_log_pending_writes--;
1246 log_block_store_checksum(
1263 ib_uint64_t start_lsn,
1266 ulint new_data_offset)
1277 ut_ad(!recv_no_log_write);
1281 if (new_data_offset == 0) {
1282 write_header = TRUE;
1284 write_header = FALSE;
1292 next_offset = log_group_calc_lsn_offset(start_lsn, group);
1294 if ((next_offset % group->
file_size == LOG_FILE_HDR_SIZE)
1298 log_group_file_header_flush(group,
1314 if (log_debug_writes) {
1317 "Writing log file segment to group %lu"
1318 " offset %lu len %lu\n"
1319 "start lsn %"PRIu64
"\n"
1320 "First block n:o %lu last block n:o %lu\n",
1321 (ulong) group->
id, (ulong) next_offset,
1348 srv_os_log_pending_writes++;
1351 next_offset / UNIV_PAGE_SIZE,
1352 next_offset % UNIV_PAGE_SIZE, write_len, buf, group);
1354 srv_os_log_pending_writes--;
1356 srv_os_log_written+= write_len;
1360 if (write_len < len) {
1361 start_lsn += write_len;
1365 write_header = TRUE;
1385 ibool flush_to_disk)
1395 ulint loop_count = 0;
1410 ut_ad(loop_count < 5);
1413 if (loop_count > 2) {
1414 fprintf(stderr,
"Log loop count %lu\n", loop_count);
1419 mutex_enter(&(log_sys->
mutex));
1420 ut_ad(!recv_no_log_write);
1425 mutex_exit(&(log_sys->
mutex));
1433 && wait != LOG_WAIT_ALL_GROUPS))) {
1435 mutex_exit(&(log_sys->
mutex));
1459 mutex_exit(&(log_sys->
mutex));
1473 mutex_exit(&(log_sys->
mutex));
1479 if (log_debug_writes) {
1481 "Writing log from %"PRIu64
" up to lsn %"PRIu64
"\n",
1501 ut_ad(area_end - area_start > 0);
1505 if (flush_to_disk) {
1511 log_block_set_flush_bit(log_sys->
buf + area_start, TRUE);
1512 log_block_set_checkpoint_no(
1533 group, log_sys->
buf + area_start,
1534 area_end - area_start,
1537 start_offset - area_start);
1544 mutex_exit(&(log_sys->
mutex));
1553 }
else if (flush_to_disk) {
1561 mutex_enter(&(log_sys->
mutex));
1571 unlock = log_group_check_flush_completion(group);
1572 unlock = unlock | log_sys_check_flush_completion();
1574 log_flush_do_unlocks(unlock);
1576 mutex_exit(&(log_sys->
mutex));
1581 mutex_exit(&(log_sys->
mutex));
1584 case LOG_WAIT_ONE_GROUP:
1587 case LOG_WAIT_ALL_GROUPS:
1608 mutex_enter(&(log_sys->
mutex));
1612 mutex_exit(&(log_sys->
mutex));
1630 mutex_enter(&(log_sys->
mutex));
1634 mutex_exit(&(log_sys->
mutex));
1645 log_flush_margin(
void)
1648 log_t* log = log_sys;
1649 ib_uint64_t lsn = 0;
1651 mutex_enter(&(log->
mutex));
1663 mutex_exit(&(log->
mutex));
1680 ib_uint64_t new_oldest,
1707 if (n_pages == ULINT_UNDEFINED) {
1719 log_complete_checkpoint(
void)
1736 log_io_complete_checkpoint(
void)
1739 mutex_enter(&(log_sys->
mutex));
1746 log_complete_checkpoint();
1749 mutex_exit(&(log_sys->
mutex));
1756 log_checkpoint_set_nth_group_info(
1766 + 8 * n + LOG_CHECKPOINT_ARCHIVED_FILE_NO, file_no);
1768 + 8 * n + LOG_CHECKPOINT_ARCHIVED_OFFSET, offset);
1785 + 8 * n + LOG_CHECKPOINT_ARCHIVED_FILE_NO);
1787 + 8 * n + LOG_CHECKPOINT_ARCHIVED_OFFSET);
1794 log_group_checkpoint(
1799 #ifdef UNIV_LOG_ARCHIVE
1800 ib_uint64_t archived_lsn;
1801 ib_uint64_t next_archived_lsn;
1817 log_group_calc_lsn_offset(
1822 #ifdef UNIV_LOG_ARCHIVE
1823 if (log_sys->archiving_state == LOG_ARCH_OFF) {
1824 archived_lsn = IB_ULONGLONG_MAX;
1826 archived_lsn = log_sys->archived_lsn;
1828 if (archived_lsn != log_sys->next_archived_lsn) {
1829 next_archived_lsn = log_sys->next_archived_lsn;
1837 (ib_uint64_t)log_group_calc_lsn_offset(
1843 log_checkpoint_set_nth_group_info(buf, i, 0, 0);
1849 log_checkpoint_set_nth_group_info(buf, group2->
id,
1850 #ifdef UNIV_LOG_ARCHIVE
1851 group2->archived_file_no,
1852 group2->archived_offset
1865 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
1872 log_fsp_current_free_limit);
1875 LOG_CHECKPOINT_FSP_MAGIC_N_VAL);
1881 write_offset = LOG_CHECKPOINT_1;
1883 write_offset = LOG_CHECKPOINT_2;
1902 write_offset / UNIV_PAGE_SIZE,
1903 write_offset % UNIV_PAGE_SIZE,
1905 buf, ((byte*)group + 1));
1907 ut_ad(((ulint)group & 0x1UL) == 0);
1912 #ifdef UNIV_HOTBACKUP
1918 log_reset_first_header_and_checkpoint(
1933 lsn = start + LOG_BLOCK_HDR_SIZE;
1936 strcpy((
char*) hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
1939 + (LOG_FILE_WAS_CREATED_BY_HOT_BACKUP
1940 + (
sizeof "ibbackup ") - 1));
1941 buf = hdr_buf + LOG_CHECKPOINT_1;
1947 LOG_FILE_HDR_SIZE + LOG_BLOCK_HDR_SIZE);
1957 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
1966 #ifndef UNIV_HOTBACKUP
1981 field / UNIV_PAGE_SIZE, field % UNIV_PAGE_SIZE,
1999 log_group_checkpoint(group);
2024 ib_uint64_t oldest_lsn;
2034 mutex_enter(&(log_sys->
mutex));
2036 ut_ad(!recv_no_log_write);
2037 oldest_lsn = log_buf_pool_get_oldest_modification();
2039 mutex_exit(&(log_sys->
mutex));
2051 mutex_enter(&(log_sys->
mutex));
2056 mutex_exit(&(log_sys->
mutex));
2066 mutex_exit(&(log_sys->
mutex));
2080 if (log_debug_writes) {
2081 fprintf(stderr,
"Making checkpoint no %lu at lsn %"PRIu64
"\n",
2089 mutex_exit(&(log_sys->
mutex));
2131 log_checkpoint_margin(
void)
2134 log_t* log = log_sys;
2136 ib_uint64_t checkpoint_age;
2137 ib_uint64_t advance;
2138 ib_uint64_t oldest_lsn;
2140 ibool checkpoint_sync;
2141 ibool do_checkpoint;
2145 checkpoint_sync = FALSE;
2146 do_checkpoint = FALSE;
2148 mutex_enter(&(log->
mutex));
2149 ut_ad(!recv_no_log_write);
2152 mutex_exit(&(log->
mutex));
2157 oldest_lsn = log_buf_pool_get_oldest_modification();
2159 age = log->
lsn - oldest_lsn;
2167 }
else if (age > log_max_modified_age_async()) {
2170 advance = age - log_max_modified_age_async();
2180 checkpoint_sync = TRUE;
2182 do_checkpoint = TRUE;
2184 }
else if (checkpoint_age > log_max_checkpoint_age_async()) {
2187 do_checkpoint = TRUE;
2194 mutex_exit(&(log->
mutex));
2197 ib_uint64_t new_oldest = oldest_lsn + advance;
2207 if (sync && !success) {
2208 mutex_enter(&(log->
mutex));
2212 mutex_exit(&(log->
mutex));
2217 if (do_checkpoint) {
2220 if (checkpoint_sync) {
2236 ib_uint64_t start_lsn,
2237 ib_uint64_t end_lsn)
2240 ulint source_offset;
2245 sync = (type == LOG_RECOVER);
2247 source_offset = log_group_calc_lsn_offset(start_lsn, group);
2249 len = (ulint) (end_lsn - start_lsn);
2258 #ifdef UNIV_LOG_ARCHIVE
2259 if (type == LOG_ARCHIVE) {
2261 log_sys->n_pending_archive_ios++;
2268 source_offset / UNIV_PAGE_SIZE, source_offset % UNIV_PAGE_SIZE,
2274 if (start_lsn != end_lsn) {
2280 #ifdef UNIV_LOG_ARCHIVE
2293 sprintf(buf,
"%sib_arch_log_%010lu", srv_arch_dir, (ulong) file_no);
2300 log_group_archive_file_header_write(
2306 ib_uint64_t start_lsn)
2314 ut_a(nth_file < group->n_files);
2316 buf = *(group->archive_file_header_bufs + nth_file);
2324 dest_offset = nth_file * group->
file_size;
2328 fil_io(OS_FILE_WRITE | OS_FILE_LOG, TRUE, group->archive_space_id,
2329 dest_offset / UNIV_PAGE_SIZE,
2330 dest_offset % UNIV_PAGE_SIZE,
2332 buf, &log_archive_io);
2339 log_group_archive_completed_header_write(
2344 ib_uint64_t end_lsn)
2350 ut_a(nth_file < group->n_files);
2352 buf = *(group->archive_file_header_bufs + nth_file);
2357 dest_offset = nth_file * group->
file_size + LOG_FILE_ARCH_COMPLETED;
2361 fil_io(OS_FILE_WRITE | OS_FILE_LOG, TRUE, group->archive_space_id,
2362 dest_offset / UNIV_PAGE_SIZE,
2363 dest_offset % UNIV_PAGE_SIZE,
2365 buf + LOG_FILE_ARCH_COMPLETED,
2378 ib_uint64_t start_lsn;
2379 ib_uint64_t end_lsn;
2390 start_lsn = log_sys->archived_lsn;
2394 end_lsn = log_sys->next_archived_lsn;
2398 buf = log_sys->archive_buf;
2402 next_offset = group->archived_offset;
2404 if ((next_offset % group->
file_size == 0)
2410 if (next_offset % group->
file_size == 0) {
2411 open_mode = OS_FILE_CREATE;
2417 group->archived_file_no + n_files);
2419 file_handle = os_file_create(innodb_file_log_key,
2424 if (!ret && (open_mode == OS_FILE_CREATE)) {
2425 file_handle = os_file_create(
2432 "InnoDB: Cannot create or open"
2433 " archive log file %s.\n"
2434 "InnoDB: Cannot continue operation.\n"
2435 "InnoDB: Check that the log archive"
2436 " directory exists,\n"
2437 "InnoDB: you have access rights to it, and\n"
2438 "InnoDB: there is space available.\n", name);
2443 if (log_debug_writes) {
2444 fprintf(stderr,
"Created archive file %s\n", name);
2448 ret = os_file_close(file_handle);
2455 group->archive_space_id, FALSE);
2457 if (next_offset % group->
file_size == 0) {
2458 log_group_archive_file_header_write(
2460 group->archived_file_no + n_files,
2463 next_offset += LOG_FILE_HDR_SIZE;
2467 len = end_lsn - start_lsn;
2475 if (log_debug_writes) {
2477 "Archiving starting at lsn %"PRIu64
", len %lu"
2480 (ulong) len, (ulong) group->
id);
2484 log_sys->n_pending_archive_ios++;
2488 fil_io(OS_FILE_WRITE | OS_FILE_LOG, FALSE, group->archive_space_id,
2489 next_offset / UNIV_PAGE_SIZE, next_offset % UNIV_PAGE_SIZE,
2497 if (next_offset % group->
file_size == 0) {
2501 if (end_lsn != start_lsn) {
2506 group->next_archived_file_no = group->archived_file_no + n_files;
2507 group->next_archived_offset = next_offset % group->
file_size;
2517 log_archive_groups(
void)
2526 log_group_archive(group);
2534 log_archive_write_complete_groups(
void)
2541 ib_uint64_t start_lsn;
2542 ib_uint64_t end_lsn;
2549 group->archived_file_no = group->next_archived_file_no;
2550 group->archived_offset = group->next_archived_offset;
2555 n_files = (UNIV_PAGE_SIZE
2560 end_offset = group->archived_offset;
2562 if (end_offset % group->
file_size == 0) {
2564 trunc_files = n_files;
2566 trunc_files = n_files - 1;
2570 if (log_debug_writes && trunc_files) {
2572 "Complete file(s) archived to group %lu\n",
2578 start_lsn = log_sys->next_archived_lsn
2579 - (end_offset - LOG_FILE_HDR_SIZE + trunc_files
2580 * (group->
file_size - LOG_FILE_HDR_SIZE));
2581 end_lsn = start_lsn;
2583 for (i = 0; i < trunc_files; i++) {
2585 end_lsn += group->
file_size - LOG_FILE_HDR_SIZE;
2590 log_group_archive_completed_header_write(group, i, end_lsn);
2593 fil_space_truncate_start(group->archive_space_id,
2597 if (log_debug_writes) {
2598 fputs(
"Archiving writes completed\n", stderr);
2607 log_archive_check_completion_low(
void)
2612 if (log_sys->n_pending_archive_ios == 0
2613 && log_sys->archiving_phase == LOG_ARCHIVE_READ) {
2616 if (log_debug_writes) {
2617 fputs(
"Archiving read completed\n", stderr);
2623 log_sys->archiving_phase = LOG_ARCHIVE_WRITE;
2625 log_archive_groups();
2628 if (log_sys->n_pending_archive_ios == 0
2629 && log_sys->archiving_phase == LOG_ARCHIVE_WRITE) {
2631 log_archive_write_complete_groups();
2633 log_sys->archived_lsn = log_sys->next_archived_lsn;
2635 rw_lock_x_unlock_gen(&(log_sys->archive_lock), LOG_ARCHIVE);
2643 log_io_complete_archive(
void)
2648 mutex_enter(&(log_sys->
mutex));
2652 mutex_exit(&(log_sys->
mutex));
2656 mutex_enter(&(log_sys->
mutex));
2658 ut_ad(log_sys->n_pending_archive_ios > 0);
2660 log_sys->n_pending_archive_ios--;
2662 log_archive_check_completion_low();
2664 mutex_exit(&(log_sys->
mutex));
2678 ibool calc_new_limit;
2679 ib_uint64_t start_lsn;
2680 ib_uint64_t limit_lsn;
2682 calc_new_limit = TRUE;
2684 mutex_enter(&(log_sys->
mutex));
2686 switch (log_sys->archiving_state) {
2689 mutex_exit(&(log_sys->
mutex));
2694 case LOG_ARCH_STOPPED:
2695 case LOG_ARCH_STOPPING2:
2696 mutex_exit(&(log_sys->
mutex));
2698 os_event_wait(log_sys->archiving_on);
2703 start_lsn = log_sys->archived_lsn;
2705 if (calc_new_limit) {
2707 limit_lsn = start_lsn + log_sys->archive_buf_size;
2709 *n_bytes = log_sys->archive_buf_size;
2711 if (limit_lsn >= log_sys->
lsn) {
2718 if (log_sys->archived_lsn >= limit_lsn) {
2725 mutex_exit(&(log_sys->
mutex));
2729 calc_new_limit = FALSE;
2734 if (log_sys->n_pending_archive_ios > 0) {
2737 mutex_exit(&(log_sys->
mutex));
2741 rw_lock_s_unlock(&(log_sys->archive_lock));
2744 *n_bytes = log_sys->archive_buf_size;
2749 rw_lock_x_lock_gen(&(log_sys->archive_lock), LOG_ARCHIVE);
2751 log_sys->archiving_phase = LOG_ARCHIVE_READ;
2753 log_sys->next_archived_lsn = limit_lsn;
2756 if (log_debug_writes) {
2758 "Archiving from lsn %"PRIu64
" to lsn %"PRIu64
"\n",
2759 log_sys->archived_lsn, limit_lsn);
2767 start_lsn, limit_lsn);
2769 mutex_exit(&(log_sys->
mutex));
2773 rw_lock_s_unlock(&(log_sys->archive_lock));
2776 *n_bytes = log_sys->archive_buf_size;
2786 log_archive_all(
void)
2789 ib_uint64_t present_lsn;
2792 mutex_enter(&(log_sys->
mutex));
2794 if (log_sys->archiving_state == LOG_ARCH_OFF) {
2795 mutex_exit(&(log_sys->
mutex));
2800 present_lsn = log_sys->
lsn;
2802 mutex_exit(&(log_sys->
mutex));
2804 log_pad_current_log_block();
2807 mutex_enter(&(log_sys->
mutex));
2809 if (present_lsn <= log_sys->archived_lsn) {
2811 mutex_exit(&(log_sys->
mutex));
2816 mutex_exit(&(log_sys->
mutex));
2827 log_archive_close_groups(
2829 ibool increment_file_count)
2837 if (log_sys->archiving_state == LOG_ARCH_OFF) {
2844 trunc_len = UNIV_PAGE_SIZE
2846 if (trunc_len > 0) {
2852 log_group_archive_completed_header_write(
2853 group, 0, log_sys->archived_lsn);
2855 fil_space_truncate_start(group->archive_space_id,
2857 if (increment_file_count) {
2858 group->archived_offset = 0;
2859 group->archived_file_no += 2;
2863 if (log_debug_writes) {
2865 "Incrementing arch file no to %lu"
2866 " in log group %lu\n",
2867 (ulong) group->archived_file_no + 2,
2887 mutex_enter(&(log_sys->
mutex));
2889 if (log_sys->archiving_state != LOG_ARCH_ON) {
2891 mutex_exit(&(log_sys->
mutex));
2896 log_sys->archiving_state = LOG_ARCH_STOPPING;
2898 mutex_exit(&(log_sys->
mutex));
2902 mutex_enter(&(log_sys->
mutex));
2904 log_sys->archiving_state = LOG_ARCH_STOPPING2;
2907 mutex_exit(&(log_sys->
mutex));
2912 rw_lock_s_unlock(&(log_sys->archive_lock));
2914 mutex_enter(&(log_sys->
mutex));
2919 log_archive_close_groups(TRUE);
2921 mutex_exit(&(log_sys->
mutex));
2932 mutex_enter(&(log_sys->
mutex));
2934 log_sys->archiving_state = LOG_ARCH_STOPPED;
2936 mutex_exit(&(log_sys->
mutex));
2949 mutex_enter(&(log_sys->
mutex));
2951 if (log_sys->archiving_state != LOG_ARCH_STOPPED) {
2953 mutex_exit(&(log_sys->
mutex));
2958 log_sys->archiving_state = LOG_ARCH_ON;
2962 mutex_exit(&(log_sys->
mutex));
2976 mutex_enter(&(log_sys->
mutex));
2978 if (log_sys->archiving_state == LOG_ARCH_STOPPED
2979 || log_sys->archiving_state == LOG_ARCH_OFF) {
2981 log_sys->archiving_state = LOG_ARCH_OFF;
2985 mutex_exit(&(log_sys->
mutex));
2990 mutex_exit(&(log_sys->
mutex));
3007 mutex_enter(&(log_sys->
mutex));
3009 if (log_sys->archiving_state == LOG_ARCH_OFF) {
3011 log_sys->archiving_state = LOG_ARCH_ON;
3013 log_sys->archived_lsn
3016 mutex_exit(&(log_sys->
mutex));
3021 mutex_exit(&(log_sys->
mutex));
3032 log_archive_margin(
void)
3035 log_t* log = log_sys;
3040 mutex_enter(&(log->
mutex));
3042 if (log->archiving_state == LOG_ARCH_OFF) {
3043 mutex_exit(&(log->
mutex));
3048 age = log->
lsn - log->archived_lsn;
3050 if (age > log->max_archived_lsn_age) {
3056 }
else if (age > log->max_archived_lsn_age_async) {
3064 mutex_exit(&(log->
mutex));
3069 mutex_exit(&(log->
mutex));
3094 log_checkpoint_margin();
3096 #ifdef UNIV_LOG_ARCHIVE
3097 log_archive_margin();
3100 mutex_enter(&(log_sys->
mutex));
3101 ut_ad(!recv_no_log_write);
3105 mutex_exit(&(log_sys->
mutex));
3110 mutex_exit(&(log_sys->
mutex));
3126 if (srv_print_verbose_log) {
3128 fprintf(stderr,
" InnoDB: Starting shutdown...\n");
3137 mutex_enter(&kernel_mutex);
3143 if (srv_fast_shutdown < 2
3144 && (srv_error_monitor_active
3145 || srv_lock_timeout_active
3146 || srv_monitor_active)) {
3148 mutex_exit(&kernel_mutex);
3161 if (! srv_apply_log_only) {
3165 mutex_exit(&kernel_mutex);
3171 if (srv_fast_shutdown == 2) {
3182 mutex_exit(&kernel_mutex);
3187 mutex_exit(&kernel_mutex);
3195 mutex_enter(&(log_sys->
mutex));
3198 #ifdef UNIV_LOG_ARCHIVE
3199 || log_sys->n_pending_archive_ios
3203 mutex_exit(&(log_sys->
mutex));
3208 mutex_exit(&(log_sys->
mutex));
3215 #ifdef UNIV_LOG_ARCHIVE
3221 mutex_enter(&(log_sys->
mutex));
3226 #ifdef UNIV_LOG_ARCHIVE
3227 || (srv_log_archive_on
3228 && lsn != log_sys->archived_lsn + LOG_BLOCK_HDR_SIZE)
3232 mutex_exit(&(log_sys->
mutex));
3239 #ifdef UNIV_LOG_ARCHIVE
3247 log_archive_close_groups(TRUE);
3250 mutex_exit(&(log_sys->
mutex));
3255 "InnoDB: Warning: some background thread woke up"
3256 " during shutdown\n");
3283 drizzled::errmsg_printf(drizzled::error::ERROR,
3284 "InnoDB: Error: log sequence number at shutdown %"PRIu64
" is lower than at startup %"PRIu64
"!",
3303 #ifdef UNIV_LOG_DEBUG
3315 ib_uint64_t buf_start_lsn)
3317 ib_uint64_t contiguous_lsn;
3318 ib_uint64_t scanned_lsn;
3337 ut_memcpy(scan_buf, start, end - start);
3341 * UNIV_PAGE_SIZE, FALSE, scan_buf, end - start,
3344 &contiguous_lsn, &scanned_lsn);
3346 ut_a(scanned_lsn == buf_start_lsn + len);
3364 if (0 == mutex_enter_nowait(&(log_sys->
mutex))) {
3365 *lsn = log_sys->
lsn;
3367 mutex_exit(&(log_sys->
mutex));
3383 double time_elapsed;
3384 time_t current_time;
3386 mutex_enter(&(log_sys->
mutex));
3389 "Log sequence number %"PRIu64
"\n"
3390 "Log flushed up to %"PRIu64
"\n"
3391 "Last checkpoint at %"PRIu64
"\n",
3397 "Max checkpoint age %lu\n"
3398 "Checkpoint age target %lu\n"
3399 "Modified age %"PRIu64
"\n"
3400 "Checkpoint age %"PRIu64
"\n",
3402 log_max_checkpoint_age_async(),
3403 log_sys->
lsn - log_buf_pool_get_oldest_modification(),
3406 current_time = time(NULL);
3408 time_elapsed = 0.001 + difftime(current_time,
3411 "%lu pending log writes, %lu pending chkp writes\n"
3412 "%lu log i/o's done, %.2f log i/o's/second\n",
3422 mutex_exit(&(log_sys->
mutex));
3446 for (i = 0; i < group->
n_files; i++) {
3448 #ifdef UNIV_LOG_ARCHIVE
3449 mem_free(group->archive_file_header_bufs_ptr[i]);
3456 #ifdef UNIV_LOG_ARCHIVE
3457 mem_free(group->archive_file_header_bufs_ptr);
3458 mem_free(group->archive_file_header_bufs);
3483 log_group_close(prev_group);
3487 log_sys->buf_ptr = NULL;
3488 log_sys->
buf = NULL;
3489 mem_free(log_sys->checkpoint_buf_ptr);
3490 log_sys->checkpoint_buf_ptr = NULL;
3498 mutex_free(&log_sys->
mutex);
3500 #ifdef UNIV_LOG_ARCHIVE
3501 rw_lock_free(&log_sys->archive_lock);
3505 #ifdef UNIV_LOG_DEBUG
3506 recv_sys_debug_free();
3519 if (log_sys != NULL) {
#define UT_LIST_GET_LEN(BASE)
UNIV_INTERN void log_io_complete(log_group_t *group)
UNIV_INTERN ulint log_calc_where_lsn_is(ib_int64_t *log_file_offset, ib_uint64_t first_header_lsn, ib_uint64_t lsn, ulint n_log_files, ib_int64_t log_file_size)
#define rw_lock_create(K, L, level)
UNIV_INLINE void log_block_set_checksum(byte *log_block, ulint checksum)
ib_uint64_t written_to_some_lsn
#define UT_LIST_GET_NEXT(NAME, N)
#define MLOG_DUMMY_RECORD
UNIV_INLINE void * ut_memmove(void *dest, const void *sour, ulint n)
UNIV_INTERN ulint fil_io(ulint type, ibool sync, ulint space_id, ulint zip_size, ulint block_offset, ulint byte_offset, ulint len, void *buf, void *message)
UNIV_INTERN void recv_sys_mem_free(void)
UNIV_INTERN void log_make_checkpoint_at(ib_uint64_t lsn, ibool write_always)
UNIV_INLINE void mach_write_to_4(byte *b, ulint n)
UNIV_INTERN void log_buffer_sync_in_background(ibool flush)
UNIV_INTERN void logs_empty_and_mark_files_at_shutdown(void)
UNIV_INTERN void log_group_read_checkpoint_info(log_group_t *group, ulint field)
ib_uint64_t flushed_to_disk_lsn
UNIV_INTERN ibool buf_pool_check_no_pending_io(void)
UNIV_INTERN void log_init(void)
UNIV_INTERN void log_group_read_log_seg(ulint type, byte *buf, log_group_t *group, ib_uint64_t start_lsn, ib_uint64_t end_lsn)
UNIV_INLINE void * ut_memcpy(void *dest, const void *sour, ulint n)
UNIV_INTERN os_event_t os_event_create(const char *name)
UNIV_INLINE void mach_write_to_8(byte *b, ib_uint64_t n)
UNIV_INTERN void log_print(FILE *file)
UNIV_INTERN void fil_flush(ulint space_id)
UNIV_INLINE ulint log_block_convert_lsn_to_no(ib_uint64_t lsn)
ulint recv_n_pool_free_frames
UNIV_INTERN void fil_node_create(const char *name, ulint size, ulint id, ibool is_raw)
ulint adm_checkpoint_interval
UNIV_INTERN void log_group_write_buf(log_group_t *group, byte *buf, ulint len, ib_uint64_t start_lsn, ulint new_data_offset)
UNIV_INTERN ulint log_archive_stop(void)
UNIV_INTERN ulint log_archive_archivelog(void)
UNIV_INTERN void log_write_up_to(ib_uint64_t lsn, ulint wait, ibool flush_to_disk)
ib_uint64_t next_checkpoint_no
ib_uint64_t recovered_lsn
ulint max_checkpoint_age_async
UNIV_INTERN ulint log_archive_noarchivelog(void)
UNIV_INTERN void recv_sys_close(void)
UNIV_INTERN void log_check_margins(void)
UNIV_INLINE void log_block_set_first_rec_group(byte *log_block, ulint offset)
ulint max_modified_age_async
byte * checkpoint_buf_ptr
UNIV_INLINE ulint ut_min(ulint n1, ulint n2)
UNIV_INLINE void log_block_set_data_len(byte *log_block, ulint len)
#define UT_LIST_REMOVE(NAME, BASE, N)
#define OS_FILE_LOG_BLOCK_SIZE
UNIV_INLINE ulint log_block_get_data_len(const byte *log_block)
UNIV_INTERN ibool log_peek_lsn(ib_uint64_t *lsn)
UNIV_INTERN void log_buffer_flush_to_disk(void)
UNIV_INTERN ib_uint64_t buf_pool_get_oldest_modification(void)
UNIV_INTERN ibool log_archive_do(ibool sync, ulint *n_bytes)
ibool check_flush_or_checkpoint
UNIV_INTERN void recv_sys_create(void)
UNIV_INTERN void log_group_init(ulint id, ulint n_files, ulint file_size, ulint space_id, ulint archive_space_id)
UNIV_INTERN void log_fsp_current_free_limit_set_and_checkpoint(ulint limit)
UNIV_INLINE void log_block_init(byte *log_block, ib_uint64_t lsn)
UNIV_INLINE void * ut_align(const void *ptr, ulint align_no)
UNIV_INTERN void os_event_set(os_event_t event)
UNIV_INLINE ulint log_block_get_first_rec_group(const byte *log_block)
UNIV_INTERN void os_thread_sleep(ulint tm)
UNIV_INTERN void log_refresh_stats(void)
UNIV_INTERN void recv_apply_hashed_log_recs(ibool allow_ibuf)
ib_uint64_t next_checkpoint_lsn
#define ut_calc_align_down(n, m)
UNIV_INTERN ib_int64_t os_event_reset(os_event_t event)
ib_uint64_t written_to_all_lsn
UNIV_INLINE ulint buf_pool_get_n_pages(void)
UNIV_INTERN void fil_close_all_files(void)
ib_uint64_t srv_start_lsn
UNIV_INTERN ulint log_archive_start(void)
UNIV_INLINE void * ut_align_down(const void *ptr, ulint align_no) __attribute__((const ))
UNIV_INTERN ib_uint64_t log_reserve_and_open(ulint len)
UNIV_INTERN ulint fil_space_get_size(ulint id)
ib_uint64_t last_checkpoint_lsn
UNIV_INTERN void recv_sys_init(ulint available_memory)
UNIV_INLINE ib_uint64_t ut_uint64_align_down(ib_uint64_t n, ulint align_no)
UNIV_INTERN ulint buf_flush_list(ulint min_n, ib_uint64_t lsn_limit)
#define UT_LIST_ADD_LAST(NAME, BASE, N)
#define UT_LIST_GET_FIRST(BASE)
UNIV_INTERN ibool buf_all_freed(void)
os_event_t one_flushed_event
UNIV_INTERN ulint log_group_get_capacity(const log_group_t *group)
#define rw_lock_s_lock(M)
UNIV_INLINE ulint ut_fold_binary(const byte *str, ulint len) __attribute__((pure))
UNIV_INTERN void log_group_set_fields(log_group_t *group, ib_uint64_t lsn)
ib_uint64_t parse_start_lsn
UNIV_INTERN void log_archived_file_name_gen(char *buf, ulint id, ulint file_no)
UNIV_INTERN ibool recv_scan_log_recs(ulint available_memory, ibool store_to_hash, const byte *buf, ulint len, ib_uint64_t start_lsn, ib_uint64_t *contiguous_lsn, ib_uint64_t *group_scanned_lsn)
UNIV_INTERN ib_uint64_t log_close(void)
#define UT_LIST_INIT(BASE)
UNIV_INTERN void ut_sprintf_timestamp(char *buf)
ib_uint64_t current_flush_lsn
ulint scanned_checkpoint_no
UNIV_INTERN ibool log_checkpoint(ibool sync, ibool write_always)
UNIV_INTERN void os_event_free(os_event_t event)
ibool recv_no_ibuf_operations
UNIV_INTERN void buf_flush_wait_batch_end(buf_pool_t *buf_pool, enum buf_flush type)
UNIV_INLINE ulint mach_read_from_4(const byte *b) __attribute__((nonnull
#define ut_calc_align(n, m)
byte ** file_header_bufs_ptr
UNIV_INTERN void fil_flush_file_spaces(ulint purpose)
UNIV_INTERN void ut_print_timestamp(FILE *file)
UNIV_INTERN ulint fil_write_flushed_lsn_to_data_files(ib_uint64_t lsn, ulint arch_log_no)
UNIV_INTERN ibool srv_is_any_background_thread_active(void)
os_event_t no_flush_event
UNIV_INTERN void log_groups_write_checkpoint_info(void)
UNIV_INTERN ibool log_preflush_pool_modified_pages(ib_uint64_t new_oldest, ibool sync)
UNIV_INLINE ulint log_block_calc_checksum(const byte *block)
UNIV_INLINE void log_release(void)
ulint trx_n_mysql_transactions
UNIV_INLINE ibool recv_recovery_is_on(void)
UNIV_INLINE ulint log_block_get_hdr_no(const byte *log_block)
ulint n_pending_checkpoint_writes
UNIV_INTERN void log_checkpoint_get_nth_group_info(const byte *buf, ulint n, ulint *file_no, ulint *offset)
ib_uint64_t srv_shutdown_lsn
mutex_t log_flush_order_mutex
time_t last_printout_time
rw_lock_t checkpoint_lock
ulint srv_buf_pool_instances
ulint max_modified_age_sync
UNIV_INTERN void log_write_low(byte *str, ulint str_len)
UNIV_INLINE ulint buf_pool_get_curr_size(void)