Skip to content

Commit d528375

Browse files
feat: use the sdk/core/store.KVStoreWithBatch interface instead of iavl/db.DB interface (#980)
1 parent c68db50 commit d528375

26 files changed

+385
-848
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [#961](https://github.com/cosmos/iavl/pull/961) Add new `GetLatestVersion` API to get the latest version.
1010
- [#965](https://github.com/cosmos/iavl/pull/965) Use expected interface for expected IAVL `Logger`.
1111
- [#970](https://github.com/cosmos/iavl/pull/970) Close the pruning process when the nodeDB is closed.
12+
- [#980](https://github.com/cosmos/iavl/pull/980) Use the `sdk/core/store.KVStoreWithBatch` interface instead of `iavl/db.DB` interface
1213

1314
## v1.2.0 May 13, 2024
1415

batch.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@ import (
44
"sync"
55

66
corestore "cosmossdk.io/core/store"
7-
dbm "github.com/cosmos/iavl/db"
87
)
98

109
// BatchWithFlusher is a wrapper
1110
// around batch that flushes batch's data to disk
1211
// as soon as the configurable limit is reached.
1312
type BatchWithFlusher struct {
1413
mtx sync.Mutex
15-
db dbm.DB // This is only used to create new batch
16-
batch corestore.Batch // Batched writing buffer.
14+
db corestore.KVStoreWithBatch // This is only used to create new batch
15+
batch corestore.Batch // Batched writing buffer.
1716

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

2120
var _ corestore.Batch = (*BatchWithFlusher)(nil)
2221

2322
// NewBatchWithFlusher returns new BatchWithFlusher wrapping the passed in batch
24-
func NewBatchWithFlusher(db dbm.DB, flushThreshold int) *BatchWithFlusher {
23+
func NewBatchWithFlusher(db corestore.KVStoreWithBatch, flushThreshold int) *BatchWithFlusher {
2524
return &BatchWithFlusher{
2625
db: db,
2726
batch: db.NewBatchWithSize(flushThreshold),

benchmarks/bench_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func randBytes(length int) []byte {
2525
return key
2626
}
2727

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

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

340340
// note that "" leads to nil backing db!
341341
var (
342-
d dbm.DB
342+
d corestore.KVStoreWithBatch
343343
err error
344344
)
345345
if bb.dbType != "nodb" {
@@ -364,7 +364,7 @@ func memUseMB() float64 {
364364
return mb
365365
}
366366

367-
func runSuite(b *testing.B, d dbm.DB, initSize, blockSize, keyLen, dataLen int) {
367+
func runSuite(b *testing.B, d corestore.KVStoreWithBatch, initSize, blockSize, keyLen, dataLen int) {
368368
// measure mem usage
369369
runtime.GC()
370370
init := memUseMB()

cmd/go.mod

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,23 @@ module github.com/cosmos/iavl/cmd
33
go 1.21
44

55
require (
6-
cosmossdk.io/core v0.12.1-0.20240725072823-6a2d039e1212
6+
cosmossdk.io/core v0.12.1-0.20240811203112-84a9978c9c5f
77
cosmossdk.io/log v1.3.1
8-
github.com/cosmos/cosmos-db v1.0.2
98
github.com/cosmos/iavl v1.2.0
109
)
1110

1211
require (
13-
github.com/DataDog/zstd v1.4.5 // indirect
14-
github.com/beorn7/perks v1.0.1 // indirect
15-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
16-
github.com/cockroachdb/errors v1.11.1 // indirect
17-
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
18-
github.com/cockroachdb/pebble v1.1.0 // indirect
19-
github.com/cockroachdb/redact v1.1.5 // indirect
20-
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
21-
github.com/cosmos/gogoproto v1.5.0 // indirect
12+
github.com/cosmos/gogoproto v1.6.0 // indirect
2213
github.com/cosmos/ics23/go v0.10.0 // indirect
2314
github.com/emicklei/dot v1.6.2 // indirect
24-
github.com/getsentry/sentry-go v0.18.0 // indirect
2515
github.com/gogo/protobuf v1.3.2 // indirect
26-
github.com/golang/protobuf v1.5.3 // indirect
2716
github.com/golang/snappy v0.0.4 // indirect
2817
github.com/google/btree v1.1.2 // indirect
2918
github.com/google/go-cmp v0.6.0 // indirect
30-
github.com/klauspost/compress v1.15.15 // indirect
31-
github.com/kr/pretty v0.3.1 // indirect
32-
github.com/kr/text v0.2.0 // indirect
33-
github.com/linxGnu/grocksdb v1.8.12 // indirect
3419
github.com/mattn/go-colorable v0.1.13 // indirect
3520
github.com/mattn/go-isatty v0.0.20 // indirect
36-
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
3721
github.com/pkg/errors v0.9.1 // indirect
38-
github.com/prometheus/client_golang v1.12.0 // indirect
39-
github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect
40-
github.com/prometheus/common v0.32.1 // indirect
41-
github.com/prometheus/procfs v0.7.3 // indirect
42-
github.com/rogpeppe/go-internal v1.11.0 // indirect
4322
github.com/rs/zerolog v1.32.0 // indirect
44-
github.com/spf13/cast v1.6.0 // indirect
4523
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
4624
golang.org/x/crypto v0.23.0 // indirect
4725
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect

0 commit comments

Comments
 (0)