leveldb 源码阅读,分析 DB 运作流程与 WAL、SSTable 等文件格式与 Compaction 过程。

Overview

leveldb 源码阅读

1. Build && Install && Debug

leveldb 本身是一个 Key-Value 存储引擎,因此并没有提供 main 入口函数,所以需要自行添加。笔者将其放到了 debug/leveldb_debug.cc 文件中,并在 CMakeLists.txtx 中将其加入:

  leveldb_test("util/env_test.cc")
  leveldb_test("util/status_test.cc")
  leveldb_test("util/no_destructor_test.cc")
  
  if(NOT BUILD_SHARED_LIBS)
    leveldb_test("debug/leveldb_debug.cc")    # 个人可执行文件
    leveldb_test("db/autocompact_test.cc")
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug .. && cmake --build .
make && make install
gdb leveldb_debug   # 此时 leveldb_debug 就在 build 目录下,可直接进行 gdb 调试

如果使用 CLion 的话,可以直接对 leveldb_debug.cc 进行 debug,比 gdb 要更方便一些。

2. leveldb 核心流程梳理

  1. leveldb 概述与 LSM-Tree
  2. leveldb 中的常用数据结构
  3. leveldb 中的 varint 与 Key 组成
  4. leveldb Key-Value 写入流程分析
  5. leveldb 预写日志格式及其读写流程
  6. SSTable(01)—概览与 Data Block
  7. SSTable(02)—Bloom Filter 与 Meta Block
  8. SSTable(03)—SSTable 之索引
  9. SSTable(04)—Table Builder
  10. Compaction(01)—何时触发 Compaction ?
  11. Compaction(02)—Minor Compaction
  12. Compaction(03)—Major Compaction
You might also like...
Comments
  • 关于 std::string

    关于 std::string

    https://github.com/SmartKeyerror/reading-source-code-of-leveldb-1.23/blob/d0067cb72506edb9865980834384d2ab2b9bf900/debug/articles/02-data-structure/README.md?plain=1#L7 现在 C++20 有 std::string::starts_with 了.

    文中提到的 Slice 看上去像 C++17 引入的 std::string_view, 也具有了 starts_with/remove_prefix 这类方法.

    opened by ShenMian 1
Owner
SmartKeyerror
知其然,知其所以然
SmartKeyerror
LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values. Authors: Sanjay Ghem

Google 31.6k Jan 7, 2023
Login & Registration system using leveldb in C++

LoginAndRegistration ?? Clone repo git clone https://github.com/dev-cetus/LoginAndRegistration.git cd LoginAndRegistration ?? Install leveldb via vcp

Cetus 3 Nov 23, 2022