69
69
/** When dropping the search hash index entries before deleting an ibd
70
70
file, we build a local array of pages belonging to that tablespace
71
in the buffer pool. Following is the size of that array. */
72
#define BUF_LRU_DROP_SEARCH_HASH_SIZE 1024
71
in the buffer pool. Following is the size of that array.
72
We also release buf_pool->mutex after scanning this many pages of the
73
flush_list when dropping a table. This is to ensure that other threads
74
are not blocked for extended period of time when using very large
76
#define BUF_LRU_DROP_SEARCH_SIZE 1024
74
78
/** If we switch on the InnoDB monitor because there are too few available
75
79
frames in the buffer pool, we set this to TRUE */
333
337
/******************************************************************//**
334
Invalidates all pages belonging to a given tablespace inside a specific
338
Remove all dirty pages belonging to a given tablespace inside a specific
335
339
buffer pool instance when we are deleting the data file(s) of that
340
tablespace. The pages still remain a part of LRU and are evicted from
341
the list as they age towards the tail of the LRU. */
339
buf_LRU_invalidate_tablespace_buf_pool_instance(
340
/*============================================*/
344
buf_LRU_remove_dirty_pages_for_tablespace(
345
/*======================================*/
341
346
buf_pool_t* buf_pool, /*!< buffer pool instance */
342
347
ulint id) /*!< in: space id */
344
349
buf_page_t* bpage;
348
354
buf_pool_mutex_enter(buf_pool);
355
buf_flush_list_mutex_enter(buf_pool);
350
357
all_freed = TRUE;
352
bpage = UT_LIST_GET_LAST(buf_pool->LRU);
359
for (bpage = UT_LIST_GET_LAST(buf_pool->flush_list), i = 0;
360
bpage != NULL; ++i) {
354
while (bpage != NULL) {
355
362
buf_page_t* prev_bpage;
356
363
mutex_t* block_mutex = NULL;
358
365
ut_a(buf_page_in_file(bpage));
360
prev_bpage = UT_LIST_GET_PREV(LRU, bpage);
367
prev_bpage = UT_LIST_GET_PREV(list, bpage);
362
369
/* bpage->space and bpage->io_fix are protected by
363
buf_pool_mutex and block_mutex. It is safe to check
364
them while holding buf_pool_mutex only. */
370
buf_pool->mutex and block_mutex. It is safe to check
371
them while holding buf_pool->mutex only. */
366
373
if (buf_page_get_space(bpage) != id) {
367
374
/* Skip this block, as it does not belong to
375
382
all_freed = FALSE;
378
block_mutex = buf_page_get_mutex(bpage);
379
mutex_enter(block_mutex);
381
if (bpage->buf_fix_count > 0) {
383
mutex_exit(block_mutex);
384
/* We cannot remove this page during
385
this scan yet; maybe the system is
386
currently reading it in, or flushing
387
the modifications to the file */
395
ut_ad(mutex_own(block_mutex));
398
if (buf_debug_prints) {
400
"Dropping space %lu page %lu\n",
401
(ulong) buf_page_get_space(bpage),
402
(ulong) buf_page_get_page_no(bpage));
405
if (buf_page_get_state(bpage) != BUF_BLOCK_FILE_PAGE) {
406
/* This is a compressed-only block
407
descriptor. Do nothing. */
408
} else if (((buf_block_t*) bpage)->is_hashed) {
412
buf_pool_mutex_exit(buf_pool);
414
zip_size = buf_page_get_zip_size(bpage);
415
page_no = buf_page_get_page_no(bpage);
417
mutex_exit(block_mutex);
419
/* Note that the following call will acquire
420
an S-latch on the page */
422
btr_search_drop_page_hash_when_freed(
423
id, zip_size, page_no);
427
if (bpage->oldest_modification != 0) {
429
buf_flush_remove(bpage);
432
/* Remove from the LRU list. */
434
if (buf_LRU_block_remove_hashed_page(bpage, TRUE)
435
!= BUF_BLOCK_ZIP_FREE) {
436
buf_LRU_block_free_hashed_page((buf_block_t*) bpage);
437
mutex_exit(block_mutex);
439
/* The block_mutex should have been released
440
by buf_LRU_block_remove_hashed_page() when it
441
returns BUF_BLOCK_ZIP_FREE. */
442
ut_ad(block_mutex == &buf_pool->zip_mutex);
443
ut_ad(!mutex_own(block_mutex));
386
/* We have to release the flush_list_mutex to obey the
387
latching order. We are however guaranteed that the page
388
will stay in the flush_list because buf_flush_remove()
389
needs buf_pool->mutex as well. */
390
buf_flush_list_mutex_exit(buf_pool);
391
block_mutex = buf_page_get_mutex(bpage);
392
mutex_enter(block_mutex);
394
if (bpage->buf_fix_count > 0) {
395
mutex_exit(block_mutex);
396
buf_flush_list_mutex_enter(buf_pool);
398
/* We cannot remove this page during
399
this scan yet; maybe the system is
400
currently reading it in, or flushing
401
the modifications to the file */
407
ut_ad(bpage->oldest_modification != 0);
409
buf_flush_remove(bpage);
411
mutex_exit(block_mutex);
412
buf_flush_list_mutex_enter(buf_pool);
446
414
bpage = prev_bpage;
420
/* Every BUF_LRU_DROP_SEARCH_SIZE iterations in the
421
loop we release buf_pool->mutex to let other threads
423
if (i < BUF_LRU_DROP_SEARCH_SIZE) {
427
/* We IO-fix the block to make sure that the block
428
stays in its position in the flush_list. */
429
if (buf_page_get_io_fix(bpage) != BUF_IO_NONE) {
430
/* Block is already IO-fixed. We don't
431
want to change the value. Lets leave
436
buf_flush_list_mutex_exit(buf_pool);
437
block_mutex = buf_page_get_mutex(bpage);
438
mutex_enter(block_mutex);
439
buf_page_set_sticky(bpage);
440
mutex_exit(block_mutex);
442
/* Now it is safe to release the buf_pool->mutex. */
443
buf_pool_mutex_exit(buf_pool);
445
buf_pool_mutex_enter(buf_pool);
447
mutex_enter(block_mutex);
448
buf_page_unset_sticky(bpage);
449
mutex_exit(block_mutex);
451
buf_flush_list_mutex_enter(buf_pool);
452
ut_ad(bpage->in_flush_list);
449
457
buf_pool_mutex_exit(buf_pool);
458
buf_flush_list_mutex_exit(buf_pool);
460
ut_ad(buf_flush_validate(buf_pool));
451
462
if (!all_freed) {
452
463
os_thread_sleep(20000);