48 #ifndef UNIV_HOTBACKUP
55 static ulint srv_data_read, srv_data_written;
133 #ifdef UNIV_PFS_MUTEX
135 UNIV_INTERN mysql_pfs_key_t fil_system_mutex_key;
138 #ifdef UNIV_PFS_RWLOCK
140 UNIV_INTERN mysql_pfs_key_t fil_space_latch_key;
181 #define FIL_NODE_MAGIC_N 89389
188 ib_int64_t tablespace_version;
225 ulint n_reserved_extents;
239 hash_node_t name_hash;
240 #ifndef UNIV_HOTBACKUP
247 bool is_in_unflushed_spaces;
256 #define FIL_SPACE_MAGIC_N 89472
262 #ifndef UNIV_HOTBACKUP
292 ulint max_assigned_id;
298 ib_int64_t tablespace_version;
308 ibool space_id_reuse_warned;
319 # define fil_is_user_tablespace_id(i) ((i) > srv_undo_tablespaces_open)
323 # define fil_buffering_disabled(s) \
324 ((s)->purpose == FIL_TABLESPACE \
325 && srv_unix_file_flush_method \
326 == SRV_UNIX_O_DIRECT_NO_FSYNC)
328 # define fil_buffering_disabled(s) (0)
333 # define FIL_VALIDATE_SKIP 17
340 fil_validate_skip(
void)
345 static int fil_validate_count = FIL_VALIDATE_SKIP;
351 if (--fil_validate_count > 0) {
355 fil_validate_count = FIL_VALIDATE_SKIP;
383 fil_node_prepare_for_io(
393 fil_node_complete_io(
438 byte_offset, len, buf, message));
468 return(
fil_io(OS_FILE_WRITE, sync, space_id, zip_size, block_offset,
469 byte_offset, len, buf, message));
505 fold = ut_fold_string(name);
510 !strcmp(name, space->
name));
515 #ifndef UNIV_HOTBACKUP
527 ib_int64_t version = -1;
531 mutex_enter(&fil_system->
mutex);
539 mutex_exit(&fil_system->
mutex);
558 mutex_enter(&fil_system->
mutex);
565 *flags = space->
flags;
568 mutex_exit(&fil_system->
mutex);
570 return(&(space->
latch));
586 mutex_enter(&fil_system->
mutex);
592 mutex_exit(&fil_system->
mutex);
604 fil_space_is_flushed(
647 mutex_enter(&fil_system->
mutex);
665 " InnoDB: Error: Could not find tablespace %lu for\n"
666 "InnoDB: file ", (ulong)
id);
668 fputs(
" in the tablespace memory cache.\n", stderr);
673 mutex_exit(&fil_system->
mutex);
684 if (id < SRV_LOG_SPACE_FIRST_ID && fil_system->max_assigned_id <
id) {
689 mutex_exit(&fil_system->
mutex);
719 if (node->
size == 0) {
728 node->
handle = os_file_create_simple_no_error_handling(
730 OS_FILE_READ_ONLY, &success);
737 ib_logf(IB_LOG_LEVEL_WARN,
"InnoDB: Error: cannot "
738 "open %s\n. InnoDB: Have you deleted .ibd "
739 "files under a running mysqld server?\n",
747 #ifdef UNIV_HOTBACKUP
748 if (space->
id == 0) {
749 node->
size = (ulint) (size_bytes / UNIV_PAGE_SIZE);
750 os_file_close(node->
handle);
759 "InnoDB: Error: the size of single-table"
760 " tablespace file %s\n"
761 "InnoDB: is only "UINT64PF
","
762 " should be at least %lu!\n",
773 buf2 =
static_cast<byte*
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
776 page =
static_cast<byte*
>(
ut_align(buf2, UNIV_PAGE_SIZE));
778 success = os_file_read(node->
handle, page, 0, UNIV_PAGE_SIZE);
787 os_file_close(node->
handle);
789 if (UNIV_UNLIKELY(space_id != space->
id)) {
791 "InnoDB: Error: tablespace id is %lu"
792 " in the data dictionary\n"
793 "InnoDB: but in file %s it is %lu!\n",
794 space->
id, node->
name, space_id);
799 if (UNIV_UNLIKELY(space_id == ULINT_UNDEFINED
802 "InnoDB: Error: tablespace id %lu"
803 " in file %s is not sensible\n",
804 (ulong) space_id, node->
name);
812 "InnoDB: Error: tablespace file %s"
813 " has page size 0x%lx\n"
814 "InnoDB: but the data dictionary"
815 " expects page size 0x%lx!\n",
822 if (UNIV_UNLIKELY(space->
flags != flags)) {
824 "InnoDB: Error: table flags are 0x%lx"
825 " in the data dictionary\n"
826 "InnoDB: but the flags in file %s are 0x%lx!\n",
832 if (size_bytes >= 1024 * 1024) {
838 node->
size = (ulint) (size_bytes / UNIV_PAGE_SIZE);
845 #ifdef UNIV_HOTBACKUP
858 node->
handle = os_file_create(innodb_file_log_key,
860 OS_FILE_AIO, OS_LOG_FILE,
863 node->
handle = os_file_create(innodb_file_data_key,
869 node->
handle = os_file_create(innodb_file_data_key,
902 ut_ad(node && system);
908 #ifndef UNIV_HOTBACKUP
913 ret = os_file_close(node->
handle);
942 fil_try_to_close_file_in_LRU(
953 "InnoDB: fil_sys open file LRU len %lu\n",
965 fil_node_close_file(node, fil_system);
975 fputs(
"InnoDB: cannot close file ", stderr);
977 fprintf(stderr,
", because n_pending_flushes %lu\n",
982 fputs(
"InnoDB: cannot close file ", stderr);
985 ", because mod_count %ld != fl_count %ld\n",
992 fputs(
"InnoDB: cannot close file ", stderr);
994 fprintf(stderr,
", because it is being extended\n");
1007 fil_mutex_enter_and_prepare_for_io(
1013 ibool print_info = FALSE;
1018 mutex_enter(&fil_system->
mutex);
1032 if (space != NULL && space->
stop_ios) {
1036 if (count2 > 20000) {
1037 fputs(
"InnoDB: Warning: tablespace ", stderr);
1040 " has i/o ops stopped for a long time %lu\n",
1044 mutex_exit(&fil_system->
mutex);
1046 #ifndef UNIV_HOTBACKUP
1092 success = fil_try_to_close_file_in_LRU(print_info);
1108 " InnoDB: Warning: too many (%lu) files stay open"
1109 " while the maximum\n"
1110 "InnoDB: allowed value would be %lu.\n"
1111 "InnoDB: You may need to raise the value of"
1112 " innodb_open_files in\n"
1113 "InnoDB: my.cnf.\n",
1114 (ulong) fil_system->
n_open,
1120 mutex_exit(&fil_system->
mutex);
1122 #ifndef UNIV_HOTBACKUP
1149 ut_ad(node && system && space);
1165 ut_ad(fil_space_is_flushed(space));
1168 && fil_space_is_flushed(space)) {
1173 system->unflushed_spaces,
1177 fil_node_close_file(node, system);
1189 #ifdef UNIV_LOG_ARCHIVE
1195 fil_space_truncate_start(
1205 mutex_enter(&fil_system->
mutex);
1211 while (trunc_len > 0) {
1214 ut_a(node->
size * UNIV_PAGE_SIZE <= trunc_len);
1216 trunc_len -= node->
size * UNIV_PAGE_SIZE;
1218 fil_node_free(node, fil_system, space);
1221 mutex_exit(&fil_system->
mutex);
1240 DBUG_EXECUTE_IF(
"fil_space_create_failure",
return(
false););
1247 mutex_enter(&fil_system->
mutex);
1253 "Tablespace '%s' exists in the cache "
1254 "with id %lu != %lu",
1255 name, (ulong) space->
id, (ulong)
id);
1259 mutex_exit(&fil_system->
mutex);
1265 "Freeing existing tablespace '%s' entry "
1266 "from the cache with id %lu",
1269 ibool success = fil_space_free(space->
id, FALSE);
1272 mutex_exit(&fil_system->
mutex);
1275 }
while (space != 0);
1281 "Trying to add tablespace '%s' with id %lu "
1282 "to the tablespace memory cache, but tablespace '%s' "
1283 "with id %lu already exists in the cache!",
1284 name, (ulong)
id, space->
name, (ulong) space->
id);
1286 mutex_exit(&fil_system->
mutex);
1298 space->
mark = FALSE;
1303 if (!fil_system->space_id_reuse_warned) {
1304 fil_system->space_id_reuse_warned = TRUE;
1307 "Allocated tablespace %lu, old maximum "
1326 ut_fold_string(name), space);
1331 mutex_exit(&fil_system->
mutex);
1350 mutex_enter(&fil_system->
mutex);
1354 if (id < fil_system->max_assigned_id) {
1363 "InnoDB: Warning: you are running out of new"
1364 " single-table tablespace id's.\n"
1365 "InnoDB: Current counter is %lu and it"
1366 " must not exceed %lu!\n"
1367 "InnoDB: To reset the counter to zero"
1368 " you have to dump all your tables and\n"
1369 "InnoDB: recreate the whole InnoDB installation.\n",
1381 "InnoDB: You have run out of single-table"
1382 " tablespace id's!\n"
1383 "InnoDB: Current counter is %lu.\n"
1384 "InnoDB: To reset the counter to zero you"
1385 " have to dump all your tables and\n"
1386 "InnoDB: recreate the whole InnoDB installation.\n",
1388 *space_id = ULINT_UNDEFINED;
1391 mutex_exit(&fil_system->
mutex);
1420 " InnoDB: Error: trying to remove tablespace %lu"
1421 " from the cache but\n"
1422 "InnoDB: it is not there.\n", (ulong)
id);
1431 ut_a(space == fnamespace);
1434 ut_fold_string(space->
name), space);
1454 fil_node_free(fil_node, fil_system, space);
1460 rw_lock_x_unlock(&space->
latch);
1463 rw_lock_free(&(space->
latch));
1487 if (space == NULL) {
1494 mutex_exit(&fil_system->
mutex);
1500 fil_mutex_enter_and_prepare_for_io(
id);
1505 if (space == NULL) {
1519 if (!fil_node_prepare_for_io(node, fil_system, space)) {
1549 fil_mutex_enter_and_prepare_for_io(
id);
1553 if (space == NULL) {
1554 mutex_exit(&fil_system->
mutex);
1565 mutex_exit(&fil_system->
mutex);
1584 mutex_enter(&fil_system->
mutex);
1588 size = space ? space->
size : 0;
1590 mutex_exit(&fil_system->
mutex);
1614 mutex_enter(&fil_system->
mutex);
1618 if (space == NULL) {
1619 mutex_exit(&fil_system->
mutex);
1621 return(ULINT_UNDEFINED);
1624 flags = space->
flags;
1626 mutex_exit(&fil_system->
mutex);
1645 if (flags && flags != ULINT_UNDEFINED) {
1681 ut_a(fil_system == NULL);
1683 ut_a(hash_size > 0);
1684 ut_a(max_n_open > 0);
1689 mutex_create(fil_system_mutex_key,
1690 &fil_system->
mutex, SYNC_ANY_LATCH);
1692 fil_system->
spaces = hash_create(hash_size);
1693 fil_system->
name_hash = hash_create(hash_size);
1713 mutex_enter(&fil_system->
mutex);
1731 if (!fil_node_open_file(node, fil_system,
1745 "InnoDB: Warning: you must"
1746 " raise the value of"
1747 " innodb_open_files in\n"
1748 "InnoDB: my.cnf! Remember that"
1749 " InnoDB keeps all log files"
1751 "InnoDB: tablespace files open"
1752 " for the whole time mysqld is"
1754 "InnoDB: needs to open also"
1755 " some .ibd files if the"
1756 " file-per-table storage\n"
1757 "InnoDB: model is used."
1758 " Current open files %lu,"
1760 " open files %lu.\n",
1761 (ulong) fil_system->
n_open,
1767 mutex_exit(&fil_system->
mutex);
1780 mutex_enter(&fil_system->
mutex);
1784 while (space != NULL) {
1793 fil_node_close_file(node, fil_system);
1799 fil_space_free(prev_space->
id, FALSE);
1802 mutex_exit(&fil_system->
mutex);
1816 mutex_enter(&fil_system->
mutex);
1820 while (space != NULL) {
1834 fil_node_close_file(node, fil_system);
1841 fil_space_free(prev_space->
id, FALSE);
1845 mutex_exit(&fil_system->
mutex);
1859 "InnoDB: Fatal error: max tablespace id"
1860 " is too high, %lu\n", (ulong) max_id);
1864 mutex_enter(&fil_system->
mutex);
1871 mutex_exit(&fil_system->
mutex);
1878 static __attribute__((warn_unused_result))
1880 fil_write_lsn_and_arch_no_to_file(
1886 ulint arch_log_no __attribute__((unused)))
1893 buf1 =
static_cast<byte*
>(mem_alloc(2 * UNIV_PAGE_SIZE));
1894 buf =
static_cast<byte*
>(
ut_align(buf1, UNIV_PAGE_SIZE));
1896 err =
fil_read(TRUE, space, 0, sum_of_sizes, 0,
1897 UNIV_PAGE_SIZE, buf, NULL);
1898 if (err == DB_SUCCESS) {
1901 err =
fil_write(TRUE, space, 0, sum_of_sizes, 0,
1902 UNIV_PAGE_SIZE, buf, NULL);
1925 mutex_enter(&fil_system->
mutex);
1945 mutex_exit(&fil_system->
mutex);
1947 err = fil_write_lsn_and_arch_no_to_file(
1948 space->
id, sum_of_sizes, lsn,
1951 if (err != DB_SUCCESS) {
1956 mutex_enter(&fil_system->
mutex);
1958 sum_of_sizes += node->
size;
1963 mutex_exit(&fil_system->
mutex);
1973 static __attribute__((warn_unused_result))
1975 fil_check_first_page(
1990 return(
"innodb-page-size mismatch");
1993 if (!space_id && !flags) {
1994 ulint nonzero_bytes = UNIV_PAGE_SIZE;
1995 const byte* b =
page;
1997 while (!*b && --nonzero_bytes) {
2001 if (!nonzero_bytes) {
2002 return(
"space header page consists of zero bytes");
2008 return(
"checksum mismatch");
2016 return(
"inconsistent data in space header");
2029 ibool one_read_already,
2034 #ifdef UNIV_LOG_ARCHIVE
2035 ulint* min_arch_log_no,
2037 ulint* max_arch_log_no,
2040 lsn_t* min_flushed_lsn,
2042 lsn_t* max_flushed_lsn)
2048 const char* check_msg = NULL;
2050 buf =
static_cast<byte*
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
2054 page =
static_cast<byte*
>(
ut_align(buf, UNIV_PAGE_SIZE));
2056 os_file_read(data_file, page, 0, UNIV_PAGE_SIZE);
2064 if (!one_read_already) {
2065 check_msg = fil_check_first_page(page);
2074 if (!one_read_already) {
2075 *min_flushed_lsn = flushed_lsn;
2076 *max_flushed_lsn = flushed_lsn;
2077 #ifdef UNIV_LOG_ARCHIVE
2078 *min_arch_log_no = arch_log_no;
2079 *max_arch_log_no = arch_log_no;
2084 if (*min_flushed_lsn > flushed_lsn) {
2085 *min_flushed_lsn = flushed_lsn;
2087 if (*max_flushed_lsn < flushed_lsn) {
2088 *max_flushed_lsn = flushed_lsn;
2090 #ifdef UNIV_LOG_ARCHIVE
2091 if (*min_arch_log_no > arch_log_no) {
2092 *min_arch_log_no = arch_log_no;
2094 if (*max_arch_log_no < arch_log_no) {
2095 *max_arch_log_no = arch_log_no;
2104 #ifndef UNIV_HOTBACKUP
2116 mutex_enter(&fil_system->
mutex);
2120 if (space == NULL) {
2122 "InnoDB: Error: trying to do an operation on a"
2123 " dropped tablespace %lu\n",
2128 mutex_exit(&fil_system->
mutex);
2135 mutex_exit(&fil_system->
mutex);
2150 mutex_enter(&fil_system->
mutex);
2154 if (space == NULL) {
2156 "InnoDB: Error: decrementing pending operation"
2157 " of a dropped tablespace %lu\n",
2161 if (space != NULL) {
2165 mutex_exit(&fil_system->
mutex);
2173 fil_create_directory_for_tablename(
2183 namend = strchr(name,
'/');
2185 path =
static_cast<char*
>(mem_alloc(len + (namend - name) + 2));
2189 memcpy(path + len + 1, name, namend - name);
2190 path[len + (namend -
name) + 1] = 0;
2198 #ifndef UNIV_HOTBACKUP
2219 const char* new_name,
2236 type, space_id, log_flags, log_ptr, mtr);
2244 len = strlen(name) + 1;
2253 len = strlen(new_name) + 1;
2303 const char* new_name = NULL;
2307 if (end_ptr < ptr + 4) {
2316 if (end_ptr < ptr + 2) {
2325 if (end_ptr < ptr + name_len) {
2330 name = (
const char*) ptr;
2335 if (end_ptr < ptr + 2) {
2344 if (end_ptr < ptr + new_name_len) {
2349 new_name = (
const char*) ptr;
2351 ptr += new_name_len;
2380 ut_a(err == DB_SUCCESS);
2394 fil_create_directory_for_tablename(new_name);
2400 == ULINT_UNDEFINED) {
2417 != ULINT_UNDEFINED) {
2422 const char* path = NULL;
2426 fil_create_directory_for_tablename(name);
2429 space_id, name, path, flags,
2453 const char* filepath)
2460 ut_ad(strlen(filepath) > 4);
2463 ut_snprintf(cfg_name + strlen(cfg_name) - 3, 4,
"cfg");
2472 fil_ibuf_check_pending_ops(
2483 "Trying to close/delete tablespace "
2484 "'%s' but there are %lu pending change "
2485 "buffer merges on it.",
2501 fil_check_pending_io(
2518 ut_a(!(*node)->being_extended);
2522 "Trying to close/delete tablespace '%s' "
2523 "but there are %lu flushes "
2524 " and %lu pending i/o's on it.",
2527 (ulong) (*node)->n_pending);
2541 fil_check_pending_operations(
2549 ut_a(
id != TRX_SYS_SPACE);
2554 mutex_enter(&fil_system->
mutex);
2559 mutex_exit(&fil_system->
mutex);
2564 mutex_enter(&fil_system->
mutex);
2568 count = fil_ibuf_check_pending_ops(sp, count);
2570 mutex_exit(&fil_system->
mutex);
2576 }
while (count > 0);
2583 mutex_enter(&fil_system->
mutex);
2588 mutex_exit(&fil_system->
mutex);
2589 return(DB_TABLESPACE_NOT_FOUND);
2594 count = fil_check_pending_io(sp, &node, count);
2600 mutex_exit(&fil_system->
mutex);
2606 }
while (count > 0);
2628 ut_a(
id != TRX_SYS_SPACE);
2630 dberr_t err = fil_check_pending_operations(
id, &space, &path);
2632 if (err != DB_SUCCESS) {
2639 rw_lock_x_lock(&space->
latch);
2641 #ifndef UNIV_HOTBACKUP
2651 mutex_enter(&fil_system->
mutex);
2656 if (!fil_space_free(
id, TRUE)) {
2657 rw_lock_x_unlock(&space->
latch);
2658 err = DB_TABLESPACE_NOT_FOUND;
2663 mutex_exit(&fil_system->
mutex);
2668 char* cfg_name = fil_make_cfg_name(path);
2670 os_file_delete_if_exists(innodb_file_data_key, cfg_name);
2694 ut_a(
id != TRX_SYS_SPACE);
2696 dberr_t err = fil_check_pending_operations(
id, &space, &path);
2698 if (err != DB_SUCCESS) {
2701 "Cannot delete tablespace %lu because it is not "
2702 "found in the tablespace memory cache.",
2721 rw_lock_x_lock(&space->
latch);
2723 #ifndef UNIV_HOTBACKUP
2752 char* cfg_name = fil_make_cfg_name(path);
2753 os_file_delete_if_exists(innodb_file_data_key, cfg_name);
2762 mutex_enter(&fil_system->
mutex);
2773 if (!fil_space_free(
id, TRUE)) {
2774 err = DB_TABLESPACE_NOT_FOUND;
2777 mutex_exit(&fil_system->
mutex);
2779 if (err != DB_SUCCESS) {
2780 rw_lock_x_unlock(&space->
latch);
2781 }
else if (!os_file_delete(innodb_file_data_key, path)
2782 && !os_file_delete_if_exists(innodb_file_data_key, path)) {
2790 if (err == DB_SUCCESS) {
2791 #ifndef UNIV_HOTBACKUP
2823 ibool is_being_deleted;
2825 mutex_enter(&fil_system->
mutex);
2829 ut_a(space != NULL);
2833 mutex_exit(&fil_system->
mutex);
2835 return(is_being_deleted);
2838 #ifndef UNIV_HOTBACKUP
2864 "While deleting tablespace %lu in DISCARD TABLESPACE."
2865 " File rename/delete failed: %s",
2869 case DB_TABLESPACE_NOT_FOUND:
2871 "Cannot delete tablespace %lu in DISCARD "
2893 fil_rename_tablespace_in_mem(
2897 const char* new_name,
2898 const char* new_path)
2901 const char* old_name = space->
name;
2906 if (space != space2) {
2907 fputs(
"InnoDB: Error: cannot find ", stderr);
2909 fputs(
" in tablespace memory cache\n", stderr);
2915 if (space2 != NULL) {
2916 fputs(
"InnoDB: Error: ", stderr);
2918 fputs(
" is already in tablespace memory cache\n", stderr);
2924 ut_fold_string(space->
name), space);
2932 ut_fold_string(new_name), space);
2948 ulint namelen = strlen(name);
2950 ulint pathlen = dirlen + namelen +
sizeof "/.ibd";
2952 filename =
static_cast<char*
>(mem_alloc(pathlen));
2955 memcpy(filename, name, namelen);
2956 memcpy(filename + namelen,
".ibd",
sizeof ".ibd");
2979 ulint namelen = strlen(name);
2981 ulint pathlen = dirlen + namelen +
sizeof "/.isl";
2983 filename =
static_cast<char*
>(mem_alloc(pathlen));
3001 const char* old_name_in,
3007 const char* new_name,
3010 const char* new_path_in)
3022 const char* not_given =
"(name not specified)";
3029 if (!(count % 1000)) {
3031 fputs(
" InnoDB: Warning: problems renaming ", stderr);
3033 old_name_in ? old_name_in : not_given);
3034 fputs(
" to ", stderr);
3036 fprintf(stderr,
", %lu iterations\n", (ulong) count);
3039 mutex_enter(&fil_system->
mutex);
3043 DBUG_EXECUTE_IF(
"fil_rename_tablespace_failure_1", space = NULL; );
3045 if (space == NULL) {
3047 "Cannot find space id %lu in the tablespace "
3048 "memory cache, though the table '%s' in a "
3049 "rename operation should have that id.",
3050 (ulong)
id, old_name_in ? old_name_in : not_given);
3051 mutex_exit(&fil_system->
mutex);
3056 if (count > 25000) {
3058 mutex_exit(&fil_system->
mutex);
3081 mutex_exit(&fil_system->
mutex);
3090 mutex_exit(&fil_system->
mutex);
3098 }
else if (node->
open) {
3101 fil_node_close_file(node, fil_system);
3108 ut_a(strcmp(space->
name, old_name) == 0);
3115 new_path = new_path_in ?
mem_strdup(new_path_in)
3118 success = fil_rename_tablespace_in_mem(
3119 space, node, new_name, new_path);
3123 DBUG_EXECUTE_IF(
"fil_rename_tablespace_failure_2",
3124 goto skip_second_rename; );
3126 success = os_file_rename(
3127 innodb_file_data_key, old_path, new_path);
3129 DBUG_EXECUTE_IF(
"fil_rename_tablespace_failure_2",
3137 ut_a(fil_rename_tablespace_in_mem(
3138 space, node, old_name, old_path));
3144 mutex_exit(&fil_system->
mutex);
3146 #ifndef UNIV_HOTBACKUP
3174 const char* tablename,
3175 const char* filepath)
3180 char* link_filepath;
3185 if (prev_filepath) {
3188 if (0 == strcmp(prev_filepath, filepath)) {
3197 file = os_file_create_simple_no_error_handling(
3198 innodb_file_data_key, link_filepath,
3206 fputs(
" InnoDB: Cannot create file ", stderr);
3208 fputs(
".\n", stderr);
3210 if (error == OS_FILE_ALREADY_EXISTS) {
3211 fputs(
"InnoDB: The link file: ", stderr);
3213 fputs(
" already exists.\n", stderr);
3216 }
else if (error == OS_FILE_DISK_FULL) {
3217 err = DB_OUT_OF_FILE_SPACE;
3228 if (!os_file_write(link_filepath, file, filepath, 0,
3229 strlen(filepath))) {
3234 os_file_close(file);
3247 const char* tablename)
3251 os_file_delete_if_exists(innodb_file_data_key, link_filepath);
3269 char* filepath = NULL;
3270 char* link_filepath;
3276 file = fopen(link_filepath,
"r+b");
3281 filepath =
static_cast<char*
>(mem_alloc(OS_FILE_MAX_PATH));
3286 if (strlen(filepath)) {
3288 ulint lastch = strlen(filepath) - 1;
3289 while (lastch > 4 && filepath[lastch] <= 0x20) {
3290 filepath[lastch--] = 0x00;
3306 const char* tablename,
3307 char** remote_filepath,
3314 if (*remote_filepath == NULL) {
3320 *remote_file = os_file_create_simple_no_error_handling(
3321 innodb_file_data_key, *remote_filepath,
3332 "A link file was found named '%s' "
3333 "but the linked tablespace '%s' "
3334 "could not be opened.",
3335 link_filepath, *remote_filepath);
3339 *remote_filepath = NULL;
3358 const char* tablename,
3361 const char* dir_path,
3389 }
else if (has_data_dir) {
3405 file = os_file_create(
3406 innodb_file_data_key, path,
3417 "Cannot create file '%s'\n", path);
3419 if (error == OS_FILE_ALREADY_EXISTS) {
3421 "The file '%s' already exists though the "
3422 "corresponding table did not exist "
3423 "in the InnoDB data dictionary. "
3424 "Have you moved InnoDB .ibd files "
3425 "around without using the SQL commands "
3426 "DISCARD TABLESPACE and IMPORT TABLESPACE, "
3427 "or did mysqld crash in the middle of "
3429 "You can resolve the problem by removing "
3430 "the file '%s' under the 'datadir' of MySQL.",
3437 if (error == OS_FILE_DISK_FULL) {
3438 err = DB_OUT_OF_FILE_SPACE;
3449 err = DB_OUT_OF_FILE_SPACE;
3464 buf2 =
static_cast<byte*
>(
ut_malloc(3 * UNIV_PAGE_SIZE));
3466 page =
static_cast<byte*
>(
ut_align(buf2, UNIV_PAGE_SIZE));
3468 memset(page,
'\0', UNIV_PAGE_SIZE);
3472 flags = fsp_flags_set_page_size(flags, UNIV_PAGE_SIZE);
3478 ret = os_file_write(path, file, page, 0, UNIV_PAGE_SIZE);
3486 page_zip.
data = page + UNIV_PAGE_SIZE;
3493 ret = os_file_write(path, file, page_zip.
data, 0, zip_size);
3500 "Could not write the first page to tablespace "
3507 ret = os_file_flush(file);
3511 "File flush of tablespace '%s' failed", path);
3519 if (err != DB_SUCCESS) {
3530 #ifndef UNIV_HOTBACKUP
3533 ulint mlog_file_flag = 0;
3541 fil_op_write_log(flags
3544 space_id, mlog_file_flag, flags,
3545 tablename, NULL, &mtr);
3556 if (has_data_dir && err != DB_SUCCESS) {
3560 os_file_close(file);
3561 if (err != DB_SUCCESS) {
3562 os_file_delete(innodb_file_data_key, path);
3570 #ifndef UNIV_HOTBACKUP
3575 fil_report_bad_tablespace(
3577 const char* filepath,
3578 const char* check_msg,
3582 ulint expected_flags)
3586 "Error %s in file '%s',"
3587 "tablespace id=%lu, flags=%lu. "
3589 REFMAN
"innodb-troubleshooting-datadict.html "
3590 "for how to resolve the issue.",
3591 check_msg, filepath,
3592 (ulong) expected_id, (ulong) expected_flags);
3597 "In file '%s', tablespace id and flags are %lu and %lu, "
3598 "but in the InnoDB data dictionary they are %lu and %lu. "
3599 "Have you moved InnoDB .ibd files around without using the "
3600 "commands DISCARD TABLESPACE and IMPORT TABLESPACE? "
3602 REFMAN
"innodb-troubleshooting-datadict.html "
3603 "for how to resolve the issue.",
3604 filepath, (ulong) found_id, (ulong) found_flags,
3605 (ulong) expected_id, (ulong) expected_flags);
3617 #ifdef UNIV_LOG_ARCHIVE
3652 const char* tablename,
3654 const char* path_in)
3657 bool dict_filepath_same_as_default =
false;
3658 bool link_file_found =
false;
3659 bool link_file_is_bad =
false;
3663 ulint tablespaces_found = 0;
3664 ulint valid_tablespaces_found = 0;
3666 #ifdef UNIV_SYNC_DEBUG
3679 memset(&def, 0,
sizeof(def));
3680 memset(&dict, 0,
sizeof(dict));
3681 memset(&remote, 0,
sizeof(remote));
3689 if (strcmp(def.
filepath, path_in)) {
3694 dict_filepath_same_as_default =
true;
3700 remote.
success = link_file_found;
3704 tablespaces_found++;
3716 os_file_close(remote.
file);
3719 tablespaces_found--;
3725 dict.
file = os_file_create_simple_no_error_handling(
3727 OS_FILE_READ_ONLY, &dict.
success);
3731 tablespaces_found++;
3737 def.
file = os_file_create_simple_no_error_handling(
3739 OS_FILE_READ_ONLY, &def.
success);
3741 tablespaces_found++;
3747 if (!validate && tablespaces_found == 1) {
3755 #ifdef UNIV_LOG_ARCHIVE
3756 &space_arch_log_no, &space_arch_log_no,
3766 valid_tablespaces_found++;
3770 fil_report_bad_tablespace(
3772 def.
flags,
id, flags);
3780 #ifdef UNIV_LOG_ARCHIVE
3781 &remote.arch_log_no, &remote.arch_log_no,
3783 &remote.
lsn, &remote.
lsn);
3789 if (remote.
valid && remote.
id ==
id
3791 valid_tablespaces_found++;
3793 remote.
valid =
false;
3795 fil_report_bad_tablespace(
3797 remote.
flags,
id, flags);
3798 link_file_is_bad =
true;
3806 #ifdef UNIV_LOG_ARCHIVE
3807 &dict.arch_log_no, &dict.arch_log_no,
3815 if (dict.
valid && dict.
id ==
id
3817 valid_tablespaces_found++;
3821 fil_report_bad_tablespace(
3823 dict.
flags,
id, flags);
3829 if (valid_tablespaces_found == 0) {
3834 "Could not find a valid tablespace file for '%s'. "
3835 "See " REFMAN
"innodb-troubleshooting-datadict.html "
3836 "for how to resolve the issue.",
3841 goto cleanup_and_exit;
3846 if (tablespaces_found > 1) {
3848 "A tablespace for %s has been found in "
3849 "multiple places;", tablename);
3852 "Default location; %s, LSN=" LSN_PF
3853 ", Space ID=%lu, Flags=%lu",
3855 (ulong) def.
id, (ulong) def.
flags);
3859 "Remote location; %s, LSN=" LSN_PF
3860 ", Space ID=%lu, Flags=%lu",
3862 (ulong) remote.
id, (ulong) remote.
flags);
3866 "Dictionary location; %s, LSN=" LSN_PF
3867 ", Space ID=%lu, Flags=%lu",
3869 (ulong) dict.
id, (ulong) dict.
flags);
3881 "Will not open the tablespace for '%s'",
3891 goto cleanup_and_exit;
3899 os_file_close(def.
file);
3900 tablespaces_found--;
3904 os_file_close(dict.
file);
3907 tablespaces_found--;
3911 os_file_close(remote.
file);
3914 tablespaces_found--;
3919 ut_a(tablespaces_found == 1);
3920 ut_a(valid_tablespaces_found == 1);
3940 if (link_file_is_bad) {
3943 }
else if (!link_file_found || link_file_is_bad) {
3952 }
else if (remote.
success && dict_filepath_same_as_default) {
3955 }
else if (remote.
success && path_in == NULL) {
3958 id, tablename, remote.
filepath, flags);
3962 if (err != DB_SUCCESS) {
3979 os_file_close(remote.
file);
3985 os_file_close(dict.
file);
3991 os_file_close(def.
file);
3999 #ifdef UNIV_HOTBACKUP
4006 fil_make_ibbackup_old_name(
4010 static const char suffix[] =
"_ibbackup_old_vers_";
4012 ulint len = strlen(name);
4014 path =
static_cast<char*
>(mem_alloc(len + (15 +
sizeof suffix)));
4016 memcpy(path, name, len);
4017 memcpy(path + len, suffix, (
sizeof suffix) - 1);
4018 ut_sprintf_timestamp_without_extra_chars(
4019 path + len + ((
sizeof suffix) - 1));
4030 fil_validate_single_table_tablespace(
4032 const char* tablename,
4037 #ifdef UNIV_LOG_ARCHIVE
4038 &fsp->arch_log_no, &fsp->arch_log_no,
4042 "%s in tablespace %s (table %s)",
4043 check_msg, fsp->
filepath, tablename);
4048 if (fsp->
id == ULINT_UNDEFINED || fsp->
id == 0) {
4050 "Tablespace is not sensible;"
4051 " Table: %s Space ID: %lu Filepath: %s\n",
4057 mutex_enter(&fil_system->
mutex);
4059 mutex_exit(&fil_system->
mutex);
4060 if (space != NULL) {
4064 "Attempted to open a previously opened tablespace. "
4065 "Previous tablespace %s uses space ID: %lu at "
4066 "filepath: %s. Cannot open tablespace %s which uses "
4067 "space ID: %lu at filepath: %s",
4068 space->
name, (ulong) space->
id, prev_filepath,
4085 fil_load_single_table_tablespace(
4088 const char* filename)
4092 ulint tablename_len;
4093 ulint dbname_len = strlen(dbname);
4094 ulint filename_len = strlen(filename);
4098 #ifdef UNIV_HOTBACKUP
4102 memset(&def, 0,
sizeof(def));
4103 memset(&remote, 0,
sizeof(remote));
4106 ut_ad(0 == memcmp(filename + filename_len - 4,
".ibd", 4)
4107 || 0 == memcmp(filename + filename_len - 4,
".isl", 4));
4110 tablename =
static_cast<char*
>(
4111 mem_alloc(dbname_len + filename_len + 2));
4112 sprintf(tablename,
"%s/%s", dbname, filename);
4113 tablename_len = strlen(tablename) - strlen(
".ibd");
4114 tablename[tablename_len] =
'\0';
4121 mutex_enter(&fil_system->
mutex);
4124 mutex_exit(&fil_system->
mutex);
4127 mutex_exit(&fil_system->
mutex);
4134 # ifndef UNIV_HOTBACKUP
4151 fil_validate_single_table_tablespace(tablename, &remote);
4153 os_file_close(remote.
file);
4160 def.
file = os_file_create_simple_no_error_handling(
4162 OS_FILE_READ_ONLY, &def.
success);
4166 fil_validate_single_table_tablespace(tablename, &def);
4168 os_file_close(def.
file);
4176 "InnoDB: Error: could not open single-table"
4177 " tablespace file %s\n", def.
filepath);
4179 if (!strncmp(filename,
4193 "InnoDB: We do not continue the crash recovery,"
4194 " because the table may become\n"
4195 "InnoDB: corrupt if we cannot apply the log"
4196 " records in the InnoDB log to it.\n"
4197 "InnoDB: To fix the problem and start mysqld:\n"
4198 "InnoDB: 1) If there is a permission problem"
4199 " in the file and mysqld cannot\n"
4200 "InnoDB: open the file, you should"
4201 " modify the permissions.\n"
4202 "InnoDB: 2) If the table is not needed, or you"
4203 " can restore it from a backup,\n"
4204 "InnoDB: then you can remove the .ibd file,"
4205 " and InnoDB will do a normal\n"
4206 "InnoDB: crash recovery and ignore that table.\n"
4207 "InnoDB: 3) If the file system or the"
4208 " disk is broken, and you cannot remove\n"
4209 "InnoDB: the .ibd file, you can set"
4210 " innodb_force_recovery > 0 in my.cnf\n"
4211 "InnoDB: and force InnoDB to continue crash"
4212 " recovery here.\n");
4224 "innodb_force_recovery was set to %lu. "
4225 "Continuing crash recovery even though we "
4226 "cannot access the .ibd file of this table.",
4236 "Tablespaces for %s have been found in two places;\n"
4237 "Location 1: SpaceID: %lu LSN: %lu File: %s\n"
4238 "Location 2: SpaceID: %lu LSN: %lu File: %s\n"
4239 "You must delete one of them.",
4240 tablename, (ulong) def.
id, (ulong) def.
lsn,
4245 os_file_close(def.
file);
4246 os_file_close(remote.
file);
4247 goto will_not_choose;
4263 "could not measure the size of single-table "
4264 "tablespace file %s", fsp->
filepath);
4266 os_file_close(fsp->
file);
4273 if (size < minimum_size) {
4274 #ifndef UNIV_HOTBACKUP
4276 "The size of single-table tablespace file %s "
4277 "is only " UINT64PF
", should be at least %lu!",
4278 fsp->
filepath, size, minimum_size);
4279 os_file_close(fsp->
file);
4282 fsp->
id = ULINT_UNDEFINED;
4287 #ifdef UNIV_HOTBACKUP
4288 if (fsp->
id == ULINT_UNDEFINED || fsp->
id == 0) {
4292 "InnoDB: Renaming tablespace %s of id %lu,\n"
4293 "InnoDB: to %s_ibbackup_old_vers_<timestamp>\n"
4294 "InnoDB: because its size %" PRId64
" is too small"
4295 " (< 4 pages 16 kB each),\n"
4296 "InnoDB: or the space id in the file header"
4297 " is not sensible.\n"
4298 "InnoDB: This can happen in an ibbackup run,"
4299 " and is not dangerous.\n",
4301 os_file_close(fsp->
file);
4303 new_path = fil_make_ibbackup_old_name(fsp->
filepath);
4305 bool success = os_file_rename(
4306 innodb_file_data_key, fsp->
filepath, new_path);
4312 goto func_exit_after_close;
4322 mutex_enter(&fil_system->
mutex);
4330 "InnoDB: Renaming tablespace %s of id %lu,\n"
4331 "InnoDB: to %s_ibbackup_old_vers_<timestamp>\n"
4332 "InnoDB: because space %s with the same id\n"
4333 "InnoDB: was scanned earlier. This can happen"
4334 " if you have renamed tables\n"
4335 "InnoDB: during an ibbackup run.\n",
4338 os_file_close(fsp->
file);
4340 new_path = fil_make_ibbackup_old_name(fsp->
filepath);
4342 mutex_exit(&fil_system->
mutex);
4344 bool success = os_file_rename(
4345 innodb_file_data_key, fsp->
filepath, new_path);
4351 goto func_exit_after_close;
4353 mutex_exit(&fil_system->
mutex);
4358 if (!file_space_create_success) {
4361 "InnoDB: innodb_force_recovery was set"
4362 " to %lu. Continuing crash recovery\n"
4363 "InnoDB: even though the tablespace"
4364 " creation of this table failed.\n",
4370 ut_a(file_space_create_success);
4382 os_file_close(fsp->
file);
4384 #ifdef UNIV_HOTBACKUP
4385 func_exit_after_close:
4404 fil_file_readdir_next_file(
4408 const char* dirname,
4413 for (ulint
i = 0;
i < 100;
i++) {
4422 "os_file_readdir_next_file() returned -1 in "
4423 "directory %s, crash recovery may have failed "
4424 "for some .ibd files!", dirname);
4446 char* dbpath = NULL;
4447 ulint dbpath_len = 100;
4463 dbpath =
static_cast<char*
>(mem_alloc(dbpath_len));
4474 if (dbinfo.
type == OS_FILE_TYPE_FILE
4475 || dbinfo.
type == OS_FILE_TYPE_UNKNOWN) {
4477 goto next_datadir_item;
4484 + strlen (dbinfo.
name) + 2;
4485 if (len > dbpath_len) {
4492 dbpath =
static_cast<char*
>(mem_alloc(dbpath_len));
4500 if (dbdir != NULL) {
4505 ret = fil_file_readdir_next_file(&err, dbpath, dbdir,
4509 if (fileinfo.
type == OS_FILE_TYPE_DIR) {
4511 goto next_file_item;
4515 if (strlen(fileinfo.
name) > 4
4516 && (0 == strcmp(fileinfo.
name
4517 + strlen(fileinfo.
name) - 4,
4519 || 0 == strcmp(fileinfo.
name
4520 + strlen(fileinfo.
name) - 4,
4524 fil_load_single_table_tablespace(
4528 ret = fil_file_readdir_next_file(&err,
4534 fputs(
"InnoDB: Warning: could not"
4535 " close database directory ", stderr);
4544 ret = fil_file_readdir_next_file(&err,
4553 "InnoDB: Error: could not close MySQL datadir\n");
4578 mutex_enter(&fil_system->
mutex);
4583 mutex_exit(&fil_system->
mutex);
4588 if (version != ((ib_int64_t)-1)
4590 mutex_exit(&fil_system->
mutex);
4595 mutex_exit(&fil_system->
mutex);
4613 mutex_enter(&fil_system->
mutex);
4617 mutex_exit(&fil_system->
mutex);
4619 return(space != NULL);
4626 fil_report_missing_tablespace(
4631 char index_name[MAX_FULL_NAME_LEN + 1];
4636 "Table %s in the InnoDB data dictionary has tablespace id %lu, "
4637 "but tablespace with that id or name does not exist. Have "
4638 "you deleted or moved .ibd files? This may also be a table "
4639 "created with CREATE TEMPORARY TABLE whose .ibd and .frm "
4640 "files MySQL automatically removed, but the table still "
4641 "exists in the InnoDB internal data dictionary.",
4665 ibool print_error_if_does_not_exist,
4673 table_id_t table_id)
4680 mutex_enter(&fil_system->
mutex);
4690 if (space && space == fnamespace) {
4697 mutex_exit(&fil_system->
mutex);
4712 mutex_exit(&fil_system->
mutex);
4714 DBUG_EXECUTE_IF(
"ib_crash_before_adjust_fil_space",
4720 tmp_name = dict_mem_create_temporary_tablename(
4721 heap, name, table_id);
4727 DBUG_EXECUTE_IF(
"ib_crash_after_adjust_one_fil_space",
4732 DBUG_EXECUTE_IF(
"ib_crash_after_adjust_fil_space",
4735 mutex_enter(&fil_system->
mutex);
4737 ut_ad(space == fnamespace);
4738 mutex_exit(&fil_system->
mutex);
4743 if (!print_error_if_does_not_exist) {
4745 mutex_exit(&fil_system->
mutex);
4750 if (space == NULL) {
4751 if (fnamespace == NULL) {
4752 if (print_error_if_does_not_exist) {
4753 fil_report_missing_tablespace(name,
id);
4757 fputs(
" InnoDB: Error: table ", stderr);
4759 fprintf(stderr,
"\n"
4760 "InnoDB: in InnoDB data dictionary has"
4761 " tablespace id %lu,\n"
4762 "InnoDB: but a tablespace with that id"
4763 " does not exist. There is\n"
4764 "InnoDB: a tablespace of name %s and id %lu,"
4766 "InnoDB: you deleted or moved .ibd files?\n",
4767 (ulong)
id, fnamespace->
name,
4768 (ulong) fnamespace->
id);
4771 fputs(
"InnoDB: Please refer to\n"
4772 "InnoDB: " REFMAN
"innodb-troubleshooting-datadict.html\n"
4773 "InnoDB: for how to resolve the issue.\n", stderr);
4775 mutex_exit(&fil_system->
mutex);
4780 if (0 != strcmp(space->
name, name)) {
4782 fputs(
" InnoDB: Error: table ", stderr);
4784 fprintf(stderr,
"\n"
4785 "InnoDB: in InnoDB data dictionary has"
4786 " tablespace id %lu,\n"
4787 "InnoDB: but the tablespace with that id"
4789 "InnoDB: Have you deleted or moved .ibd files?\n",
4790 (ulong)
id, space->
name);
4792 if (fnamespace != NULL) {
4793 fputs(
"InnoDB: There is a tablespace"
4794 " with the right name\n"
4795 "InnoDB: ", stderr);
4797 fprintf(stderr,
", but its id is %lu.\n",
4798 (ulong) fnamespace->
id);
4804 mutex_exit(&fil_system->
mutex);
4817 const char* tablename)
4821 ulint
id = ULINT_UNDEFINED;
4825 mutex_enter(&fil_system->
mutex);
4832 id = fnamespace->
id;
4835 mutex_exit(&fil_system->
mutex);
4853 ulint size_after_extend)
4862 ulint start_page_no;
4863 ulint file_start_page_no;
4874 fil_mutex_enter_and_prepare_for_io(space_id);
4879 if (space->
size >= size_after_extend) {
4882 *actual_size = space->
size;
4884 mutex_exit(&fil_system->
mutex);
4891 page_size = UNIV_PAGE_SIZE;
4906 mutex_exit(&fil_system->
mutex);
4911 if (!fil_node_prepare_for_io(node, fil_system, space)) {
4914 mutex_exit(&fil_system->
mutex);
4922 mutex_exit(&fil_system->
mutex);
4924 start_page_no = space->
size;
4925 file_start_page_no = space->
size - node->
size;
4928 buf_size =
ut_min(64, size_after_extend - start_page_no) * page_size;
4929 buf2 =
static_cast<byte*
>(mem_alloc(buf_size + page_size));
4930 buf =
static_cast<byte*
>(
ut_align(buf2, page_size));
4932 memset(buf, 0, buf_size);
4934 while (start_page_no < size_after_extend) {
4936 =
ut_min(buf_size / page_size,
4937 size_after_extend - start_page_no);
4940 = ((
os_offset_t) (start_page_no - file_start_page_no))
4942 #ifdef UNIV_HOTBACKUP
4943 success = os_file_write(node->
name, node->
handle, buf,
4944 offset, page_size * n_pages);
4948 offset, page_size * n_pages,
4952 os_has_said_disk_full = FALSE;
4961 n_pages = ((ulint) (size / page_size))
4962 - node->
size - pages_added;
4964 pages_added += n_pages;
4968 start_page_no += n_pages;
4969 pages_added += n_pages;
4974 mutex_enter(&fil_system->
mutex);
4978 space->
size += pages_added;
4979 node->
size += pages_added;
4982 fil_node_complete_io(node, fil_system, OS_FILE_WRITE);
4984 *actual_size = space->
size;
4986 #ifndef UNIV_HOTBACKUP
4987 if (space_id == 0) {
4988 ulint pages_per_mb = (1024 * 1024) / page_size;
4993 srv_data_file_sizes[srv_n_data_files - 1]
4994 = (node->
size / pages_per_mb) * pages_per_mb;
5001 mutex_exit(&fil_system->
mutex);
5008 #ifdef UNIV_HOTBACKUP
5016 fil_extend_tablespaces_to_stored_len(
void)
5022 ulint size_in_header;
5026 buf = mem_alloc(UNIV_PAGE_SIZE);
5028 mutex_enter(&fil_system->
mutex);
5035 mutex_exit(&fil_system->
mutex);
5040 0, 0, UNIV_PAGE_SIZE, buf, NULL);
5041 ut_a(error == DB_SUCCESS);
5046 &actual_size, space->
id, size_in_header);
5049 "InnoDB: Error: could not extend the"
5050 " tablespace of %s\n"
5051 "InnoDB: to the size stored in header,"
5053 "InnoDB: size after extension %lu pages\n"
5054 "InnoDB: Check that you have free disk space"
5056 space->
name, size_in_header, actual_size);
5060 mutex_enter(&fil_system->
mutex);
5065 mutex_exit(&fil_system->
mutex);
5089 mutex_enter(&fil_system->
mutex);
5102 mutex_exit(&fil_system->
mutex);
5120 mutex_enter(&fil_system->
mutex);
5129 mutex_exit(&fil_system->
mutex);
5146 mutex_enter(&fil_system->
mutex);
5154 mutex_exit(&fil_system->
mutex);
5171 fil_node_prepare_for_io(
5177 ut_ad(node && system && space);
5183 " InnoDB: Warning: open files %lu"
5184 " exceeds the limit %lu\n",
5189 if (node->
open == FALSE) {
5193 if (!fil_node_open_file(node, system, space)) {
5216 fil_node_complete_io(
5232 if (type == OS_FILE_WRITE) {
5249 system->unflushed_spaces,
5265 fil_report_invalid_page_access(
5269 const char* space_name,
5275 "InnoDB: Error: trying to access page number %lu"
5277 "InnoDB: space name %s,\n"
5278 "InnoDB: which is outside the tablespace bounds.\n"
5279 "InnoDB: Byte offset %lu, len %lu, i/o type %lu.\n"
5280 "InnoDB: If you get this error at mysqld startup,"
5281 " please check that\n"
5282 "InnoDB: your my.cnf matches the ibdata files"
5283 " that you have in the\n"
5284 "InnoDB: MySQL server.\n",
5285 (ulong) block_offset, (ulong) space_id, space_name,
5286 (ulong) byte_offset, (ulong) len, (ulong) type);
5330 ibool ignore_nonexistent_pages;
5332 is_log = type & OS_FILE_LOG;
5333 type = type & ~OS_FILE_LOG;
5336 type = type & ~OS_AIO_SIMULATED_WAKE_LATER;
5339 type &= ~BUF_READ_IGNORE_NONEXISTENT_PAGES;
5341 ut_ad(byte_offset < UNIV_PAGE_SIZE);
5342 ut_ad(!zip_size || !byte_offset);
5346 ut_ad(UNIV_PAGE_SIZE == (ulong)(1 << UNIV_PAGE_SIZE_SHIFT));
5347 #if (1 << UNIV_PAGE_SIZE_SHIFT_MAX) != UNIV_PAGE_SIZE_MAX
5348 # error "(1 << UNIV_PAGE_SIZE_SHIFT_MAX) != UNIV_PAGE_SIZE_MAX"
5350 #if (1 << UNIV_PAGE_SIZE_SHIFT_MIN) != UNIV_PAGE_SIZE_MIN
5351 # error "(1 << UNIV_PAGE_SIZE_SHIFT_MIN) != UNIV_PAGE_SIZE_MIN"
5353 ut_ad(fil_validate_skip());
5354 #ifndef UNIV_HOTBACKUP
5355 # ifndef UNIV_LOG_DEBUG
5358 || type == OS_FILE_WRITE
5365 }
else if (is_log) {
5369 &&
ibuf_page(space_id, zip_size, block_offset, NULL)) {
5381 }
else if (type == OS_FILE_WRITE) {
5389 fil_mutex_enter_and_prepare_for_io(space_id);
5396 mutex_exit(&fil_system->
mutex);
5399 "Trying to do i/o to a tablespace which does "
5400 "not exist. i/o type %lu, space id %lu, "
5401 "page no. %lu, i/o length %lu bytes",
5402 (ulong) type, (ulong) space_id, (ulong) block_offset,
5414 if (ignore_nonexistent_pages) {
5415 mutex_exit(&fil_system->
mutex);
5419 fil_report_invalid_page_access(
5420 block_offset, space_id, space->
name,
5421 byte_offset, len, type);
5426 && node->
size == 0) {
5431 }
else if (node->
size > block_offset) {
5435 block_offset -= node->
size;
5441 if (!fil_node_prepare_for_io(node, fil_system, space)) {
5444 mutex_exit(&fil_system->
mutex);
5447 "Trying to do i/o to a tablespace which "
5448 "exists without .ibd data file. "
5449 "i/o type %lu, space id %lu, page no %lu, "
5450 "i/o length %lu bytes",
5451 (ulong) type, (ulong) space_id,
5452 (ulong) block_offset, (ulong) len);
5466 if (UNIV_UNLIKELY(node->
size <= block_offset)
5469 fil_report_invalid_page_access(
5470 block_offset, space_id, space->
name, byte_offset,
5477 mutex_exit(&fil_system->
mutex);
5482 offset = ((
os_offset_t) block_offset << UNIV_PAGE_SIZE_SHIFT)
5486 >= ((byte_offset + len + (UNIV_PAGE_SIZE - 1))
5489 ulint zip_size_shift;
5491 case 1024: zip_size_shift = 10;
break;
5492 case 2048: zip_size_shift = 11;
break;
5493 case 4096: zip_size_shift = 12;
break;
5494 case 8192: zip_size_shift = 13;
break;
5495 case 16384: zip_size_shift = 14;
break;
5498 offset = ((
os_offset_t) block_offset << zip_size_shift)
5501 >= (len + (zip_size - 1)) / zip_size);
5509 #ifdef UNIV_HOTBACKUP
5512 ret = os_file_read(node->
handle, buf, offset, len);
5515 ret = os_file_write(node->
name, node->
handle, buf,
5520 ret = os_aio(type, mode | wake_later, node->
name, node->
handle, buf,
5521 offset, len, node, message);
5529 mutex_enter(&fil_system->
mutex);
5531 fil_node_complete_io(node, fil_system, type);
5533 mutex_exit(&fil_system->
mutex);
5535 ut_ad(fil_validate_skip());
5541 #ifndef UNIV_HOTBACKUP
5559 ut_ad(fil_validate_skip());
5561 if (srv_use_native_aio) {
5564 ret = os_aio_windows_handle(
5565 segment, 0, &fil_node, &message, &type);
5566 #elif defined(LINUX_NATIVE_AIO)
5567 ret = os_aio_linux_handle(
5568 segment, &fil_node, &message, &type);
5577 segment, &fil_node, &message, &type);
5581 if (fil_node == NULL) {
5588 mutex_enter(&fil_system->
mutex);
5590 fil_node_complete_io(fil_node, fil_system, type);
5592 mutex_exit(&fil_system->
mutex);
5594 ut_ad(fil_validate_skip());
5627 mutex_enter(&fil_system->
mutex);
5632 mutex_exit(&fil_system->
mutex);
5642 ut_ad(fil_space_is_flushed(space));
5655 mutex_exit(&fil_system->
mutex);
5692 ib_int64_t sig_count =
5695 mutex_exit(&fil_system->
mutex);
5699 mutex_enter(&fil_system->
mutex);
5713 mutex_exit(&fil_system->
mutex);
5715 os_file_flush(file);
5717 mutex_enter(&fil_system->
mutex);
5727 && fil_space_is_flushed(space)) {
5733 fil_system->unflushed_spaces,
5747 mutex_exit(&fil_system->
mutex);
5764 mutex_enter(&fil_system->
mutex);
5767 if (n_space_ids == 0) {
5769 mutex_exit(&fil_system->
mutex);
5777 space_ids =
static_cast<ulint*
>(
5778 mem_alloc(n_space_ids *
sizeof *space_ids));
5788 space_ids[n_space_ids++] = space->
id;
5792 mutex_exit(&fil_system->
mutex);
5796 for (i = 0; i < n_space_ids; i++) {
5825 mutex_enter(&fil_system->
mutex);
5831 for (space = static_cast<fil_space_t*>(
5848 if (fil_node->
open) {
5857 UT_LIST_CHECK(LRU,
fil_node_t, fil_system->LRU);
5869 mutex_exit(&fil_system->
mutex);
5946 #ifndef UNIV_HOTBACKUP
5973 UNIV_MEM_DESC(frame, UNIV_PAGE_SIZE);
5975 block->
frame = frame;
6028 for (offset = iter.
start; offset < iter.
end; offset += n_bytes) {
6032 block->
frame = io_buffer;
6050 n_bytes =
static_cast<ulint
>(
6051 ut_min(static_cast<os_offset_t>(n_bytes),
6052 iter.
end - offset));
6057 if (!os_file_read(iter.
file, io_buffer, offset,
6060 ib_logf(IB_LOG_LEVEL_ERROR,
"os_file_read() failed");
6065 bool updated =
false;
6067 ulint n_pages_read = (ulint) n_bytes / iter.
page_size;
6069 for (ulint
i = 0;
i < n_pages_read; ++
i) {
6075 if ((err = callback(page_off, block)) != DB_SUCCESS) {
6079 }
else if (!updated) {
6095 offset, (ulint) n_bytes)) {
6097 ib_logf(IB_LOG_LEVEL_ERROR,
"os_file_write() failed");
6124 ut_a(n_io_buffers > 0);
6127 DBUG_EXECUTE_IF(
"ib_import_trigger_corruption_1",
6143 file = os_file_create_simple_no_error_handling(
6144 innodb_file_data_key, filepath,
6147 DBUG_EXECUTE_IF(
"fil_tablespace_iterate_failure",
6154 os_file_close(file);
6163 "Trying to import a tablespace, but could not "
6164 "open the tablespace file %s", filepath);
6168 return(DB_TABLESPACE_NOT_FOUND);
6183 memset(&block, 0x0,
sizeof(block));
6190 void* page_ptr = mem_alloc(3 * UNIV_PAGE_SIZE);
6191 byte* page =
static_cast<byte*
>(
ut_align(page_ptr, UNIV_PAGE_SIZE));
6193 fil_buf_block_init(&block, page);
6197 if (!os_file_read(file, page, 0, UNIV_PAGE_SIZE)) {
6201 }
else if ((err = callback.
init(file_size, &block)) == DB_SUCCESS) {
6206 iter.
end = file_size;
6222 void* io_buffer = mem_alloc(
6226 ut_align(io_buffer, UNIV_PAGE_SIZE));
6228 err = fil_iterate(iter, &block, callback);
6233 if (err == DB_SUCCESS) {
6235 ib_logf(IB_LOG_LEVEL_INFO,
"Sync to disk");
6237 if (!os_file_flush(file)) {
6238 ib_logf(IB_LOG_LEVEL_INFO,
"os_file_flush() failed!");
6241 ib_logf(IB_LOG_LEVEL_INFO,
"Sync to disk - done!");
6245 os_file_close(file);
6261 if (!
ut_is_2pow(m_zip_size) || m_zip_size > UNIV_ZIP_SIZE_MAX) {
6275 const char* ibd_name)
6280 ib_logf(IB_LOG_LEVEL_INFO,
"Deleting %s", ibd_name);
6282 os_file_delete_if_exists(innodb_file_data_key, ibd_name);
6284 char* cfg_name = fil_make_cfg_name(ibd_name);
6286 os_file_delete_if_exists(innodb_file_data_key, cfg_name);
6300 space_name_list_t& space_name_list)
6306 mutex_enter(&fil_system->
mutex);
6316 len = strlen(space->
name);
6317 name =
new(std::nothrow)
char[len + 1];
6321 err = DB_OUT_OF_MEMORY;
6325 memcpy(name, space->
name, len);
6328 space_name_list.push_back(name);
6332 mutex_exit(&fil_system->
mutex);
6345 const char* old_name,
6348 const char* new_name,
6349 const char* tmp_name,
6353 if (old_space_id != TRX_SYS_SPACE) {
6355 0, 0, old_name, tmp_name, mtr);
6358 if (new_space_id != TRX_SYS_SPACE) {
6360 0, 0, new_name, old_name, mtr);