368
374
/******************************************************************//**
369
Invalidates all pages belonging to a given tablespace inside a specific
375
Remove all dirty pages belonging to a given tablespace inside a specific
370
376
buffer pool instance when we are deleting the data file(s) of that
377
tablespace. The pages still remain a part of LRU and are evicted from
378
the list as they age towards the tail of the LRU. */
374
buf_LRU_invalidate_tablespace_buf_pool_instance(
375
/*============================================*/
381
buf_LRU_remove_dirty_pages_for_tablespace(
382
/*======================================*/
376
383
buf_pool_t* buf_pool, /*!< buffer pool instance */
377
384
ulint id) /*!< in: space id */
379
386
buf_page_t* bpage;
383
391
//buf_pool_mutex_enter(buf_pool);
384
392
mutex_enter(&buf_pool->LRU_list_mutex);
385
393
rw_lock_x_lock(&buf_pool->page_hash_latch);
394
buf_flush_list_mutex_enter(buf_pool);
387
396
all_freed = TRUE;
389
bpage = UT_LIST_GET_LAST(buf_pool->LRU);
398
for (bpage = UT_LIST_GET_LAST(buf_pool->flush_list), i = 0;
399
bpage != NULL; ++i) {
391
while (bpage != NULL) {
392
401
buf_page_t* prev_bpage;
393
402
mutex_t* block_mutex = NULL;
395
404
ut_a(buf_page_in_file(bpage));
397
prev_bpage = UT_LIST_GET_PREV(LRU, bpage);
406
prev_bpage = UT_LIST_GET_PREV(flush_list, bpage);
399
408
/* bpage->space and bpage->io_fix are protected by
400
buf_pool_mutex and block_mutex. It is safe to check
401
them while holding buf_pool_mutex only. */
409
buf_pool->mutex and block_mutex. It is safe to check
410
them while holding buf_pool->mutex only. */
403
412
if (buf_page_get_space(bpage) != id) {
404
413
/* Skip this block, as it does not belong to
412
421
all_freed = FALSE;
415
block_mutex = buf_page_get_mutex_enter(bpage);
418
/* It may be impossible case...
419
Something wrong, so will be scan_again */
425
if (bpage->buf_fix_count > 0) {
427
mutex_exit(block_mutex);
428
/* We cannot remove this page during
429
this scan yet; maybe the system is
430
currently reading it in, or flushing
431
the modifications to the file */
439
ut_ad(mutex_own(block_mutex));
442
if (buf_debug_prints) {
444
"Dropping space %lu page %lu\n",
445
(ulong) buf_page_get_space(bpage),
446
(ulong) buf_page_get_page_no(bpage));
449
if (buf_page_get_state(bpage) != BUF_BLOCK_FILE_PAGE) {
450
/* This is a compressed-only block
451
descriptor. Do nothing. */
452
} else if (((buf_block_t*) bpage)->is_hashed) {
456
//buf_pool_mutex_exit(buf_pool);
457
mutex_exit(&buf_pool->LRU_list_mutex);
458
rw_lock_x_unlock(&buf_pool->page_hash_latch);
460
zip_size = buf_page_get_zip_size(bpage);
461
page_no = buf_page_get_page_no(bpage);
463
mutex_exit(block_mutex);
465
/* Note that the following call will acquire
466
an S-latch on the page */
468
btr_search_drop_page_hash_when_freed(
469
id, zip_size, page_no);
473
if (bpage->oldest_modification != 0) {
475
buf_flush_remove(bpage);
478
/* Remove from the LRU list. */
480
if (buf_LRU_block_remove_hashed_page(bpage, TRUE)
481
!= BUF_BLOCK_ZIP_FREE) {
482
buf_LRU_block_free_hashed_page((buf_block_t*) bpage, TRUE);
483
mutex_exit(block_mutex);
485
/* The block_mutex should have been released
486
by buf_LRU_block_remove_hashed_page() when it
487
returns BUF_BLOCK_ZIP_FREE. */
488
ut_ad(block_mutex == &buf_pool->zip_mutex);
489
ut_ad(!mutex_own(block_mutex));
425
/* We have to release the flush_list_mutex to obey the
426
latching order. We are however guaranteed that the page
427
will stay in the flush_list because buf_flush_remove()
428
needs buf_pool->mutex as well. */
429
buf_flush_list_mutex_exit(buf_pool);
430
block_mutex = buf_page_get_mutex_enter(bpage);
433
/* It may be impossible case...
434
Something wrong, so will be scan_again */
439
if (bpage->buf_fix_count > 0) {
440
mutex_exit(block_mutex);
441
buf_flush_list_mutex_enter(buf_pool);
443
/* We cannot remove this page during
444
this scan yet; maybe the system is
445
currently reading it in, or flushing
446
the modifications to the file */
452
ut_ad(bpage->oldest_modification != 0);
454
buf_flush_remove(bpage);
456
mutex_exit(block_mutex);
457
buf_flush_list_mutex_enter(buf_pool);
492
459
bpage = prev_bpage;
465
/* Every BUF_LRU_DROP_SEARCH_SIZE iterations in the
466
loop we release buf_pool->mutex to let other threads
468
if (i < BUF_LRU_DROP_SEARCH_SIZE) {
472
/* We IO-fix the block to make sure that the block
473
stays in its position in the flush_list. */
474
if (buf_page_get_io_fix(bpage) != BUF_IO_NONE) {
475
/* Block is already IO-fixed. We don't
476
want to change the value. Lets leave
481
buf_flush_list_mutex_exit(buf_pool);
482
block_mutex = buf_page_get_mutex(bpage);
483
mutex_enter(block_mutex);
484
buf_page_set_sticky(bpage);
485
mutex_exit(block_mutex);
487
/* Now it is safe to release the buf_pool->mutex. */
488
//buf_pool_mutex_exit(buf_pool);
489
mutex_exit(&buf_pool->LRU_list_mutex);
490
rw_lock_x_unlock(&buf_pool->page_hash_latch);
493
//buf_pool_mutex_enter(buf_pool);
494
mutex_enter(&buf_pool->LRU_list_mutex);
495
rw_lock_x_lock(&buf_pool->page_hash_latch);
498
mutex_enter(block_mutex);
499
buf_page_unset_sticky(bpage);
500
mutex_exit(block_mutex);
502
buf_flush_list_mutex_enter(buf_pool);
503
ut_ad(bpage->in_flush_list);
495
//buf_pool_mutex_exit(buf_pool);
508
// buf_pool_mutex_exit(buf_pool);
496
509
mutex_exit(&buf_pool->LRU_list_mutex);
497
510
rw_lock_x_unlock(&buf_pool->page_hash_latch);
511
buf_flush_list_mutex_exit(buf_pool);
513
ut_ad(buf_flush_validate(buf_pool));
499
515
if (!all_freed) {
500
516
os_thread_sleep(20000);