使用的调用链路
db.get
先查memtable,找到直接返回
memtable找不到再请求table_cache的Get,找row cache,row cache找不到再找下面block cache;
Rocksdb lru cache的实现:
shard分多个桶,
每个桶:链表+map
初始化
LRUCache::LRUCache(size_t capacity, int num_shard_bits, bool strict_capacity_limit, double high_pri_pool_ratio, std::shared_ptr<MemoryAllocator> allocator, bool use_adaptive_mutex)
num_shard_bits 未设置的话,默认的计算: 输入参数是用户设置的容量单位(B) 最小512KB;
int GetDefaultCacheShardBits(size_t capacity) {
int num_shard_bits = 0;
size_t min_shard_size = 512L * 1024L; // Every shard is at least 512KB.
size_t num_shards = capacity / min_shard_size;
while (num_shards >>= 1) {
if (++num_shard_bits >= 6) {
// No more than 6.
return num_shard_bits;
}
}
return num_shard_bits;
}