• Stars
    star
    4,825
  • Rank 8,724 (Top 0.2 %)
  • Language
    Go
  • License
    BSD 3-Clause "New...
  • Created over 6 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RocksDB/LevelDB inspired key-value database in Go

Pebble Build Status GoDoc Coverage

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)
	}
}

More Repositories

1

cockroach

CockroachDB β€” the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
Go
30,059
star
2

errors

Go error library with error portability over the network
Go
1,869
star
3

copyist

Mocking your SQL database in Go tests has never been easier.
Go
833
star
4

apd

Arbitrary-precision decimals for Go
Go
540
star
5

cockroach-operator

k8s operator for CRDB
Go
264
star
6

docs

CockroachDB user documentation
HTML
177
star
7

django-cockroachdb

CockroachDB Backend for Django
Python
155
star
8

sqlalchemy-cockroachdb

SQLAlchemy adapter for CockroachDB
Python
143
star
9

activerecord-cockroachdb-adapter

CockroachDB adapter for ActiveRecord.
Ruby
103
star
10

rpc-bench

Benchmarking various RPC implementations
Go
87
star
11

examples-orms

Sample uses of CockroachDB with popular ORMs
Go
82
star
12

helm-charts

Helm charts for cockroachdb
Go
81
star
13

examples-go

Sample uses of cockroachDB.
Go
75
star
14

replicator

replicator is a toolkit for ingesting logical replication feeds into a CockroachDB cluster
Go
57
star
15

terraform-provider-cockroach

Terraform provider for CockroachDB Cloud
Go
56
star
16

sequelize-cockroachdb

Use Sequelize and CockroachDB together
JavaScript
52
star
17

cockroachdb-todo-apps

CockroachDB To-Do Apps
Python
51
star
18

c-rocksdb

🚫 DEPRECATED
C++
46
star
19

datadriven

Data-Driven Testing for Go
Go
38
star
20

logtags

key/value annotations for Go contexts
Go
35
star
21

cockroach-gen

CockroachDB with pre-generated Go code
Go
33
star
22

movr

A fictional ride sharing company.
Python
32
star
23

loadgen

CockroachDB load generators
Go
30
star
24

k8s

Images and utilities to run cockroach on kubernetes
Go
26
star
25

redact

Utilities to redact Go strings for confidentiality
Go
25
star
26

c-snappy

C++
21
star
27

ui

Published assets for Cockroach Labs user interfaces
TypeScript
20
star
28

cockroachdb-parser

Apache licensed CockroachDB parser and dependencies.
Go
19
star
29

roachprod

Internal CockroachDB production testing tool
Go
15
star
30

crlfmt

Formatter for CockroachDB's additions to the Go style guide.
Go
14
star
31

cockroachdb-typescript

A modern cloud-native web app using TypeScript, React, Prisma, Netlify serverless functions, and CockroachDB
TypeScript
14
star
32

homebrew-tap

`brew install cockroachdb/tap/cockroach`
Ruby
14
star
33

c-protobuf

🚫 DEPRECATED: go-gettable version of google/protobuf
C++
13
star
34

watermill-crdb

CockroachDB Pub/Sub for the Watermill project.
Go
13
star
35

molt

Migrate Off Legacy Things - open-source tooling to assist migrations to CockroachDB.
Go
12
star
36

cockroachdb-cloudformation

Quickly setup dev/test CockroachDB clusters using AWS CloudFormation and Kubernetes
Shell
12
star
37

vendored

CockroachDB's vendored Go dependencies
Go
11
star
38

c-jemalloc

🚫 DEPRECATED
C
11
star
39

yacc

Fork of go yacc tool with increased hardcoded constants to handle larger grammars.
Go
11
star
40

examples-python

Sample uses of CockroachDB
Python
10
star
41

c-lz4

C
10
star
42

build-cache

Cache the installed output of go builds
Go
9
star
43

definitive_guide_sample_code

Sample code for The Definitive Guide to CockroachDB
JavaScript
8
star
44

quickstart-code-samples

Java
8
star
45

pcf-crdb-service-broker

Pivotal Cloud Foundry service broker for CockroachDB.
Go
8
star
46

dcos-cockroachdb-service

Framework for running CockroachDB on Mesosphere DC/OS
Python
8
star
47

backport

automatically backport pull requests
Go
7
star
48

cockroach-proto

Protocol Buffer
7
star
49

python-heroku-cockroachdb

A modern cloud-native web app using Python, Flask, Heroku, and CockroachDB
Python
7
star
50

walkabout

Walkabout generates visitor-pattern accessors for your existing go structs.
Go
6
star
51

sample-apps

6
star
52

nextjs-react-vercel-crdb-app

A CockroachDB sample app for coordinating social events using Next.js with react-bootstrap deployed on vercel
JavaScript
6
star
53

rksql

Fork of scaledata/rksql
Go
5
star
54

ddshop

TodoMVC app for distributed database workshop
JavaScript
5
star
55

postgres-test

Dockerfile
5
star
56

benchviz

A tool used for visualizing results from benchmark tests over time.
Go
5
star
57

cockroach-cloud-sdk-go

Go client SDK for CockroachDB Cloud
Mustache
5
star
58

stress

A fork of Golang's stress function.
Go
5
star
59

example-app-rust-postgres

Rust
4
star
60

protoc-gen-gogoroach

protoc (protobuf compiler) plugin for CockroachDB protobuf files
Go
4
star
61

efcore.pg.cockroach

C#
4
star
62

generated-diagrams

HTML
4
star
63

roachspeed

codespeed instance
Python
4
star
64

hibernate-savepoint-fix

Java
4
star
65

scripts

Utility and helper scripts for CockroachDB contributors -
Vim Script
4
star
66

go-lab

Scripts and test programs to reveal what happens under the hood in Go.
Go
4
star
67

cockroachdb.github.io

Supporting static content for CockroachDB
JavaScript
3
star
68

cgo_static_boom

cgo static binary boom
Go
3
star
69

docs-docker

Docker image for the docs build
3
star
70

libedit

CockroachDB fork of the libedit terminal line-editing library
3
star
71

yarn-vendored

CockroachDB's vendored JavaScript dependencies
3
star
72

gostdlib

Vendor-friendly Go standard library packages
Go
3
star
73

dev

A utility for performing common CockroachDB development tasks
3
star
74

scp-interview

Shell
3
star
75

university-getting-started-with-sql-app-exercises

Exercise code for the Cockroach University - Getting Started with SQL for Application Developers course
Shell
3
star
76

university-event-driven-architecture-for-java-developers-app-exercises

Exercise code for Cockroach University - Event Driven Architecture for Java Developers
Java
3
star
77

bincheck

Verify CockroachDB binaries
Shell
3
star
78

eddie

Big Eddie, the golang contract enforcer
Go
3
star
79

roachperf-og

🚫 Deprecated CockroachDB performance tool β€” use roachprod instead!
Go
3
star
80

jsonb-spec

Acceptance tests/spec for CockroachDB JSONB support, complement to scoping RFC
JavaScript
3
star
81

social-events-app

JavaScript
3
star
82

example-app-python-psycopg3

Simple CRUD application in Python using the psycopg3 driver.
Python
3
star
83

ttycolor

Conditionally expose ANSI color codes for use on a terminal
Go
2
star
84

fullstack-node-cockroachdb-app

Fullstack sample application in Node.js using Sequelize
JavaScript
2
star
85

rails-crdb-app

A CockroachDB leaderboard sample application using Rails deployed on Heroku
Ruby
2
star
86

university-multi-region-course-app-exercises

exercise code for the cockroach university multi-region course
Java
2
star
87

tokenbucket

Token bucket implementation in Go
Go
2
star
88

go-plus

API library for CRL's custom Go extensions
Go
2
star
89

admin-ui-components

Shared frontend components between the CRDB Admin UI and other apps
TypeScript
2
star
90

build-utils

🚫 DEPRECATED: Build utilities for CockroachDB
Go
2
star
91

psycopg2-cockroachdb

Testing psycopg2 against cockroachdb
Shell
2
star
92

katacoda

In-browser, interactive tutorials on CockroachDB
Shell
2
star
93

cockroachdb-hibernate

Package to improve compatibility between CockroachDB and Hibernate
2
star
94

homebrew-go

🚫 DEPRECATED 🚫 β€” use `brew install go` instead
Ruby
2
star
95

pulumi-poc

Demo of simple control plane built on top of Pulumi.
Go
2
star
96

s3checker

Check s3 support for bulk operations
Go
1
star
97

avrogen

Avro generator for import testing
Go
1
star
98

redcarpet-extender

Extends the Redcarpet Markdown parser to handle CockroachDB documentation
1
star
99

university-getting-started-with-node-postgres-app-exercises

JavaScript
1
star
100

university-multi-region-latency-exercises

Optimizing latency in multi-region database course exercise code
Shell
1
star