| 3585 | */ |
| 3586 | |
| 3587 | static int flush_key_blocks_int(KEY_CACHE *keycache, |
| 3588 | File file, enum flush_type type) |
| 3589 | { |
| 3590 | BLOCK_LINK *cache_buff[FLUSH_CACHE],**cache; |
| 3591 | int last_errno= 0; |
| 3592 | int last_errcnt= 0; |
| 3593 | DBUG_ENTER("flush_key_blocks_int"); |
| 3594 | DBUG_PRINT("enter",("file: %d blocks_used: %lu blocks_changed: %lu", |
| 3595 | file, keycache->blocks_used, keycache->blocks_changed)); |
| 3596 | |
| 3597 | #if !defined(DBUG_OFF) && defined(EXTRA_DEBUG) |
| 3598 | DBUG_EXECUTE("check_keycache", |
| 3599 | test_key_cache(keycache, "start of flush_key_blocks", 0);); |
| 3600 | #endif |
| 3601 | |
| 3602 | cache= cache_buff; |
| 3603 | if (keycache->disk_blocks > 0 && |
| 3604 | (!my_disable_flush_key_blocks || type != FLUSH_KEEP)) |
| 3605 | { |
| 3606 | /* Key cache exists and flush is not disabled */ |
| 3607 | int error= 0; |
| 3608 | uint count= FLUSH_CACHE; |
| 3609 | BLOCK_LINK **pos,**end; |
| 3610 | BLOCK_LINK *first_in_switch= NULL; |
| 3611 | BLOCK_LINK *last_in_flush; |
| 3612 | BLOCK_LINK *last_for_update; |
| 3613 | BLOCK_LINK *block, *next; |
| 3614 | #if defined(KEYCACHE_DEBUG) |
| 3615 | uint cnt=0; |
| 3616 | #endif |
| 3617 | |
| 3618 | if (type != FLUSH_IGNORE_CHANGED) |
| 3619 | { |
| 3620 | /* |
| 3621 | Count how many key blocks we have to cache to be able |
| 3622 | to flush all dirty pages with minimum seek moves |
| 3623 | */ |
| 3624 | count= 0; |
| 3625 | for (block= keycache->changed_blocks[FILE_HASH(file)] ; |
| 3626 | block ; |
| 3627 | block= block->next_changed) |
| 3628 | { |
| 3629 | if ((block->hash_link->file == file) && |
| 3630 | !(block->status & BLOCK_IN_FLUSH)) |
| 3631 | { |
| 3632 | count++; |
| 3633 | KEYCACHE_DBUG_ASSERT(count<= keycache->blocks_used); |
| 3634 | } |
| 3635 | } |
| 3636 | /* |
| 3637 | Allocate a new buffer only if its bigger than the one we have. |
| 3638 | Assure that we always have some entries for the case that new |
| 3639 | changed blocks appear while we need to wait for something. |
| 3640 | */ |
| 3641 | if ((count > FLUSH_CACHE) && |
| 3642 | !(cache= (BLOCK_LINK**) my_malloc(sizeof(BLOCK_LINK*)*count, |
| 3643 | MYF(0)))) |
| 3644 | cache= cache_buff; |
no test coverage detected