Skip to content

Commit

Permalink
Temporarily revert v0.6.7 changes (#9)
Browse files Browse the repository at this point in the history
* Revert "Remove @creachadair from the CODEOWNERS file. (#285)"

This reverts commit 0c9484c.

* Revert all changes since v0.6.6

Signed-off-by: Thane Thomson <[email protected]>

* make format

Signed-off-by: Thane Thomson <[email protected]>

* Address linter complaints

Signed-off-by: Thane Thomson <[email protected]>

* Remove deprecated io/ioutil usage

Signed-off-by: Thane Thomson <[email protected]>

* Use latest GitHub workflows

Signed-off-by: Thane Thomson <[email protected]>

* regenerate certs (#280)

* Disable CI failure if coverage upload fails

Signed-off-by: Thane Thomson <[email protected]>

* Remove redundant Printf/Println statements/comments

Signed-off-by: Thane Thomson <[email protected]>

Signed-off-by: Thane Thomson <[email protected]>
Co-authored-by: Jacob Gadikian <[email protected]>
  • Loading branch information
thanethomson and faddat authored Jan 12, 2023
1 parent 33ef5c0 commit 56cf362
Show file tree
Hide file tree
Showing 34 changed files with 168 additions and 328 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ jobs:
- uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
fail_ci_if_error: true
# TODO(thane): Re-enable once we make the repo public
fail_ci_if_error: false
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
*.out

.idea
.vscode
vendor/*
7 changes: 0 additions & 7 deletions .gitpod.yml

This file was deleted.

28 changes: 17 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
# - funlen
# - gochecknoglobals
# - gochecknoinits
- goconst
- gocritic
- gofumpt
- revive
# - gocyclo
# - godox
- gofmt
- goimports
- golint
- gosec
- gosimple
- govet
- ineffassign
# - interfacer
- lll
- misspell
- maligned
- nakedret
- prealloc
# - scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- revive
- unconvert
# - unparam
- unused
- varcheck
# - whitespace
# - wsl
# - gocognit
- nolintlint

run:
build-tags:
- cleveldb
- rocksdb
- badgerdb
- boltdb

issues:
exclude-rules:
- path: _test\.go
Expand Down
11 changes: 0 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
# Changelog

## Unreleased

- remove mutex from prefixdb

## 0.6.7

**2022-2-21**

- Use cosmos/rocksdb instead of techbot/rocksdb
- Add `ForceCopmact` to goleveldb database

## 0.6.6

**2021-11-08**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Go 1.13+

- **[BoltDB](https://github.com/etcd-io/bbolt) [experimental]:** A [fork](https://github.com/etcd-io/bbolt) of [BoltDB](https://github.com/boltdb/bolt). Uses B+trees for on-disk storage, which have good performance for read-heavy workloads and range scans. Supports serializable ACID transactions.

- **[RocksDB](https://github.com/cosmos/gorocksdb) [experimental]:** A [Go wrapper](https://github.com/cosmos/gorocksdb) around [RocksDB](https://rocksdb.org). Similarly to LevelDB (above) it uses LSM-trees for on-disk storage, but is optimized for fast storage media such as SSDs and memory. Supports atomic transactions, but not full ACID transactions.
- **[RocksDB](https://github.com/tecbot/gorocksdb) [experimental]:** A [Go wrapper](https://github.com/tecbot/gorocksdb) around [RocksDB](https://rocksdb.org). Similarly to LevelDB (above) it uses LSM-trees for on-disk storage, but is optimized for fast storage media such as SSDs and memory. Supports atomic transactions, but not full ACID transactions.

- **[BadgerDB](https://github.com/dgraph-io/badger) [experimental]:** A key-value database written as a pure-Go alternative to e.g. LevelDB and RocksDB, with LSM-tree storage. Makes use of multiple goroutines for performance, and includes advanced features such as serializable ACID transactions, write batches, compression, and more.

Expand Down
7 changes: 3 additions & 4 deletions backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package db

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -13,7 +12,7 @@ import (

// Register a test backend for PrefixDB as well, with some unrelated junk data
func init() {
// nolint: errcheck
//nolint: errcheck
registerDBCreator("prefixdb", func(name, dir string) (DB, error) {
mdb := NewMemDB()
mdb.Set([]byte("a"), []byte{1})
Expand All @@ -35,7 +34,7 @@ func cleanupDBDir(dir, name string) {

func testBackendGetSetDelete(t *testing.T, backend BackendType) {
// Default
dirname, err := ioutil.TempDir("", fmt.Sprintf("test_backend_%s_", backend))
dirname, err := os.MkdirTemp("", fmt.Sprintf("test_backend_%s_", backend))
require.Nil(t, err)
db, err := NewDB("testdb", backend, dirname)
require.NoError(t, err)
Expand Down Expand Up @@ -302,7 +301,7 @@ func testDBIterator(t *testing.T, backend BackendType) {
[]int64(nil), "reverse iterator from 2 (ex) to 4")

// Ensure that the iterators don't panic with an empty database.
dir2, err := ioutil.TempDir("", "tm-db-test")
dir2, err := os.MkdirTemp("", "tm-db-test")
require.NoError(t, err)
db2, err := NewDB(name, backend, dir2)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions badger_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"
"path/filepath"

"github.com/dgraph-io/badger/v3"
"github.com/dgraph-io/badger/v2"
)

func init() { registerDBCreator(BadgerDBBackend, badgerDBCreator, true) }
Expand All @@ -25,7 +25,7 @@ func NewBadgerDB(dbName, dir string) (*BadgerDB, error) {
// the final directory to use for the database.
path := filepath.Join(dir, dbName)

if err := os.MkdirAll(path, 0o755); err != nil {
if err := os.MkdirAll(path, 0755); err != nil {
return nil, err
}
opts := badger.DefaultOptions(path)
Expand Down
9 changes: 6 additions & 3 deletions boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import (
"go.etcd.io/bbolt"
)

var bucket = []byte("tm")
var (
bucket = []byte("tm")
)

func init() {
registerDBCreator(BoltDBBackend, NewBoltDB, false)
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 Expand Up @@ -136,7 +140,6 @@ func (bdb *BoltDB) Close() error {
}

// Print implements DB.
// nolint: errcheck
func (bdb *BoltDB) Print() error {
stats := bdb.db.Stats()
fmt.Printf("%v\n", stats)
Expand Down
11 changes: 0 additions & 11 deletions boltdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package db
import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -22,16 +21,6 @@ func TestBoltDBNewBoltDB(t *testing.T) {
db.Close()
}

func TestWithBoltDB(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "boltdb")

db, err := NewBoltDB(path, "")
require.NoError(t, err)

t.Run("BoltDB", func(t *testing.T) { Run(t, db) })
}

func BenchmarkBoltDBRandomReadsWrites(b *testing.B) {
name := fmt.Sprintf("test_%x", randStr(12))
db, err := NewBoltDB(name, "")
Expand Down
6 changes: 5 additions & 1 deletion cleveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,14 @@ func (db *CLevelDB) Print() error {
// Stats implements DB.
func (db *CLevelDB) Stats() map[string]string {
keys := []string{
"leveldb.aliveiters",
"leveldb.alivesnaps",
"leveldb.blockpool",
"leveldb.cachedblock",
"leveldb.num-files-at-level{n}",
"leveldb.openedtables",
"leveldb.sstables",
"leveldb.stats",
"leveldb.approximate-memory-usage",
}

stats := make(map[string]string, len(keys))
Expand Down
15 changes: 10 additions & 5 deletions cleveldb_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var _ Iterator = (*cLevelDBIterator)(nil)

func newCLevelDBIterator(source *levigo.Iterator, start, end []byte, isReverse bool) *cLevelDBIterator {
if isReverse {
if len(end) == 0 {
if end == nil || len(end) == 0 {
source.SeekToLast()
} else {
source.Seek(end)
Expand All @@ -35,7 +35,7 @@ func newCLevelDBIterator(source *levigo.Iterator, start, end []byte, isReverse b
}
}
} else {
if len(start) == 0 {
if start == nil || len(start) == 0 {
source.SeekToFirst()
} else {
source.Seek(start)
Expand All @@ -57,31 +57,36 @@ func (itr cLevelDBIterator) Domain() ([]byte, []byte) {

// Valid implements Iterator.
func (itr cLevelDBIterator) Valid() bool {

// Once invalid, forever invalid.
if itr.isInvalid {
return false
}

// If source errors, invalid.
if itr.source.GetError() != nil {
itr.isInvalid = true
return false
}

// If source is invalid, invalid.
if !itr.source.Valid() {
itr.isInvalid = true
return false
}

// If key is end or past it, invalid.
start := itr.start
end := itr.end
key := itr.source.Key()
var start = itr.start
var end = itr.end
var key = itr.source.Key()
if itr.isReverse {
if start != nil && bytes.Compare(key, start) < 0 {
itr.isInvalid = true
return false
}
} else {
if end != nil && bytes.Compare(end, key) <= 0 {
itr.isInvalid = true
return false
}
}
Expand Down
20 changes: 3 additions & 17 deletions cleveldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,12 @@ import (
"fmt"
"math/rand"
"os"
"path/filepath"
"testing"

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

func TestWithClevelDB(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "cleveldb")

db, err := NewCLevelDB(path, "")
require.NoError(t, err)

t.Run("ClevelDB", func(t *testing.T) { Run(t, db) })
}

//nolint: errcheck
func BenchmarkRandomReadsWrites2(b *testing.B) {
b.StopTimer()

Expand All @@ -40,7 +28,6 @@ func BenchmarkRandomReadsWrites2(b *testing.B) {
return
}

fmt.Println("ok, starting")
b.StartTimer()

for i := 0; i < b.N; i++ {
Expand All @@ -49,8 +36,8 @@ func BenchmarkRandomReadsWrites2(b *testing.B) {
idx := (int64(rand.Int()) % numItems)
internal[idx]++
val := internal[idx]
idxBytes := int642Bytes(idx)
valBytes := int642Bytes(val)
idxBytes := int642Bytes(int64(idx))
valBytes := int642Bytes(int64(val))
db.Set(
idxBytes,
valBytes,
Expand All @@ -60,12 +47,11 @@ func BenchmarkRandomReadsWrites2(b *testing.B) {
{
idx := (int64(rand.Int()) % numItems)
val := internal[idx]
idxBytes := int642Bytes(idx)
idxBytes := int642Bytes(int64(idx))
valBytes, err := db.Get(idxBytes)
if err != nil {
b.Error(err)
}
// fmt.Printf("Get %X -> %X\n", idxBytes, valBytes)
if val == 0 {
if !bytes.Equal(valBytes, nil) {
b.Errorf("Expected %v for %v, got %X",
Expand Down
5 changes: 2 additions & 3 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package db
import (
"bytes"
"encoding/binary"
"io/ioutil"
"math/rand"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -67,7 +67,7 @@ func checkValuePanics(t *testing.T, itr Iterator) {
}

func newTempDB(t *testing.T, backend BackendType) (db DB, dbDir string) {
dirname, err := ioutil.TempDir("", "db_common_test")
dirname, err := os.MkdirTemp("", "db_common_test")
require.NoError(t, err)
db, err = NewDB("testdb", backend, dirname)
require.NoError(t, err)
Expand Down Expand Up @@ -116,7 +116,6 @@ func benchmarkRandomReadsWrites(b *testing.B, db DB) {
internal[int64(i)] = int64(0)
}

// fmt.Println("ok, starting")
b.StartTimer()

for i := 0; i < b.N; i++ {
Expand Down
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
// - may be faster is some use-cases (random reads - indexer)
// - use boltdb build tag (go build -tags boltdb)
BoltDBBackend BackendType = "boltdb"
// RocksDBBackend represents rocksdb (uses github.com/cosmos/gorocksdb)
// RocksDBBackend represents rocksdb (uses github.com/tecbot/gorocksdb)
// - EXPERIMENTAL
// - requires gcc
// - use rocksdb build tag (go build -tags rocksdb)
Expand Down
Loading

0 comments on commit 56cf362

Please sign in to comment.