32 #ifndef UNIV_HOTBACKUP
55 #include <drizzled/errmsg_print.h>
84 UNIV_INTERN ib_int64_t trx_sys_mysql_master_log_pos = -1;
94 UNIV_INTERN ib_int64_t trx_sys_mysql_bin_log_pos = -1;
102 static const char* file_format_name_map[] = {
132 static const ulint FILE_FORMAT_NAME_N
133 =
sizeof(file_format_name_map) /
sizeof(file_format_name_map[0]);
135 #ifdef UNIV_PFS_MUTEX
137 UNIV_INTERN mysql_pfs_key_t trx_doublewrite_mutex_key;
138 UNIV_INTERN mysql_pfs_key_t file_format_max_mutex_key;
141 #ifndef UNIV_HOTBACKUP
163 && page_no < trx_doublewrite->block1
169 && page_no < trx_doublewrite->block2
181 trx_doublewrite_init(
191 os_do_not_call_flush_at_each_write = TRUE;
194 mutex_create(trx_doublewrite_mutex_key,
232 buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
257 #ifdef UNIV_SYNC_DEBUG
279 buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
288 trx_doublewrite_init(doublewrite);
294 "InnoDB: Doublewrite buffer not found:"
299 + FSP_EXTENT_SIZE / 2 + 100)
302 "InnoDB: Cannot create doublewrite buffer:"
304 "InnoDB: increase your buffer pool size.\n"
305 "InnoDB: Cannot continue operation.\n");
310 block2 = fseg_create(TRX_SYS_SPACE, TRX_SYS_PAGE_NO,
317 buf_block_dbg_add_level(block2, SYNC_NO_ORDER_CHECK);
319 if (block2 == NULL) {
321 "InnoDB: Cannot create doublewrite buffer:"
323 "InnoDB: increase your tablespace size.\n"
324 "InnoDB: Cannot continue operation.\n");
332 fseg_header = buf_block_get_frame(block)
337 + FSP_EXTENT_SIZE / 2; i++) {
338 page_no = fseg_alloc_free_page(fseg_header,
343 "InnoDB: Cannot create doublewrite"
344 " buffer: you must\n"
345 "InnoDB: increase your"
346 " tablespace size.\n"
347 "InnoDB: Cannot continue operation.\n"
362 #ifdef UNIV_SYNC_DEBUG
367 buf_block_dbg_add_level(new_block,
368 SYNC_NO_ORDER_CHECK);
370 if (i == FSP_EXTENT_SIZE / 2) {
371 ut_a(page_no == FSP_EXTENT_SIZE);
379 }
else if (i == FSP_EXTENT_SIZE / 2
381 ut_a(page_no == 2 * FSP_EXTENT_SIZE);
389 }
else if (i > FSP_EXTENT_SIZE / 2) {
390 ut_a(page_no == prev_page_no + 1);
393 prev_page_no = page_no;
413 fprintf(stderr,
"InnoDB: Doublewrite buffer created\n");
432 ibool restore_corrupt_pages)
436 byte* unaligned_read_buf;
439 ulint source_page_no;
448 unaligned_read_buf =
static_cast<byte *
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
449 read_buf =
static_cast<byte *
>(
ut_align(unaligned_read_buf, UNIV_PAGE_SIZE));
454 fil_io(
OS_FILE_READ, TRUE, TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO, 0,
455 UNIV_PAGE_SIZE, read_buf, NULL);
462 trx_doublewrite_init(doublewrite);
484 "InnoDB: Resetting space id's in the"
485 " doublewrite buffer\n");
517 if (i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
518 source_page_no = block1 + i;
520 source_page_no = block2
524 fil_io(OS_FILE_WRITE, TRUE, 0, 0, source_page_no, 0,
525 UNIV_PAGE_SIZE, page, NULL);
533 if (!restore_corrupt_pages) {
537 }
else if (!fil_tablespace_exists_in_mem(space_id)) {
541 }
else if (!fil_check_adress_in_tablespace(space_id,
544 "InnoDB: Warning: a page in the"
545 " doublewrite buffer is not within space\n"
546 "InnoDB: bounds; space id %lu"
547 " page number %lu, page %lu in"
548 " doublewrite buf.\n",
549 (ulong) space_id, (ulong) page_no, (ulong) i);
551 }
else if (space_id == TRX_SYS_SPACE
552 && ((page_no >= block1
554 < block1 + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)
555 || (page_no >= block2
558 + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)))) {
563 ulint zip_size = fil_space_get_zip_size(space_id);
568 zip_size ? zip_size : UNIV_PAGE_SIZE,
574 (buf_page_is_corrupted(read_buf, zip_size))) {
577 "InnoDB: Warning: database page"
578 " corruption or a failed\n"
579 "InnoDB: file read of"
580 " space %lu page %lu.\n"
581 "InnoDB: Trying to recover it from"
582 " the doublewrite buffer.\n",
583 (ulong) space_id, (ulong) page_no);
585 if (buf_page_is_corrupted(page, zip_size)) {
587 "InnoDB: Dump of the page:\n");
588 buf_page_print(read_buf, zip_size);
591 " corresponding page"
592 " in doublewrite buffer:\n");
593 buf_page_print(page, zip_size);
596 "InnoDB: Also the page in the"
597 " doublewrite buffer"
599 "InnoDB: Cannot continue"
601 "InnoDB: You can try to"
602 " recover the database"
606 " innodb_force_recovery=6\n");
614 fil_io(OS_FILE_WRITE, TRUE, space_id,
615 zip_size, page_no, 0,
616 zip_size ? zip_size : UNIV_PAGE_SIZE,
619 "InnoDB: Recovered the page from"
620 " the doublewrite buffer.\n");
624 page += UNIV_PAGE_SIZE;
644 ut_ad(mutex_own(&(kernel_mutex)));
648 while (trx != NULL) {
665 trx_sys_flush_max_trx_id(
void)
671 ut_ad(mutex_own(&kernel_mutex));
726 ut_ad(mutex_own(&(kernel_mutex)));
730 for (i = 0; i < TRX_SYS_N_RSEGS; i++) {
740 return(ULINT_UNDEFINED);
766 mtr_x_lock(fil_space_get_latch(TRX_SYS_SPACE, NULL), mtr);
767 mutex_enter(&kernel_mutex);
772 buf_block_dbg_add_level(block, SYNC_TRX_SYS_HEADER);
776 page = buf_block_get_frame(block);
797 len =
ut_max(TRX_SYS_OLD_N_RSEGS, TRX_SYS_N_RSEGS)
798 * TRX_SYS_RSEG_SLOT_SIZE;
799 memset(ptr, 0xff, len);
807 + page - sys_header, mtr);
813 ut_a(slot_no == TRX_SYS_SYSTEM_RSEG_ID);
814 ut_a(page_no == FSP_FIRST_RSEG_PAGE_NO);
816 mutex_exit(&kernel_mutex);
828 ib_uint64_t rows_to_undo = 0;
829 const char* unit =
"";
837 mutex_enter(&kernel_mutex);
879 if (rows_to_undo > 1000000000) {
881 rows_to_undo = rows_to_undo / 1000000;
885 "InnoDB: %lu transaction(s) which must be"
886 " rolled back or cleaned up\n"
887 "InnoDB: in total %lu%s row operations to undo\n",
889 (ulong) rows_to_undo, unit);
891 fprintf(stderr,
"InnoDB: Trx id counter is " TRX_ID_FMT "\n",
899 mutex_exit(&kernel_mutex);
915 trx_sysf_create(&mtr);
927 trx_sys_file_format_max_write(
936 ib_uint64_t tag_value;
941 TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO, RW_X_LATCH, &mtr);
943 file_format_max.
id = format_id;
950 *name = file_format_max.
name;
965 trx_sys_file_format_max_read(
void)
971 ib_id_t file_format_id;
978 TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO, RW_X_LATCH, &mtr);
987 if (file_format_id >= FILE_FORMAT_NAME_N) {
990 return(ULINT_UNDEFINED);
993 return((ulint) file_format_id);
1005 ut_a(
id < FILE_FORMAT_NAME_N);
1007 return(file_format_name_map[
id]);
1018 ulint max_format_id)
1025 format_id = trx_sys_file_format_max_read();
1026 if (format_id == ULINT_UNDEFINED) {
1032 drizzled::errmsg_printf(drizzled::error::INFO,
"InnoDB: highest supported file format is %s",
1037 ut_a(format_id < FILE_FORMAT_NAME_N);
1039 drizzled::errmsg_printf(drizzled::error::ERROR,
1040 "InnoDB: %s: the system tablespace is in a file "
1041 "format that this version doesn't support - %s",
1043 ?
"Error" :
"Warning"),
1051 format_id = (format_id > max_format_id) ? format_id : max_format_id;
1055 file_format_max.
id = format_id;
1077 mutex_enter(&file_format_max.
mutex);
1080 if (format_id != file_format_max.
id) {
1082 ret = trx_sys_file_format_max_write(format_id, name);
1085 mutex_exit(&file_format_max.
mutex);
1102 format_id = trx_sys_file_format_max_read();
1105 if (format_id == ULINT_UNDEFINED) {
1124 ut_a(file_format_max.
name != NULL);
1127 mutex_enter(&file_format_max.
mutex);
1129 if (format_id > file_format_max.
id) {
1131 ret = trx_sys_file_format_max_write(format_id, name);
1134 mutex_exit(&file_format_max.
mutex);
1147 return(file_format_max.
name);
1157 mutex_create(file_format_max_mutex_key,
1158 &file_format_max.
mutex, SYNC_FILE_FORMAT_TAG);
1165 file_format_max.
id);
1186 ulint new_rsegs = 0;
1194 for (i = 0; i < n_rsegs; ++i) {
1196 if (trx_rseg_create() != NULL) {
1204 if (new_rsegs > 0) {
1206 "InnoDB: %lu rollback segment(s) active.\n",
1217 #define TRX_SYS_SPACE 0
1219 #define TRX_SYS_FILE_FORMAT_TAG (UNIV_PAGE_SIZE - 16)
1223 #define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW 3645922177UL
1224 #define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH 2745987765UL
1237 trx_sys_read_file_format_id(
1239 const char *pathname,
1246 byte buf[UNIV_PAGE_SIZE * 2];
1249 ib_id_t file_format_id;
1251 *format_id = ULINT_UNDEFINED;
1253 file = os_file_create_simple_no_error_handling(
1254 innodb_file_data_key,
1267 " ibbackup: Error: trying to read system tablespace file format,\n"
1268 " ibbackup: but could not open the tablespace file %s!\n",
1276 success = os_file_read_no_error_handling(
1277 file, page, TRX_SYS_PAGE_NO * UNIV_PAGE_SIZE, 0, UNIV_PAGE_SIZE
1286 " ibbackup: Error: trying to read system table space file format,\n"
1287 " ibbackup: but failed to read the tablespace file %s!\n",
1290 os_file_close(file);
1293 os_file_close(file);
1300 if (file_format_id >= FILE_FORMAT_NAME_N) {
1306 *format_id = (ulint) file_format_id;
1317 trx_sys_read_pertable_file_format_id(
1319 const char *pathname,
1326 byte buf[UNIV_PAGE_SIZE * 2];
1331 *format_id = ULINT_UNDEFINED;
1333 file = os_file_create_simple_no_error_handling(
1334 innodb_file_data_key,
1347 " ibbackup: Error: trying to read per-table tablespace format,\n"
1348 " ibbackup: but could not open the tablespace file %s!\n",
1356 success = os_file_read_no_error_handling(
1357 file, page, 0, 0, UNIV_PAGE_SIZE
1366 " ibbackup: Error: trying to per-table data file format,\n"
1367 " ibbackup: but failed to read the tablespace file %s!\n",
1370 os_file_close(file);
1373 os_file_close(file);
1382 }
else if (flags & 1) {
1384 *format_id = (flags / 32) % 128;
1402 if (!(
id < FILE_FORMAT_NAME_N)) {
1407 return(file_format_name_map[
id]);
1412 #ifndef UNIV_HOTBACKUP
1430 "InnoDB: Error: all read views were not closed"
1431 " before shutdown:\n"
1432 "InnoDB: %lu read views open \n",
1441 mutex_enter(&kernel_mutex);
1458 while (rseg != NULL) {
1469 while (view != NULL) {
1479 if (! srv_apply_log_only) {
1489 mutex_exit(&kernel_mutex);