~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/fil/fil0fil.c

  • Committer: lbieber
  • Date: 2010-10-01 12:16:18 UTC
  • mfrom: (1802.1.1 fix-bug-651256)
  • Revision ID: lbieber@orisndriz08-20101001121618-uqcboygpjwbiglem
Merge Vijay - fix bug 651256 - Remove --help-extended

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
13
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
 
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
38
38
#include "mtr0mtr.h"
39
39
#include "mtr0log.h"
40
40
#include "dict0dict.h"
41
 
#include "page0page.h"
42
41
#include "page0zip.h"
43
42
#ifndef UNIV_HOTBACKUP
44
43
# include "buf0lru.h"
121
120
/** The null file address */
122
121
UNIV_INTERN fil_addr_t  fil_addr_null = {FIL_NULL, 0};
123
122
 
124
 
#ifdef UNIV_PFS_MUTEX
125
 
/* Key to register fil_system_mutex with performance schema */
126
 
UNIV_INTERN mysql_pfs_key_t     fil_system_mutex_key;
127
 
#endif /* UNIV_PFS_MUTEX */
128
 
 
129
 
#ifdef UNIV_PFS_RWLOCK
130
 
/* Key to register file space latch with performance schema */
131
 
UNIV_INTERN mysql_pfs_key_t     fil_space_latch_key;
132
 
#endif /* UNIV_PFS_RWLOCK */
133
 
 
134
123
/** File node of a tablespace or the log data space */
135
124
struct fil_node_struct {
136
125
        fil_space_t*    space;  /*!< backpointer to the space where this node
289
278
                                        request */
290
279
        UT_LIST_BASE_NODE_T(fil_space_t) space_list;
291
280
                                        /*!< list of all file spaces */
292
 
        ibool           space_id_reuse_warned;
293
 
                                        /* !< TRUE if fil_space_create()
294
 
                                        has issued a warning about
295
 
                                        potential space_id reuse */
296
281
};
297
282
 
298
283
/** The tablespace memory cache. This variable is NULL before the module is
336
321
/*=======================*/
337
322
        const char*     name);  /*!< in: table name in the standard
338
323
                                'databasename/tablename' format */
339
 
/*******************************************************************//**
340
 
Frees a space object from the tablespace memory cache. Closes the files in
341
 
the chain but does not delete them. There must not be any pending i/o's or
342
 
flushes on the files.
343
 
@return TRUE on success */
344
 
static
345
 
ibool
346
 
fil_space_free(
347
 
/*===========*/
348
 
        ulint           id,             /* in: space id */
349
 
        ibool           x_latched);     /* in: TRUE if caller has space->latch
350
 
                                        in X mode */
351
324
/********************************************************************//**
352
325
Reads data from a space to a buffer. Remember that the possible incomplete
353
326
blocks at the end of file are ignored: they are not taken into account when
581
554
 
582
555
        mutex_enter(&fil_system->mutex);
583
556
 
584
 
        node = static_cast<fil_node_t *>(mem_alloc(sizeof(fil_node_t)));
 
557
        node = mem_alloc(sizeof(fil_node_t));
585
558
 
586
559
        node->name = mem_strdup(name);
587
560
        node->open = FALSE;
621
594
 
622
595
        UT_LIST_ADD_LAST(chain, space->chain, node);
623
596
 
624
 
        if (id < SRV_LOG_SPACE_FIRST_ID && fil_system->max_assigned_id < id) {
625
 
 
626
 
                fil_system->max_assigned_id = id;
627
 
        }
628
 
 
629
597
        mutex_exit(&fil_system->mutex);
630
598
}
631
599
 
645
613
        ulint           size_high;
646
614
        ibool           ret;
647
615
        ibool           success;
 
616
#ifndef UNIV_HOTBACKUP
648
617
        byte*           buf2;
649
618
        byte*           page;
650
619
        ulint           space_id;
651
620
        ulint           flags;
 
621
#endif /* !UNIV_HOTBACKUP */
652
622
 
653
623
        ut_ad(mutex_own(&(system->mutex)));
654
624
        ut_a(node->n_pending == 0);
664
634
                async I/O! */
665
635
 
666
636
                node->handle = os_file_create_simple_no_error_handling(
667
 
                        innodb_file_data_key, node->name, OS_FILE_OPEN,
668
 
                        OS_FILE_READ_ONLY, &success);
 
637
                        node->name, OS_FILE_OPEN, OS_FILE_READ_ONLY, &success);
669
638
                if (!success) {
670
639
                        /* The following call prints an error message */
671
640
                        os_file_get_last_error(TRUE);
685
654
                size_bytes = (((ib_int64_t)size_high) << 32)
686
655
                        + (ib_int64_t)size_low;
687
656
#ifdef UNIV_HOTBACKUP
688
 
                if (space->id == 0) {
689
 
                        node->size = (ulint) (size_bytes / UNIV_PAGE_SIZE);
690
 
                        os_file_close(node->handle);
691
 
                        goto add_size;
692
 
                }
693
 
#endif /* UNIV_HOTBACKUP */
 
657
                node->size = (ulint) (size_bytes / UNIV_PAGE_SIZE);
 
658
                /* TODO: adjust to zip_size, like below? */
 
659
#else
694
660
                ut_a(space->purpose != FIL_LOG);
695
661
                ut_a(space->id != 0);
696
662
 
711
677
 
712
678
                /* Read the first page of the tablespace */
713
679
 
714
 
                buf2 = static_cast<unsigned char *>(ut_malloc(2 * UNIV_PAGE_SIZE));
 
680
                buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
715
681
                /* Align the memory for file i/o if we might have O_DIRECT
716
682
                set */
717
 
                page = static_cast<unsigned char *>(ut_align(buf2, UNIV_PAGE_SIZE));
 
683
                page = ut_align(buf2, UNIV_PAGE_SIZE);
718
684
 
719
685
                success = os_file_read(node->handle, page, 0, 0,
720
686
                                       UNIV_PAGE_SIZE);
769
735
                                (size_bytes
770
736
                                 / dict_table_flags_to_zip_size(flags));
771
737
                }
772
 
 
773
 
#ifdef UNIV_HOTBACKUP
774
 
add_size:
775
 
#endif /* UNIV_HOTBACKUP */
 
738
#endif
776
739
                space->size += node->size;
777
740
        }
778
741
 
783
746
        os_file_create() to fall back to the normal file I/O mode. */
784
747
 
785
748
        if (space->purpose == FIL_LOG) {
786
 
                node->handle = os_file_create(innodb_file_log_key,
787
 
                                              node->name, OS_FILE_OPEN,
788
 
                                              OS_FILE_AIO, OS_LOG_FILE,
789
 
                                              &ret);
 
749
                node->handle = os_file_create(node->name, OS_FILE_OPEN,
 
750
                                              OS_FILE_AIO, OS_LOG_FILE, &ret);
790
751
        } else if (node->is_raw_disk) {
791
 
                node->handle = os_file_create(innodb_file_data_key,
792
 
                                              node->name,
 
752
                node->handle = os_file_create(node->name,
793
753
                                              OS_FILE_OPEN_RAW,
794
 
                                              OS_FILE_AIO, OS_DATA_FILE,
795
 
                                                     &ret);
 
754
                                              OS_FILE_AIO, OS_DATA_FILE, &ret);
796
755
        } else {
797
 
                node->handle = os_file_create(innodb_file_data_key,
798
 
                                              node->name, OS_FILE_OPEN,
799
 
                                              OS_FILE_AIO, OS_DATA_FILE,
800
 
                                              &ret);
 
756
                node->handle = os_file_create(node->name, OS_FILE_OPEN,
 
757
                                              OS_FILE_AIO, OS_DATA_FILE, &ret);
801
758
        }
802
759
 
803
760
        ut_a(ret);
998
955
                        " while the maximum\n"
999
956
                        "InnoDB: allowed value would be %lu.\n"
1000
957
                        "InnoDB: You may need to raise the value of"
1001
 
                        " innodb_open_files in\n"
 
958
                        " innodb_max_files_open in\n"
1002
959
                        "InnoDB: my.cnf.\n",
1003
960
                        (ulong) fil_system->n_open,
1004
961
                        (ulong) fil_system->max_n_open);
1120
1077
        fil_space_t*    space;
1121
1078
 
1122
1079
        /* The tablespace flags (FSP_SPACE_FLAGS) should be 0 for
1123
 
        ROW_FORMAT=COMPACT
1124
 
        ((table->flags & ~(~0 << DICT_TF_BITS)) == DICT_TF_COMPACT) and
 
1080
        ROW_FORMAT=COMPACT (table->flags == DICT_TF_COMPACT) and
1125
1081
        ROW_FORMAT=REDUNDANT (table->flags == 0).  For any other
1126
 
        format, the tablespace flags should equal
1127
 
        (table->flags & ~(~0 << DICT_TF_BITS)). */
 
1082
        format, the tablespace flags should equal table->flags. */
1128
1083
        ut_a(flags != DICT_TF_COMPACT);
1129
 
        ut_a(!(flags & (~0UL << DICT_TF_BITS)));
1130
1084
 
1131
1085
try_again:
1132
1086
        /*printf(
1141
1095
        space = fil_space_get_by_name(name);
1142
1096
 
1143
1097
        if (UNIV_LIKELY_NULL(space)) {
1144
 
                ibool   success;
1145
1098
                ulint   namesake_id;
1146
1099
 
1147
1100
                ut_print_timestamp(stderr);
1180
1133
 
1181
1134
                namesake_id = space->id;
1182
1135
 
1183
 
                success = fil_space_free(namesake_id, FALSE);
1184
 
                ut_a(success);
1185
 
 
1186
1136
                mutex_exit(&fil_system->mutex);
1187
1137
 
 
1138
                fil_space_free(namesake_id);
 
1139
 
1188
1140
                goto try_again;
1189
1141
        }
1190
1142
 
1208
1160
                return(FALSE);
1209
1161
        }
1210
1162
 
1211
 
        space = static_cast<fil_space_t *>(mem_alloc(sizeof(fil_space_t)));
 
1163
        space = mem_alloc(sizeof(fil_space_t));
1212
1164
 
1213
1165
        space->name = mem_strdup(name);
1214
1166
        space->id = id;
1217
1169
        space->tablespace_version = fil_system->tablespace_version;
1218
1170
        space->mark = FALSE;
1219
1171
 
1220
 
        if (UNIV_LIKELY(purpose == FIL_TABLESPACE && !recv_recovery_on)
1221
 
            && UNIV_UNLIKELY(id > fil_system->max_assigned_id)) {
1222
 
                if (!fil_system->space_id_reuse_warned) {
1223
 
                        fil_system->space_id_reuse_warned = TRUE;
1224
 
 
1225
 
                        ut_print_timestamp(stderr);
1226
 
                        fprintf(stderr,
1227
 
                                "  InnoDB: Warning: allocated tablespace %lu,"
1228
 
                                " old maximum was %lu\n",
1229
 
                                (ulong) id,
1230
 
                                (ulong) fil_system->max_assigned_id);
1231
 
                }
1232
 
 
 
1172
        if (purpose == FIL_TABLESPACE && id > fil_system->max_assigned_id) {
1233
1173
                fil_system->max_assigned_id = id;
1234
1174
        }
1235
1175
 
1248
1188
        UT_LIST_INIT(space->chain);
1249
1189
        space->magic_n = FIL_SPACE_MAGIC_N;
1250
1190
 
1251
 
        rw_lock_create(fil_space_latch_key, &space->latch, SYNC_FSP);
 
1191
        rw_lock_create(&space->latch, SYNC_FSP);
1252
1192
 
1253
1193
        HASH_INSERT(fil_space_t, hash, fil_system->spaces, id, space);
1254
1194
 
1267
1207
Assigns a new space id for a new single-table tablespace. This works simply by
1268
1208
incrementing the global counter. If 4 billion id's is not enough, we may need
1269
1209
to recycle id's.
1270
 
@return TRUE if assigned, FALSE if not */
1271
 
UNIV_INTERN
1272
 
ibool
1273
 
fil_assign_new_space_id(
1274
 
/*====================*/
1275
 
        ulint*  space_id)       /*!< in/out: space id */
 
1210
@return new tablespace id; ULINT_UNDEFINED if could not assign an id */
 
1211
static
 
1212
ulint
 
1213
fil_assign_new_space_id(void)
 
1214
/*=========================*/
1276
1215
{
1277
 
        ulint   id;
1278
 
        ibool   success;
 
1216
        ulint           id;
1279
1217
 
1280
1218
        mutex_enter(&fil_system->mutex);
1281
1219
 
1282
 
        id = *space_id;
1283
 
 
1284
 
        if (id < fil_system->max_assigned_id) {
1285
 
                id = fil_system->max_assigned_id;
1286
 
        }
1287
 
 
1288
 
        id++;
 
1220
        fil_system->max_assigned_id++;
 
1221
 
 
1222
        id = fil_system->max_assigned_id;
1289
1223
 
1290
1224
        if (id > (SRV_LOG_SPACE_FIRST_ID / 2) && (id % 1000000UL == 0)) {
1291
1225
                ut_print_timestamp(stderr);
1301
1235
                        (ulong) SRV_LOG_SPACE_FIRST_ID);
1302
1236
        }
1303
1237
 
1304
 
        success = (id < SRV_LOG_SPACE_FIRST_ID);
1305
 
 
1306
 
        if (success) {
1307
 
                *space_id = fil_system->max_assigned_id = id;
1308
 
        } else {
 
1238
        if (id >= SRV_LOG_SPACE_FIRST_ID) {
1309
1239
                ut_print_timestamp(stderr);
1310
1240
                fprintf(stderr,
1311
1241
                        "InnoDB: You have run out of single-table"
1315
1245
                        " have to dump all your tables and\n"
1316
1246
                        "InnoDB: recreate the whole InnoDB installation.\n",
1317
1247
                        (ulong) id);
1318
 
                *space_id = ULINT_UNDEFINED;
 
1248
                fil_system->max_assigned_id--;
 
1249
 
 
1250
                id = ULINT_UNDEFINED;
1319
1251
        }
1320
1252
 
1321
1253
        mutex_exit(&fil_system->mutex);
1322
1254
 
1323
 
        return(success);
 
1255
        return(id);
1324
1256
}
1325
1257
 
1326
1258
/*******************************************************************//**
1328
1260
the chain but does not delete them. There must not be any pending i/o's or
1329
1261
flushes on the files.
1330
1262
@return TRUE if success */
1331
 
static
 
1263
UNIV_INTERN
1332
1264
ibool
1333
1265
fil_space_free(
1334
1266
/*===========*/
1335
 
                                        /* out: TRUE if success */
1336
 
        ulint           id,             /* in: space id */
1337
 
        ibool           x_latched)      /* in: TRUE if caller has space->latch
1338
 
                                        in X mode */
 
1267
        ulint   id)     /*!< in: space id */
1339
1268
{
1340
1269
        fil_space_t*    space;
1341
 
        fil_space_t*    tablespace;
 
1270
        fil_space_t*    namespace;
1342
1271
        fil_node_t*     fil_node;
1343
1272
 
1344
 
        ut_ad(mutex_own(&fil_system->mutex));
 
1273
        mutex_enter(&fil_system->mutex);
1345
1274
 
1346
1275
        space = fil_space_get_by_id(id);
1347
1276
 
1352
1281
                        " from the cache but\n"
1353
1282
                        "InnoDB: it is not there.\n", (ulong) id);
1354
1283
 
 
1284
                mutex_exit(&fil_system->mutex);
 
1285
 
1355
1286
                return(FALSE);
1356
1287
        }
1357
1288
 
1358
1289
        HASH_DELETE(fil_space_t, hash, fil_system->spaces, id, space);
1359
1290
 
1360
 
        tablespace = fil_space_get_by_name(space->name);
1361
 
        ut_a(tablespace);
1362
 
        ut_a(space == tablespace);
 
1291
        namespace = fil_space_get_by_name(space->name);
 
1292
        ut_a(namespace);
 
1293
        ut_a(space == namespace);
1363
1294
 
1364
1295
        HASH_DELETE(fil_space_t, name_hash, fil_system->name_hash,
1365
1296
                    ut_fold_string(space->name), space);
1386
1317
 
1387
1318
        ut_a(0 == UT_LIST_GET_LEN(space->chain));
1388
1319
 
1389
 
        if (x_latched) {
1390
 
                rw_lock_x_unlock(&space->latch);
1391
 
        }
 
1320
        mutex_exit(&fil_system->mutex);
1392
1321
 
1393
1322
        rw_lock_free(&(space->latch));
1394
1323
 
1553
1482
        ut_a(hash_size > 0);
1554
1483
        ut_a(max_n_open > 0);
1555
1484
 
1556
 
        void *fil_system_ptr= mem_zalloc(sizeof(fil_system_t));
1557
 
        fil_system = static_cast<fil_system_t *>(fil_system_ptr);
 
1485
        fil_system = mem_alloc(sizeof(fil_system_t));
1558
1486
 
1559
 
        mutex_create(fil_system_mutex_key,
1560
 
                     &fil_system->mutex, SYNC_ANY_LATCH);
 
1487
        mutex_create(&fil_system->mutex, SYNC_ANY_LATCH);
1561
1488
 
1562
1489
        fil_system->spaces = hash_create(hash_size);
1563
1490
        fil_system->name_hash = hash_create(hash_size);
1564
1491
 
1565
1492
        UT_LIST_INIT(fil_system->LRU);
1566
1493
 
 
1494
        fil_system->n_open = 0;
1567
1495
        fil_system->max_n_open = max_n_open;
 
1496
 
 
1497
        fil_system->modification_counter = 0;
 
1498
        fil_system->max_assigned_id = 0;
 
1499
 
 
1500
        fil_system->tablespace_version = 0;
 
1501
 
 
1502
        UT_LIST_INIT(fil_system->unflushed_spaces);
 
1503
        UT_LIST_INIT(fil_system->space_list);
1568
1504
}
1569
1505
 
1570
1506
/*******************************************************************//**
1599
1535
                                        fprintf(stderr,
1600
1536
                                                "InnoDB: Warning: you must"
1601
1537
                                                " raise the value of"
1602
 
                                                " innodb_open_files in\n"
 
1538
                                                " innodb_max_open_files in\n"
1603
1539
                                                "InnoDB: my.cnf! Remember that"
1604
1540
                                                " InnoDB keeps all log files"
1605
1541
                                                " and all system\n"
1634
1570
/*=====================*/
1635
1571
{
1636
1572
        fil_space_t*    space;
 
1573
        fil_node_t*     node;
1637
1574
 
1638
1575
        mutex_enter(&fil_system->mutex);
1639
1576
 
1640
1577
        space = UT_LIST_GET_FIRST(fil_system->space_list);
1641
1578
 
1642
1579
        while (space != NULL) {
1643
 
                fil_node_t*     node;
1644
 
                fil_space_t*    prev_space = space;
1645
 
 
1646
 
                for (node = UT_LIST_GET_FIRST(space->chain);
1647
 
                     node != NULL;
1648
 
                     node = UT_LIST_GET_NEXT(chain, node)) {
1649
 
 
 
1580
                node = UT_LIST_GET_FIRST(space->chain);
 
1581
 
 
1582
                while (node != NULL) {
1650
1583
                        if (node->open) {
1651
1584
                                fil_node_close_file(node, fil_system);
1652
1585
                        }
 
1586
                        node = UT_LIST_GET_NEXT(chain, node);
1653
1587
                }
1654
 
 
1655
1588
                space = UT_LIST_GET_NEXT(space_list, space);
1656
 
 
1657
 
                fil_space_free(prev_space->id, FALSE);
1658
1589
        }
1659
1590
 
1660
1591
        mutex_exit(&fil_system->mutex);
1697
1628
        ulint           sum_of_sizes,   /*!< in: combined size of previous files
1698
1629
                                        in space, in database pages */
1699
1630
        ib_uint64_t     lsn,            /*!< in: lsn to write */
1700
 
        ulint           /*arch_log_no __attribute__((unused))*/)
 
1631
        ulint           arch_log_no __attribute__((unused)))
1701
1632
                                        /*!< in: archived log number to write */
1702
1633
{
1703
1634
        byte*   buf1;
1704
1635
        byte*   buf;
1705
1636
 
1706
 
        buf1 = static_cast<byte *>(mem_alloc(2 * UNIV_PAGE_SIZE));
1707
 
        buf = static_cast<byte *>(ut_align(buf1, UNIV_PAGE_SIZE));
 
1637
        buf1 = mem_alloc(2 * UNIV_PAGE_SIZE);
 
1638
        buf = ut_align(buf1, UNIV_PAGE_SIZE);
1708
1639
 
1709
1640
        fil_read(TRUE, 0, 0, sum_of_sizes, 0, UNIV_PAGE_SIZE, buf, NULL);
1710
1641
 
1711
 
        mach_write_to_8(buf + FIL_PAGE_FILE_FLUSH_LSN, lsn);
 
1642
        mach_write_ull(buf + FIL_PAGE_FILE_FLUSH_LSN, lsn);
1712
1643
 
1713
1644
        fil_write(TRUE, 0, 0, sum_of_sizes, 0, UNIV_PAGE_SIZE, buf, NULL);
1714
1645
 
1796
1727
        byte*           buf2;
1797
1728
        ib_uint64_t     flushed_lsn;
1798
1729
 
1799
 
        buf2 = static_cast<byte *>(ut_malloc(2 * UNIV_PAGE_SIZE));
 
1730
        buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
1800
1731
        /* Align the memory for a possible read from a raw device */
1801
 
        buf = static_cast<byte *>(ut_align(buf2, UNIV_PAGE_SIZE));
 
1732
        buf = ut_align(buf2, UNIV_PAGE_SIZE);
1802
1733
 
1803
1734
        os_file_read(data_file, buf, 0, 0, UNIV_PAGE_SIZE);
1804
1735
 
1805
 
        flushed_lsn = mach_read_from_8(buf + FIL_PAGE_FILE_FLUSH_LSN);
 
1736
        flushed_lsn = mach_read_ull(buf + FIL_PAGE_FILE_FLUSH_LSN);
1806
1737
 
1807
1738
        ut_free(buf2);
1808
1739
 
1916
1847
        len = strlen(fil_path_to_mysql_datadir);
1917
1848
        namend = strchr(name, '/');
1918
1849
        ut_a(namend);
1919
 
        path = static_cast<char *>(mem_alloc(len + (namend - name) + 2));
 
1850
        path = mem_alloc(len + (namend - name) + 2);
1920
1851
 
1921
1852
        memcpy(path, fil_path_to_mysql_datadir, len);
1922
1853
        path[len] = '/';
2151
2082
                        fil_create_directory_for_tablename(name);
2152
2083
 
2153
2084
                        if (fil_create_new_single_table_tablespace(
2154
 
                                    space_id, name, FALSE, flags,
 
2085
                                    &space_id, name, FALSE, flags,
2155
2086
                                    FIL_IBD_FILE_INITIAL_SIZE) != DB_SUCCESS) {
2156
2087
                                ut_error;
2157
2088
                        }
2274
2205
        path = mem_strdup(space->name);
2275
2206
 
2276
2207
        mutex_exit(&fil_system->mutex);
2277
 
 
2278
 
        /* Important: We rely on the data dictionary mutex to ensure
2279
 
        that a race is not possible here. It should serialize the tablespace
2280
 
        drop/free. We acquire an X latch only to avoid a race condition
2281
 
        when accessing the tablespace instance via:
2282
 
 
2283
 
          fsp_get_available_space_in_free_extents().
2284
 
 
2285
 
        There our main motivation is to reduce the contention on the
2286
 
        dictionary mutex. */
2287
 
 
2288
 
        rw_lock_x_lock(&space->latch);
2289
 
 
2290
2208
#ifndef UNIV_HOTBACKUP
2291
2209
        /* Invalidate in the buffer pool all pages belonging to the
2292
2210
        tablespace. Since we have set space->is_being_deleted = TRUE, readahead
2299
2217
#endif
2300
2218
        /* printf("Deleting tablespace %s id %lu\n", space->name, id); */
2301
2219
 
2302
 
        mutex_enter(&fil_system->mutex);
2303
 
 
2304
 
        success = fil_space_free(id, TRUE);
2305
 
 
2306
 
        mutex_exit(&fil_system->mutex);
 
2220
        success = fil_space_free(id);
2307
2221
 
2308
2222
        if (success) {
2309
2223
                success = os_file_delete(path);
2311
2225
                if (!success) {
2312
2226
                        success = os_file_delete_if_exists(path);
2313
2227
                }
2314
 
        } else {
2315
 
                rw_lock_x_unlock(&space->latch);
2316
2228
        }
2317
2229
 
2318
2230
        if (success) {
2340
2252
        return(FALSE);
2341
2253
}
2342
2254
 
2343
 
/*******************************************************************//**
2344
 
Returns TRUE if a single-table tablespace is being deleted.
2345
 
@return TRUE if being deleted */
2346
 
UNIV_INTERN
2347
 
ibool
2348
 
fil_tablespace_is_being_deleted(
2349
 
/*============================*/
2350
 
        ulint           id)     /*!< in: space id */
2351
 
{
2352
 
        fil_space_t*    space;
2353
 
        ibool           is_being_deleted;
2354
 
 
2355
 
        mutex_enter(&fil_system->mutex);
2356
 
 
2357
 
        space = fil_space_get_by_id(id);
2358
 
 
2359
 
        ut_a(space != NULL);
2360
 
 
2361
 
        is_being_deleted = space->is_being_deleted;
2362
 
 
2363
 
        mutex_exit(&fil_system->mutex);
2364
 
 
2365
 
        return(is_being_deleted);
2366
 
}
2367
 
 
2368
2255
#ifndef UNIV_HOTBACKUP
2369
2256
/*******************************************************************//**
2370
2257
Discards a single-table tablespace. The tablespace must be cached in the
2463
2350
{
2464
2351
        ulint   namelen         = strlen(name);
2465
2352
        ulint   dirlen          = strlen(fil_path_to_mysql_datadir);
2466
 
        char*   filename        = static_cast<char *>(mem_alloc(namelen + dirlen + sizeof "/.ibd"));
 
2353
        char*   filename        = mem_alloc(namelen + dirlen + sizeof "/.ibd");
2467
2354
 
2468
2355
        if (is_temp) {
2469
2356
                memcpy(filename, name, namelen);
2599
2486
        success = fil_rename_tablespace_in_mem(space, node, path);
2600
2487
 
2601
2488
        if (success) {
2602
 
                success = os_file_rename(innodb_file_data_key, old_path, path);
 
2489
                success = os_file_rename(old_path, path);
2603
2490
 
2604
2491
                if (!success) {
2605
2492
                        /* We have to revert the changes we made
2642
2529
ulint
2643
2530
fil_create_new_single_table_tablespace(
2644
2531
/*===================================*/
2645
 
        ulint           space_id,       /*!< in: space id */
 
2532
        ulint*          space_id,       /*!< in/out: space id; if this is != 0,
 
2533
                                        then this is an input parameter,
 
2534
                                        otherwise output */
2646
2535
        const char*     tablename,      /*!< in: the table name in the usual
2647
2536
                                        databasename/tablename format
2648
2537
                                        of InnoDB, or a dir path to a temp
2662
2551
        ibool           success;
2663
2552
        char*           path;
2664
2553
 
2665
 
        ut_a(space_id > 0);
2666
 
        ut_a(space_id < SRV_LOG_SPACE_FIRST_ID);
2667
2554
        ut_a(size >= FIL_IBD_FILE_INITIAL_SIZE);
2668
2555
        /* The tablespace flags (FSP_SPACE_FLAGS) should be 0 for
2669
 
        ROW_FORMAT=COMPACT
2670
 
        ((table->flags & ~(~0 << DICT_TF_BITS)) == DICT_TF_COMPACT) and
 
2556
        ROW_FORMAT=COMPACT (table->flags == DICT_TF_COMPACT) and
2671
2557
        ROW_FORMAT=REDUNDANT (table->flags == 0).  For any other
2672
 
        format, the tablespace flags should equal
2673
 
        (table->flags & ~(~0 << DICT_TF_BITS)). */
 
2558
        format, the tablespace flags should equal table->flags. */
2674
2559
        ut_a(flags != DICT_TF_COMPACT);
2675
 
        ut_a(!(flags & (~0UL << DICT_TF_BITS)));
2676
2560
 
2677
2561
        path = fil_make_ibd_name(tablename, is_temp);
2678
2562
 
2679
 
        file = os_file_create(innodb_file_data_key, path,
2680
 
                              OS_FILE_CREATE, OS_FILE_NORMAL,
 
2563
        file = os_file_create(path, OS_FILE_CREATE, OS_FILE_NORMAL,
2681
2564
                              OS_DATA_FILE, &ret);
2682
2565
        if (ret == FALSE) {
2683
2566
                ut_print_timestamp(stderr);
2721
2604
                return(DB_ERROR);
2722
2605
        }
2723
2606
 
 
2607
        buf2 = ut_malloc(3 * UNIV_PAGE_SIZE);
 
2608
        /* Align the memory for file i/o if we might have O_DIRECT set */
 
2609
        page = ut_align(buf2, UNIV_PAGE_SIZE);
 
2610
 
2724
2611
        ret = os_file_set_size(path, file, size * UNIV_PAGE_SIZE, 0);
2725
2612
 
2726
2613
        if (!ret) {
2727
 
                err = DB_OUT_OF_FILE_SPACE;
 
2614
                ut_free(buf2);
 
2615
                os_file_close(file);
 
2616
                os_file_delete(path);
 
2617
 
 
2618
                mem_free(path);
 
2619
                return(DB_OUT_OF_FILE_SPACE);
 
2620
        }
 
2621
 
 
2622
        if (*space_id == 0) {
 
2623
                *space_id = fil_assign_new_space_id();
 
2624
        }
 
2625
 
 
2626
        /* printf("Creating tablespace %s id %lu\n", path, *space_id); */
 
2627
 
 
2628
        if (*space_id == ULINT_UNDEFINED) {
 
2629
                ut_free(buf2);
2728
2630
error_exit:
2729
2631
                os_file_close(file);
2730
2632
error_exit2:
2731
2633
                os_file_delete(path);
2732
2634
 
2733
2635
                mem_free(path);
2734
 
                return(err);
 
2636
                return(DB_ERROR);
2735
2637
        }
2736
2638
 
2737
 
        /* printf("Creating tablespace %s id %lu\n", path, space_id); */
2738
 
 
2739
2639
        /* We have to write the space id to the file immediately and flush the
2740
2640
        file to disk. This is because in crash recovery we must be aware what
2741
2641
        tablespaces exist and what are their space id's, so that we can apply
2745
2645
        with zeros from the call of os_file_set_size(), until a buffer pool
2746
2646
        flush would write to it. */
2747
2647
 
2748
 
        buf2 = static_cast<byte *>(ut_malloc(3 * UNIV_PAGE_SIZE));
2749
 
        /* Align the memory for file i/o if we might have O_DIRECT set */
2750
 
        page = static_cast<byte *>(ut_align(buf2, UNIV_PAGE_SIZE));
2751
 
 
2752
2648
        memset(page, '\0', UNIV_PAGE_SIZE);
2753
2649
 
2754
 
        fsp_header_init_fields(page, space_id, flags);
2755
 
        mach_write_to_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, space_id);
 
2650
        fsp_header_init_fields(page, *space_id, flags);
 
2651
        mach_write_to_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, *space_id);
2756
2652
 
2757
2653
        if (!(flags & DICT_TF_ZSSIZE_MASK)) {
2758
2654
                buf_flush_init_for_writing(page, NULL, 0);
2783
2679
                      " to tablespace ", stderr);
2784
2680
                ut_print_filename(stderr, path);
2785
2681
                putc('\n', stderr);
2786
 
                err = DB_ERROR;
2787
2682
                goto error_exit;
2788
2683
        }
2789
2684
 
2793
2688
                fputs("InnoDB: Error: file flush of tablespace ", stderr);
2794
2689
                ut_print_filename(stderr, path);
2795
2690
                fputs(" failed\n", stderr);
2796
 
                err = DB_ERROR;
2797
2691
                goto error_exit;
2798
2692
        }
2799
2693
 
2800
2694
        os_file_close(file);
2801
2695
 
2802
 
        success = fil_space_create(path, space_id, flags, FIL_TABLESPACE);
 
2696
        if (*space_id == ULINT_UNDEFINED) {
 
2697
                goto error_exit2;
 
2698
        }
 
2699
 
 
2700
        success = fil_space_create(path, *space_id, flags, FIL_TABLESPACE);
2803
2701
 
2804
2702
        if (!success) {
2805
 
                err = DB_ERROR;
2806
2703
                goto error_exit2;
2807
2704
        }
2808
2705
 
2809
 
        fil_node_create(path, size, space_id, FALSE);
 
2706
        fil_node_create(path, size, *space_id, FALSE);
2810
2707
 
2811
2708
#ifndef UNIV_HOTBACKUP
2812
2709
        {
2817
2714
                fil_op_write_log(flags
2818
2715
                                 ? MLOG_FILE_CREATE2
2819
2716
                                 : MLOG_FILE_CREATE,
2820
 
                                 space_id,
 
2717
                                 *space_id,
2821
2718
                                 is_temp ? MLOG_FILE_FLAG_TEMP : 0,
2822
2719
                                 flags,
2823
2720
                                 tablename, NULL, &mtr);
2860
2757
        ib_int64_t      offset;
2861
2758
        ulint           zip_size;
2862
2759
        ibool           success;
2863
 
        page_zip_des_t  page_zip;
2864
2760
 
2865
2761
        filepath = fil_make_ibd_name(name, FALSE);
2866
2762
 
2867
2763
        file = os_file_create_simple_no_error_handling(
2868
 
                innodb_file_data_key, filepath, OS_FILE_OPEN,
2869
 
                OS_FILE_READ_WRITE, &success);
 
2764
                filepath, OS_FILE_OPEN, OS_FILE_READ_WRITE, &success);
2870
2765
        if (!success) {
2871
2766
                /* The following call prints an error message */
2872
2767
                os_file_get_last_error(TRUE);
2885
2780
 
2886
2781
        /* Read the first page of the tablespace */
2887
2782
 
2888
 
        buf2 = static_cast<byte *>(ut_malloc(3 * UNIV_PAGE_SIZE));
 
2783
        buf2 = ut_malloc(3 * UNIV_PAGE_SIZE);
2889
2784
        /* Align the memory for file i/o if we might have O_DIRECT set */
2890
 
        page = static_cast<byte *>(ut_align(buf2, UNIV_PAGE_SIZE));
 
2785
        page = ut_align(buf2, UNIV_PAGE_SIZE);
2891
2786
 
2892
2787
        success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
2893
2788
        if (!success) {
2897
2792
 
2898
2793
        /* We have to read the file flush lsn from the header of the file */
2899
2794
 
2900
 
        flush_lsn = mach_read_from_8(page + FIL_PAGE_FILE_FLUSH_LSN);
 
2795
        flush_lsn = mach_read_ull(page + FIL_PAGE_FILE_FLUSH_LSN);
2901
2796
 
2902
2797
        if (current_lsn >= flush_lsn) {
2903
2798
                /* Ok */
2909
2804
        space_id = fsp_header_get_space_id(page);
2910
2805
        zip_size = fsp_header_get_zip_size(page);
2911
2806
 
2912
 
        page_zip_des_init(&page_zip);
2913
 
        page_zip_set_size(&page_zip, zip_size);
2914
 
        if (zip_size) {
2915
 
                page_zip.data = page + UNIV_PAGE_SIZE;
2916
 
        }
2917
 
 
2918
2807
        ut_print_timestamp(stderr);
2919
2808
        fprintf(stderr,
2920
2809
                "  InnoDB: Flush lsn in the tablespace file %lu"
2945
2834
 
2946
2835
                        goto func_exit;
2947
2836
                }
2948
 
                if (mach_read_from_8(page + FIL_PAGE_LSN) > current_lsn) {
 
2837
                if (mach_read_ull(page + FIL_PAGE_LSN) > current_lsn) {
2949
2838
                        /* We have to reset the lsn */
2950
2839
 
2951
2840
                        if (zip_size) {
2952
 
                                memcpy(page_zip.data, page, zip_size);
 
2841
                                memcpy(page + UNIV_PAGE_SIZE, page, zip_size);
2953
2842
                                buf_flush_init_for_writing(
2954
 
                                        page, &page_zip, current_lsn);
2955
 
                                success = os_file_write(
2956
 
                                        filepath, file, page_zip.data,
2957
 
                                        (ulint) offset & 0xFFFFFFFFUL,
2958
 
                                        (ulint) (offset >> 32), zip_size);
 
2843
                                        page, page + UNIV_PAGE_SIZE,
 
2844
                                        current_lsn);
2959
2845
                        } else {
2960
2846
                                buf_flush_init_for_writing(
2961
2847
                                        page, NULL, current_lsn);
2962
 
                                success = os_file_write(
2963
 
                                        filepath, file, page,
2964
 
                                        (ulint)(offset & 0xFFFFFFFFUL),
2965
 
                                        (ulint)(offset >> 32),
2966
 
                                        UNIV_PAGE_SIZE);
2967
2848
                        }
2968
 
 
 
2849
                        success = os_file_write(filepath, file, page,
 
2850
                                                (ulint)(offset & 0xFFFFFFFFUL),
 
2851
                                                (ulint)(offset >> 32),
 
2852
                                                zip_size
 
2853
                                                ? zip_size
 
2854
                                                : UNIV_PAGE_SIZE);
2969
2855
                        if (!success) {
2970
2856
 
2971
2857
                                goto func_exit;
2987
2873
                goto func_exit;
2988
2874
        }
2989
2875
 
2990
 
        mach_write_to_8(page + FIL_PAGE_FILE_FLUSH_LSN, current_lsn);
 
2876
        mach_write_ull(page + FIL_PAGE_FILE_FLUSH_LSN, current_lsn);
2991
2877
 
2992
2878
        success = os_file_write(filepath, file, page, 0, 0,
2993
2879
                                zip_size ? zip_size : UNIV_PAGE_SIZE);
3037
2923
        byte*           page;
3038
2924
        ulint           space_id;
3039
2925
        ulint           space_flags;
 
2926
        ibool           ret             = TRUE;
3040
2927
 
3041
2928
        filepath = fil_make_ibd_name(name, FALSE);
3042
2929
 
3043
2930
        /* The tablespace flags (FSP_SPACE_FLAGS) should be 0 for
3044
 
        ROW_FORMAT=COMPACT
3045
 
        ((table->flags & ~(~0 << DICT_TF_BITS)) == DICT_TF_COMPACT) and
 
2931
        ROW_FORMAT=COMPACT (table->flags == DICT_TF_COMPACT) and
3046
2932
        ROW_FORMAT=REDUNDANT (table->flags == 0).  For any other
3047
 
        format, the tablespace flags should equal
3048
 
        (table->flags & ~(~0 << DICT_TF_BITS)). */
 
2933
        format, the tablespace flags should equal table->flags. */
3049
2934
        ut_a(flags != DICT_TF_COMPACT);
3050
 
        ut_a(!(flags & (~0UL << DICT_TF_BITS)));
3051
2935
 
3052
2936
        file = os_file_create_simple_no_error_handling(
3053
 
                innodb_file_data_key, filepath, OS_FILE_OPEN,
3054
 
                OS_FILE_READ_ONLY, &success);
 
2937
                filepath, OS_FILE_OPEN, OS_FILE_READ_ONLY, &success);
3055
2938
        if (!success) {
3056
2939
                /* The following call prints an error message */
3057
2940
                os_file_get_last_error(TRUE);
3087
2970
 
3088
2971
        /* Read the first page of the tablespace */
3089
2972
 
3090
 
        buf2 = static_cast<byte *>(ut_malloc(2 * UNIV_PAGE_SIZE));
 
2973
        buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
3091
2974
        /* Align the memory for file i/o if we might have O_DIRECT set */
3092
 
        page = static_cast<byte *>(ut_align(buf2, UNIV_PAGE_SIZE));
 
2975
        page = ut_align(buf2, UNIV_PAGE_SIZE);
3093
2976
 
3094
2977
        success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
3095
2978
 
3100
2983
 
3101
2984
        ut_free(buf2);
3102
2985
 
3103
 
        if (UNIV_UNLIKELY(space_id != id
3104
 
                          || space_flags != (flags & ~(~0 << DICT_TF_BITS)))) {
 
2986
        if (UNIV_UNLIKELY(space_id != id || space_flags != flags)) {
3105
2987
                ut_print_timestamp(stderr);
3106
2988
 
3107
2989
                fputs("  InnoDB: Error: tablespace id and flags in file ",
3119
3001
                        (ulong) space_id, (ulong) space_flags,
3120
3002
                        (ulong) id, (ulong) flags);
3121
3003
 
3122
 
                success = FALSE;
 
3004
                ret = FALSE;
3123
3005
 
3124
3006
                goto func_exit;
3125
3007
        }
3139
3021
        os_file_close(file);
3140
3022
        mem_free(filepath);
3141
3023
 
3142
 
        return(success);
 
3024
        return(ret);
3143
3025
}
3144
3026
#endif /* !UNIV_HOTBACKUP */
3145
3027
 
3189
3071
#ifdef UNIV_HOTBACKUP
3190
3072
        fil_space_t*    space;
3191
3073
#endif
3192
 
        filepath = static_cast<char *>(mem_alloc(strlen(dbname) + strlen(filename)
3193
 
                             + strlen(fil_path_to_mysql_datadir) + 3));
 
3074
        filepath = mem_alloc(strlen(dbname) + strlen(filename)
 
3075
                             + strlen(fil_path_to_mysql_datadir) + 3);
3194
3076
 
3195
3077
        sprintf(filepath, "%s/%s/%s", fil_path_to_mysql_datadir, dbname,
3196
3078
                filename);
3207
3089
# endif /* !UNIV_HOTBACKUP */
3208
3090
#endif
3209
3091
        file = os_file_create_simple_no_error_handling(
3210
 
                innodb_file_data_key, filepath, OS_FILE_OPEN,
3211
 
                OS_FILE_READ_ONLY, &success);
 
3092
                filepath, OS_FILE_OPEN, OS_FILE_READ_ONLY, &success);
3212
3093
        if (!success) {
3213
3094
                /* The following call prints an error message */
3214
3095
                os_file_get_last_error(TRUE);
3324
3205
#endif
3325
3206
        /* Read the first page of the tablespace if the size big enough */
3326
3207
 
3327
 
        buf2 = static_cast<byte *>(ut_malloc(2 * UNIV_PAGE_SIZE));
 
3208
        buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
3328
3209
        /* Align the memory for file i/o if we might have O_DIRECT set */
3329
 
        page = static_cast<byte *>(ut_align(buf2, UNIV_PAGE_SIZE));
 
3210
        page = ut_align(buf2, UNIV_PAGE_SIZE);
3330
3211
 
3331
3212
        if (size >= FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE) {
3332
3213
                success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
3356
3237
                fprintf(stderr,
3357
3238
                        "InnoDB: Renaming tablespace %s of id %lu,\n"
3358
3239
                        "InnoDB: to %s_ibbackup_old_vers_<timestamp>\n"
3359
 
                        "InnoDB: because its size %" PRId64 " is too small"
 
3240
                        "InnoDB: because its size %lld is too small"
3360
3241
                        " (< 4 pages 16 kB each),\n"
3361
3242
                        "InnoDB: or the space id in the file header"
3362
3243
                        " is not sensible.\n"
3366
3247
                os_file_close(file);
3367
3248
 
3368
3249
                new_path = fil_make_ibbackup_old_name(filepath);
3369
 
                ut_a(os_file_rename(innodb_file_data_key, filepath, new_path));
 
3250
                ut_a(os_file_rename(filepath, new_path));
3370
3251
 
3371
3252
                ut_free(buf2);
3372
3253
                mem_free(filepath);
3404
3285
 
3405
3286
                mutex_exit(&fil_system->mutex);
3406
3287
 
3407
 
                ut_a(os_file_rename(innodb_file_data_key, filepath, new_path));
 
3288
                ut_a(os_file_rename(filepath, new_path));
3408
3289
 
3409
3290
                ut_free(buf2);
3410
3291
                mem_free(filepath);
3418
3299
 
3419
3300
        if (!success) {
3420
3301
 
3421
 
                if (srv_force_recovery > 0) {
3422
 
                        fprintf(stderr,
3423
 
                                "InnoDB: innodb_force_recovery"
3424
 
                                " was set to %lu. Continuing crash recovery\n"
3425
 
                                "InnoDB: even though the tablespace creation"
3426
 
                                " of this table failed.\n",
3427
 
                                srv_force_recovery);
3428
 
                        goto func_exit;
3429
 
                }
3430
 
 
3431
 
                exit(1);
 
3302
                goto func_exit;
3432
3303
        }
3433
3304
 
3434
3305
        /* We do not use the size information we have about the file, because
3513
3384
                return(DB_ERROR);
3514
3385
        }
3515
3386
 
3516
 
        dbpath = static_cast<char *>(mem_alloc(dbpath_len));
 
3387
        dbpath = mem_alloc(dbpath_len);
3517
3388
 
3518
3389
        /* Scan all directories under the datadir. They are the database
3519
3390
        directories of MySQL. */
3542
3413
                                mem_free(dbpath);
3543
3414
                        }
3544
3415
 
3545
 
                        dbpath = static_cast<char *>(mem_alloc(dbpath_len));
 
3416
                        dbpath = mem_alloc(dbpath_len);
3546
3417
                }
3547
3418
                sprintf(dbpath, "%s/%s", fil_path_to_mysql_datadir,
3548
3419
                        dbinfo.name);
3611
3482
        return(err);
3612
3483
}
3613
3484
 
 
3485
/********************************************************************//**
 
3486
If we need crash recovery, and we have called
 
3487
fil_load_single_table_tablespaces() and dict_load_single_table_tablespaces(),
 
3488
we can call this function to print an error message of orphaned .ibd files
 
3489
for which there is not a data dictionary entry with a matching table name
 
3490
and space id. */
 
3491
UNIV_INTERN
 
3492
void
 
3493
fil_print_orphaned_tablespaces(void)
 
3494
/*================================*/
 
3495
{
 
3496
        fil_space_t*    space;
 
3497
 
 
3498
        mutex_enter(&fil_system->mutex);
 
3499
 
 
3500
        space = UT_LIST_GET_FIRST(fil_system->space_list);
 
3501
 
 
3502
        while (space) {
 
3503
                if (space->purpose == FIL_TABLESPACE && space->id != 0
 
3504
                    && !space->mark) {
 
3505
                        fputs("InnoDB: Warning: tablespace ", stderr);
 
3506
                        ut_print_filename(stderr, space->name);
 
3507
                        fprintf(stderr, " of id %lu has no matching table in\n"
 
3508
                                "InnoDB: the InnoDB data dictionary.\n",
 
3509
                                (ulong) space->id);
 
3510
                }
 
3511
 
 
3512
                space = UT_LIST_GET_NEXT(space_list, space);
 
3513
        }
 
3514
 
 
3515
        mutex_exit(&fil_system->mutex);
 
3516
}
 
3517
 
3614
3518
/*******************************************************************//**
3615
3519
Returns TRUE if a single-table tablespace does not exist in the memory cache,
3616
3520
or is being deleted there.
3699
3603
                                        matching tablespace is not found from
3700
3604
                                        memory */
3701
3605
{
3702
 
        fil_space_t*    tablespace;
 
3606
        fil_space_t*    namespace;
3703
3607
        fil_space_t*    space;
3704
3608
        char*           path;
3705
3609
 
3716
3620
        /* Look if there is a space with the same name; the name is the
3717
3621
        directory path from the datadir to the file */
3718
3622
 
3719
 
        tablespace = fil_space_get_by_name(path);
3720
 
        if (space && space == tablespace) {
 
3623
        namespace = fil_space_get_by_name(path);
 
3624
        if (space && space == namespace) {
3721
3625
                /* Found */
3722
3626
 
3723
3627
                if (mark_space) {
3739
3643
        }
3740
3644
 
3741
3645
        if (space == NULL) {
3742
 
                if (tablespace == NULL) {
 
3646
                if (namespace == NULL) {
3743
3647
                        ut_print_timestamp(stderr);
3744
3648
                        fputs("  InnoDB: Error: table ", stderr);
3745
3649
                        ut_print_filename(stderr, name);
3768
3672
                                "InnoDB: a tablespace of name %s and id %lu,"
3769
3673
                                " though. Have\n"
3770
3674
                                "InnoDB: you deleted or moved .ibd files?\n",
3771
 
                                (ulong) id, tablespace->name,
3772
 
                                (ulong) tablespace->id);
 
3675
                                (ulong) id, namespace->name,
 
3676
                                (ulong) namespace->id);
3773
3677
                }
3774
3678
error_exit:
3775
3679
                fputs("InnoDB: Please refer to\n"
3794
3698
                        "InnoDB: Have you deleted or moved .ibd files?\n",
3795
3699
                        (ulong) id, space->name);
3796
3700
 
3797
 
                if (tablespace != NULL) {
 
3701
                if (namespace != NULL) {
3798
3702
                        fputs("InnoDB: There is a tablespace"
3799
3703
                              " with the right name\n"
3800
3704
                              "InnoDB: ", stderr);
3801
 
                        ut_print_filename(stderr, tablespace->name);
 
3705
                        ut_print_filename(stderr, namespace->name);
3802
3706
                        fprintf(stderr, ", but its id is %lu.\n",
3803
 
                                (ulong) tablespace->id);
 
3707
                                (ulong) namespace->id);
3804
3708
                }
3805
3709
 
3806
3710
                goto error_exit;
3823
3727
        const char*     name)   /*!< in: table name in the standard
3824
3728
                                'databasename/tablename' format */
3825
3729
{
3826
 
        fil_space_t*    tablespace;
 
3730
        fil_space_t*    namespace;
3827
3731
        ulint           id              = ULINT_UNDEFINED;
3828
3732
        char*           path;
3829
3733
 
3836
3740
        /* Look if there is a space with the same name; the name is the
3837
3741
        directory path to the file */
3838
3742
 
3839
 
        tablespace = fil_space_get_by_name(path);
 
3743
        namespace = fil_space_get_by_name(path);
3840
3744
 
3841
 
        if (tablespace) {
3842
 
                id = tablespace->id;
 
3745
        if (namespace) {
 
3746
                id = namespace->id;
3843
3747
        }
3844
3748
 
3845
3749
        mem_free(path);
3907
3811
 
3908
3812
        /* Extend at most 64 pages at a time */
3909
3813
        buf_size = ut_min(64, size_after_extend - start_page_no) * page_size;
3910
 
        buf2 = static_cast<byte *>(mem_alloc(buf_size + page_size));
3911
 
        buf = static_cast<byte *>(ut_align(buf2, page_size));
 
3814
        buf2 = mem_alloc(buf_size + page_size);
 
3815
        buf = ut_align(buf2, page_size);
3912
3816
 
3913
3817
        memset(buf, 0, buf_size);
3914
3818
 
4493
4397
 
4494
4398
        ut_ad(fil_validate());
4495
4399
 
4496
 
        if (srv_use_native_aio) {
 
4400
        if (os_aio_use_native_aio) {
4497
4401
                srv_set_io_thread_op_info(segment, "native aio handle");
4498
4402
#ifdef WIN_ASYNC_IO
4499
4403
                ret = os_aio_windows_handle(segment, 0, &fil_node,
4500
4404
                                            &message, &type);
4501
 
#elif defined(LINUX_NATIVE_AIO)
4502
 
                ret = os_aio_linux_handle(segment, &fil_node,
4503
 
                                          &message, &type);
4504
4405
#else
4505
4406
                ret = 0; /* Eliminate compiler warning */
4506
4407
                ut_error;
4532
4433
 
4533
4434
        if (fil_node->space->purpose == FIL_TABLESPACE) {
4534
4435
                srv_set_io_thread_op_info(segment, "complete io for buf page");
4535
 
                buf_page_io_complete(static_cast<buf_page_t *>(message));
 
4436
                buf_page_io_complete(message);
4536
4437
        } else {
4537
4438
                srv_set_io_thread_op_info(segment, "complete io for log");
4538
 
                log_io_complete(static_cast<log_group_t *>(message));
 
4439
                log_io_complete(message);
4539
4440
        }
4540
4441
}
4541
4442
#endif /* UNIV_HOTBACKUP */
4682
4583
        traversed fil_system->unflushed_spaces and called UT_LIST_GET_NEXT()
4683
4584
        on a space that was just removed from the list by fil_flush().
4684
4585
        Thus, the space could be dropped and the memory overwritten. */
4685
 
        space_ids = static_cast<unsigned long *>(mem_alloc(n_space_ids * sizeof *space_ids));
 
4586
        space_ids = mem_alloc(n_space_ids * sizeof *space_ids);
4686
4587
 
4687
4588
        n_space_ids = 0;
4688
4589
 
4727
4628
 
4728
4629
        for (i = 0; i < hash_get_n_cells(fil_system->spaces); i++) {
4729
4630
 
4730
 
                space = static_cast<fil_space_t *>(HASH_GET_FIRST(fil_system->spaces, i));
 
4631
                space = HASH_GET_FIRST(fil_system->spaces, i);
4731
4632
 
4732
4633
                while (space != NULL) {
4733
4634
                        UT_LIST_VALIDATE(chain, fil_node_t, space->chain,
4746
4647
                                }
4747
4648
                                fil_node = UT_LIST_GET_NEXT(chain, fil_node);
4748
4649
                        }
4749
 
                        space = static_cast<fil_space_t *>(HASH_GET_NEXT(hash, space));
 
4650
                        space = HASH_GET_NEXT(hash, space);
4750
4651
                }
4751
4652
        }
4752
4653
 
4834
4735
 
4835
4736
        return(mach_read_from_2(page + FIL_PAGE_TYPE));
4836
4737
}
4837
 
 
4838
 
/****************************************************************//**
4839
 
Initializes the tablespace memory cache. */
4840
 
UNIV_INTERN
4841
 
void
4842
 
fil_close(void)
4843
 
/*===========*/
4844
 
{
4845
 
#ifndef UNIV_HOTBACKUP
4846
 
        /* The mutex should already have been freed. */
4847
 
        ut_ad(fil_system->mutex.magic_n == 0);
4848
 
#endif /* !UNIV_HOTBACKUP */
4849
 
 
4850
 
        hash_table_free(fil_system->spaces);
4851
 
 
4852
 
        hash_table_free(fil_system->name_hash);
4853
 
 
4854
 
        ut_a(UT_LIST_GET_LEN(fil_system->LRU) == 0);
4855
 
        ut_a(UT_LIST_GET_LEN(fil_system->unflushed_spaces) == 0);
4856
 
        ut_a(UT_LIST_GET_LEN(fil_system->space_list) == 0);
4857
 
 
4858
 
        mem_free(fil_system);
4859
 
 
4860
 
        fil_system = NULL;
4861
 
}