Skip to content

Commit

Permalink
refactor: remove cosmos-db as a dep (backport #955) (#968)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko <[email protected]>
Co-authored-by: Cool Developer <[email protected]>
  • Loading branch information
3 people authored Jul 29, 2024
1 parent 8ecbd9f commit 984d49b
Show file tree
Hide file tree
Showing 41 changed files with 1,678 additions and 727 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [#961](https://github.com/cosmos/iavl/pull/961) Add new `GetLatestVersion` API to get the latest version.
- [#965](https://github.com/cosmos/iavl/pull/965) Use expected interface for expected IAVL `Logger`.
- [#970](https://github.com/cosmos/iavl/pull/970) Close the pruning process when the nodeDB is closed.
- [#968](https://github.com/cosmos/iavl/pull/968) Get rid of `cosmos-db` deps completely.

## v1.2.0 May 13, 2024

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ format:

# look into .golangci.yml for enabling / disabling linters
golangci_lint_cmd=golangci-lint
golangci_version=v1.55.2
golangci_version=v1.59.1

lint:
@echo "--> Running linter"
Expand Down
2 changes: 1 addition & 1 deletion basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func TestIterateRange(t *testing.T) {
}
// test traversing the whole node works... in order
viewed := []string{}
tree.Iterate(func(key []byte, value []byte) bool {
tree.Iterate(func(key []byte, _ []byte) bool {
viewed = append(viewed, string(key))
return false
})
Expand Down
7 changes: 4 additions & 3 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package iavl
import (
"sync"

corestore "cosmossdk.io/core/store"
dbm "github.com/cosmos/iavl/db"
)

Expand All @@ -11,13 +12,13 @@ import (
// as soon as the configurable limit is reached.
type BatchWithFlusher struct {
mtx sync.Mutex
db dbm.DB // This is only used to create new batch
batch dbm.Batch // Batched writing buffer.
db dbm.DB // This is only used to create new batch
batch corestore.Batch // Batched writing buffer.

flushThreshold int // The threshold to flush the batch to disk.
}

var _ dbm.Batch = (*BatchWithFlusher)(nil)
var _ corestore.Batch = (*BatchWithFlusher)(nil)

// NewBatchWithFlusher returns new BatchWithFlusher wrapping the passed in batch
func NewBatchWithFlusher(db dbm.DB, flushThreshold int) *BatchWithFlusher {
Expand Down
12 changes: 3 additions & 9 deletions batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,13 @@ func makeKey(n uint16) []byte {
}

func TestBatchWithFlusher(t *testing.T) {
testedBackends := []string{
"goleveldb",
}

for _, backend := range testedBackends {
testBatchWithFlusher(t, backend)
}
testBatchWithFlusher(t)
}

func testBatchWithFlusher(t *testing.T, backend string) {
func testBatchWithFlusher(t *testing.T) {
name := fmt.Sprintf("test_%x", randstr(12))
dir := t.TempDir()
db, err := dbm.NewDB(name, backend, dir)
db, err := dbm.NewGoLevelDB(name, dir)
require.NoError(t, err)
defer cleanupDBDir(dir, name)

Expand Down
17 changes: 3 additions & 14 deletions benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
mrand "math/rand"
"os"
"runtime"
"strings"
"testing"

corestore "cosmossdk.io/core/store"
"github.com/stretchr/testify/require"

"github.com/cosmos/iavl"
Expand Down Expand Up @@ -146,7 +146,7 @@ func runIterationSlow(b *testing.B, t *iavl.MutableTree, expectedSize int) {
}
}

func iterate(b *testing.B, itr dbm.Iterator, expectedSize int) {
func iterate(b *testing.B, itr corestore.Iterator, expectedSize int) {
b.StartTimer()
keyValuePairs := make([][][]byte, 0, expectedSize)
for i := 0; i < expectedSize && itr.Valid(); i++ {
Expand Down Expand Up @@ -329,9 +329,6 @@ func runBenchmarks(b *testing.B, benchmarks []benchmark) {

// prepare a dir for the db and cleanup afterwards
dirName := fmt.Sprintf("./%s-db", prefix)
if bb.dbType == "rocksdb" {
_ = os.Mkdir(dirName, 0o755)
}

defer func() {
err := os.RemoveAll(dirName)
Expand All @@ -346,16 +343,8 @@ func runBenchmarks(b *testing.B, benchmarks []benchmark) {
err error
)
if bb.dbType != "nodb" {
d, err = dbm.NewDB("test", bb.dbType, dirName)

d, err = dbm.NewGoLevelDB("test", dirName)
if err != nil {
if strings.Contains(err.Error(), "unknown db_backend") {
// As an exception to run benchmarks: if the error is about cleveldb, or rocksdb,
// it requires a tag "cleveldb" to link the database at runtime, so instead just
// log the error instead of failing.
b.Logf("%+v\n", err)
continue
}
require.NoError(b, err)
}
defer d.Close()
Expand Down
14 changes: 6 additions & 8 deletions benchmarks/cosmos-exim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"os"
"time"

tmdb "github.com/cosmos/cosmos-db"

"github.com/cosmos/iavl"
idbm "github.com/cosmos/iavl/db"
)
Expand Down Expand Up @@ -88,11 +86,11 @@ func run(dbPath string) error {

// runExport runs an export benchmark and returns a map of store names/export nodes
func runExport(dbPath string) (int64, map[string][]*iavl.ExportNode, error) {
ldb, err := tmdb.NewDB("application", tmdb.GoLevelDBBackend, dbPath)
ldb, err := idbm.NewGoLevelDB("application", dbPath)
if err != nil {
return 0, nil, err
}
tree := iavl.NewMutableTree(idbm.NewWrapper(tmdb.NewPrefixDB(ldb, []byte("s/k:main/"))), 0, false, iavl.NewNopLogger())
tree := iavl.NewMutableTree(idbm.NewPrefixDB(ldb, []byte("s/k:main/")), 0, false, iavl.NewNopLogger())
version, err := tree.LoadVersion(0)
if err != nil {
return 0, nil, err
Expand All @@ -103,8 +101,8 @@ func runExport(dbPath string) (int64, map[string][]*iavl.ExportNode, error) {

totalStats := Stats{}
for _, name := range stores {
db := tmdb.NewPrefixDB(ldb, []byte("s/k:"+name+"/"))
tree := iavl.NewMutableTree(idbm.NewWrapper(db), 0, false, iavl.NewNopLogger())
db := idbm.NewPrefixDB(ldb, []byte("s/k:"+name+"/"))
tree := iavl.NewMutableTree(db, 0, false, iavl.NewNopLogger())

stats := Stats{}
export := make([]*iavl.ExportNode, 0, 100000)
Expand Down Expand Up @@ -165,11 +163,11 @@ func runImport(version int64, exports map[string][]*iavl.ExportNode) error {
start := time.Now()
stats := Stats{}

newDB, err := tmdb.NewDB(name, tmdb.GoLevelDBBackend, tempdir)
newDB, err := idbm.NewGoLevelDB(name, tempdir)
if err != nil {
return err
}
newTree := iavl.NewMutableTree(idbm.NewWrapper(newDB), 0, false, iavl.NewNopLogger())
newTree := iavl.NewMutableTree(newDB, 0, false, iavl.NewNopLogger())
importer, err := newTree.Import(version)
if err != nil {
return err
Expand Down
53 changes: 0 additions & 53 deletions benchmarks/hash_test.go

This file was deleted.

53 changes: 53 additions & 0 deletions cmd/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module github.com/cosmos/iavl/cmd

go 1.21

require (
cosmossdk.io/core v0.12.1-0.20240514205955-97c9bbb0341b
cosmossdk.io/log v1.3.2-0.20240514205955-97c9bbb0341b
github.com/cosmos/cosmos-db v1.0.2
github.com/cosmos/iavl v1.2.0
)

require (
github.com/DataDog/zstd v1.4.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cosmos/gogoproto v1.4.12 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/emicklei/dot v1.6.2 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/linxGnu/grocksdb v1.8.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.12.0 // indirect
github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
)

replace github.com/cosmos/iavl => ../.
Loading

0 comments on commit 984d49b

Please sign in to comment.