43#include "xtrabackup_api.h"
50static ulint srv_data_read, srv_data_written;
111UNIV_INTERN
const char* fil_path_to_mysql_datadir =
".";
114UNIV_INTERN ulint fil_n_log_flushes = 0;
117UNIV_INTERN ulint fil_n_pending_log_flushes = 0;
119UNIV_INTERN ulint fil_n_pending_tablespace_flushes = 0;
126UNIV_INTERN mysql_pfs_key_t fil_system_mutex_key;
129#ifdef UNIV_PFS_RWLOCK
131UNIV_INTERN mysql_pfs_key_t fil_space_latch_key;
167#define FIL_NODE_MAGIC_N 89389
221#ifndef UNIV_HOTBACKUP
236#define FIL_SPACE_MAGIC_N 89472
246#ifndef UNIV_HOTBACKUP
292 ibool space_id_reuse_warned;
300fil_system_t* fil_system = NULL;
304# define FIL_VALIDATE_SKIP 17
311fil_validate_skip(
void)
316 static int fil_validate_count = FIL_VALIDATE_SKIP;
322 if (--fil_validate_count > 0) {
326 fil_validate_count = FIL_VALIDATE_SKIP;
340fil_node_prepare_for_io(
343 fil_system_t* system,
353 fil_system_t* system,
363fil_get_space_id_for_table(
404 return(fil_io(
OS_FILE_READ, sync, space_id, zip_size, block_offset,
405 byte_offset, len, buf, message));
433 return(fil_io(OS_FILE_WRITE, sync, space_id, zip_size, block_offset,
434 byte_offset, len, buf, message));
447 ut_ad(mutex_own(&fil_system->mutex));
461fil_space_get_by_name(
468 ut_ad(mutex_own(&fil_system->mutex));
472 HASH_SEARCH(name_hash, fil_system->name_hash, fold,
475 !strcmp(name, space->
name));
480#ifndef UNIV_HOTBACKUP
487fil_space_get_version(
492 ib_int64_t version = -1;
496 mutex_enter(&fil_system->mutex);
498 space = fil_space_get_by_id(
id);
504 mutex_exit(&fil_system->mutex);
523 mutex_enter(&fil_system->mutex);
525 space = fil_space_get_by_id(
id);
530 *flags = space->
flags;
533 mutex_exit(&fil_system->mutex);
535 return(&(space->
latch));
551 mutex_enter(&fil_system->mutex);
553 space = fil_space_get_by_id(
id);
557 mutex_exit(&fil_system->mutex);
575 ut_ad(mutex_own(&fil_system->mutex));
610 mutex_enter(&fil_system->mutex);
621 node->
magic_n = FIL_NODE_MAGIC_N;
628 space = fil_space_get_by_id(
id);
633 " InnoDB: Error: Could not find tablespace %lu for\n"
634 "InnoDB: file ", (ulong)
id);
636 fputs(
" in the tablespace memory cache.\n", stderr);
641 mutex_exit(&fil_system->mutex);
652 if (id < SRV_LOG_SPACE_FIRST_ID && fil_system->max_assigned_id <
id) {
654 fil_system->max_assigned_id = id;
657 mutex_exit(&fil_system->mutex);
668 fil_system_t* system,
685 if (node->
size == 0) {
694 node->
handle = os_file_create_simple_no_error_handling(
696 OS_FILE_READ_ONLY, &success);
704 " InnoDB: Fatal error: cannot open %s\n."
705 "InnoDB: Have you deleted .ibd files"
706 " under a running mysqld server?\n",
713 size_bytes = (((uint64_t)size_high) << 32) + size_low;
715 if (space->
id == 0) {
716 node->
size = size_bytes / UNIV_PAGE_SIZE;
717 os_file_close(node->
handle);
726 "InnoDB: Error: the size of single-table"
727 " tablespace file %s\n"
728 "InnoDB: is only %lu %lu,"
729 " should be at least %lu!\n",
741 buf2 =
static_cast<unsigned char *
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
744 page =
static_cast<unsigned char *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
746 success = os_file_read(node->
handle, page, 0, 0,
748 space_id = fsp_header_get_space_id(page);
749 flags = fsp_header_get_flags(page);
755 os_file_close(node->
handle);
757 if (UNIV_UNLIKELY(space_id != space->
id)) {
759 "InnoDB: Error: tablespace id is %lu"
760 " in the data dictionary\n"
761 "InnoDB: but in file %s it is %lu!\n",
762 space->
id, node->
name, space_id);
767 if (UNIV_UNLIKELY(space_id == ULINT_UNDEFINED
770 "InnoDB: Error: tablespace id %lu"
771 " in file %s is not sensible\n",
772 (ulong) space_id, node->
name);
777 if (UNIV_UNLIKELY(space->
flags != flags)) {
779 "InnoDB: Error: table flags are %lx"
780 " in the data dictionary\n"
781 "InnoDB: but the flags in file %s are %lx!\n",
787 if (size_bytes >= 1024 * 1024) {
792 if (!(flags & DICT_TF_ZSSIZE_MASK)) {
793 node->
size = (ulint)size_bytes / UNIV_PAGE_SIZE;
813 node->
handle = os_file_create(innodb_file_log_key,
815 OS_FILE_AIO, OS_LOG_FILE,
818 node->
handle = os_file_create(innodb_file_data_key,
824 node->
handle = os_file_create(innodb_file_data_key,
849 fil_system_t* system)
853 ut_ad(node && system);
860 ret = os_file_close(node->
handle);
887fil_try_to_close_file_in_LRU(
894 ut_ad(mutex_own(&fil_system->mutex));
900 "InnoDB: fil_sys open file LRU len %lu\n",
904 while (node != NULL) {
908 fil_node_close_file(node, fil_system);
914 fputs(
"InnoDB: cannot close file ", stderr);
916 fprintf(stderr,
", because n_pending_flushes %lu\n",
922 fputs(
"InnoDB: cannot close file ", stderr);
925 ", because mod_count %ld != fl_count %ld\n",
942fil_mutex_enter_and_prepare_for_io(
948 ibool print_info = FALSE;
953 mutex_enter(&fil_system->mutex);
965 if (fil_system->n_open < fil_system->max_n_open) {
970 space = fil_space_get_by_id(space_id);
972 if (space != NULL && space->
stop_ios) {
976 if (count2 > 20000) {
977 fputs(
"InnoDB: Warning: tablespace ", stderr);
980 " has i/o ops stopped for a long time %lu\n",
984 mutex_exit(&fil_system->mutex);
1008 success = fil_try_to_close_file_in_LRU(print_info);
1010 if (success && fil_system->n_open >= fil_system->max_n_open) {
1015 if (fil_system->n_open < fil_system->max_n_open) {
1024 " InnoDB: Warning: too many (%lu) files stay open"
1025 " while the maximum\n"
1026 "InnoDB: allowed value would be %lu.\n"
1027 "InnoDB: You may need to raise the value of"
1028 " innodb_open_files in\n"
1029 "InnoDB: my.cnf.\n",
1030 (ulong) fil_system->n_open,
1031 (ulong) fil_system->max_n_open);
1036 mutex_exit(&fil_system->mutex);
1038#ifndef UNIV_HOTBACKUP
1062 fil_system_t* system,
1065 ut_ad(node && system && space);
1077 && fil_space_is_flushed(space)) {
1082 system->unflushed_spaces,
1086 fil_node_close_file(node, system);
1097#ifdef UNIV_LOG_ARCHIVE
1103fil_space_truncate_start(
1113 mutex_enter(&fil_system->mutex);
1115 space = fil_space_get_by_id(
id);
1119 while (trunc_len > 0) {
1122 ut_a(node->
size * UNIV_PAGE_SIZE <= trunc_len);
1124 trunc_len -= node->
size * UNIV_PAGE_SIZE;
1126 fil_node_free(node, fil_system, space);
1129 mutex_exit(&fil_system->mutex);
1166 mutex_enter(&fil_system->mutex);
1168 space = fil_space_get_by_name(name);
1170 if (UNIV_LIKELY_NULL(space)) {
1176 " InnoDB: Warning: trying to init to the"
1177 " tablespace memory cache\n"
1178 "InnoDB: a tablespace %lu of name ", (ulong)
id);
1180 fprintf(stderr,
",\n"
1181 "InnoDB: but a tablespace %lu of the same name\n"
1182 "InnoDB: already exists in the"
1183 " tablespace memory cache!\n",
1188 mutex_exit(&fil_system->mutex);
1194 "InnoDB: We assume that InnoDB did a crash recovery,"
1196 "InnoDB: an .ibd file for which the table"
1197 " did not exist in the\n"
1198 "InnoDB: InnoDB internal data dictionary in the"
1200 "InnoDB: We assume that you later removed the"
1201 " .ibd and .frm files,\n"
1202 "InnoDB: and are now trying to recreate the table."
1203 " We now remove the\n"
1204 "InnoDB: conflicting tablespace object"
1205 " from the memory cache and try\n"
1206 "InnoDB: the init again.\n");
1208 namesake_id = space->
id;
1210 success = fil_space_free(namesake_id, FALSE);
1213 mutex_exit(&fil_system->mutex);
1218 space = fil_space_get_by_id(
id);
1220 if (UNIV_LIKELY_NULL(space)) {
1222 "InnoDB: Error: trying to add tablespace %lu"
1223 " of name ", (ulong)
id);
1225 fprintf(stderr,
"\n"
1226 "InnoDB: to the tablespace memory cache,"
1228 "InnoDB: %lu of name ", (ulong) space->
id);
1230 fputs(
" already exists in the tablespace\n"
1231 "InnoDB: memory cache!\n", stderr);
1233 mutex_exit(&fil_system->mutex);
1238 space =
static_cast<fil_space_t *
>(mem_alloc(
sizeof(fil_space_t)));
1243 fil_system->tablespace_version++;
1245 space->
mark = FALSE;
1248 && UNIV_UNLIKELY(
id > fil_system->max_assigned_id)) {
1249 if (!fil_system->space_id_reuse_warned) {
1250 fil_system->space_id_reuse_warned = TRUE;
1254 " InnoDB: Warning: allocated tablespace %lu,"
1255 " old maximum was %lu\n",
1257 (ulong) fil_system->max_assigned_id);
1260 fil_system->max_assigned_id = id;
1268 space->
flags = flags;
1276 space->
magic_n = FIL_SPACE_MAGIC_N;
1280 HASH_INSERT(fil_space_t, hash, fil_system->spaces,
id, space);
1282 HASH_INSERT(fil_space_t, name_hash, fil_system->name_hash,
1288 mutex_exit(&fil_system->mutex);
1300fil_assign_new_space_id(
1307 mutex_enter(&fil_system->mutex);
1311 if (id < fil_system->max_assigned_id) {
1312 id = fil_system->max_assigned_id;
1320 "InnoDB: Warning: you are running out of new"
1321 " single-table tablespace id's.\n"
1322 "InnoDB: Current counter is %lu and it"
1323 " must not exceed %lu!\n"
1324 "InnoDB: To reset the counter to zero"
1325 " you have to dump all your tables and\n"
1326 "InnoDB: recreate the whole InnoDB installation.\n",
1334 *space_id = fil_system->max_assigned_id = id;
1338 "InnoDB: You have run out of single-table"
1339 " tablespace id's!\n"
1340 "InnoDB: Current counter is %lu.\n"
1341 "InnoDB: To reset the counter to zero you"
1342 " have to dump all your tables and\n"
1343 "InnoDB: recreate the whole InnoDB installation.\n",
1345 *space_id = ULINT_UNDEFINED;
1348 mutex_exit(&fil_system->mutex);
1368 fil_space_t* tablespace;
1371 ut_ad(mutex_own(&fil_system->mutex));
1373 space = fil_space_get_by_id(
id);
1378 " InnoDB: Error: trying to remove tablespace %lu"
1379 " from the cache but\n"
1380 "InnoDB: it is not there.\n", (ulong)
id);
1385 HASH_DELETE(fil_space_t, hash, fil_system->spaces,
id, space);
1387 tablespace = fil_space_get_by_name(space->
name);
1389 ut_a(space == tablespace);
1391 HASH_DELETE(fil_space_t, name_hash, fil_system->name_hash,
1408 while (fil_node != NULL) {
1409 fil_node_free(fil_node, fil_system, space);
1417 rw_lock_x_unlock(&space->
latch);
1420 rw_lock_free(&(space->
latch));
1444 fil_mutex_enter_and_prepare_for_io(
id);
1446 space = fil_space_get_by_id(
id);
1448 if (space == NULL) {
1449 mutex_exit(&fil_system->mutex);
1465 fil_node_prepare_for_io(node, fil_system, space);
1471 mutex_exit(&fil_system->mutex);
1492 if (UNIV_UNLIKELY(!
id)) {
1496 fil_mutex_enter_and_prepare_for_io(
id);
1498 space = fil_space_get_by_id(
id);
1500 if (space == NULL) {
1501 mutex_exit(&fil_system->mutex);
1503 return(ULINT_UNDEFINED);
1517 fil_node_prepare_for_io(node, fil_system, space);
1521 flags = space->
flags;
1523 mutex_exit(&fil_system->mutex);
1534fil_space_get_zip_size(
1540 flags = fil_space_get_flags(
id);
1542 if (flags && flags != ULINT_UNDEFINED) {
1556fil_check_adress_in_tablespace(
1561 if (fil_space_get_size(
id) > page_no) {
1578 ut_a(fil_system == NULL);
1580 ut_a(hash_size > 0);
1581 ut_a(max_n_open > 0);
1583 void *fil_system_ptr=
mem_zalloc(
sizeof(fil_system_t));
1584 fil_system =
static_cast<fil_system_t *
>(fil_system_ptr);
1586 mutex_create(fil_system_mutex_key,
1587 &fil_system->mutex, SYNC_ANY_LATCH);
1589 fil_system->spaces = hash_create(hash_size);
1590 fil_system->name_hash = hash_create(hash_size);
1594 fil_system->max_n_open = max_n_open;
1611 mutex_enter(&fil_system->mutex);
1615 while (space != NULL) {
1619 while (node != NULL) {
1621 fil_node_open_file(node, fil_system,
1624 if (fil_system->max_n_open
1625 < 10 + fil_system->n_open) {
1627 "InnoDB: Warning: you must"
1628 " raise the value of"
1629 " innodb_open_files in\n"
1630 "InnoDB: my.cnf! Remember that"
1631 " InnoDB keeps all log files"
1633 "InnoDB: tablespace files open"
1634 " for the whole time mysqld is"
1636 "InnoDB: needs to open also"
1637 " some .ibd files if the"
1638 " file-per-table storage\n"
1639 "InnoDB: model is used."
1640 " Current open files %lu,"
1642 " open files %lu.\n",
1643 (ulong) fil_system->n_open,
1644 (ulong) fil_system->max_n_open);
1652 mutex_exit(&fil_system->mutex);
1665 mutex_enter(&fil_system->mutex);
1669 while (space != NULL) {
1671 fil_space_t* prev_space = space;
1678 fil_node_close_file(node, fil_system);
1684 fil_space_free(prev_space->
id, FALSE);
1687 mutex_exit(&fil_system->mutex);
1695fil_set_max_space_id_if_bigger(
1701 "InnoDB: Fatal error: max tablespace id"
1702 " is too high, %lu\n", (ulong) max_id);
1706 mutex_enter(&fil_system->mutex);
1708 if (fil_system->max_assigned_id < max_id) {
1710 fil_system->max_assigned_id = max_id;
1713 mutex_exit(&fil_system->mutex);
1722fil_write_lsn_and_arch_no_to_file(
1733 buf1 =
static_cast<byte *
>(mem_alloc(2 * UNIV_PAGE_SIZE));
1734 buf =
static_cast<byte *
>(
ut_align(buf1, UNIV_PAGE_SIZE));
1736 fil_read(TRUE, 0, 0, sum_of_sizes, 0, UNIV_PAGE_SIZE, buf, NULL);
1740 fil_write(TRUE, 0, 0, sum_of_sizes, 0, UNIV_PAGE_SIZE, buf, NULL);
1753fil_write_flushed_lsn_to_data_files(
1764 mutex_enter(&fil_system->mutex);
1776 && space->
id == 0) {
1781 mutex_exit(&fil_system->mutex);
1783 err = fil_write_lsn_and_arch_no_to_file(
1784 sum_of_sizes, lsn, arch_log_no);
1785 if (err != DB_SUCCESS) {
1790 mutex_enter(&fil_system->mutex);
1792 sum_of_sizes += node->
size;
1799 mutex_exit(&fil_system->mutex);
1809fil_read_flushed_lsn_and_arch_log_no(
1812 ibool one_read_already,
1815#ifdef UNIV_LOG_ARCHIVE
1816 ulint* min_arch_log_no,
1817 ulint* max_arch_log_no,
1819 ib_uint64_t* min_flushed_lsn,
1820 ib_uint64_t* max_flushed_lsn)
1824 ib_uint64_t flushed_lsn;
1826 buf2 =
static_cast<byte *
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
1828 buf =
static_cast<byte *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
1830 os_file_read(data_file, buf, 0, 0, UNIV_PAGE_SIZE);
1836 if (!one_read_already) {
1837 *min_flushed_lsn = flushed_lsn;
1838 *max_flushed_lsn = flushed_lsn;
1839#ifdef UNIV_LOG_ARCHIVE
1840 *min_arch_log_no = arch_log_no;
1841 *max_arch_log_no = arch_log_no;
1846 if (*min_flushed_lsn > flushed_lsn) {
1847 *min_flushed_lsn = flushed_lsn;
1849 if (*max_flushed_lsn < flushed_lsn) {
1850 *max_flushed_lsn = flushed_lsn;
1852#ifdef UNIV_LOG_ARCHIVE
1853 if (*min_arch_log_no > arch_log_no) {
1854 *min_arch_log_no = arch_log_no;
1856 if (*max_arch_log_no < arch_log_no) {
1857 *max_arch_log_no = arch_log_no;
1864#ifndef UNIV_HOTBACKUP
1871fil_inc_pending_ibuf_merges(
1877 mutex_enter(&fil_system->mutex);
1879 space = fil_space_get_by_id(
id);
1881 if (space == NULL) {
1883 "InnoDB: Error: trying to do ibuf merge to a"
1884 " dropped tablespace %lu\n",
1889 mutex_exit(&fil_system->mutex);
1896 mutex_exit(&fil_system->mutex);
1905fil_decr_pending_ibuf_merges(
1911 mutex_enter(&fil_system->mutex);
1913 space = fil_space_get_by_id(
id);
1915 if (space == NULL) {
1917 "InnoDB: Error: decrementing ibuf merge of a"
1918 " dropped tablespace %lu\n",
1922 if (space != NULL) {
1926 mutex_exit(&fil_system->mutex);
1934fil_create_directory_for_tablename(
1943 len = strlen(fil_path_to_mysql_datadir);
1944 namend = strchr(name,
'/');
1946 path =
static_cast<char *
>(mem_alloc(len + (namend - name) + 2));
1948 memcpy(path, fil_path_to_mysql_datadir, len);
1950 memcpy(path + len + 1, name, namend - name);
1951 path[len + (namend - name) + 1] = 0;
1959#ifndef UNIV_HOTBACKUP
1980 const char* new_name,
1997 type, space_id, log_flags, log_ptr, mtr);
2005 len = strlen(name) + 1;
2014 len = strlen(new_name) + 1;
2042fil_op_log_parse_or_replay(
2058 const char* new_name = NULL;
2062 if (end_ptr < ptr + 4) {
2071 if (end_ptr < ptr + 2) {
2080 if (end_ptr < ptr + name_len) {
2085 name = (
const char*) ptr;
2090 if (end_ptr < ptr + 2) {
2099 if (end_ptr < ptr + new_name_len) {
2104 new_name = (
const char*) ptr;
2106 ptr += new_name_len;
2133 if (fil_tablespace_exists_in_mem(space_id)) {
2134 ut_a(fil_delete_tablespace(space_id));
2145 if (fil_tablespace_exists_in_mem(space_id)) {
2148 fil_create_directory_for_tablename(new_name);
2153 if (fil_get_space_id_for_table(new_name)
2154 == ULINT_UNDEFINED) {
2157 if (!fil_rename_tablespace(NULL, space_id,
2168 if (fil_tablespace_exists_in_mem(space_id)) {
2170 }
else if (fil_get_space_id_for_table(name)
2171 != ULINT_UNDEFINED) {
2178 fil_create_directory_for_tablename(name);
2180 if (fil_create_new_single_table_tablespace(
2181 space_id, name, FALSE, flags,
2202fil_delete_tablespace(
2214 mutex_enter(&fil_system->mutex);
2216 space = fil_space_get_by_id(
id);
2218 if (space != NULL) {
2222 mutex_exit(&fil_system->mutex);
2230 fputs(
" InnoDB: Warning: trying to"
2231 " delete tablespace ", stderr);
2233 fprintf(stderr,
",\n"
2234 "InnoDB: but there are %lu pending"
2235 " ibuf merges on it.\n"
2236 "InnoDB: Loop %lu.\n",
2241 mutex_exit(&fil_system->mutex);
2246 goto stop_ibuf_merges;
2250 mutex_exit(&fil_system->mutex);
2254 mutex_enter(&fil_system->mutex);
2256 space = fil_space_get_by_id(
id);
2258 if (space == NULL) {
2261 " InnoDB: Error: cannot delete tablespace %lu\n"
2262 "InnoDB: because it is not found in the"
2263 " tablespace memory cache.\n",
2266 mutex_exit(&fil_system->mutex);
2282 fputs(
" InnoDB: Warning: trying to"
2283 " delete tablespace ", stderr);
2285 fprintf(stderr,
",\n"
2286 "InnoDB: but there are %lu flushes"
2287 " and %lu pending i/o's on it\n"
2288 "InnoDB: Loop %lu.\n",
2293 mutex_exit(&fil_system->mutex);
2303 mutex_exit(&fil_system->mutex);
2315 rw_lock_x_lock(&space->
latch);
2317#ifndef UNIV_HOTBACKUP
2325 buf_LRU_invalidate_tablespace(
id);
2329 mutex_enter(&fil_system->mutex);
2331 success = fil_space_free(
id, TRUE);
2333 mutex_exit(&fil_system->mutex);
2342 rw_lock_x_unlock(&space->
latch);
2346#ifndef UNIV_HOTBACKUP
2375fil_tablespace_is_being_deleted(
2380 ibool is_being_deleted;
2382 mutex_enter(&fil_system->mutex);
2384 space = fil_space_get_by_id(
id);
2386 ut_a(space != NULL);
2390 mutex_exit(&fil_system->mutex);
2392 return(is_being_deleted);
2395#ifndef UNIV_HOTBACKUP
2407fil_discard_tablespace(
2413 success = fil_delete_tablespace(
id);
2417 "InnoDB: Warning: cannot delete tablespace %lu"
2418 " in DISCARD TABLESPACE.\n"
2419 "InnoDB: But let us remove the"
2420 " insert buffer entries for this tablespace.\n",
2426 ibuf_delete_for_discarded_space(
id);
2437fil_rename_tablespace_in_mem(
2443 fil_space_t* space2;
2444 const char* old_name = space->
name;
2446 ut_ad(mutex_own(&fil_system->mutex));
2448 space2 = fil_space_get_by_name(old_name);
2449 if (space != space2) {
2450 fputs(
"InnoDB: Error: cannot find ", stderr);
2452 fputs(
" in tablespace memory cache\n", stderr);
2457 space2 = fil_space_get_by_name(path);
2458 if (space2 != NULL) {
2459 fputs(
"InnoDB: Error: ", stderr);
2461 fputs(
" is already in tablespace memory cache\n", stderr);
2466 HASH_DELETE(fil_space_t, name_hash, fil_system->name_hash,
2474 HASH_INSERT(fil_space_t, name_hash, fil_system->name_hash,
2491 ulint namelen = strlen(name);
2492 ulint dirlen = strlen(fil_path_to_mysql_datadir);
2493 char* filename =
static_cast<char *
>(mem_alloc(namelen + dirlen +
sizeof "/.ibd"));
2496 memcpy(filename, name, namelen);
2497 memcpy(filename + namelen,
".ibd",
sizeof ".ibd");
2499 memcpy(filename, fil_path_to_mysql_datadir, dirlen);
2500 filename[dirlen] =
'/';
2502 memcpy(filename + dirlen + 1, name, namelen);
2503 memcpy(filename + dirlen + namelen + 1,
".ibd",
sizeof ".ibd");
2517fil_rename_tablespace(
2519 const char* old_name,
2524 const char* new_name)
2533 ibool old_name_was_specified = TRUE;
2538 if (old_name == NULL) {
2539 old_name =
"(name not specified)";
2540 old_name_was_specified = FALSE;
2547 fputs(
" InnoDB: Warning: problems renaming ", stderr);
2549 fputs(
" to ", stderr);
2551 fprintf(stderr,
", %lu iterations\n", (ulong) count);
2554 mutex_enter(&fil_system->mutex);
2556 space = fil_space_get_by_id(
id);
2558 if (space == NULL) {
2560 "InnoDB: Error: cannot find space id %lu"
2561 " in the tablespace memory cache\n"
2562 "InnoDB: though the table ", (ulong)
id);
2564 fputs(
" in a rename operation should have that id\n", stderr);
2565 mutex_exit(&fil_system->mutex);
2570 if (count > 25000) {
2572 mutex_exit(&fil_system->mutex);
2590 mutex_exit(&fil_system->mutex);
2599 mutex_exit(&fil_system->mutex);
2607 }
else if (node->
open) {
2610 fil_node_close_file(node, fil_system);
2615 if (old_name_was_specified) {
2616 old_path = fil_make_ibd_name(old_name, FALSE);
2618 ut_a(strcmp(space->
name, old_path) == 0);
2619 ut_a(strcmp(node->
name, old_path) == 0);
2625 path = fil_make_ibd_name(new_name, FALSE);
2626 success = fil_rename_tablespace_in_mem(space, node, path);
2629 success = os_file_rename(innodb_file_data_key, old_path, path);
2635 ut_a(fil_rename_tablespace_in_mem(space, node,
2645 mutex_exit(&fil_system->mutex);
2647#ifndef UNIV_HOTBACKUP
2670fil_create_new_single_table_tablespace(
2673 const char* tablename,
2704 path = fil_make_ibd_name(tablename, is_temp);
2706 file = os_file_create(innodb_file_data_key, path,
2707 OS_FILE_CREATE, OS_FILE_NORMAL,
2711 fputs(
" InnoDB: Error creating file ", stderr);
2713 fputs(
".\n", stderr);
2719 if (err == OS_FILE_ALREADY_EXISTS) {
2720 fputs(
"InnoDB: The file already exists though"
2721 " the corresponding table did not\n"
2722 "InnoDB: exist in the InnoDB data dictionary."
2723 " Have you moved InnoDB\n"
2724 "InnoDB: .ibd files around without using the"
2726 "InnoDB: DISCARD TABLESPACE and"
2727 " IMPORT TABLESPACE, or did\n"
2728 "InnoDB: mysqld crash in the middle of"
2729 " CREATE TABLE? You can\n"
2730 "InnoDB: resolve the problem by"
2731 " removing the file ", stderr);
2734 "InnoDB: under the 'datadir' of MySQL.\n",
2738 return(DB_TABLESPACE_ALREADY_EXISTS);
2741 if (err == OS_FILE_DISK_FULL) {
2744 return(DB_OUT_OF_FILE_SPACE);
2754 err = DB_OUT_OF_FILE_SPACE;
2756 os_file_close(file);
2775 buf2 =
static_cast<byte *
>(
ut_malloc(3 * UNIV_PAGE_SIZE));
2777 page =
static_cast<byte *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
2779 memset(page,
'\0', UNIV_PAGE_SIZE);
2781 fsp_header_init_fields(page, space_id, flags);
2784 if (!(flags & DICT_TF_ZSSIZE_MASK)) {
2785 buf_flush_init_for_writing(page, NULL, 0);
2786 ret = os_file_write(path, file, page, 0, 0, UNIV_PAGE_SIZE);
2792 << ((flags & DICT_TF_ZSSIZE_MASK)
2796 page_zip.
data = page + UNIV_PAGE_SIZE;
2802 buf_flush_init_for_writing(page, &page_zip, 0);
2803 ret = os_file_write(path, file, page_zip.
data, 0, 0, zip_size);
2809 fputs(
"InnoDB: Error: could not write the first page"
2810 " to tablespace ", stderr);
2817 ret = os_file_flush(file);
2820 fputs(
"InnoDB: Error: file flush of tablespace ", stderr);
2822 fputs(
" failed\n", stderr);
2827 os_file_close(file);
2829 success = fil_space_create(path, space_id, flags,
FIL_TABLESPACE);
2836 fil_node_create(path, size, space_id, FALSE);
2838#ifndef UNIV_HOTBACKUP
2844 fil_op_write_log(flags
2850 tablename, NULL, &mtr);
2859#ifndef UNIV_HOTBACKUP
2872fil_reset_too_high_lsns(
2876 ib_uint64_t current_lsn)
2884 ib_uint64_t flush_lsn;
2886 ib_int64_t file_size;
2892 filepath = fil_make_ibd_name(name, FALSE);
2894 file = os_file_create_simple_no_error_handling(
2896 OS_FILE_READ_WRITE, &success);
2903 fputs(
" InnoDB: Error: trying to open a table,"
2905 "InnoDB: open the tablespace file ", stderr);
2907 fputs(
"!\n", stderr);
2915 buf2 =
static_cast<byte *
>(
ut_malloc(3 * UNIV_PAGE_SIZE));
2917 page =
static_cast<byte *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
2919 success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
2929 if (current_lsn >= flush_lsn) {
2936 space_id = fsp_header_get_space_id(page);
2937 zip_size = fsp_header_get_zip_size(page);
2942 page_zip.
data = page + UNIV_PAGE_SIZE;
2947 " InnoDB: Flush lsn in the tablespace file %lu"
2949 "InnoDB: is %" PRIu64
", which exceeds current"
2950 " system lsn %" PRIu64
".\n"
2951 "InnoDB: We reset the lsn's in the file ",
2953 flush_lsn, current_lsn);
2955 fputs(
".\n", stderr);
2958 ut_a(zip_size <= UNIV_PAGE_SIZE);
2965 for (offset = 0; offset < file_size;
2966 offset += zip_size ? zip_size : UNIV_PAGE_SIZE) {
2967 success = os_file_read(file, page,
2968 (ulint)(offset & 0xFFFFFFFFUL),
2969 (ulint)(offset >> 32),
2970 zip_size ? zip_size : UNIV_PAGE_SIZE);
2979 memcpy(page_zip.
data, page, zip_size);
2980 buf_flush_init_for_writing(
2981 page, &page_zip, current_lsn);
2982 success = os_file_write(
2983 filepath, file, page_zip.
data,
2984 (ulint) offset & 0xFFFFFFFFUL,
2985 (ulint) (offset >> 32), zip_size);
2987 buf_flush_init_for_writing(
2988 page, NULL, current_lsn);
2989 success = os_file_write(
2990 filepath, file, page,
2991 (ulint)(offset & 0xFFFFFFFFUL),
2992 (ulint)(offset >> 32),
3003 success = os_file_flush(file);
3010 success = os_file_read(file, page, 0, 0,
3011 zip_size ? zip_size : UNIV_PAGE_SIZE);
3019 success = os_file_write(filepath, file, page, 0, 0,
3020 zip_size ? zip_size : UNIV_PAGE_SIZE);
3025 success = os_file_flush(file);
3027 os_file_close(file);
3046fil_open_single_table_tablespace(
3048 ibool check_space_id,
3068 filepath = fil_make_ibd_name(name, FALSE);
3079 file = os_file_create_simple_no_error_handling(
3081 OS_FILE_READ_ONLY, &success);
3088 fputs(
" InnoDB: Error: trying to open a table,"
3090 "InnoDB: open the tablespace file ", stderr);
3093 "InnoDB: Have you moved InnoDB .ibd files around"
3094 " without using the\n"
3095 "InnoDB: commands DISCARD TABLESPACE and"
3096 " IMPORT TABLESPACE?\n"
3097 "InnoDB: It is also possible that this is"
3098 " a temporary table #sql...,\n"
3099 "InnoDB: and MySQL removed the .ibd file for this.\n"
3100 "InnoDB: Please refer to\n"
3101 "InnoDB: " REFMAN
"innodb-troubleshooting-datadict.html\n"
3102 "InnoDB: for how to resolve the issue.\n", stderr);
3109 if (!check_space_id) {
3117 buf2 =
static_cast<byte *
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
3119 page =
static_cast<byte *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
3121 success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
3125 space_id = fsp_header_get_space_id(page);
3126 space_flags = fsp_header_get_flags(page);
3130 if (UNIV_UNLIKELY(space_id !=
id
3134 fputs(
" InnoDB: Error: tablespace id and flags in file ",
3137 fprintf(stderr,
" are %lu and %lu, but in the InnoDB\n"
3138 "InnoDB: data dictionary they are %lu and %lu.\n"
3139 "InnoDB: Have you moved InnoDB .ibd files"
3140 " around without using the\n"
3141 "InnoDB: commands DISCARD TABLESPACE and"
3142 " IMPORT TABLESPACE?\n"
3143 "InnoDB: Please refer to\n"
3144 "InnoDB: " REFMAN
"innodb-troubleshooting-datadict.html\n"
3145 "InnoDB: for how to resolve the issue.\n",
3146 (ulong) space_id, (ulong) space_flags,
3147 (ulong)
id, (ulong) flags);
3155 success = fil_space_create(filepath, space_id, flags,
FIL_TABLESPACE);
3164 fil_node_create(filepath, 0, space_id, FALSE);
3166 os_file_close(file);
3173#ifdef UNIV_HOTBACKUP
3180fil_make_ibbackup_old_name(
3184 static const char suffix[] =
"_ibbackup_old_vers_";
3185 ulint len = strlen(name);
3186 char* path = mem_alloc(len + (15 +
sizeof suffix));
3188 memcpy(path, name, len);
3189 memcpy(path + len, suffix, (
sizeof suffix) - 1);
3190 ut_sprintf_timestamp_without_extra_chars(path + len +
sizeof suffix);
3200fil_load_single_table_tablespace(
3203 const char* filename)
3216#ifdef UNIV_HOTBACKUP
3219 filepath =
static_cast<char *
>(mem_alloc(strlen(dbname) + strlen(filename)
3220 + strlen(fil_path_to_mysql_datadir) + 3));
3222 sprintf(filepath,
"%s/%s/%s", fil_path_to_mysql_datadir, dbname,
3226# ifndef UNIV_HOTBACKUP
3233 dict_casedn_str(filepath);
3236 file = os_file_create_simple_no_error_handling(
3238 OS_FILE_READ_ONLY, &success);
3244 "InnoDB: Error: could not open single-table tablespace"
3247 "InnoDB: We do not continue the crash recovery,"
3248 " because the table may become\n"
3249 "InnoDB: corrupt if we cannot apply the log records"
3250 " in the InnoDB log to it.\n"
3251 "InnoDB: To fix the problem and start mysqld:\n"
3252 "InnoDB: 1) If there is a permission problem"
3253 " in the file and mysqld cannot\n"
3254 "InnoDB: open the file, you should"
3255 " modify the permissions.\n"
3256 "InnoDB: 2) If the table is not needed, or you can"
3257 " restore it from a backup,\n"
3258 "InnoDB: then you can remove the .ibd file,"
3259 " and InnoDB will do a normal\n"
3260 "InnoDB: crash recovery and ignore that table.\n"
3261 "InnoDB: 3) If the file system or the"
3262 " disk is broken, and you cannot remove\n"
3263 "InnoDB: the .ibd file, you can set"
3264 " innodb_force_recovery > 0 in my.cnf\n"
3265 "InnoDB: and force InnoDB to continue crash"
3266 " recovery here.\n", filepath);
3270 if (srv_force_recovery > 0) {
3272 "InnoDB: innodb_force_recovery"
3273 " was set to %lu. Continuing crash recovery\n"
3274 "InnoDB: even though we cannot access"
3275 " the .ibd file of this table.\n",
3276 srv_force_recovery);
3290 "InnoDB: Error: could not measure the size"
3291 " of single-table tablespace file\n"
3293 "InnoDB: We do not continue crash recovery,"
3294 " because the table will become\n"
3295 "InnoDB: corrupt if we cannot apply the log records"
3296 " in the InnoDB log to it.\n"
3297 "InnoDB: To fix the problem and start mysqld:\n"
3298 "InnoDB: 1) If there is a permission problem"
3299 " in the file and mysqld cannot\n"
3300 "InnoDB: access the file, you should"
3301 " modify the permissions.\n"
3302 "InnoDB: 2) If the table is not needed,"
3303 " or you can restore it from a backup,\n"
3304 "InnoDB: then you can remove the .ibd file,"
3305 " and InnoDB will do a normal\n"
3306 "InnoDB: crash recovery and ignore that table.\n"
3307 "InnoDB: 3) If the file system or the disk is broken,"
3308 " and you cannot remove\n"
3309 "InnoDB: the .ibd file, you can set"
3310 " innodb_force_recovery > 0 in my.cnf\n"
3311 "InnoDB: and force InnoDB to continue"
3312 " crash recovery here.\n", filepath);
3314 os_file_close(file);
3317 if (srv_force_recovery > 0) {
3319 "InnoDB: innodb_force_recovery"
3320 " was set to %lu. Continuing crash recovery\n"
3321 "InnoDB: even though we cannot access"
3322 " the .ibd file of this table.\n",
3323 srv_force_recovery);
3336 size = (((ib_int64_t)size_high) << 32) + (ib_int64_t)size_low;
3337#ifndef UNIV_HOTBACKUP
3340 "InnoDB: Error: the size of single-table tablespace"
3342 "InnoDB: is only %lu %lu, should be at least %lu!",
3345 (ulong) size_low, (ulong) (4 * UNIV_PAGE_SIZE));
3346 os_file_close(file);
3354 buf2 =
static_cast<byte *
>(
ut_malloc(2 * UNIV_PAGE_SIZE));
3356 page =
static_cast<byte *
>(
ut_align(buf2, UNIV_PAGE_SIZE));
3359 success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
3363 space_id = fsp_header_get_space_id(page);
3364 flags = fsp_header_get_flags(page);
3366 space_id = ULINT_UNDEFINED;
3370#ifndef UNIV_HOTBACKUP
3371 if (space_id == ULINT_UNDEFINED || space_id == 0) {
3373 "InnoDB: Error: tablespace id %lu in file %s"
3374 " is not sensible\n",
3380 if (space_id == ULINT_UNDEFINED || space_id == 0) {
3384 "InnoDB: Renaming tablespace %s of id %lu,\n"
3385 "InnoDB: to %s_ibbackup_old_vers_<timestamp>\n"
3386 "InnoDB: because its size %" PRId64
" is too small"
3387 " (< 4 pages 16 kB each),\n"
3388 "InnoDB: or the space id in the file header"
3389 " is not sensible.\n"
3390 "InnoDB: This can happen in an ibbackup run,"
3391 " and is not dangerous.\n",
3392 filepath, space_id, filepath, size);
3393 os_file_close(file);
3395 new_path = fil_make_ibbackup_old_name(filepath);
3396 ut_a(os_file_rename(innodb_file_data_key, filepath, new_path));
3412 mutex_enter(&fil_system->mutex);
3414 space = fil_space_get_by_id(space_id);
3420 "InnoDB: Renaming tablespace %s of id %lu,\n"
3421 "InnoDB: to %s_ibbackup_old_vers_<timestamp>\n"
3422 "InnoDB: because space %s with the same id\n"
3423 "InnoDB: was scanned earlier. This can happen"
3424 " if you have renamed tables\n"
3425 "InnoDB: during an ibbackup run.\n",
3426 filepath, space_id, filepath,
3428 os_file_close(file);
3430 new_path = fil_make_ibbackup_old_name(filepath);
3432 mutex_exit(&fil_system->mutex);
3434 ut_a(os_file_rename(innodb_file_data_key, filepath, new_path));
3442 mutex_exit(&fil_system->mutex);
3444 success = fil_space_create(filepath, space_id, flags,
FIL_TABLESPACE);
3448 if (srv_force_recovery > 0) {
3450 "InnoDB: innodb_force_recovery"
3451 " was set to %lu. Continuing crash recovery\n"
3452 "InnoDB: even though the tablespace creation"
3453 " of this table failed.\n",
3454 srv_force_recovery);
3465 fil_node_create(filepath, 0, space_id, FALSE);
3467 os_file_close(file);
3479fil_file_readdir_next_file(
3483 const char* dirname,
3485 os_file_stat_t* info)
3490 for (i = 0; i < 100; i++) {
3499 "InnoDB: Error: os_file_readdir_next_file()"
3501 "InnoDB: directory %s\n"
3502 "InnoDB: Crash recovery may have failed"
3503 " for some .ibd files!\n", dirname);
3525 char* dbpath = NULL;
3526 ulint dbpath_len = 100;
3529 os_file_stat_t dbinfo;
3530 os_file_stat_t fileinfo;
3531 ulint err = DB_SUCCESS;
3542 dbpath =
static_cast<char *
>(mem_alloc(dbpath_len));
3547 ret = fil_file_readdir_next_file(&err, fil_path_to_mysql_datadir, dir,
3553 if (dbinfo.
type == OS_FILE_TYPE_FILE
3554 || dbinfo.
type == OS_FILE_TYPE_UNKNOWN) {
3556 goto next_datadir_item;
3562 len = strlen(fil_path_to_mysql_datadir)
3563 + strlen (dbinfo.
name) + 2;
3564 if (len > dbpath_len) {
3571 dbpath =
static_cast<char *
>(mem_alloc(dbpath_len));
3573 sprintf(dbpath,
"%s/%s", fil_path_to_mysql_datadir,
3579 if (dbdir != NULL) {
3585 ret = fil_file_readdir_next_file(&err, dbpath, dbdir,
3591 if (fileinfo.
type == OS_FILE_TYPE_DIR) {
3593 goto next_file_item;
3597 if (strlen(fileinfo.
name) > 4
3598 && 0 == strcmp(fileinfo.
name
3599 + strlen(fileinfo.
name) - 4,
3603 fil_load_single_table_tablespace(
3607 ret = fil_file_readdir_next_file(&err,
3613 fputs(
"InnoDB: Warning: could not"
3614 " close database directory ", stderr);
3623 ret = fil_file_readdir_next_file(&err,
3624 fil_path_to_mysql_datadir,
3632 "InnoDB: Error: could not close MySQL datadir\n");
3646fil_tablespace_deleted_or_being_deleted_in_mem(
3657 mutex_enter(&fil_system->mutex);
3659 space = fil_space_get_by_id(
id);
3662 mutex_exit(&fil_system->mutex);
3667 if (version != ((ib_int64_t)-1)
3669 mutex_exit(&fil_system->mutex);
3674 mutex_exit(&fil_system->mutex);
3684fil_tablespace_exists_in_mem(
3692 mutex_enter(&fil_system->mutex);
3694 space = fil_space_get_by_id(
id);
3696 mutex_exit(&fil_system->mutex);
3698 return(space != NULL);
3708fil_space_for_table_exists_in_mem(
3722 ibool print_error_if_does_not_exist)
3728 fil_space_t* tablespace;
3734 mutex_enter(&fil_system->mutex);
3736 path = fil_make_ibd_name(name, is_temp);
3740 space = fil_space_get_by_id(
id);
3745 tablespace = fil_space_get_by_name(path);
3746 if (space && space == tablespace) {
3754 mutex_exit(&fil_system->mutex);
3759 if (!print_error_if_does_not_exist) {
3762 mutex_exit(&fil_system->mutex);
3767 if (space == NULL) {
3768 if (tablespace == NULL) {
3770 fputs(
" InnoDB: Error: table ", stderr);
3772 fprintf(stderr,
"\n"
3773 "InnoDB: in InnoDB data dictionary"
3774 " has tablespace id %lu,\n"
3775 "InnoDB: but tablespace with that id"
3776 " or name does not exist. Have\n"
3777 "InnoDB: you deleted or moved .ibd files?\n"
3778 "InnoDB: This may also be a table created with"
3779 " CREATE TEMPORARY TABLE\n"
3780 "InnoDB: whose .ibd and .frm files"
3781 " MySQL automatically removed, but the\n"
3782 "InnoDB: table still exists in the"
3783 " InnoDB internal data dictionary.\n",
3787 fputs(
" InnoDB: Error: table ", stderr);
3789 fprintf(stderr,
"\n"
3790 "InnoDB: in InnoDB data dictionary has"
3791 " tablespace id %lu,\n"
3792 "InnoDB: but a tablespace with that id"
3793 " does not exist. There is\n"
3794 "InnoDB: a tablespace of name %s and id %lu,"
3796 "InnoDB: you deleted or moved .ibd files?\n",
3797 (ulong)
id, tablespace->
name,
3798 (ulong) tablespace->
id);
3801 fputs(
"InnoDB: Please refer to\n"
3802 "InnoDB: " REFMAN
"innodb-troubleshooting-datadict.html\n"
3803 "InnoDB: for how to resolve the issue.\n", stderr);
3806 mutex_exit(&fil_system->mutex);
3811 if (0 != strcmp(space->
name, path)) {
3813 fputs(
" InnoDB: Error: table ", stderr);
3815 fprintf(stderr,
"\n"
3816 "InnoDB: in InnoDB data dictionary has"
3817 " tablespace id %lu,\n"
3818 "InnoDB: but the tablespace with that id"
3820 "InnoDB: Have you deleted or moved .ibd files?\n",
3821 (ulong)
id, space->
name);
3823 if (tablespace != NULL) {
3824 fputs(
"InnoDB: There is a tablespace"
3825 " with the right name\n"
3826 "InnoDB: ", stderr);
3828 fprintf(stderr,
", but its id is %lu.\n",
3829 (ulong) tablespace->
id);
3836 mutex_exit(&fil_system->mutex);
3847fil_get_space_id_for_table(
3852 fil_space_t* tablespace;
3853 ulint
id = ULINT_UNDEFINED;
3858 mutex_enter(&fil_system->mutex);
3860 path = fil_make_ibd_name(name, FALSE);
3865 tablespace = fil_space_get_by_name(path);
3868 id = tablespace->
id;
3873 mutex_exit(&fil_system->mutex);
3885fil_extend_space_to_desired_size(
3891 ulint size_after_extend)
3900 ulint start_page_no;
3901 ulint file_start_page_no;
3905 ibool success = TRUE;
3907 fil_mutex_enter_and_prepare_for_io(space_id);
3909 space = fil_space_get_by_id(space_id);
3912 if (space->
size >= size_after_extend) {
3915 *actual_size = space->
size;
3917 mutex_exit(&fil_system->mutex);
3924 page_size = UNIV_PAGE_SIZE;
3929 fil_node_prepare_for_io(node, fil_system, space);
3931 start_page_no = space->
size;
3932 file_start_page_no = space->
size - node->
size;
3935 buf_size =
ut_min(64, size_after_extend - start_page_no) * page_size;
3936 buf2 =
static_cast<byte *
>(mem_alloc(buf_size + page_size));
3937 buf =
static_cast<byte *
>(
ut_align(buf2, page_size));
3939 memset(buf, 0, buf_size);
3941 while (start_page_no < size_after_extend) {
3942 ulint n_pages =
ut_min(buf_size / page_size,
3943 size_after_extend - start_page_no);
3945 offset_high = (start_page_no - file_start_page_no)
3946 / (4096 * ((1024 * 1024) / page_size));
3947 offset_low = ((start_page_no - file_start_page_no)
3948 % (4096 * ((1024 * 1024) / page_size)))
3950#ifdef UNIV_HOTBACKUP
3951 success = os_file_write(node->
name, node->
handle, buf,
3952 offset_low, offset_high,
3953 page_size * n_pages);
3957 offset_low, offset_high,
3958 page_size * n_pages,
3962 node->
size += n_pages;
3963 space->
size += n_pages;
3965 os_has_said_disk_full = FALSE;
3973 / page_size)) - node->
size;
3975 node->
size += n_pages;
3976 space->
size += n_pages;
3981 start_page_no += n_pages;
3986 fil_node_complete_io(node, fil_system, OS_FILE_WRITE);
3988 *actual_size = space->
size;
3990#ifndef UNIV_HOTBACKUP
3991 if (space_id == 0) {
3992 ulint pages_per_mb = (1024 * 1024) / page_size;
3997 srv_data_file_sizes[srv_n_data_files - 1]
3998 = (node->
size / pages_per_mb) * pages_per_mb;
4005 mutex_exit(&fil_system->mutex);
4007 fil_flush(space_id);
4012#ifdef UNIV_HOTBACKUP
4020fil_extend_tablespaces_to_stored_len(
void)
4026 ulint size_in_header;
4030 buf = mem_alloc(UNIV_PAGE_SIZE);
4032 mutex_enter(&fil_system->mutex);
4039 mutex_exit(&fil_system->mutex);
4042 error = fil_read(TRUE, space->
id,
4044 0, 0, UNIV_PAGE_SIZE, buf, NULL);
4045 ut_a(error == DB_SUCCESS);
4047 size_in_header = fsp_get_size_low(buf);
4049 success = fil_extend_space_to_desired_size(
4050 &actual_size, space->
id, size_in_header);
4053 "InnoDB: Error: could not extend the"
4054 " tablespace of %s\n"
4055 "InnoDB: to the size stored in header,"
4057 "InnoDB: size after extension %lu pages\n"
4058 "InnoDB: Check that you have free disk space"
4060 space->
name, size_in_header, actual_size);
4064 mutex_enter(&fil_system->mutex);
4069 mutex_exit(&fil_system->mutex);
4082fil_space_reserve_free_extents(
4093 mutex_enter(&fil_system->mutex);
4095 space = fil_space_get_by_id(
id);
4106 mutex_exit(&fil_system->mutex);
4115fil_space_release_free_extents(
4124 mutex_enter(&fil_system->mutex);
4126 space = fil_space_get_by_id(
id);
4133 mutex_exit(&fil_system->mutex);
4141fil_space_get_n_reserved_extents(
4150 mutex_enter(&fil_system->mutex);
4152 space = fil_space_get_by_id(
id);
4158 mutex_exit(&fil_system->mutex);
4174fil_node_prepare_for_io(
4177 fil_system_t* system,
4180 ut_ad(node && system && space);
4186 " InnoDB: Warning: open files %lu"
4187 " exceeds the limit %lu\n",
4192 if (node->
open == FALSE) {
4196 fil_node_open_file(node, system, space);
4200 && space->
id != 0) {
4216fil_node_complete_io(
4219 fil_system_t* system,
4232 if (type == OS_FILE_WRITE) {
4240 system->unflushed_spaces,
4256fil_report_invalid_page_access(
4260 const char* space_name,
4266 "InnoDB: Error: trying to access page number %lu"
4268 "InnoDB: space name %s,\n"
4269 "InnoDB: which is outside the tablespace bounds.\n"
4270 "InnoDB: Byte offset %lu, len %lu, i/o type %lu.\n"
4271 "InnoDB: If you get this error at mysqld startup,"
4272 " please check that\n"
4273 "InnoDB: your my.cnf matches the ibdata files"
4274 " that you have in the\n"
4275 "InnoDB: MySQL server.\n",
4276 (ulong) block_offset, (ulong) space_id, space_name,
4277 (ulong) byte_offset, (ulong) len, (ulong) type);
4323 is_log = type & OS_FILE_LOG;
4324 type = type & ~OS_FILE_LOG;
4329 ut_ad(byte_offset < UNIV_PAGE_SIZE);
4330 ut_ad(!zip_size || !byte_offset);
4334 ut_ad(fil_validate_skip());
4335#ifndef UNIV_HOTBACKUP
4336# ifndef UNIV_LOG_DEBUG
4344 }
else if (is_log) {
4348 &&
ibuf_page(space_id, zip_size, block_offset, NULL)) {
4359 srv_data_read+= len;
4360 }
else if (type == OS_FILE_WRITE) {
4361 srv_data_written+= len;
4367 fil_mutex_enter_and_prepare_for_io(space_id);
4369 space = fil_space_get_by_id(space_id);
4372 mutex_exit(&fil_system->mutex);
4376 " InnoDB: Error: trying to do i/o"
4377 " to a tablespace which does not exist.\n"
4378 "InnoDB: i/o type %lu, space id %lu,"
4379 " page no. %lu, i/o length %lu bytes\n",
4380 (ulong) type, (ulong) space_id, (ulong) block_offset,
4383 return(DB_TABLESPACE_DELETED);
4391 if (UNIV_UNLIKELY(node == NULL)) {
4392 fil_report_invalid_page_access(
4393 block_offset, space_id, space->
name,
4394 byte_offset, len, type);
4399 if (space->
id != 0 && node->
size == 0) {
4406 if (node->
size > block_offset) {
4410 block_offset -= node->
size;
4416 fil_node_prepare_for_io(node, fil_system, space);
4420 if (UNIV_UNLIKELY(node->
size <= block_offset)
4423 fil_report_invalid_page_access(
4424 block_offset, space_id, space->
name, byte_offset,
4431 mutex_exit(&fil_system->mutex);
4436 offset_high = (block_offset >> (32 - UNIV_PAGE_SIZE_SHIFT));
4437 offset_low = ((block_offset << UNIV_PAGE_SIZE_SHIFT)
4438 & 0xFFFFFFFFUL) + byte_offset;
4441 >= ((byte_offset + len + (UNIV_PAGE_SIZE - 1))
4444 ulint zip_size_shift;
4446 case 1024: zip_size_shift = 10;
break;
4447 case 2048: zip_size_shift = 11;
break;
4448 case 4096: zip_size_shift = 12;
break;
4449 case 8192: zip_size_shift = 13;
break;
4450 case 16384: zip_size_shift = 14;
break;
4453 offset_high = block_offset >> (32 - zip_size_shift);
4454 offset_low = (block_offset << zip_size_shift & 0xFFFFFFFFUL)
4457 >= (len + (zip_size - 1)) / zip_size);
4465#ifdef UNIV_HOTBACKUP
4468 ret = os_file_read(node->
handle, buf, offset_low, offset_high,
4471 ret = os_file_write(node->
name, node->
handle, buf,
4472 offset_low, offset_high, len);
4476 ret = os_aio(type, mode | wake_later, node->
name, node->
handle, buf,
4477 offset_low, offset_high, len, node, message);
4485 mutex_enter(&fil_system->mutex);
4487 fil_node_complete_io(node, fil_system, type);
4489 mutex_exit(&fil_system->mutex);
4491 ut_ad(fil_validate_skip());
4512 fil_mutex_enter_and_prepare_for_io(space_id);
4514 space = fil_space_get_by_id(space_id);
4517 mutex_exit(&fil_system->mutex);
4524 if (UNIV_UNLIKELY(node == NULL)) {
4525 mutex_exit(&fil_system->mutex);
4529 if (space->
id != 0 && node->
size == 0) {
4536 if (node->
size > block_offset) {
4540 block_offset -= node->
size;
4546 fil_node_prepare_for_io(node, fil_system, space);
4551 if (UNIV_UNLIKELY(node->
size <= block_offset)
4553 mutex_exit(&fil_system->mutex);
4557 mutex_exit(&fil_system->mutex);
4561#ifndef UNIV_HOTBACKUP
4579 ut_ad(fil_validate_skip());
4581 if (srv_use_native_aio) {
4584 ret = os_aio_windows_handle(segment, 0, &fil_node,
4586#elif defined(LINUX_NATIVE_AIO)
4587 ret = os_aio_linux_handle(segment, &fil_node,
4604 mutex_enter(&fil_system->mutex);
4606 fil_node_complete_io(fil_node, fil_system, type);
4608 mutex_exit(&fil_system->mutex);
4610 ut_ad(fil_validate_skip());
4620 buf_page_io_complete(
static_cast<buf_page_t *
>(message));
4641 ib_int64_t old_mod_counter;
4643 mutex_enter(&fil_system->mutex);
4645 space = fil_space_get_by_id(space_id);
4648 mutex_exit(&fil_system->mutex);
4666 fil_n_pending_tablespace_flushes++;
4668 fil_n_pending_log_flushes++;
4669 fil_n_log_flushes++;
4684 mutex_exit(&fil_system->mutex);
4688 mutex_enter(&fil_system->mutex);
4702 mutex_exit(&fil_system->mutex);
4707 os_file_flush(file);
4709 mutex_enter(&fil_system->mutex);
4717 && fil_space_is_flushed(space)) {
4723 fil_system->unflushed_spaces,
4729 fil_n_pending_tablespace_flushes--;
4731 fil_n_pending_log_flushes--;
4740 mutex_exit(&fil_system->mutex);
4748fil_flush_file_spaces(
4757 mutex_enter(&fil_system->mutex);
4760 if (n_space_ids == 0) {
4762 mutex_exit(&fil_system->mutex);
4770 space_ids =
static_cast<unsigned long *
>(mem_alloc(n_space_ids *
sizeof *space_ids));
4780 space_ids[n_space_ids++] = space->
id;
4784 mutex_exit(&fil_system->mutex);
4788 for (i = 0; i < n_space_ids; i++) {
4790 fil_flush(space_ids[i]);
4809 mutex_enter(&fil_system->mutex);
4815 space =
static_cast<fil_space_t *
>(
HASH_GET_FIRST(fil_system->spaces, i));
4817 while (space != NULL) {
4819 ut_a(ut_list_node_313->open
4820 || !ut_list_node_313->n_pending));
4824 while (fil_node != NULL) {
4829 if (fil_node->
open) {
4834 space =
static_cast<fil_space_t *
>(
HASH_GET_NEXT(hash, space));
4838 ut_a(fil_system->n_open == n_open);
4844 while (fil_node != NULL) {
4853 mutex_exit(&fil_system->mutex);
4930#ifndef UNIV_HOTBACKUP
4932 ut_ad(fil_system->mutex.magic_n == 0);
4935 hash_table_free(fil_system->spaces);
4937 hash_table_free(fil_system->name_hash);
struct buf_page_struct buf_page_t
UNIV_INLINE ulint dict_table_flags_to_zip_size(ulint flags) __attribute__((const))
#define DICT_TF_ZSSIZE_SHIFT
#define FIL_IBD_FILE_INITIAL_SIZE
#define FIL_PAGE_FILE_FLUSH_LSN
UNIV_INTERN void fil_close_all_files(void)
struct fil_addr_struct fil_addr_t
UNIV_INTERN void fil_open_log_and_system_tablespace_files(void)
#define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID
UNIV_INTERN ibool fil_validate(void)
UNIV_INTERN void fil_close(void)
UNIV_INTERN ulint fil_load_single_table_tablespaces(void)
#define HASH_INSERT(TYPE, NAME, TABLE, FOLD, DATA)
UNIV_INLINE ulint hash_get_n_cells(hash_table_t *table)
#define HASH_SEARCH(NAME, TABLE, FOLD, TYPE, DATA, ASSERTION, TEST)
#define HASH_GET_NEXT(NAME, DATA)
#define HASH_DELETE(TYPE, NAME, TABLE, FOLD, DATA)
#define HASH_GET_FIRST(TABLE, HASH_VAL)
UNIV_INLINE ibool ibuf_bitmap_page(ulint zip_size, ulint page_no)
#define ibuf_page(space, zip_size, page_no, mtr)
UNIV_INTERN void log_io_complete(log_group_t *group)
struct log_group_struct log_group_t
ibool recv_no_ibuf_operations
UNIV_INLINE void mach_write_to_2(byte *b, ulint n)
UNIV_INLINE ib_uint64_t mach_read_from_8(const byte *b) __attribute__((nonnull
UNIV_INLINE void mach_write_to_8(byte *b, ib_uint64_t n)
UNIV_INLINE ulint mach_read_from_2(const byte *b) __attribute__((nonnull
UNIV_INLINE void mach_write_to_4(byte *b, ulint n)
UNIV_INLINE ulint mach_read_from_4(const byte *b) __attribute__((nonnull
UNIV_INLINE char * mem_strdup(const char *str)
UNIV_INLINE void mlog_close(mtr_t *mtr, byte *ptr)
UNIV_INLINE byte * mlog_write_initial_log_record_for_file_op(ulint type, ulint space_id, ulint page_no, byte *log_ptr, mtr_t *mtr)
UNIV_INLINE byte * mlog_open(mtr_t *mtr, ulint size)
UNIV_INTERN void mlog_catenate_string(mtr_t *mtr, const byte *str, ulint len)
UNIV_INTERN void mtr_commit(mtr_t *mtr) __attribute__((nonnull))
UNIV_INLINE void mtr_start(mtr_t *mtr) __attribute__((nonnull))
#define MLOG_FILE_CREATE2
#define MLOG_FILE_FLAG_TEMP
UNIV_INTERN ulint os_file_get_last_error(ibool report_all_errors)
UNIV_INTERN int os_file_closedir(os_file_dir_t dir)
struct fil_node_struct fil_node_t
UNIV_INTERN ibool os_aio_simulated_handle(ulint segment, fil_node_t **message1, void **message2, ulint *type)
UNIV_INTERN void os_aio_simulated_wake_handler_threads(void)
UNIV_INTERN int os_file_readdir_next_file(const char *dirname, os_file_dir_t dir, os_file_stat_t *info)
UNIV_INTERN ibool os_file_get_size(os_file_t file, ulint *size, ulint *size_high)
#define OS_FILE_LOG_BLOCK_SIZE
UNIV_INTERN ibool os_file_set_size(const char *name, os_file_t file, ulint size, ulint size_high)
UNIV_INTERN ibool os_file_delete_if_exists(const char *name)
#define OS_AIO_SIMULATED_WAKE_LATER
UNIV_INTERN ibool os_file_delete(const char *name)
UNIV_INTERN ib_int64_t os_file_get_size_as_iblonglong(os_file_t file)
UNIV_INTERN ibool os_file_create_directory(const char *pathname, ibool fail_if_exists)
UNIV_INTERN os_file_dir_t os_file_opendir(const char *dirname, ibool error_is_fatal)
UNIV_INTERN void os_thread_sleep(ulint tm)
struct page_zip_des_struct page_zip_des_t
#define PAGE_ZIP_MIN_SIZE
UNIV_INLINE void page_zip_des_init(page_zip_des_t *page_zip)
UNIV_INLINE void page_zip_set_size(page_zip_des_t *page_zip, ulint size)
UNIV_INTERN void srv_set_io_thread_op_info(ulint i, const char *str)
UNIV_INTERN void srv_normalize_path_for_win(char *str)
#define SRV_LOG_SPACE_FIRST_ID
ibool srv_start_raw_disk_in_use
UT_LIST_NODE_T(fil_node_t) LRU
UT_LIST_NODE_T(fil_node_t) chain
ib_int64_t modification_counter
ib_int64_t tablespace_version
UT_LIST_BASE_NODE_T(fil_node_t) chain
UT_LIST_NODE_T(fil_space_t) space_list
ulint n_pending_ibuf_merges
ibool is_in_unflushed_spaces
UT_LIST_NODE_T(fil_space_t) unflushed_spaces
UT_LIST_BASE_NODE_T(fil_space_t) space_list
ib_int64_t modification_counter
UT_LIST_BASE_NODE_T(fil_space_t) unflushed_spaces
ib_int64_t tablespace_version
UT_LIST_BASE_NODE_T(fil_node_t) LRU
char name[OS_FILE_MAX_PATH]
#define rw_lock_create(K, L, level)
UNIV_INLINE void * ut_align(const void *ptr, ulint align_no)
#define UT_LIST_GET_LEN(BASE)
#define UT_LIST_REMOVE(NAME, BASE, N)
#define UT_LIST_GET_FIRST(BASE)
#define UT_LIST_GET_LAST(BASE)
#define UT_LIST_ADD_LAST(NAME, BASE, N)
#define UT_LIST_GET_PREV(NAME, N)
#define UT_LIST_ADD_FIRST(NAME, BASE, N)
#define UT_LIST_GET_NEXT(NAME, N)
#define UT_LIST_INIT(BASE)
#define UT_LIST_VALIDATE(NAME, TYPE, BASE, ASSERTION)
UNIV_INTERN void ut_free(void *ptr)
UNIV_INTERN void * ut_malloc(ulint n)
UNIV_INLINE ulint ut_fold_string(const char *str) __attribute__((pure))
UNIV_INLINE ulint ut_min(ulint n1, ulint n2)
UNIV_INTERN void ut_print_timestamp(FILE *file)
UNIV_INTERN void ut_print_filename(FILE *f, const char *name)
#define ut_2pow_round(n, m)