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++) {
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));
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) {
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)))) {
568 zip_size ? zip_size : UNIV_PAGE_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);
587 "InnoDB: Dump of the page:\n");
591 " corresponding page"
592 " in doublewrite buffer:\n");
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);
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);
823 trx_rseg_compare_last_trx_no(
837 }
else if (cmp > 0) {
853 ib_uint64_t rows_to_undo = 0;
854 const char* unit =
"";
863 mutex_enter(&kernel_mutex);
870 trx_rseg_compare_last_trx_no,
913 if (rows_to_undo > 1000000000) {
915 rows_to_undo = rows_to_undo / 1000000;
919 "InnoDB: %lu transaction(s) which must be"
920 " rolled back or cleaned up\n"
921 "InnoDB: in total %lu%s row operations to undo\n",
923 (ulong) rows_to_undo, unit);
925 fprintf(stderr,
"InnoDB: Trx id counter is " TRX_ID_FMT "\n",
934 mutex_exit(&kernel_mutex);
950 trx_sysf_create(&mtr);
962 trx_sys_file_format_max_write(
971 ib_uint64_t tag_value;
976 TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO, RW_X_LATCH, &mtr);
978 file_format_max.
id = format_id;
985 *name = file_format_max.
name;
1000 trx_sys_file_format_max_read(
void)
1006 ib_id_t file_format_id;
1013 TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO, RW_X_LATCH, &mtr);
1022 if (file_format_id >= FILE_FORMAT_NAME_N) {
1025 return(ULINT_UNDEFINED);
1028 return((ulint) file_format_id);
1040 ut_a(
id < FILE_FORMAT_NAME_N);
1042 return(file_format_name_map[
id]);
1053 ulint max_format_id)
1060 format_id = trx_sys_file_format_max_read();
1061 if (format_id == ULINT_UNDEFINED) {
1067 drizzled::errmsg_printf(drizzled::error::INFO,
"InnoDB: highest supported file format is %s",
1072 ut_a(format_id < FILE_FORMAT_NAME_N);
1074 drizzled::errmsg_printf(drizzled::error::ERROR,
1075 "InnoDB: %s: the system tablespace is in a file "
1076 "format that this version doesn't support - %s",
1078 ?
"Error" :
"Warning"),
1086 format_id = (format_id > max_format_id) ? format_id : max_format_id;
1090 file_format_max.
id = format_id;
1112 mutex_enter(&file_format_max.
mutex);
1115 if (format_id != file_format_max.
id) {
1117 ret = trx_sys_file_format_max_write(format_id, name);
1120 mutex_exit(&file_format_max.
mutex);
1137 format_id = trx_sys_file_format_max_read();
1140 if (format_id == ULINT_UNDEFINED) {
1159 ut_a(file_format_max.
name != NULL);
1162 mutex_enter(&file_format_max.
mutex);
1164 if (format_id > file_format_max.
id) {
1166 ret = trx_sys_file_format_max_write(format_id, name);
1169 mutex_exit(&file_format_max.
mutex);
1182 return(file_format_max.
name);
1192 mutex_create(file_format_max_mutex_key,
1193 &file_format_max.
mutex, SYNC_FILE_FORMAT_TAG);
1200 file_format_max.
id);
1221 ulint new_rsegs = 0;
1229 for (i = 0; i < n_rsegs; ++i) {
1231 if (trx_rseg_create() != NULL) {
1239 if (new_rsegs > 0) {
1241 "InnoDB: %lu rollback segment(s) active.\n",
1252 #define TRX_SYS_SPACE 0
1254 #define TRX_SYS_FILE_FORMAT_TAG (UNIV_PAGE_SIZE - 16)
1258 #define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW 3645922177UL
1259 #define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH 2745987765UL
1272 trx_sys_read_file_format_id(
1274 const char *pathname,
1281 byte buf[UNIV_PAGE_SIZE * 2];
1284 ib_id_t file_format_id;
1286 *format_id = ULINT_UNDEFINED;
1288 file = os_file_create_simple_no_error_handling(
1289 innodb_file_data_key,
1302 " ibbackup: Error: trying to read system tablespace file format,\n"
1303 " ibbackup: but could not open the tablespace file %s!\n",
1311 success = os_file_read_no_error_handling(
1312 file, page, TRX_SYS_PAGE_NO * UNIV_PAGE_SIZE, 0, UNIV_PAGE_SIZE
1321 " ibbackup: Error: trying to read system table space file format,\n"
1322 " ibbackup: but failed to read the tablespace file %s!\n",
1325 os_file_close(file);
1328 os_file_close(file);
1335 if (file_format_id >= FILE_FORMAT_NAME_N) {
1341 *format_id = (ulint) file_format_id;
1352 trx_sys_read_pertable_file_format_id(
1354 const char *pathname,
1361 byte buf[UNIV_PAGE_SIZE * 2];
1366 *format_id = ULINT_UNDEFINED;
1368 file = os_file_create_simple_no_error_handling(
1369 innodb_file_data_key,
1382 " ibbackup: Error: trying to read per-table tablespace format,\n"
1383 " ibbackup: but could not open the tablespace file %s!\n",
1391 success = os_file_read_no_error_handling(
1392 file, page, 0, 0, UNIV_PAGE_SIZE
1401 " ibbackup: Error: trying to per-table data file format,\n"
1402 " ibbackup: but failed to read the tablespace file %s!\n",
1405 os_file_close(file);
1408 os_file_close(file);
1417 }
else if (flags & 1) {
1419 *format_id = (flags / 32) % 128;
1437 if (!(
id < FILE_FORMAT_NAME_N)) {
1442 return(file_format_name_map[
id]);
1447 #ifndef UNIV_HOTBACKUP
1465 "InnoDB: Error: all read views were not closed"
1466 " before shutdown:\n"
1467 "InnoDB: %lu read views open \n",
1476 mutex_enter(&kernel_mutex);
1493 while (rseg != NULL) {
1504 while (view != NULL) {
1514 if (! srv_apply_log_only) {
1524 mutex_exit(&kernel_mutex);
#define FIL_PAGE_DATA_END
#define UT_LIST_GET_LEN(BASE)
trx_doublewrite_t * trx_doublewrite
UNIV_INTERN void trx_sys_create_rsegs(ulint n_rsegs)
UNIV_INTERN void trx_sys_file_format_tag_init(void)
#define TRX_SYS_DOUBLEWRITE
#define UT_LIST_GET_NEXT(NAME, N)
UNIV_INTERN void trx_sys_file_format_init(void)
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_INLINE trx_sysf_t * trx_sysf_get(mtr_t *mtr)
#define DICT_TF_FORMAT_MIN
UNIV_INTERN void log_make_checkpoint_at(ib_uint64_t lsn, ibool write_always)
UNIV_INTERN void trx_sys_doublewrite_init_or_restore_pages(ibool restore_corrupt_pages)
UNIV_INLINE void mach_write_to_4(byte *b, ulint n)
UNIV_INTERN void trx_sys_file_format_close(void)
UNIV_INTERN const char * trx_sys_file_format_max_get(void)
ibool trx_sys_multiple_tablespace_format
#define TRX_SYS_DOUBLEWRITE_MAGIC_N
UNIV_INTERN void buf_page_print(const byte *read_buf, ulint zip_size)
UNIV_INTERN void trx_rseg_list_and_array_init(trx_sysf_t *sys_header, ib_bh_t *ib_bh, mtr_t *mtr)
UNIV_INTERN void * ut_malloc(ulint n)
UNIV_INLINE void mach_write_to_8(byte *b, ib_uint64_t n)
#define TRX_SYS_FILE_FORMAT_TAG
UNIV_INTERN ibool trx_sys_file_format_max_upgrade(const char **name, ulint format_id)
UNIV_INTERN void mlog_write_ulint(byte *ptr, ulint val, byte type, mtr_t *mtr)
UNIV_INTERN ib_bh_t * ib_bh_create(ib_bh_cmp_t compare, ulint sizeof_elem, ulint max_elems)
UNIV_INTERN void trx_lists_init_at_db_start(void)
#define TRX_SYS_DRIZZLE_LOG_INFO
ibool trx_doublewrite_must_reset_space_ids
UNIV_INTERN ibool buf_page_is_corrupted(const byte *read_buf, ulint zip_size)
UNIV_INTERN void trx_sys_init_at_db_start(void)
UNIV_INTERN ulint fil_space_get_zip_size(ulint id)
#define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED
UNIV_INTERN void trx_sys_mark_upgraded_to_multiple_tablespaces(void)
#define TRX_SYS_DOUBLEWRITE_MAGIC
UNIV_INTERN void sess_close(sess_t *sess)
#define FIL_PAGE_TYPE_TRX_SYS
UNIV_INTERN ulint fseg_alloc_free_page(fseg_header_t *seg_header, ulint hint, byte direction, mtr_t *mtr)
UNIV_INTERN rw_lock_t * fil_space_get_latch(ulint id, ulint *zip_size)
UNIV_INTERN void trx_purge_sys_create(ib_bh_t *ib_bh)
UNIV_INTERN void trx_sys_read_commit_id(void)
#define TRX_SYS_DOUBLEWRITE_REPEAT
UNIV_INLINE ulint buf_block_get_page_no(const buf_block_t *block) __attribute__((pure))
UNIV_INTERN void mtr_commit(mtr_t *mtr) __attribute__((nonnull))
#define UT_LIST_REMOVE(NAME, BASE, N)
#define DICT_TF_FORMAT_MAX
UNIV_INTERN void trx_sys_flush_commit_id(uint64_t commit_id, ulint field, mtr_t *mtr)
UNIV_INTERN void mlog_write_ull(byte *ptr, ib_uint64_t val, mtr_t *mtr)
UNIV_INTERN ibool trx_in_trx_list(trx_t *in_trx)
UNIV_INTERN ulint trx_rseg_header_create(ulint space, ulint zip_size, ulint max_size, ulint rseg_slot_no, mtr_t *mtr)
UNIV_INLINE void * ut_align(const void *ptr, ulint align_no)
#define TRX_SYS_TRX_ID_WRITE_MARGIN
UNIV_INLINE ib_uint64_t ut_uint64_align_up(ib_uint64_t n, ulint align_no)
ibool trx_doublewrite_buf_is_being_created
UNIV_INTERN void trx_sys_close(void)
UNIV_INLINE ulint ut_max(ulint n1, ulint n2)
UNIV_INTERN ulint trx_sys_file_format_max_check(ulint max_format_id)
ibool recv_needed_recovery
UNIV_INTERN ulint os_file_get_last_error(ibool report_all_errors)
#define UT_LIST_GET_FIRST(BASE)
#define TRX_SYS_DOUBLEWRITE_FSEG
UNIV_INTERN ulint trx_sysf_rseg_find_free(mtr_t *mtr)
#define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N
UNIV_INTERN buf_block_t * fseg_create(ulint space, ulint page, ulint byte_offset, mtr_t *mtr)
#define mtr_x_lock(B, MTR)
UNIV_INTERN void trx_sys_create(void)
UNIV_INTERN void ut_free(void *ptr)
#define UT_LIST_INIT(BASE)
#define TRX_SYS_DRIZZLE_MAX_COMMIT_ID
UNIV_INTERN sess_t * sess_open(void)
UNIV_INLINE ulint trx_sysf_rseg_get_page_no(trx_sysf_t *sys_header, ulint i, mtr_t *mtr)
buf_page_t ** buf_block_arr
#define TRX_SYS_TRX_ID_STORE
UNIV_INLINE ulint mach_read_from_4(const byte *b) __attribute__((nonnull
UNIV_INTERN void trx_sys_create_doublewrite_buf(void)
UNIV_INTERN void fil_flush_file_spaces(ulint purpose)
UNIV_INTERN void ut_print_timestamp(FILE *file)
UNIV_INTERN const char * trx_sys_file_format_id_to_name(const ulint id)
#define TRX_SYS_MYSQL_LOG_NAME_LEN
UNIV_INTERN void trx_rseg_mem_free(trx_rseg_t *rseg)
UNIV_INTERN void trx_purge_sys_close(void)
drizzled::atomic< uint64_t > trx_sys_commit_id
UNIV_INLINE void mtr_start(mtr_t *mtr) __attribute__((nonnull))
#define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N
#define TRX_SYS_DOUBLEWRITE_BLOCK2
#define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID
#define TRX_SYS_DOUBLEWRITE_BLOCK1
UNIV_INTERN ibool fil_check_adress_in_tablespace(ulint id, ulint page_no)
UNIV_INLINE ib_uint64_t mach_read_from_8(const byte *b) __attribute__((nonnull
#define TRX_SYS_FSEG_HEADER
UNIV_INTERN void mlog_log_string(byte *ptr, ulint len, mtr_t *mtr)
#define TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
UNIV_INTERN ibool trx_doublewrite_page_inside(ulint page_no)
UNIV_INLINE ulint buf_pool_get_curr_size(void)
UNIV_INTERN ibool trx_sys_file_format_max_set(ulint format_id, const char **name)
#define buf_page_get(SP, ZS, OF, LA, MTR)
UNIV_INTERN ibool fil_tablespace_exists_in_mem(ulint id)
byte * write_buf_unaligned