RocksDB/LevelDB inspired key-value database in Go
  • Go 99.4%
  • JavaScript 0.4%
  • Shell 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jackson Owens 2801a3eab3 colblk: add KeyCount, UnsafeBoundaryKeys to KeyspanBlockWriter
Add KeyCount and UnsafeBoundaryKeys methods to the KeyspanBlockWriter. The
KeyCount will be used by the sstable writer to determine whether a range
deletion or range key block needs to be serialized at all. The
UnsafeBoundaryKeys method will be used to determine the smallest and largest
rangedel/rangekey keys within a table.
2024-08-30 09:34:01 -04:00
.github github: don't use -v flag for windows test run 2024-06-21 09:30:58 -07:00
batchrepr colblk: add UintBuilder, DeltaEncoding 2024-07-10 12:15:21 -04:00
bloom *: use Go 1.21 new primitives: min, max, clear 2023-10-30 14:26:33 -04:00
cmd/pebble Revert "cmd/pebble: use zstd in Pebble nightly benchmarks" 2024-06-24 13:04:38 -04:00
docs docs/rfc: add RFC for point tombstone density compaction heuristic 2024-08-19 12:01:00 -04:00
internal treeprinter: fix license 2024-08-27 13:42:41 -07:00
metamorphic vfs: redesign MemFS strict mode 2024-08-26 15:07:05 -07:00
objstorage vfs: redesign MemFS strict mode 2024-08-26 15:07:05 -07:00
rangekey pebble: Export keyspan.Fragmenter 2023-08-11 10:39:41 -04:00
record vfs: add write category during file creation 2024-04-08 15:12:02 -04:00
replay compact: add point tombstone density compaction heuristic 2024-08-14 11:38:51 -04:00
scripts github: add nightly stress action 2024-01-08 16:22:50 -08:00
sstable colblk: add KeyCount, UnsafeBoundaryKeys to KeyspanBlockWriter 2024-08-30 09:34:01 -04:00
testdata vfs: redesign MemFS strict mode 2024-08-26 15:07:05 -07:00
tool sstable: avoid repetition in sstable parsing error messages 2024-08-29 11:12:26 -04:00
vfs vfs: workaround for a maps.Clone bug 2024-08-28 10:48:46 -07:00
wal wal: ensure last record.LogWriter is closed to avoid spurious errors on open 2024-08-28 15:13:52 -04:00
.editorconfig *: add .editorconfig 2021-11-20 05:20:35 +00:00
.gitignore Makefile: add gen-bazel target 2024-06-24 08:17:36 -07:00
batch.go db: strictly enforce prefix in [flushable]BatchIter.SeekPrefixGE 2024-07-26 17:26:42 -04:00
batch_test.go db: store *Comparer on Batch 2024-07-26 17:26:42 -04:00
cache.go *: apply Go 1.19 gofmt 2023-01-09 12:42:38 -05:00
checkpoint.go db: fix Open issue with single-item relative paths 2024-08-13 16:07:31 -04:00
checkpoint_test.go vfs: redesign MemFS strict mode 2024-08-26 15:07:05 -07:00
commit.go base: add SeqNum type 2024-06-22 07:47:58 -07:00
commit_test.go base: clean up seq num constants 2024-06-25 15:47:32 -07:00
compaction.go sstable: convert RawWriter into an interface 2024-08-23 18:55:36 -04:00
compaction_picker.go compact: add point tombstone density compaction heuristic 2024-08-14 11:38:51 -04:00
compaction_picker_test.go compact: add point tombstone density compaction heuristic 2024-08-14 11:38:51 -04:00
compaction_test.go db: plumb context through ingest methods 2024-08-13 13:33:33 -07:00
comparer.go base: add CompareSuffixes to Comparer 2024-07-31 13:34:40 -07:00
data_test.go sstable: convert RawWriter into an interface 2024-08-23 18:55:36 -04:00
db.go db: refactor disk usage estimate using range annotations 2024-08-27 14:54:51 -04:00
db_internals.go db: reimplement Download 2024-04-04 15:56:09 -07:00
db_test.go db: plumb context through ingest methods 2024-08-13 13:33:33 -07:00
download.go manifest: clean up Level 2024-07-29 17:36:51 -07:00
download_test.go db: reimplement Download 2024-04-04 15:56:09 -07:00
error_iter.go keyspan: add contexts to keyspan iterators 2024-07-23 23:02:39 -04:00
error_test.go vfs: redesign MemFS strict mode 2024-08-26 15:07:05 -07:00
event.go base: add SeqNum type 2024-06-22 07:47:58 -07:00
event_listener_test.go db: plumb context through ingest methods 2024-08-13 13:33:33 -07:00
example_test.go add ExampleIterator and ExampleIterator_SeekGE 2021-04-14 08:32:54 -04:00
external_iterator.go base: add CompareSuffixes to Comparer 2024-07-31 13:34:40 -07:00
external_iterator_test.go sstable: consolidate reader/writer options 2024-07-09 11:56:03 -07:00
external_test.go db: fix some iterator error paths 2024-01-30 13:05:30 -08:00
filenames.go db: deprecate older format versions 2023-12-18 16:52:37 -08:00
filenames_test.go tests: use testLogger 2024-03-13 18:04:34 -04:00
flush_test.go db: refactor obsolete file deletion code 2023-06-26 12:32:48 -07:00
flushable.go manifest: clean up Level 2024-07-29 17:36:51 -07:00
flushable_test.go db: plumb context through ingest methods 2024-08-13 13:33:33 -07:00
format_major_version.go manifest: improve Annotator interface with generics 2024-07-26 11:38:46 -04:00
format_major_version_test.go vfs: redesign MemFS strict mode 2024-08-26 15:07:05 -07:00
get_iter.go manifest: clean up Level 2024-07-29 17:36:51 -07:00
get_iter_test.go db: track files' pre-zeroing largest sequence numbers 2024-05-03 10:22:25 -04:00
go.mod colblk: use crlib/crbytes.CommonPrefix 2024-08-19 12:13:49 -07:00
go.sum colblk: use crlib/crbytes.CommonPrefix 2024-08-19 12:13:49 -07:00
ingest.go db: plumb context through ingest methods 2024-08-13 13:33:33 -07:00
ingest_test.go vfs: redesign MemFS strict mode 2024-08-26 15:07:05 -07:00
internal.go db: export MakeTrailer 2024-08-06 16:26:36 -04:00
iterator.go base: add CompareSuffixes to Comparer 2024-07-31 13:34:40 -07:00
iterator_example_test.go *: add error return value to NewIter{,WithContext} 2023-08-14 17:30:59 -04:00
iterator_histories_test.go db: strictly enforce prefix in [flushable]BatchIter.SeekPrefixGE 2024-07-26 17:26:42 -04:00
iterator_test.go vfs: redesign MemFS strict mode 2024-08-26 15:07:05 -07:00
keyspan_probe_test.go keyspan: add contexts to keyspan iterators 2024-07-23 23:02:39 -04:00
level_checker.go manifest: clean up Level 2024-07-29 17:36:51 -07:00
level_checker_test.go internal/{rangedel,rangekey}: take Span by value 2024-07-31 07:13:36 -04:00
level_iter.go db: remove IterOptions.TableFilter 2024-07-29 21:18:42 -04:00
level_iter_test.go sstable: convert RawWriter into an interface 2024-08-23 18:55:36 -04:00
LICENSE Initial check-in. 2011-08-23 21:55:03 +10:00
logger.go db: add Options.LoggerAndTracer for tracing 2023-03-02 10:20:29 -05:00
lsm_view.go *: return *InternalKV from internal iterators 2024-04-10 18:18:56 -04:00
lsm_view_test.go db: LSM viewer URL generation 2024-02-28 14:10:55 -08:00
Makefile devtools: use separate module for dev tool dependencies 2024-08-01 16:02:51 -07:00
mem_table.go base: add SeqNum type 2024-06-22 07:47:58 -07:00
mem_table_test.go base: add SeqNum type 2024-06-22 07:47:58 -07:00
merger.go *: apply crlfmt 2022-03-10 08:23:30 -08:00
merging_iter.go *: add facility to print the iterator stack 2024-07-08 13:58:23 -07:00
merging_iter_heap.go *: return *InternalKV from internal iterators 2024-04-10 18:18:56 -04:00
merging_iter_test.go sstable: convert RawWriter into an interface 2024-08-23 18:55:36 -04:00
metrics.go compact: add point tombstone density compaction heuristic 2024-08-14 11:38:51 -04:00
metrics_test.go compact: add point tombstone density compaction heuristic 2024-08-14 11:38:51 -04:00
obsolete_files.go db: move obsolete files code 2024-04-20 14:46:25 -07:00
obsolete_files_test.go db: rename cleanup.go to obsolete_files.go 2024-04-20 14:46:25 -07:00
open.go db: refactor disk usage estimate using range annotations 2024-08-27 14:54:51 -04:00
open_test.go db: add TestWALFailoverRandomized 2024-08-28 15:25:59 -04:00
options.go compact: add point tombstone density compaction heuristic 2024-08-14 11:38:51 -04:00
options_test.go compact: add point tombstone density compaction heuristic 2024-08-14 11:38:51 -04:00
overlap.go overlap: rework ingest LSM overlap check code 2024-05-29 13:33:25 -07:00
pacer.go db: smoother thresholds for the delete pacer 2023-07-13 15:46:48 -07:00
pacer_test.go *: use new slices, cmp standard library funcs 2023-10-30 14:26:33 -04:00
range_del_test.go db: plumb context through ingest methods 2024-08-13 13:33:33 -07:00
range_keys.go base: add CompareSuffixes to Comparer 2024-07-31 13:34:40 -07:00
read_compaction_queue.go *: move test-only code into test files 2021-11-01 12:45:13 -04:00
read_state.go db: refactor obsolete file deletion code 2023-06-26 12:32:48 -07:00
read_state_test.go *: start reading range keys from sstables 2022-06-10 13:02:44 -04:00
README.md db: deprecate older format versions 2023-12-18 16:52:37 -08:00
scan_internal.go keyspan: use slices.Sort functions 2024-07-31 13:34:40 -07:00
scan_internal_test.go sstable: convert RawWriter into an interface 2024-08-23 18:55:36 -04:00
snapshot.go base: add SeqNum type 2024-06-22 07:47:58 -07:00
snapshot_test.go base: add SeqNum type 2024-06-22 07:47:58 -07:00
table_cache.go db: refactor disk usage estimate using range annotations 2024-08-27 14:54:51 -04:00
table_cache_test.go sstable: avoid repetition in sstable parsing error messages 2024-08-29 11:12:26 -04:00
table_stats.go compact: add point tombstone density compaction heuristic 2024-08-14 11:38:51 -04:00
table_stats_test.go internal/{rangedel,rangekey}: take Span by value 2024-07-31 07:13:36 -04:00
version_set.go compact: add point tombstone density compaction heuristic 2024-08-14 11:38:51 -04:00
version_set_test.go db: plumb context through ingest methods 2024-08-13 13:33:33 -07:00

Pebble Build Status GoDoc Coverage

Nightly benchmarks

Pebble is a LevelDB/RocksDB inspired key-value store focused on performance and internal usage by CockroachDB. Pebble inherits the RocksDB file formats and a few extensions such as range deletion tombstones, table-level bloom filters, and updates to the MANIFEST format.

Pebble intentionally does not aspire to include every feature in RocksDB and specifically targets the use case and feature set needed by CockroachDB:

  • Block-based tables
  • Checkpoints
  • Indexed batches
  • Iterator options (lower/upper bound, table filter)
  • Level-based compaction
  • Manual compaction
  • Merge operator
  • Prefix bloom filters
  • Prefix iteration
  • Range deletion tombstones
  • Reverse iteration
  • SSTable ingestion
  • Single delete
  • Snapshots
  • Table-level bloom filters

RocksDB has a large number of features that are not implemented in Pebble:

  • Backups
  • Column families
  • Delete files in range
  • FIFO compaction style
  • Forward iterator / tailing iterator
  • Hash table format
  • Memtable bloom filter
  • Persistent cache
  • Pin iterator key / value
  • Plain table format
  • SSTable ingest-behind
  • Sub-compactions
  • Transactions
  • Universal compaction style

WARNING: Pebble may silently corrupt data or behave incorrectly if used with a RocksDB database that uses a feature Pebble doesn't support. Caveat emptor!

Production Ready

Pebble was introduced as an alternative storage engine to RocksDB in CockroachDB v20.1 (released May 2020) and was used in production successfully at that time. Pebble was made the default storage engine in CockroachDB v20.2 (released Nov 2020). Pebble is being used in production by users of CockroachDB at scale and is considered stable and production ready.

Advantages

Pebble offers several improvements over RocksDB:

  • Faster reverse iteration via backwards links in the memtable's skiplist.
  • Faster commit pipeline that achieves better concurrency.
  • Seamless merged iteration of indexed batches. The mutations in the batch conceptually occupy another memtable level.
  • L0 sublevels and flush splitting for concurrent compactions out of L0 and reduced read-amplification during heavy write load.
  • Faster LSM edits in LSMs with large numbers of sstables through use of a copy-on-write B-tree to hold file metadata.
  • Delete-only compactions that drop whole sstables that fall within the bounds of a range deletion.
  • Block-property collectors and filters that enable iterators to skip tables, index blocks and data blocks that are irrelevant, according to user-defined properties over key-value pairs.
  • Range keys API, allowing KV pairs defined over a range of keyspace with user-defined semantics and interleaved during iteration.
  • Smaller, more approachable code base.

See the Pebble vs RocksDB: Implementation Differences doc for more details on implementation differences.

RocksDB Compatibility

Pebble strives for forward compatibility with RocksDB 6.2.1 (the latest version of RocksDB used by CockroachDB). Forward compatibility means that a DB generated by RocksDB 6.2.1 can be upgraded for use by Pebble. Pebble versions in the v1 series may open DBs generated by RocksDB 6.2.1. Since its introduction, Pebble has adopted various backwards-incompatible format changes that are gated behind new 'format major versions'. The Pebble master branch does not support opening DBs generated by RocksDB. DBs generated by RocksDB may only be used with recent versions of Pebble after migrating them through format major version upgrades using previous versions of Pebble. See the below section of format major versions.

Even the RocksDB-compatible versions of Pebble only provide compatibility with the subset of functionality and configuration used by CockroachDB. The scope of RocksDB functionality and configuration is too large to adequately test and document all the incompatibilities. The list below contains known incompatibilities.

  • Pebble's use of WAL recycling is only compatible with RocksDB's kTolerateCorruptedTailRecords WAL recovery mode. Older versions of RocksDB would automatically map incompatible WAL recovery modes to kTolerateCorruptedTailRecords. New versions of RocksDB will disable WAL recycling.
  • Column families. Pebble does not support column families, nor does it attempt to detect their usage when opening a DB that may contain them.
  • Hash table format. Pebble does not support the hash table sstable format.
  • Plain table format. Pebble does not support the plain table sstable format.
  • SSTable format version 3 and 4. Pebble does not support version 3 and version 4 format sstables. The sstable format version is controlled by the BlockBasedTableOptions::format_version option. See #97.

Format major versions

Over time Pebble has introduced new physical file formats. Backwards incompatible changes are made through the introduction of 'format major versions'. By default, when Pebble opens a database, it defaults to the lowest supported version. In v1, this is FormatMostCompatible, which is bi-directionally compatible with RocksDB 6.2.1 (with the caveats described above).

Databases created by RocksDB or Pebble versions v1 and earlier must be upgraded to a compatible format major version before running newer Pebble versions. Newer Pebble versions will refuse to open databases in no longer supported formats.

To opt into new formats, a user may set FormatMajorVersion on the Options supplied to Open, or upgrade the format major version at runtime using DB.RatchetFormatMajorVersion. Format major version upgrades are permanent; There is no option to return to an earlier format.

The table below outlines the history of format major versions, along with what range of Pebble versions support that format.

Name Value Migration Pebble support
FormatMostCompatible 1 No v1
FormatVersioned 3 No v1
FormatSetWithDelete 4 No v1
FormatBlockPropertyCollector 5 No v1
FormatSplitUserKeysMarked 6 Background v1
FormatSplitUserKeysMarkedCompacted 7 Blocking v1
FormatRangeKeys 8 No v1
FormatMinTableFormatPebblev1 9 No v1
FormatPrePebblev1Marked 10 Background v1
FormatSSTableValueBlocks 12 No v1
FormatFlushableIngest 13 No v1, master
FormatPrePebblev1MarkedCompacted 14 Blocking v1, master
FormatDeleteSizedAndObsolete 15 No v1, master
FormatVirtualSSTables 16 No v1, master

Upgrading to a format major version with 'Background' in the migration column may trigger background activity to rewrite physical file formats, typically through compactions. Upgrading to a format major version with 'Blocking' in the migration column will block until a migration is complete. The database may continue to serve reads and writes if upgrading a live database through RatchetFormatMajorVersion, but the method call will not return until the migration is complete.

For reference, the table below lists the range of supported Pebble format major versions for CockroachDB releases.

CockroachDB release Earliest supported Latest supported
20.1 through 21.1 FormatMostCompatible FormatMostCompatible
21.2 FormatMostCompatible FormatSetWithDelete
21.2 FormatMostCompatible FormatSetWithDelete
22.1 FormatMostCompatible FormatSplitUserKeysMarked
22.2 FormatMostCompatible FormatPrePebblev1Marked
23.1 FormatSplitUserKeysMarkedCompacted FormatFlushableIngest
23.2 FormatSplitUserKeysMarkedCompacted FormatVirtualSSTables

Pedigree

Pebble is based on the incomplete Go version of LevelDB:

https://github.com/golang/leveldb

The Go version of LevelDB is based on the C++ original:

https://github.com/google/leveldb

Optimizations and inspiration were drawn from RocksDB:

https://github.com/facebook/rocksdb

Getting Started

Example Code

package main

import (
	"fmt"
	"log"

	"github.com/cockroachdb/pebble"
)

func main() {
	db, err := pebble.Open("demo", &pebble.Options{})
	if err != nil {
		log.Fatal(err)
	}
	key := []byte("hello")
	if err := db.Set(key, []byte("world"), pebble.Sync); err != nil {
		log.Fatal(err)
	}
	value, closer, err := db.Get(key)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s %s\n", key, value)
	if err := closer.Close(); err != nil {
		log.Fatal(err)
	}
	if err := db.Close(); err != nil {
		log.Fatal(err)
	}
}