43 #include "xtrabackup_api.h"
44 #ifndef UNIV_HOTBACKUP
50 static ulint srv_data_read, srv_data_written;
112 UNIV_INTERN
const char* fil_path_to_mysql_datadir =
".";
115 UNIV_INTERN ulint fil_n_log_flushes = 0;
118 UNIV_INTERN ulint fil_n_pending_log_flushes = 0;
120 UNIV_INTERN ulint fil_n_pending_tablespace_flushes = 0;
125 #ifdef UNIV_PFS_MUTEX
127 UNIV_INTERN mysql_pfs_key_t fil_system_mutex_key;
130 #ifdef UNIV_PFS_RWLOCK
132 UNIV_INTERN mysql_pfs_key_t fil_space_latch_key;
168 #define FIL_NODE_MAGIC_N 89389
208 ulint n_reserved_extents;
214 ulint n_pending_ibuf_merges;
221 hash_node_t name_hash;
222 #ifndef UNIV_HOTBACKUP
229 ibool is_in_unflushed_spaces;
237 #define FIL_SPACE_MAGIC_N 89472
247 #ifndef UNIV_HOTBACKUP
277 ulint max_assigned_id;
283 ib_int64_t tablespace_version;
293 ibool space_id_reuse_warned;
313 fil_node_prepare_for_io(
323 fil_node_complete_io(
336 fil_get_space_id_for_table(
377 return(fil_io(
OS_FILE_READ, sync, space_id, zip_size, block_offset,
378 byte_offset, len, buf, message));
406 return(fil_io(OS_FILE_WRITE, sync, space_id, zip_size, block_offset,
407 byte_offset, len, buf, message));
434 fil_space_get_by_name(
448 !strcmp(name, space->
name));
453 #ifndef UNIV_HOTBACKUP
460 fil_space_get_version(
465 ib_int64_t version = -1;
469 mutex_enter(&fil_system->
mutex);
471 space = fil_space_get_by_id(
id);
477 mutex_exit(&fil_system->
mutex);
496 mutex_enter(&fil_system->
mutex);
498 space = fil_space_get_by_id(
id);
503 *flags = space->
flags;
506 mutex_exit(&fil_system->
mutex);
508 return(&(space->
latch));
524 mutex_enter(&fil_system->
mutex);
526 space = fil_space_get_by_id(
id);
530 mutex_exit(&fil_system->
mutex);
542 fil_space_is_flushed(
583 mutex_enter(&fil_system->
mutex);
594 node->
magic_n = FIL_NODE_MAGIC_N;
601 space = fil_space_get_by_id(
id);
606 " InnoDB: Error: Could not find tablespace %lu for\n"
607 "InnoDB: file ", (ulong)
id);
609 fputs(
" in the tablespace memory cache.\n", stderr);
614 mutex_exit(&fil_system->
mutex);
625 if (id < SRV_LOG_SPACE_FIRST_ID && fil_system->max_assigned_id <
id) {
630 mutex_exit(&fil_system->
mutex);
658 if (node->
size == 0) {
667 node->
handle = os_file_create_simple_no_error_handling(
669 OS_FILE_READ_ONLY, &success);
677 " InnoDB: Fatal error: cannot open %s\n."
678 "InnoDB: Have you deleted .ibd files"
679 " under a running mysqld server?\n",
686 size_bytes = (((uint64_t)size_high) << 32) + size_low;
687 #ifdef UNIV_HOTBACKUP
688 if (space->
id == 0) {
689 node->
size = size_bytes / UNIV_PAGE_SIZE;
690 os_file_close(node->
handle);
699 "InnoDB: Error: the size of single-table"
700 " tablespace file %s\n"
701 "InnoDB: is only %lu %lu,"
702 " should be at least %lu!\n",
714 buf2 =
static_cast<unsigned char *
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
717 page =
static_cast<unsigned char *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
719 success = os_file_read(node->
handle, page, 0, 0,
721 space_id = fsp_header_get_space_id(page);
722 flags = fsp_header_get_flags(page);
728 os_file_close(node->
handle);
730 if (UNIV_UNLIKELY(space_id != space->
id)) {
732 "InnoDB: Error: tablespace id is %lu"
733 " in the data dictionary\n"
734 "InnoDB: but in file %s it is %lu!\n",
735 space->
id, node->
name, space_id);
740 if (UNIV_UNLIKELY(space_id == ULINT_UNDEFINED
743 "InnoDB: Error: tablespace id %lu"
744 " in file %s is not sensible\n",
745 (ulong) space_id, node->
name);
750 if (UNIV_UNLIKELY(space->
flags != flags)) {
752 "InnoDB: Error: table flags are %lx"
753 " in the data dictionary\n"
754 "InnoDB: but the flags in file %s are %lx!\n",
760 if (size_bytes >= 1024 * 1024) {
765 if (!(flags & DICT_TF_ZSSIZE_MASK)) {
766 node->
size = (ulint)size_bytes / UNIV_PAGE_SIZE;
773 #ifdef UNIV_HOTBACKUP
786 node->
handle = os_file_create(innodb_file_log_key,
788 OS_FILE_AIO, OS_LOG_FILE,
791 node->
handle = os_file_create(innodb_file_data_key,
797 node->
handle = os_file_create(innodb_file_data_key,
826 ut_ad(node && system);
833 ret = os_file_close(node->
handle);
860 fil_try_to_close_file_in_LRU(
873 "InnoDB: fil_sys open file LRU len %lu\n",
877 while (node != NULL) {
881 fil_node_close_file(node, fil_system);
887 fputs(
"InnoDB: cannot close file ", stderr);
889 fprintf(stderr,
", because n_pending_flushes %lu\n",
895 fputs(
"InnoDB: cannot close file ", stderr);
898 ", because mod_count %ld != fl_count %ld\n",
915 fil_mutex_enter_and_prepare_for_io(
921 ibool print_info = FALSE;
926 mutex_enter(&fil_system->
mutex);
943 space = fil_space_get_by_id(space_id);
945 if (space != NULL && space->
stop_ios) {
949 if (count2 > 20000) {
950 fputs(
"InnoDB: Warning: tablespace ", stderr);
953 " has i/o ops stopped for a long time %lu\n",
957 mutex_exit(&fil_system->
mutex);
981 success = fil_try_to_close_file_in_LRU(print_info);
997 " InnoDB: Warning: too many (%lu) files stay open"
998 " while the maximum\n"
999 "InnoDB: allowed value would be %lu.\n"
1000 "InnoDB: You may need to raise the value of"
1001 " innodb_open_files in\n"
1002 "InnoDB: my.cnf.\n",
1003 (ulong) fil_system->
n_open,
1009 mutex_exit(&fil_system->
mutex);
1011 #ifndef UNIV_HOTBACKUP
1038 ut_ad(node && system && space);
1050 && fil_space_is_flushed(space)) {
1055 system->unflushed_spaces,
1059 fil_node_close_file(node, system);
1070 #ifdef UNIV_LOG_ARCHIVE
1076 fil_space_truncate_start(
1086 mutex_enter(&fil_system->
mutex);
1088 space = fil_space_get_by_id(
id);
1092 while (trunc_len > 0) {
1095 ut_a(node->
size * UNIV_PAGE_SIZE <= trunc_len);
1097 trunc_len -= node->
size * UNIV_PAGE_SIZE;
1099 fil_node_free(node, fil_system, space);
1102 mutex_exit(&fil_system->
mutex);
1139 mutex_enter(&fil_system->
mutex);
1141 space = fil_space_get_by_name(name);
1143 if (UNIV_LIKELY_NULL(space)) {
1149 " InnoDB: Warning: trying to init to the"
1150 " tablespace memory cache\n"
1151 "InnoDB: a tablespace %lu of name ", (ulong)
id);
1153 fprintf(stderr,
",\n"
1154 "InnoDB: but a tablespace %lu of the same name\n"
1155 "InnoDB: already exists in the"
1156 " tablespace memory cache!\n",
1161 mutex_exit(&fil_system->
mutex);
1167 "InnoDB: We assume that InnoDB did a crash recovery,"
1169 "InnoDB: an .ibd file for which the table"
1170 " did not exist in the\n"
1171 "InnoDB: InnoDB internal data dictionary in the"
1173 "InnoDB: We assume that you later removed the"
1174 " .ibd and .frm files,\n"
1175 "InnoDB: and are now trying to recreate the table."
1176 " We now remove the\n"
1177 "InnoDB: conflicting tablespace object"
1178 " from the memory cache and try\n"
1179 "InnoDB: the init again.\n");
1181 namesake_id = space->
id;
1183 success = fil_space_free(namesake_id, FALSE);
1186 mutex_exit(&fil_system->
mutex);
1191 space = fil_space_get_by_id(
id);
1193 if (UNIV_LIKELY_NULL(space)) {
1195 "InnoDB: Error: trying to add tablespace %lu"
1196 " of name ", (ulong)
id);
1198 fprintf(stderr,
"\n"
1199 "InnoDB: to the tablespace memory cache,"
1201 "InnoDB: %lu of name ", (ulong) space->
id);
1203 fputs(
" already exists in the tablespace\n"
1204 "InnoDB: memory cache!\n", stderr);
1206 mutex_exit(&fil_system->
mutex);
1218 space->
mark = FALSE;
1222 if (!fil_system->space_id_reuse_warned) {
1223 fil_system->space_id_reuse_warned = TRUE;
1227 " InnoDB: Warning: allocated tablespace %lu,"
1228 " old maximum was %lu\n",
1241 space->
flags = flags;
1249 space->
magic_n = FIL_SPACE_MAGIC_N;
1261 mutex_exit(&fil_system->
mutex);
1273 fil_assign_new_space_id(
1280 mutex_enter(&fil_system->
mutex);
1284 if (id < fil_system->max_assigned_id) {
1293 "InnoDB: Warning: you are running out of new"
1294 " single-table tablespace id's.\n"
1295 "InnoDB: Current counter is %lu and it"
1296 " must not exceed %lu!\n"
1297 "InnoDB: To reset the counter to zero"
1298 " you have to dump all your tables and\n"
1299 "InnoDB: recreate the whole InnoDB installation.\n",
1311 "InnoDB: You have run out of single-table"
1312 " tablespace id's!\n"
1313 "InnoDB: Current counter is %lu.\n"
1314 "InnoDB: To reset the counter to zero you"
1315 " have to dump all your tables and\n"
1316 "InnoDB: recreate the whole InnoDB installation.\n",
1318 *space_id = ULINT_UNDEFINED;
1321 mutex_exit(&fil_system->
mutex);
1346 space = fil_space_get_by_id(
id);
1351 " InnoDB: Error: trying to remove tablespace %lu"
1352 " from the cache but\n"
1353 "InnoDB: it is not there.\n", (ulong)
id);
1360 tablespace = fil_space_get_by_name(space->
name);
1362 ut_a(space == tablespace);
1381 while (fil_node != NULL) {
1382 fil_node_free(fil_node, fil_system, space);
1390 rw_lock_x_unlock(&space->
latch);
1393 rw_lock_free(&(space->
latch));
1417 fil_mutex_enter_and_prepare_for_io(
id);
1419 space = fil_space_get_by_id(
id);
1421 if (space == NULL) {
1422 mutex_exit(&fil_system->
mutex);
1438 fil_node_prepare_for_io(node, fil_system, space);
1444 mutex_exit(&fil_system->
mutex);
1455 fil_space_get_flags(
1465 if (UNIV_UNLIKELY(!
id)) {
1469 fil_mutex_enter_and_prepare_for_io(
id);
1471 space = fil_space_get_by_id(
id);
1473 if (space == NULL) {
1474 mutex_exit(&fil_system->
mutex);
1476 return(ULINT_UNDEFINED);
1490 fil_node_prepare_for_io(node, fil_system, space);
1494 flags = space->
flags;
1496 mutex_exit(&fil_system->
mutex);
1507 fil_space_get_zip_size(
1513 flags = fil_space_get_flags(
id);
1515 if (flags && flags != ULINT_UNDEFINED) {
1529 fil_check_adress_in_tablespace(
1534 if (fil_space_get_size(
id) > page_no) {
1551 ut_a(fil_system == NULL);
1553 ut_a(hash_size > 0);
1554 ut_a(max_n_open > 0);
1557 fil_system =
static_cast<fil_system_t *
>(fil_system_ptr);
1559 mutex_create(fil_system_mutex_key,
1560 &fil_system->
mutex, SYNC_ANY_LATCH);
1562 fil_system->
spaces = hash_create(hash_size);
1563 fil_system->
name_hash = hash_create(hash_size);
1578 fil_open_log_and_system_tablespace_files(
void)
1584 mutex_enter(&fil_system->
mutex);
1588 while (space != NULL) {
1592 while (node != NULL) {
1594 fil_node_open_file(node, fil_system,
1598 < 10 + fil_system->
n_open) {
1600 "InnoDB: Warning: you must"
1601 " raise the value of"
1602 " innodb_open_files in\n"
1603 "InnoDB: my.cnf! Remember that"
1604 " InnoDB keeps all log files"
1606 "InnoDB: tablespace files open"
1607 " for the whole time mysqld is"
1609 "InnoDB: needs to open also"
1610 " some .ibd files if the"
1611 " file-per-table storage\n"
1612 "InnoDB: model is used."
1613 " Current open files %lu,"
1615 " open files %lu.\n",
1616 (ulong) fil_system->
n_open,
1625 mutex_exit(&fil_system->
mutex);
1633 fil_close_all_files(
void)
1638 mutex_enter(&fil_system->
mutex);
1642 while (space != NULL) {
1651 fil_node_close_file(node, fil_system);
1657 fil_space_free(prev_space->
id, FALSE);
1660 mutex_exit(&fil_system->
mutex);
1668 fil_set_max_space_id_if_bigger(
1674 "InnoDB: Fatal error: max tablespace id"
1675 " is too high, %lu\n", (ulong) max_id);
1679 mutex_enter(&fil_system->
mutex);
1686 mutex_exit(&fil_system->
mutex);
1695 fil_write_lsn_and_arch_no_to_file(
1706 buf1 =
static_cast<byte *
>(mem_alloc(2 * UNIV_PAGE_SIZE));
1707 buf =
static_cast<byte *
>(
ut_align(buf1, UNIV_PAGE_SIZE));
1709 fil_read(TRUE, 0, 0, sum_of_sizes, 0, UNIV_PAGE_SIZE, buf, NULL);
1713 fil_write(TRUE, 0, 0, sum_of_sizes, 0, UNIV_PAGE_SIZE, buf, NULL);
1726 fil_write_flushed_lsn_to_data_files(
1737 mutex_enter(&fil_system->
mutex);
1749 && space->
id == 0) {
1754 mutex_exit(&fil_system->
mutex);
1756 err = fil_write_lsn_and_arch_no_to_file(
1757 sum_of_sizes, lsn, arch_log_no);
1758 if (err != DB_SUCCESS) {
1763 mutex_enter(&fil_system->
mutex);
1765 sum_of_sizes += node->
size;
1772 mutex_exit(&fil_system->
mutex);
1782 fil_read_flushed_lsn_and_arch_log_no(
1785 ibool one_read_already,
1788 #ifdef UNIV_LOG_ARCHIVE
1789 ulint* min_arch_log_no,
1790 ulint* max_arch_log_no,
1792 ib_uint64_t* min_flushed_lsn,
1793 ib_uint64_t* max_flushed_lsn)
1797 ib_uint64_t flushed_lsn;
1799 buf2 =
static_cast<byte *
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
1801 buf =
static_cast<byte *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
1803 os_file_read(data_file, buf, 0, 0, UNIV_PAGE_SIZE);
1809 if (!one_read_already) {
1810 *min_flushed_lsn = flushed_lsn;
1811 *max_flushed_lsn = flushed_lsn;
1812 #ifdef UNIV_LOG_ARCHIVE
1813 *min_arch_log_no = arch_log_no;
1814 *max_arch_log_no = arch_log_no;
1819 if (*min_flushed_lsn > flushed_lsn) {
1820 *min_flushed_lsn = flushed_lsn;
1822 if (*max_flushed_lsn < flushed_lsn) {
1823 *max_flushed_lsn = flushed_lsn;
1825 #ifdef UNIV_LOG_ARCHIVE
1826 if (*min_arch_log_no > arch_log_no) {
1827 *min_arch_log_no = arch_log_no;
1829 if (*max_arch_log_no < arch_log_no) {
1830 *max_arch_log_no = arch_log_no;
1837 #ifndef UNIV_HOTBACKUP
1844 fil_inc_pending_ibuf_merges(
1850 mutex_enter(&fil_system->
mutex);
1852 space = fil_space_get_by_id(
id);
1854 if (space == NULL) {
1856 "InnoDB: Error: trying to do ibuf merge to a"
1857 " dropped tablespace %lu\n",
1862 mutex_exit(&fil_system->
mutex);
1869 mutex_exit(&fil_system->
mutex);
1878 fil_decr_pending_ibuf_merges(
1884 mutex_enter(&fil_system->
mutex);
1886 space = fil_space_get_by_id(
id);
1888 if (space == NULL) {
1890 "InnoDB: Error: decrementing ibuf merge of a"
1891 " dropped tablespace %lu\n",
1895 if (space != NULL) {
1899 mutex_exit(&fil_system->
mutex);
1907 fil_create_directory_for_tablename(
1916 len = strlen(fil_path_to_mysql_datadir);
1917 namend = strchr(name,
'/');
1919 path =
static_cast<char *
>(mem_alloc(len + (namend - name) + 2));
1921 memcpy(path, fil_path_to_mysql_datadir, len);
1923 memcpy(path + len + 1, name, namend - name);
1924 path[len + (namend -
name) + 1] = 0;
1932 #ifndef UNIV_HOTBACKUP
1953 const char* new_name,
1970 type, space_id, log_flags, log_ptr, mtr);
1978 len = strlen(name) + 1;
1987 len = strlen(new_name) + 1;
2015 fil_op_log_parse_or_replay(
2031 const char* new_name = NULL;
2035 if (end_ptr < ptr + 4) {
2044 if (end_ptr < ptr + 2) {
2053 if (end_ptr < ptr + name_len) {
2058 name = (
const char*) ptr;
2063 if (end_ptr < ptr + 2) {
2072 if (end_ptr < ptr + new_name_len) {
2077 new_name = (
const char*) ptr;
2079 ptr += new_name_len;
2106 if (fil_tablespace_exists_in_mem(space_id)) {
2107 ut_a(fil_delete_tablespace(space_id));
2118 if (fil_tablespace_exists_in_mem(space_id)) {
2121 fil_create_directory_for_tablename(new_name);
2126 if (fil_get_space_id_for_table(new_name)
2127 == ULINT_UNDEFINED) {
2130 if (!fil_rename_tablespace(NULL, space_id,
2141 if (fil_tablespace_exists_in_mem(space_id)) {
2143 }
else if (fil_get_space_id_for_table(name)
2144 != ULINT_UNDEFINED) {
2151 fil_create_directory_for_tablename(name);
2153 if (fil_create_new_single_table_tablespace(
2154 space_id, name, FALSE, flags,
2175 fil_delete_tablespace(
2187 mutex_enter(&fil_system->
mutex);
2189 space = fil_space_get_by_id(
id);
2191 if (space != NULL) {
2195 mutex_exit(&fil_system->
mutex);
2203 fputs(
" InnoDB: Warning: trying to"
2204 " delete tablespace ", stderr);
2206 fprintf(stderr,
",\n"
2207 "InnoDB: but there are %lu pending"
2208 " ibuf merges on it.\n"
2209 "InnoDB: Loop %lu.\n",
2214 mutex_exit(&fil_system->
mutex);
2219 goto stop_ibuf_merges;
2223 mutex_exit(&fil_system->
mutex);
2227 mutex_enter(&fil_system->
mutex);
2229 space = fil_space_get_by_id(
id);
2231 if (space == NULL) {
2234 " InnoDB: Error: cannot delete tablespace %lu\n"
2235 "InnoDB: because it is not found in the"
2236 " tablespace memory cache.\n",
2239 mutex_exit(&fil_system->
mutex);
2255 fputs(
" InnoDB: Warning: trying to"
2256 " delete tablespace ", stderr);
2258 fprintf(stderr,
",\n"
2259 "InnoDB: but there are %lu flushes"
2260 " and %lu pending i/o's on it\n"
2261 "InnoDB: Loop %lu.\n",
2266 mutex_exit(&fil_system->
mutex);
2276 mutex_exit(&fil_system->
mutex);
2288 rw_lock_x_lock(&space->
latch);
2290 #ifndef UNIV_HOTBACKUP
2298 buf_LRU_invalidate_tablespace(
id);
2302 mutex_enter(&fil_system->
mutex);
2304 success = fil_space_free(
id, TRUE);
2306 mutex_exit(&fil_system->
mutex);
2315 rw_lock_x_unlock(&space->
latch);
2319 #ifndef UNIV_HOTBACKUP
2348 fil_tablespace_is_being_deleted(
2353 ibool is_being_deleted;
2355 mutex_enter(&fil_system->
mutex);
2357 space = fil_space_get_by_id(
id);
2359 ut_a(space != NULL);
2363 mutex_exit(&fil_system->
mutex);
2365 return(is_being_deleted);
2368 #ifndef UNIV_HOTBACKUP
2380 fil_discard_tablespace(
2386 success = fil_delete_tablespace(
id);
2390 "InnoDB: Warning: cannot delete tablespace %lu"
2391 " in DISCARD TABLESPACE.\n"
2392 "InnoDB: But let us remove the"
2393 " insert buffer entries for this tablespace.\n",
2399 ibuf_delete_for_discarded_space(
id);
2410 fil_rename_tablespace_in_mem(
2417 const char* old_name = space->
name;
2421 space2 = fil_space_get_by_name(old_name);
2422 if (space != space2) {
2423 fputs(
"InnoDB: Error: cannot find ", stderr);
2425 fputs(
" in tablespace memory cache\n", stderr);
2430 space2 = fil_space_get_by_name(path);
2431 if (space2 != NULL) {
2432 fputs(
"InnoDB: Error: ", stderr);
2434 fputs(
" is already in tablespace memory cache\n", stderr);
2464 ulint namelen = strlen(name);
2465 ulint dirlen = strlen(fil_path_to_mysql_datadir);
2466 char* filename =
static_cast<char *
>(mem_alloc(namelen + dirlen +
sizeof "/.ibd"));
2469 memcpy(filename, name, namelen);
2470 memcpy(filename + namelen,
".ibd",
sizeof ".ibd");
2472 memcpy(filename, fil_path_to_mysql_datadir, dirlen);
2473 filename[dirlen] =
'/';
2475 memcpy(filename + dirlen + 1, name, namelen);
2476 memcpy(filename + dirlen + namelen + 1,
".ibd",
sizeof ".ibd");
2490 fil_rename_tablespace(
2492 const char* old_name,
2497 const char* new_name)
2506 ibool old_name_was_specified = TRUE;
2511 if (old_name == NULL) {
2512 old_name =
"(name not specified)";
2513 old_name_was_specified = FALSE;
2520 fputs(
" InnoDB: Warning: problems renaming ", stderr);
2522 fputs(
" to ", stderr);
2524 fprintf(stderr,
", %lu iterations\n", (ulong) count);
2527 mutex_enter(&fil_system->
mutex);
2529 space = fil_space_get_by_id(
id);
2531 if (space == NULL) {
2533 "InnoDB: Error: cannot find space id %lu"
2534 " in the tablespace memory cache\n"
2535 "InnoDB: though the table ", (ulong)
id);
2537 fputs(
" in a rename operation should have that id\n", stderr);
2538 mutex_exit(&fil_system->
mutex);
2543 if (count > 25000) {
2545 mutex_exit(&fil_system->
mutex);
2563 mutex_exit(&fil_system->
mutex);
2572 mutex_exit(&fil_system->
mutex);
2580 }
else if (node->
open) {
2583 fil_node_close_file(node, fil_system);
2588 if (old_name_was_specified) {
2589 old_path = fil_make_ibd_name(old_name, FALSE);
2591 ut_a(strcmp(space->
name, old_path) == 0);
2592 ut_a(strcmp(node->
name, old_path) == 0);
2598 path = fil_make_ibd_name(new_name, FALSE);
2599 success = fil_rename_tablespace_in_mem(space, node, path);
2602 success = os_file_rename(innodb_file_data_key, old_path, path);
2608 ut_a(fil_rename_tablespace_in_mem(space, node,
2618 mutex_exit(&fil_system->
mutex);
2620 #ifndef UNIV_HOTBACKUP
2643 fil_create_new_single_table_tablespace(
2646 const char* tablename,
2677 path = fil_make_ibd_name(tablename, is_temp);
2679 file = os_file_create(innodb_file_data_key, path,
2680 OS_FILE_CREATE, OS_FILE_NORMAL,
2684 fputs(
" InnoDB: Error creating file ", stderr);
2686 fputs(
".\n", stderr);
2692 if (err == OS_FILE_ALREADY_EXISTS) {
2693 fputs(
"InnoDB: The file already exists though"
2694 " the corresponding table did not\n"
2695 "InnoDB: exist in the InnoDB data dictionary."
2696 " Have you moved InnoDB\n"
2697 "InnoDB: .ibd files around without using the"
2699 "InnoDB: DISCARD TABLESPACE and"
2700 " IMPORT TABLESPACE, or did\n"
2701 "InnoDB: mysqld crash in the middle of"
2702 " CREATE TABLE? You can\n"
2703 "InnoDB: resolve the problem by"
2704 " removing the file ", stderr);
2707 "InnoDB: under the 'datadir' of MySQL.\n",
2711 return(DB_TABLESPACE_ALREADY_EXISTS);
2714 if (err == OS_FILE_DISK_FULL) {
2717 return(DB_OUT_OF_FILE_SPACE);
2727 err = DB_OUT_OF_FILE_SPACE;
2729 os_file_close(file);
2748 buf2 =
static_cast<byte *
>(
ut_malloc(3 * UNIV_PAGE_SIZE));
2750 page =
static_cast<byte *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
2752 memset(page,
'\0', UNIV_PAGE_SIZE);
2754 fsp_header_init_fields(page, space_id, flags);
2757 if (!(flags & DICT_TF_ZSSIZE_MASK)) {
2758 buf_flush_init_for_writing(page, NULL, 0);
2759 ret = os_file_write(path, file, page, 0, 0, UNIV_PAGE_SIZE);
2765 << ((flags & DICT_TF_ZSSIZE_MASK)
2769 page_zip.
data = page + UNIV_PAGE_SIZE;
2775 buf_flush_init_for_writing(page, &page_zip, 0);
2776 ret = os_file_write(path, file, page_zip.
data, 0, 0, zip_size);
2782 fputs(
"InnoDB: Error: could not write the first page"
2783 " to tablespace ", stderr);
2790 ret = os_file_flush(file);
2793 fputs(
"InnoDB: Error: file flush of tablespace ", stderr);
2795 fputs(
" failed\n", stderr);
2800 os_file_close(file);
2802 success = fil_space_create(path, space_id, flags,
FIL_TABLESPACE);
2809 fil_node_create(path, size, space_id, FALSE);
2811 #ifndef UNIV_HOTBACKUP
2817 fil_op_write_log(flags
2823 tablename, NULL, &mtr);
2832 #ifndef UNIV_HOTBACKUP
2845 fil_reset_too_high_lsns(
2849 ib_uint64_t current_lsn)
2857 ib_uint64_t flush_lsn;
2859 ib_int64_t file_size;
2865 filepath = fil_make_ibd_name(name, FALSE);
2867 file = os_file_create_simple_no_error_handling(
2869 OS_FILE_READ_WRITE, &success);
2876 fputs(
" InnoDB: Error: trying to open a table,"
2878 "InnoDB: open the tablespace file ", stderr);
2880 fputs(
"!\n", stderr);
2888 buf2 =
static_cast<byte *
>(
ut_malloc(3 * UNIV_PAGE_SIZE));
2890 page =
static_cast<byte *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
2892 success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
2902 if (current_lsn >= flush_lsn) {
2909 space_id = fsp_header_get_space_id(page);
2910 zip_size = fsp_header_get_zip_size(page);
2915 page_zip.
data = page + UNIV_PAGE_SIZE;
2920 " InnoDB: Flush lsn in the tablespace file %lu"
2922 "InnoDB: is %"PRIu64
", which exceeds current"
2923 " system lsn %"PRIu64
".\n"
2924 "InnoDB: We reset the lsn's in the file ",
2926 flush_lsn, current_lsn);
2928 fputs(
".\n", stderr);
2931 ut_a(zip_size <= UNIV_PAGE_SIZE);
2938 for (offset = 0; offset < file_size;
2939 offset += zip_size ? zip_size : UNIV_PAGE_SIZE) {
2940 success = os_file_read(file, page,
2941 (ulint)(offset & 0xFFFFFFFFUL),
2942 (ulint)(offset >> 32),
2943 zip_size ? zip_size : UNIV_PAGE_SIZE);
2952 memcpy(page_zip.
data, page, zip_size);
2953 buf_flush_init_for_writing(
2954 page, &page_zip, current_lsn);
2955 success = os_file_write(
2956 filepath, file, page_zip.
data,
2957 (ulint) offset & 0xFFFFFFFFUL,
2958 (ulint) (offset >> 32), zip_size);
2960 buf_flush_init_for_writing(
2961 page, NULL, current_lsn);
2962 success = os_file_write(
2963 filepath, file, page,
2964 (ulint)(offset & 0xFFFFFFFFUL),
2965 (ulint)(offset >> 32),
2976 success = os_file_flush(file);
2983 success = os_file_read(file, page, 0, 0,
2984 zip_size ? zip_size : UNIV_PAGE_SIZE);
2992 success = os_file_write(filepath, file, page, 0, 0,
2993 zip_size ? zip_size : UNIV_PAGE_SIZE);
2998 success = os_file_flush(file);
3000 os_file_close(file);
3019 fil_open_single_table_tablespace(
3021 ibool check_space_id,
3041 filepath = fil_make_ibd_name(name, FALSE);
3052 file = os_file_create_simple_no_error_handling(
3054 OS_FILE_READ_ONLY, &success);
3061 fputs(
" InnoDB: Error: trying to open a table,"
3063 "InnoDB: open the tablespace file ", stderr);
3066 "InnoDB: Have you moved InnoDB .ibd files around"
3067 " without using the\n"
3068 "InnoDB: commands DISCARD TABLESPACE and"
3069 " IMPORT TABLESPACE?\n"
3070 "InnoDB: It is also possible that this is"
3071 " a temporary table #sql...,\n"
3072 "InnoDB: and MySQL removed the .ibd file for this.\n"
3073 "InnoDB: Please refer to\n"
3074 "InnoDB: " REFMAN
"innodb-troubleshooting-datadict.html\n"
3075 "InnoDB: for how to resolve the issue.\n", stderr);
3082 if (!check_space_id) {
3090 buf2 =
static_cast<byte *
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
3092 page =
static_cast<byte *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
3094 success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
3098 space_id = fsp_header_get_space_id(page);
3099 space_flags = fsp_header_get_flags(page);
3103 if (UNIV_UNLIKELY(space_id !=
id
3107 fputs(
" InnoDB: Error: tablespace id and flags in file ",
3110 fprintf(stderr,
" are %lu and %lu, but in the InnoDB\n"
3111 "InnoDB: data dictionary they are %lu and %lu.\n"
3112 "InnoDB: Have you moved InnoDB .ibd files"
3113 " around without using the\n"
3114 "InnoDB: commands DISCARD TABLESPACE and"
3115 " IMPORT TABLESPACE?\n"
3116 "InnoDB: Please refer to\n"
3117 "InnoDB: " REFMAN
"innodb-troubleshooting-datadict.html\n"
3118 "InnoDB: for how to resolve the issue.\n",
3119 (ulong) space_id, (ulong) space_flags,
3120 (ulong)
id, (ulong) flags);
3128 success = fil_space_create(filepath, space_id, flags,
FIL_TABLESPACE);
3137 fil_node_create(filepath, 0, space_id, FALSE);
3139 os_file_close(file);
3146 #ifdef UNIV_HOTBACKUP
3153 fil_make_ibbackup_old_name(
3157 static const char suffix[] =
"_ibbackup_old_vers_";
3158 ulint len = strlen(name);
3159 char* path = mem_alloc(len + (15 +
sizeof suffix));
3161 memcpy(path, name, len);
3162 memcpy(path + len, suffix, (
sizeof suffix) - 1);
3163 ut_sprintf_timestamp_without_extra_chars(path + len +
sizeof suffix);
3173 fil_load_single_table_tablespace(
3176 const char* filename)
3189 #ifdef UNIV_HOTBACKUP
3192 filepath =
static_cast<char *
>(mem_alloc(strlen(dbname) + strlen(filename)
3193 + strlen(fil_path_to_mysql_datadir) + 3));
3195 sprintf(filepath,
"%s/%s/%s", fil_path_to_mysql_datadir, dbname,
3199 # ifndef UNIV_HOTBACKUP
3206 dict_casedn_str(filepath);
3209 file = os_file_create_simple_no_error_handling(
3211 OS_FILE_READ_ONLY, &success);
3217 "InnoDB: Error: could not open single-table tablespace"
3220 "InnoDB: We do not continue the crash recovery,"
3221 " because the table may become\n"
3222 "InnoDB: corrupt if we cannot apply the log records"
3223 " in the InnoDB log to it.\n"
3224 "InnoDB: To fix the problem and start mysqld:\n"
3225 "InnoDB: 1) If there is a permission problem"
3226 " in the file and mysqld cannot\n"
3227 "InnoDB: open the file, you should"
3228 " modify the permissions.\n"
3229 "InnoDB: 2) If the table is not needed, or you can"
3230 " restore it from a backup,\n"
3231 "InnoDB: then you can remove the .ibd file,"
3232 " and InnoDB will do a normal\n"
3233 "InnoDB: crash recovery and ignore that table.\n"
3234 "InnoDB: 3) If the file system or the"
3235 " disk is broken, and you cannot remove\n"
3236 "InnoDB: the .ibd file, you can set"
3237 " innodb_force_recovery > 0 in my.cnf\n"
3238 "InnoDB: and force InnoDB to continue crash"
3239 " recovery here.\n", filepath);
3243 if (srv_force_recovery > 0) {
3245 "InnoDB: innodb_force_recovery"
3246 " was set to %lu. Continuing crash recovery\n"
3247 "InnoDB: even though we cannot access"
3248 " the .ibd file of this table.\n",
3249 srv_force_recovery);
3263 "InnoDB: Error: could not measure the size"
3264 " of single-table tablespace file\n"
3266 "InnoDB: We do not continue crash recovery,"
3267 " because the table will become\n"
3268 "InnoDB: corrupt if we cannot apply the log records"
3269 " in the InnoDB log to it.\n"
3270 "InnoDB: To fix the problem and start mysqld:\n"
3271 "InnoDB: 1) If there is a permission problem"
3272 " in the file and mysqld cannot\n"
3273 "InnoDB: access the file, you should"
3274 " modify the permissions.\n"
3275 "InnoDB: 2) If the table is not needed,"
3276 " or you can restore it from a backup,\n"
3277 "InnoDB: then you can remove the .ibd file,"
3278 " and InnoDB will do a normal\n"
3279 "InnoDB: crash recovery and ignore that table.\n"
3280 "InnoDB: 3) If the file system or the disk is broken,"
3281 " and you cannot remove\n"
3282 "InnoDB: the .ibd file, you can set"
3283 " innodb_force_recovery > 0 in my.cnf\n"
3284 "InnoDB: and force InnoDB to continue"
3285 " crash recovery here.\n", filepath);
3287 os_file_close(file);
3290 if (srv_force_recovery > 0) {
3292 "InnoDB: innodb_force_recovery"
3293 " was set to %lu. Continuing crash recovery\n"
3294 "InnoDB: even though we cannot access"
3295 " the .ibd file of this table.\n",
3296 srv_force_recovery);
3309 size = (((ib_int64_t)size_high) << 32) + (ib_int64_t)size_low;
3310 #ifndef UNIV_HOTBACKUP
3313 "InnoDB: Error: the size of single-table tablespace"
3315 "InnoDB: is only %lu %lu, should be at least %lu!",
3318 (ulong) size_low, (ulong) (4 * UNIV_PAGE_SIZE));
3319 os_file_close(file);
3327 buf2 =
static_cast<byte *
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
3329 page =
static_cast<byte *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
3332 success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
3336 space_id = fsp_header_get_space_id(page);
3337 flags = fsp_header_get_flags(page);
3339 space_id = ULINT_UNDEFINED;
3343 #ifndef UNIV_HOTBACKUP
3344 if (space_id == ULINT_UNDEFINED || space_id == 0) {
3346 "InnoDB: Error: tablespace id %lu in file %s"
3347 " is not sensible\n",
3353 if (space_id == ULINT_UNDEFINED || space_id == 0) {
3357 "InnoDB: Renaming tablespace %s of id %lu,\n"
3358 "InnoDB: to %s_ibbackup_old_vers_<timestamp>\n"
3359 "InnoDB: because its size %" PRId64
" is too small"
3360 " (< 4 pages 16 kB each),\n"
3361 "InnoDB: or the space id in the file header"
3362 " is not sensible.\n"
3363 "InnoDB: This can happen in an ibbackup run,"
3364 " and is not dangerous.\n",
3365 filepath, space_id, filepath, size);
3366 os_file_close(file);
3368 new_path = fil_make_ibbackup_old_name(filepath);
3369 ut_a(os_file_rename(innodb_file_data_key, filepath, new_path));
3385 mutex_enter(&fil_system->
mutex);
3387 space = fil_space_get_by_id(space_id);
3393 "InnoDB: Renaming tablespace %s of id %lu,\n"
3394 "InnoDB: to %s_ibbackup_old_vers_<timestamp>\n"
3395 "InnoDB: because space %s with the same id\n"
3396 "InnoDB: was scanned earlier. This can happen"
3397 " if you have renamed tables\n"
3398 "InnoDB: during an ibbackup run.\n",
3399 filepath, space_id, filepath,
3401 os_file_close(file);
3403 new_path = fil_make_ibbackup_old_name(filepath);
3405 mutex_exit(&fil_system->
mutex);
3407 ut_a(os_file_rename(innodb_file_data_key, filepath, new_path));
3415 mutex_exit(&fil_system->
mutex);
3417 success = fil_space_create(filepath, space_id, flags,
FIL_TABLESPACE);
3421 if (srv_force_recovery > 0) {
3423 "InnoDB: innodb_force_recovery"
3424 " was set to %lu. Continuing crash recovery\n"
3425 "InnoDB: even though the tablespace creation"
3426 " of this table failed.\n",
3427 srv_force_recovery);
3438 fil_node_create(filepath, 0, space_id, FALSE);
3440 os_file_close(file);
3452 fil_file_readdir_next_file(
3456 const char* dirname,
3463 for (i = 0; i < 100; i++) {
3472 "InnoDB: Error: os_file_readdir_next_file()"
3474 "InnoDB: directory %s\n"
3475 "InnoDB: Crash recovery may have failed"
3476 " for some .ibd files!\n", dirname);
3494 fil_load_single_table_tablespaces(
void)
3498 char* dbpath = NULL;
3499 ulint dbpath_len = 100;
3504 ulint err = DB_SUCCESS;
3515 dbpath =
static_cast<char *
>(mem_alloc(dbpath_len));
3520 ret = fil_file_readdir_next_file(&err, fil_path_to_mysql_datadir, dir,
3526 if (dbinfo.
type == OS_FILE_TYPE_FILE
3527 || dbinfo.
type == OS_FILE_TYPE_UNKNOWN) {
3529 goto next_datadir_item;
3535 len = strlen(fil_path_to_mysql_datadir)
3536 + strlen (dbinfo.
name) + 2;
3537 if (len > dbpath_len) {
3544 dbpath =
static_cast<char *
>(mem_alloc(dbpath_len));
3546 sprintf(dbpath,
"%s/%s", fil_path_to_mysql_datadir,
3552 if (dbdir != NULL) {
3558 ret = fil_file_readdir_next_file(&err, dbpath, dbdir,
3564 if (fileinfo.
type == OS_FILE_TYPE_DIR) {
3566 goto next_file_item;
3570 if (strlen(fileinfo.
name) > 4
3571 && 0 == strcmp(fileinfo.
name
3572 + strlen(fileinfo.
name) - 4,
3576 fil_load_single_table_tablespace(
3580 ret = fil_file_readdir_next_file(&err,
3586 fputs(
"InnoDB: Warning: could not"
3587 " close database directory ", stderr);
3596 ret = fil_file_readdir_next_file(&err,
3597 fil_path_to_mysql_datadir,
3605 "InnoDB: Error: could not close MySQL datadir\n");
3619 fil_tablespace_deleted_or_being_deleted_in_mem(
3630 mutex_enter(&fil_system->
mutex);
3632 space = fil_space_get_by_id(
id);
3635 mutex_exit(&fil_system->
mutex);
3640 if (version != ((ib_int64_t)-1)
3642 mutex_exit(&fil_system->
mutex);
3647 mutex_exit(&fil_system->
mutex);
3657 fil_tablespace_exists_in_mem(
3665 mutex_enter(&fil_system->
mutex);
3667 space = fil_space_get_by_id(
id);
3669 mutex_exit(&fil_system->
mutex);
3671 return(space != NULL);
3681 fil_space_for_table_exists_in_mem(
3695 ibool print_error_if_does_not_exist)
3707 mutex_enter(&fil_system->
mutex);
3709 path = fil_make_ibd_name(name, is_temp);
3713 space = fil_space_get_by_id(
id);
3718 tablespace = fil_space_get_by_name(path);
3719 if (space && space == tablespace) {
3727 mutex_exit(&fil_system->
mutex);
3732 if (!print_error_if_does_not_exist) {
3735 mutex_exit(&fil_system->
mutex);
3740 if (space == NULL) {
3741 if (tablespace == NULL) {
3743 fputs(
" InnoDB: Error: table ", stderr);
3745 fprintf(stderr,
"\n"
3746 "InnoDB: in InnoDB data dictionary"
3747 " has tablespace id %lu,\n"
3748 "InnoDB: but tablespace with that id"
3749 " or name does not exist. Have\n"
3750 "InnoDB: you deleted or moved .ibd files?\n"
3751 "InnoDB: This may also be a table created with"
3752 " CREATE TEMPORARY TABLE\n"
3753 "InnoDB: whose .ibd and .frm files"
3754 " MySQL automatically removed, but the\n"
3755 "InnoDB: table still exists in the"
3756 " InnoDB internal data dictionary.\n",
3760 fputs(
" InnoDB: Error: table ", stderr);
3762 fprintf(stderr,
"\n"
3763 "InnoDB: in InnoDB data dictionary has"
3764 " tablespace id %lu,\n"
3765 "InnoDB: but a tablespace with that id"
3766 " does not exist. There is\n"
3767 "InnoDB: a tablespace of name %s and id %lu,"
3769 "InnoDB: you deleted or moved .ibd files?\n",
3770 (ulong)
id, tablespace->
name,
3771 (ulong) tablespace->
id);
3774 fputs(
"InnoDB: Please refer to\n"
3775 "InnoDB: " REFMAN
"innodb-troubleshooting-datadict.html\n"
3776 "InnoDB: for how to resolve the issue.\n", stderr);
3779 mutex_exit(&fil_system->
mutex);
3784 if (0 != strcmp(space->
name, path)) {
3786 fputs(
" InnoDB: Error: table ", stderr);
3788 fprintf(stderr,
"\n"
3789 "InnoDB: in InnoDB data dictionary has"
3790 " tablespace id %lu,\n"
3791 "InnoDB: but the tablespace with that id"
3793 "InnoDB: Have you deleted or moved .ibd files?\n",
3794 (ulong)
id, space->
name);
3796 if (tablespace != NULL) {
3797 fputs(
"InnoDB: There is a tablespace"
3798 " with the right name\n"
3799 "InnoDB: ", stderr);
3801 fprintf(stderr,
", but its id is %lu.\n",
3802 (ulong) tablespace->
id);
3809 mutex_exit(&fil_system->
mutex);
3820 fil_get_space_id_for_table(
3826 ulint
id = ULINT_UNDEFINED;
3831 mutex_enter(&fil_system->
mutex);
3833 path = fil_make_ibd_name(name, FALSE);
3838 tablespace = fil_space_get_by_name(path);
3841 id = tablespace->
id;
3846 mutex_exit(&fil_system->
mutex);
3858 fil_extend_space_to_desired_size(
3864 ulint size_after_extend)
3873 ulint start_page_no;
3874 ulint file_start_page_no;
3878 ibool success = TRUE;
3880 fil_mutex_enter_and_prepare_for_io(space_id);
3882 space = fil_space_get_by_id(space_id);
3885 if (space->
size >= size_after_extend) {
3888 *actual_size = space->
size;
3890 mutex_exit(&fil_system->
mutex);
3897 page_size = UNIV_PAGE_SIZE;
3902 fil_node_prepare_for_io(node, fil_system, space);
3904 start_page_no = space->
size;
3905 file_start_page_no = space->
size - node->
size;
3908 buf_size =
ut_min(64, size_after_extend - start_page_no) * page_size;
3909 buf2 =
static_cast<byte *
>(mem_alloc(buf_size + page_size));
3910 buf =
static_cast<byte *
>(
ut_align(buf2, page_size));
3912 memset(buf, 0, buf_size);
3914 while (start_page_no < size_after_extend) {
3915 ulint n_pages =
ut_min(buf_size / page_size,
3916 size_after_extend - start_page_no);
3918 offset_high = (start_page_no - file_start_page_no)
3919 / (4096 * ((1024 * 1024) / page_size));
3920 offset_low = ((start_page_no - file_start_page_no)
3921 % (4096 * ((1024 * 1024) / page_size)))
3923 #ifdef UNIV_HOTBACKUP
3924 success = os_file_write(node->
name, node->
handle, buf,
3925 offset_low, offset_high,
3926 page_size * n_pages);
3930 offset_low, offset_high,
3931 page_size * n_pages,
3935 node->
size += n_pages;
3936 space->
size += n_pages;
3938 os_has_said_disk_full = FALSE;
3946 / page_size)) - node->
size;
3948 node->
size += n_pages;
3949 space->
size += n_pages;
3954 start_page_no += n_pages;
3959 fil_node_complete_io(node, fil_system, OS_FILE_WRITE);
3961 *actual_size = space->
size;
3963 #ifndef UNIV_HOTBACKUP
3964 if (space_id == 0) {
3965 ulint pages_per_mb = (1024 * 1024) / page_size;
3970 srv_data_file_sizes[srv_n_data_files - 1]
3971 = (node->
size / pages_per_mb) * pages_per_mb;
3978 mutex_exit(&fil_system->
mutex);
3980 fil_flush(space_id);
3985 #ifdef UNIV_HOTBACKUP
3993 fil_extend_tablespaces_to_stored_len(
void)
3999 ulint size_in_header;
4003 buf = mem_alloc(UNIV_PAGE_SIZE);
4005 mutex_enter(&fil_system->
mutex);
4012 mutex_exit(&fil_system->
mutex);
4015 error = fil_read(TRUE, space->
id,
4017 0, 0, UNIV_PAGE_SIZE, buf, NULL);
4018 ut_a(error == DB_SUCCESS);
4020 size_in_header = fsp_get_size_low(buf);
4022 success = fil_extend_space_to_desired_size(
4023 &actual_size, space->
id, size_in_header);
4026 "InnoDB: Error: could not extend the"
4027 " tablespace of %s\n"
4028 "InnoDB: to the size stored in header,"
4030 "InnoDB: size after extension %lu pages\n"
4031 "InnoDB: Check that you have free disk space"
4033 space->
name, size_in_header, actual_size);
4037 mutex_enter(&fil_system->
mutex);
4042 mutex_exit(&fil_system->
mutex);
4055 fil_space_reserve_free_extents(
4066 mutex_enter(&fil_system->
mutex);
4068 space = fil_space_get_by_id(
id);
4079 mutex_exit(&fil_system->
mutex);
4088 fil_space_release_free_extents(
4097 mutex_enter(&fil_system->
mutex);
4099 space = fil_space_get_by_id(
id);
4106 mutex_exit(&fil_system->
mutex);
4114 fil_space_get_n_reserved_extents(
4123 mutex_enter(&fil_system->
mutex);
4125 space = fil_space_get_by_id(
id);
4131 mutex_exit(&fil_system->
mutex);
4147 fil_node_prepare_for_io(
4153 ut_ad(node && system && space);
4159 " InnoDB: Warning: open files %lu"
4160 " exceeds the limit %lu\n",
4165 if (node->
open == FALSE) {
4169 fil_node_open_file(node, system, space);
4173 && space->
id != 0) {
4189 fil_node_complete_io(
4205 if (type == OS_FILE_WRITE) {
4213 system->unflushed_spaces,
4229 fil_report_invalid_page_access(
4233 const char* space_name,
4239 "InnoDB: Error: trying to access page number %lu"
4241 "InnoDB: space name %s,\n"
4242 "InnoDB: which is outside the tablespace bounds.\n"
4243 "InnoDB: Byte offset %lu, len %lu, i/o type %lu.\n"
4244 "InnoDB: If you get this error at mysqld startup,"
4245 " please check that\n"
4246 "InnoDB: your my.cnf matches the ibdata files"
4247 " that you have in the\n"
4248 "InnoDB: MySQL server.\n",
4249 (ulong) block_offset, (ulong) space_id, space_name,
4250 (ulong) byte_offset, (ulong) len, (ulong) type);
4296 is_log = type & OS_FILE_LOG;
4297 type = type & ~OS_FILE_LOG;
4300 type = type & ~OS_AIO_SIMULATED_WAKE_LATER;
4302 ut_ad(byte_offset < UNIV_PAGE_SIZE);
4303 ut_ad(!zip_size || !byte_offset);
4307 ut_ad(fil_validate());
4308 #ifndef UNIV_HOTBACKUP
4309 # ifndef UNIV_LOG_DEBUG
4314 ut_ad(!ibuf_inside() || is_log || (type == OS_FILE_WRITE)
4315 || ibuf_page(space_id, zip_size, block_offset, NULL));
4319 }
else if (is_log) {
4323 && ibuf_page(space_id, zip_size, block_offset, NULL)) {
4334 srv_data_read+= len;
4335 }
else if (type == OS_FILE_WRITE) {
4336 srv_data_written+= len;
4342 fil_mutex_enter_and_prepare_for_io(space_id);
4344 space = fil_space_get_by_id(space_id);
4347 mutex_exit(&fil_system->
mutex);
4351 " InnoDB: Error: trying to do i/o"
4352 " to a tablespace which does not exist.\n"
4353 "InnoDB: i/o type %lu, space id %lu,"
4354 " page no. %lu, i/o length %lu bytes\n",
4355 (ulong) type, (ulong) space_id, (ulong) block_offset,
4358 return(DB_TABLESPACE_DELETED);
4366 if (UNIV_UNLIKELY(node == NULL)) {
4367 fil_report_invalid_page_access(
4368 block_offset, space_id, space->
name,
4369 byte_offset, len, type);
4374 if (space->
id != 0 && node->
size == 0) {
4381 if (node->
size > block_offset) {
4385 block_offset -= node->
size;
4391 fil_node_prepare_for_io(node, fil_system, space);
4395 if (UNIV_UNLIKELY(node->
size <= block_offset)
4398 fil_report_invalid_page_access(
4399 block_offset, space_id, space->
name, byte_offset,
4406 mutex_exit(&fil_system->
mutex);
4411 offset_high = (block_offset >> (32 - UNIV_PAGE_SIZE_SHIFT));
4412 offset_low = ((block_offset << UNIV_PAGE_SIZE_SHIFT)
4413 & 0xFFFFFFFFUL) + byte_offset;
4416 >= ((byte_offset + len + (UNIV_PAGE_SIZE - 1))
4419 ulint zip_size_shift;
4421 case 1024: zip_size_shift = 10;
break;
4422 case 2048: zip_size_shift = 11;
break;
4423 case 4096: zip_size_shift = 12;
break;
4424 case 8192: zip_size_shift = 13;
break;
4425 case 16384: zip_size_shift = 14;
break;
4428 offset_high = block_offset >> (32 - zip_size_shift);
4429 offset_low = (block_offset << zip_size_shift & 0xFFFFFFFFUL)
4432 >= (len + (zip_size - 1)) / zip_size);
4440 #ifdef UNIV_HOTBACKUP
4443 ret = os_file_read(node->
handle, buf, offset_low, offset_high,
4446 ret = os_file_write(node->
name, node->
handle, buf,
4447 offset_low, offset_high, len);
4451 ret = os_aio(type, mode | wake_later, node->
name, node->
handle, buf,
4452 offset_low, offset_high, len, node, message);
4460 mutex_enter(&fil_system->
mutex);
4462 fil_node_complete_io(node, fil_system, type);
4464 mutex_exit(&fil_system->
mutex);
4466 ut_ad(fil_validate());
4487 fil_mutex_enter_and_prepare_for_io(space_id);
4489 space = fil_space_get_by_id(space_id);
4492 mutex_exit(&fil_system->
mutex);
4499 if (UNIV_UNLIKELY(node == NULL)) {
4500 mutex_exit(&fil_system->
mutex);
4504 if (space->
id != 0 && node->
size == 0) {
4511 if (node->
size > block_offset) {
4515 block_offset -= node->
size;
4521 fil_node_prepare_for_io(node, fil_system, space);
4526 if (UNIV_UNLIKELY(node->
size <= block_offset)
4528 mutex_exit(&fil_system->
mutex);
4532 mutex_exit(&fil_system->
mutex);
4536 #ifndef UNIV_HOTBACKUP
4554 ut_ad(fil_validate());
4556 if (srv_use_native_aio) {
4559 ret = os_aio_windows_handle(segment, 0, &fil_node,
4561 #elif defined(LINUX_NATIVE_AIO)
4562 ret = os_aio_linux_handle(segment, &fil_node,
4579 mutex_enter(&fil_system->
mutex);
4581 fil_node_complete_io(fil_node, fil_system, type);
4583 mutex_exit(&fil_system->
mutex);
4585 ut_ad(fil_validate());
4595 buf_page_io_complete(static_cast<buf_page_t *>(message));
4616 ib_int64_t old_mod_counter;
4618 mutex_enter(&fil_system->
mutex);
4620 space = fil_space_get_by_id(space_id);
4623 mutex_exit(&fil_system->
mutex);
4641 fil_n_pending_tablespace_flushes++;
4643 fil_n_pending_log_flushes++;
4644 fil_n_log_flushes++;
4659 mutex_exit(&fil_system->
mutex);
4663 mutex_enter(&fil_system->
mutex);
4677 mutex_exit(&fil_system->
mutex);
4682 os_file_flush(file);
4684 mutex_enter(&fil_system->
mutex);
4692 && fil_space_is_flushed(space)) {
4698 fil_system->unflushed_spaces,
4704 fil_n_pending_tablespace_flushes--;
4706 fil_n_pending_log_flushes--;
4715 mutex_exit(&fil_system->
mutex);
4723 fil_flush_file_spaces(
4732 mutex_enter(&fil_system->
mutex);
4735 if (n_space_ids == 0) {
4737 mutex_exit(&fil_system->
mutex);
4745 space_ids =
static_cast<unsigned long *
>(mem_alloc(n_space_ids *
sizeof *space_ids));
4755 space_ids[n_space_ids++] = space->
id;
4759 mutex_exit(&fil_system->
mutex);
4763 for (i = 0; i < n_space_ids; i++) {
4765 fil_flush(space_ids[i]);
4784 mutex_enter(&fil_system->
mutex);
4792 while (space != NULL) {
4794 ut_a(ut_list_node_313->open
4795 || !ut_list_node_313->n_pending));
4799 while (fil_node != NULL) {
4804 if (fil_node->
open) {
4819 while (fil_node != NULL) {
4828 mutex_exit(&fil_system->
mutex);
4905 #ifndef UNIV_HOTBACKUP
4910 hash_table_free(fil_system->
spaces);