Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make pebble the clear choice #115

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6dc7c0c
add pebbledb
baabeetaa Mar 21, 2023
5c90ecd
use latest pebble
faddat Jan 7, 2024
ef2dfbb
Merge remote-tracking branch 'origin/main' into pebble
faddat Jan 7, 2024
90d9aff
added a ton of test rigor and fixed linting
faddat Jan 7, 2024
019ce53
if always false we don't need the param
faddat Jan 7, 2024
e454ccb
let's go fast
faddat Jan 7, 2024
0e42443
implement stats()
faddat Jan 7, 2024
adbd834
really we don't need that
faddat Jan 7, 2024
a574117
remove databases no one uses
faddat Jan 7, 2024
ecf08bc
boring certs thing
faddat Jan 7, 2024
198e605
Osmo needed it and I have the tattoo
faddat Jan 7, 2024
445087c
hope this does better in ci than on my mac...
faddat Jan 7, 2024
137f7b1
demonstrate the issue with goleveldb
faddat Jan 7, 2024
bd93ba0
Merge branch 'faddat/remove-obvious-dead-dbs' into faddat/make-pebble…
faddat Jan 7, 2024
75c7319
change some settings
faddat Jan 7, 2024
1d8211f
make bemchmarks clearer output i hope
faddat Jan 7, 2024
33d6190
lint
faddat Jan 14, 2024
4dcf12a
fix all lints
faddat Jan 14, 2024
03509f9
update pebble
faddat Jan 14, 2024
d3d7c79
update to main
faddat Jan 14, 2024
400c03e
add experimental options and increase ram caches
faddat Jan 14, 2024
81c42cc
enhance benchmarks. All results where goleveldb wins never happen in…
faddat Jan 14, 2024
74b6b1b
make benchmarks as clear as possible
faddat Jan 14, 2024
5b165c3
Revert "remove databases no one uses"
faddat Jan 15, 2024
070a044
Merge remote-tracking branch 'origin/main' into faddat/make-pebble-ov…
faddat Jan 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# runs benchmarks on the pebble and goleveldb backends
name: Benchmarks

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v3
with:
go-version: 1.21
- name: Run benchmarks
run: go test -bench=.
118 changes: 90 additions & 28 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,113 @@
linters:
run:
tests: true
timeout: 10m

linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- dupl
- exportloopref
- errcheck
- gci
- goconst
- gocritic
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- staticcheck
- thelper
- typecheck
- stylecheck
- revive
- typecheck
- tenv
- unconvert
# Prefer unparam over revive's unused param. It is more thorough in its checking.
- unparam
- unused
- nolintlint
- misspell

issues:
exclude-rules:
- text: 'differs only by capitalization to method'
linters:
- revive
- text: 'Use of weak random number generator'
linters:
- gosec
- linters:
- staticcheck
text: "SA1019:" # silence errors on usage of deprecated funcs

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
errcheck:
check-blank: true
depguard:
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- blank # blank imports
- dot # dot imports
- prefix(github.com/cometbft/cometbft-db)
custom-order: true
revive:
enable-all-rules: true
# Do NOT whine about the following, full explanation found in:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#description-of-available-rules
rules:
main:
files:
- $all
- "!$test"
allow:
- $gostd
- github.com/cometbft
- github.com/syndtr/goleveldb/leveldb
- github.com/google/btree
test:
files:
- $test
allow:
- $gostd
- github.com/cometbft
- github.com/syndtr/goleveldb/leveldb
- github.com/stretchr/testify
- name: use-any
disabled: true
- name: if-return
disabled: true
- name: max-public-structs
disabled: true
- name: cognitive-complexity
disabled: true
- name: argument-limit
disabled: true
- name: cyclomatic
disabled: true
- name: file-header
disabled: true
- name: function-length
disabled: true
- name: function-result-limit
disabled: true
- name: line-length-limit
disabled: true
- name: flag-parameter
disabled: true
- name: add-constant
disabled: true
- name: empty-lines
disabled: true
- name: banned-characters
disabled: true
- name: deep-exit
disabled: true
- name: confusing-results
disabled: true
- name: unused-parameter
disabled: true
- name: modifies-value-receiver
disabled: true
- name: early-return
disabled: true
- name: confusing-naming
disabled: true
- name: defer
disabled: true
# Disabled in favour of unparam.
- name: unused-parameter
disabled: true
- name: unhandled-error
disabled: false
arguments:
- 'fmt.Printf'
- 'fmt.Print'
- 'fmt.Println'
- 'myFunction'
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ test-badgerdb:
@go test $(PACKAGES) -tags badgerdb -v
.PHONY: test-badgerdb

test-pebble:
@echo "--> Running go test"
@go test $(PACKAGES) -tags pebbledb -v

test-all:
@echo "--> Running go test"
@go test $(PACKAGES) -tags cleveldb,boltdb,rocksdb,grocksdb_clean_link,badgerdb -v
Expand All @@ -52,7 +56,6 @@ test-all-with-coverage:
-race \
-coverprofile=coverage.txt \
-covermode=atomic \
-tags=memdb,goleveldb,cleveldb,boltdb,rocksdb,grocksdb_clean_link,badgerdb \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing this line?

-v
.PHONY: test-all-with-coverage

Expand Down
34 changes: 27 additions & 7 deletions backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"os"
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// Register a test backend for PrefixDB as well, with some unrelated junk data
func init() {
//nolint: errcheck
//nolint: errcheck, revive // probably should check errors?
registerDBCreator("prefixdb", func(name, dir string) (DB, error) {
mdb := NewMemDB()
mdb.Set([]byte("a"), []byte{1})
Expand All @@ -22,17 +23,25 @@ func init() {
mdb.Set([]byte("u"), []byte{21})
mdb.Set([]byte("z"), []byte{26})
return NewPrefixDB(mdb, []byte("test/")), nil
}, false)
})
}

func cleanupDBDir(dir, name string) {
err := os.RemoveAll(filepath.Join(dir, name) + ".db")
if err != nil {
panic(err)
for i := 0; i < 5; i++ {
err := os.RemoveAll(filepath.Join(dir, name) + ".db")
if err != nil {
if i == 4 { // If this was the last attempt, panic
panic(err)
}
time.Sleep(time.Second) // Wait for a second before the next attempt
} else {
break // If there was no error, break the loop
}
}
}

func testBackendGetSetDelete(t *testing.T, backend BackendType) {
t.Helper()
// Default
dirname, err := os.MkdirTemp("", fmt.Sprintf("test_backend_%s_", backend))
require.Nil(t, err)
Expand Down Expand Up @@ -161,6 +170,8 @@ func TestDBIterator(t *testing.T) {
}

func testDBIterator(t *testing.T, backend BackendType) {
t.Helper()

name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()
db, err := NewDB(name, backend, dir)
Expand Down Expand Up @@ -317,6 +328,8 @@ func testDBIterator(t *testing.T, backend BackendType) {
}

func verifyIterator(t *testing.T, itr Iterator, expected []int64, msg string) {
t.Helper()

var list []int64
for itr.Valid() {
key := itr.Key()
Expand All @@ -335,6 +348,8 @@ func TestDBBatch(t *testing.T) {
}

func testDBBatch(t *testing.T, backend BackendType) {
t.Helper()

name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()
db, err := NewDB(name, backend, dir)
Expand Down Expand Up @@ -396,8 +411,12 @@ func testDBBatch(t *testing.T, backend BackendType) {

// it should be possible to close an empty batch, and to re-close a closed batch
batch = db.NewBatch()
batch.Close()
batch.Close()
if err := batch.Close(); err != nil {
require.NoError(t, err)
}
if err := batch.Close(); err != nil {
require.NoError(t, err)
}

// all other operations on a closed batch should error
require.Error(t, batch.Set([]byte("a"), []byte{9}))
Expand All @@ -407,6 +426,7 @@ func testDBBatch(t *testing.T, backend BackendType) {
}

func assertKeyValues(t *testing.T, db DB, expect map[string][]byte) {
t.Helper()
iter, err := db.Iterator(nil, nil)
require.NoError(t, err)
defer iter.Close()
Expand Down
2 changes: 1 addition & 1 deletion badger_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/dgraph-io/badger/v2"
)

func init() { registerDBCreator(BadgerDBBackend, badgerDBCreator, true) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason for changing this interface?

func init() { registerDBCreator(BadgerDBBackend, badgerDBCreator) }

func badgerDBCreator(dbName, dir string) (DB, error) {
return NewBadgerDB(dbName, dir)
Expand Down
2 changes: 1 addition & 1 deletion boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
func init() {
registerDBCreator(BoltDBBackend, func(name, dir string) (DB, error) {
return NewBoltDB(name, dir)
}, false)
})
}

// BoltDB is a wrapper around etcd's fork of bolt (https://github.com/etcd-io/bbolt).
Expand Down
2 changes: 1 addition & 1 deletion cleveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func init() {
dbCreator := func(name string, dir string) (DB, error) {
return NewCLevelDB(name, dir)
}
registerDBCreator(CLevelDBBackend, dbCreator, false)
registerDBCreator(CLevelDBBackend, dbCreator)
}

// CLevelDB uses the C LevelDB database via a Go wrapper.
Expand Down
Loading
Loading