rocksDB的LRU cache 三两说

先讲单shard的LRU cache,主要有3个数据结构
LRUHandle 作为LRU的一个个体元素,其数据结构如下,next,prev是在LRU的双向列表的next和prev,next_hash是在hash_table用来解决拉链地址冲突。key_data[1]被分配了连续的地址,用来存储key值

struct LRUHandle {
  void* value;
  void (*deleter)(const Slice&, void* value);
  LRUHandle* next_hash;
  LRUHandle* next;
  LRUHandle* prev;
  size_t charge;  // TODO(opt): Only allow uint32_t?
  size_t key_length;
  // The hash of key(). Used for fast sharding and comparisons.
  uint32_t hash;
  // The number of external refs to this entry. The cache itself is not counted.
  uint32_t refs;

  enum Flags : uint8_t {
    // Whether this entry is referenced by the hash table.
    IN_CACHE = (1 << 0),
    // Whether this entry is high priority entry.
    IS_HIGH_PRI = (1 << 1),
    // Whether this entry is in high-pri pool.
    IN_HIGH_PRI_POOL = (1 << 2),
    // Wwhether this entry has had any lookups (hits).
    HAS_HIT = (1 << 3),
  };
   char key_data[1];

LRUHandleTable是个自建的Hash Table,通过key用来快速定位到LRUHandle,从而得到prev 还是next

class LRUHandleTable {
}

LRUCacheShard是LRU的核心数据结构, 包括了insert ,LookUp数据结构

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值