@@ -28,7 +28,6 @@ Created 10/25/1995 Heikki Tuuri
28
28
#include " fil0crypt.h"
29
29
30
30
#include " btr0btr.h"
31
- #include " btr0sea.h"
32
31
#include " buf0buf.h"
33
32
#include " dict0boot.h"
34
33
#include " dict0dict.h"
@@ -2395,235 +2394,6 @@ fil_name_write(
2395
2394
fil_name_write (space->id , first_page_no, file->name , mtr);
2396
2395
}
2397
2396
2398
- /* *******************************************************/ /* *
2399
- Recreates table indexes by applying
2400
- TRUNCATE log record during recovery.
2401
- @return DB_SUCCESS or error code */
2402
- dberr_t
2403
- fil_recreate_table (
2404
- /* ===============*/
2405
- ulint space_id, /* !< in: space id */
2406
- ulint format_flags, /* !< in: page format */
2407
- ulint flags, /* !< in: tablespace flags */
2408
- const char * name, /* !< in: table name */
2409
- truncate_t & truncate) /* !< in: The information of
2410
- TRUNCATE log record */
2411
- {
2412
- dberr_t err = DB_SUCCESS;
2413
- bool found;
2414
- const page_size_t page_size (fil_space_get_page_size (space_id,
2415
- &found));
2416
-
2417
- if (!found) {
2418
- ib::info () << " Missing .ibd file for table '" << name
2419
- << " ' with tablespace " << space_id;
2420
- return (DB_ERROR);
2421
- }
2422
-
2423
- ut_ad (!truncate_t ::s_fix_up_active);
2424
- truncate_t ::s_fix_up_active = true ;
2425
-
2426
- /* Step-1: Scan for active indexes from REDO logs and drop
2427
- all the indexes using low level function that take root_page_no
2428
- and space-id. */
2429
- truncate.drop_indexes (space_id);
2430
-
2431
- /* Step-2: Scan for active indexes and re-create them. */
2432
- err = truncate.create_indexes (
2433
- name, space_id, page_size, flags, format_flags);
2434
- if (err != DB_SUCCESS) {
2435
- ib::info () << " Failed to create indexes for the table '"
2436
- << name << " ' with tablespace " << space_id
2437
- << " while fixing up truncate action" ;
2438
- return (err);
2439
- }
2440
-
2441
- truncate_t ::s_fix_up_active = false ;
2442
-
2443
- return (err);
2444
- }
2445
-
2446
- /* *******************************************************/ /* *
2447
- Recreates the tablespace and table indexes by applying
2448
- TRUNCATE log record during recovery.
2449
- @return DB_SUCCESS or error code */
2450
- dberr_t
2451
- fil_recreate_tablespace (
2452
- /* ====================*/
2453
- ulint space_id, /* !< in: space id */
2454
- ulint format_flags, /* !< in: page format */
2455
- ulint flags, /* !< in: tablespace flags */
2456
- const char * name, /* !< in: table name */
2457
- truncate_t & truncate, /* !< in: The information of
2458
- TRUNCATE log record */
2459
- lsn_t recv_lsn) /* !< in: the end LSN of
2460
- the log record */
2461
- {
2462
- dberr_t err = DB_SUCCESS;
2463
- mtr_t mtr;
2464
-
2465
- ut_ad (!truncate_t ::s_fix_up_active);
2466
- truncate_t ::s_fix_up_active = true ;
2467
-
2468
- /* Step-1: Invalidate buffer pool pages belonging to the tablespace
2469
- to re-create. */
2470
- buf_LRU_flush_or_remove_pages (space_id, NULL );
2471
-
2472
- /* Remove all insert buffer entries for the tablespace */
2473
- ibuf_delete_for_discarded_space (space_id);
2474
-
2475
- /* Step-2: truncate tablespace (reset the size back to original or
2476
- default size) of tablespace. */
2477
- err = truncate.truncate (
2478
- space_id, truncate.get_dir_path (), name, flags, true );
2479
-
2480
- if (err != DB_SUCCESS) {
2481
-
2482
- ib::info () << " Cannot access .ibd file for table '"
2483
- << name << " ' with tablespace " << space_id
2484
- << " while truncating" ;
2485
- return (DB_ERROR);
2486
- }
2487
-
2488
- fil_space_t * space = fil_space_acquire (space_id);
2489
- if (!space) {
2490
- ib::info () << " Missing .ibd file for table '" << name
2491
- << " ' with tablespace " << space_id;
2492
- return (DB_ERROR);
2493
- }
2494
-
2495
- const page_size_t page_size (space->flags );
2496
-
2497
- /* Step-3: Initialize Header. */
2498
- if (page_size.is_compressed ()) {
2499
- byte* buf;
2500
- page_t * page;
2501
-
2502
- buf = static_cast <byte*>(ut_zalloc_nokey (3 * UNIV_PAGE_SIZE));
2503
-
2504
- /* Align the memory for file i/o */
2505
- page = static_cast <byte*>(ut_align (buf, UNIV_PAGE_SIZE));
2506
-
2507
- flags |= FSP_FLAGS_PAGE_SSIZE ();
2508
-
2509
- fsp_header_init_fields (page, space_id, flags);
2510
-
2511
- mach_write_to_4 (
2512
- page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, space_id);
2513
-
2514
- page_zip_des_t page_zip;
2515
- page_zip_set_size (&page_zip, page_size.physical ());
2516
- page_zip.data = page + UNIV_PAGE_SIZE;
2517
-
2518
- #ifdef UNIV_DEBUG
2519
- page_zip.m_start =
2520
- #endif /* UNIV_DEBUG */
2521
- page_zip.m_end = page_zip.m_nonempty = page_zip.n_blobs = 0 ;
2522
- buf_flush_init_for_writing (NULL , page, &page_zip, 0 );
2523
-
2524
- err = fil_write (page_id_t (space_id, 0 ), page_size, 0 ,
2525
- page_size.physical (), page_zip.data );
2526
-
2527
- ut_free (buf);
2528
-
2529
- if (err != DB_SUCCESS) {
2530
- ib::info () << " Failed to clean header of the"
2531
- " table '" << name << " ' with tablespace "
2532
- << space_id;
2533
- goto func_exit;
2534
- }
2535
- }
2536
-
2537
- mtr_start (&mtr);
2538
- /* Don't log the operation while fixing up table truncate operation
2539
- as crash at this level can still be sustained with recovery restarting
2540
- from last checkpoint. */
2541
- mtr_set_log_mode (&mtr, MTR_LOG_NO_REDO);
2542
-
2543
- /* Initialize the first extent descriptor page and
2544
- the second bitmap page for the new tablespace. */
2545
- fsp_header_init (space, FIL_IBD_FILE_INITIAL_SIZE, &mtr);
2546
- mtr_commit (&mtr);
2547
-
2548
- /* Step-4: Re-Create Indexes to newly re-created tablespace.
2549
- This operation will restore tablespace back to what it was
2550
- when it was created during CREATE TABLE. */
2551
- err = truncate.create_indexes (
2552
- name, space_id, page_size, flags, format_flags);
2553
- if (err != DB_SUCCESS) {
2554
- goto func_exit;
2555
- }
2556
-
2557
- /* Step-5: Write new created pages into ibd file handle and
2558
- flush it to disk for the tablespace, in case i/o-handler thread
2559
- deletes the bitmap page from buffer. */
2560
- mtr_start (&mtr);
2561
-
2562
- mtr_set_log_mode (&mtr, MTR_LOG_NO_REDO);
2563
-
2564
- for (ulint page_no = 0 ;
2565
- page_no < UT_LIST_GET_FIRST (space->chain )->size ; ++page_no) {
2566
-
2567
- const page_id_t cur_page_id (space_id, page_no);
2568
-
2569
- buf_block_t * block = buf_page_get (cur_page_id, page_size,
2570
- RW_X_LATCH, &mtr);
2571
-
2572
- byte* page = buf_block_get_frame (block);
2573
-
2574
- if (!FSP_FLAGS_GET_ZIP_SSIZE (flags)) {
2575
- ut_ad (!page_size.is_compressed ());
2576
-
2577
- buf_flush_init_for_writing (
2578
- block, page, NULL , recv_lsn);
2579
-
2580
- err = fil_write (cur_page_id, page_size, 0 ,
2581
- page_size.physical (), page);
2582
- } else {
2583
- ut_ad (page_size.is_compressed ());
2584
-
2585
- /* We don't want to rewrite empty pages. */
2586
-
2587
- if (fil_page_get_type (page) != 0 ) {
2588
- page_zip_des_t * page_zip =
2589
- buf_block_get_page_zip (block);
2590
-
2591
- buf_flush_init_for_writing (
2592
- block, page, page_zip, recv_lsn);
2593
-
2594
- err = fil_write (cur_page_id, page_size, 0 ,
2595
- page_size.physical (),
2596
- page_zip->data );
2597
- } else {
2598
- #ifdef UNIV_DEBUG
2599
- const byte* data = block->page .zip .data ;
2600
-
2601
- /* Make sure that the page is really empty */
2602
- for (ulint i = 0 ;
2603
- i < page_size.physical ();
2604
- ++i) {
2605
-
2606
- ut_a (data[i] == 0 );
2607
- }
2608
- #endif /* UNIV_DEBUG */
2609
- }
2610
- }
2611
-
2612
- if (err != DB_SUCCESS) {
2613
- ib::info () << " Cannot write page " << page_no
2614
- << " into a .ibd file for table '"
2615
- << name << " ' with tablespace " << space_id;
2616
- }
2617
- }
2618
-
2619
- mtr_commit (&mtr);
2620
-
2621
- truncate_t ::s_fix_up_active = false ;
2622
- func_exit:
2623
- fil_space_release (space);
2624
- return (err);
2625
- }
2626
-
2627
2397
/* * Replay a file rename operation if possible.
2628
2398
@param[in] space_id tablespace identifier
2629
2399
@param[in] first_page_no first page number in the file
@@ -3186,67 +2956,6 @@ fil_prepare_for_truncate(
3186
2956
return (err);
3187
2957
}
3188
2958
3189
- /* * Reinitialize the original tablespace header with the same space id
3190
- for single tablespace
3191
- @param[in] table table belongs to tablespace
3192
- @param[in] size size in blocks
3193
- @param[in] trx Transaction covering truncate */
3194
- void
3195
- fil_reinit_space_header_for_table (
3196
- dict_table_t * table,
3197
- ulint size,
3198
- trx_t * trx)
3199
- {
3200
- ulint id = table->space ;
3201
-
3202
- ut_a (!is_system_tablespace (id));
3203
-
3204
- /* Invalidate in the buffer pool all pages belonging
3205
- to the tablespace. The buffer pool scan may take long
3206
- time to complete, therefore we release dict_sys->mutex
3207
- and the dict operation lock during the scan and aquire
3208
- it again after the buffer pool scan.*/
3209
-
3210
- /* Release the lock on the indexes too. So that
3211
- they won't violate the latch ordering. */
3212
- dict_table_x_unlock_indexes (table);
3213
- row_mysql_unlock_data_dictionary (trx);
3214
-
3215
- /* Lock the search latch in shared mode to prevent user
3216
- from disabling AHI during the scan */
3217
- btr_search_s_lock_all ();
3218
- DEBUG_SYNC_C (" buffer_pool_scan" );
3219
- buf_LRU_flush_or_remove_pages (id, NULL );
3220
- btr_search_s_unlock_all ();
3221
-
3222
- row_mysql_lock_data_dictionary (trx);
3223
-
3224
- dict_table_x_lock_indexes (table);
3225
-
3226
- /* Remove all insert buffer entries for the tablespace */
3227
- ibuf_delete_for_discarded_space (id);
3228
-
3229
- mutex_enter (&fil_system.mutex );
3230
- fil_space_t * space = fil_space_get_by_id (id);
3231
- /* TRUNCATE TABLE is protected by an exclusive table lock.
3232
- The table cannot be dropped or the tablespace discarded
3233
- while we are holding the transactional table lock. Thus,
3234
- there is no need to invoke fil_space_acquire(). */
3235
- mutex_exit (&fil_system.mutex );
3236
-
3237
- mtr_t mtr;
3238
-
3239
- mtr.start ();
3240
- mtr.set_named_space (space);
3241
- mtr_x_lock (&space->latch , &mtr);
3242
-
3243
- ut_ad (UT_LIST_GET_LEN (space->chain ) == 1 );
3244
- space->size = UT_LIST_GET_FIRST (space->chain )->size = size;
3245
- fsp_header_init (space, size, &mtr);
3246
-
3247
- mtr.commit ();
3248
- }
3249
-
3250
2959
#ifdef UNIV_DEBUG
3251
2960
/* * Increase redo skipped count for a tablespace.
3252
2961
@param[in] id space id */
0 commit comments