How google/leveldb works
LevelDB is an embedded, ordered key-value storage library. Applications open a database, then read, write or delete keys; writes may be batched, reads may use snapshots or iterators, and background compaction maintains the on-disk structure. The map highlights the DB implementation, its memory/log and versioned-table storage stages, and the table/block layer. It also includes the C interface and configurable environment. Edges reflect README statements or SOURCE INDEX references; where the index shows a dependency but not the exact runtime call, the relationship is conservative.
Main entry points: db_impl.cc DB implementation · version_set.cc Versions and compaction · env.h Environment interface · db.h C++ DB API
Components 22
Public interfaces
- C++ DB API
include/leveldb/db.h - C API
db/c.cc - DB options
include/leveldb/options.h
Database engine
- DB implementation
db/db_impl.cc - Atomic batches
db/write_batch.cc - DB iterators
db/db_iter.cc - Internal key format
db/dbformat.h - Memtable
db/memtable.cc - Write-ahead log
db/log_writer.cc - Log recovery
db/log_reader.cc
Persistent storage
- Versions and compaction
db/version_set.cc - Table cache
db/table_cache.cc - Sorted table reader
table/table.cc - Sorted table writer
table/table_builder.cc - Data blocks
table/block.cc - Block encoding
table/block_builder.cc - Block cache
util/cache.cc
Platform services
- Environment interface
include/leveldb/env.h - POSIX environment
util/env_posix.cc - Windows environment
util/env_windows.cc - In-memory environment
helpers/memenv/memenv.cc
Other components
- Application
Connections 23
- Application → C++ DB API: uses
README.md - Application → C API: uses
db/c.cc - C++ DB API → DB implementation: implemented by
db/db_impl.cc - C API → DB implementation: delegates to
db/c.cc - C++ DB API → DB options: accepts
include/leveldb/db.h - DB implementation → Memtable: uses
db/db_impl.cc - DB implementation → Atomic batches: applies
db/db_impl.cc - DB implementation → DB iterators: creates
db/db_impl.cc - DB implementation → Internal key format: encodes keys
db/db_impl.cc - DB implementation → Write-ahead log: appends log
db/db_impl.cc - DB implementation → Log recovery: recovers from
db/db_impl.cc - DB implementation → Versions and compaction: manages versions
db/db_impl.cc - Versions and compaction → Table cache: reads tables
db/version_set.cc - Versions and compaction → Sorted table writer: builds tables
db/version_set.cc - Versions and compaction → DB iterators: merges iterators
db/version_set.cc - Table cache → Sorted table reader: opens tables
- Sorted table reader → Data blocks: reads blocks
table/table.cc - Sorted table writer → Block encoding: encodes blocks
table/table_builder.cc - Sorted table reader → Block cache: uses cache
table/table.cc - DB implementation → Environment interface: uses
db/db_impl.cc - POSIX environment → Environment interface: implements
util/env_posix.cc - Windows environment → Environment interface: implements
util/env_windows.cc - In-memory environment → Environment interface: implements
helpers/memenv/memenv.cc