Skip to content

Commit

Permalink
batch size with tmdb wrapper (#582)
Browse files Browse the repository at this point in the history
(cherry picked from commit dead65a)
  • Loading branch information
cool-develope authored and mergify[bot] committed Mar 22, 2024
1 parent 9157f02 commit df5b06a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions store/wrapper/tmdb.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package wrapper

import (
"encoding/binary"

tdbm "github.com/cometbft/cometbft-db"
iavldb "github.com/cosmos/iavl/db"
)
Expand Down Expand Up @@ -39,12 +41,12 @@ func (db *DBWrapper) DeleteSync(key []byte) error {

func (db *DBWrapper) Iterator(start, end []byte) (iavldb.Iterator, error) {
it, err := db.db.Iterator(start, end)
return it.(iavldb.Iterator), err
return it, err
}

func (db *DBWrapper) ReverseIterator(start, end []byte) (iavldb.Iterator, error) {
it, err := db.db.ReverseIterator(start, end)
return it.(iavldb.Iterator), err
return it, err
}

func (db *DBWrapper) NewBatch() iavldb.Batch {
Expand All @@ -69,25 +71,30 @@ func (db *DBWrapper) Close() error {

type BatchWrapper struct {
batch tdbm.Batch
size int
}

func NewCosmosBatch(batch tdbm.Batch) iavldb.Batch {
return &BatchWrapper{batch: batch}
}

func (b *BatchWrapper) Set(key, value []byte) error {
b.size += 1 + binary.MaxVarintLen32 + len(key) + binary.MaxVarintLen32 + len(value)
return b.batch.Set(key, value)
}

func (b *BatchWrapper) Delete(key []byte) error {
b.size += 1 + binary.MaxVarintLen32 + len(key)
return b.batch.Delete(key)
}

func (b *BatchWrapper) Write() error {
b.size = 0
return b.batch.Write()
}

func (b *BatchWrapper) WriteSync() error {
b.size = 0
return b.batch.WriteSync()
}

Expand All @@ -96,5 +103,5 @@ func (b *BatchWrapper) Close() error {
}

func (b *BatchWrapper) GetByteSize() (int, error) {
return 0, nil
return b.size, nil
}

0 comments on commit df5b06a

Please sign in to comment.