~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/innodb_plugin/fil/fil0fil.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-06-21 15:31:05 UTC
  • mfrom: (1.1.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20100621153105-pbbz3t6nyrf9t2zq
Tags: upstream-5.1.48
ImportĀ upstreamĀ versionĀ 5.1.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
279
279
                                        request */
280
280
        UT_LIST_BASE_NODE_T(fil_space_t) space_list;
281
281
                                        /*!< list of all file spaces */
 
282
        ibool           space_id_reuse_warned;
 
283
                                        /* !< TRUE if fil_space_create()
 
284
                                        has issued a warning about
 
285
                                        potential space_id reuse */
282
286
};
283
287
 
284
288
/** The tablespace memory cache. This variable is NULL before the module is
1193
1197
        space->tablespace_version = fil_system->tablespace_version;
1194
1198
        space->mark = FALSE;
1195
1199
 
1196
 
        if (purpose == FIL_TABLESPACE && id > fil_system->max_assigned_id) {
 
1200
        if (UNIV_LIKELY(purpose == FIL_TABLESPACE)
 
1201
            && UNIV_UNLIKELY(id > fil_system->max_assigned_id)) {
 
1202
                if (!fil_system->space_id_reuse_warned) {
 
1203
                        fil_system->space_id_reuse_warned = TRUE;
 
1204
 
 
1205
                        ut_print_timestamp(stderr);
 
1206
                        fprintf(stderr,
 
1207
                                "  InnoDB: Warning: allocated tablespace %lu,"
 
1208
                                " old maximum was %lu\n",
 
1209
                                (ulong) id,
 
1210
                                (ulong) fil_system->max_assigned_id);
 
1211
                }
 
1212
 
1197
1213
                fil_system->max_assigned_id = id;
1198
1214
        }
1199
1215
 
1231
1247
Assigns a new space id for a new single-table tablespace. This works simply by
1232
1248
incrementing the global counter. If 4 billion id's is not enough, we may need
1233
1249
to recycle id's.
1234
 
@return new tablespace id; ULINT_UNDEFINED if could not assign an id */
1235
 
static
1236
 
ulint
1237
 
fil_assign_new_space_id(void)
1238
 
/*=========================*/
 
1250
@return TRUE if assigned, FALSE if not */
 
1251
UNIV_INTERN
 
1252
ibool
 
1253
fil_assign_new_space_id(
 
1254
/*====================*/
 
1255
        ulint*  space_id)       /*!< in/out: space id */
1239
1256
{
1240
 
        ulint           id;
 
1257
        ulint   id;
 
1258
        ibool   success;
1241
1259
 
1242
1260
        mutex_enter(&fil_system->mutex);
1243
1261
 
1244
 
        fil_system->max_assigned_id++;
1245
 
 
1246
 
        id = fil_system->max_assigned_id;
 
1262
        id = *space_id;
 
1263
 
 
1264
        if (id < fil_system->max_assigned_id) {
 
1265
                id = fil_system->max_assigned_id;
 
1266
        }
 
1267
 
 
1268
        id++;
1247
1269
 
1248
1270
        if (id > (SRV_LOG_SPACE_FIRST_ID / 2) && (id % 1000000UL == 0)) {
1249
1271
                ut_print_timestamp(stderr);
1259
1281
                        (ulong) SRV_LOG_SPACE_FIRST_ID);
1260
1282
        }
1261
1283
 
1262
 
        if (id >= SRV_LOG_SPACE_FIRST_ID) {
 
1284
        success = (id < SRV_LOG_SPACE_FIRST_ID);
 
1285
 
 
1286
        if (success) {
 
1287
                *space_id = fil_system->max_assigned_id = id;
 
1288
        } else {
1263
1289
                ut_print_timestamp(stderr);
1264
1290
                fprintf(stderr,
1265
1291
                        "InnoDB: You have run out of single-table"
1269
1295
                        " have to dump all your tables and\n"
1270
1296
                        "InnoDB: recreate the whole InnoDB installation.\n",
1271
1297
                        (ulong) id);
1272
 
                fil_system->max_assigned_id--;
1273
 
 
1274
 
                id = ULINT_UNDEFINED;
 
1298
                *space_id = ULINT_UNDEFINED;
1275
1299
        }
1276
1300
 
1277
1301
        mutex_exit(&fil_system->mutex);
1278
1302
 
1279
 
        return(id);
 
1303
        return(success);
1280
1304
}
1281
1305
 
1282
1306
/*******************************************************************//**
1512
1536
        ut_a(hash_size > 0);
1513
1537
        ut_a(max_n_open > 0);
1514
1538
 
1515
 
        fil_system = mem_alloc(sizeof(fil_system_t));
 
1539
        fil_system = mem_zalloc(sizeof(fil_system_t));
1516
1540
 
1517
1541
        mutex_create(&fil_system->mutex, SYNC_ANY_LATCH);
1518
1542
 
1521
1545
 
1522
1546
        UT_LIST_INIT(fil_system->LRU);
1523
1547
 
1524
 
        fil_system->n_open = 0;
1525
1548
        fil_system->max_n_open = max_n_open;
1526
 
 
1527
 
        fil_system->modification_counter = 0;
1528
 
        fil_system->max_assigned_id = 0;
1529
 
 
1530
 
        fil_system->tablespace_version = 0;
1531
 
 
1532
 
        UT_LIST_INIT(fil_system->unflushed_spaces);
1533
 
        UT_LIST_INIT(fil_system->space_list);
1534
1549
}
1535
1550
 
1536
1551
/*******************************************************************//**
2115
2130
                        fil_create_directory_for_tablename(name);
2116
2131
 
2117
2132
                        if (fil_create_new_single_table_tablespace(
2118
 
                                    &space_id, name, FALSE, flags,
 
2133
                                    space_id, name, FALSE, flags,
2119
2134
                                    FIL_IBD_FILE_INITIAL_SIZE) != DB_SUCCESS) {
2120
2135
                                ut_error;
2121
2136
                        }
2562
2577
ulint
2563
2578
fil_create_new_single_table_tablespace(
2564
2579
/*===================================*/
2565
 
        ulint*          space_id,       /*!< in/out: space id; if this is != 0,
2566
 
                                        then this is an input parameter,
2567
 
                                        otherwise output */
 
2580
        ulint           space_id,       /*!< in: space id */
2568
2581
        const char*     tablename,      /*!< in: the table name in the usual
2569
2582
                                        databasename/tablename format
2570
2583
                                        of InnoDB, or a dir path to a temp
2584
2597
        ibool           success;
2585
2598
        char*           path;
2586
2599
 
 
2600
        ut_a(space_id > 0);
 
2601
        ut_a(space_id < SRV_LOG_SPACE_FIRST_ID);
2587
2602
        ut_a(size >= FIL_IBD_FILE_INITIAL_SIZE);
2588
2603
        /* The tablespace flags (FSP_SPACE_FLAGS) should be 0 for
2589
2604
        ROW_FORMAT=COMPACT
2640
2655
                return(DB_ERROR);
2641
2656
        }
2642
2657
 
2643
 
        buf2 = ut_malloc(3 * UNIV_PAGE_SIZE);
2644
 
        /* Align the memory for file i/o if we might have O_DIRECT set */
2645
 
        page = ut_align(buf2, UNIV_PAGE_SIZE);
2646
 
 
2647
2658
        ret = os_file_set_size(path, file, size * UNIV_PAGE_SIZE, 0);
2648
2659
 
2649
2660
        if (!ret) {
2650
 
                ut_free(buf2);
2651
 
                os_file_close(file);
2652
 
                os_file_delete(path);
2653
 
 
2654
 
                mem_free(path);
2655
 
                return(DB_OUT_OF_FILE_SPACE);
2656
 
        }
2657
 
 
2658
 
        if (*space_id == 0) {
2659
 
                *space_id = fil_assign_new_space_id();
2660
 
        }
2661
 
 
2662
 
        /* printf("Creating tablespace %s id %lu\n", path, *space_id); */
2663
 
 
2664
 
        if (*space_id == ULINT_UNDEFINED) {
2665
 
                ut_free(buf2);
 
2661
                err = DB_OUT_OF_FILE_SPACE;
2666
2662
error_exit:
2667
2663
                os_file_close(file);
2668
2664
error_exit2:
2669
2665
                os_file_delete(path);
2670
2666
 
2671
2667
                mem_free(path);
2672
 
                return(DB_ERROR);
 
2668
                return(err);
2673
2669
        }
2674
2670
 
 
2671
        /* printf("Creating tablespace %s id %lu\n", path, space_id); */
 
2672
 
2675
2673
        /* We have to write the space id to the file immediately and flush the
2676
2674
        file to disk. This is because in crash recovery we must be aware what
2677
2675
        tablespaces exist and what are their space id's, so that we can apply
2681
2679
        with zeros from the call of os_file_set_size(), until a buffer pool
2682
2680
        flush would write to it. */
2683
2681
 
 
2682
        buf2 = ut_malloc(3 * UNIV_PAGE_SIZE);
 
2683
        /* Align the memory for file i/o if we might have O_DIRECT set */
 
2684
        page = ut_align(buf2, UNIV_PAGE_SIZE);
 
2685
 
2684
2686
        memset(page, '\0', UNIV_PAGE_SIZE);
2685
2687
 
2686
 
        fsp_header_init_fields(page, *space_id, flags);
2687
 
        mach_write_to_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, *space_id);
 
2688
        fsp_header_init_fields(page, space_id, flags);
 
2689
        mach_write_to_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, space_id);
2688
2690
 
2689
2691
        if (!(flags & DICT_TF_ZSSIZE_MASK)) {
2690
2692
                buf_flush_init_for_writing(page, NULL, 0);
2715
2717
                      " to tablespace ", stderr);
2716
2718
                ut_print_filename(stderr, path);
2717
2719
                putc('\n', stderr);
 
2720
                err = DB_ERROR;
2718
2721
                goto error_exit;
2719
2722
        }
2720
2723
 
2724
2727
                fputs("InnoDB: Error: file flush of tablespace ", stderr);
2725
2728
                ut_print_filename(stderr, path);
2726
2729
                fputs(" failed\n", stderr);
 
2730
                err = DB_ERROR;
2727
2731
                goto error_exit;
2728
2732
        }
2729
2733
 
2730
2734
        os_file_close(file);
2731
2735
 
2732
 
        if (*space_id == ULINT_UNDEFINED) {
2733
 
                goto error_exit2;
2734
 
        }
2735
 
 
2736
 
        success = fil_space_create(path, *space_id, flags, FIL_TABLESPACE);
 
2736
        success = fil_space_create(path, space_id, flags, FIL_TABLESPACE);
2737
2737
 
2738
2738
        if (!success) {
 
2739
                err = DB_ERROR;
2739
2740
                goto error_exit2;
2740
2741
        }
2741
2742
 
2742
 
        fil_node_create(path, size, *space_id, FALSE);
 
2743
        fil_node_create(path, size, space_id, FALSE);
2743
2744
 
2744
2745
#ifndef UNIV_HOTBACKUP
2745
2746
        {
2750
2751
                fil_op_write_log(flags
2751
2752
                                 ? MLOG_FILE_CREATE2
2752
2753
                                 : MLOG_FILE_CREATE,
2753
 
                                 *space_id,
 
2754
                                 space_id,
2754
2755
                                 is_temp ? MLOG_FILE_FLAG_TEMP : 0,
2755
2756
                                 flags,
2756
2757
                                 tablename, NULL, &mtr);