# reading-source-code-of-leveldb-1.23 **Repository Path**: kaley/reading-source-code-of-leveldb-1.23 ## Basic Information - **Project Name**: reading-source-code-of-leveldb-1.23 - **Description**: leveldb 源码阅读,分析 DB 运作流程与 WAL、SSTable 等文件格式与 Compaction 过程。 - **Primary Language**: Unknown - **License**: BSD-2-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-09-26 - **Last Updated**: 2026-07-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## leveldb 源码阅读 ![](leveldb.png) ### 1. Build && Install && Debug leveldb 本身是一个 Key-Value 存储引擎,因此并没有提供 `main` 入口函数,所以需要自行添加。笔者将其放到了 `debug/leveldb_debug.cc` 文件中,并在 `CMakeLists.txtx` 中将其加入: ```bash 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") ``` ```bash 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 中的常用数据结构](/debug/articles/02-data-structure/README.md) 3. [leveldb 中的 varint 与 Key 组成](/debug/articles/03-varint-and-key-format/README.md) 4. [leveldb Key-Value 写入流程分析](/debug/articles/04-write-process/README.md) 5. [leveldb 预写日志格式及其读写流程](/debug/articles/05-WAL/README.md) 6. [SSTable(01)—概览与 Data Block](/debug/articles/06-SSTable-data-block/README.md) 7. [SSTable(02)—Bloom Filter 与 Meta Block](/debug/articles/07-SSTable-meta-block/README.md) 8. [SSTable(03)—SSTable 之索引](/debug/articles/08-SSTable-index/README.md) 9. [SSTable(04)—Table Builder](/debug/articles/09-SSTable-table-builder/README.md) 10. [Compaction(01)—Minor Compaction](/debug/articles/10-minor-compaction/README.md) 11. [leveldb 版本控制概览](/debug/articles/11-version-control-overview/README.md) 12. Compaction(02)—Major Compaction