实现个 Buffer Pool(Extendible Hasing/LRUK Replacer)

· Technology

Private Code

Desc

Extendible Hashing

Extendible Hashing (Dynamic approach to DBMS) - GeeksforGeeks

Insert 的时候,当 global depth 和 bucket local depth 一样时,扩容时应该将新的 directory idx 一个个指向从老的 idx 顺序下来赋值 bucket。

在将新的桶赋值给 directory 时找新 idx 应该是(depth: 新加的一位应该为 1)

将操作的 bucket 老的元素重新插入

  /**
   *
   * TODO(P1): Add implementation
   *
   * @brief Insert the given key-value pair into the hash table.
   * If a key already exists, the value should be updated.
   * If the bucket is full and can't be inserted, do the following steps before retrying:
   *    1. If the local depth of the bucket is equal to the global depth,
   *        increment the global depth and double the size of the directory.
   *    2. Increment the local depth of the bucket.
   *    3. Split the bucket and redistribute directory pointers & the kv pairs in the bucket.
   *
   * @param key The key to be inserted.
   * @param value The value to be inserted.
   */
  void Insert(const K &key, const V &value) override;

LRUKReplacer

LRU-cache Leetcode
The LRU-K page replacement algorithm for database disk buffering | ACM SIGMOD Record

一个 unordered_map 记录 frame_id 和对应的信息(evictable, access_times)

可以用于一个 set 来快速判断某个 frame_id 是否是 evictable 的

Buffer Pool

揭开 Buffer Pool 的面纱 | 小林 coding

在上面的 extendible hash 实现又留下了坑,哭,还是自己得多写测试用例呀。
image

Comments (0)

    Send comment

    Markdown supported. Please keep comments clean.