|
| 1 | +LevelDB overview |
| 2 | +================= |
| 3 | + |
| 4 | +LevelDB is a fast, embeddable key–value storage library created at Google. It provides an ordered mapping from arbitrary byte-string keys to byte-string values, optimized for high write throughput and efficient range queries. |
| 5 | + |
| 6 | +Why Bitcoin Knots uses LevelDB |
| 7 | +------------------------------ |
| 8 | +Bitcoin Knots (like Bitcoin Core) embeds LevelDB to persist several on-disk databases, for example: |
| 9 | +- The chainstate (UTXO set) and block index metadata |
| 10 | +- Various indexes and caches used by optional components |
| 11 | + |
| 12 | +LevelDB’s log-structured merge-tree (LSM) design offers: |
| 13 | +- High write performance with sequential disk access patterns |
| 14 | +- Background compaction for space and read amplification control |
| 15 | +- Forward/backward iteration and efficient prefix/range scans |
| 16 | + |
| 17 | +Key characteristics |
| 18 | +------------------- |
| 19 | +- API: Put(key, value), Get(key), Delete(key); batched atomic writes via WriteBatch; consistent point-in-time Snapshots; forward/backward Iterators. |
| 20 | +- Ordering: Keys are stored in sorted order (default bytewise comparator; custom comparators supported). |
| 21 | +- Compression: Supports Snappy compression when available. |
| 22 | +- Embedding: Single-process library; there is no built-in client/server mode. |
| 23 | + |
| 24 | +Limitations to be aware of |
| 25 | +-------------------------- |
| 26 | +- Not a SQL or relational database; no secondary indexes or query language. |
| 27 | +- Single-process access to a given database path at a time. |
| 28 | +- Behavior and performance can be sensitive to filesystem and OS parameters (e.g., open file limits). |
| 29 | + |
| 30 | +Project references and further reading |
| 31 | +-------------------------------------- |
| 32 | +- Upstream LevelDB documentation: src/leveldb/README.md (bundled) and https://github.com/google/leveldb/blob/master/doc/index.md |
| 33 | +- Bitcoin developer notes on "Upgrading LevelDB": doc/developer-notes.md#upgrading-leveldb — important considerations for compatibility, file descriptor usage, and consensus safety when changing LevelDB versions. |
| 34 | + |
| 35 | +Notes for contributors |
| 36 | +---------------------- |
| 37 | +- Any upgrades to the embedded LevelDB subtree must follow the guidance in the developer notes to avoid consensus-affecting changes and resource limit issues. |
| 38 | +- CRC32C acceleration used by LevelDB is provided via src/crc32c; see developer notes for details. |
0 commit comments