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

feat: use the sdk/core/store.KVStoreWithBatch interface instead of iavl/db.DB interface #980

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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.
- [#980](https://github.com/cosmos/iavl/pull/980) Use the `sdk/core/store.KVStoreWithBatch` interface instead of `iavl/db.DB` interface

## v1.2.0 May 13, 2024

Expand Down
7 changes: 3 additions & 4 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import (
"sync"

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

// BatchWithFlusher is a wrapper
// around batch that flushes batch's data to disk
// 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 corestore.Batch // Batched writing buffer.
db corestore.KVStoreWithBatch // 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 _ corestore.Batch = (*BatchWithFlusher)(nil)

// NewBatchWithFlusher returns new BatchWithFlusher wrapping the passed in batch
func NewBatchWithFlusher(db dbm.DB, flushThreshold int) *BatchWithFlusher {
func NewBatchWithFlusher(db corestore.KVStoreWithBatch, flushThreshold int) *BatchWithFlusher {
return &BatchWithFlusher{
db: db,
batch: db.NewBatchWithSize(flushThreshold),
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func randBytes(length int) []byte {
return key
}

func prepareTree(b *testing.B, db dbm.DB, size, keyLen, dataLen int) (*iavl.MutableTree, [][]byte) {
func prepareTree(b *testing.B, db corestore.KVStoreWithBatch, size, keyLen, dataLen int) (*iavl.MutableTree, [][]byte) {
t := iavl.NewMutableTree(db, size, false, iavl.NewNopLogger())
keys := make([][]byte, size)

Expand Down Expand Up @@ -339,7 +339,7 @@ func runBenchmarks(b *testing.B, benchmarks []benchmark) {

// note that "" leads to nil backing db!
var (
d dbm.DB
d corestore.KVStoreWithBatch
err error
)
if bb.dbType != "nodb" {
Expand All @@ -364,7 +364,7 @@ func memUseMB() float64 {
return mb
}

func runSuite(b *testing.B, d dbm.DB, initSize, blockSize, keyLen, dataLen int) {
func runSuite(b *testing.B, d corestore.KVStoreWithBatch, initSize, blockSize, keyLen, dataLen int) {
// measure mem usage
runtime.GC()
init := memUseMB()
Expand Down
26 changes: 2 additions & 24 deletions cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,23 @@ module github.com/cosmos/iavl/cmd
go 1.21

require (
cosmossdk.io/core v0.12.1-0.20240725072823-6a2d039e1212
cosmossdk.io/core v0.12.1-0.20240811203112-84a9978c9c5f
cosmossdk.io/log v1.3.1
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.5.0 // indirect
github.com/cosmos/gogoproto v1.6.0 // 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
Expand Down
Loading