~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, 2010, 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
121
121
/** The null file address */
122
122
UNIV_INTERN fil_addr_t  fil_addr_null = {FIL_NULL, 0};
123
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
 
124
134
/** File node of a tablespace or the log data space */
125
135
struct fil_node_struct {
126
136
        fil_space_t*    space;  /*!< backpointer to the space where this node
329
339
/*******************************************************************//**
330
340
Frees a space object from the tablespace memory cache. Closes the files in
331
341
the chain but does not delete them. There must not be any pending i/o's or
332
 
flushes on the files. */
 
342
flushes on the files.
 
343
@return TRUE on success */
333
344
static
334
345
ibool
335
346
fil_space_free(
336
347
/*===========*/
337
 
                                /* out: TRUE if success */
338
 
        ulint           id,     /* in: space id */
339
 
        ibool           own_mutex);/* in: TRUE if own system->mutex */
 
348
        ulint           id,             /* in: space id */
 
349
        ibool           x_latched);     /* in: TRUE if caller has space->latch
 
350
                                        in X mode */
340
351
/********************************************************************//**
341
352
Reads data from a space to a buffer. Remember that the possible incomplete
342
353
blocks at the end of file are ignored: they are not taken into account when
570
581
 
571
582
        mutex_enter(&fil_system->mutex);
572
583
 
573
 
        node = mem_alloc(sizeof(fil_node_t));
 
584
        node = static_cast<fil_node_t *>(mem_alloc(sizeof(fil_node_t)));
574
585
 
575
586
        node->name = mem_strdup(name);
576
587
        node->open = FALSE;
653
664
                async I/O! */
654
665
 
655
666
                node->handle = os_file_create_simple_no_error_handling(
656
 
                        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);
657
669
                if (!success) {
658
670
                        /* The following call prints an error message */
659
671
                        os_file_get_last_error(TRUE);
699
711
 
700
712
                /* Read the first page of the tablespace */
701
713
 
702
 
                buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
 
714
                buf2 = static_cast<unsigned char *>(ut_malloc(2 * UNIV_PAGE_SIZE));
703
715
                /* Align the memory for file i/o if we might have O_DIRECT
704
716
                set */
705
 
                page = ut_align(buf2, UNIV_PAGE_SIZE);
 
717
                page = static_cast<unsigned char *>(ut_align(buf2, UNIV_PAGE_SIZE));
706
718
 
707
719
                success = os_file_read(node->handle, page, 0, 0,
708
720
                                       UNIV_PAGE_SIZE);
771
783
        os_file_create() to fall back to the normal file I/O mode. */
772
784
 
773
785
        if (space->purpose == FIL_LOG) {
774
 
                node->handle = os_file_create(node->name, OS_FILE_OPEN,
775
 
                                              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);
776
790
        } else if (node->is_raw_disk) {
777
 
                node->handle = os_file_create(node->name,
 
791
                node->handle = os_file_create(innodb_file_data_key,
 
792
                                              node->name,
778
793
                                              OS_FILE_OPEN_RAW,
779
 
                                              OS_FILE_AIO, OS_DATA_FILE, &ret);
 
794
                                              OS_FILE_AIO, OS_DATA_FILE,
 
795
                                                     &ret);
780
796
        } else {
781
 
                node->handle = os_file_create(node->name, OS_FILE_OPEN,
782
 
                                              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);
783
801
        }
784
802
 
785
803
        ut_a(ret);
1123
1141
        space = fil_space_get_by_name(name);
1124
1142
 
1125
1143
        if (UNIV_LIKELY_NULL(space)) {
 
1144
                ibool   success;
1126
1145
                ulint   namesake_id;
1127
1146
 
1128
1147
                ut_print_timestamp(stderr);
1161
1180
 
1162
1181
                namesake_id = space->id;
1163
1182
 
 
1183
                success = fil_space_free(namesake_id, FALSE);
 
1184
                ut_a(success);
 
1185
 
1164
1186
                mutex_exit(&fil_system->mutex);
1165
1187
 
1166
 
                fil_space_free(namesake_id, FALSE);
1167
 
 
1168
1188
                goto try_again;
1169
1189
        }
1170
1190
 
1188
1208
                return(FALSE);
1189
1209
        }
1190
1210
 
1191
 
        space = mem_alloc(sizeof(fil_space_t));
 
1211
        space = static_cast<fil_space_t *>(mem_alloc(sizeof(fil_space_t)));
1192
1212
 
1193
1213
        space->name = mem_strdup(name);
1194
1214
        space->id = id;
1197
1217
        space->tablespace_version = fil_system->tablespace_version;
1198
1218
        space->mark = FALSE;
1199
1219
 
1200
 
        if (UNIV_LIKELY(purpose == FIL_TABLESPACE)
 
1220
        if (UNIV_LIKELY(purpose == FIL_TABLESPACE && !recv_recovery_on)
1201
1221
            && UNIV_UNLIKELY(id > fil_system->max_assigned_id)) {
1202
1222
                if (!fil_system->space_id_reuse_warned) {
1203
1223
                        fil_system->space_id_reuse_warned = TRUE;
1228
1248
        UT_LIST_INIT(space->chain);
1229
1249
        space->magic_n = FIL_SPACE_MAGIC_N;
1230
1250
 
1231
 
        rw_lock_create(&space->latch, SYNC_FSP);
 
1251
        rw_lock_create(fil_space_latch_key, &space->latch, SYNC_FSP);
1232
1252
 
1233
1253
        HASH_INSERT(fil_space_t, hash, fil_system->spaces, id, space);
1234
1254
 
1314
1334
/*===========*/
1315
1335
                                        /* out: TRUE if success */
1316
1336
        ulint           id,             /* in: space id */
1317
 
        ibool           own_mutex)      /* in: TRUE if own system->mutex */
 
1337
        ibool           x_latched)      /* in: TRUE if caller has space->latch
 
1338
                                        in X mode */
1318
1339
{
1319
1340
        fil_space_t*    space;
1320
 
        fil_space_t*    namespace;
 
1341
        fil_space_t*    tablespace;
1321
1342
        fil_node_t*     fil_node;
1322
1343
 
1323
 
        if (!own_mutex) {
1324
 
                mutex_enter(&fil_system->mutex);
1325
 
        }
 
1344
        ut_ad(mutex_own(&fil_system->mutex));
1326
1345
 
1327
1346
        space = fil_space_get_by_id(id);
1328
1347
 
1333
1352
                        " from the cache but\n"
1334
1353
                        "InnoDB: it is not there.\n", (ulong) id);
1335
1354
 
1336
 
                mutex_exit(&fil_system->mutex);
1337
 
 
1338
1355
                return(FALSE);
1339
1356
        }
1340
1357
 
1341
1358
        HASH_DELETE(fil_space_t, hash, fil_system->spaces, id, space);
1342
1359
 
1343
 
        namespace = fil_space_get_by_name(space->name);
1344
 
        ut_a(namespace);
1345
 
        ut_a(space == namespace);
 
1360
        tablespace = fil_space_get_by_name(space->name);
 
1361
        ut_a(tablespace);
 
1362
        ut_a(space == tablespace);
1346
1363
 
1347
1364
        HASH_DELETE(fil_space_t, name_hash, fil_system->name_hash,
1348
1365
                    ut_fold_string(space->name), space);
1369
1386
 
1370
1387
        ut_a(0 == UT_LIST_GET_LEN(space->chain));
1371
1388
 
1372
 
        if (!own_mutex) {
1373
 
                mutex_exit(&fil_system->mutex);
 
1389
        if (x_latched) {
 
1390
                rw_lock_x_unlock(&space->latch);
1374
1391
        }
1375
1392
 
1376
1393
        rw_lock_free(&(space->latch));
1536
1553
        ut_a(hash_size > 0);
1537
1554
        ut_a(max_n_open > 0);
1538
1555
 
1539
 
        fil_system = mem_zalloc(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);
1540
1558
 
1541
 
        mutex_create(&fil_system->mutex, SYNC_ANY_LATCH);
 
1559
        mutex_create(fil_system_mutex_key,
 
1560
                     &fil_system->mutex, SYNC_ANY_LATCH);
1542
1561
 
1543
1562
        fil_system->spaces = hash_create(hash_size);
1544
1563
        fil_system->name_hash = hash_create(hash_size);
1615
1634
/*=====================*/
1616
1635
{
1617
1636
        fil_space_t*    space;
1618
 
        fil_node_t*     node;
1619
1637
 
1620
1638
        mutex_enter(&fil_system->mutex);
1621
1639
 
1622
1640
        space = UT_LIST_GET_FIRST(fil_system->space_list);
1623
1641
 
1624
1642
        while (space != NULL) {
 
1643
                fil_node_t*     node;
1625
1644
                fil_space_t*    prev_space = space;
1626
1645
 
1627
 
                node = UT_LIST_GET_FIRST(space->chain);
 
1646
                for (node = UT_LIST_GET_FIRST(space->chain);
 
1647
                     node != NULL;
 
1648
                     node = UT_LIST_GET_NEXT(chain, node)) {
1628
1649
 
1629
 
                while (node != NULL) {
1630
1650
                        if (node->open) {
1631
1651
                                fil_node_close_file(node, fil_system);
1632
1652
                        }
1633
 
                        node = UT_LIST_GET_NEXT(chain, node);
1634
1653
                }
 
1654
 
1635
1655
                space = UT_LIST_GET_NEXT(space_list, space);
1636
 
                fil_space_free(prev_space->id, TRUE);
 
1656
 
 
1657
                fil_space_free(prev_space->id, FALSE);
1637
1658
        }
1638
1659
 
1639
1660
        mutex_exit(&fil_system->mutex);
1676
1697
        ulint           sum_of_sizes,   /*!< in: combined size of previous files
1677
1698
                                        in space, in database pages */
1678
1699
        ib_uint64_t     lsn,            /*!< in: lsn to write */
1679
 
        ulint           arch_log_no __attribute__((unused)))
 
1700
        ulint           /*arch_log_no __attribute__((unused))*/)
1680
1701
                                        /*!< in: archived log number to write */
1681
1702
{
1682
1703
        byte*   buf1;
1683
1704
        byte*   buf;
1684
1705
 
1685
 
        buf1 = mem_alloc(2 * UNIV_PAGE_SIZE);
1686
 
        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));
1687
1708
 
1688
1709
        fil_read(TRUE, 0, 0, sum_of_sizes, 0, UNIV_PAGE_SIZE, buf, NULL);
1689
1710
 
1690
 
        mach_write_ull(buf + FIL_PAGE_FILE_FLUSH_LSN, lsn);
 
1711
        mach_write_to_8(buf + FIL_PAGE_FILE_FLUSH_LSN, lsn);
1691
1712
 
1692
1713
        fil_write(TRUE, 0, 0, sum_of_sizes, 0, UNIV_PAGE_SIZE, buf, NULL);
1693
1714
 
1775
1796
        byte*           buf2;
1776
1797
        ib_uint64_t     flushed_lsn;
1777
1798
 
1778
 
        buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
 
1799
        buf2 = static_cast<byte *>(ut_malloc(2 * UNIV_PAGE_SIZE));
1779
1800
        /* Align the memory for a possible read from a raw device */
1780
 
        buf = ut_align(buf2, UNIV_PAGE_SIZE);
 
1801
        buf = static_cast<byte *>(ut_align(buf2, UNIV_PAGE_SIZE));
1781
1802
 
1782
1803
        os_file_read(data_file, buf, 0, 0, UNIV_PAGE_SIZE);
1783
1804
 
1784
 
        flushed_lsn = mach_read_ull(buf + FIL_PAGE_FILE_FLUSH_LSN);
 
1805
        flushed_lsn = mach_read_from_8(buf + FIL_PAGE_FILE_FLUSH_LSN);
1785
1806
 
1786
1807
        ut_free(buf2);
1787
1808
 
1895
1916
        len = strlen(fil_path_to_mysql_datadir);
1896
1917
        namend = strchr(name, '/');
1897
1918
        ut_a(namend);
1898
 
        path = mem_alloc(len + (namend - name) + 2);
 
1919
        path = static_cast<char *>(mem_alloc(len + (namend - name) + 2));
1899
1920
 
1900
1921
        memcpy(path, fil_path_to_mysql_datadir, len);
1901
1922
        path[len] = '/';
2253
2274
        path = mem_strdup(space->name);
2254
2275
 
2255
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
 
2256
2290
#ifndef UNIV_HOTBACKUP
2257
2291
        /* Invalidate in the buffer pool all pages belonging to the
2258
2292
        tablespace. Since we have set space->is_being_deleted = TRUE, readahead
2265
2299
#endif
2266
2300
        /* printf("Deleting tablespace %s id %lu\n", space->name, id); */
2267
2301
 
2268
 
        success = fil_space_free(id, FALSE);
 
2302
        mutex_enter(&fil_system->mutex);
 
2303
 
 
2304
        success = fil_space_free(id, TRUE);
 
2305
 
 
2306
        mutex_exit(&fil_system->mutex);
2269
2307
 
2270
2308
        if (success) {
2271
2309
                success = os_file_delete(path);
2273
2311
                if (!success) {
2274
2312
                        success = os_file_delete_if_exists(path);
2275
2313
                }
 
2314
        } else {
 
2315
                rw_lock_x_unlock(&space->latch);
2276
2316
        }
2277
2317
 
2278
2318
        if (success) {
2300
2340
        return(FALSE);
2301
2341
}
2302
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
 
2303
2368
#ifndef UNIV_HOTBACKUP
2304
2369
/*******************************************************************//**
2305
2370
Discards a single-table tablespace. The tablespace must be cached in the
2398
2463
{
2399
2464
        ulint   namelen         = strlen(name);
2400
2465
        ulint   dirlen          = strlen(fil_path_to_mysql_datadir);
2401
 
        char*   filename        = mem_alloc(namelen + dirlen + sizeof "/.ibd");
 
2466
        char*   filename        = static_cast<char *>(mem_alloc(namelen + dirlen + sizeof "/.ibd"));
2402
2467
 
2403
2468
        if (is_temp) {
2404
2469
                memcpy(filename, name, namelen);
2534
2599
        success = fil_rename_tablespace_in_mem(space, node, path);
2535
2600
 
2536
2601
        if (success) {
2537
 
                success = os_file_rename(old_path, path);
 
2602
                success = os_file_rename(innodb_file_data_key, old_path, path);
2538
2603
 
2539
2604
                if (!success) {
2540
2605
                        /* We have to revert the changes we made
2611
2676
 
2612
2677
        path = fil_make_ibd_name(tablename, is_temp);
2613
2678
 
2614
 
        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,
2615
2681
                              OS_DATA_FILE, &ret);
2616
2682
        if (ret == FALSE) {
2617
2683
                ut_print_timestamp(stderr);
2679
2745
        with zeros from the call of os_file_set_size(), until a buffer pool
2680
2746
        flush would write to it. */
2681
2747
 
2682
 
        buf2 = ut_malloc(3 * UNIV_PAGE_SIZE);
 
2748
        buf2 = static_cast<byte *>(ut_malloc(3 * UNIV_PAGE_SIZE));
2683
2749
        /* Align the memory for file i/o if we might have O_DIRECT set */
2684
 
        page = ut_align(buf2, UNIV_PAGE_SIZE);
 
2750
        page = static_cast<byte *>(ut_align(buf2, UNIV_PAGE_SIZE));
2685
2751
 
2686
2752
        memset(page, '\0', UNIV_PAGE_SIZE);
2687
2753
 
2799
2865
        filepath = fil_make_ibd_name(name, FALSE);
2800
2866
 
2801
2867
        file = os_file_create_simple_no_error_handling(
2802
 
                filepath, OS_FILE_OPEN, OS_FILE_READ_WRITE, &success);
 
2868
                innodb_file_data_key, filepath, OS_FILE_OPEN,
 
2869
                OS_FILE_READ_WRITE, &success);
2803
2870
        if (!success) {
2804
2871
                /* The following call prints an error message */
2805
2872
                os_file_get_last_error(TRUE);
2818
2885
 
2819
2886
        /* Read the first page of the tablespace */
2820
2887
 
2821
 
        buf2 = ut_malloc(3 * UNIV_PAGE_SIZE);
 
2888
        buf2 = static_cast<byte *>(ut_malloc(3 * UNIV_PAGE_SIZE));
2822
2889
        /* Align the memory for file i/o if we might have O_DIRECT set */
2823
 
        page = ut_align(buf2, UNIV_PAGE_SIZE);
 
2890
        page = static_cast<byte *>(ut_align(buf2, UNIV_PAGE_SIZE));
2824
2891
 
2825
2892
        success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
2826
2893
        if (!success) {
2830
2897
 
2831
2898
        /* We have to read the file flush lsn from the header of the file */
2832
2899
 
2833
 
        flush_lsn = mach_read_ull(page + FIL_PAGE_FILE_FLUSH_LSN);
 
2900
        flush_lsn = mach_read_from_8(page + FIL_PAGE_FILE_FLUSH_LSN);
2834
2901
 
2835
2902
        if (current_lsn >= flush_lsn) {
2836
2903
                /* Ok */
2878
2945
 
2879
2946
                        goto func_exit;
2880
2947
                }
2881
 
                if (mach_read_ull(page + FIL_PAGE_LSN) > current_lsn) {
 
2948
                if (mach_read_from_8(page + FIL_PAGE_LSN) > current_lsn) {
2882
2949
                        /* We have to reset the lsn */
2883
2950
 
2884
2951
                        if (zip_size) {
2920
2987
                goto func_exit;
2921
2988
        }
2922
2989
 
2923
 
        mach_write_ull(page + FIL_PAGE_FILE_FLUSH_LSN, current_lsn);
 
2990
        mach_write_to_8(page + FIL_PAGE_FILE_FLUSH_LSN, current_lsn);
2924
2991
 
2925
2992
        success = os_file_write(filepath, file, page, 0, 0,
2926
2993
                                zip_size ? zip_size : UNIV_PAGE_SIZE);
2983
3050
        ut_a(!(flags & (~0UL << DICT_TF_BITS)));
2984
3051
 
2985
3052
        file = os_file_create_simple_no_error_handling(
2986
 
                filepath, OS_FILE_OPEN, OS_FILE_READ_ONLY, &success);
 
3053
                innodb_file_data_key, filepath, OS_FILE_OPEN,
 
3054
                OS_FILE_READ_ONLY, &success);
2987
3055
        if (!success) {
2988
3056
                /* The following call prints an error message */
2989
3057
                os_file_get_last_error(TRUE);
3019
3087
 
3020
3088
        /* Read the first page of the tablespace */
3021
3089
 
3022
 
        buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
 
3090
        buf2 = static_cast<byte *>(ut_malloc(2 * UNIV_PAGE_SIZE));
3023
3091
        /* Align the memory for file i/o if we might have O_DIRECT set */
3024
 
        page = ut_align(buf2, UNIV_PAGE_SIZE);
 
3092
        page = static_cast<byte *>(ut_align(buf2, UNIV_PAGE_SIZE));
3025
3093
 
3026
3094
        success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
3027
3095
 
3121
3189
#ifdef UNIV_HOTBACKUP
3122
3190
        fil_space_t*    space;
3123
3191
#endif
3124
 
        filepath = mem_alloc(strlen(dbname) + strlen(filename)
3125
 
                             + 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));
3126
3194
 
3127
3195
        sprintf(filepath, "%s/%s/%s", fil_path_to_mysql_datadir, dbname,
3128
3196
                filename);
3139
3207
# endif /* !UNIV_HOTBACKUP */
3140
3208
#endif
3141
3209
        file = os_file_create_simple_no_error_handling(
3142
 
                filepath, OS_FILE_OPEN, OS_FILE_READ_ONLY, &success);
 
3210
                innodb_file_data_key, filepath, OS_FILE_OPEN,
 
3211
                OS_FILE_READ_ONLY, &success);
3143
3212
        if (!success) {
3144
3213
                /* The following call prints an error message */
3145
3214
                os_file_get_last_error(TRUE);
3255
3324
#endif
3256
3325
        /* Read the first page of the tablespace if the size big enough */
3257
3326
 
3258
 
        buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
 
3327
        buf2 = static_cast<byte *>(ut_malloc(2 * UNIV_PAGE_SIZE));
3259
3328
        /* Align the memory for file i/o if we might have O_DIRECT set */
3260
 
        page = ut_align(buf2, UNIV_PAGE_SIZE);
 
3329
        page = static_cast<byte *>(ut_align(buf2, UNIV_PAGE_SIZE));
3261
3330
 
3262
3331
        if (size >= FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE) {
3263
3332
                success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
3297
3366
                os_file_close(file);
3298
3367
 
3299
3368
                new_path = fil_make_ibbackup_old_name(filepath);
3300
 
                ut_a(os_file_rename(filepath, new_path));
 
3369
                ut_a(os_file_rename(innodb_file_data_key, filepath, new_path));
3301
3370
 
3302
3371
                ut_free(buf2);
3303
3372
                mem_free(filepath);
3335
3404
 
3336
3405
                mutex_exit(&fil_system->mutex);
3337
3406
 
3338
 
                ut_a(os_file_rename(filepath, new_path));
 
3407
                ut_a(os_file_rename(innodb_file_data_key, filepath, new_path));
3339
3408
 
3340
3409
                ut_free(buf2);
3341
3410
                mem_free(filepath);
3444
3513
                return(DB_ERROR);
3445
3514
        }
3446
3515
 
3447
 
        dbpath = mem_alloc(dbpath_len);
 
3516
        dbpath = static_cast<char *>(mem_alloc(dbpath_len));
3448
3517
 
3449
3518
        /* Scan all directories under the datadir. They are the database
3450
3519
        directories of MySQL. */
3473
3542
                                mem_free(dbpath);
3474
3543
                        }
3475
3544
 
3476
 
                        dbpath = mem_alloc(dbpath_len);
 
3545
                        dbpath = static_cast<char *>(mem_alloc(dbpath_len));
3477
3546
                }
3478
3547
                sprintf(dbpath, "%s/%s", fil_path_to_mysql_datadir,
3479
3548
                        dbinfo.name);
3542
3611
        return(err);
3543
3612
}
3544
3613
 
3545
 
/********************************************************************//**
3546
 
If we need crash recovery, and we have called
3547
 
fil_load_single_table_tablespaces() and dict_load_single_table_tablespaces(),
3548
 
we can call this function to print an error message of orphaned .ibd files
3549
 
for which there is not a data dictionary entry with a matching table name
3550
 
and space id. */
3551
 
UNIV_INTERN
3552
 
void
3553
 
fil_print_orphaned_tablespaces(void)
3554
 
/*================================*/
3555
 
{
3556
 
        fil_space_t*    space;
3557
 
 
3558
 
        mutex_enter(&fil_system->mutex);
3559
 
 
3560
 
        space = UT_LIST_GET_FIRST(fil_system->space_list);
3561
 
 
3562
 
        while (space) {
3563
 
                if (space->purpose == FIL_TABLESPACE && space->id != 0
3564
 
                    && !space->mark) {
3565
 
                        fputs("InnoDB: Warning: tablespace ", stderr);
3566
 
                        ut_print_filename(stderr, space->name);
3567
 
                        fprintf(stderr, " of id %lu has no matching table in\n"
3568
 
                                "InnoDB: the InnoDB data dictionary.\n",
3569
 
                                (ulong) space->id);
3570
 
                }
3571
 
 
3572
 
                space = UT_LIST_GET_NEXT(space_list, space);
3573
 
        }
3574
 
 
3575
 
        mutex_exit(&fil_system->mutex);
3576
 
}
3577
 
 
3578
3614
/*******************************************************************//**
3579
3615
Returns TRUE if a single-table tablespace does not exist in the memory cache,
3580
3616
or is being deleted there.
3663
3699
                                        matching tablespace is not found from
3664
3700
                                        memory */
3665
3701
{
3666
 
        fil_space_t*    namespace;
 
3702
        fil_space_t*    tablespace;
3667
3703
        fil_space_t*    space;
3668
3704
        char*           path;
3669
3705
 
3680
3716
        /* Look if there is a space with the same name; the name is the
3681
3717
        directory path from the datadir to the file */
3682
3718
 
3683
 
        namespace = fil_space_get_by_name(path);
3684
 
        if (space && space == namespace) {
 
3719
        tablespace = fil_space_get_by_name(path);
 
3720
        if (space && space == tablespace) {
3685
3721
                /* Found */
3686
3722
 
3687
3723
                if (mark_space) {
3703
3739
        }
3704
3740
 
3705
3741
        if (space == NULL) {
3706
 
                if (namespace == NULL) {
 
3742
                if (tablespace == NULL) {
3707
3743
                        ut_print_timestamp(stderr);
3708
3744
                        fputs("  InnoDB: Error: table ", stderr);
3709
3745
                        ut_print_filename(stderr, name);
3732
3768
                                "InnoDB: a tablespace of name %s and id %lu,"
3733
3769
                                " though. Have\n"
3734
3770
                                "InnoDB: you deleted or moved .ibd files?\n",
3735
 
                                (ulong) id, namespace->name,
3736
 
                                (ulong) namespace->id);
 
3771
                                (ulong) id, tablespace->name,
 
3772
                                (ulong) tablespace->id);
3737
3773
                }
3738
3774
error_exit:
3739
3775
                fputs("InnoDB: Please refer to\n"
3758
3794
                        "InnoDB: Have you deleted or moved .ibd files?\n",
3759
3795
                        (ulong) id, space->name);
3760
3796
 
3761
 
                if (namespace != NULL) {
 
3797
                if (tablespace != NULL) {
3762
3798
                        fputs("InnoDB: There is a tablespace"
3763
3799
                              " with the right name\n"
3764
3800
                              "InnoDB: ", stderr);
3765
 
                        ut_print_filename(stderr, namespace->name);
 
3801
                        ut_print_filename(stderr, tablespace->name);
3766
3802
                        fprintf(stderr, ", but its id is %lu.\n",
3767
 
                                (ulong) namespace->id);
 
3803
                                (ulong) tablespace->id);
3768
3804
                }
3769
3805
 
3770
3806
                goto error_exit;
3787
3823
        const char*     name)   /*!< in: table name in the standard
3788
3824
                                'databasename/tablename' format */
3789
3825
{
3790
 
        fil_space_t*    namespace;
 
3826
        fil_space_t*    tablespace;
3791
3827
        ulint           id              = ULINT_UNDEFINED;
3792
3828
        char*           path;
3793
3829
 
3800
3836
        /* Look if there is a space with the same name; the name is the
3801
3837
        directory path to the file */
3802
3838
 
3803
 
        namespace = fil_space_get_by_name(path);
 
3839
        tablespace = fil_space_get_by_name(path);
3804
3840
 
3805
 
        if (namespace) {
3806
 
                id = namespace->id;
 
3841
        if (tablespace) {
 
3842
                id = tablespace->id;
3807
3843
        }
3808
3844
 
3809
3845
        mem_free(path);
3871
3907
 
3872
3908
        /* Extend at most 64 pages at a time */
3873
3909
        buf_size = ut_min(64, size_after_extend - start_page_no) * page_size;
3874
 
        buf2 = mem_alloc(buf_size + page_size);
3875
 
        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));
3876
3912
 
3877
3913
        memset(buf, 0, buf_size);
3878
3914
 
4457
4493
 
4458
4494
        ut_ad(fil_validate());
4459
4495
 
4460
 
        if (os_aio_use_native_aio) {
 
4496
        if (srv_use_native_aio) {
4461
4497
                srv_set_io_thread_op_info(segment, "native aio handle");
4462
4498
#ifdef WIN_ASYNC_IO
4463
4499
                ret = os_aio_windows_handle(segment, 0, &fil_node,
4464
4500
                                            &message, &type);
 
4501
#elif defined(LINUX_NATIVE_AIO)
 
4502
                ret = os_aio_linux_handle(segment, &fil_node,
 
4503
                                          &message, &type);
4465
4504
#else
4466
4505
                ret = 0; /* Eliminate compiler warning */
4467
4506
                ut_error;
4493
4532
 
4494
4533
        if (fil_node->space->purpose == FIL_TABLESPACE) {
4495
4534
                srv_set_io_thread_op_info(segment, "complete io for buf page");
4496
 
                buf_page_io_complete(message);
 
4535
                buf_page_io_complete(static_cast<buf_page_t *>(message));
4497
4536
        } else {
4498
4537
                srv_set_io_thread_op_info(segment, "complete io for log");
4499
 
                log_io_complete(message);
 
4538
                log_io_complete(static_cast<log_group_t *>(message));
4500
4539
        }
4501
4540
}
4502
4541
#endif /* UNIV_HOTBACKUP */
4643
4682
        traversed fil_system->unflushed_spaces and called UT_LIST_GET_NEXT()
4644
4683
        on a space that was just removed from the list by fil_flush().
4645
4684
        Thus, the space could be dropped and the memory overwritten. */
4646
 
        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));
4647
4686
 
4648
4687
        n_space_ids = 0;
4649
4688
 
4688
4727
 
4689
4728
        for (i = 0; i < hash_get_n_cells(fil_system->spaces); i++) {
4690
4729
 
4691
 
                space = HASH_GET_FIRST(fil_system->spaces, i);
 
4730
                space = static_cast<fil_space_t *>(HASH_GET_FIRST(fil_system->spaces, i));
4692
4731
 
4693
4732
                while (space != NULL) {
4694
4733
                        UT_LIST_VALIDATE(chain, fil_node_t, space->chain,
4707
4746
                                }
4708
4747
                                fil_node = UT_LIST_GET_NEXT(chain, fil_node);
4709
4748
                        }
4710
 
                        space = HASH_GET_NEXT(hash, space);
 
4749
                        space = static_cast<fil_space_t *>(HASH_GET_NEXT(hash, space));
4711
4750
                }
4712
4751
        }
4713
4752
 
4796
4835
        return(mach_read_from_2(page + FIL_PAGE_TYPE));
4797
4836
}
4798
4837
 
4799
 
/********************************************************************
 
4838
/****************************************************************//**
4800
4839
Initializes the tablespace memory cache. */
4801
4840
UNIV_INTERN
4802
4841
void