~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2010-11-08 18:26:08 UTC
  • mto: This revision was merged to the branch mainline in revision 1931.
  • Revision ID: mordred@inaugust.com-20101108182608-lci86acl7r53sbi3
Replaced auto_ptr with scoped_ptr.

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