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

Function find_key_block

mysys/mf_keycache.c:1630–2356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1628*/
1629
1630static BLOCK_LINK *find_key_block(KEY_CACHE *keycache,
1631 File file, my_off_t filepos,
1632 int init_hits_left,
1633 int wrmode, int *page_st)
1634{
1635 HASH_LINK *hash_link;
1636 BLOCK_LINK *block;
1637 int error= 0;
1638 int page_status;
1639
1640 DBUG_ENTER("find_key_block");
1641 KEYCACHE_THREAD_TRACE("find_key_block:begin");
1642 DBUG_PRINT("enter", ("fd: %d pos: %lu wrmode: %d",
1643 file, (ulong) filepos, wrmode));
1644 KEYCACHE_DBUG_PRINT("find_key_block", ("fd: %d pos: %lu wrmode: %d",
1645 file, (ulong) filepos,
1646 wrmode));
1647#if !defined(DBUG_OFF) && defined(EXTRA_DEBUG)
1648 DBUG_EXECUTE("check_keycache2",
1649 test_key_cache(keycache, "start of find_key_block", 0););
1650#endif
1651
1652restart:
1653 /*
1654 If the flush phase of a resize operation fails, the cache is left
1655 unusable. This will be detected only after "goto restart".
1656 */
1657 if (!keycache->can_be_used)
1658 DBUG_RETURN(0);
1659
1660 /*
1661 Find the hash_link for the requested file block (file, filepos). We
1662 do always get a hash_link here. It has registered our request so
1663 that no other thread can use it for another file block until we
1664 release the request (which is done by remove_reader() usually). The
1665 hash_link can have a block assigned to it or not. If there is a
1666 block, it may be assigned to this hash_link or not. In cases where a
1667 block is evicted from the cache, it is taken from the LRU ring and
1668 referenced by the new hash_link. But the block can still be assigned
1669 to its old hash_link for some time if it needs to be flushed first,
1670 or if there are other threads still reading it.
1671
1672 Summary:
1673 hash_link is always returned.
1674 hash_link->block can be:
1675 - NULL or
1676 - not assigned to this hash_link or
1677 - assigned to this hash_link. If assigned, the block can have
1678 - invalid data (when freshly assigned) or
1679 - valid data. Valid data can be
1680 - changed over the file contents (dirty) or
1681 - not changed (clean).
1682 */
1683 hash_link= get_hash_link(keycache, file, filepos);
1684 DBUG_ASSERT((hash_link->file == file) && (hash_link->diskpos == filepos));
1685
1686 page_status= -1;
1687 if ((block= hash_link->block) &&

Callers 3

key_cache_readFunction · 0.85
key_cache_insertFunction · 0.85
key_cache_writeFunction · 0.85

Calls 15

test_key_cacheFunction · 0.85
get_hash_linkFunction · 0.85
unlink_hashFunction · 0.85
link_into_queueFunction · 0.85
reg_requestsFunction · 0.85
wait_on_queueFunction · 0.85
fail_blockFunction · 0.85
remove_readerFunction · 0.85
unreg_requestFunction · 0.85
free_blockFunction · 0.85
link_to_file_listFunction · 0.85

Tested by

no test coverage detected