Configs2026年9月11日·1 分钟阅读

goleveldb — Pure Go Implementation of LevelDB Key-Value Store

Embed a fast, sorted key-value storage engine in your Go application without any CGo dependencies.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
goleveldb
直接安装命令
npx -y tokrepo@latest install 07308605-ade6-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

goleveldb is a pure Go implementation of Google's LevelDB key-value store. It provides an embedded, persistent, sorted key-value database that compiles and runs anywhere Go does, with no CGo or external C library required.

What goleveldb Does

  • Stores key-value pairs sorted by key in a persistent on-disk database
  • Supports Get, Put, Delete, and ordered iteration over key ranges
  • Provides atomic batch writes for grouping multiple operations
  • Implements LSM-tree (Log-Structured Merge-tree) storage for write-optimized workloads
  • Offers Bloom filters, LRU caches, and compression to tune read/write performance

Architecture Overview

goleveldb follows the classic LSM-tree design. Writes go to an in-memory table (memtable) backed by a write-ahead log for durability. When the memtable fills, it is flushed to a sorted SSTable file on disk. Background compaction merges SSTables across levels to reclaim space and maintain read performance. The implementation mirrors the original LevelDB design but is written entirely in Go.

Self-Hosting & Configuration

  • Add to your project: go get github.com/syndtr/goleveldb/leveldb
  • Open a database with leveldb.OpenFile(path, opts) — the directory is created automatically
  • Tune write buffer size, compaction thresholds, and block cache size via opt.Options
  • Enable Bloom filters to reduce disk reads on key lookups
  • Use snapshots for consistent point-in-time reads during iteration

Key Features

  • Pure Go with zero CGo dependencies, cross-compiles to any Go target
  • Sorted key ordering enables efficient range scans and prefix iteration
  • Batch API for atomic multi-key writes with a single fsync
  • Built-in Snappy compression reduces on-disk storage size
  • Thread-safe: concurrent reads and writes from multiple goroutines

Comparison with Similar Tools

  • BadgerDB — Go-native KV store with value separation for large values; goleveldb stores everything in SSTables
  • BoltDB / bbolt — B+ tree design optimized for reads; goleveldb's LSM-tree favors write-heavy workloads
  • Pebble — CockroachDB's LevelDB-inspired store with advanced compaction; heavier but more feature-rich
  • Original LevelDB (C++) — the reference implementation; goleveldb avoids CGo at the cost of some performance

FAQ

Q: Is goleveldb production-ready? A: Yes. It has been used in production by many Go projects, including early versions of go-ethereum.

Q: How does performance compare to the original C++ LevelDB? A: Throughput is somewhat lower due to Go runtime overhead, but the difference is negligible for most workloads. The main advantage is CGo-free compilation.

Q: Can multiple processes access the same database? A: No. LevelDB uses file-level locking for single-process access only. Use a server wrapper for multi-process scenarios.

Q: What license does goleveldb use? A: BSD 2-Clause license.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产