| 558 | */ |
| 559 | |
| 560 | int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, |
| 561 | size_t use_mem, uint division_limit, |
| 562 | uint age_threshold) |
| 563 | { |
| 564 | int blocks; |
| 565 | DBUG_ENTER("resize_key_cache"); |
| 566 | |
| 567 | if (!keycache->key_cache_inited) |
| 568 | DBUG_RETURN(keycache->disk_blocks); |
| 569 | |
| 570 | if(key_cache_block_size == keycache->key_cache_block_size && |
| 571 | use_mem == keycache->key_cache_mem_size) |
| 572 | { |
| 573 | change_key_cache_param(keycache, division_limit, age_threshold); |
| 574 | DBUG_RETURN(keycache->disk_blocks); |
| 575 | } |
| 576 | |
| 577 | keycache_pthread_mutex_lock(&keycache->cache_lock); |
| 578 | |
| 579 | /* |
| 580 | We may need to wait for another thread which is doing a resize |
| 581 | already. This cannot happen in the MySQL server though. It allows |
| 582 | one resizer only. In set_var.cc keycache->in_init is used to block |
| 583 | multiple attempts. |
| 584 | */ |
| 585 | while (keycache->in_resize) |
| 586 | { |
| 587 | /* purecov: begin inspected */ |
| 588 | wait_on_queue(&keycache->resize_queue, &keycache->cache_lock); |
| 589 | /* purecov: end */ |
| 590 | } |
| 591 | |
| 592 | /* |
| 593 | Mark the operation in progress. This blocks other threads from doing |
| 594 | a resize in parallel. It prohibits new blocks to enter the cache. |
| 595 | Read/write requests can bypass the cache during the flush phase. |
| 596 | */ |
| 597 | keycache->in_resize= 1; |
| 598 | |
| 599 | /* Need to flush only if keycache is enabled. */ |
| 600 | if (keycache->can_be_used) |
| 601 | { |
| 602 | /* Start the flush phase. */ |
| 603 | keycache->resize_in_flush= 1; |
| 604 | |
| 605 | if (flush_all_key_blocks(keycache)) |
| 606 | { |
| 607 | /* TODO: if this happens, we should write a warning in the log file ! */ |
| 608 | keycache->resize_in_flush= 0; |
| 609 | blocks= 0; |
| 610 | keycache->can_be_used= 0; |
| 611 | goto finish; |
| 612 | } |
| 613 | DBUG_ASSERT(cache_empty(keycache)); |
| 614 | |
| 615 | /* End the flush phase. */ |
| 616 | keycache->resize_in_flush= 0; |
| 617 | } |
nothing calls this directly
no test coverage detected