MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / flush_key_blocks_int

Function flush_key_blocks_int

mysys/mf_keycache.c:3587–4018  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3585*/
3586
3587static 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;

Callers 2

flush_key_blocksFunction · 0.85
flush_all_key_blocksFunction · 0.85

Calls 11

test_key_cacheFunction · 0.85
my_mallocFunction · 0.85
reg_requestsFunction · 0.85
unreg_requestFunction · 0.85
flush_cached_blocksFunction · 0.85
link_to_file_listFunction · 0.85
free_blockFunction · 0.85
unlink_changedFunction · 0.85
link_changedFunction · 0.85
wait_on_queueFunction · 0.85
my_freeFunction · 0.85

Tested by

no test coverage detected