33 #include "buf0checksum.h"
39 #ifndef UNIV_HOTBACKUP
43 UNIV_INTERN mysql_pfs_key_t buf_dblwr_mutex_key;
68 && page_no < buf_dblwr->block1
74 && page_no < buf_dblwr->block2
97 buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
145 mutex_create(buf_dblwr_mutex_key,
163 ut_malloc((1 + buf_size) * UNIV_PAGE_SIZE));
207 buf_dblwr_init(doublewrite);
215 "Doublewrite buffer not found: creating new");
219 + FSP_EXTENT_SIZE / 2 + 100)
223 "Cannot create doublewrite buffer: you must "
224 "increase your buffer pool size. Cannot continue "
230 block2 =
fseg_create(TRX_SYS_SPACE, TRX_SYS_PAGE_NO,
237 buf_block_dbg_add_level(block2, SYNC_NO_ORDER_CHECK);
239 if (block2 == NULL) {
241 "Cannot create doublewrite buffer: you must "
242 "increase your tablespace size. "
243 "Cannot continue operation.");
255 + FSP_EXTENT_SIZE / 2; i++) {
257 fseg_header, prev_page_no + 1, FSP_UP, &mtr);
258 if (new_block == NULL) {
260 "Cannot create doublewrite buffer: you must "
261 "increase your tablespace size. "
262 "Cannot continue operation.");
279 if (i == FSP_EXTENT_SIZE / 2) {
280 ut_a(page_no == FSP_EXTENT_SIZE);
289 }
else if (i == FSP_EXTENT_SIZE / 2
291 ut_a(page_no == 2 * FSP_EXTENT_SIZE);
300 }
else if (i > FSP_EXTENT_SIZE / 2) {
301 ut_a(page_no == prev_page_no + 1);
304 if (((i + 1) & 15) == 0) {
317 fseg_header = doublewrite
321 prev_page_no = page_no;
344 ib_logf(IB_LOG_LEVEL_INFO,
"Doublewrite buffer created");
360 ibool restore_corrupt_pages)
364 byte* unaligned_read_buf;
368 ibool reset_space_ids = FALSE;
376 unaligned_read_buf =
static_cast<byte*
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
378 read_buf =
static_cast<byte*
>(
379 ut_align(unaligned_read_buf, UNIV_PAGE_SIZE));
385 UNIV_PAGE_SIZE, read_buf, NULL);
392 buf_dblwr_init(doublewrite);
411 reset_space_ids = TRUE;
414 "Resetting space id's in the doublewrite buffer");
433 ulint source_page_no;
436 if (reset_space_ids) {
445 if (i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
446 source_page_no = block1 +
i;
448 source_page_no = block2
452 fil_io(OS_FILE_WRITE,
true, 0, 0, source_page_no, 0,
453 UNIV_PAGE_SIZE, page, NULL);
460 if (!restore_corrupt_pages) {
471 "A page in the doublewrite buffer is not "
472 "within space bounds; space id %lu "
473 "page number %lu, page %lu in "
475 (ulong) space_id, (ulong) page_no, (ulong) i);
477 }
else if (space_id == TRX_SYS_SPACE
478 && ((page_no >= block1
480 < block1 + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)
481 || (page_no >= block2
484 + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)))) {
494 zip_size ? zip_size : UNIV_PAGE_SIZE,
502 "InnoDB: Warning: database page"
503 " corruption or a failed\n"
504 "InnoDB: file read of"
505 " space %lu page %lu.\n"
506 "InnoDB: Trying to recover it from"
507 " the doublewrite buffer.\n",
508 (ulong) space_id, (ulong) page_no);
513 "InnoDB: Dump of the page:\n");
519 " corresponding page"
520 " in doublewrite buffer:\n");
526 "InnoDB: Also the page in the"
527 " doublewrite buffer"
529 "InnoDB: Cannot continue"
531 "InnoDB: You can try to"
532 " recover the database"
536 " innodb_force_recovery=6\n");
544 fil_io(OS_FILE_WRITE,
true, space_id,
545 zip_size, page_no, 0,
546 zip_size ? zip_size : UNIV_PAGE_SIZE,
550 "Recovered the page from"
551 " the doublewrite buffer.");
555 page += UNIV_PAGE_SIZE;
601 if (!srv_use_doublewrite_buf ||
buf_dblwr == NULL) {
605 switch (flush_type) {
661 buf_dblwr_check_page_lsn(
666 page + (UNIV_PAGE_SIZE
672 " InnoDB: ERROR: The page to be written"
674 "InnoDB: The low 4 bytes of LSN fields do not match "
675 "(" ULINTPF
" != " ULINTPF
")!"
676 " Noticed in the buffer pool.\n",
680 page + UNIV_PAGE_SIZE
690 buf_dblwr_assert_on_corrupt_block(
698 " InnoDB: Apparent corruption of an"
699 " index page n:o %lu in space %lu\n"
700 "InnoDB: to be written to data file."
701 " We intentionally crash server\n"
702 "InnoDB: to prevent corrupt data"
703 " from ending up in data\n"
716 buf_dblwr_check_block(
726 buf_dblwr_check_page_lsn(block->
frame);
734 buf_dblwr_assert_on_corrupt_block(block);
738 buf_dblwr_assert_on_corrupt_block(block);
747 buf_dblwr_write_block_to_datafile(
756 const ulint
flags = sync
774 buf_dblwr_check_page_lsn(block->
frame);
778 (
void*) block->
frame, (
void*) block);
796 if (!srv_use_doublewrite_buf ||
buf_dblwr == NULL) {
842 for (ulint len2 = 0,
i = 0;
844 len2 += UNIV_PAGE_SIZE,
i++) {
859 buf_dblwr_check_block(block);
863 buf_dblwr_check_page_lsn(write_buf + len2);
870 fil_io(OS_FILE_WRITE,
true, TRX_SYS_SPACE, 0,
872 (
void*) write_buf, NULL);
886 fil_io(OS_FILE_WRITE,
true, TRX_SYS_SPACE, 0,
888 (
void*) write_buf, NULL);
914 for (ulint
i = 0;
i < first_free;
i++) {
915 buf_dblwr_write_block_to_datafile(
971 UNIV_MEM_ASSERT_RW(bpage->
zip.
data, zip_size);
978 + zip_size, 0, UNIV_PAGE_SIZE - zip_size);
1031 ut_a(srv_use_doublewrite_buf);
1050 buf_dblwr_check_page_lsn(
1060 ib_int64_t sig_count =
1068 for (i = srv_doublewrite_batch_size; i <
size; ++
i) {
1112 + zip_size, 0, UNIV_PAGE_SIZE - zip_size);
1114 fil_io(OS_FILE_WRITE,
true, TRX_SYS_SPACE, 0,
1115 offset, 0, UNIV_PAGE_SIZE,
1117 + UNIV_PAGE_SIZE * i), NULL);
1121 fil_io(OS_FILE_WRITE,
true, TRX_SYS_SPACE, 0,
1122 offset, 0, UNIV_PAGE_SIZE,
1133 buf_dblwr_write_block_to_datafile(bpage, sync);