~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

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