Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsSep 11, 2026·3 min de lecture

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.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
goleveldb
Commande d'installation directe
npx -y tokrepo@latest install 07308605-ade6-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en 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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires