Skip to content

Commit

Permalink
feat: use the sdk/core/store.KVStoreWithBatch interface instead of …
Browse files Browse the repository at this point in the history
…`iavl/db.DB` interface (#980)
  • Loading branch information
cool-develope authored Aug 14, 2024
1 parent c68db50 commit d528375
Show file tree
Hide file tree
Showing 26 changed files with 385 additions and 848 deletions.
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

0 comments on commit d528375

Please sign in to comment.